mirror of
https://github.com/OpenLiberty/liberty-bikes.git
synced 2024-11-27 01:20:01 +08:00
Send users back to login page if they end up at the game page for an invalid round
This commit is contained in:
parent
10bb5805b0
commit
e048675b58
@ -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 });
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -73,4 +73,13 @@ public class OutboundMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorEvent {
|
||||
@JsonbProperty("errorMessage")
|
||||
public final String msg;
|
||||
|
||||
public ErrorEvent(String errMsg) {
|
||||
msg = errMsg;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user