public void AddTempPlayObject(GameBase.Network.Internal.RoleInfo info) { TempPlayObject temp = new TempPlayObject(); PlayerObject play = new PlayerObject(); temp.play = play; temp.key = info.mKey; temp.key2 = info.mKey1; temp.isRole = info.isRole; temp.accountid = info.accountid; //基本属性 m_DicTempPlayObject[play.GetGameID()] = temp; if (temp.isRole) { play.SetName(info.name); GameStruct.PlayerAttribute attr = play.GetBaseAttr(); attr.account_id = info.accountid; attr.player_id = info.playerid; attr.mana = info.mana; attr.lookface = info.lookface; attr.hair = info.hair; attr.profession = info.profession; attr.level = info.lv; attr.exp = (int)info.exp; attr.life = info.life; attr.pk = info.pk; attr.gold = info.gold; attr.gamegold = info.gamegold; attr.stronggold = info.stronggold; attr.mapid = (uint)info.mapid; attr.guanjue = info.guanjue; attr.sAccount = info.sAccount; attr.godlevel = (byte)info.godlevel; attr.maxeudemon = info.maxeudemon; play.SetHotKeyInfo(info.hotkey); play.CalcSex(); play.SetPoint(info.x, info.y); //官爵信息 GameStruct.GUANGJUELEVEL gjlevel = GuanJueManager.Instance().GetLevel(play); play.SetGuanJue(gjlevel); //初始化军团信息 play.GetLegionSystem().Init(); } }
public void ProcessDBNetMsg() { if (!mbConnect && System.Environment.TickCount - mnReconnectTick > 5000)//五秒重连 { mTcpDBClient.ReConnect(); mnReconnectTick = System.Environment.TickCount; } byte[] buff = null; lock (_lock) { buff = mDBPacket.GetData(); } if (buff == null) { return; } PackIn inpack = new PackIn(buff); ushort param = inpack.ReadUInt16(); switch (param) { case GameBase.Network.Internal.Define.ROLEINFO: { GameBase.Network.Internal.RoleInfo roleinfo = new GameBase.Network.Internal.RoleInfo(buff); //判断是否有缓存数据- PlayerObject cacheplay = UserEngine.Instance().GetCachePlay(roleinfo.sAccount); if (cacheplay != null) { Log.Instance().WriteLog("检测到角色缓存数据,保存中!" + cacheplay.GetName()); UserEngine.Instance().RemoveCachePlay(cacheplay); cacheplay.ExitGame(); return; } UserEngine.Instance().AddTempPlayObject(roleinfo); //回发给dbserver 表示收到了角色信息- 让他通知loginserver 发数据给玩家连接mapserver GameBase.Network.Internal.RoleInfo_Ret ret = new GameBase.Network.Internal.RoleInfo_Ret(); ret.gameid = roleinfo.gameid; ret.key = roleinfo.mKey; ret.key2 = roleinfo.mKey1; ret.accountid = roleinfo.accountid; mTcpDBClient.SendData(ret.GetBuffer()); Log.Instance().WriteLog("收到临时角色信息:" + roleinfo.sAccount + " id:" + roleinfo.accountid.ToString()); break; } case GameBase.Network.Internal.Define.QUERYROLENAME_RET: { QueryRoleName_Ret ret = new QueryRoleName_Ret(); ret.Create(buff); TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(ret.gameid); if (temp == null) { Log.Instance().WriteLog("找到玩家对象..在--ProcessDBNetMsg code:2"); break; } NetMsg.MsgNotice notice = new NetMsg.MsgNotice(); notice.Create(null, temp.play.GetGamePackKeyEx()); temp.play.SendData(notice.GetQueryNameBuff(!ret.tag)); break; } case GameBase.Network.Internal.Define.CREATEROLE_RET: { CreateRole_Ret ret = new CreateRole_Ret(); ret.Create(buff); TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(ret.gameid); if (temp == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:3"); break; } UserEngine.Instance().RemoveTempPlayObject(ret.gameid); //从临时列表出移除-- //进入游戏 temp.play.GetBaseAttr().account_id = temp.accountid; temp.play.GetBaseAttr().player_id = ret.playerid; temp.play.EnterGame(null, true); break; } case GameBase.Network.Internal.Define.ADDROLEDATA_ITEM_RET: { GameBase.Network.Internal.AddRoleData_Item_Ret ret = new GameBase.Network.Internal.AddRoleData_Item_Ret(); ret.Create(buff); PlayerObject play = UserEngine.Instance().FindPlayerObjectToID(ret.gameid); if (play == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:4"); break; } play.GetItemSystem().AwardItem_Ret(ret.sordid, ret.id); break; } case GameBase.Network.Internal.Define.LOADROLEDATA_ITEM: { GameBase.Network.Internal.ROLEDATA_ITEM item = new GameBase.Network.Internal.ROLEDATA_ITEM(); item.Create(buff); TempPlayObject play = UserEngine.Instance().GetTempPlayObj(item.key, item.key2); if (play == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:5"); break; } for (int i = 0; i < item.mListItem.Count; i++) { play.play.GetItemSystem().AddItemInfo(item.mListItem[i]); } break; } case GameBase.Network.Internal.Define.LOADROLEDATA_MAGIC: { GameBase.Network.Internal.RoleData_Magic magic = new GameBase.Network.Internal.RoleData_Magic(); magic.Create(buff); TempPlayObject play = UserEngine.Instance().GetTempPlayObj(magic.key, magic.key2); if (play == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:6"); break; } for (int i = 0; i < magic.mListMagic.Count; i++) { GameBase.Network.Internal.MagicInfo info = magic.mListMagic[i]; play.play.GetMagicSystem().AddMagicInfo(info); } break; } case GameBase.Network.Internal.Define.KICKGAMEPLAY: { GameBase.Network.Internal.KickGamePlay kickplay = new GameBase.Network.Internal.KickGamePlay(); kickplay.Create(buff); PlayerObject play = UserEngine.Instance().FindPlayerObjectToAccountId(kickplay.accountid); if (play != null) { SessionManager.Instance().RemoveSession(play.GetGameSession().m_Socket); play.Kick(); } break; } case GameBase.Network.Internal.Define.LOADROLEDATA_EUDEMON: { GameBase.Network.Internal.ROLEDATE_EUDEMON eudemon = new GameBase.Network.Internal.ROLEDATE_EUDEMON(); eudemon.Create(buff); TempPlayObject play = UserEngine.Instance().GetTempPlayObj(eudemon.key, eudemon.key2); if (play == null) { //只是为了下断点后延迟问题解决方案 PlayerObject _play = UserEngine.Instance().FindPlayerObjectToPlayerId(eudemon.playerid); if (_play == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:6"); } else { _play.GetEudemonSystem().DB_Load(eudemon); _play.GetEudemonSystem().SendAllEudemonInfo(); } break; } else { play.play.GetEudemonSystem().DB_Load(eudemon); } break; } case GameBase.Network.Internal.Define.LOADROLEDATA_FRIEND: { GameBase.Network.Internal.ROLEDATA_FRIEND friend = new GameBase.Network.Internal.ROLEDATA_FRIEND(); friend.Create(buff); TempPlayObject play = UserEngine.Instance().GetTempPlayObj(friend.key, friend.key2); if (play == null) { //只是为了下断点后延迟问题解决方案 PlayerObject _play = UserEngine.Instance().FindPlayerObjectToPlayerId(friend.playerid); if (_play == null) { Log.Instance().WriteLog("未找到玩家对象..在--ProcessDBNetMsg code:7"); } else { _play.GetFriendSystem().DB_Load(friend); _play.GetFriendSystem().SendAllFriendInfo(); } break; } else { play.play.GetFriendSystem().DB_Load(friend); } break; } case GameBase.Network.Internal.Define.GUANJUEDATA: //爵位数据 { GameBase.Network.Internal.GUANJUEINFO juewei = new GameBase.Network.Internal.GUANJUEINFO(); juewei.Create(buff); GuanJueManager.Instance().DB_Load(juewei); break; } case GameBase.Network.Internal.Define.LOADLEGION: //军团数据 { GameBase.Network.Internal.LEGIONINFO info = new GameBase.Network.Internal.LEGIONINFO(); info.Create(buff); LegionManager.Instance().DB_Load(info); break; } case GameBase.Network.Internal.Define.CREATELEGION_RET: //创建军团返回数据 { GameBase.Network.Internal.CreateLegion_Ret info = new GameBase.Network.Internal.CreateLegion_Ret(); info.Create(buff); LegionManager.Instance().CreateLegion_Ret(info); break; } case GameBase.Network.Internal.Define.LOADPAYRECINFO: //充值数据 { GameBase.Network.Internal.PackPayRecInfo info = new GameBase.Network.Internal.PackPayRecInfo(); info.Creaet(buff); PayManager.Instance().DB_Load(info); break; } } }
public void ProcessNetMsg() { foreach (GameSession session in m_DicSession.Values) { if (session == null || session.m_GamePack == null) { continue; } byte[] retdata = session.m_GamePack.GetData(); if (retdata != null) { GameBase.Network.PackIn packin = new GameBase.Network.PackIn(retdata); PlayerObject play = UserEngine.Instance().FindPlayerObjectToID(session.gameid); ushort tag = packin.ReadUInt16(); if (play != null) { play.ProcessNetMsg(tag, retdata); continue; } //第一次的封包一定是更新key哒.. if (play == null && tag != PacketProtoco.C_UPDATEKEY && tag != PacketProtoco.C_QUERYCREATEROLENAME && tag != PacketProtoco.C_CREATEROLE) { continue; } switch (tag) { case PacketProtoco.C_UPDATEKEY: { int key = packin.ReadInt32(); int key2 = packin.ReadInt32(); TempPlayObject tempplay = UserEngine.Instance().GetTempPlayObj(key, key2); if (tempplay == null) { return; //没有经过loginsserver进入的非法封包 } tempplay.play.SetGameSession(session); session.GetGamePackKeyEx().SunUpdateKey(key, key2); NetMsg.MsgNotice msgNotice; //没有角色就创建角色 if (!tempplay.isRole) { msgNotice = new NetMsg.MsgNotice(); msgNotice.Create(null, session.GetGamePackKeyEx()); session.SendData(msgNotice.GetCreateRoleBuff()); return; } //有角色就进游戏 UserEngine.Instance().RemoveTempPlayObject(tempplay.play.GetGameID()); tempplay.play.EnterGame(session); break; } case PacketProtoco.C_QUERYCREATEROLENAME: //创建角色名查询 { NetMsg.MsgQueryCreateRoleName info = new NetMsg.MsgQueryCreateRoleName(); info.Create(retdata, null); int key = 0, key2 = 0; session.GetGamePackKeyEx().GetKey(ref key, ref key2); TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(key, key2); if (temp == null) { Log.Instance().WriteLog("找到玩家对象-在ProcessNetMsg code:1"); break; } //发给dbserver 查询 GameBase.Network.Internal.QueryRoleName query = new GameBase.Network.Internal.QueryRoleName(); query.gameid = temp.play.GetGameID(); query.name = info.GetName(); DBServer.Instance().GetDBClient().SendData(query.GetBuffer()); //NetMsg.MsgNotice notice = new NetMsg.MsgNotice(); //notice.Create(null, session.GetGamePackKeyEx()); //session.SendData(notice.GetQueryNameBuff()); break; } case PacketProtoco.C_CREATEROLE: //创建角色 { int key = 0, key2 = 0; session.GetGamePackKeyEx().GetKey(ref key, ref key2); TempPlayObject temp = UserEngine.Instance().GetTempPlayObj(key, key2); if (temp == null) { Log.Instance().WriteLog("找到玩家对象-在ProcessNetMsg code:2"); break; } NetMsg.MsgCreateRoleInfo info = new NetMsg.MsgCreateRoleInfo(); info.Create(retdata, null); if (info.GetName().Length <= 0) { Log.Instance().WriteLog("角色名称为空!!"); break; } PlayerObject _play = temp.play; _play.SetGameSession(session); _play.SetName(info.GetName()); _play.GetBaseAttr().profession = (byte)info.profession; _play.GetBaseAttr().lookface = info.lookface; //发给dbserver GameBase.Network.Internal.CreateRole create = new GameBase.Network.Internal.CreateRole(); create.accountid = temp.accountid; create.lookface = info.lookface; create.name = info.GetName(); create.profession = (byte)info.profession; create.gameid = temp.play.GetGameID(); DBServer.Instance().GetDBClient().SendData(create.GetBuffer()); //测试游戏 //play = new PlayerObject(); //play.mapid = 1000; //play.mPoint.x = 400; //play.mPoint.y = 440; //session.gameid = play.GetGameID(); //MapManager.Instance().GetGameMapToID(play.mapid).AddObject(play, session); //UserEngine.Instance().AddPlayerObject(play); ////公告信息 //NetMsg.MsgNotice msgNotice = new NetMsg.MsgNotice(); //msgNotice.Create(null, session.GetGamePackKeyEx()); //session.SendData(msgNotice.GetStartGameBuff()); //byte[] roledata = {238, 3, 64, 66, 15, 0, 241, 73, 2, 0, 101, // 0, 0, 0, 60, 1, 0, 0, 0, 0, 0, 0, 81, 118, // 203, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 31, 1, 0, 0, 73, 0, 0, 0, 30, 0, 100, 0, 99, // 0, 102, 0, 0, 0, 202, 3, 222, 3, 134, 7, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 255, 10, 0, 0, 1, 0, 0, // 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 12, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 20, 0, 4, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 105, // 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 2, 8, 102, 101, 111, 119, 102, 113, 101, 119, 2, // 206, 222, 0, 0, 0 }; ////session.GetGamePackKeyEx().EncodePacket(ref roledata, roledata.Length); ////session.SendData(roledata); //// //NetMsg.MsgSelfRoleInfo rolemsg = new NetMsg.MsgSelfRoleInfo(); //rolemsg.Create(roledata, session.GetGamePackKeyEx()); //rolemsg.roletype = 140001; //rolemsg.roleid = play.GetTypeId(); //rolemsg.name = "测试角色" + play.GetTypeId().ToString(); //play.Name = rolemsg.name; //session.SendData(rolemsg.GetBuffer()); ////测试增加装备 测试装备 //NetMsg.MsgItemInfo item = new NetMsg.MsgItemInfo(); //item.Create(null, session.GetGamePackKeyEx()); //item.postion = NetMsg.MsgItemInfo.ITEMPOSITION_ARMOR; //item.id = 112434; //item.item_id = 135114; //item.amount = item.amount_limit = 1; //session.SendData(item.GetBuffer()); ////测试武器 //item = new NetMsg.MsgItemInfo(); //item.Create(null, session.GetGamePackKeyEx()); //item.postion = NetMsg.MsgItemInfo.ITEMPOSITION_WEAPONR; //item.id = 112435; //item.item_id = 440244; //item.amount = item.amount_limit = 1; //session.SendData(item.GetBuffer()); //NetMsg.MsgUpdateSP sp = new NetMsg.MsgUpdateSP(); //sp.Create(null, session.GetGamePackKeyEx()); //sp.role_id = play.GetTypeId(); //sp.value = 37; //sp.sp = 100; //session.SendData(sp.GetBuffer()); //sp = new NetMsg.MsgUpdateSP(); //sp.Create(null, session.GetGamePackKeyEx()); //sp.role_id = play.GetTypeId(); //session.SendData(sp.GetBuffer()); ////测试新增技能 //ushort[] skill = { 3011 };//, 3002, 1010, 3005, 3009, 8003 //for (int i = 0; i < skill.Length; i++) //{ // NetMsg.MsgMagicInfo magicinfo = new NetMsg.MsgMagicInfo(); // magicinfo.Create(null, session.GetGamePackKeyEx()); // magicinfo.id = play.GetTypeId(); // magicinfo.magicid = skill[i]; // magicinfo.level = 2; // session.SendData(magicinfo.GetBuffer()); //} ////进入地图 //NetMsg.MsgMapInfo mapinfo = new NetMsg.MsgMapInfo(); //mapinfo.Create(null, session.GetGamePackKeyEx()); //mapinfo.Init(play.mapid, play.mPoint.x, play.mPoint.y); //session.SendData(mapinfo.GetBuffer()); ////刷新可视列表; //play.RefreshVisibleObject(); //GameStruct.Action act = new GameStruct.Action(GameStruct.Action.MOVE); //play.PushAction(act); break; } } } } }