diff --git a/DataTypes.cs b/DataTypes.cs index 89e917a..b60f5fa 100644 --- a/DataTypes.cs +++ b/DataTypes.cs @@ -562,8 +562,8 @@ public override void bind() if(vtype.GetType ().BaseType.ToString() == "KBEngine.KBEDATATYPE_BASE") ((KBEDATATYPE_BASE)vtype).bind(); else - if(EntityDef.iddatatypes.ContainsKey((UInt16)vtype)) - vtype = EntityDef.iddatatypes[(UInt16)vtype]; + if(EntityDef.id2datatypes.ContainsKey((UInt16)vtype)) + vtype = EntityDef.id2datatypes[(UInt16)vtype]; } public override object createFromStream(MemoryStream stream) @@ -637,8 +637,8 @@ public override void bind() if(type.GetType ().BaseType.ToString() == "KBEngine.KBEDATATYPE_BASE") ((KBEDATATYPE_BASE)type).bind(); else - if(EntityDef.iddatatypes.ContainsKey((UInt16)type)) - dicttype[itemkey] = EntityDef.iddatatypes[(UInt16)type]; + if(EntityDef.id2datatypes.ContainsKey((UInt16)type)) + dicttype[itemkey] = EntityDef.id2datatypes[(UInt16)type]; } } diff --git a/EntityDef.cs b/EntityDef.cs index 515ff73..11088ee 100644 --- a/EntityDef.cs +++ b/EntityDef.cs @@ -11,10 +11,10 @@ */ public class EntityDef { + // 所有的数据类型 public static Dictionary datatype2id = new Dictionary(); - public static Dictionary datatypes = new Dictionary(); - public static Dictionary iddatatypes = new Dictionary(); + public static Dictionary id2datatypes = new Dictionary(); public static Dictionary entityclass = new Dictionary(); @@ -25,7 +25,7 @@ public static void clear() { datatype2id.Clear(); datatypes.Clear(); - iddatatypes.Clear(); + id2datatypes.Clear(); entityclass.Clear(); moduledefs.Clear(); idmoduledefs.Clear(); @@ -73,7 +73,7 @@ public static void bindMessageDataType() datatype2id["STRING"] = 1; datatype2id["STD::STRING"] = 1; - iddatatypes[1] = datatypes["STRING"]; + id2datatypes[1] = datatypes["STRING"]; datatype2id["UINT8"] = 2; datatype2id["BOOL"] = 2; @@ -82,7 +82,7 @@ public static void bindMessageDataType() datatype2id["DETAIL_TYPE"] = 2; datatype2id["MAIL_TYPE"] = 2; - iddatatypes[2] = datatypes["UINT8"]; + id2datatypes[2] = datatypes["UINT8"]; datatype2id["UINT16"] = 3; datatype2id["UNSIGNED SHORT"] = 3; @@ -93,7 +93,7 @@ public static void bindMessageDataType() datatype2id["ENTITY_SCRIPT_UID"] = 3; datatype2id["DATATYPE_UID"] = 3; - iddatatypes[3] = datatypes["UINT16"]; + id2datatypes[3] = datatypes["UINT16"]; datatype2id["UINT32"] = 4; datatype2id["UINT"] = 4; @@ -103,23 +103,23 @@ public static void bindMessageDataType() datatype2id["GAME_TIME"] = 4; datatype2id["TIMER_ID"] = 4; - iddatatypes[4] = datatypes["UINT32"]; + id2datatypes[4] = datatypes["UINT32"]; datatype2id["UINT64"] = 5; datatype2id["DBID"] = 5; datatype2id["COMPONENT_ID"] = 5; - iddatatypes[5] = datatypes["UINT64"]; + id2datatypes[5] = datatypes["UINT64"]; datatype2id["INT8"] = 6; datatype2id["COMPONENT_ORDER"] = 6; - iddatatypes[6] = datatypes["INT8"]; + id2datatypes[6] = datatypes["INT8"]; datatype2id["INT16"] = 7; datatype2id["SHORT"] = 7; - iddatatypes[7] = datatypes["INT16"]; + id2datatypes[7] = datatypes["INT16"]; datatype2id["INT32"] = 8; datatype2id["INT"] = 8; @@ -127,11 +127,11 @@ public static void bindMessageDataType() datatype2id["CALLBACK_ID"] = 8; datatype2id["COMPONENT_TYPE"] = 8; - iddatatypes[8] = datatypes["INT32"]; + id2datatypes[8] = datatypes["INT32"]; datatype2id["INT64"] = 9; - iddatatypes[9] = datatypes["INT64"]; + id2datatypes[9] = datatypes["INT64"]; datatype2id["PYTHON"] = 10; datatype2id["PY_DICT"] = 10; @@ -139,43 +139,43 @@ public static void bindMessageDataType() datatype2id["PY_LIST"] = 10; datatype2id["MAILBOX"] = 10; - iddatatypes[10] = datatypes["PYTHON"]; + id2datatypes[10] = datatypes["PYTHON"]; datatype2id["BLOB"] = 11; - iddatatypes[11] = datatypes["BLOB"]; + id2datatypes[11] = datatypes["BLOB"]; datatype2id["UNICODE"] = 12; - iddatatypes[12] = datatypes["UNICODE"]; + id2datatypes[12] = datatypes["UNICODE"]; datatype2id["FLOAT"] = 13; - iddatatypes[13] = datatypes["FLOAT"]; + id2datatypes[13] = datatypes["FLOAT"]; datatype2id["DOUBLE"] = 14; - iddatatypes[14] = datatypes["DOUBLE"]; + id2datatypes[14] = datatypes["DOUBLE"]; datatype2id["VECTOR2"] = 15; - iddatatypes[15] = datatypes["VECTOR2"]; + id2datatypes[15] = datatypes["VECTOR2"]; datatype2id["VECTOR3"] = 16; - iddatatypes[16] = datatypes["VECTOR3"]; + id2datatypes[16] = datatypes["VECTOR3"]; datatype2id["VECTOR4"] = 17; - iddatatypes[17] = datatypes["VECTOR4"]; + id2datatypes[17] = datatypes["VECTOR4"]; datatype2id["FIXED_DICT"] = 18; // 这里不需要绑定,FIXED_DICT需要根据不同类型实例化动态得到id - //iddatatypes[18] = datatypes["FIXED_DICT"]; + //id2datatypes[18] = datatypes["FIXED_DICT"]; datatype2id["ARRAY"] = 19; // 这里不需要绑定,ARRAY需要根据不同类型实例化动态得到id - //iddatatypes[19] = datatypes["ARRAY"]; + //id2datatypes[19] = datatypes["ARRAY"]; } } diff --git a/KBEngine.cs b/KBEngine.cs index 98e5d3f..8ce6798 100644 --- a/KBEngine.cs +++ b/KBEngine.cs @@ -709,16 +709,36 @@ private void onImportClientMessagesCompleted() /* 从二进制流创建entitydef支持的数据类型 */ + public void createDataTypeFromStreams(MemoryStream stream, bool canprint) + { + UInt16 aliassize = stream.readUint16(); + Dbg.DEBUG_MSG("KBEngine::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!"); + + while(aliassize > 0) + { + aliassize--; + createDataTypeFromStream(stream, canprint); + }; + + foreach(string datatype in EntityDef.datatypes.Keys) + { + if(EntityDef.datatypes[datatype] != null) + { + EntityDef.datatypes[datatype].bind(); + } + } + } + public void createDataTypeFromStream(MemoryStream stream, bool canprint) { UInt16 utype = stream.readUint16(); string name = stream.readString(); string valname = stream.readString(); - //if(canprint) - // Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!"); + if(canprint) + Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ":" + utype + ")!"); - if(valname == "FIXED_DICT") + if(name == "FIXED_DICT") { KBEDATATYPE_FIXED_DICT datatype = new KBEDATATYPE_FIXED_DICT(); Byte keysize = stream.readUint8(); @@ -733,24 +753,26 @@ public void createDataTypeFromStream(MemoryStream stream, bool canprint) datatype.dicttype[keyname] = keyutype; }; - EntityDef.datatypes[name] = datatype; + EntityDef.datatypes[valname] = datatype; } - else if(valname == "ARRAY") + else if(name == "ARRAY") { UInt16 uitemtype = stream.readUint16(); KBEDATATYPE_ARRAY datatype = new KBEDATATYPE_ARRAY(); datatype.vtype = uitemtype; - EntityDef.datatypes[name] = datatype; + EntityDef.datatypes[valname] = datatype; } else { KBEDATATYPE_BASE val = null; - EntityDef.datatypes.TryGetValue(valname, out val); - EntityDef.datatypes[name] = val; + EntityDef.datatypes.TryGetValue(name, out val); + EntityDef.datatypes[valname] = val; } - EntityDef.iddatatypes[utype] = EntityDef.datatypes[name]; - EntityDef.datatype2id[name] = EntityDef.datatype2id[valname]; + EntityDef.id2datatypes[utype] = EntityDef.datatypes[valname]; + + // 将用户自定义的类型补充到映射表中 + EntityDef.datatype2id[valname] = utype; } public void Client_onImportClientEntityDef(MemoryStream stream) @@ -766,22 +788,8 @@ public void Client_onImportClientEntityDef(MemoryStream stream) public void onImportClientEntityDef(MemoryStream stream) { - UInt16 aliassize = stream.readUint16(); - Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(size=" + aliassize + ")!"); - - while(aliassize > 0) - { - aliassize--; - createDataTypeFromStream(stream, true); - }; - - foreach(string datatype in EntityDef.datatypes.Keys) - { - if(EntityDef.datatypes[datatype] != null) - { - EntityDef.datatypes[datatype].bind(); - } - } + createDataTypeFromStreams(stream, true); + while(stream.length() > 0) { @@ -811,7 +819,7 @@ public void onImportClientEntityDef(MemoryStream stream) Int16 ialiasID = stream.readInt16(); string name = stream.readString(); string defaultValStr = stream.readString(); - KBEDATATYPE_BASE utype = EntityDef.iddatatypes[stream.readUint16()]; + KBEDATATYPE_BASE utype = EntityDef.id2datatypes[stream.readUint16()]; System.Reflection.MethodInfo setmethod = null; @@ -868,7 +876,7 @@ public void onImportClientEntityDef(MemoryStream stream) while(argssize > 0) { argssize--; - args.Add(EntityDef.iddatatypes[stream.readUint16()]); + args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); @@ -918,7 +926,7 @@ public void onImportClientEntityDef(MemoryStream stream) while(argssize > 0) { argssize--; - args.Add(EntityDef.iddatatypes[stream.readUint16()]); + args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); @@ -946,7 +954,7 @@ public void onImportClientEntityDef(MemoryStream stream) while(argssize > 0) { argssize--; - args.Add(EntityDef.iddatatypes[stream.readUint16()]); + args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); diff --git a/Message.cs b/Message.cs index c85e92a..9a7c0ac 100644 --- a/Message.cs +++ b/Message.cs @@ -80,7 +80,7 @@ public Message(MessageID msgid, string msgname, Int16 length, sbyte argstype, Li argtypes = new KBEDATATYPE_BASE[msgargtypes.Count]; for(int i=0; i