From 732d0ee66a61d02cfc956b1ff91de4dbce08e268 Mon Sep 17 00:00:00 2001 From: Jesse Selover Date: Wed, 8 May 2024 02:18:18 -0700 Subject: [PATCH 1/4] Attempt 1 at exponential backoff in server-down behavior. --- src/ui/unavailable-modal-ui-handler.ts | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 4481746c7..4f6001d9f 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -6,10 +6,12 @@ import { updateUserInfo } from "#app/account"; export default class UnavailableModalUiHandler extends ModalUiHandler { private reconnectTimer: number; + private reconnectInterval: number; private reconnectCallback: () => void; constructor(scene: BattleScene, mode?: Mode) { super(scene, mode); + this.reconnectInterval = 5000; } getModalTitle(): string { @@ -41,6 +43,23 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { this.modalContainer.add(label); } + tryReconnect(): void { + updateUserInfo().then(response => { + if (response[0] || [200, 400].includes(response[1])) { + clearInterval(this.reconnectTimer); + this.reconnectTimer = null; + this.reconnectInterval = 5000; + this.scene.playSound('pb_bounce_1'); + this.reconnectCallback(); + } + else { + clearInterval(this.reconnectTimer); + this.reconnectInterval *= 2; + this.reconnectTimer = setInterval(this.tryReconnect, reconnectInterval); + } + }); + } + show(args: any[]): boolean { if (args.length >= 1 && args[0] instanceof Function) { const config: ModalConfig = { @@ -49,20 +68,11 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { this.reconnectCallback = args[0]; - this.reconnectTimer = setInterval(() => { - updateUserInfo().then(response => { - if (response[0] || [200, 400].includes(response[1])) { - clearInterval(this.reconnectTimer); - this.reconnectTimer = null; - this.scene.playSound('pb_bounce_1'); - this.reconnectCallback(); - } - }) - }, 5000); + this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval); return super.show([ config ]); } return false; } -} \ No newline at end of file +} From af48bea179bca0620dfea89bbf01e526d6c73197 Mon Sep 17 00:00:00 2001 From: Jesse Selover Date: Wed, 8 May 2024 02:46:07 -0700 Subject: [PATCH 2/4] Add a maximum delay of 5 minutes, and compliance fixup. --- src/ui/unavailable-modal-ui-handler.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 4f6001d9f..d9678a67f 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -55,7 +55,10 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { else { clearInterval(this.reconnectTimer); this.reconnectInterval *= 2; - this.reconnectTimer = setInterval(this.tryReconnect, reconnectInterval); + if (this.reconnectInterval >= 300000) { + this.reconnectInterval = 300000; // 300 seconds (5 minutes) maximum delay. + } + this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval); } }); } From 817ee3158e5b449446e591e31fcd9a13683edc83 Mon Sep 17 00:00:00 2001 From: Jesse Selover Date: Wed, 8 May 2024 02:51:15 -0700 Subject: [PATCH 3/4] Lower maximum interval to 1 minute. --- src/ui/unavailable-modal-ui-handler.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index d9678a67f..137469a0d 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -55,8 +55,8 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { else { clearInterval(this.reconnectTimer); this.reconnectInterval *= 2; - if (this.reconnectInterval >= 300000) { - this.reconnectInterval = 300000; // 300 seconds (5 minutes) maximum delay. + if (this.reconnectInterval >= 60000) { + this.reconnectInterval = 60000; // 1 minute maximum delay. } this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval); } From 935e1f59091a5139397d7a32d52842e8865b0e97 Mon Sep 17 00:00:00 2001 From: Jesse Selover Date: Wed, 8 May 2024 04:06:28 -0700 Subject: [PATCH 4/4] Fix indentation and use setTimeout instead of setInterval. --- src/ui/unavailable-modal-ui-handler.ts | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ui/unavailable-modal-ui-handler.ts b/src/ui/unavailable-modal-ui-handler.ts index 137469a0d..b9d374b73 100644 --- a/src/ui/unavailable-modal-ui-handler.ts +++ b/src/ui/unavailable-modal-ui-handler.ts @@ -44,23 +44,23 @@ export default class UnavailableModalUiHandler extends ModalUiHandler { } tryReconnect(): void { - updateUserInfo().then(response => { - if (response[0] || [200, 400].includes(response[1])) { - clearInterval(this.reconnectTimer); - this.reconnectTimer = null; - this.reconnectInterval = 5000; - this.scene.playSound('pb_bounce_1'); - this.reconnectCallback(); - } - else { - clearInterval(this.reconnectTimer); - this.reconnectInterval *= 2; - if (this.reconnectInterval >= 60000) { - this.reconnectInterval = 60000; // 1 minute maximum delay. - } - this.reconnectTimer = setInterval(this.tryReconnect, this.reconnectInterval); - } - }); + updateUserInfo().then(response => { + if (response[0] || [200, 400].includes(response[1])) { + clearInterval(this.reconnectTimer); + this.reconnectTimer = null; + this.reconnectInterval = 5000; + this.scene.playSound('pb_bounce_1'); + this.reconnectCallback(); + } + else { + clearInterval(this.reconnectTimer); + this.reconnectInterval *= 2; + if (this.reconnectInterval > 60000) { + this.reconnectInterval = 60000; // 1 minute maximum delay. + } + this.reconnectTimer = setTimeout(this.tryReconnect, this.reconnectInterval); + } + }); } show(args: any[]): boolean {