separate DMs and spectators

This commit is contained in:
Gavin McDonald
2025-04-14 14:22:06 -04:00
parent 4189e41da5
commit 424b8e0ec3
4 changed files with 59 additions and 21 deletions

View File

@@ -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);