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",
"5": "PlayerGetTokenCsReq",
"48": "PlayerGetTokenScRsp",
"22": "PlayerKeepAliveNotify"
"DebugNotify": "101",
"PlayerGetTokenCsReq": "5",
"PlayerGetTokenScRsp": "48",
"PlayerKeepAliveNotify": "22"
}

View File

@ -2,16 +2,21 @@ import Logger, { VerboseLevel } from "../../util/Logger";
import protobuf from 'protobufjs';
import { resolve } from 'path';
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;
})();
const c = new Logger("Packet")
export default class Packet {