package opcodes // Constants for opcode management const ( MAX_EQ_OPCODE = 0xFFFF APP_OPCODE_SIZE_1 = 1 APP_OPCODE_SIZE_2 = 2 ) // Opcode type definitions type ( ProtocolOpcode uint8 ServerOpcode uint16 AppOpcode uint16 EmuOpcode uint16 ) // Quick lookup maps for efficient opcode translation var ( ProtocolOpcodeNames = map[ProtocolOpcode]string{ OP_SessionRequest: "OP_SessionRequest", OP_SessionResponse: "OP_SessionResponse", OP_Combined: "OP_Combined", OP_SessionDisconnect: "OP_SessionDisconnect", OP_KeepAlive: "OP_KeepAlive", OP_ServerKeyRequest: "OP_ServerKeyRequest", OP_SessionStatResponse: "OP_SessionStatResponse", OP_Packet: "OP_Packet", OP_Fragment: "OP_Fragment", OP_OutOfOrderAck: "OP_OutOfOrderAck", OP_Ack: "OP_Ack", OP_AppCombined: "OP_AppCombined", OP_OutOfSession: "OP_OutOfSession", } ServerOpcodeNames = map[ServerOpcode]string{ ServerOP_KeepAlive: "ServerOP_KeepAlive", ServerOP_ChannelMessage: "ServerOP_ChannelMessage", ServerOP_SetZone: "ServerOP_SetZone", ServerOP_ShutdownAll: "ServerOP_ShutdownAll", // Add more as needed for performance-critical lookups } ) // Helper functions for efficient opcode operations func IsProtocolOpcode(op uint8) bool { _, exists := ProtocolOpcodeNames[ProtocolOpcode(op)] return exists } func IsServerOpcode(op uint16) bool { return op >= 0x0001 && op <= 0xFFFF } func GetProtocolOpcodeName(op ProtocolOpcode) string { if name, exists := ProtocolOpcodeNames[op]; exists { return name } return "OP_Unknown" } func GetServerOpcodeName(op ServerOpcode) string { if name, exists := ServerOpcodeNames[op]; exists { return name } return "ServerOP_Unknown" }