Skip to content

Commit 9876289

Browse files
committed
修正服务端alias类型超过127时客户端插件导入协议时产生错误问题
1 parent 7dc2180 commit 9876289

File tree

4 files changed

+65
-57
lines changed

4 files changed

+65
-57
lines changed

DataTypes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ public override void bind()
562562
if(vtype.GetType ().BaseType.ToString() == "KBEngine.KBEDATATYPE_BASE")
563563
((KBEDATATYPE_BASE)vtype).bind();
564564
else
565-
if(EntityDef.iddatatypes.ContainsKey((UInt16)vtype))
566-
vtype = EntityDef.iddatatypes[(UInt16)vtype];
565+
if(EntityDef.id2datatypes.ContainsKey((UInt16)vtype))
566+
vtype = EntityDef.id2datatypes[(UInt16)vtype];
567567
}
568568

569569
public override object createFromStream(MemoryStream stream)
@@ -637,8 +637,8 @@ public override void bind()
637637
if(type.GetType ().BaseType.ToString() == "KBEngine.KBEDATATYPE_BASE")
638638
((KBEDATATYPE_BASE)type).bind();
639639
else
640-
if(EntityDef.iddatatypes.ContainsKey((UInt16)type))
641-
dicttype[itemkey] = EntityDef.iddatatypes[(UInt16)type];
640+
if(EntityDef.id2datatypes.ContainsKey((UInt16)type))
641+
dicttype[itemkey] = EntityDef.id2datatypes[(UInt16)type];
642642
}
643643
}
644644

EntityDef.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
*/
1212
public class EntityDef
1313
{
14+
// 所有的数据类型
1415
public static Dictionary<string, Int32> datatype2id = new Dictionary<string, Int32>();
15-
1616
public static Dictionary<string, KBEDATATYPE_BASE> datatypes = new Dictionary<string, KBEDATATYPE_BASE>();
17-
public static Dictionary<UInt16, KBEDATATYPE_BASE> iddatatypes = new Dictionary<UInt16, KBEDATATYPE_BASE>();
17+
public static Dictionary<UInt16, KBEDATATYPE_BASE> id2datatypes = new Dictionary<UInt16, KBEDATATYPE_BASE>();
1818

1919
public static Dictionary<string, Int32> entityclass = new Dictionary<string, Int32>();
2020

@@ -25,7 +25,7 @@ public static void clear()
2525
{
2626
datatype2id.Clear();
2727
datatypes.Clear();
28-
iddatatypes.Clear();
28+
id2datatypes.Clear();
2929
entityclass.Clear();
3030
moduledefs.Clear();
3131
idmoduledefs.Clear();
@@ -73,7 +73,7 @@ public static void bindMessageDataType()
7373
datatype2id["STRING"] = 1;
7474
datatype2id["STD::STRING"] = 1;
7575

76-
iddatatypes[1] = datatypes["STRING"];
76+
id2datatypes[1] = datatypes["STRING"];
7777

7878
datatype2id["UINT8"] = 2;
7979
datatype2id["BOOL"] = 2;
@@ -82,7 +82,7 @@ public static void bindMessageDataType()
8282
datatype2id["DETAIL_TYPE"] = 2;
8383
datatype2id["MAIL_TYPE"] = 2;
8484

85-
iddatatypes[2] = datatypes["UINT8"];
85+
id2datatypes[2] = datatypes["UINT8"];
8686

8787
datatype2id["UINT16"] = 3;
8888
datatype2id["UNSIGNED SHORT"] = 3;
@@ -93,7 +93,7 @@ public static void bindMessageDataType()
9393
datatype2id["ENTITY_SCRIPT_UID"] = 3;
9494
datatype2id["DATATYPE_UID"] = 3;
9595

96-
iddatatypes[3] = datatypes["UINT16"];
96+
id2datatypes[3] = datatypes["UINT16"];
9797

9898
datatype2id["UINT32"] = 4;
9999
datatype2id["UINT"] = 4;
@@ -103,79 +103,79 @@ public static void bindMessageDataType()
103103
datatype2id["GAME_TIME"] = 4;
104104
datatype2id["TIMER_ID"] = 4;
105105

106-
iddatatypes[4] = datatypes["UINT32"];
106+
id2datatypes[4] = datatypes["UINT32"];
107107

108108
datatype2id["UINT64"] = 5;
109109
datatype2id["DBID"] = 5;
110110
datatype2id["COMPONENT_ID"] = 5;
111111

112-
iddatatypes[5] = datatypes["UINT64"];
112+
id2datatypes[5] = datatypes["UINT64"];
113113

114114
datatype2id["INT8"] = 6;
115115
datatype2id["COMPONENT_ORDER"] = 6;
116116

117-
iddatatypes[6] = datatypes["INT8"];
117+
id2datatypes[6] = datatypes["INT8"];
118118

119119
datatype2id["INT16"] = 7;
120120
datatype2id["SHORT"] = 7;
121121

122-
iddatatypes[7] = datatypes["INT16"];
122+
id2datatypes[7] = datatypes["INT16"];
123123

124124
datatype2id["INT32"] = 8;
125125
datatype2id["INT"] = 8;
126126
datatype2id["ENTITY_ID"] = 8;
127127
datatype2id["CALLBACK_ID"] = 8;
128128
datatype2id["COMPONENT_TYPE"] = 8;
129129

130-
iddatatypes[8] = datatypes["INT32"];
130+
id2datatypes[8] = datatypes["INT32"];
131131

132132
datatype2id["INT64"] = 9;
133133

134-
iddatatypes[9] = datatypes["INT64"];
134+
id2datatypes[9] = datatypes["INT64"];
135135

136136
datatype2id["PYTHON"] = 10;
137137
datatype2id["PY_DICT"] = 10;
138138
datatype2id["PY_TUPLE"] = 10;
139139
datatype2id["PY_LIST"] = 10;
140140
datatype2id["MAILBOX"] = 10;
141141

142-
iddatatypes[10] = datatypes["PYTHON"];
142+
id2datatypes[10] = datatypes["PYTHON"];
143143

144144
datatype2id["BLOB"] = 11;
145145

146-
iddatatypes[11] = datatypes["BLOB"];
146+
id2datatypes[11] = datatypes["BLOB"];
147147

148148
datatype2id["UNICODE"] = 12;
149149

150-
iddatatypes[12] = datatypes["UNICODE"];
150+
id2datatypes[12] = datatypes["UNICODE"];
151151

152152
datatype2id["FLOAT"] = 13;
153153

154-
iddatatypes[13] = datatypes["FLOAT"];
154+
id2datatypes[13] = datatypes["FLOAT"];
155155

156156
datatype2id["DOUBLE"] = 14;
157157

158-
iddatatypes[14] = datatypes["DOUBLE"];
158+
id2datatypes[14] = datatypes["DOUBLE"];
159159

160160
datatype2id["VECTOR2"] = 15;
161161

162-
iddatatypes[15] = datatypes["VECTOR2"];
162+
id2datatypes[15] = datatypes["VECTOR2"];
163163

164164
datatype2id["VECTOR3"] = 16;
165165

166-
iddatatypes[16] = datatypes["VECTOR3"];
166+
id2datatypes[16] = datatypes["VECTOR3"];
167167

168168
datatype2id["VECTOR4"] = 17;
169169

170-
iddatatypes[17] = datatypes["VECTOR4"];
170+
id2datatypes[17] = datatypes["VECTOR4"];
171171

172172
datatype2id["FIXED_DICT"] = 18;
173173
// 这里不需要绑定,FIXED_DICT需要根据不同类型实例化动态得到id
174-
//iddatatypes[18] = datatypes["FIXED_DICT"];
174+
//id2datatypes[18] = datatypes["FIXED_DICT"];
175175

176176
datatype2id["ARRAY"] = 19;
177177
// 这里不需要绑定,ARRAY需要根据不同类型实例化动态得到id
178-
//iddatatypes[19] = datatypes["ARRAY"];
178+
//id2datatypes[19] = datatypes["ARRAY"];
179179
}
180180
}
181181

KBEngine.cs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -709,16 +709,36 @@ private void onImportClientMessagesCompleted()
709709
/*
710710
从二进制流创建entitydef支持的数据类型
711711
*/
712+
public void createDataTypeFromStreams(MemoryStream stream, bool canprint)
713+
{
714+
UInt16 aliassize = stream.readUint16();
715+
Dbg.DEBUG_MSG("KBEngine::createDataTypeFromStreams: importAlias(size=" + aliassize + ")!");
716+
717+
while(aliassize > 0)
718+
{
719+
aliassize--;
720+
createDataTypeFromStream(stream, canprint);
721+
};
722+
723+
foreach(string datatype in EntityDef.datatypes.Keys)
724+
{
725+
if(EntityDef.datatypes[datatype] != null)
726+
{
727+
EntityDef.datatypes[datatype].bind();
728+
}
729+
}
730+
}
731+
712732
public void createDataTypeFromStream(MemoryStream stream, bool canprint)
713733
{
714734
UInt16 utype = stream.readUint16();
715735
string name = stream.readString();
716736
string valname = stream.readString();
717737

718-
//if(canprint)
719-
// Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ")!");
738+
if(canprint)
739+
Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ":" + utype + ")!");
720740

721-
if(valname == "FIXED_DICT")
741+
if(name == "FIXED_DICT")
722742
{
723743
KBEDATATYPE_FIXED_DICT datatype = new KBEDATATYPE_FIXED_DICT();
724744
Byte keysize = stream.readUint8();
@@ -733,24 +753,26 @@ public void createDataTypeFromStream(MemoryStream stream, bool canprint)
733753
datatype.dicttype[keyname] = keyutype;
734754
};
735755

736-
EntityDef.datatypes[name] = datatype;
756+
EntityDef.datatypes[valname] = datatype;
737757
}
738-
else if(valname == "ARRAY")
758+
else if(name == "ARRAY")
739759
{
740760
UInt16 uitemtype = stream.readUint16();
741761
KBEDATATYPE_ARRAY datatype = new KBEDATATYPE_ARRAY();
742762
datatype.vtype = uitemtype;
743-
EntityDef.datatypes[name] = datatype;
763+
EntityDef.datatypes[valname] = datatype;
744764
}
745765
else
746766
{
747767
KBEDATATYPE_BASE val = null;
748-
EntityDef.datatypes.TryGetValue(valname, out val);
749-
EntityDef.datatypes[name] = val;
768+
EntityDef.datatypes.TryGetValue(name, out val);
769+
EntityDef.datatypes[valname] = val;
750770
}
751771

752-
EntityDef.iddatatypes[utype] = EntityDef.datatypes[name];
753-
EntityDef.datatype2id[name] = EntityDef.datatype2id[valname];
772+
EntityDef.id2datatypes[utype] = EntityDef.datatypes[valname];
773+
774+
// 将用户自定义的类型补充到映射表中
775+
EntityDef.datatype2id[valname] = utype;
754776
}
755777

756778
public void Client_onImportClientEntityDef(MemoryStream stream)
@@ -766,22 +788,8 @@ public void Client_onImportClientEntityDef(MemoryStream stream)
766788

767789
public void onImportClientEntityDef(MemoryStream stream)
768790
{
769-
UInt16 aliassize = stream.readUint16();
770-
Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(size=" + aliassize + ")!");
771-
772-
while(aliassize > 0)
773-
{
774-
aliassize--;
775-
createDataTypeFromStream(stream, true);
776-
};
777-
778-
foreach(string datatype in EntityDef.datatypes.Keys)
779-
{
780-
if(EntityDef.datatypes[datatype] != null)
781-
{
782-
EntityDef.datatypes[datatype].bind();
783-
}
784-
}
791+
createDataTypeFromStreams(stream, true);
792+
785793

786794
while(stream.length() > 0)
787795
{
@@ -811,7 +819,7 @@ public void onImportClientEntityDef(MemoryStream stream)
811819
Int16 ialiasID = stream.readInt16();
812820
string name = stream.readString();
813821
string defaultValStr = stream.readString();
814-
KBEDATATYPE_BASE utype = EntityDef.iddatatypes[stream.readUint16()];
822+
KBEDATATYPE_BASE utype = EntityDef.id2datatypes[stream.readUint16()];
815823

816824
System.Reflection.MethodInfo setmethod = null;
817825

@@ -868,7 +876,7 @@ public void onImportClientEntityDef(MemoryStream stream)
868876
while(argssize > 0)
869877
{
870878
argssize--;
871-
args.Add(EntityDef.iddatatypes[stream.readUint16()]);
879+
args.Add(EntityDef.id2datatypes[stream.readUint16()]);
872880
};
873881

874882
Method savedata = new Method();
@@ -918,7 +926,7 @@ public void onImportClientEntityDef(MemoryStream stream)
918926
while(argssize > 0)
919927
{
920928
argssize--;
921-
args.Add(EntityDef.iddatatypes[stream.readUint16()]);
929+
args.Add(EntityDef.id2datatypes[stream.readUint16()]);
922930
};
923931

924932
Method savedata = new Method();
@@ -946,7 +954,7 @@ public void onImportClientEntityDef(MemoryStream stream)
946954
while(argssize > 0)
947955
{
948956
argssize--;
949-
args.Add(EntityDef.iddatatypes[stream.readUint16()]);
957+
args.Add(EntityDef.id2datatypes[stream.readUint16()]);
950958
};
951959

952960
Method savedata = new Method();

Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Message(MessageID msgid, string msgname, Int16 length, sbyte argstype, Li
8080
argtypes = new KBEDATATYPE_BASE[msgargtypes.Count];
8181
for(int i=0; i<msgargtypes.Count; i++)
8282
{
83-
if(!EntityDef.iddatatypes.TryGetValue(msgargtypes[i], out argtypes[i]))
83+
if(!EntityDef.id2datatypes.TryGetValue(msgargtypes[i], out argtypes[i]))
8484
{
8585
Dbg.ERROR_MSG("Message::Message(): argtype(" + msgargtypes[i] + ") is not found!");
8686
}

0 commit comments

Comments
 (0)