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);
|
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) {
|
if (!game) {
|
||||||
socket.emit(`res:lobby.players.join`, {
|
socket.emit(`res:lobby.players.join`, {
|
||||||
status: Status.NotFound,
|
status: Status.NotFound,
|
||||||
|
|
@ -24,6 +24,7 @@ const data: WebsocketEvent = {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Player name unique-ness check
|
||||||
let sameName = game.players.find(p => p.name == name);
|
let sameName = game.players.find(p => p.name == name);
|
||||||
if (sameName) {
|
if (sameName) {
|
||||||
socket.emit(`res:lobby.players.join`, {
|
socket.emit(`res:lobby.players.join`, {
|
||||||
|
|
@ -33,7 +34,7 @@ const data: WebsocketEvent = {
|
||||||
return;
|
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`) {
|
if (game.status !== `lobby`) {
|
||||||
socket.emit(`res:lobby.players.join`, {
|
socket.emit(`res:lobby.players.join`, {
|
||||||
status: Status.Forbidden,
|
status: Status.Forbidden,
|
||||||
|
|
@ -42,6 +43,15 @@ const data: WebsocketEvent = {
|
||||||
return;
|
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 usedColours = game.players.map(p => p.colour);
|
||||||
let newPlayerColour = null;
|
let newPlayerColour = null;
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue