From 400bb016b83d67b5d34dd2b7da2f606e8c7712ac Mon Sep 17 00:00:00 2001 From: TheLostTree <65834918+TheLostTree@users.noreply.github.com> Date: Thu, 28 Jul 2022 18:41:51 -0700 Subject: [PATCH] slight change to encode func --- src/server/kcp/Packet.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/server/kcp/Packet.ts b/src/server/kcp/Packet.ts index 8534d36..81f0fd1 100644 --- a/src/server/kcp/Packet.ts +++ b/src/server/kcp/Packet.ts @@ -4,13 +4,13 @@ import { resolve } from 'path'; import _packetIds from '../../data/packetIds.json'; -export type PacketTypes = keyof typeof _packetIds; -const switchedPacketIds = _packetIds as { [key in PacketTypes]: string }; -const packetIds: { [key: string]: PacketTypes } = (function () { - const obj: { [key: string]: PacketTypes } = {}; +export type PacketType = keyof typeof _packetIds; +const switchedPacketIds = _packetIds as { [key in PacketType]: string }; +const packetIds: { [key: string]: PacketType } = (function () { + const obj: { [key: string]: PacketType } = {}; Object.keys(switchedPacketIds).forEach((key) => { - obj[switchedPacketIds[key as PacketTypes]] = key as PacketTypes; + obj[switchedPacketIds[key as PacketType]] = key as PacketType; }); return obj; @@ -54,9 +54,9 @@ export default class Packet { return str.startsWith("01234567") && str.endsWith("89abcdef"); } - public static encode(name: string, body: {}, customCmdId?: number): Packet | null { + public static encode(name: PacketType, body: {}, customCmdId?: number): Packet | null { try { - const cmdid = switchedPacketIds[name]; + const cmdid = Number(switchedPacketIds[name]); const root = protobuf.loadSync(resolve(__dirname, `../../data/proto/${name}.proto`)); const Message = root.lookupTypeOrEnum(name);