More commands

- fixed backend error responses
- added round abort command
pull/15/head
Julius 6 years ago
parent 31c91c54ad
commit d0085a2bfd

@ -49,3 +49,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- code style issues
- Bingo button not shown on refresh
- bingo chat style (images too large)
- backend now returns precise error messages

@ -24,6 +24,9 @@ type LobbyMutation {
"starts a round in a lobby if the user is the admin"
startRound: BingoRound
"sets the round status"
setRoundStatus(status: RoundStatus): BingoRound
"sets the new gridsize for the lobby"
setGridSize(gridSize: Int!): BingoLobby

@ -125,7 +125,7 @@ async function leaveLobby() {
/**
* Kicks a player by id.
* @param playerId
* @param pid
* @returns {Promise<void>}
*/
async function kickPlayer(pid) {
@ -167,6 +167,7 @@ async function executeCommand(message) {
/hideinfo - hides all info messages <br>
/showinfo - shows all info messages <br>
/ping - shows the current ping <br>
/abortround - aborts the current round <br>
`);
break;
case '/hideinfo':
@ -178,6 +179,9 @@ async function executeCommand(message) {
case '/ping':
reply(`Ping: ${await ping()} ms`);
break;
case '/abortround':
reply(await setRoundFinished());
break;
default:
reply('Unknown command');
break;
@ -334,6 +338,30 @@ async function submitFieldToggle(wordPanel) {
}
}
/**
* Sets the round status to FINISHED
* @returns {Promise<string>}
*/
async function setRoundFinished() {
let response = await postGraphqlQuery(`
mutation($lobbyId:ID!){
bingo {
mutateLobby(id:$lobbyId) {
setRoundStatus(status:FINISHED) {
status
}
}
}
}`, {lobbyId: getLobbyParam()});
if (response.status === 200 && response.data.bingo.mutateLobby.setRoundStatus) {
return 'Set round to finished';
} else {
console.error(response);
showError('Failed to set round status');
}
}
/**
* Submits bingo
* @returns {Promise<void>}
@ -442,7 +470,10 @@ async function loadWinnerInfo() {
}`, {lobbyId: getLobbyParam()});
if (response.status === 200) {
let roundInfo = response.data.bingo.lobby.currentRound;
displayWinner(roundInfo);
if (roundInfo.winner)
displayWinner(roundInfo);
else
window.location.reload();
} else {
console.error(response);
showError('Failed to get round information');

@ -1064,6 +1064,18 @@ class LobbyWrapper {
let currentRound = await this.currentRound();
return currentRound && (await currentRound.status()) === 'ACTIVE';
}
/**
* Sets the status of the current round
* @param status {String} - the status
* @returns {Promise<RoundWrapper>}
*/
async setRoundStatus(status) {
let currentRound = await this.currentRound();
await currentRound.updateStatus(status);
await bdm.addInfoMessage(this.id, `Admin set round status to ${status}`);
return currentRound;
}
}
@ -1386,6 +1398,9 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) {
await lobbyWrapper.removePlayer(pid);
return new PlayerWrapper(pid);
} else {
res.status(403);
return new GraphQLError('You are not an admin');
}
},
startRound: async () => {
@ -1393,6 +1408,18 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) {
await lobbyWrapper.startNewRound();
return lobbyWrapper.currentRound();
} else {
res.status(403);
return new GraphQLError('You are not an admin');
}
},
setRoundStatus: async ({status}) => {
let admin = await lobbyWrapper.admin();
if (admin.id === playerId) {
return await lobbyWrapper.setRoundStatus(status);
} else {
res.status(403);
return new GraphQLError('You are not an admin');
}
},
setGridSize: async ({gridSize}) => {
@ -1400,6 +1427,9 @@ router.graphqlResolver = async (req, res) => {
if (admin.id === playerId) {
await lobbyWrapper.setGridSize(gridSize);
return lobbyWrapper;
} else {
res.status(403);
return new GraphQLError('You are not an admin');
}
},
setWords: async({words}) => {
@ -1410,6 +1440,7 @@ router.graphqlResolver = async (req, res) => {
return lobbyWrapper;
} else {
res.status(413); // request entity too large
return new GraphQLError('Too many words');
}
else
res.status(403); // forbidden
@ -1421,6 +1452,7 @@ router.graphqlResolver = async (req, res) => {
return new MessageWrapper(result);
} else {
res.status(401); // unautorized
return new GraphQLError('You are not in the lobby');
}
},
submitBingo: async () => {
@ -1428,10 +1460,13 @@ router.graphqlResolver = async (req, res) => {
let currentRound = await lobbyWrapper.currentRound();
if (isBingo && await lobbyWrapper.hasPlayer(playerId)) {
let result = await currentRound.setWinner(playerId);
if (result)
let username = await new PlayerWrapper(playerId).username();
if (result) {
await bdm.addInfoMessage(lobbyId, `**${username}** won!`);
return currentRound;
else
} else {
res.status(500);
}
} else {
res.status(400);
return new GraphQLError('Bingo check failed. This is not a bingo!');

Loading…
Cancel
Save