.
This commit is contained in:
commit
1f0daf82cb
15 changed files with 730 additions and 0 deletions
32
src/callbacks/disconnect.ts
Normal file
32
src/callbacks/disconnect.ts
Normal 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.',
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue