{"record":{"id":"bac2dde833640366","repo":"egametang/ET","slug":"opcodetype-not-found-type-opcode","errorCode":null,"errorMessage":"OpcodeType not found type: {opcode}","messagePattern":"OpcodeType not found type: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Network/OpcodeType.cs","lineNumber":74,"sourceCode":"            }\n        }\n        \n        public ushort GetOpcode(Type type)\n        {\n            ushort opcode = this.typeOpcode.GetValueByKey(type);\n            if (opcode == 0)\n            {\n                throw new Exception($\"OpcodeType not found opcode: {type.FullName}\");\n            }\n            return opcode;\n        }\n\n        public Type GetType(ushort opcode)\n        {\n            Type type = this.typeOpcode.GetKeyByValue(opcode);\n            if (type == null)\n            {\n                throw new Exception($\"OpcodeType not found type: {opcode}\");\n            }\n            return type;\n        }\n\n        public Type GetResponseType(Type request)\n        {\n            if (!this.requestResponse.TryGetValue(request, out Type response))\n            {\n                throw new Exception($\"not found response type, request type: {request.FullName}\");\n            }\n\n            return response;\n        }\n    }\n}\n","sourceCodeStart":56,"sourceCodeEnd":90,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Network/OpcodeType.cs#L56-L90","documentation":"OpcodeType.GetType(ushort) reverses the opcode->Type map and throws when the opcode is unknown. This fires during deserialization when a numeric opcode arrives that has no registered message type, typically a protocol/version mismatch.","triggerScenarios":"Receiving a packet whose opcode is not in the local table, e.g. client and server built from different protocol versions, or an opcode injected by a scanner.","commonSituations":"Client/server out of sync after a protocol change, an old client hitting a new server, or malicious/garbage traffic.","solutions":["Keep client and server protocol/opcode tables in sync (regenerate together).","Drop/log unknown opcodes at the dispatch boundary instead of letting GetType throw.","Verify protocol version on connect and reject mismatched peers."],"exampleFix":"// before\nType t = OpcodeType.Instance.GetType(opcode);\n// after\nType t = OpcodeType.Instance.TryGetType(opcode);\nif (t == null) { Log.Warning($\"unknown opcode {opcode}\"); return; }","handlingStrategy":"validation","validationCode":"if (!OpcodeType.Instance.TryGetType(opcode, out Type t)) { Log.Warning($\"unknown opcode {opcode}\"); return; }","typeGuard":"public bool TryGetType(ushort opcode, out Type t) { t = typeOpcode.GetKeyByValue(opcode); return t != null; }","tryCatchPattern":"null","preventionTips":["Keep client and server opcode tables generated from the same source.","Drop/log unknown opcodes at dispatch instead of throwing.","Version-check the protocol on connect."],"tags":["network","serialization","opcode","csharp"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}