separate DMs and spectators
This commit is contained in:
12
server.ts
12
server.ts
@@ -2,8 +2,8 @@ import next from 'next';
|
||||
import { createServer } from 'http';
|
||||
import { Server as SocketIOServer, type Socket } from 'socket.io';
|
||||
|
||||
import GameStore from './lib/GameStore';
|
||||
import type { ClientUpdate } from './types';
|
||||
import GameStore from '@/lib/GameStore';
|
||||
import type { ClientUpdate } from '@/types';
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
const hostname = '0.0.0.0';
|
||||
@@ -22,6 +22,14 @@ app.prepare().then(() => {
|
||||
io.on('connection', (socket: Socket) => {
|
||||
console.log(`Client connected: ${socket.id}`);
|
||||
|
||||
socket.on('start', () => {
|
||||
const gameUpdate = gameStore.createGame();
|
||||
|
||||
console.log(`Socket ${socket.id} started game ${gameUpdate.dmID}`);
|
||||
|
||||
socket.emit('new-game', gameUpdate);
|
||||
});
|
||||
|
||||
socket.on('join', (gameID) => {
|
||||
socket.join(gameID);
|
||||
const gameUpdate = gameStore.joinGame(gameID, socket.id);
|
||||
|
||||
Reference in New Issue
Block a user