Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueBurger committed Aug 25, 2024
1 parent 4010e4d commit ac881a6
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.nio.file.Path;
import java.util.ArrayList;

@SuppressWarnings("unchecked")
public final class BurgerPanelIntegrator extends JavaPlugin {
static String burgerpanelID;
static String burgerpanelSocketPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.io.IOException;
import java.util.Collection;

public class StatusPacket extends Packet {
@SuppressWarnings("unchecked")
@Override
protected void execute(JSONObject data, String id) throws IOException {
JSONObject responseObj = new JSONObject();
Expand Down
1 change: 1 addition & 0 deletions Server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ _build
packets.mjs
*.log
test-context/
servers/
1 change: 1 addition & 0 deletions Server/kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ps aux | grep node | grep burgerpanel.mjs | awk "{print \$2}" | xargs kill -9
9 changes: 7 additions & 2 deletions Server/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export default new class Logger {
async setupWriteStream(location: string | null) {
if(!location) return;
if(process.env.SKIP_BURGERPANEL_LOGFILE) return;
this.writeStream = fs.createWriteStream(location);
try {
this.writeStream = fs.createWriteStream(location);
} catch(err) {
this.log("Cannot setup write stream to " + location, "error", LogLevel.ERROR, false, true);
return;
}
this.log("Logging to " + location, "info", LogLevel.DEBUG, false, false)
}
makeNiceDate(replaceColon: boolean = false) {
Expand Down Expand Up @@ -96,4 +101,4 @@ export default new class Logger {
});
return;
}
}
}
3 changes: 2 additions & 1 deletion Server/src/packets/integrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fs from "node:fs/promises";

import IntegratorInstall from "./integrator/IntegratorInstall.js"
import serverIntegrator from "../serverIntegrator.js";
import { exists } from "../util/exists.js";

export default class IntegratorPacket extends Packet {
name: Request = "integrator";
Expand All @@ -29,7 +30,7 @@ export default class IntegratorPacket extends Packet {
case "isInstalled":
return {
type: "isInstalled",
installed: (await fs.readdir(server.path + "/plugins/")).some(a => a.endsWith(".jar") && a.startsWith("BurgerPanelIntegrator-"))
installed: (await exists(server.path + "/plugins/")) && (await fs.readdir(server.path + "/plugins/")).some(a => a.endsWith(".jar") && a.startsWith("BurgerPanelIntegrator-"))
}
}
return;
Expand Down
2 changes: 2 additions & 0 deletions Server/src/packets/integrator/IntegratorInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import fs from "node:fs/promises";
import { buildInfo } from "../../../../Share/BuildInfo.js";
import { integratorJarPath } from "../../serverIntegrator.js";
import logger from "../../logger.js";
import { exists } from "../../util/exists.js";

export default async function install(server: Server, client: OurClient, data: any): Promise<{type: "install-success"}> {
logger.log(`${client.data.auth.user?.username} is installing the BurgerPanel integrator on server ${server.name}`, "server.integrator");
if(!(await exists(server.path + "/plugins/"))) await fs.mkdir(server.path + "/plugins/");
await fs.copyFile(integratorJarPath, server.path + `/plugins/BurgerPanelIntegrator-${buildInfo.version}.jar`);
return {
type: "install-success"
Expand Down
6 changes: 2 additions & 4 deletions Server/src/serverIntegrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export default new class ServerIntegrator {
if(Array.isArray(json)) return;
if(!["request", "response"].includes(json.dataType)) return;
if(json.dataType == "response") {
console.log(JSON.stringify(json, null, 2));
if(!c.burgerpanelData.server) return;
if(!this.requestCallbacks[c.burgerpanelData.server] || !this.requestCallbacks[c.burgerpanelData.server][json.id]) return;
this.requestCallbacks[c.burgerpanelData.server][json.id](json.data);
Expand Down Expand Up @@ -124,7 +123,7 @@ export default new class ServerIntegrator {
if(this.requestCallbacks[server._id][str]) continue;
return str;
}
throw new Error("somehow didnt find a id in 100 tries");
throw new Error("somehow didnt find a id in 100 tries... MILLIONS TO ONE");
}
request(server: Server, packet: string, data: any = {}, useCache: boolean = false): Promise<any> {
if(!this.isReadyForRequests(server)) throw new Error("Server isn't ready for requests!");
Expand All @@ -140,13 +139,12 @@ export default new class ServerIntegrator {
packet,
data
});
console.log("Sending", toSend);
client.write(toSend);
return new Promise((res, rej) => {
let timeout = setTimeout(() => {
delete this.requestCallbacks[server._id][id];
rej("Request timed out");
}, 10_000);
}, 30_000);
this.requestCallbacks[server._id][id] = (d) => {
delete this.requestCallbacks[server._id][id];
clearTimeout(timeout);
Expand Down
7 changes: 4 additions & 3 deletions Web/src/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ export const useUser = defineStore("user", () => {
if (testToken) {
try {
await loginToken(testToken);
failedLogin.value = true;
} catch {
failedLogin.value = true;
localStorage.removeItem("token");
return true;
return false;
}
return true;
} return false;
}
return false;
}
function resetUser() {
user.value = undefined;
Expand Down

0 comments on commit ac881a6

Please sign in to comment.