public static TCPProcessCmdResults ProcessSetSecPwd(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;
            try
            {
                SetSecondPassword setReq = DataHelper.BytesToObject <SetSecondPassword>(data, 0, count);
                if (setReq == null)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("解析指令错误, cmd={0}", nID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (client == null || client.ClientData.RoleID != setReq.RoleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), setReq.RoleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                if (GameFuncControlManager.IsGameFuncDisabled(GameFuncType.System1Dot4Dot1))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("ProcessSetSecPwd功能尚未开放, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket, false), setReq.RoleID), null, true);
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }
                SecPwdState         pwdState            = SecondPasswordManager.GetSecPwdState(client.strUserID);
                string              oldSecPwd_Encrypted = (pwdState != null) ? pwdState.SecPwd : null;
                SecondPasswordError error;
                if (!string.IsNullOrEmpty(oldSecPwd_Encrypted))
                {
                    if (setReq.OldSecPwd == null || oldSecPwd_Encrypted != setReq.OldSecPwd)
                    {
                        error = SecondPasswordError.SecPwdVerifyFailed;
                        goto IL_1F8;
                    }
                }
                string newSecPwd_Decrypted = SecondPasswordRC4.Decrypt(setReq.NewSecPwd);
                if (string.IsNullOrEmpty(newSecPwd_Decrypted))
                {
                    error = SecondPasswordError.SecPwdIsNull;
                }
                else if (!Regex.IsMatch(newSecPwd_Decrypted, "^[a-zA-Z0-9_]+$"))
                {
                    error = SecondPasswordError.SecPwdCharInvalid;
                }
                else if (newSecPwd_Decrypted.Length < 6)
                {
                    error = SecondPasswordError.SecPwdIsTooShort;
                }
                else if (newSecPwd_Decrypted.Length > 8)
                {
                    error = SecondPasswordError.SecPwdIsTooLong;
                }
                else
                {
                    string   cmd2db   = string.Format("{0}:{1}", client.strUserID, setReq.NewSecPwd);
                    string[] dbFields = Global.ExecuteDBCmd(10183, cmd2db, client.ServerId);
                    if (dbFields == null || dbFields.Length != 2)
                    {
                        error = SecondPasswordError.SecPwdDBFailed;
                    }
                    else
                    {
                        error = SecondPasswordError.SecPwdSetSuccess;
                    }
                }
IL_1F8:
                if (error == SecondPasswordError.SecPwdSetSuccess)
                {
                    if (pwdState == null)
                    {
                        pwdState = new SecPwdState();
                    }
                    pwdState.SecPwd     = setReq.NewSecPwd;
                    pwdState.NeedVerify = false;
                    SecondPasswordManager.SetSecPwdState(client.strUserID, pwdState);
                }
                int has  = 0;
                int need = 0;
                if (pwdState != null)
                {
                    has  = 1;
                    need = (pwdState.NeedVerify ? 1 : 0);
                }
                string rsp = string.Format("{0}:{1}:{2}:{3}", new object[]
                {
                    setReq.RoleID,
                    (int)error,
                    has,
                    need
                });
                GameManager.ClientMgr.SendToClient(client, rsp, nID);
                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false, false);
            }
            return(TCPProcessCmdResults.RESULT_FAILED);
        }
        /// <summary>
        /// 设置二级密码
        /// </summary>
        public static TCPProcessCmdResults ProcessSetSecPwd(TCPManager tcpMgr, TMSKSocket socket, TCPClientPool tcpClientPool, TCPRandKey tcpRandKey, TCPOutPacketPool pool, int nID, byte[] data, int count, out TCPOutPacket tcpOutPacket)
        {
            tcpOutPacket = null;

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

                GameClient client = GameManager.ClientMgr.FindClient(socket);
                if (null == client || client.ClientData.RoleID != setReq.RoleID)
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("根据RoleID定位GameClient对象失败, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), setReq.RoleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                // 如果1.4.1的功能没开放
                if (GameFuncControlManager.IsGameFuncDisabled(GameFuncType.System1Dot4Dot1))
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("ProcessSetSecPwd功能尚未开放, CMD={0}, Client={1}, RoleID={2}", (TCPGameServerCmds)nID, Global.GetSocketRemoteEndPoint(socket), setReq.RoleID));
                    return(TCPProcessCmdResults.RESULT_FAILED);
                }

                //旧的加密后的二级密码, 如果尚未设置,则为空
                SecPwdState         pwdState            = GetSecPwdState(client.strUserID);
                string              oldSecPwd_Encrypted = pwdState != null ? pwdState.SecPwd : null;
                SecondPasswordError error = SecondPasswordError.SecPwdSetSuccess;
                do
                {
                    if (!string.IsNullOrEmpty(oldSecPwd_Encrypted))
                    {
                        // 存在旧的二级密码,直接进行密文比较
                        if (setReq.OldSecPwd == null ||
                            oldSecPwd_Encrypted != setReq.OldSecPwd)
                        {
                            error = SecondPasswordError.SecPwdVerifyFailed;
                            break;
                        }
                    }

                    //解密后的新二级密码
                    string newSecPwd_Decrypted = SecondPasswordRC4.Decrypt(setReq.NewSecPwd);
                    if (string.IsNullOrEmpty(newSecPwd_Decrypted))
                    {
                        error = SecondPasswordError.SecPwdIsNull;
                        break;
                    }

                    if (!Regex.IsMatch(newSecPwd_Decrypted, "^[a-zA-Z0-9_]+$"))
                    {
                        error = SecondPasswordError.SecPwdCharInvalid;
                        break;
                    }

                    if (newSecPwd_Decrypted.Length < _PwdMinLen)
                    {
                        error = SecondPasswordError.SecPwdIsTooShort;
                        break;
                    }

                    if (newSecPwd_Decrypted.Length > _PwdMaxLen)
                    {
                        error = SecondPasswordError.SecPwdIsTooLong;
                        break;
                    }

                    //直接存储密文
                    string   cmd2db   = string.Format("{0}:{1}", client.strUserID, setReq.NewSecPwd);
                    string[] dbFields = Global.ExecuteDBCmd((int)TCPGameServerCmds.CMD_DB_UPDATE_USR_SECOND_PASSWORD, cmd2db, client.ServerId);
                    if (null == dbFields || dbFields.Length != 2)
                    {
                        error = SecondPasswordError.SecPwdDBFailed;
                        break;
                    }

                    error = SecondPasswordError.SecPwdSetSuccess;
                    break;
                } while (false);

                if (error == SecondPasswordError.SecPwdSetSuccess)
                {
                    // 设置二级密码成功了,更新状态
                    if (pwdState == null)
                    {
                        pwdState = new SecPwdState();
                    }
                    pwdState.SecPwd     = setReq.NewSecPwd;
                    pwdState.NeedVerify = false;
                    SetSecPwdState(client.strUserID, pwdState);
                }

                int has = 0, need = 0;
                if (pwdState != null)
                {
                    has  = 1;
                    need = pwdState.NeedVerify ? 1 : 0;
                }

                string rsp = string.Format("{0}:{1}:{2}:{3}", setReq.RoleID, (int)error, has, need);
                GameManager.ClientMgr.SendToClient(client, rsp, nID);
                return(TCPProcessCmdResults.RESULT_OK);
            }
            catch (Exception ex)
            {
                DataHelper.WriteFormatExceptionLog(ex, Global.GetDebugHelperInfo(socket), false);
            }

            return(TCPProcessCmdResults.RESULT_FAILED);
        }