static int readUint16(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); KBEngine.MemoryStream obj = (KBEngine.MemoryStream)ToLua.CheckObject <KBEngine.MemoryStream>(L, 1); ushort o = obj.readUint16(); LuaDLL.lua_pushnumber(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.useMethodDescrAlias) { componentPropertyUType = stream.readUint8(); methodUtype = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); 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 21: string ReceiveChatMessage_arg1 = stream.readUnicode(); ReceiveChatMessage(ReceiveChatMessage_arg1); break; case 10104: dialog_close(); break; case 10101: Int32 dialog_setContent_arg1 = stream.readInt32(); List <UInt32> dialog_setContent_arg2 = ((DATATYPE_AnonymousArray_31)method.args[1]).createFromStreamEx(stream); List <string> dialog_setContent_arg3 = ((DATATYPE_AnonymousArray_32)method.args[2]).createFromStreamEx(stream); string dialog_setContent_arg4 = stream.readUnicode(); string dialog_setContent_arg5 = stream.readUnicode(); string dialog_setContent_arg6 = stream.readUnicode(); dialog_setContent(dialog_setContent_arg1, dialog_setContent_arg2, dialog_setContent_arg3, dialog_setContent_arg4, dialog_setContent_arg5, dialog_setContent_arg6); break; case 24: Int32 dropItem_re_arg1 = stream.readInt32(); UInt64 dropItem_re_arg2 = stream.readUint64(); dropItem_re(dropItem_re_arg1, dropItem_re_arg2); break; case 25: ITEM_INFO equipItemRequest_re_arg1 = ((DATATYPE_ITEM_INFO)method.args[0]).createFromStreamEx(stream); ITEM_INFO equipItemRequest_re_arg2 = ((DATATYPE_ITEM_INFO)method.args[1]).createFromStreamEx(stream); equipItemRequest_re(equipItemRequest_re_arg1, equipItemRequest_re_arg2); break; case 26: Int32 errorInfo_arg1 = stream.readInt32(); errorInfo(errorInfo_arg1); break; case 31: Int32 onAddSkill_arg1 = stream.readInt32(); onAddSkill(onAddSkill_arg1); break; case 32: Int32 onRemoveSkill_arg1 = stream.readInt32(); onRemoveSkill(onRemoveSkill_arg1); break; case 22: ITEM_INFO_LIST onReqItemList_arg1 = ((DATATYPE_ITEM_INFO_LIST)method.args[0]).createFromStreamEx(stream); ITEM_INFO_LIST onReqItemList_arg2 = ((DATATYPE_ITEM_INFO_LIST)method.args[1]).createFromStreamEx(stream); onReqItemList(onReqItemList_arg1, onReqItemList_arg2); break; case 23: ITEM_INFO pickUp_re_arg1 = ((DATATYPE_ITEM_INFO)method.args[0]).createFromStreamEx(stream); pickUp_re(pickUp_re_arg1); break; case 35: 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 void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["City"]; 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 7: Int64 oldval_BusinessDvelopment = BusinessDvelopment; BusinessDvelopment = stream.readInt64(); if(prop.isBase()) { if(inited) onBusinessDvelopmentChanged(oldval_BusinessDvelopment); } else { if(inWorld) onBusinessDvelopmentChanged(oldval_BusinessDvelopment); } break; case 6: Byte oldval_CityCountry = CityCountry; CityCountry = stream.readUint8(); if(prop.isBase()) { if(inited) onCityCountryChanged(oldval_CityCountry); } else { if(inWorld) onCityCountryChanged(oldval_CityCountry); } break; case 3: UInt32 oldval_CityID = CityID; CityID = stream.readUint32(); if(prop.isBase()) { if(inited) onCityIDChanged(oldval_CityID); } else { if(inWorld) onCityIDChanged(oldval_CityID); } break; case 4: string oldval_CityName = CityName; CityName = stream.readUnicode(); if(prop.isBase()) { if(inited) onCityNameChanged(oldval_CityName); } else { if(inWorld) onCityNameChanged(oldval_CityName); } break; case 5: Byte oldval_CityType = CityType; CityType = stream.readUint8(); if(prop.isBase()) { if(inited) onCityTypeChanged(oldval_CityType); } else { if(inWorld) onCityTypeChanged(oldval_CityType); } break; case 8: Int64 oldval_MilitaryDvelopment = MilitaryDvelopment; MilitaryDvelopment = stream.readInt64(); if(prop.isBase()) { if(inited) onMilitaryDvelopmentChanged(oldval_MilitaryDvelopment); } else { if(inWorld) onMilitaryDvelopmentChanged(oldval_MilitaryDvelopment); } break; case 9: CITY_SELL_GOODS_LIST oldval_SellGoodsList = SellGoodsList; SellGoodsList = ((DATATYPE_CITY_SELL_GOODS_LIST)EntityDef.id2datatypes[23]).createFromStreamEx(stream); if(prop.isBase()) { if(inited) onSellGoodsListChanged(oldval_SellGoodsList); } else { if(inWorld) onSellGoodsListChanged(oldval_SellGoodsList); } 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 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["NPC"]; 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 49: UInt32 oldval_dialogID = dialogID; dialogID = stream.readUint32(); if (prop.isBase()) { if (inited) { onDialogIDChanged(oldval_dialogID); } } else { if (inWorld) { onDialogIDChanged(oldval_dialogID); } } 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 51007: UInt32 oldval_entityNO = entityNO; entityNO = stream.readUint32(); if (prop.isBase()) { if (inited) { onEntityNOChanged(oldval_entityNO); } } else { if (inWorld) { onEntityNOChanged(oldval_entityNO); } } 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 50: 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 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 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 16: ITEM_LIST oldval_bagItemList = bagItemList; bagItemList = ((DATATYPE_ITEM_LIST)EntityDef.id2datatypes[23]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onBagItemListChanged(oldval_bagItemList); } } else { if (inWorld) { onBagItemListChanged(oldval_bagItemList); } } break; case 17: EQUIP_DICT oldval_currentItemDict = currentItemDict; currentItemDict = ((DATATYPE_EQUIP_DICT)EntityDef.id2datatypes[24]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onCurrentItemDictChanged(oldval_currentItemDict); } } else { if (inWorld) { onCurrentItemDictChanged(oldval_currentItemDict); } } 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 8: Int32 oldval_gold = gold; gold = stream.readInt32(); if (prop.isBase()) { if (inited) { onGoldChanged(oldval_gold); } } else { if (inWorld) { onGoldChanged(oldval_gold); } } break; case 3: SByte oldval_lastLoginDate = lastLoginDate; lastLoginDate = stream.readInt8(); if (prop.isBase()) { if (inited) { onLastLoginDateChanged(oldval_lastLoginDate); } } else { if (inWorld) { onLastLoginDateChanged(oldval_lastLoginDate); } } break; case 7: Int16 oldval_lastLoginDayLoginTimes = lastLoginDayLoginTimes; lastLoginDayLoginTimes = stream.readInt16(); if (prop.isBase()) { if (inited) { onLastLoginDayLoginTimesChanged(oldval_lastLoginDayLoginTimes); } } else { if (inWorld) { onLastLoginDayLoginTimesChanged(oldval_lastLoginDayLoginTimes); } } break; case 5: Int16 oldval_lastLoginDayPlayTime = lastLoginDayPlayTime; lastLoginDayPlayTime = stream.readInt16(); if (prop.isBase()) { if (inited) { onLastLoginDayPlayTimeChanged(oldval_lastLoginDayPlayTime); } } else { if (inWorld) { onLastLoginDayPlayTimeChanged(oldval_lastLoginDayPlayTime); } } break; case 2: string oldval_nameS = nameS; nameS = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameSChanged(oldval_nameS); } } else { if (inWorld) { onNameSChanged(oldval_nameS); } } 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 13: Int32 oldval_progress = progress; progress = stream.readInt32(); if (prop.isBase()) { if (inited) { onProgressChanged(oldval_progress); } } else { if (inWorld) { onProgressChanged(oldval_progress); } } break; case 15: Int32 oldval_roomNo = roomNo; roomNo = stream.readInt32(); if (prop.isBase()) { if (inited) { onRoomNoChanged(oldval_roomNo); } } else { if (inWorld) { onRoomNoChanged(oldval_roomNo); } } break; case 40002: stream.readUint32(); break; case 6: Int16 oldval_totalLoginTimes = totalLoginTimes; totalLoginTimes = stream.readInt16(); if (prop.isBase()) { if (inited) { onTotalLoginTimesChanged(oldval_totalLoginTimes); } } else { if (inWorld) { onTotalLoginTimesChanged(oldval_totalLoginTimes); } } break; case 4: Int16 oldval_totalPlayTime = totalPlayTime; totalPlayTime = stream.readInt16(); if (prop.isBase()) { if (inited) { onTotalPlayTimeChanged(oldval_totalPlayTime); } } else { if (inWorld) { onTotalPlayTimeChanged(oldval_totalPlayTime); } } break; default: break; } ; } }
/* 账号创建返回结果 */ public void Client_onCreateAccountResult(MemoryStream stream) { UInt16 retcode = stream.readUint16(); byte[] datas = stream.readBlob(); Event.fireOut("onCreateAccountResult", new object[]{retcode, datas}); if(retcode != 0) { Dbg.WARNING_MSG("KBEngine::Client_onCreateAccountResult: " + username + " create is failed! code=" + retcode + "!"); return; } Dbg.DEBUG_MSG("KBEngine::Client_onCreateAccountResult: " + username + " create is successfully!"); }
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(); }
public void Client_onRemoteMethodCall(MemoryStream stream) { Int32 eid = stream.readInt32(); Entity entity = null; if(!entities.TryGetValue(eid, out entity)) { Dbg.ERROR_MSG("KBEngine::Client_onRemoteMethodCall: entity(" + eid + ") not found!"); return; } UInt16 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 void process(byte[] datas, MessageLength length, Dictionary <uint, MessageHandler> flowHandler) { //Log.Net("process receive Data " + length + " state " + state); MessageLength totallen = 0; while (length > 0 && expectSize > 0) { if (state == READ_STATE.READ_STATE_FLAG) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; flag = stream.readUint8(); stream.clear(); state = READ_STATE.READ_STATE_MSGLEN; expectSize = 4; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_MSGLEN) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; msglen = stream.readUint32(); stream.clear(); state = READ_STATE.READ_STATE_FLOWID; expectSize = 4; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_FLOWID) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; flowId = stream.readUint32(); stream.clear(); state = READ_STATE.READ_STATE_MODULEID; expectSize = 1; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_MODULEID) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; moduleId = stream.readUint8(); stream.clear(); state = READ_STATE.READ_STATE_MSGID; expectSize = 2; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_MSGID) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; msgid = stream.readUint16(); stream.clear(); state = READ_STATE.READ_STATE_RESPONSE_TIME; expectSize = 4; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_RESPONSE_TIME) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; responseTime = stream.readUint32(); stream.clear(); state = READ_STATE.READ_STATE_RESPONSE_FLAG; expectSize = 2; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_RESPONSE_FLAG) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; responseFlag = stream.readInt16(); stream.clear(); state = READ_STATE.READ_STATE_BODY; expectSize = msglen - 4 - 1 - 2 - 4 - 2; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } /* * body Can be empty */ if (state == READ_STATE.READ_STATE_BODY) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; /* * No Handler Or PushMessage forward To IPacketHandler * Call Who's RPC Method Or Register Many RPC Method to Handle It ? * [PushHandler] * void GCPushSpriteInfo(Packet packet) { * } * * PacketHandler namespace * IPacketHandler---->GCPushSpriteInfo */ MessageHandler handler = null; if (flowHandler == null) { handler = msgHandle; } else if (flowHandler.ContainsKey(flowId)) { handler = flowHandler [flowId]; flowHandler.Remove(flowId); } else { handler = msgHandle; } IMessageLite pbmsg = KBEngine.Message.handlePB(moduleId, msgid, stream); Packet p = new Packet(flag, msglen, flowId, moduleId, msgid, responseTime, responseFlag, pbmsg); var fullName = pbmsg.GetType().FullName; if (fullName.Contains("Push")) { //Log.Net("MessageReader Handler PushMessage"); if (mainLoop != null) { mainLoop.queueInLoop(delegate { var handlerName = fullName.Replace("MyLib", "PacketHandler"); var tp = Type.GetType(handlerName); if (tp == null) { Debug.LogError("PushMessage noHandler " + handlerName); } else { //Debug.Log("Handler Push Message here "+handlerName); var ph = (PacketHandler.IPacketHandler)Activator.CreateInstance(tp); ph.HandlePacket(p); } }); } } else if (handler != null) { mainLoop.queueInLoop(() => { handler(p); }); } else { //flowHandler.Remove(flowId); Debug.LogError("MessageReader::process No handler for flow Message " + msgid + " " + flowId + " " + pbmsg.GetType() + " " + pbmsg); } stream.clear(); state = READ_STATE.READ_STATE_FLAG; expectSize = 1; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } } if (responseFlag != 0) { Debug.LogError("MessageReader:: read Error Packet " + responseFlag); } //Log.Net("current state after " + state + " msglen " + msglen + " " + length); //Log.Net("MessageReader:: prop flag" + flag + " msglen " + msglen + " flowId " + flowId + " moduleId " + moduleId + " msgid " + msgid + " responseTime " + responseTime + " responseFlag " + responseFlag + " expectSize " + expectSize); }
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 6: CARDGROUP_INFO_LIST oldval_CardGroupList = CardGroupList; CardGroupList = ((DATATYPE_CARDGROUP_INFO_LIST)EntityDef.id2datatypes[29]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onCardGroupListChanged(oldval_CardGroupList); } } else { if (inWorld) { onCardGroupListChanged(oldval_CardGroupList); } } break; case 5: CARD_LIST oldval_CardList = CardList; CardList = ((DATATYPE_CARD_LIST)EntityDef.id2datatypes[24]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onCardListChanged(oldval_CardList); } } else { if (inWorld) { onCardListChanged(oldval_CardList); } } break; case 3: Int32 oldval_Gold = Gold; Gold = stream.readInt32(); if (prop.isBase()) { if (inited) { onGoldChanged(oldval_Gold); } } else { if (inWorld) { onGoldChanged(oldval_Gold); } } break; case 4: Int32 oldval_Kabao = Kabao; Kabao = stream.readInt32(); if (prop.isBase()) { if (inited) { onKabaoChanged(oldval_Kabao); } } else { if (inWorld) { onKabaoChanged(oldval_Kabao); } } break; case 2: Int16 oldval_Level = Level; Level = stream.readInt16(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_Level); } } else { if (inWorld) { onLevelChanged(oldval_Level); } } break; case 1: string oldval_Name = Name; Name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_Name); } } else { if (inWorld) { onNameChanged(oldval_Name); } } 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 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 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 17: compMatchAvatar.onRemoteMethodCall(methodUtype, stream); break; case 8: component1.onRemoteMethodCall(methodUtype, stream); break; case 11: component2.onRemoteMethodCall(methodUtype, stream); break; case 15: component3.onRemoteMethodCall(methodUtype, stream); break; default: break; } return; } switch (method.methodUtype) { default: break; } ; }
public override void onUpdatePropertys(UInt16 propUtype, MemoryStream stream, int maxCount) { ScriptModule sm = EntityDef.moduledefs["Operation"]; 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 10: SByte oldval_isWathcher = isWathcher; isWathcher = stream.readInt8(); if (prop.isBase()) { if (owner.inited) { onIsWathcherChanged(oldval_isWathcher); } } else { if (owner.inWorld) { onIsWathcherChanged(oldval_isWathcher); } } break; case 9: Int32 oldval_lossScore = lossScore; lossScore = stream.readInt32(); if (prop.isBase()) { if (owner.inited) { onLossScoreChanged(oldval_lossScore); } } else { if (owner.inWorld) { onLossScoreChanged(oldval_lossScore); } } break; case 7: SByte oldval_state = state; state = stream.readInt8(); if (prop.isBase()) { if (owner.inited) { onStateChanged(oldval_state); } } else { if (owner.inWorld) { onStateChanged(oldval_state); } } break; case 8: Int32 oldval_winScore = winScore; winScore = stream.readInt32(); if (prop.isBase()) { if (owner.inited) { onWinScoreChanged(oldval_winScore); } } else { if (owner.inWorld) { onWinScoreChanged(oldval_winScore); } } 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 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_isNewPlayer = isNewPlayer; isNewPlayer = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsNewPlayerChanged(oldval_isNewPlayer); } } else { if (inWorld) { onIsNewPlayerChanged(oldval_isNewPlayer); } } break; case 4: UInt16 oldval_playerID = playerID; playerID = stream.readUint16(); if (prop.isBase()) { if (inited) { onPlayerIDChanged(oldval_playerID); } } else { if (inWorld) { onPlayerIDChanged(oldval_playerID); } } break; case 2: 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 3: string oldval_playerName = playerName; playerName = stream.readUnicode(); if (prop.isBase()) { if (inited) { onPlayerNameChanged(oldval_playerName); } } else { if (inWorld) { onPlayerNameChanged(oldval_playerName); } } break; case 1: 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 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 15: componentFrameSync.onUpdatePropertys(_t_child_utype, stream, -1); break; default: break; } return; } switch (prop.properUtype) { case 15: componentFrameSync.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 11: SByte oldval_gameStateC = gameStateC; gameStateC = stream.readInt8(); if (prop.isBase()) { if (inited) { onGameStateCChanged(oldval_gameStateC); } } else { if (inWorld) { onGameStateCChanged(oldval_gameStateC); } } break; case 13: Byte oldval_modelID = modelID; modelID = stream.readUint8(); if (prop.isBase()) { if (inited) { onModelIDChanged(oldval_modelID); } } else { if (inWorld) { onModelIDChanged(oldval_modelID); } } break; case 8: float oldval_moveSpeed = moveSpeed; moveSpeed = stream.readFloat(); if (prop.isBase()) { if (inited) { onMoveSpeedChanged(oldval_moveSpeed); } } else { if (inWorld) { onMoveSpeedChanged(oldval_moveSpeed); } } break; case 3: 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 4: Byte oldval_roleType = roleType; roleType = stream.readUint8(); if (prop.isBase()) { if (inited) { onRoleTypeChanged(oldval_roleType); } } else { if (inWorld) { onRoleTypeChanged(oldval_roleType); } } break; case 40002: stream.readUint32(); break; case 9: SByte oldval_state = state; state = stream.readInt8(); if (prop.isBase()) { if (inited) { onStateChanged(oldval_state); } } else { if (inWorld) { onStateChanged(oldval_state); } } break; case 6: Byte oldval_teamID = teamID; teamID = stream.readUint8(); if (prop.isBase()) { if (inited) { onTeamIDChanged(oldval_teamID); } } else { if (inWorld) { onTeamIDChanged(oldval_teamID); } } break; case 5: Int32 oldval_weaponID = weaponID; weaponID = stream.readInt32(); if (prop.isBase()) { if (inited) { onWeaponIDChanged(oldval_weaponID); } } else { if (inWorld) { onWeaponIDChanged(oldval_weaponID); } } break; default: break; } ; } }
public override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.useMethodDescrAlias) { componentPropertyUType = stream.readUint8(); methodUtype = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); methodUtype = stream.readUint16(); } Method method = null; if (componentPropertyUType == 0) { method = sm.idmethods[methodUtype]; } else { Property pComponentPropertyDescription = sm.idpropertys[componentPropertyUType]; switch (pComponentPropertyDescription.properUtype) { case 15: componentFrameSync.onRemoteMethodCall(methodUtype, stream); break; default: break; } return; } switch (method.methodUtype) { case 14: onEnding(); break; case 10: Int32 onPlayerQuitMatch_arg1 = stream.readInt32(); onPlayerQuitMatch(onPlayerQuitMatch_arg1); break; case 12: onReadyForBattle(); break; case 9: MATCHING_INFOS_LIST onResPlayersInfo_arg1 = ((DATATYPE_MATCHING_INFOS_LIST)method.args[0]).createFromStreamEx(stream); onResPlayersInfo(onResPlayersInfo_arg1); break; case 13: onReturnHalls(); break; case 15: Byte onStatisticalResult_arg1 = stream.readUint8(); float onStatisticalResult_arg2 = stream.readFloat(); onStatisticalResult(onStatisticalResult_arg1, onStatisticalResult_arg2); break; case 11: onTeamMateChange(); break; default: break; } ; }
public void Client_onUpdatePropertys(MemoryStream stream) { Int32 eid = stream.readInt32(); 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; } Dictionary<UInt16, Property> pdatas = EntityDef.moduledefs[entity.classtype].idpropertys; while(stream.opsize() > 0) { UInt16 utype = stream.readUint16(); Property propertydata = pdatas[utype]; System.Reflection.MethodInfo setmethod = propertydata.setmethod; object val = propertydata.utype.createFromStream(stream); object oldval = entity.getDefinedProptertyByUType(utype); Dbg.DEBUG_MSG("KBEngine::Client_onUpdatePropertys: " + entity.classtype + "(id=" + eid + " " + propertydata.name + "=" + val + "), hasSetMethod=" + setmethod + "!"); entity.setDefinedProptertyByUType(utype, val); if(setmethod != null) { setmethod.Invoke(entity, new object[]{oldval}); } } }
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 override void onRemoteMethodCall(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Avatar"]; UInt16 methodUtype = 0; UInt16 componentPropertyUType = 0; if (sm.useMethodDescrAlias) { componentPropertyUType = stream.readUint8(); methodUtype = stream.readUint8(); } else { componentPropertyUType = stream.readUint16(); 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 61003: UInt16 canUseWeaponResult_arg1 = stream.readUint16(); Byte canUseWeaponResult_arg2 = stream.readUint8(); canUseWeaponResult(canUseWeaponResult_arg1, canUseWeaponResult_arg2); break; case 17: onJump(); break; case 21: 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; case 22: UInt32 recvPropEffect_arg1 = stream.readUint32(); Int32 recvPropEffect_arg2 = stream.readInt32(); recvPropEffect(recvPropEffect_arg1, recvPropEffect_arg2); break; default: break; } ; }
/* 从二进制流创建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 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 48005: UInt32 oldval_Die_Count = Die_Count; Die_Count = stream.readUint32(); if (prop.isBase()) { if (inited) { onDie_CountChanged(oldval_Die_Count); } } else { if (inWorld) { onDie_CountChanged(oldval_Die_Count); } } break; case 47005: Int32 oldval_EXP = EXP; EXP = stream.readInt32(); if (prop.isBase()) { if (inited) { onEXPChanged(oldval_EXP); } } else { if (inWorld) { onEXPChanged(oldval_EXP); } } break; case 47006: Int32 oldval_EXP_Max = EXP_Max; EXP_Max = stream.readInt32(); if (prop.isBase()) { if (inited) { onEXP_MaxChanged(oldval_EXP_Max); } } else { if (inWorld) { onEXP_MaxChanged(oldval_EXP_Max); } } break; 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 48006: UInt32 oldval_Kill_Count = Kill_Count; Kill_Count = stream.readUint32(); if (prop.isBase()) { if (inited) { onKill_CountChanged(oldval_Kill_Count); } } else { if (inWorld) { onKill_CountChanged(oldval_Kill_Count); } } 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 48003: UInt32 oldval_Rank = Rank; Rank = stream.readUint32(); if (prop.isBase()) { if (inited) { onRankChanged(oldval_Rank); } } else { if (inWorld) { onRankChanged(oldval_Rank); } } break; case 48001: Int32 oldval_Round = Round; Round = stream.readInt32(); if (prop.isBase()) { if (inited) { onRoundChanged(oldval_Round); } } else { if (inWorld) { onRoundChanged(oldval_Round); } } break; case 48002: Int32 oldval_Round_Max = Round_Max; Round_Max = stream.readInt32(); if (prop.isBase()) { if (inited) { onRound_MaxChanged(oldval_Round_Max); } } else { if (inWorld) { onRound_MaxChanged(oldval_Round_Max); } } break; case 48004: UInt32 oldval_Score = Score; Score = stream.readUint32(); if (prop.isBase()) { if (inited) { onScoreChanged(oldval_Score); } } else { if (inWorld) { onScoreChanged(oldval_Score); } } break; case 12: UInt16 oldval_cruiseSpeed = cruiseSpeed; cruiseSpeed = stream.readUint16(); if (prop.isBase()) { if (inited) { onCruiseSpeedChanged(oldval_cruiseSpeed); } } else { if (inWorld) { onCruiseSpeedChanged(oldval_cruiseSpeed); } } 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 41002: UInt16 oldval_level = level; level = stream.readUint16(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_level); } } else { if (inWorld) { onLevelChanged(oldval_level); } } break; case 42006: UInt32 oldval_modelID = modelID; modelID = stream.readUint32(); if (prop.isBase()) { if (inited) { onModelIDChanged(oldval_modelID); } } else { if (inWorld) { onModelIDChanged(oldval_modelID); } } break; case 42007: Byte oldval_modelScale = modelScale; modelScale = stream.readUint8(); if (prop.isBase()) { if (inited) { onModelScaleChanged(oldval_modelScale); } } else { if (inWorld) { onModelScaleChanged(oldval_modelScale); } } break; case 11: UInt16 oldval_moveSpeed = moveSpeed; moveSpeed = stream.readUint16(); if (prop.isBase()) { if (inited) { onMoveSpeedChanged(oldval_moveSpeed); } } else { if (inWorld) { onMoveSpeedChanged(oldval_moveSpeed); } } break; case 42003: 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 42008: UInt32 oldval_spaceUType = spaceUType; spaceUType = stream.readUint32(); if (prop.isBase()) { if (inited) { onSpaceUTypeChanged(oldval_spaceUType); } } else { if (inWorld) { onSpaceUTypeChanged(oldval_spaceUType); } } break; case 44006: SByte oldval_state = state; state = stream.readInt8(); if (prop.isBase()) { if (inited) { onStateChanged(oldval_state); } } else { if (inWorld) { onStateChanged(oldval_state); } } break; case 42004: UInt32 oldval_uid = uid; uid = stream.readUint32(); if (prop.isBase()) { if (inited) { onUidChanged(oldval_uid); } } else { if (inWorld) { onUidChanged(oldval_uid); } } break; case 42005: 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 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 override bool recv(MessageReaderBase reader, byte[] buffer, UInt32 rpos, UInt32 len) { if (!_blowfish.isGood()) { Dbg.ERROR_MSG("BlowfishFilter::recv: Dropping packet, due to invalid filter"); return(false); } if (_packet.length() == 0 && len >= MIN_PACKET_SIZE && BitConverter.ToUInt16(buffer, (int)rpos) - 1 == len - 3) { int packLen = BitConverter.ToUInt16(buffer, (int)rpos) - 1; int padSize = buffer[rpos + 2]; decrypt(buffer, (int)(rpos + 3), (int)(len - 3)); int length = packLen - padSize; if (reader != null) { reader.process(buffer, rpos + 3, (UInt32)length); } return(true); } _packet.append(buffer, rpos, len); while (_packet.length() > 0) { UInt32 currLen = 0; int oldwpos = 0; if (_packLen <= 0) { // 如果满足一个最小包则尝试解包, 否则缓存这个包待与下一个包合并然后解包 if (_packet.length() >= MIN_PACKET_SIZE) { _packLen = _packet.readUint16(); _padSize = _packet.readUint8(); _packLen -= 1; if (_packet.length() > _packLen) { currLen = (UInt32)(_packet.rpos + _packLen); oldwpos = _packet.wpos; _packet.wpos = (int)currLen; } else if (_packet.length() < _packLen) { return(false); } } else { return(false); } } else { // 如果上一次有做过解包行为但包还没有完整则继续处理 // 如果包是完整的下面流程会解密, 如果有多余的内容需要将其剪裁出来待与下一个包合并 if (_packet.length() > _packLen) { currLen = (UInt32)(_packet.rpos + _packLen); oldwpos = _packet.wpos; _packet.wpos = (int)currLen; } else if (_packet.length() < _packLen) { return(false); } } decrypt(_packet); _packet.wpos -= _padSize; // 上面的流程能保证wpos之后不会有多余的包 // 如果有多余的包数据会放在_recvStream if (reader != null) { reader.process(_packet.data(), (UInt32)_packet.rpos, _packet.length()); } if (currLen > 0) { _packet.rpos = (int)currLen; _packet.wpos = oldwpos; } else { _packet.clear(); } _packLen = 0; _padSize = 0; } return(true); }
/* 登录loginapp失败了 */ public void Client_onLoginFailed(MemoryStream stream) { UInt16 failedcode = stream.readUint16(); _serverdatas = stream.readBlob(); Dbg.ERROR_MSG("KBEngine::Client_onLoginFailed: failedcode(" + failedcode + "), datas(" + _serverdatas.Length + ")!"); Event.fireAll("onLoginFailed", new object[]{failedcode}); }
public override void onUpdatePropertys(Property prop, MemoryStream stream) { switch (prop.properUtype) { case 21: UInt16 oldval_anYeYiYangGold = anYeYiYangGold; anYeYiYangGold = stream.readUint16(); if (prop.isBase()) { if (inited) { onAnYeYiYangGoldChanged(oldval_anYeYiYangGold); } } else { if (inWorld) { onAnYeYiYangGoldChanged(oldval_anYeYiYangGold); } } break; case 18: string oldval_animState = animState; animState = stream.readUnicode(); if (prop.isBase()) { if (inited) { onAnimStateChanged(oldval_animState); } } else { if (inWorld) { onAnimStateChanged(oldval_animState); } } 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 13: UInt16 oldval_goldNum = goldNum; goldNum = stream.readUint16(); if (prop.isBase()) { if (inited) { onGoldNumChanged(oldval_goldNum); } } else { if (inWorld) { onGoldNumChanged(oldval_goldNum); } } break; case 20: UInt16 oldval_jiaSuGold = jiaSuGold; jiaSuGold = stream.readUint16(); if (prop.isBase()) { if (inited) { onJiaSuGoldChanged(oldval_jiaSuGold); } } else { if (inWorld) { onJiaSuGoldChanged(oldval_jiaSuGold); } } break; case 19: UInt16 oldval_keepJiaSuTime = keepJiaSuTime; keepJiaSuTime = stream.readUint16(); if (prop.isBase()) { if (inited) { onKeepJiaSuTimeChanged(oldval_keepJiaSuTime); } } else { if (inWorld) { onKeepJiaSuTimeChanged(oldval_keepJiaSuTime); } } break; case 14: float oldval_moveSpeed = moveSpeed; moveSpeed = stream.readFloat(); if (prop.isBase()) { if (inited) { onMoveSpeedChanged(oldval_moveSpeed); } } else { if (inWorld) { onMoveSpeedChanged(oldval_moveSpeed); } } break; case 16: string oldval_name = name; name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_name); } } else { if (inWorld) { onNameChanged(oldval_name); } } break; case 23: UInt16 oldval_nanShangJiaNanGold = nanShangJiaNanGold; nanShangJiaNanGold = stream.readUint16(); if (prop.isBase()) { if (inited) { onNanShangJiaNanGoldChanged(oldval_nanShangJiaNanGold); } } else { if (inWorld) { onNanShangJiaNanGoldChanged(oldval_nanShangJiaNanGold); } } 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 12: Byte oldval_track = track; track = stream.readUint8(); if (prop.isBase()) { if (inited) { onTrackChanged(oldval_track); } } else { if (inWorld) { onTrackChanged(oldval_track); } } break; case 22: UInt16 oldval_xiaCiYiDingGold = xiaCiYiDingGold; xiaCiYiDingGold = stream.readUint16(); if (prop.isBase()) { if (inited) { onXiaCiYiDingGoldChanged(oldval_xiaCiYiDingGold); } } else { if (inWorld) { onXiaCiYiDingGoldChanged(oldval_xiaCiYiDingGold); } } 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) { 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 override void onUpdatePropertys(Property prop, MemoryStream stream) { switch (prop.properUtype) { case 4: FRIEND_INFO_LIST oldval_Friend_list = Friend_list; Friend_list = ((DATATYPE_FRIEND_INFO_LIST)EntityDef.id2datatypes[23]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onFriend_listChanged(oldval_Friend_list); } } else { if (inWorld) { onFriend_listChanged(oldval_Friend_list); } } break; case 3: UInt16 oldval_Icon = Icon; Icon = stream.readUint16(); if (prop.isBase()) { if (inited) { onIconChanged(oldval_Icon); } } else { if (inWorld) { onIconChanged(oldval_Icon); } } break; case 2: Byte oldval_Level = Level; Level = stream.readUint8(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_Level); } } else { if (inWorld) { onLevelChanged(oldval_Level); } } break; case 1: string oldval_Name = Name; Name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameChanged(oldval_Name); } } else { if (inWorld) { onNameChanged(oldval_Name); } } 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 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 object createFromStream(MemoryStream stream) { return(stream.readUint16()); }
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 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["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 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(); } } }
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 17: Byte oldval_CrystalAvaliable = CrystalAvaliable; CrystalAvaliable = stream.readUint8(); if (prop.isBase()) { if (inited) { onCrystalAvaliableChanged(oldval_CrystalAvaliable); } } else { if (inWorld) { onCrystalAvaliableChanged(oldval_CrystalAvaliable); } } break; case 16: Byte oldval_CrystalSum = CrystalSum; CrystalSum = stream.readUint8(); if (prop.isBase()) { if (inited) { onCrystalSumChanged(oldval_CrystalSum); } } else { if (inWorld) { onCrystalSumChanged(oldval_CrystalSum); } } break; case 21: Int16 oldval_HP = HP; HP = stream.readInt16(); if (prop.isBase()) { if (inited) { onHPChanged(oldval_HP); } } else { if (inWorld) { onHPChanged(oldval_HP); } } break; case 11: string oldval_NameA = NameA; NameA = stream.readUnicode(); if (prop.isBase()) { if (inited) { onNameAChanged(oldval_NameA); } } else { if (inWorld) { onNameAChanged(oldval_NameA); } } break; case 12: Byte oldval_RoleType = RoleType; RoleType = stream.readUint8(); if (prop.isBase()) { if (inited) { onRoleTypeChanged(oldval_RoleType); } } else { if (inWorld) { onRoleTypeChanged(oldval_RoleType); } } break; case 13: Byte oldval_Situation = Situation; Situation = stream.readUint8(); if (prop.isBase()) { if (inited) { onSituationChanged(oldval_Situation); } } else { if (inWorld) { onSituationChanged(oldval_Situation); } } break; case 23: UInt16 oldval_armor = armor; armor = stream.readUint16(); if (prop.isBase()) { if (inited) { onArmorChanged(oldval_armor); } } else { if (inWorld) { onArmorChanged(oldval_armor); } } break; case 22: UInt16 oldval_att = att; att = stream.readUint16(); if (prop.isBase()) { if (inited) { onAttChanged(oldval_att); } } else { if (inWorld) { onAttChanged(oldval_att); } } break; case 24: UInt16 oldval_attSum = attSum; attSum = stream.readUint16(); if (prop.isBase()) { if (inited) { onAttSumChanged(oldval_attSum); } } else { if (inWorld) { onAttSumChanged(oldval_attSum); } } break; case 20: UInt32 oldval_cardID = cardID; cardID = stream.readUint32(); if (prop.isBase()) { if (inited) { onCardIDChanged(oldval_cardID); } } else { if (inWorld) { onCardIDChanged(oldval_cardID); } } break; case 25: UInt16 oldval_cost = cost; cost = stream.readUint16(); if (prop.isBase()) { if (inited) { onCostChanged(oldval_cost); } } else { if (inWorld) { onCostChanged(oldval_cost); } } 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 36: Byte oldval_frozen = frozen; frozen = stream.readUint8(); if (prop.isBase()) { if (inited) { onFrozenChanged(oldval_frozen); } } else { if (inWorld) { onFrozenChanged(oldval_frozen); } } break; case 37: Byte oldval_immune = immune; immune = stream.readUint8(); if (prop.isBase()) { if (inited) { onImmuneChanged(oldval_immune); } } else { if (inWorld) { onImmuneChanged(oldval_immune); } } break; case 34: Byte oldval_isAbled = isAbled; isAbled = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsAbledChanged(oldval_isAbled); } } else { if (inWorld) { onIsAbledChanged(oldval_isAbled); } } break; case 33: Byte oldval_isDivineShield = isDivineShield; isDivineShield = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsDivineShieldChanged(oldval_isDivineShield); } } else { if (inWorld) { onIsDivineShieldChanged(oldval_isDivineShield); } } break; case 31: Byte oldval_isRush = isRush; isRush = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsRushChanged(oldval_isRush); } } else { if (inWorld) { onIsRushChanged(oldval_isRush); } } break; case 35: Byte oldval_isStealth = isStealth; isStealth = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsStealthChanged(oldval_isStealth); } } else { if (inWorld) { onIsStealthChanged(oldval_isStealth); } } break; case 30: Byte oldval_isTaunt = isTaunt; isTaunt = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsTauntChanged(oldval_isTaunt); } } else { if (inWorld) { onIsTauntChanged(oldval_isTaunt); } } break; case 32: Byte oldval_isWindfury = isWindfury; isWindfury = stream.readUint8(); if (prop.isBase()) { if (inited) { onIsWindfuryChanged(oldval_isWindfury); } } else { if (inWorld) { onIsWindfuryChanged(oldval_isWindfury); } } break; case 29: Byte oldval_maxHP = maxHP; maxHP = stream.readUint8(); if (prop.isBase()) { if (inited) { onMaxHPChanged(oldval_maxHP); } } else { if (inWorld) { onMaxHPChanged(oldval_maxHP); } } break; case 27: Byte oldval_playerID = playerID; playerID = stream.readUint8(); if (prop.isBase()) { if (inited) { onPlayerIDChanged(oldval_playerID); } } else { if (inWorld) { onPlayerIDChanged(oldval_playerID); } } break; case 28: string oldval_pos = pos; pos = stream.readUnicode(); if (prop.isBase()) { if (inited) { onPosChanged(oldval_pos); } } else { if (inWorld) { onPosChanged(oldval_pos); } } 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 26: UInt16 oldval_type = type; type = stream.readUint16(); if (prop.isBase()) { if (inited) { onTypeChanged(oldval_type); } } else { if (inWorld) { onTypeChanged(oldval_type); } } break; default: break; } ; } }
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 process(byte[] datas, MessageLengthEx offset, MessageLengthEx length) { MessageLengthEx totallen = offset; while (length > 0 && expectSize > 0) { if (state == READ_STATE.READ_STATE_MSGID) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; msgid = stream.readUint16(); stream.clear(); Message msg = Messages.clientMessages[msgid]; if (msg.msglen == -1) { state = READ_STATE.READ_STATE_MSGLEN; expectSize = 2; } else if (msg.msglen == 0) { // 如果是0个参数的消息,那么没有后续内容可读了,处理本条消息并且直接跳到下一条消息 #if UNITY_EDITOR Dbg.profileStart(msg.name); #endif msg.handleMessage(stream); #if UNITY_EDITOR Dbg.profileEnd(msg.name); #endif state = READ_STATE.READ_STATE_MSGID; expectSize = 2; } else { expectSize = (MessageLengthEx)msg.msglen; state = READ_STATE.READ_STATE_BODY; } } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_MSGLEN) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; msglen = stream.readUint16(); stream.clear(); // 长度扩展 if (msglen >= 65535) { state = READ_STATE.READ_STATE_MSGLEN_EX; expectSize = 4; } else { state = READ_STATE.READ_STATE_BODY; expectSize = msglen; } } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_MSGLEN_EX) { if (length >= expectSize) { Array.Copy(datas, totallen, stream.data(), stream.wpos, expectSize); totallen += expectSize; stream.wpos += (int)expectSize; length -= expectSize; expectSize = stream.readUint32(); stream.clear(); state = READ_STATE.READ_STATE_BODY; } else { Array.Copy(datas, totallen, stream.data(), stream.wpos, length); stream.wpos += (int)length; expectSize -= length; break; } } else if (state == READ_STATE.READ_STATE_BODY) { if (length >= expectSize) { stream.append(datas, totallen, expectSize); totallen += expectSize; length -= expectSize; Message msg = Messages.clientMessages[msgid]; #if UNITY_EDITOR Dbg.profileStart(msg.name); #endif msg.handleMessage(stream); #if UNITY_EDITOR Dbg.profileEnd(msg.name); #endif stream.clear(); state = READ_STATE.READ_STATE_MSGID; expectSize = 2; } else { stream.append(datas, totallen, length); expectSize -= length; break; } } } }
public void Client_onImportMercuryErrorsDescr(MemoryStream stream) { UInt16 size = stream.readUint16(); while(size > 0) { size -= 1; MercuryErr e; e.id = stream.readUint16(); e.name = stream.readString(); e.descr = stream.readString(); mercuryErrs.Add(e.id, e); Dbg.DEBUG_MSG("Client_onImportMercuryErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } }
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 6: component1.onUpdatePropertys(_t_child_utype, stream, -1); break; default: break; } return; } switch (prop.properUtype) { case 6: component1.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 41002: UInt16 oldval_level = level; level = stream.readUint16(); if (prop.isBase()) { if (inited) { onLevelChanged(oldval_level); } } else { if (inWorld) { onLevelChanged(oldval_level); } } 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; default: break; } ; } }
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["Room"]; 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 11: Byte oldval_RoomType = RoomType; RoomType = stream.readUint8(); if (prop.isBase()) { if (inited) { onRoomTypeChanged(oldval_RoomType); } } else { if (inWorld) { onRoomTypeChanged(oldval_RoomType); } } break; case 15: Byte oldval_cur_turn = cur_turn; cur_turn = stream.readUint8(); if (prop.isBase()) { if (inited) { onCur_turnChanged(oldval_cur_turn); } } else { if (inWorld) { onCur_turnChanged(oldval_cur_turn); } } 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 14: Byte oldval_numOfMJ = numOfMJ; numOfMJ = stream.readUint8(); if (prop.isBase()) { if (inited) { onNumOfMJChanged(oldval_numOfMJ); } } else { if (inWorld) { onNumOfMJChanged(oldval_numOfMJ); } } break; case 13: Byte oldval_playerMaxCount = playerMaxCount; playerMaxCount = stream.readUint8(); if (prop.isBase()) { if (inited) { onPlayerMaxCountChanged(oldval_playerMaxCount); } } else { if (inWorld) { onPlayerMaxCountChanged(oldval_playerMaxCount); } } 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 16: ROOM_PUBLIC_INFO oldval_public_roomInfo = public_roomInfo; public_roomInfo = ((DATATYPE_ROOM_PUBLIC_INFO)EntityDef.id2datatypes[26]).createFromStreamEx(stream); if (prop.isBase()) { if (inited) { onPublic_roomInfoChanged(oldval_public_roomInfo); } } else { if (inWorld) { onPublic_roomInfoChanged(oldval_public_roomInfo); } } break; case 10: UInt64 oldval_roomKey = roomKey; roomKey = stream.readUint64(); if (prop.isBase()) { if (inited) { onRoomKeyChanged(oldval_roomKey); } } else { if (inWorld) { onRoomKeyChanged(oldval_roomKey); } } break; case 40002: stream.readUint32(); 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.readUint16(); }
/* 服务端错误描述导入了 */ public void onImportServerErrorsDescr(MemoryStream stream) { UInt16 size = stream.readUint16(); while(size > 0) { size -= 1; ServerErr e; e.id = stream.readUint16(); e.name = System.Text.Encoding.UTF8.GetString(stream.readBlob()); e.descr = System.Text.Encoding.UTF8.GetString(stream.readBlob()); serverErrs.Add(e.id, e); //Dbg.DEBUG_MSG("Client_onImportServerErrorsDescr: id=" + e.id + ", name=" + e.name + ", descr=" + e.descr); } }
public override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Spaces"]; 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 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 override void onUpdatePropertys(MemoryStream stream) { ScriptModule sm = EntityDef.moduledefs["Chess"]; 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 11: UInt64 oldval_chess_attack = chess_attack; chess_attack = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_attackChanged(oldval_chess_attack); } } else { if (inWorld) { onChess_attackChanged(oldval_chess_attack); } } break; case 12: UInt64 oldval_chess_defense = chess_defense; chess_defense = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_defenseChanged(oldval_chess_defense); } } else { if (inWorld) { onChess_defenseChanged(oldval_chess_defense); } } break; case 6: UInt64 oldval_chess_id = chess_id; chess_id = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_idChanged(oldval_chess_id); } } else { if (inWorld) { onChess_idChanged(oldval_chess_id); } } break; case 9: UInt64 oldval_chess_index_x = chess_index_x; chess_index_x = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_index_xChanged(oldval_chess_index_x); } } else { if (inWorld) { onChess_index_xChanged(oldval_chess_index_x); } } break; case 10: UInt64 oldval_chess_index_z = chess_index_z; chess_index_z = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_index_zChanged(oldval_chess_index_z); } } else { if (inWorld) { onChess_index_zChanged(oldval_chess_index_z); } } break; case 7: UInt64 oldval_chess_level = chess_level; chess_level = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_levelChanged(oldval_chess_level); } } else { if (inWorld) { onChess_levelChanged(oldval_chess_level); } } break; case 8: string oldval_chess_name = chess_name; chess_name = stream.readUnicode(); if (prop.isBase()) { if (inited) { onChess_nameChanged(oldval_chess_name); } } else { if (inWorld) { onChess_nameChanged(oldval_chess_name); } } break; case 13: UInt64 oldval_chess_owner_player = chess_owner_player; chess_owner_player = stream.readUint64(); if (prop.isBase()) { if (inited) { onChess_owner_playerChanged(oldval_chess_owner_player); } } else { if (inWorld) { onChess_owner_playerChanged(oldval_chess_owner_player); } } 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 14: UInt64 oldval_max_hp = max_hp; max_hp = stream.readUint64(); if (prop.isBase()) { if (inited) { onMax_hpChanged(oldval_max_hp); } } else { if (inWorld) { onMax_hpChanged(oldval_max_hp); } } 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; } ; } }
/* 服务端通知一个实体进入了世界(如果实体是当前玩家则玩家第一次在一个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 onUpdatePropertys(Property prop, MemoryStream stream) { 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 24: UInt16 oldval_goldValue = goldValue; goldValue = stream.readUint16(); if (prop.isBase()) { if (inited) { onGoldValueChanged(oldval_goldValue); } } else { if (inWorld) { onGoldValueChanged(oldval_goldValue); } } break; case 25: 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; default: break; } ; }
/* 登录loginapp成功了 */ public void Client_onLoginSuccessfully(MemoryStream stream) { var accountName = stream.readString(); username = accountName; baseappIP = stream.readString(); baseappPort = stream.readUint16(); Dbg.DEBUG_MSG("KBEngine::Client_onLoginSuccessfully: accountName(" + accountName + "), addr(" + baseappIP + ":" + baseappPort + "), datas(" + _serverdatas.Length + ")!"); _serverdatas = stream.readBlob(); login_baseapp(true); }
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 20: Int32 onBuyEquip_arg1 = stream.readInt32(); Byte onBuyEquip_arg2 = stream.readUint8(); onBuyEquip(onBuyEquip_arg1, onBuyEquip_arg2); break; case 21: Int32 onChangeEquip_arg1 = stream.readInt32(); Byte onChangeEquip_arg2 = stream.readUint8(); onChangeEquip(onChangeEquip_arg1, onChangeEquip_arg2); break; case 19: Int32 onExitRoom_arg1 = stream.readInt32(); onExitRoom(onExitRoom_arg1); break; case 22: Int32 onGetGold_arg1 = stream.readInt32(); onGetGold(onGetGold_arg1); break; case 17: Int32 onGetPropsClient_arg1 = stream.readInt32(); string onGetPropsClient_arg2 = stream.readUnicode(); Int32 onGetPropsClient_arg3 = stream.readInt32(); onGetPropsClient(onGetPropsClient_arg1, onGetPropsClient_arg2, onGetPropsClient_arg3); break; case 14: Int32 onLoginState_arg1 = stream.readInt32(); onLoginState(onLoginState_arg1); break; case 15: Int32 onMapModeChanged_arg1 = stream.readInt32(); Int32 onMapModeChanged_arg2 = stream.readInt32(); onMapModeChanged(onMapModeChanged_arg1, onMapModeChanged_arg2); break; case 16: Int32 onMatchingFinish_arg1 = stream.readInt32(); onMatchingFinish(onMatchingFinish_arg1); break; case 18: Int32 onUseProp_arg1 = stream.readInt32(); Int32 onUseProp_arg2 = stream.readInt32(); Int32 onUseProp_arg3 = stream.readInt32(); Vector3 onUseProp_arg4 = stream.readVector3(); onUseProp(onUseProp_arg1, onUseProp_arg2, onUseProp_arg3, onUseProp_arg4); break; default: break; } ; }