From 590236cbfab496680d6e0270a4f118a725e36e0f Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Fri, 5 Aug 2022 07:54:05 +0200 Subject: [PATCH] Implement /ban command --- src/commands/ban.ts | 17 +++++++++++++++++ src/server/kcp/Session.ts | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/commands/ban.ts diff --git a/src/commands/ban.ts b/src/commands/ban.ts new file mode 100644 index 0000000..ff89115 --- /dev/null +++ b/src/commands/ban.ts @@ -0,0 +1,17 @@ +import Logger from "../util/Logger"; +import Interface, { Command } from "./Interface"; +const c = new Logger("/ban", "blue"); + +export default async function handle(command: Command) { + if (!Interface.target) { + c.log("No target specified"); + return; + } + + const banStatus = Interface.target.player.db.banned; + Interface.target.player.db.banned = !banStatus; + Interface.target.player.save(); + Interface.target.kick(); + + c.log(`${banStatus ? "Banned" : "Unbanned"} ${Interface.target.account.name}`); +} \ No newline at end of file diff --git a/src/server/kcp/Session.ts b/src/server/kcp/Session.ts index 194f38f..f810f8d 100644 --- a/src/server/kcp/Session.ts +++ b/src/server/kcp/Session.ts @@ -96,13 +96,13 @@ export default class Session { //this.player.save(); } - public async send, >(type: Class, data: UnWrapMessageType) { + public async send,>(type: Class, data: UnWrapMessageType) { const typeName = ProtoFactory.getName(type); const encodedBuffer = type.encode(type.fromPartial(data)).finish(); const packet = Packet.fromEncodedBuffer(Buffer.from(encodedBuffer), typeName); this.c.verbL(data); this.c.verbH(encodedBuffer); - if(!encodedBuffer) console.log("sad!") + if (!encodedBuffer) this.c.error("encodedBuffer is undefined"); if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(typeName); //todo: might want to regen the ts-proto types with env = node this.kcpobj.send(packet); @@ -112,6 +112,7 @@ export default class Session { public kick(hard: boolean = true) { SRServer.getInstance().sessions.delete(this.id); this.kicked = true; + if (hard) this.send(PlayerKickOutScNotify, { kickType: PlayerKickOutScNotify_KickType.KICK_BLACK, blackInfo: {