0
0
Fork 0

Change error events to the main event response name.

This commit is contained in:
Oliver-Akins 2021-01-01 15:55:51 -07:00
parent 7f93f2730c
commit 580382b7b2

View file

@ -7,10 +7,10 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
// Assert game exists // Assert game exists
if (!games[data.game_code]) { if (!games[data.game_code]) {
log.debug(`Can't delete game that doesn't exist: ${data.game_code}`); log.debug(`Can't join game that doesn't exist: ${data.game_code}`);
socket.emit(`Error`, { socket.emit(`GameJoined`, {
status: 404, status: 404,
message: `Game with code ${data.game_code} could not be found`, message: `Game with code "${data.game_code}" could not be found`,
source: `JoinGame` source: `JoinGame`
}); });
return; return;
@ -23,13 +23,13 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
let sameName = game.players.find(x => x.name == data.name); let sameName = game.players.find(x => x.name == data.name);
if (sameName != null) { if (sameName != null) {
if (!game.ingame) { if (!game.ingame) {
socket.emit(`Error`, { socket.emit(`GameJoined`, {
status: 400, status: 400,
message: `A player already has that name in the game.`, message: `A player already has that name in the game.`,
source: `JoinGame` source: `JoinGame`
}); });
return; return;
} };
// Player has the same name but is allowed to rejoin if they // Player has the same name but is allowed to rejoin if they
// disconnect in the middle of the game // disconnect in the middle of the game
@ -37,7 +37,7 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
socket.emit(`GameRejoined`, { status: 200 }); socket.emit(`GameRejoined`, { status: 200 });
return; return;
} else { } else {
socket.emit(`Error`, { socket.emit(`GameJoined`, {
status: 403, status: 403,
message: `Can't connect to an already connected client`, message: `Can't connect to an already connected client`,
source: `JoinGame` source: `JoinGame`
@ -49,7 +49,7 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
// Assert game is not in-progess // Assert game is not in-progess
if (game.ingame) { if (game.ingame) {
socket.emit(`Error`, { socket.emit(`GameJoined`, {
status: 403, status: 403,
message: `Cannot connect to a game that's in progress.`, message: `Cannot connect to a game that's in progress.`,
source: `JoinGame` source: `JoinGame`
@ -68,7 +68,7 @@ export default (io: Server, socket: Socket, data: JoinGame) => {
}); });
} }
catch (err) { catch (err) {
socket.emit(`Error`, { socket.emit(`GameJoined`, {
status: 500, status: 500,
message: `${err.name}: ${err.message}`, message: `${err.name}: ${err.message}`,
source: `JoinGame`, source: `JoinGame`,