-
×
+
×
Join Private Lobby
@@ -117,7 +118,7 @@ export class JoinPrivateLobbyModal extends LitElement {
${this.message}
-
Join Lobby
+ ${!this.hasJoined ? html`
Join Lobby ` : ''}
`;
@@ -129,13 +130,18 @@ export class JoinPrivateLobbyModal extends LitElement {
public close() {
this.isModalOpen = false;
+ this.lobbyIdInput.value = null
+ }
+
+ public closeAndLeave() {
+ this.close()
+ this.hasJoined = false
+ this.message = ""
this.dispatchEvent(new CustomEvent('leave-lobby', {
detail: {lobby: this.lobbyIdInput.value},
bubbles: true,
composed: true
}));
- this.lobbyIdInput.value = null
-
}
private async pasteFromClipboard() {
@@ -162,6 +168,7 @@ export class JoinPrivateLobbyModal extends LitElement {
.then(data => {
if (data.exists) {
this.message = 'Joined successfully! Waiting for game to start...';
+ this.hasJoined = true
this.dispatchEvent(new CustomEvent('join-lobby', {
detail: {
lobby: {id: lobbyId},
diff --git a/src/client/Main.ts b/src/client/Main.ts
index 205956428..4f0eef669 100644
--- a/src/client/Main.ts
+++ b/src/client/Main.ts
@@ -29,6 +29,11 @@ class Client {
if (!this.usernameInput) {
console.warn('Username input element not found');
}
+ const s = this.stopGame
+ window.addEventListener('beforeunload', function (event) {
+ console.log('Browser is closing');
+ s()
+ });
setFavicon()
this.ip = getClientIP()
@@ -76,13 +81,15 @@ class Client {
}
);
this.game.join(() => {
- this.joinModal.close()
+ this.joinModal.closeAndLeave()
});
const g = this.game;
- window.addEventListener('beforeunload', function (event) {
- console.log('Browser is closing');
- g.stop();
- });
+ }
+
+ private stopGame() {
+ if (this.game != null) {
+ this.game.stop()
+ }
}
private async handleLeaveLobby(event: CustomEvent) {
diff --git a/src/client/Transport.ts b/src/client/Transport.ts
index faf45845a..07b3b22f3 100644
--- a/src/client/Transport.ts
+++ b/src/client/Transport.ts
@@ -123,11 +123,11 @@ export class Transport {
};
this.socket.onclose = (event: CloseEvent) => {
console.log(`WebSocket closed. Code: ${event.code}, Reason: ${event.reason}`);
- if (!isActive()) {
- return
- }
if (event.code != 1000) {
+ console.log(`reconnecting`)
this.connect(onconnect, onmessage, isActive)
+ } else {
+ console.log('normal websocket closure')
}
};
}
@@ -147,6 +147,9 @@ export class Transport {
}
leaveGame() {
+ if (this.isLocal) {
+ return
+ }
if (this.socket.readyState === WebSocket.OPEN) {
console.log('on stop: leaving game')
const msg = ClientLeaveMessageSchema.parse({
@@ -159,6 +162,7 @@ export class Transport {
console.log('WebSocket is not open. Current state:', this.socket.readyState);
console.log('attempting reconnect')
}
+ this.socket = null
}
private onSendAllianceRequest(event: SendAllianceRequestIntentEvent) {
diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts
index 0b211f167..e1f7973a1 100644
--- a/src/core/configuration/DevConfig.ts
+++ b/src/core/configuration/DevConfig.ts
@@ -6,7 +6,7 @@ export const devConfig = new class extends DefaultConfig {
return 95
}
numSpawnPhaseTurns(): number {
- return 40
+ return 400
}
gameCreationRate(): number {
return 20 * 1000
diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts
index d915cbf54..e494dd3c2 100644
--- a/src/server/GameServer.ts
+++ b/src/server/GameServer.ts
@@ -137,6 +137,7 @@ export class GameServer {
if (!this.isPublic) {
if (this._hasStarted) {
if (this.clients.length == 0) {
+ console.log(`game ${this.id} is finisehd`)
return GamePhase.Finished
} else {
return GamePhase.Active