Add some sanity comments and a full lobby check
This commit is contained in:
parent
c340755ba2
commit
3f96b97194
1 changed files with 12 additions and 2 deletions
|
|
@ -15,7 +15,7 @@ const data: WebsocketEvent = {
|
|||
let game = games.get(gID);
|
||||
|
||||
|
||||
// Ensure the user provided a game code that could be found
|
||||
// Make sure the lobby exists that the player is attempting to connect to
|
||||
if (!game) {
|
||||
socket.emit(`res:lobby.players.join`, {
|
||||
status: Status.NotFound,
|
||||
|
|
@ -24,6 +24,7 @@ const data: WebsocketEvent = {
|
|||
return;
|
||||
};
|
||||
|
||||
// Player name unique-ness check
|
||||
let sameName = game.players.find(p => p.name == name);
|
||||
if (sameName) {
|
||||
socket.emit(`res:lobby.players.join`, {
|
||||
|
|
@ -33,7 +34,7 @@ const data: WebsocketEvent = {
|
|||
return;
|
||||
};
|
||||
|
||||
// Ensure the game is currently in the lobby state
|
||||
// Make sure the player isn't trying to join a game part-way through
|
||||
if (game.status !== `lobby`) {
|
||||
socket.emit(`res:lobby.players.join`, {
|
||||
status: Status.Forbidden,
|
||||
|
|
@ -42,6 +43,15 @@ const data: WebsocketEvent = {
|
|||
return;
|
||||
};
|
||||
|
||||
// Lobby is full already
|
||||
if (game.players.length >= 4) {
|
||||
socket.emit(`res:lobby.players.join`, {
|
||||
status: Status.Forbidden,
|
||||
message: `Can't join a game that has all 4 spots taken already.`,
|
||||
});
|
||||
return;
|
||||
};
|
||||
|
||||
let usedColours = game.players.map(p => p.colour);
|
||||
let newPlayerColour = null;
|
||||
do {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue