Skip to content

Commit

Permalink
fix connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stonedDiscord committed Dec 24, 2024
1 parent 2c410fc commit 4676dd6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
19 changes: 12 additions & 7 deletions webAO/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ export const setExtraFeatures = (val: any) => {
extrafeatures = val;
};

export let banned: boolean = false;
export const setBanned = (val: boolean) => {
banned = val;
};

let hdid: string;

const fpPromise = FingerprintJS.load();
Expand Down Expand Up @@ -183,6 +180,7 @@ class Client extends EventEmitter {
}
};

this.banned = false;
this.hp = [0, 0];
this.playerID = 1;
this.charID = -1;
Expand Down Expand Up @@ -276,13 +274,20 @@ class Client extends EventEmitter {
onClose(e: CloseEvent) {
client.state = clientState.NotConnected;
console.error(`The connection was closed: ${e.reason} (${e.code})`);
if (extrafeatures.length == 0 && banned === false) {
console.log(this.areas.length);
console.log(this.banned);
if (this.banned === false) {
if (this.areas.length > 0) {
document.getElementById("client_errortext").textContent =
"Could not connect to the server";
"You were disconnected from the server.";
} else {
document.getElementById("client_errortext").textContent =
"Could not connect to the server.";
}
}
document.getElementById("client_waiting").style.display = "block";
document.getElementById("client_error").style.display = "flex";
document.getElementById("client_loading").style.display = "none";
document.getElementById("client_loading").style.display = "none";
document.getElementById("error_id").textContent = String(e.code);
this.cleanup();
}
Expand Down
4 changes: 2 additions & 2 deletions webAO/packets/handlers/handleBD.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setBanned } from "../../client";
import { client } from "../../client";
import { handleBans } from "../../client/handleBans";

/**
Expand All @@ -7,6 +7,6 @@ import { handleBans } from "../../client/handleBans";
* @param {Array} args ban reason
*/
export const handleBD = (args: string[]) => {
client.banned = true;
handleBans("Banned", args[1]);
setBanned(true);
};
4 changes: 2 additions & 2 deletions webAO/packets/handlers/handleKB.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setBanned } from "../../client";
import { client } from "../../client";
import { handleBans } from "../../client/handleBans";

/**
Expand All @@ -7,6 +7,6 @@ import { handleBans } from "../../client/handleBans";
* @param {Array} args ban reason
*/
export const handleKB = (args: string[]) => {
client.banned = true;
handleBans("Banned", args[1]);
setBanned(true);
};
5 changes: 3 additions & 2 deletions webAO/packets/handlers/handleKK.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { safeTags } from "../../encoding";
import { client } from "../../client";
import { handleBans } from "../../client/handleBans";

/**
* Handles the kicked packet
* @param {Array} args kick reason
*/
export const handleKK = (args: string[]) => {
handleBans("Kicked", safeTags(args[1]));
client.banned = true;
handleBans("Kicked", args[1]);
};

0 comments on commit 4676dd6

Please sign in to comment.