-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin,sm): Add controls for configuring the servers.2.json endpo…
…int (#125)
- Loading branch information
1 parent
dbf71cb
commit 17ea110
Showing
11 changed files
with
204 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Main } from "./main.js"; | ||
|
||
export class LegacyServerManager { | ||
#mainInstance; | ||
#ip4El; | ||
#ip6El; | ||
|
||
/** | ||
* @param {Main} mainInstance | ||
*/ | ||
constructor(mainInstance) { | ||
this.#mainInstance = mainInstance; | ||
|
||
this.el = document.createElement("div"); | ||
this.el.classList.add("legay-server-manager"); | ||
|
||
this.#ip4El = this.#createIpInput("Legacy IPv4: "); | ||
this.#ip6El = this.#createIpInput("Legacy IPv6: "); | ||
} | ||
|
||
/** | ||
* @param {string} labelText | ||
*/ | ||
#createIpInput(labelText) { | ||
const labelEl = document.createElement("label"); | ||
this.el.append(labelEl); | ||
const inputEl = document.createElement("input"); | ||
inputEl.addEventListener("change", () => { | ||
this.#mainInstance.webSocketManager.messenger.send.setLegacyServerData({ | ||
ipv4: this.#ip4El.value, | ||
ipv6: this.#ip6El.value, | ||
}); | ||
}); | ||
labelEl.append(labelText, inputEl); | ||
return inputEl; | ||
} | ||
|
||
/** | ||
* @param {import("../../serverManager/src/LegacyServerManager.js").LegacyServerData} serverData | ||
*/ | ||
setServerData(serverData) { | ||
this.#ip4El.value = serverData.ipv4; | ||
this.#ip6El.value = serverData.ipv6; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { LegacyServerManager } from "./LegacyServerManager.js"; | ||
import { ServerManager } from "./ServerManager.js"; | ||
import { WebSocketManager } from "./WebsocketManager.js"; | ||
|
||
export class Main { | ||
constructor() { | ||
this.webSocketManager = new WebSocketManager(this); | ||
this.legacyServersManager = new LegacyServerManager(this); | ||
this.serverManager = new ServerManager(this); | ||
} | ||
} | ||
|
||
const main = new Main(); | ||
globalThis.main = main; | ||
|
||
document.body.appendChild(main.legacyServersManager.el); | ||
document.body.appendChild(main.serverManager.el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Main } from "./Main.js"; | ||
|
||
/** | ||
* @typedef LegacyServerData | ||
* @property {string} ipv6 | ||
* @property {string} ipv4 | ||
*/ | ||
|
||
const PERSISTENT_STORAGE_KEY = "legacyServersManagerData"; | ||
|
||
export class LegacyServerManager { | ||
#mainInstance; | ||
|
||
/** @type {LegacyServerData} */ | ||
#serverData = { | ||
ipv4: "", | ||
ipv6: "", | ||
}; | ||
|
||
/** | ||
* @param {Main} mainInstance | ||
*/ | ||
constructor(mainInstance) { | ||
this.#mainInstance = mainInstance; | ||
|
||
const loadedData = this.#mainInstance.persistentStorage.get(PERSISTENT_STORAGE_KEY); | ||
if (loadedData && typeof loadedData == "object") { | ||
if ("ipv4" in loadedData && typeof loadedData.ipv4 == "string") { | ||
this.#serverData.ipv4 = loadedData.ipv4; | ||
} | ||
if ("ipv6" in loadedData && typeof loadedData.ipv6 == "string") { | ||
this.#serverData.ipv6 = loadedData.ipv6; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {LegacyServerData} data | ||
*/ | ||
setServerData(data) { | ||
this.#serverData = data; | ||
this.#mainInstance.websocketManager.sendAllLegacyServerData(data); | ||
this.#mainInstance.persistentStorage.set(PERSISTENT_STORAGE_KEY, data); | ||
} | ||
|
||
getServerData() { | ||
return { | ||
...this.#serverData, | ||
}; | ||
} | ||
|
||
getServersJson() { | ||
return { | ||
retentionSamples: [], | ||
teamServers: [], | ||
mobileAdData: { | ||
videoInterstitialRate: -1, | ||
limitFrequencySeconds: 300, | ||
disabledNetworks: "", | ||
promoBannerUrls: [ | ||
"ducklings", | ||
], | ||
doBanner: true, | ||
promoBannerUrl: "https://splix.io/banners/ducklings/index.html", | ||
showPromoForPatreonUsers: true, | ||
}, | ||
locations: [ | ||
{ | ||
pingIpv4: "splix.io", | ||
loc: "nyc", | ||
gamemodes: [ | ||
{ | ||
gm: "default", | ||
versions: [ | ||
{ | ||
lobbies: [ | ||
{ | ||
securePort: 443, | ||
ipv6: this.#serverData.ipv6, | ||
port: 80, | ||
hash: "fish", | ||
ipv4: this.#serverData.ipv4, | ||
}, | ||
], | ||
ver: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
locId: 3, | ||
pingIpv6: "splix.io", | ||
}, | ||
], | ||
"requiredMobileVersion": 11, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters