better typed packetIds

This commit is contained in:
TheLostTree 2022-07-28 18:40:59 -07:00
parent 5af80ad18f
commit c422bf2fe9
2 changed files with 14 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"101": "DebugNotify", "DebugNotify": "101",
"5": "PlayerGetTokenCsReq", "PlayerGetTokenCsReq": "5",
"48": "PlayerGetTokenScRsp", "PlayerGetTokenScRsp": "48",
"22": "PlayerKeepAliveNotify" "PlayerKeepAliveNotify": "22"
} }

View File

@ -2,16 +2,21 @@ import Logger, { VerboseLevel } from "../../util/Logger";
import protobuf from 'protobufjs'; import protobuf from 'protobufjs';
import { resolve } from 'path'; import { resolve } from 'path';
import _packetIds from '../../data/packetIds.json'; import _packetIds from '../../data/packetIds.json';
const packetIds = _packetIds as { [key: string]: string };
const switchedPacketIds: { [key: string]: number } = (function () {
const obj: { [key: string]: number } = {};
Object.keys(packetIds).forEach((key) => {
obj[packetIds[key]] = Number(key); 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 } = {};
Object.keys(switchedPacketIds).forEach((key) => {
obj[switchedPacketIds[key as PacketTypes]] = key as PacketTypes;
}); });
return obj; return obj;
})(); })();
const c = new Logger("Packet") const c = new Logger("Packet")
export default class Packet { export default class Packet {