Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Che bato/manual disconnect #425

Merged
merged 5 commits into from
Jan 10, 2025
Merged

Che bato/manual disconnect #425

merged 5 commits into from
Jan 10, 2025

Conversation

CheBato
Copy link
Collaborator

@CheBato CheBato commented Jan 9, 2025

Changes

GameServer.ts

  • Changed import "import socketio from 'socket.io' to import type { Socket as IOSocket } from 'socket.io';
    import { Server as IOServer } from 'socket.io'; This lets us have more possibilities when extending base types for Socket and Server.

  • extended server and socket to type <ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData> reference document

  • Added interface SocketData which will be used as additional data for a socket. Currently it only holds manualDisconnect but might be useful later on for more custom data.

  • Changed type socketio.Socket throughout the file to IOSocket<any, any, any, SocketData> since we now have an extended Socket type.

  • Added a manualDisconnect listener to the socket that sets the manualDisconnect parameter in the socket.data. This will tell us if a user wilfully wishes to leave a game

  • Removed throw new Error because players can come to this state when they wish to reconnect to a game that they left but the game has removed them from its mapping (they took longer then 20s).

  • rewrote onSocketDisconnected function to check if the players socket has the manualDisconnect property set to true if it is set to true we remove the player from the userlobbymap and game. We cleanup the lobby if there are no users left.

  • Added a new timeout for all other types of disconnect which is 20s.

- Started with manualDisconnects.
- Changed error handling to logger so that server doesn't crash if a user tries to reconnect to a lobby and can't because it already removed him.
@CheBato CheBato marked this pull request as ready for review January 9, 2025 15:08
@CheBato CheBato requested a review from AMMayberry1 as a code owner January 9, 2025 15:08
server/gamenode/GameServer.ts Outdated Show resolved Hide resolved
server/gamenode/GameServer.ts Outdated Show resolved Hide resolved
server/gamenode/GameServer.ts Outdated Show resolved Hide resolved
server/gamenode/GameServer.ts Show resolved Hide resolved
@AMMayberry1 AMMayberry1 merged commit fb01cbe into main Jan 10, 2025
2 checks passed
@AMMayberry1 AMMayberry1 deleted the CheBato/ManualDisconnect branch January 10, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants