From be8200ebf3a9b11a9a716102cd9254360a1b3d45 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Wed, 3 Aug 2022 01:04:34 +0200 Subject: [PATCH] Add verbL and verbH levels to Logger --- src/server/kcp/Session.ts | 6 ++++-- src/util/Logger.ts | 14 ++++++++++++++ src/util/ProtoFactory.ts | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/server/kcp/Session.ts b/src/server/kcp/Session.ts index ab7fd8d..8306076 100644 --- a/src/server/kcp/Session.ts +++ b/src/server/kcp/Session.ts @@ -58,7 +58,8 @@ export default class Session { public async handlePacket(packet: Packet) { if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName) - this.c.debug(packet.body); + this.c.verbL(packet.body); + this.c.verbH(packet.rawData); import(`../packets/${packet.protoName}`).then(mod => { mod.default(this, packet); @@ -83,9 +84,10 @@ export default class Session { } public send(name: PacketName, body: {}) { - this.c.debug(body); + this.c.verbL(body); const packet = Packet.encode(name, body); if (!packet) return; + this.c.verbH(packet.rawData); if (Logger.VERBOSE_LEVEL >= VerboseLevel.WARNS) this.c.log(packet.protoName); this.kcpobj.send(packet.rawData); } diff --git a/src/util/Logger.ts b/src/util/Logger.ts index 78fe92f..a1a473e 100644 --- a/src/util/Logger.ts +++ b/src/util/Logger.ts @@ -5,6 +5,8 @@ export enum VerboseLevel { NONE = 0, // No logging except for errors WARNS = 1, // Log warns ALL = 2, // Warns and (useless) debug + VERBL = 3, // Warns, debug and verbose + VERBH = 4, // Warns, debug, verbose and very verbose (thanks copilot this is so funny) } type Color = 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | 'black' | 'italic' | 'bold' | 'underline' | 'strikethrough' | 'inverse' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgBlack' | 'bgGray' | 'bgItalic'; @@ -50,4 +52,16 @@ export default class Logger { console.log(`[${this.getDate().white.bold}] ${`DEBUG<${this.name}>`.bgBlue.bold}`, ...args); this.trail(new Error().stack!.split('\n').slice(2).join('\n')); } + + public verbL(...args: any) { + if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBL) return; + console.log(`[${this.getDate().white.bold}] ${`VERBL<${this.name}>`.bgCyan.bold}`, ...args); + this.trail(new Error().stack!.split('\n').slice(2).join('\n')); + } + + public verbH(...args: any) { + if (Logger.VERBOSE_LEVEL < VerboseLevel.VERBH) return; + console.log(`[${this.getDate().white.bold}] ${`VERBH<${this.name}>`.bgCyan.bold}`, ...args); + this.trail(new Error().stack!.split('\n').slice(2).join('\n')); + } } \ No newline at end of file diff --git a/src/util/ProtoFactory.ts b/src/util/ProtoFactory.ts index a2d63d7..ae56ae7 100644 --- a/src/util/ProtoFactory.ts +++ b/src/util/ProtoFactory.ts @@ -2,7 +2,7 @@ import * as types from "../data/proto/StarRail"; import protobufjs from "protobufjs"; import { CmdID, PacketName } from "../server/kcp/Packet" -import Logger from "./Logger"; +import Logger, { VerboseLevel } from "./Logger"; const c = new Logger("ProtoFactory"); class MessageType { @@ -56,7 +56,7 @@ export default class ProtoFactory { } } - c.debug(`Initialized with ${messageTypeMap.size} types`); + if (Logger.VERBOSE_LEVEL > VerboseLevel.ALL) c.log(`Initialized with ${messageTypeMap.size} types`); //c.log(this.getName(types.PlayerLoginScRsp)) return;