Ejemplo n.º 1
0
        /// <summary>
        /// 客户端请求验证usrid的二级密码
        /// </summary>
        public static TCPProcessCmdResults ProcessUsrVerify(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;

            try
            {
                VerifySecondPassword verifyReq = DataHelper.BytesToObject <VerifySecondPassword>(data, 0, count);
                if (verifyReq == null)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("解析指令错误, cmd={0}", (int)nID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int errcode, has, need;

                SecPwdState pwdState = GetSecPwdState(verifyReq.UserID);
                if (pwdState == null)
                {
                    //没有二级密码,客户端却请求验证,设为验证成功
                    errcode = (int)SecondPasswordError.SecPwdVerifySuccess;
                    has     = 0;
                    need    = 0;
                }
                else
                {
                    //有二级密码,开始验证

                    if (string.IsNullOrEmpty(verifyReq.SecPwd) || verifyReq.SecPwd != pwdState.SecPwd)
                    {
                        errcode = (int)SecondPasswordError.SecPwdVerifyFailed;
                        has     = 1;
                        need    = 1;
                    }
                    else
                    {
                        //验证成功了,更新usrid的验证状态
                        errcode             = (int)SecondPasswordError.SecPwdVerifySuccess;
                        has                 = 1;
                        need                = 0;
                        pwdState.NeedVerify = false;
                    }
                }


                string rsp = string.Format("{0}:{1}:{2}", errcode, has, need);
                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, rsp, nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }
Ejemplo n.º 2
0
        // 清除二级密码
        public static TCPProcessCmdResults ProcClrSecPwd(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;

            try
            {
                VerifySecondPassword verifyReq = DataHelper.BytesToObject <VerifySecondPassword>(data, 0, count);
                if (verifyReq == null)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("解析指令错误, cmd={0}", (int)nID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                string uid = GameManager.OnlineUserSession.FindUserID(socket);
                if (string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(verifyReq.UserID) || uid != verifyReq.UserID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("玩家请求清除二级密码,但是玩家发送的uid错误, {0}", Global.GetSocketRemoteEndPoint(socket)));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                int errcode;

                SecPwdState pwdState = GetSecPwdState(verifyReq.UserID);
                if (pwdState == null)
                {
                    //没有二级密码,客户端却请求删除
                    errcode = (int)SecondPasswordError.SecPwdIsNotSet;
                }
                else
                {
                    if (string.IsNullOrEmpty(verifyReq.SecPwd) || verifyReq.SecPwd != pwdState.SecPwd)
                    {
                        errcode = (int)SecondPasswordError.SecPwdVerifyFailed;
                    }
                    else if (!ClearUserSecPwd(verifyReq.UserID))
                    {
                        errcode = (int)SecondPasswordError.SecPwdDBFailed;
                    }
                    else
                    {
                        errcode = (int)SecondPasswordError.SecPwdClearSuccess;
                    }
                }

                tcpOutPacket = TCPOutPacket.MakeTCPOutPacket(pool, errcode.ToString(), nID);
                return(TCPProcessCmdResults.RESULT_DATA);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }