Compare commits

..

No commits in common. "6d0d606b7a6da784274a673923c4bfeef36c6753" and "ed98239bdf59eae48438b9b43e510e135a9f42ba" have entirely different histories.

2 changed files with 6 additions and 23 deletions

View File

@ -86,7 +86,7 @@ async function main() {
Global.wait("Starting Application")
app.listen(process.env.PORT || 8080, () => {
app.listen(8080, () => {
Global.info("Application successfully started.")
Global.info("Started on http://localhost:8080")
})

View File

@ -39,26 +39,15 @@ export async function startGameServer(ws: WebSocket, req: Request) {
toServer.attach(toServerHandler)
})
handlers.set("ping", async (data, send) => {
send(serialize(createPacket("ping", {})))
})
ws.send(BSON.serialize(createPacket("cfg.gameSecrets", {
gameCode: myCode,
})))
ws.on("message", async (msg: Buffer) => {
console.log(msg)
const data = BSON.deserialize(new Uint8Array(msg.buffer))
handlePacket(handlers, data, (data) => {
ws.send(BSON.serialize(data))
})
const data = BSON.deserialize(new Uint8Array(msg.buffer));
if (messageChannel.length > 0) {
if (handlers.has(data.op)) {
return
}
console.log(`publishing to clients on ${messageChannel}: `, data);
toClient.post({
@ -66,6 +55,10 @@ export async function startGameServer(ws: WebSocket, req: Request) {
data: data
})
}
handlePacket(handlers, data, (data) => {
ws.send(BSON.serialize(data))
})
})
ws.on("close", () => {
@ -109,9 +102,6 @@ export async function joinGameInstance(ws: WebSocket, req: Request){
uuid = data.uuid
console.log(uuid)
})
handlers.set("ping", async (data, send) => {
send(serialize(createPacket("ping", {})))
})
ws.on("message", async (msg: Buffer) => {
// BSON: const data = BSON.deserialize(new Uint8Array(msg.buffer)) as Packet;
@ -119,13 +109,6 @@ export async function joinGameInstance(ws: WebSocket, req: Request){
try {
const data = BSON.deserialize(msg) as Packet
data.conn = connectionId;
handlePacket(handlers, data, (data) => {
ws.send(BSON.serialize(data))
})
if (handlers.has(data.op ?? "")) {
return
}
toServer.post({
channel: messageChannel,