Inheritance: global::ProtoBuf.IExtensible
Esempio n. 1
0
        private void HandleRoleEnterResult(NodeMessage lobbyMsg)
        {
            GameFrameworkMessage.NodeMessageWithAccountAndGuid headerData = lobbyMsg.m_NodeHeader as GameFrameworkMessage.NodeMessageWithAccountAndGuid;
            GameFrameworkMessage.RoleEnterResult protoData = lobbyMsg.m_ProtoData as GameFrameworkMessage.RoleEnterResult;
            if (null != protoData)
            {
                RoleEnterResult.RoleEnterResultEnum ret = protoData.Result;
                m_Guid = headerData.m_Guid;
                ClientInfo.Instance.Guid     = m_Guid;
                ClientInfo.Instance.RoleData = protoData;

                if (ret == RoleEnterResult.RoleEnterResultEnum.Wait)
                {
                    PluginFramework.Instance.HighlightPrompt("Tip_WaitOffline");
                    Thread.Sleep(2000);
                    NodeMessage msg = new NodeMessage(LobbyMessageDefine.RoleEnter, m_AccountId);
                    GameFrameworkMessage.RoleEnter data = new GameFrameworkMessage.RoleEnter();
                    msg.m_ProtoData = data;
                    SendMessage(msg);
                    LogSystem.Info("Retry RoleEnter {0} {1}", m_AccountId, m_Guid);
                    return;
                }
                else if (ret == RoleEnterResult.RoleEnterResultEnum.Success)
                {
                    //客户端接收服务器传来的数据,创建玩家对象
                    m_WorldId = protoData.WorldId;
                    ///
                    m_IsLogining  = false;
                    m_HasLoggedOn = true;
                    GfxStorySystem.Instance.SendMessage("start_game");
                }
                else if (ret == RoleEnterResult.RoleEnterResultEnum.Reconnect)
                {
                    //重连用户,等待服务器处理重连过程后返回进场景消息,这种情形不用做任何处理
                    PluginFramework.Instance.HighlightPrompt("Tip_Reconnecting");
                }
                else
                {
                    //进入游戏失败
                    PluginFramework.Instance.HighlightPrompt("Tip_RoleEnterFailed");
                }
            }
        }
 internal void DSPLoadUserCallback(Msg_DL_LoadResult ret, string accountId, string nickname)
 {
     AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId);
     if (accountInfo == null) {
         return;
     }
     ulong userGuid = 0;// accountInfo.UserGuid;
     if (Msg_DL_LoadResult.ErrorNoEnum.Success == ret.ErrorNo) {
         TableUserInfo dataUser = null;
         foreach (var result in ret.Results) {
             object _msg;
             if (DbDataSerializer.Decode(result.Data, DataEnum2Type.Query(result.MsgId), out _msg)) {
                 DataEnum msgEnum = (DataEnum)result.MsgId;
                 switch (msgEnum) {
                     case DataEnum.TableUserInfo:
                         dataUser = _msg as TableUserInfo;
                         break;
                     default:
                         LogSys.Log(LOG_TYPE.ERROR, ConsoleColor.Red, "Decode user data ERROR. Wrong message id. UserGuid:{0}, WrongId:{1}", userGuid, msgEnum);
                         break;
                 }
             }
         }
         #region 由数据库数据构建UserInfo
         UserInfo ui = NewUserInfo();
         //基础数据
         ui.FromProto(dataUser);
         ui.SetMoneyForDB(dataUser.Money);
         ui.SetGoldForDB(dataUser.Gold);
         #endregion
         ui.NodeName = accountInfo.NodeName;
         this.DoUserLogin(ui);
         NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, ui.AccountId, ui.Guid);
         GameFrameworkMessage.RoleEnterResult protoData = CreateRoleEnterResultMsg(ui);
         protoData.Result = RoleEnterResult.RoleEnterResultEnum.Success;
         replyMsg.m_ProtoData = protoData;
         NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg);
     } else if (Msg_DL_LoadResult.ErrorNoEnum.NotFound == ret.ErrorNo) {
         CreateRole(accountId, nickname, 1);
     } else {
         NodeMessage replyMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountInfo.AccountId, userGuid);
         GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult();
         protoData.Result = RoleEnterResult.RoleEnterResultEnum.UnknownError;
         replyMsg.m_ProtoData = protoData;
         NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, replyMsg);
     }
     LogSys.Log(LOG_TYPE.INFO, "UserProcessScheduler-OnRoleEnter-EndLoadUser. AccountId:{0}, UserGuid:{1}, Result:{2}",
       accountId, userGuid, ret.ErrorNo);
 }
        private GameFrameworkMessage.RoleEnterResult CreateRoleEnterResultMsg(UserInfo ui)
        {
            GameFrameworkMessage.RoleEnterResult replyMsg = new GameFrameworkMessage.RoleEnterResult();
            //
            replyMsg.Nickname = ui.Nickname;
            replyMsg.HeroId = ui.HeroId;
            replyMsg.Level = ui.Level;
            replyMsg.Money = ui.Money;
            replyMsg.Gold = ui.Gold;
            replyMsg.Level = ui.Level;
            replyMsg.SceneId = ui.SceneId;
            replyMsg.SummonerSkillId = ui.SummonerSkillId;
            replyMsg.WorldId = UserServerConfig.WorldId;

            for (int i = 0; i < ui.MemberInfos.Count; ++i) {
                MemberInfoForMessage mi = new MemberInfoForMessage();
                mi.Hero = ui.MemberInfos[i].HeroId;
                mi.Level = ui.MemberInfos[i].Level;
            }
            return replyMsg;
        }
 internal void DoRoleEnter(string accountId, string nickname)
 {
     AccountInfo accountInfo = m_AccountSystem.FindAccountById(accountId);
     if (accountInfo != null) {
         ulong userGuid = accountInfo.UserGuid;
         UserInfo user = GetUserInfo(userGuid);
         if (null != user) {
             if (user.CurrentState == UserState.DropOrOffline) {
                 //用户处在下线过程中,需要等待lobby离线流程完成
                 NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountId, user.Guid);
                 GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult();
                 protoData.Result = RoleEnterResult.RoleEnterResultEnum.Wait;
                 roleEnterResultMsg.m_ProtoData = protoData;
                 NodeMessageDispatcher.SendNodeMessage(user.NodeName, roleEnterResultMsg);
                 LogSys.Log(LOG_TYPE.WARN, "RoleEnter AccountId:{0} Guid:{1} Wait Offline", accountId, userGuid);
             } else {
                 if (user.AccountId.Equals(accountInfo.AccountId)) {
                     user.NodeName = accountInfo.NodeName;
                     user.LeftLife = UserInfo.LifeTimeOfNoHeartbeat;
                     DoUserRelogin(user);
                     LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_8a: Role Reenter SUCCESS. AccountId:{0}, UserGuid:{1}, Nickname:{2}",
                         accountId, userGuid, user.Nickname);
                     //回复客户端
                     NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, user.AccountId, user.Guid);
                     GameFrameworkMessage.RoleEnterResult protoData = CreateRoleEnterResultMsg(user);
                     protoData.Result = RoleEnterResult.RoleEnterResultEnum.Reconnect;
                     roleEnterResultMsg.m_ProtoData = protoData;
                     NodeMessageDispatcher.SendNodeMessage(accountInfo.NodeName, roleEnterResultMsg);
                 } else {
                     //角色AccountId与账号AccountId不匹配,进入游戏失败
                     NodeMessage roleEnterResultMsg = new NodeMessage(LobbyMessageDefine.RoleEnterResult, accountId, user.Guid);
                     GameFrameworkMessage.RoleEnterResult protoData = new GameFrameworkMessage.RoleEnterResult();
                     protoData.Result = RoleEnterResult.RoleEnterResultEnum.UnknownError;
                     roleEnterResultMsg.m_ProtoData = protoData;
                     LogSys.Log(LOG_TYPE.ERROR, "LoginStep_8a: Role Reenter FAILED. AccountId:{0}, UserGuid:{1}, Nickname:{2}, UserAccountId:{3}",
                         accountId, userGuid, user.Nickname, user.AccountId);
                 }
             }
         } else {
             var ds_thread = UserServer.Instance.DataCacheThread;
             if (ds_thread.DataStoreAvailable == true) {
                 LogSys.Log(LOG_TYPE.INFO, ConsoleColor.Green, "LoginStep_8b: Load UserInfo. AccountId:{0}, UserGuid:{1}", accountId, userGuid);
                 ds_thread.DispatchAction(ds_thread.DSPLoadUser, userGuid, accountId, nickname);
             } else {
                 CreateRole(accountId, nickname, 1);
             }
         }
     }
 }