fixed bug that would cause the client to not disconnect if an error occurs whilst switching servers

This commit is contained in:
q13x 2023-07-05 11:09:30 -07:00
parent b348c2bef2
commit 3e6f59b9e0
6 changed files with 23 additions and 37 deletions

View File

@ -0,0 +1,4 @@
export const config = {
bindInternalServerPort: 25569,
bindInternalServerIp: "127.0.0.1",
};

View File

@ -1,4 +0,0 @@
export const config = {
bindInternalServerPort: 25569,
bindInternalServerIp: "127.0.0.1",
};

View File

@ -1,9 +1,7 @@
import metadata from "./metadata.json" assert { type: "json" };
import { createServer } from "minecraft-protocol";
import { config } from "./config.js";
const PluginManager = PLUGIN_MANAGER as any;
const PluginManager = PLUGIN_MANAGER;
const Logger = PluginManager.Logger;
const Enums = PluginManager.Enums;
const Chat = PluginManager.Chat;
@ -13,13 +11,9 @@ const Player = PluginManager.Player;
const MineProtocol = PluginManager.MineProtocol;
const EaglerSkins = PluginManager.EaglerSkins;
const Util = PluginManager.Util;
const logger = new Logger("AutoKicker");
logger.info(`Starting ${metadata.name} v${metadata.version}...`);
logger.info(
`(internal server port: ${config.bindInternalServerPort}, internal server IP: ${config.bindInternalServerPort})`
);
logger.info(`(internal server port: ${config.bindInternalServerPort}, internal server IP: ${config.bindInternalServerPort})`);
logger.info("Starting internal server...");
let server = createServer({
host: config.bindInternalServerIp,
@ -28,17 +22,13 @@ let server = createServer({
"online-mode": false,
version: "1.8.9",
});
server.on("login", (client) => {
logger.info(`Client ${client.username} has connected to the dummy server.`);
client.write("kick_disconnect", {
reason: "NO",
});
});
logger.info(
"Redirecting backend server IP... (this is required for the plugin to function)"
);
logger.info("Redirecting backend server IP... (this is required for the plugin to function)");
CONFIG.adapter.server = {
host: config.bindInternalServerIp,
port: config.bindInternalServerPort,

View File

@ -1,5 +0,0 @@
declare global {
var PLUGIN_MANAGER;
}
export {};

View File

@ -290,7 +290,7 @@ export class Player extends EventEmitter {
}, 30000);
client.on("error", errListener);
client.on("end", (reason) => {
if (!this._switchingServers) {
if (!this._switchingServers && !switchingServers) {
this.disconnect(this._kickMessage ?? reason);
}
this.ws.removeListener("message", listener);

View File

@ -6,8 +6,9 @@
"moduleResolution": "node",
"sourceMap": false,
"outDir": "build",
"resolveJsonModule": true
"resolveJsonModule": true,
"rootDir": "src"
},
"include": ["src/**/*.json", "src/**/*", "example_plugins/AutokickPlugin"],
"include": ["src/**/*.json", "src/**/*"],
"hooks": ["copy-files"]
}