Send users back to login page if they end up at the game page for an invalid round

This commit is contained in:
Andrew Guibert 2018-05-15 10:30:36 -05:00
parent 10bb5805b0
commit e048675b58
4 changed files with 28 additions and 0 deletions

View File

@ -52,6 +52,13 @@ export class ControlsComponent implements OnInit, OnDestroy {
gameService.messages.subscribe((msg) => {
const json = msg as any;
console.log(`received: ${JSON.stringify(json)}`);
if (json.errorMessage) {
console.log('Received error message from server: ' + json.errorMessage);
alert('Your connection to the game server has been closed. You will be redirected to the login page.');
this.ngZone.run(() => {
this.router.navigate(['/login']);
});
}
if (json.keepAlive) {
this.gameService.send({ keepAlive: true });
}

View File

@ -53,6 +53,13 @@ export class GameComponent implements OnInit, OnDestroy {
this.ngZone.runOutsideAngular(() => {
gameService.messages.subscribe((msg) => {
const json = msg as any;
if (json.errorMessage) {
console.log('Received error message from server: ' + json.errorMessage);
alert('Your connection to the game server has been closed. You will be redirected to the login page.');
this.ngZone.run(() => {
this.router.navigate(['/login']);
});
}
if (json.countdown) {
this.ngZone.run(() => this.startingCountdown(json.countdown));
}

View File

@ -73,4 +73,13 @@ public class OutboundMessage {
}
}
public static class ErrorEvent {
@JsonbProperty("errorMessage")
public final String msg;
public ErrorEvent(String errMsg) {
msg = errMsg;
}
}
}

View File

@ -22,6 +22,7 @@ import org.libertybikes.game.core.GameRound;
import org.libertybikes.game.core.GameRound.State;
import org.libertybikes.game.core.InboundMessage;
import org.libertybikes.game.core.InboundMessage.GameEvent;
import org.libertybikes.game.core.OutboundMessage;
import org.libertybikes.restclient.PlayerService;
@Dependent
@ -65,6 +66,10 @@ public class GameRoundWebsocket {
final GameRound round = gameSvc.getRound(roundId);
if (round == null || round.gameState == State.FINISHED) {
log(roundId, "[onMessage] Received message for round that did not exist or has completed. Closing this websocket connection.");
if (round == null)
sendToClient(session, new OutboundMessage.ErrorEvent("Round " + roundId + " did not exist"));
else
sendToClient(session, new OutboundMessage.ErrorEvent("Round " + roundId + " has already completed."));
session.close();
return;
}