static int readUint8(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); KBEngine.MemoryStream obj = (KBEngine.MemoryStream)ToLua.CheckObject <KBEngine.MemoryStream>(L, 1); byte o = obj.readUint8(); LuaDLL.lua_pushnumber(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
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(valname == "FIXED_DICT") { KBEDATATYPE_FIXED_DICT datatype = new KBEDATATYPE_FIXED_DICT(); Byte keysize = stream.readUint8(); datatype.implementedBy = stream.readString(); while(keysize > 0) { keysize--; string keyname = stream.readString(); UInt16 keyutype = stream.readUint16(); datatype.dicttype[keyname] = keyutype; }; EntityDef.datatypes[name] = datatype; } else if(valname == "ARRAY") { UInt16 uitemtype = stream.readUint16(); KBEDATATYPE_ARRAY datatype = new KBEDATATYPE_ARRAY(); datatype.type = uitemtype; EntityDef.datatypes[name] = datatype; } else { KBEDATATYPE_BASE val = null; EntityDef.datatypes.TryGetValue(valname, out val); EntityDef.datatypes[name] = val; } EntityDef.iddatatypes[utype] = EntityDef.datatypes[name]; EntityDef.datatype2id[name] = EntityDef.datatype2id[valname]; }
public void onRemoteMethodCall_(Int32 eid, MemoryStream stream) { Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { Dbg.ERROR_MSG("KBEngine::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } UInt16 methodUtype = 0; if(EntityDef.moduledefs[entity.classtype].useMethodDescrAlias) methodUtype = stream.readUint8(); else methodUtype = stream.readUint16(); Method methoddata = EntityDef.moduledefs[entity.classtype].idmethods[methodUtype]; Dbg.DEBUG_MSG("KBEngine::Client_onRemoteMethodCall: " + entity.classtype + "." + methoddata.name); object[] args = new object[methoddata.args.Count]; for(int i=0; i<methoddata.args.Count; i++) { args[i] = methoddata.args[i].createFromStream(stream); } methoddata.handler.Invoke(entity, args); }
public Int32 getAoiEntityIDFromStream(MemoryStream stream) { Int32 id = 0; if(entityIDAliasIDList.Count > 255) { id = stream.readInt32(); } else { byte aliasID = stream.readUint8(); id = entityIDAliasIDList[aliasID]; } return id; }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = 0; { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; if (_t_utype == 0) { prop = pdatas[_t_child_utype]; } else { Property pComponentPropertyDescription = pdatas[_t_utype]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (prop.properUtype) { case 40001: Vector3 oldval_direction = direction; direction = stream.readVector3(); if (prop.isBase()) { if (inited) { onDirectionChanged(oldval_direction); } } else { if (inWorld) { onDirectionChanged(oldval_direction); } } break; case 5: Byte oldval_level = level; level = stream.readUint8(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_level); } } else { if (inWorld) { onLevelChanged(oldval_level); } } break; case 4: Int32 oldval_mass = mass; mass = stream.readInt32(); if (prop.isBase()) { if (inited) { onMassChanged(oldval_mass); } } else { if (inWorld) { onMassChanged(oldval_mass); } } break; case 9: Byte oldval_modelID = modelID; modelID = stream.readUint8(); if (prop.isBase()) { if (inited) { onModelIDChanged(oldval_modelID); } } else { if (inWorld) { onModelIDChanged(oldval_modelID); } } break; case 7: float oldval_modelScale = modelScale; modelScale = stream.readFloat(); if (prop.isBase()) { if (inited) { onModelScaleChanged(oldval_modelScale); } } else { if (inWorld) { onModelScaleChanged(oldval_modelScale); } } break; case 6: float oldval_moveSpeed = moveSpeed; moveSpeed = stream.readFloat(); if (prop.isBase()) { if (inited) { onMoveSpeedChanged(oldval_moveSpeed); } } else { if (inWorld) { onMoveSpeedChanged(oldval_moveSpeed); } } break; case 2: string oldval_name = name; name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_name); } } else { if (inWorld) { onNameChanged(oldval_name); } } break; case 40000: Vector3 oldval_position = position; position = stream.readVector3(); if (prop.isBase()) { if (inited) { onPositionChanged(oldval_position); } } else { if (inWorld) { onPositionChanged(oldval_position); } } break; case 40002: stream.readUint32(); break; case 8: SByte oldval_state = state; state = stream.readInt8(); if (prop.isBase()) { if (inited) { onStateChanged(oldval_state); } } else { if (inWorld) { onStateChanged(oldval_state); } } break; default: break; } ; } }
public void onUpdatePropertys_(Int32 eid, MemoryStream stream) { Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { MemoryStream entityMessage = null; if(_bufferedCreateEntityMessage.TryGetValue(eid, out entityMessage)) { Dbg.ERROR_MSG("KBEngine::Client_onUpdatePropertys: entity(" + eid + ") not found!"); return; } MemoryStream stream1 = new MemoryStream(); stream1.wpos = stream.wpos; stream1.rpos = stream.rpos - 4; Array.Copy(stream.data(), stream1.data(), stream.data().Length); _bufferedCreateEntityMessage[eid] = stream1; return; } ScriptModule sm = EntityDef.moduledefs[entity.className]; Dictionary<UInt16, Property> pdatas = sm.idpropertys; while(stream.length() > 0) { UInt16 utype = 0; if(sm.usePropertyDescrAlias) { utype = stream.readUint8(); } else { utype = stream.readUint16(); } Property propertydata = pdatas[utype]; utype = propertydata.properUtype; System.Reflection.MethodInfo setmethod = propertydata.setmethod; object val = propertydata.utype.createFromStream(stream); object oldval = entity.getDefinedProptertyByUType(utype); // Dbg.DEBUG_MSG("KBEngine::Client_onUpdatePropertys: " + entity.className + "(id=" + eid + " " + // propertydata.name + "=" + val + "), hasSetMethod=" + setmethod + "!"); entity.setDefinedProptertyByUType(utype, val); if(setmethod != null) { if(propertydata.isBase() || entity.inWorld) setmethod.Invoke(entity, new object[]{oldval}); } } }
public void onImportClientMessages(MemoryStream stream) { UInt16 msgcount = stream.readUint16(); Dbg.DEBUG_MSG(string.Format("KBEngine::Client_onImportClientMessages: start currserver=" + currserver + "(msgsize={0})...", msgcount)); while(msgcount > 0) { msgcount--; MessageID msgid = stream.readUint16(); Int16 msglen = stream.readInt16(); string msgname = stream.readString(); sbyte argstype = stream.readInt8(); Byte argsize = stream.readUint8(); List<Byte> argstypes = new List<Byte>(); for(Byte i=0; i<argsize; i++) { argstypes.Add(stream.readUint8()); } System.Reflection.MethodInfo handler = null; bool isClientMethod = msgname.Contains("Client_"); if(isClientMethod) { handler = typeof(KBEngineApp).GetMethod(msgname); if(handler == null) { Dbg.WARNING_MSG(string.Format("KBEngine::onImportClientMessages[{0}]: interface({1}/{2}/{3}) no implement!", currserver, msgname, msgid, msglen)); handler = null; } else { //Dbg.DEBUG_MSG(string.Format("KBEngine::onImportClientMessages: imported({0}/{1}/{2}) successfully!", // msgname, msgid, msglen)); } } if(msgname.Length > 0) { Message.messages[msgname] = new Message(msgid, msgname, msglen, argstype, argstypes, handler); //if(!isClientMethod) // Dbg.DEBUG_MSG(string.Format("KBEngine::onImportClientMessages[{0}]: imported({1}/{2}/{3}) successfully!", // currserver, msgname, msgid, msglen)); if(isClientMethod) { Message.clientMessages[msgid] = Message.messages[msgname]; } else { if(currserver == "loginapp") Message.loginappMessages[msgid] = Message.messages[msgname]; else Message.baseappMessages[msgid] = Message.messages[msgname]; } } else { Message msg = new Message(msgid, msgname, msglen, argstype, argstypes, handler); //if(!isClientMethod) // Dbg.DEBUG_MSG(string.Format("KBEngine::onImportClientMessages[{0}]: imported({1}/{2}/{3}) successfully!", // currserver, msgname, msgid, msglen)); if(currserver == "loginapp") Message.loginappMessages[msgid] = msg; else Message.baseappMessages[msgid] = msg; } }; onImportClientMessagesCompleted(); }
/* 通过流数据获得AOI实体的ID */ public Int32 getAoiEntityIDFromStream(MemoryStream stream) { if (!_args.useAliasEntityID) return stream.readInt32(); Int32 id = 0; if(_entityIDAliasIDList.Count > 255) { id = stream.readInt32(); // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 if(_entityIDAliasIDList.Count == 0) return 0; } else { byte aliasID = stream.readUint8(); // 如果为0且客户端上一步是重登陆或者重连操作并且服务端entity在断线期间一直处于在线状态 // 则可以忽略这个错误, 因为cellapp可能一直在向baseapp发送同步消息, 当客户端重连上时未等 // 服务端初始化步骤开始则收到同步信息, 此时这里就会出错。 if(_entityIDAliasIDList.Count == 0) return 0; id = _entityIDAliasIDList[aliasID]; } return id; }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Account"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = 0; { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; if (_t_utype == 0) { prop = pdatas[_t_child_utype]; } else { Property pComponentPropertyDescription = pdatas[_t_utype]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (prop.properUtype) { case 40001: Vector3 oldval_direction = direction; direction = stream.readVector3(); if (prop.isBase()) { if (inited) { onDirectionChanged(oldval_direction); } } else { if (inWorld) { onDirectionChanged(oldval_direction); } } break; case 40000: Vector3 oldval_position = position; position = stream.readVector3(); if (prop.isBase()) { if (inited) { onPositionChanged(oldval_position); } } else { if (inWorld) { onPositionChanged(oldval_position); } } break; case 40002: stream.readUint32(); break; default: break; } ; } }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = 0; { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; if (_t_utype == 0) { prop = pdatas[_t_child_utype]; } else { Property pComponentPropertyDescription = pdatas[_t_utype]; switch (pComponentPropertyDescription.properUtype) { case 16: component1.onUpdatePropertys(_t_child_utype, stream, -1); break; case 21: component2.onUpdatePropertys(_t_child_utype, stream, -1); break; case 22: component3.onUpdatePropertys(_t_child_utype, stream, -1); break; default: break; } return; } switch (prop.properUtype) { case 47001: Int32 oldval_HP = HP; HP = stream.readInt32(); if (prop.isBase()) { if (inited) { onHPChanged(oldval_HP); } } else { if (inWorld) { onHPChanged(oldval_HP); } } break; case 47002: Int32 oldval_HP_Max = HP_Max; HP_Max = stream.readInt32(); if (prop.isBase()) { if (inited) { onHP_MaxChanged(oldval_HP_Max); } } else { if (inWorld) { onHP_MaxChanged(oldval_HP_Max); } } break; case 47003: Int32 oldval_MP = MP; MP = stream.readInt32(); if (prop.isBase()) { if (inited) { onMPChanged(oldval_MP); } } else { if (inWorld) { onMPChanged(oldval_MP); } } break; case 47004: Int32 oldval_MP_Max = MP_Max; MP_Max = stream.readInt32(); if (prop.isBase()) { if (inited) { onMP_MaxChanged(oldval_MP_Max); } } else { if (inWorld) { onMP_MaxChanged(oldval_MP_Max); } } break; case 16: component1.createFromStream(stream); break; case 21: component2.createFromStream(stream); break; case 22: component3.createFromStream(stream); break; case 40001: Vector3 oldval_direction = direction; direction = stream.readVector3(); if (prop.isBase()) { if (inited) { onDirectionChanged(oldval_direction); } } else { if (inWorld) { onDirectionChanged(oldval_direction); } } break; case 47005: Int32 oldval_forbids = forbids; forbids = stream.readInt32(); if (prop.isBase()) { if (inited) { onForbidsChanged(oldval_forbids); } } else { if (inWorld) { onForbidsChanged(oldval_forbids); } } break; case 41002: UInt16 oldval_level = level; level = stream.readUint16(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_level); } } else { if (inWorld) { onLevelChanged(oldval_level); } } break; case 41006: UInt32 oldval_modelID = modelID; modelID = stream.readUint32(); if (prop.isBase()) { if (inited) { onModelIDChanged(oldval_modelID); } } else { if (inWorld) { onModelIDChanged(oldval_modelID); } } break; case 41007: Byte oldval_modelScale = modelScale; modelScale = stream.readUint8(); if (prop.isBase()) { if (inited) { onModelScaleChanged(oldval_modelScale); } } else { if (inWorld) { onModelScaleChanged(oldval_modelScale); } } break; case 11: Byte oldval_moveSpeed = moveSpeed; moveSpeed = stream.readUint8(); if (prop.isBase()) { if (inited) { onMoveSpeedChanged(oldval_moveSpeed); } } else { if (inWorld) { onMoveSpeedChanged(oldval_moveSpeed); } } break; case 41003: string oldval_name = name; name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_name); } } else { if (inWorld) { onNameChanged(oldval_name); } } break; case 6: UInt16 oldval_own_val = own_val; own_val = stream.readUint16(); if (prop.isBase()) { if (inited) { onOwn_valChanged(oldval_own_val); } } else { if (inWorld) { onOwn_valChanged(oldval_own_val); } } break; case 40000: Vector3 oldval_position = position; position = stream.readVector3(); if (prop.isBase()) { if (inited) { onPositionChanged(oldval_position); } } else { if (inWorld) { onPositionChanged(oldval_position); } } break; case 40002: stream.readUint32(); break; case 41001: UInt32 oldval_spaceUType = spaceUType; spaceUType = stream.readUint32(); if (prop.isBase()) { if (inited) { onSpaceUTypeChanged(oldval_spaceUType); } } else { if (inWorld) { onSpaceUTypeChanged(oldval_spaceUType); } } break; case 47006: SByte oldval_state = state; state = stream.readInt8(); if (prop.isBase()) { if (inited) { onStateChanged(oldval_state); } } else { if (inWorld) { onStateChanged(oldval_state); } } break; case 47007: Byte oldval_subState = subState; subState = stream.readUint8(); if (prop.isBase()) { if (inited) { onSubStateChanged(oldval_subState); } } else { if (inWorld) { onSubStateChanged(oldval_subState); } } break; case 41004: UInt32 oldval_uid = uid; uid = stream.readUint32(); if (prop.isBase()) { if (inited) { onUidChanged(oldval_uid); } } else { if (inWorld) { onUidChanged(oldval_uid); } } break; case 41005: UInt32 oldval_utype = utype; utype = stream.readUint32(); if (prop.isBase()) { if (inited) { onUtypeChanged(oldval_utype); } } else { if (inWorld) { onUtypeChanged(oldval_utype); } } break; default: break; } ; } }
public override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.usePropertyDescrAlias) { componentPropertyUType = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); } if (sm.useMethodDescrAlias) { methodUtype = stream.readUint8(); } else { methodUtype = stream.readUint16(); } Method method = null; if (componentPropertyUType == 0) { method = sm.idmethods[methodUtype]; } else { Property pComponentPropertyDescription = sm.idpropertys[componentPropertyUType]; switch (pComponentPropertyDescription.properUtype) { case 16: component1.onRemoteMethodCall(methodUtype, stream); break; case 21: component2.onRemoteMethodCall(methodUtype, stream); break; case 22: component3.onRemoteMethodCall(methodUtype, stream); break; default: break; } return; } switch (method.methodUtype) { case 10101: Byte dialog_addOption_arg1 = stream.readUint8(); UInt32 dialog_addOption_arg2 = stream.readUint32(); string dialog_addOption_arg3 = stream.readUnicode(); Int32 dialog_addOption_arg4 = stream.readInt32(); dialog_addOption(dialog_addOption_arg1, dialog_addOption_arg2, dialog_addOption_arg3, dialog_addOption_arg4); break; case 10104: dialog_close(); break; case 10102: string dialog_setText_arg1 = stream.readUnicode(); Byte dialog_setText_arg2 = stream.readUint8(); UInt32 dialog_setText_arg3 = stream.readUint32(); string dialog_setText_arg4 = stream.readUnicode(); dialog_setText(dialog_setText_arg1, dialog_setText_arg2, dialog_setText_arg3, dialog_setText_arg4); break; case 12: Int32 onAddSkill_arg1 = stream.readInt32(); onAddSkill(onAddSkill_arg1); break; case 7: onJump(); break; case 13: Int32 onRemoveSkill_arg1 = stream.readInt32(); onRemoveSkill(onRemoveSkill_arg1); break; case 16: Int32 recvDamage_arg1 = stream.readInt32(); Int32 recvDamage_arg2 = stream.readInt32(); Int32 recvDamage_arg3 = stream.readInt32(); Int32 recvDamage_arg4 = stream.readInt32(); recvDamage(recvDamage_arg1, recvDamage_arg2, recvDamage_arg3, recvDamage_arg4); break; default: break; } ; }
public override object createFromStream(MemoryStream stream) { return(stream.readUint8()); }
public override void onUpdatePropertys(UInt16 propUtype, MemoryStream stream, int maxCount) { ScriptModule sm = EntityDef.moduledefs["Test"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0 && maxCount-- != 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = propUtype; if (_t_child_utype == 0) { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; prop = pdatas[_t_child_utype]; switch (prop.properUtype) { case 18: Int32 oldval_own = own; own = stream.readInt32(); if (prop.isBase()) { if (owner.inited) { onOwnChanged(oldval_own); } } else { if (owner.inWorld) { onOwnChanged(oldval_own); } } break; case 17: Int32 oldval_state = state; state = stream.readInt32(); if (prop.isBase()) { if (owner.inited) { onStateChanged(oldval_state); } } else { if (owner.inWorld) { onStateChanged(oldval_state); } } break; default: break; } ; } }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Account"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = 0; { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; if (_t_utype == 0) { prop = pdatas[_t_child_utype]; } else { Property pComponentPropertyDescription = pdatas[_t_utype]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (prop.properUtype) { case 13: TING_PAI_LIST oldval_TingPaiList = TingPaiList; TingPaiList = ((DATATYPE_TING_PAI_LIST)EntityDef.id2datatypes[34]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onTingPaiListChanged(oldval_TingPaiList); } } else { if (inWorld) { onTingPaiListChanged(oldval_TingPaiList); } } break; case 15: Int32 oldval__lastmailID = _lastmailID; _lastmailID = stream.readInt32(); if (prop.isBase()) { if (inited) { on_lastmailIDChanged(oldval__lastmailID); } } else { if (inWorld) { on_lastmailIDChanged(oldval__lastmailID); } } break; case 12: PLAYER_ACTION_DIC oldval_actionData = actionData; actionData = ((DATATYPE_PLAYER_ACTION_DIC)EntityDef.id2datatypes[32]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onActionDataChanged(oldval_actionData); } } else { if (inWorld) { onActionDataChanged(oldval_actionData); } } break; case 40001: Vector3 oldval_direction = direction; direction = stream.readVector3(); if (prop.isBase()) { if (inited) { onDirectionChanged(oldval_direction); } } else { if (inWorld) { onDirectionChanged(oldval_direction); } } break; case 1: FRIENDS_LIST oldval_friendsList = friendsList; friendsList = ((DATATYPE_FRIENDS_LIST)EntityDef.id2datatypes[26]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onFriendsListChanged(oldval_friendsList); } } else { if (inWorld) { onFriendsListChanged(oldval_friendsList); } } break; case 11: MJ_LIST oldval_holds = holds; holds = ((DATATYPE_MJ_LIST)EntityDef.id2datatypes[22]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onHoldsChanged(oldval_holds); } } else { if (inWorld) { onHoldsChanged(oldval_holds); } } break; case 4: Byte oldval_inRoom = inRoom; inRoom = stream.readUint8(); if (prop.isBase()) { if (inited) { onInRoomChanged(oldval_inRoom); } } else { if (inWorld) { onInRoomChanged(oldval_inRoom); } } break; case 8: Byte oldval_isNewPlayer = isNewPlayer; isNewPlayer = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsNewPlayerChanged(oldval_isNewPlayer); } } else { if (inWorld) { onIsNewPlayerChanged(oldval_isNewPlayer); } } break; case 10: Byte oldval_isReady = isReady; isReady = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsReadyChanged(oldval_isReady); } } else { if (inWorld) { onIsReadyChanged(oldval_isReady); } } break; case 14: MAIL_LIST oldval_mailList = mailList; mailList = ((DATATYPE_MAIL_LIST)EntityDef.id2datatypes[25]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onMailListChanged(oldval_mailList); } } else { if (inWorld) { onMailListChanged(oldval_mailList); } } break; case 7: UInt32 oldval_playerGold = playerGold; playerGold = stream.readUint32(); if (prop.isBase()) { if (inited) { onPlayerGoldChanged(oldval_playerGold); } } else { if (inWorld) { onPlayerGoldChanged(oldval_playerGold); } } break; case 6: UInt16 oldval_playerID = playerID; playerID = stream.readUint16(); if (prop.isBase()) { if (inited) { onPlayerIDChanged(oldval_playerID); } } else { if (inWorld) { onPlayerIDChanged(oldval_playerID); } } break; case 3: UInt16 oldval_playerID_base = playerID_base; playerID_base = stream.readUint16(); if (prop.isBase()) { if (inited) { onPlayerID_baseChanged(oldval_playerID_base); } } else { if (inWorld) { onPlayerID_baseChanged(oldval_playerID_base); } } break; case 5: string oldval_playerName = playerName; playerName = stream.readUnicode(); if (prop.isBase()) { if (inited) { onPlayerNameChanged(oldval_playerName); } } else { if (inWorld) { onPlayerNameChanged(oldval_playerName); } } break; case 2: string oldval_playerName_base = playerName_base; playerName_base = stream.readUnicode(); if (prop.isBase()) { if (inited) { onPlayerName_baseChanged(oldval_playerName_base); } } else { if (inWorld) { onPlayerName_baseChanged(oldval_playerName_base); } } break; case 40000: Vector3 oldval_position = position; position = stream.readVector3(); if (prop.isBase()) { if (inited) { onPositionChanged(oldval_position); } } else { if (inWorld) { onPositionChanged(oldval_position); } } break; case 9: Byte oldval_roomSeatIndex = roomSeatIndex; roomSeatIndex = stream.readUint8(); if (prop.isBase()) { if (inited) { onRoomSeatIndexChanged(oldval_roomSeatIndex); } } else { if (inWorld) { onRoomSeatIndexChanged(oldval_roomSeatIndex); } } break; case 40002: stream.readUint32(); break; default: break; } ; } }
public override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Account"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.usePropertyDescrAlias) { componentPropertyUType = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); } if (sm.useMethodDescrAlias) { methodUtype = stream.readUint8(); } else { methodUtype = stream.readUint16(); } Method method = null; if (componentPropertyUType == 0) { method = sm.idmethods[methodUtype]; } else { Property pComponentPropertyDescription = sm.idpropertys[componentPropertyUType]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (method.methodUtype) { case 23: Byte OnReqCreateAvatar_arg1 = stream.readUint8(); OnReqCreateAvatar(OnReqCreateAvatar_arg1); break; case 48: MAIL addMail_arg1 = ((DATATYPE_MAIL)method.args[0]).createFromStreamEx(stream); addMail(addMail_arg1); break; case 40: string callClientMsg_arg1 = stream.readUnicode(); callClientMsg(callClientMsg_arg1); break; case 49: Int32 deleMail_arg1 = stream.readInt32(); deleMail(deleMail_arg1); break; case 26: game_begin_push(); break; case 29: game_chupai_push(); break; case 31: SByte game_mopai_push_arg1 = stream.readInt8(); game_mopai_push(game_mopai_push_arg1); break; case 37: TING_PAI_LIST hasTing_arg1 = ((DATATYPE_TING_PAI_LIST)method.args[0]).createFromStreamEx(stream); hasTing(hasTing_arg1); break; case 28: has_action(); break; case 39: PLAYRE_DATA_LIST initFriendsListOK_arg1 = ((DATATYPE_PLAYRE_DATA_LIST)method.args[0]).createFromStreamEx(stream); initFriendsListOK(initFriendsListOK_arg1); break; case 38: onGameOver(); break; case 34: UInt32 onGang_arg1 = stream.readUint32(); SByte onGang_arg2 = stream.readInt8(); string onGang_arg3 = stream.readUnicode(); onGang(onGang_arg1, onGang_arg2, onGang_arg3); break; case 25: ROOM_PUBLIC_INFO onGetRoomInfo_arg1 = ((DATATYPE_ROOM_PUBLIC_INFO)method.args[0]).createFromStreamEx(stream); onGetRoomInfo(onGetRoomInfo_arg1); break; case 35: UInt32 onHu_arg1 = stream.readUint32(); Byte onHu_arg2 = stream.readUint8(); SByte onHu_arg3 = stream.readInt8(); onHu(onHu_arg1, onHu_arg2, onHu_arg3); break; case 30: UInt32 onPlayCard_arg1 = stream.readUint32(); SByte onPlayCard_arg2 = stream.readInt8(); onPlayCard(onPlayCard_arg1, onPlayCard_arg2); break; case 36: UInt32 onPlayCardOver_arg1 = stream.readUint32(); SByte onPlayCardOver_arg2 = stream.readInt8(); onPlayCardOver(onPlayCardOver_arg1, onPlayCardOver_arg2); break; case 32: UInt32 otherPlayerMopai_arg1 = stream.readUint32(); otherPlayerMopai(otherPlayerMopai_arg1); break; case 33: UInt32 peng_notify_push_arg1 = stream.readUint32(); SByte peng_notify_push_arg2 = stream.readInt8(); peng_notify_push(peng_notify_push_arg1, peng_notify_push_arg2); break; case 24: playerLevelRoom(); break; case 27: ROOM_PUBLIC_INFO upDataClientRoomInfo_arg1 = ((DATATYPE_ROOM_PUBLIC_INFO)method.args[0]).createFromStreamEx(stream); upDataClientRoomInfo(upDataClientRoomInfo_arg1); break; default: break; } ; }
public void Client_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(); } } while(stream.opsize() > 0) { string scriptmethod_name = stream.readString(); UInt16 scriptUtype = stream.readUint16(); UInt16 propertysize = stream.readUint16(); UInt16 methodsize = stream.readUint16(); UInt16 base_methodsize = stream.readUint16(); UInt16 cell_methodsize = stream.readUint16(); Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: import(" + scriptmethod_name + "), propertys(" + propertysize + "), " + "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!"); ScriptModule module = new ScriptModule(scriptmethod_name); EntityDef.moduledefs[scriptmethod_name] = module; EntityDef.idmoduledefs[scriptUtype] = module; Dictionary<string, Property> defpropertys = new Dictionary<string, Property>(); Entity.alldefpropertys.Add(scriptmethod_name, defpropertys); Type Class = module.script; while(propertysize > 0) { propertysize--; UInt16 properUtype = stream.readUint16(); string name = stream.readString(); string defaultValStr = stream.readString(); KBEDATATYPE_BASE utype = EntityDef.iddatatypes[stream.readUint16()]; System.Reflection.MethodInfo setmethod = null; if(Class != null) { setmethod = Class.GetMethod("set_" + name); } Property savedata = new Property(); savedata.name = name; savedata.properUtype = properUtype; savedata.defaultValStr = defaultValStr; savedata.utype = utype; savedata.setmethod = setmethod; module.propertys[name] = savedata; module.idpropertys[properUtype] = savedata; Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), property(" + name + "/" + properUtype + ")."); }; while(methodsize > 0) { methodsize--; UInt16 methodUtype = stream.readUint16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.iddatatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.args = args; if(Class != null) savedata.handler = Class.GetMethod(name); module.methods[name] = savedata; module.idmethods[methodUtype] = savedata; Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), method(" + name + ")."); }; while(base_methodsize > 0) { base_methodsize--; UInt16 methodUtype = stream.readUint16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.iddatatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.args = args; module.base_methods[name] = savedata; module.idbase_methods[methodUtype] = savedata; Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), base_method(" + name + ")."); }; while(cell_methodsize > 0) { cell_methodsize--; UInt16 methodUtype = stream.readUint16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.iddatatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.args = args; module.cell_methods[name] = savedata; module.idcell_methods[methodUtype] = savedata; Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), cell_method(" + name + ")."); }; if(module.script == null) { Dbg.ERROR_MSG("KBEngine::Client_onImportClientEntityDef: module(" + scriptmethod_name + ") not found!"); } foreach(string name in module.propertys.Keys) { Property infos = module.propertys[name]; Property newp = new Property(); newp.name = infos.name; newp.properUtype = infos.properUtype; newp.utype = infos.utype; newp.val = infos.utype.parseDefaultValStr(infos.defaultValStr); newp.setmethod = infos.setmethod; defpropertys.Add(infos.name, newp); if(module.script != null && module.script.GetMember(name) == null) { Dbg.ERROR_MSG(scriptmethod_name + "(" + module.script + "):: property(" + name + ") no defined!"); } }; foreach(string name in module.methods.Keys) { Method infos = module.methods[name]; if(module.script != null && module.script.GetMethod(name) == null) { Dbg.WARNING_MSG(scriptmethod_name + "(" + module.script + "):: method(" + name + ") no implement!"); } }; } onImportEntityDefCompleted(); }
public void createDataTypeFromStream(MemoryStream stream, bool canprint) { UInt16 utype = stream.readUint16(); string name = stream.readString(); string valname = stream.readString(); /* 有一些匿名类型,我们需要提供一个唯一名称放到datatypes中 如: <onRemoveAvatar> <Arg> ARRAY <of> INT8 </of> </Arg> </onRemoveAvatar> */ if(valname.Length == 0) valname = "Null_" + utype; if(canprint) Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: importAlias(" + name + ":" + valname + ":" + utype + ")!"); if(name == "FIXED_DICT") { KBEDATATYPE_FIXED_DICT datatype = new KBEDATATYPE_FIXED_DICT(); Byte keysize = stream.readUint8(); datatype.implementedBy = stream.readString(); while(keysize > 0) { keysize--; string keyname = stream.readString(); UInt16 keyutype = stream.readUint16(); datatype.dicttype[keyname] = keyutype; }; EntityDef.datatypes[valname] = datatype; } else if(name == "ARRAY") { UInt16 uitemtype = stream.readUint16(); KBEDATATYPE_ARRAY datatype = new KBEDATATYPE_ARRAY(); datatype.vtype = uitemtype; EntityDef.datatypes[valname] = datatype; } else { KBEDATATYPE_BASE val = null; EntityDef.datatypes.TryGetValue(name, out val); EntityDef.datatypes[valname] = val; } EntityDef.id2datatypes[utype] = EntityDef.datatypes[valname]; // 将用户自定义的类型补充到映射表中 EntityDef.datatype2id[valname] = utype; }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["SpawnPoint"]; Dictionary <UInt16, Property> pdatas = sm.idpropertys; while (stream.length() > 0) { UInt16 _t_utype = 0; UInt16 _t_child_utype = 0; { if (sm.usePropertyDescrAlias) { _t_utype = stream.readUint8(); _t_child_utype = stream.readUint8(); } else { _t_utype = stream.readUint16(); _t_child_utype = stream.readUint16(); } } Property prop = null; if (_t_utype == 0) { prop = pdatas[_t_child_utype]; } else { Property pComponentPropertyDescription = pdatas[_t_utype]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (prop.properUtype) { case 40001: Vector3 oldval_direction = direction; direction = stream.readVector3(); if (prop.isBase()) { if (inited) { onDirectionChanged(oldval_direction); } } else { if (inWorld) { onDirectionChanged(oldval_direction); } } break; case 41006: UInt32 oldval_modelID = modelID; modelID = stream.readUint32(); if (prop.isBase()) { if (inited) { onModelIDChanged(oldval_modelID); } } else { if (inWorld) { onModelIDChanged(oldval_modelID); } } break; case 41007: Byte oldval_modelScale = modelScale; modelScale = stream.readUint8(); if (prop.isBase()) { if (inited) { onModelScaleChanged(oldval_modelScale); } } else { if (inWorld) { onModelScaleChanged(oldval_modelScale); } } break; case 41003: string oldval_name = name; name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_name); } } else { if (inWorld) { onNameChanged(oldval_name); } } break; case 40000: Vector3 oldval_position = position; position = stream.readVector3(); if (prop.isBase()) { if (inited) { onPositionChanged(oldval_position); } } else { if (inWorld) { onPositionChanged(oldval_position); } } break; case 40002: stream.readUint32(); break; case 41004: UInt32 oldval_uid = uid; uid = stream.readUint32(); if (prop.isBase()) { if (inited) { onUidChanged(oldval_uid); } } else { if (inWorld) { onUidChanged(oldval_uid); } } break; case 41005: UInt32 oldval_utype = utype; utype = stream.readUint32(); if (prop.isBase()) { if (inited) { onUtypeChanged(oldval_utype); } } else { if (inWorld) { onUtypeChanged(oldval_utype); } } break; default: break; } ; } }
public void onImportClientEntityDef(MemoryStream stream) { createDataTypeFromStreams(stream, true); while(stream.length() > 0) { string scriptmethod_name = stream.readString(); UInt16 scriptUtype = stream.readUint16(); UInt16 propertysize = stream.readUint16(); UInt16 methodsize = stream.readUint16(); UInt16 base_methodsize = stream.readUint16(); UInt16 cell_methodsize = stream.readUint16(); Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: import(" + scriptmethod_name + "), propertys(" + propertysize + "), " + "clientMethods(" + methodsize + "), baseMethods(" + base_methodsize + "), cellMethods(" + cell_methodsize + ")!"); ScriptModule module = new ScriptModule(scriptmethod_name); EntityDef.moduledefs[scriptmethod_name] = module; EntityDef.idmoduledefs[scriptUtype] = module; Type Class = module.script; while(propertysize > 0) { propertysize--; UInt16 properUtype = stream.readUint16(); UInt32 properFlags = stream.readUint32(); Int16 ialiasID = stream.readInt16(); string name = stream.readString(); string defaultValStr = stream.readString(); KBEDATATYPE_BASE utype = EntityDef.id2datatypes[stream.readUint16()]; System.Reflection.MethodInfo setmethod = null; if(Class != null) { try{ setmethod = Class.GetMethod("set_" + name); } catch (Exception e) { string err = "KBEngine::Client_onImportClientEntityDef: " + scriptmethod_name + ".set_" + name + ", error=" + e.ToString(); throw new Exception(err); } } Property savedata = new Property(); savedata.name = name; savedata.utype = utype; savedata.properUtype = properUtype; savedata.properFlags = properFlags; savedata.aliasID = ialiasID; savedata.defaultValStr = defaultValStr; savedata.setmethod = setmethod; savedata.val = savedata.utype.parseDefaultValStr(savedata.defaultValStr); module.propertys[name] = savedata; if(ialiasID >= 0) { module.usePropertyDescrAlias = true; module.idpropertys[(UInt16)ialiasID] = savedata; } else { module.usePropertyDescrAlias = false; module.idpropertys[properUtype] = savedata; } //Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), property(" + name + "/" + properUtype + ")."); }; while(methodsize > 0) { methodsize--; UInt16 methodUtype = stream.readUint16(); Int16 ialiasID = stream.readInt16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.aliasID = ialiasID; savedata.args = args; if(Class != null) { try{ savedata.handler = Class.GetMethod(name); } catch (Exception e) { string err = "KBEngine::Client_onImportClientEntityDef: " + scriptmethod_name + "." + name + ", error=" + e.ToString(); throw new Exception(err); } } module.methods[name] = savedata; if(ialiasID >= 0) { module.useMethodDescrAlias = true; module.idmethods[(UInt16)ialiasID] = savedata; } else { module.useMethodDescrAlias = false; module.idmethods[methodUtype] = savedata; } //Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), method(" + name + ")."); }; while(base_methodsize > 0) { base_methodsize--; UInt16 methodUtype = stream.readUint16(); Int16 ialiasID = stream.readInt16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.aliasID = ialiasID; savedata.args = args; module.base_methods[name] = savedata; module.idbase_methods[methodUtype] = savedata; //Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), base_method(" + name + ")."); }; while(cell_methodsize > 0) { cell_methodsize--; UInt16 methodUtype = stream.readUint16(); Int16 ialiasID = stream.readInt16(); string name = stream.readString(); Byte argssize = stream.readUint8(); List<KBEDATATYPE_BASE> args = new List<KBEDATATYPE_BASE>(); while(argssize > 0) { argssize--; args.Add(EntityDef.id2datatypes[stream.readUint16()]); }; Method savedata = new Method(); savedata.name = name; savedata.methodUtype = methodUtype; savedata.aliasID = ialiasID; savedata.args = args; module.cell_methods[name] = savedata; module.idcell_methods[methodUtype] = savedata; //Dbg.DEBUG_MSG("KBEngine::Client_onImportClientEntityDef: add(" + scriptmethod_name + "), cell_method(" + name + ")."); }; if(module.script == null) { Dbg.ERROR_MSG("KBEngine::Client_onImportClientEntityDef: module(" + scriptmethod_name + ") not found!"); } foreach(string name in module.methods.Keys) { // Method infos = module.methods[name]; if(module.script != null && module.script.GetMethod(name) == null) { Dbg.WARNING_MSG(scriptmethod_name + "(" + module.script + "):: method(" + name + ") no implement!"); } }; } onImportEntityDefCompleted(); }
public override object createFromStream(MemoryStream stream) { return stream.readUint8(); }
public void onRemoteMethodCall_(Int32 eid, MemoryStream stream) { Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { Dbg.ERROR_MSG("KBEngine::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } UInt16 methodUtype = 0; if(EntityDef.moduledefs[entity.className].useMethodDescrAlias) methodUtype = stream.readUint8(); else methodUtype = stream.readUint16(); Method methoddata = EntityDef.moduledefs[entity.className].idmethods[methodUtype]; // Dbg.DEBUG_MSG("KBEngine::Client_onRemoteMethodCall: " + entity.className + "." + methoddata.name); object[] args = new object[methoddata.args.Count]; for(int i=0; i<methoddata.args.Count; i++) { args[i] = methoddata.args[i].createFromStream(stream); } try { methoddata.handler.Invoke(entity, args); } catch (Exception e) { if(methoddata.handler != null) { Dbg.ERROR_MSG("KBEngine::Client_onRemoteMethodCall: " + entity.className + "(" + eid + "), callMethod(" + entity.className + "." + methoddata.name + ") is error!\nerror=" + e.ToString()); } else { Dbg.ERROR_MSG("KBEngine::Client_onRemoteMethodCall: " + entity.className + "(" + eid + "), not found method(" + entity.className + "." + methoddata.name + ")!\nerror=" + e.ToString()); } } }
public void Client_onEntityEnterWorld(MemoryStream stream) { Int32 eid = stream.readInt32(); if(entity_id > 0 && entity_id != eid) entityIDAliasIDList.Add(eid); UInt16 uentityType; if(EntityDef.idmoduledefs.Count > 255) uentityType = stream.readUint16(); else uentityType = stream.readUint8(); sbyte isOnGound = 1; if(stream.opsize() > 0) isOnGound = stream.readInt8(); string entityType = EntityDef.idmoduledefs[uentityType].name; Dbg.DEBUG_MSG("KBEngine::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngineApp.app.spaceID + ")!"); Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { MemoryStream entityMessage = null; if(!bufferedCreateEntityMessage.TryGetValue(eid, out entityMessage)) { Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); return; } Type runclass = EntityDef.moduledefs[entityType].script; if(runclass == null) return; entity = (Entity)Activator.CreateInstance(runclass); entity.id = eid; entity.classtype = entityType; entity.cellMailbox = new Mailbox(); entity.cellMailbox.id = eid; entity.cellMailbox.classtype = entityType; entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL; entities[eid] = entity; Client_onUpdatePropertys(entityMessage); bufferedCreateEntityMessage.Remove(eid); entity.isOnGound = isOnGound > 0; entity.__init__(); entity.onEnterWorld(); Event.fireOut("set_direction", new object[]{entity}); Event.fireOut("set_position", new object[]{entity}); } else { if(!entity.inWorld) { entity.cellMailbox = new Mailbox(); entity.cellMailbox.id = eid; entity.cellMailbox.classtype = entityType; entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL; entityServerPos = entity.position; entity.isOnGound = isOnGound > 0; entity.onEnterWorld(); } } }
/* 服务端通知一个实体进入了世界(如果实体是当前玩家则玩家第一次在一个space中创建了, 如果是其他实体则是其他实体进入了玩家的AOI) */ public void Client_onEntityEnterWorld(MemoryStream stream) { Int32 eid = stream.readInt32(); if(entity_id > 0 && entity_id != eid) _entityIDAliasIDList.Add(eid); UInt16 uentityType; if(EntityDef.idmoduledefs.Count > 255) uentityType = stream.readUint16(); else uentityType = stream.readUint8(); sbyte isOnGround = 1; if(stream.length() > 0) isOnGround = stream.readInt8(); string entityType = EntityDef.idmoduledefs[uentityType].name; // Dbg.DEBUG_MSG("KBEngine::Client_onEntityEnterWorld: " + entityType + "(" + eid + "), spaceID(" + KBEngineApp.app.spaceID + ")!"); Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { MemoryStream entityMessage = null; if(!_bufferedCreateEntityMessage.TryGetValue(eid, out entityMessage)) { Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterWorld: entity(" + eid + ") not found!"); return; } ScriptModule module = null; if(!EntityDef.moduledefs.TryGetValue(entityType, out module)) { Dbg.ERROR_MSG("KBEngine::Client_onEntityEnterWorld: not found module(" + entityType + ")!"); } Type runclass = module.script; if(runclass == null) return; entity = (Entity)Activator.CreateInstance(runclass); entity.id = eid; entity.className = entityType; entity.cellMailbox = new Mailbox(); entity.cellMailbox.id = eid; entity.cellMailbox.className = entityType; entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL; entities[eid] = entity; Client_onUpdatePropertys(entityMessage); _bufferedCreateEntityMessage.Remove(eid); entity.isOnGround = isOnGround > 0; entity.set_direction(entity.getDefinedPropterty("direction")); entity.set_position(entity.getDefinedPropterty("position")); entity.__init__(); entity.enterWorld(); } else { if(!entity.inWorld) { // 安全起见, 这里清空一下 // 如果服务端上使用giveClientTo切换控制权 // 之前的实体已经进入世界, 切换后的实体也进入世界, 这里可能会残留之前那个实体进入世界的信息 _entityIDAliasIDList.Clear(); clearEntities(false); entities[entity.id] = entity; entity.cellMailbox = new Mailbox(); entity.cellMailbox.id = eid; entity.cellMailbox.className = entityType; entity.cellMailbox.type = Mailbox.MAILBOX_TYPE.MAILBOX_TYPE_CELL; entity.set_direction(entity.getDefinedPropterty("direction")); entity.set_position(entity.getDefinedPropterty("position")); _entityServerPos = entity.position; entity.isOnGround = isOnGround > 0; entity.enterWorld(); } } }
public override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Account"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.usePropertyDescrAlias) { componentPropertyUType = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); } if (sm.useMethodDescrAlias) { methodUtype = stream.readUint8(); } else { methodUtype = stream.readUint16(); } Method method = null; if (componentPropertyUType == 0) { method = sm.idmethods[methodUtype]; } else { Property pComponentPropertyDescription = sm.idpropertys[componentPropertyUType]; switch (pComponentPropertyDescription.properUtype) { default: break; } return; } switch (method.methodUtype) { case 10005: Byte onCreateAvatarResult_arg1 = stream.readUint8(); AVATAR_INFOS onCreateAvatarResult_arg2 = ((DATATYPE_AVATAR_INFOS)method.args[1]).createFromStreamEx(stream); onCreateAvatarResult(onCreateAvatarResult_arg1, onCreateAvatarResult_arg2); break; case 3: UInt64 onRemoveAvatar_arg1 = stream.readUint64(); onRemoveAvatar(onRemoveAvatar_arg1); break; case 10003: AVATAR_INFOS_LIST onReqAvatarList_arg1 = ((DATATYPE_AVATAR_INFOS_LIST)method.args[0]).createFromStreamEx(stream); onReqAvatarList(onReqAvatarList_arg1); break; default: break; } ; }