This commit is contained in:
Ruan Fernandes Guimaraes 2025-06-29 10:55:10 -03:00
commit 1f0daf82cb
15 changed files with 730 additions and 0 deletions

View file

@ -0,0 +1,32 @@
import { Client } from 'colyseus';
import { MessageType } from '../protocol/MessageType';
import { GameRoom } from '../rooms/GameRoom';
export default function disconnectCallback(
client: Client,
consented: boolean,
room: GameRoom
) {
console.log(
'Client disconnected:',
client.sessionId,
'consented:',
consented
);
room.broadcast(MessageType.CLIENT_PLAYER_LEFT, {
sessionId: client.sessionId,
});
room.deletePlayer(client.sessionId);
if (consented) {
client.send(MessageType.CLIENT_WELCOME, {
message: 'You have successfully disconnected.',
});
} else {
client.send(MessageType.CLIENT_ERROR, {
message: 'You were disconnected unexpectedly.',
});
}
}