added Context
This commit is contained in:
12
server.ts
12
server.ts
@@ -4,7 +4,7 @@ import { Server as SocketIOServer, type Socket } from 'socket.io';
|
||||
|
||||
import GameStore from '@/lib/GameStore';
|
||||
import omit from '@/tools/omit';
|
||||
import type { ClientUpdate, GameUpdate } from '@/types';
|
||||
import type { ClientUpdate, GameUpdate, Tilt } from '@/types';
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
const hostname = '0.0.0.0';
|
||||
@@ -119,6 +119,16 @@ app.prepare().then(() => {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('tilt', ({ gameID, tilt }: { gameID: string; tilt: Tilt }) => {
|
||||
try {
|
||||
const gameState = gameStore.getGame(gameID);
|
||||
broadcast('tilt', gameState);
|
||||
} catch (e) {
|
||||
const error = e instanceof Error ? e.message : e;
|
||||
console.error(Date.now(), 'Error[tilt]', error);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
try {
|
||||
const game = gameStore.playerExit(socket.id);
|
||||
|
||||
Reference in New Issue
Block a user