Skip to content

Commit

Permalink
修正服务端alias类型超过127时客户端插件导入协议时产生错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kbengine committed Sep 11, 2015
1 parent 7dc2180 commit 9876289
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 57 deletions.
8 changes: 4 additions & 4 deletions DataTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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];
}
}

Expand Down
44 changes: 22 additions & 22 deletions EntityDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/
public class EntityDef
{
// 所有的数据类型
public static Dictionary<string, Int32> datatype2id = new Dictionary<string, Int32>();

public static Dictionary<string, KBEDATATYPE_BASE> datatypes = new Dictionary<string, KBEDATATYPE_BASE>();
public static Dictionary<UInt16, KBEDATATYPE_BASE> iddatatypes = new Dictionary<UInt16, KBEDATATYPE_BASE>();
public static Dictionary<UInt16, KBEDATATYPE_BASE> id2datatypes = new Dictionary<UInt16, KBEDATATYPE_BASE>();

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

Expand All @@ -25,7 +25,7 @@ public static void clear()
{
datatype2id.Clear();
datatypes.Clear();
iddatatypes.Clear();
id2datatypes.Clear();
entityclass.Clear();
moduledefs.Clear();
idmoduledefs.Clear();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -103,79 +103,79 @@ 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;
datatype2id["ENTITY_ID"] = 8;
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;
datatype2id["PY_TUPLE"] = 10;
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"];
}
}

Expand Down
68 changes: 38 additions & 30 deletions KBEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<msgargtypes.Count; i++)
{
if(!EntityDef.iddatatypes.TryGetValue(msgargtypes[i], out argtypes[i]))
if(!EntityDef.id2datatypes.TryGetValue(msgargtypes[i], out argtypes[i]))
{
Dbg.ERROR_MSG("Message::Message(): argtype(" + msgargtypes[i] + ") is not found!");
}
Expand Down

0 comments on commit 9876289

Please sign in to comment.