diff --git a/src/p4/PackagerOptions.svelte b/src/p4/PackagerOptions.svelte index 63c91b4..526df35 100644 --- a/src/p4/PackagerOptions.svelte +++ b/src/p4/PackagerOptions.svelte @@ -525,10 +525,13 @@ {$_('options.cloudVariablesHost')} - -

- Update: The default cloud variable server has changed from clouddata.turbowarp.org to clouddata.turbowarp.xyz. It's the same server with the same variables, just a different name. -

+ + {#if $options.cloudVariables.cloudHost === 'wss://clouddata.turbowarp.org'} +

+ Another update: The packager will try to connect to clouddata.turbowarp.org first, and if that fails, it will try clouddata.turbowarp.xyz instead. + This should make connections more reliable on filtered internet connections. +

+ {/if} {/if} diff --git a/src/packager/packager.js b/src/packager/packager.js index 7705dde..e1aa7ab 100644 --- a/src/packager/packager.js +++ b/src/packager/packager.js @@ -600,7 +600,14 @@ cd "$(dirname "$0")" } makeWebSocketProvider () { - return `new Scaffolding.Cloud.WebSocketProvider(${JSON.stringify(this.options.cloudVariables.cloudHost)}, ${JSON.stringify(this.options.projectId)})`; + // If using the default turbowarp.org server, we'll add a fallback for the turbowarp.xyz alias. + // This helps work around web filters as turbowarp.org can be blocked for games and turbowarp.xyz uses + // a problematic TLD. These are the same server and same variables, just different domain. + const cloudHost = this.options.cloudVariables.cloudHost === 'wss://clouddata.turbowarp.org' ? [ + 'wss://clouddata.turbowarp.org', + 'wss://clouddata.turbowarp.xyz' + ] : this.options.cloudVariables.cloudHost; + return `new Scaffolding.Cloud.WebSocketProvider(${JSON.stringify(cloudHost)}, ${JSON.stringify(this.options.projectId)})`; } makeLocalStorageProvider () { @@ -1285,7 +1292,7 @@ Packager.DEFAULT_OPTIONS = () => ({ }, cloudVariables: { mode: 'ws', - cloudHost: 'wss://clouddata.turbowarp.xyz', + cloudHost: 'wss://clouddata.turbowarp.org', custom: {}, specialCloudBehaviors: false, }, diff --git a/src/scaffolding/cloud.js b/src/scaffolding/cloud.js index 97bf49b..77ccc7c 100644 --- a/src/scaffolding/cloud.js +++ b/src/scaffolding/cloud.js @@ -79,14 +79,19 @@ class CloudManager { } class WebSocketProvider { + /** + * @param {string[]|string} cloudHost URLs of servers to connect to, including ws:// or wss:// + * If cloudHost is an array, the server will consecutively try each server until one connects. + * @param {string} projectId The ID of the project + */ constructor(cloudHost, projectId) { - this.cloudHost = cloudHost; + this.cloudHosts = Array.isArray(cloudHost) ? cloudHost : [cloudHost]; this.projectId = projectId; - this.connectionAttempts = 0; - this.openConnection = this.openConnection.bind(this); - this._throttleTimeoutFinished = this._throttleTimeoutFinished.bind(this); + this.attemptedConnections = 0; this.messageQueue = []; this.throttleTimeout = null; + this.openConnection = this.openConnection.bind(this); + this._throttleTimeoutFinished = this._throttleTimeoutFinished.bind(this); } enable () { @@ -94,8 +99,10 @@ class WebSocketProvider { } openConnection () { - this.connectionAttempts += 1; - this.ws = new WebSocket(this.cloudHost); + this.currentCloudHost = this.cloudHosts[this.attemptedConnections % this.cloudHosts.length]; + this.attemptedConnections++; + console.log(`Connecting to ${this.currentCloudHost}`); + this.ws = new WebSocket(this.currentCloudHost); this.ws.onerror = this.onerror.bind(this); this.ws.onmessage = this.onmessage.bind(this); this.ws.onopen = this.onopen.bind(this); @@ -118,7 +125,7 @@ class WebSocketProvider { } onopen () { - this.connectionAttempts = 1; + this.attemptedConnections = 0; this.writeToServer({ method: 'handshake' }); @@ -131,8 +138,8 @@ class WebSocketProvider { console.log('WebSocket username is invalid, not reconnecting.'); return; } - const timeout = Math.random() * (Math.pow(2, Math.min(this.connectionAttempts, 5)) - 1) * 1000; - console.log(`Reconnecting in ${(timeout / 1000).toFixed(1)}s, attempt ${this.connectionAttempts}`); + const timeout = Math.random() * (Math.pow(2, Math.min(this.attemptedConnections + 1, 5)) - 1) * 1000; + console.log(`Reconnecting in ${Math.round(timeout)}ms`); setTimeout(this.openConnection, timeout); }