Skip to content

Commit

Permalink
Remove configuration setting for connecting test client to main server
Browse files Browse the repository at this point in the history
Only allow configuring through query string.
  • Loading branch information
AntumDeluge committed Dec 16, 2023
1 parent b0913ff commit 7bc2fb7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
4 changes: 0 additions & 4 deletions srcjs/stendhal.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ <h3></h3>
<label class="checksetting"><input type="checkbox" id="chk_pvtsnd">Private message notifications</label>
</div>
<div id="settings_panel3" class="verticalgroup vgroupcolr">
<div class="hidden">
<label for="selserver">Server:</label>
<select id="selserver"></select>
</div>
<div>
<label for="selecttheme">Theme:</label>
<select id="selecttheme"></select>
Expand Down
2 changes: 1 addition & 1 deletion srcjs/stendhal/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class Client {
this.registerBrowserEventHandlers();

let ws = Paths.ws.substring(1);
if (stendhal.session.isTestClient() && !stendhal.config.getBoolean("connection.testserver")) {
if (stendhal.session.isTestClient() && !stendhal.session.isServerDefault()) {
ws = ws.replace(/t/, "s");
// disclaimer for using the test client on the main server
Chat.log("warning", "WARNING: You are connecting to the production server with a development"
Expand Down
13 changes: 0 additions & 13 deletions srcjs/stendhal/ui/dialog/SettingsDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export class SettingsDialog extends DialogContentComponent {

this.initialStates = {
"gamescreen.blood": stendhal.config.get("gamescreen.blood"),
"connection.testserver": stendhal.config.get("connection.testserver")
};


Expand Down Expand Up @@ -130,18 +129,6 @@ export class SettingsDialog extends DialogContentComponent {

/* *** right panel *** */

const sel_server = this.createSelect("selserver", {"test": "test", "main": "main"},
stendhal.config.getBoolean("connection.testserver") ? 0 : 1,
"Select \"main\" to connect to main server with test client (requires page reload)");
sel_server.addEventListener("change", (e) => {
stendhal.config.set("connection.testserver", sel_server.selectedIndex == 0);
this.refresh();
});
// server selection is hidden unless test client is detected
if (stendhal.session.isTestClient()) {
sel_server.parentElement!.style["display"] = "block";
}

const themes = {} as {[index: string]: string};
for (const t of Object.keys(stendhal.config.themes.map)) {
if (t === "wood") {
Expand Down
2 changes: 0 additions & 2 deletions srcjs/stendhal/util/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export class ConfigManager {
"action.inventory.quickpickup": "true",
"event.pvtmsg.sound": "ui/notify_up",
"chat.custom_keywords": "",
// test client only
"connection.testserver": "true"
} as {[id: string]: string};

private themes = {
Expand Down
22 changes: 17 additions & 5 deletions srcjs/stendhal/util/SessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SessionManager {
private storage = window.sessionStorage;
private charname?: string;
private initialized = false;
private server_default = true;

/** Singleton instance. */
private static instance: SessionManager;
Expand Down Expand Up @@ -50,12 +51,10 @@ export class SessionManager {
if (charname) {
this.setCharName(charname);
}
// server selection (test client only)
// server selection from query string (test client only)
const server = args.get("server");
if (server) {
// TODO: Don't store connection & remove option from settings dialog. Note that Android
// WebView client will need updated to set server connection in query string.
stendhal.config.set("connection.testserver", server !== "main");
if (server && this.isTestClient()) {
this.server_default = server !== "main";
}
}

Expand Down Expand Up @@ -113,4 +112,17 @@ export class SessionManager {
isTestClient(): boolean {
return stendhal.paths.data === "/testdata";
}

/**
* Checks if the client should connect to its default server counterpart.
*
* Used for test client only.
*
* @return
* `true` is test client should connect to test server. `false` if it should connect to main
* server.
*/
isServerDefault(): boolean {
return this.server_default;
}
}

0 comments on commit 7bc2fb7

Please sign in to comment.