public RegsiterVerifyContextAsyncAction(GameServerPlayerContext context, string username, string password, Action <S2C_RegisterMessage> reply, bool needResult = false, bool needSeq = false) : base(context, context.ContextId.ToString(), needResult, needSeq)
 {
     m_username   = username;
     m_password   = password;
     m_state      = false;
     m_errorInfo  = "";
     this.m_reply = reply;
 }
 public LoginVerifyContextAsyncAction(GameServerPlayerContext gameServerContext, string account, string password, Action <S2C_LoginMessage> reply, bool needResult = false, bool needSeq = false) : base(gameServerContext, gameServerContext.ContextId.ToString(), needResult, needSeq)
 {
     this.m_gameServerContext = gameServerContext;
     this.m_username          = account;
     this.m_password          = password;
     this.m_reply             = reply;
     this.m_state             = false;
 }
        protected override void Run(ISession playerContext, C2S_RegisterMessage message, Action <S2C_RegisterMessage> reply)
        {
            GameServerPlayerContext gameServerContext = playerContext as GameServerPlayerContext;
            S2C_RegisterMessage     response          = new S2C_RegisterMessage();

            try
            {
                new RegsiterVerifyContextAsyncAction(gameServerContext, message.Account, message.Password, reply, true, true).Start();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override async void Run(ISession playerContext, C2S_LoginMessage message, Action <S2C_LoginMessage> reply)
        {
            GameServerPlayerContext gameServerContext = playerContext as GameServerPlayerContext;
            S2C_LoginMessage        response          = new S2C_LoginMessage();

            try
            {
                Log.Info($"登陆 {message} ");
                await gameServerContext.OnAuthByLogin(message, reply);

                //原始的Action方法不再使用 目前逻辑都在playerContext
            }catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        private async Task <bool> ContextTransform(GameServerPlayerContext target)
        {
            await target.EnterLock();//要操作目标现场需要先把目标现场上锁

            //判断状态机
            if (!target.CanAcceptContextTransform())
            {
                Log.Info("GameServerPlayerContext::ContextTransform can not AcceptContextTransform. target sessionId = " + target.SessionId + " state = " + target.m_csm.State);
                // 释放访问权限
                target.LeaveLock();
                return(false);
            }
            bool resetSucess = false;

            if (!m_client.Closed && !m_client.Disconnected)
            {
                // 此处需要先处理掉前面一个现场的连接,因为close后不会再收到任何回调,所以不用调用m_client.ResetCientEventHandler(null);
                target.m_client.Close();

                target.m_client = m_client;
                m_client.ResetCientEventHandler(target);
                m_client = null;

                resetSucess = true;
            }

            // 释放访问权限
            target.LeaveLock();

            Log.Debug("GameServerBasePlayerContext::ContextTransform resetSucess=" + resetSucess);

            // 向目标现场发送msg,来执行后续操作
            if (resetSucess)
            {
                target.PostLocalMessage(new LocalMessageContextTransformOk());
            }

            // 由于已经没有client对象所以本现场不易久留
            Release();

            return(resetSucess);
        }
        /// <summary>
        /// 软登陆,由于玩家掉线延迟导致断网,选择重连进行验证时候的登陆
        /// 如果存在旧现场需要恢复,则进行恢复现场上下文
        /// </summary>
        /// <returns></returns>
        public async Task OnAuthReCByLogin(C2S_ReConnectByLogin message)
        {
            string account  = message.Account;
            string password = message.Password;

#pragma warning disable CS0219 // 变量“response”已被赋值,但从未使用过它的值
            S2C_LoginMessage response = null;
#pragma warning restore CS0219 // 变量“response”已被赋值,但从未使用过它的值

            //设置现场状态
            if (m_csm.SetStateCheck(PlayerContextStateMachine.EventOnSessionLoginReq) == -1)
            {
                Log.Info("OnAuthByLogin::PlayerContextStateMachine switch Fail to SessionLoginReq");
                return;
            }
            // 进行数据库验证
            var authDB = await ValidateAuthLogin(account, password);

            if (!authDB)
            {
                Log.Info("OnAuthReCByLogin::FAIL TO authDB");
                //验证Session失败先不理会
                goto RETURN;
            }
            //获取数据库player的实体
            m_gameServerDBPlayer = await GetPlayerFromDBAsync(account);

            if (m_gameServerDBPlayer == null)
            {
                Log.Info("gameServerDBPlayer is NULL");
                goto RETURN;
            }
            //DB的唯一标识符代表着这个玩家应用层的Id
            m_gameUserId = m_gameServerDBPlayer.userName.ToString();

            //开始验证是否已经存在userid对应的玩家现场
            GameServerPlayerContext oldCtx = (GameServerPlayerContext)GameServer.
                                             Instance.PlayerCtxManager.FindPlayerContextByString(m_gameUserId);
            //如果存在 则判定为需要重连 需要恢复现场状态
            //这里可以判断设备Id 判断是否需要重连 或者是挤掉原来老的现场设备
            //PS:以后Session验证要更加完全 不能只验证账号密码
            if (oldCtx != null)
            {
                bool ret = await ContextTransform(oldCtx);

                if (!ret)
                {
                }
                // 在现场转移之后不能执行任何代码了,立刻退出
                return;
            }
            //当前玩家验证成功且不存在断线则设置正确的玩家状态
RETURN:
            if (authDB)
            {
                m_csm.SetStateCheck(PlayerContextStateMachine.EventOnSessionLoginOK);
            }
            //TODO:添加发给客户端的验证成功且不重连的消息
            //Send(null);
            return;
        }
 protected override async void Run(ISession playerContext, C2S_ReConnectByLogin message)
 {
     GameServerPlayerContext gameServerContext = playerContext as GameServerPlayerContext;
     await gameServerContext.OnAuthReCByLogin(message);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="targetQueueUserId"></param>
 /// <param name="needResult"></param>
 /// <param name="needSeq"></param>
 public SampleGameServerContextAsyncAction(GameServerPlayerContext context, String targetQueueUserId, Boolean needResult = false, Boolean needSeq = false)
     : base(context, GameServer.Instance.AsyncActionQueuePool.GetAdaptedQueueByUserId(targetQueueUserId), needResult, needSeq)
 {
     ContextUserId = context.ContextId;
 }
 public GetAllBarrierRecordAsyncAction(GameServerPlayerContext context, string targetQueueUserId, bool needResult = false, bool needSeq = false) : base(context, targetQueueUserId, needResult, needSeq)
 {
 }
 public UpLoadBarrierRecordAsyncAction(GameServerDBarrierRecord data, GameServerPlayerContext gameServerContext, bool needResult = false, bool needSeq = false) : base(gameServerContext, null, needResult, needSeq)
 {
     m_data = data;
 }