Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
commit
bf10363581
|
|
@ -39,15 +39,26 @@ 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));
|
||||
const data = BSON.deserialize(new Uint8Array(msg.buffer))
|
||||
|
||||
handlePacket(handlers, data, (data) => {
|
||||
ws.send(BSON.serialize(data))
|
||||
})
|
||||
|
||||
if (messageChannel.length > 0) {
|
||||
if (handlers.has(data.op)) {
|
||||
return
|
||||
}
|
||||
console.log(`publishing to clients on ${messageChannel}: `, data);
|
||||
|
||||
toClient.post({
|
||||
|
|
@ -55,10 +66,6 @@ export async function startGameServer(ws: WebSocket, req: Request) {
|
|||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
handlePacket(handlers, data, (data) => {
|
||||
ws.send(BSON.serialize(data))
|
||||
})
|
||||
})
|
||||
|
||||
ws.on("close", () => {
|
||||
|
|
@ -102,6 +109,9 @@ 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;
|
||||
|
|
@ -109,6 +119,13 @@ 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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user