Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@
},
"kick_reason": {
"duplicate_session": "Kicked from game (you may have been playing on another tab)",
"lobby_creator": "Kicked by lobby creator"
"lobby_creator": "Kicked by lobby creator",
"host_left": "The host has left the lobby."
},
"send_troops_modal": {
"title_with_name": "Send Troops to {name}",
Expand Down
9 changes: 9 additions & 0 deletions src/client/ClientGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ export function joinLobby(
composed: true,
}),
);
} else if (message.error === "kick_reason.host_left") {
alert(translateText("kick_reason.host_left"));
document.dispatchEvent(
new CustomEvent("leave-lobby", {
detail: { lobby: lobbyConfig.gameID, cause: "host-left" },
bubbles: true,
composed: true,
}),
);
} else {
showErrorModal(
message.error,
Expand Down
17 changes: 17 additions & 0 deletions src/server/GameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum GamePhase {

const KICK_REASON_DUPLICATE_SESSION = "kick_reason.duplicate_session";
const KICK_REASON_LOBBY_CREATOR = "kick_reason.lobby_creator";
const KICK_REASON_HOST_LEFT = "kick_reason.host_left";
const KICK_REASON_TOO_MUCH_DATA = "kick_reason.too_much_data";
const KICK_REASON_INVALID_MESSAGE = "kick_reason.invalid_message";

Expand Down Expand Up @@ -537,6 +538,20 @@ export class GameServer {
this.activeClients = this.activeClients.filter(
(c) => c.clientID !== client.clientID,
);
// Close lobby when host leaves before game starts
if (
!this._hasStarted &&
!this.isPublic() &&
client.persistentID === this.creatorPersistentID
) {
this.log.info("Host left, closing lobby", {
gameID: this.id,
});
for (const c of [...this.activeClients]) {
this.kickClient(c.clientID, KICK_REASON_HOST_LEFT);
}
this._hasEnded = true;
}
});
client.ws.on("error", (error: Error) => {
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
Expand Down Expand Up @@ -839,6 +854,8 @@ export class GameServer {
} else {
return GamePhase.Active;
}
} else if (this._hasEnded) {
return GamePhase.Finished;
} else {
return GamePhase.Lobby;
}
Expand Down
Loading