Exemplo n.º 1
0
 /// <summary>
 /// 获取封禁原因
 /// </summary>
 /// <param name="banPlayer">目标玩家</param>
 /// <returns></returns>
 public string GetBanReason(ServerPlayer banPlayer)
 {
     try
     {
         MySqlManager dbm = new MySqlManager();
         dbm.Connect();
         MySqlCommand cmd = dbm.command;
         cmd.CommandText = "select ban, banreason from users where username = @UserName";
         cmd.Parameters.AddWithValue("@UserName", banPlayer.Name);
         using (MySqlDataReader mdr = cmd.ExecuteReader())
         {
             if (mdr.Read())
             {
                 Ban       = mdr["ban"].ToString();
                 BanReason = mdr["banreason"].ToString();
             }
         }
         cmd.Cancel();
         if (Ban == "1")
         {
             return(BanReason);
         }
         else
         {
             return("");
         }
     }
     catch (Exception ex)
     {
         ErrorLog = ex.Message;
         return("");
     }
 }
Exemplo n.º 2
0
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            ServerPlayer player = null;

            if (args[0][0] == '$')
            {
                var GUID = Convert.ToInt32(args[0].Substring(1));
                player = ServerSideCharacter2.PlayerCollection.Get(GUID);
            }
            else
            {
                player = ServerSideCharacter2.PlayerCollection.Get(args[0]);
            }
            if (player != null)
            {
                try
                {
                    var s = $"玩家 {player.Name} 的密码已经被重置";
                    player.HasPassword = false;
                    MySqlManager __dbm = new MySqlManager();
                    __dbm.Connect();
                    MySqlCommand __cmd = __dbm.command;
                    __cmd.CommandText = $"update users set machinecode = '' where username = '******'";
                    __cmd.ExecuteNonQuery();
                    __cmd.Cancel();
                    ServerSideCharacter2.ErrorLogger.WriteToFile(s);
                    player.Kick("你的密码已经被重置");
                    CommandBoardcast.ConsoleMessage(s);
                }
                catch (Exception ex)
                {
                    CommandBoardcast.ConsoleError(ex);
                }
            }
            else
            {
                CommandBoardcast.ConsoleError("该玩家不存在");
            }

            //{
            //	CommandBoardcast.ShowInWorldTest("正在向服务器请求在线玩家信息");
            //	MessageSender.SendRequestOnlinePlayer();
            //}
        }
Exemplo n.º 3
0
 /// <summary>
 /// 头衔修改
 /// </summary>
 /// <param name="toPlayer">修改的用户</param>
 /// <param name="Prefix">头衔</param>
 /// <returns>成功返回true,失败返回false</returns>
 public bool ChangePrefix(ServerPlayer toPlayer, string Prefix)
 {
     try
     {
         MySqlManager dbm = new MySqlManager();
         dbm.Connect();
         MySqlCommand cmd = dbm.command;
         cmd.CommandText = "update users set customchatprefix = @Prefix where username = @UserName";
         cmd.Parameters.AddWithValue("@UserName", toPlayer.Name);
         cmd.Parameters.AddWithValue("@Prefix", Prefix);
         cmd.Cancel();
         return(true);
     }
     catch (Exception ex)
     {
         ErrorLog = ex.Message;
         return(false);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// 用户解封
 /// </summary>
 /// <param name="banPlayer">解封的用户</param>
 /// <param name="banner">解封操作者</param>
 /// <returns>成功返回true,失败返回false</returns>
 public bool UnbanPlayer(ServerPlayer banPlayer, string banner)
 {
     try
     {
         MySqlManager dbm = new MySqlManager();
         dbm.Connect();
         MySqlCommand cmd = dbm.command;
         cmd.CommandText = "update users set ban = 0 , banner = @Banner where username = @UserName";
         cmd.Parameters.AddWithValue("@UserName", banPlayer.Name);
         cmd.Parameters.AddWithValue("@Banner", banner);
         cmd.ExecuteNonQuery();
         cmd.Cancel();
         return(true);
     }
     catch (Exception ex)
     {
         ErrorLog = ex.Message;
         return(false);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 用户封禁
 /// </summary>
 /// <param name="banPlayer">封禁的用户</param>
 /// <param name="banner">封禁操作者</param>
 /// <param name="banReason">封禁的原因</param>
 /// <returns>成功返回true,失败返回false</returns>
 public bool BanPlayer(ServerPlayer banPlayer, string banner, string banReason)
 {
     Console.WriteLine("Ban");
     try
     {
         MySqlManager dbm = new MySqlManager();
         dbm.Connect();
         MySqlCommand cmd = dbm.command;
         cmd.CommandText = "update users set ban = 1 , banner = @Banner , banreason = @BanReason where username = @UserName";
         cmd.Parameters.AddWithValue("@UserName", banPlayer.Name);
         cmd.Parameters.AddWithValue("@Banner", banner);
         cmd.Parameters.AddWithValue("@BanReason", banReason);
         cmd.ExecuteNonQuery();
         cmd.Cancel();
         return(true);
     }
     catch (Exception ex)
     {
         CommandBoardcast.ConsoleError(ex);
         ErrorLog = ex.Message;
         return(false);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 用户注册
        /// </summary>
        public States.RegisterState Register(CryptedUserInfo info)
        {
            if (ServerSideCharacter2.DEBUGMODE)
            {
                return(States.RegisterState.Debug);
            }
            QQ = info.UserName;
            string UserName = "";

            if (QQ == "")
            {
                return(States.RegisterState.NullQQ);
            }
            try
            {
                // 判断QQ是否跳过机器码验证
                bool         SkipMCCheck = false;
                MySqlManager _dbm        = new MySqlManager();
                _dbm.Connect();
                MySqlCommand _cmd = _dbm.command;
                _cmd.CommandText = "select * from users where qq = @QQ and skipmccheck = 1";
                _cmd.Parameters.AddWithValue("@QQ", QQ);
                MySqlDataReader _mdr = _cmd.ExecuteReader();
                if (_mdr.Read())
                {
                    SkipMCCheck = true;
                }
                _mdr.Close();
                _cmd.Cancel();
                // 机器码校验
                if (!SkipMCCheck)
                {
                    // 机器码获取失败
                    if (MachineCode == "")
                    {
                        return(States.RegisterState.GetMCFailed);
                    }
                    else
                    {
                        MySqlManager __dbm = new MySqlManager();
                        __dbm.Connect();
                        MySqlCommand __cmd = __dbm.command;
                        __cmd.CommandText = "select username from users where machinecode = @MachineCode";
                        __cmd.Parameters.AddWithValue("@MachineCode", MachineCode);
                        MySqlDataReader __mdr = __cmd.ExecuteReader();
                        if (__mdr.Read())
                        {
                            UserName = __mdr["username"].ToString();
                        }
                        __mdr.Close();
                        __cmd.Cancel();
                        // 机器码重复绑定
                        if (UserName != "" && UserName != CharacterName)
                        {
                            return(States.RegisterState.MCBound);
                        }
                    }
                }
                // 判断角色是否已绑定QQ
                string       _QQ = "";
                MySqlManager dbm = new MySqlManager();
                dbm.Connect();
                MySqlCommand cmd = dbm.command;
                cmd.CommandText = "select qq from users where username = @UserName";
                cmd.Parameters.AddWithValue("@UserName", CharacterName);
                MySqlDataReader mdr = cmd.ExecuteReader();
                if (mdr.HasRows)
                {
                    if (mdr.Read())
                    {
                        _QQ = mdr["qq"].ToString();
                    }
                }
                else
                {
                    _QQ = "";
                }
                mdr.Close();
                cmd.Cancel();
                // 判断QQ是否已绑定角色
                MySqlManager ___dbm = new MySqlManager();
                ___dbm.Connect();
                MySqlCommand ___cmd = ___dbm.command;
                ___cmd.CommandText = "select username from users where qq = @QQ";
                ___cmd.Parameters.AddWithValue("@QQ", QQ);
                MySqlDataReader ___mdr = ___cmd.ExecuteReader();
                if (___mdr.HasRows)
                {
                    if (___mdr.Read())
                    {
                        UserName = ___mdr["username"].ToString();
                    }
                }
                else
                {
                    UserName = "";
                }
                ___mdr.Close();
                ___cmd.Cancel();

                // 未绑定
                if (_QQ == "" && UserName == "")
                {
                    try
                    {
                        MySqlManager __dbm = new MySqlManager();
                        __dbm.Connect();
                        MySqlCommand __cmd = __dbm.command;
                        __cmd.CommandText = "insert into users set qq = @QQ , username = @UserName , machinecode = @MachineCode , ban = 0 , setpwreq = 0 ON DUPLICATE KEY UPDATE qq = @QQ , username = @UserName , machinecode = @MachineCode , ban = 0 , setpwreq = 0";
                        __cmd.Parameters.AddWithValue("@QQ", QQ);
                        __cmd.Parameters.AddWithValue("@UserName", CharacterName);
                        __cmd.Parameters.AddWithValue("@MachineCode", MachineCode);
                        __cmd.ExecuteNonQuery();
                        __cmd.Cancel();
                        return(States.RegisterState.RegisterSuccess);
                    }
                    catch (Exception ex)
                    {
                        ErrorLog = ex.Message;
                        return(States.RegisterState.Error);
                    }
                }
                if (_QQ == QQ && UserName == CharacterName)
                {
                    // 已被当前角色绑定
                    return(States.RegisterState.RegisterRep);
                }
                else
                {
                    // 已被其他角色绑定
                    return(States.RegisterState.QQBound);
                }
            }
            catch (Exception ex)
            {
                if (MySqlManager.connection != null)
                {
                    MySqlManager.connection.Close();
                    MySqlManager.connection.Dispose();
                    MySqlManager.connection = null;
                }
                ErrorLog = ex.Message;
                return(States.RegisterState.Error);
            }
        }
Exemplo n.º 7
0
 // 方法
 /// <summary>
 /// 登录验证
 /// </summary>
 public States.LoginState Login(CryptedUserInfo info)
 {
     if (ServerSideCharacter2.DEBUGMODE)
     {
         return(States.LoginState.Debug);
     }
     try
     {
         string       ChangePasswordRequired = "";
         bool         isCharacterFound       = false;
         MySqlManager dbm = new MySqlManager();
         dbm.Connect();
         MySqlCommand cmd = dbm.command;
         cmd.CommandText = "select * from users where username = @UserName";
         cmd.Parameters.AddWithValue("@UserName", CharacterName);
         MySqlDataReader mdr = cmd.ExecuteReader();
         if (mdr.Read())
         {
             isCharacterFound = true;
             QQ                     = mdr["qq"].ToString();
             OpenID                 = mdr["openid"].ToString();
             Ban                    = mdr["ban"].ToString();
             Banner                 = mdr["banner"].ToString();
             BanReason              = mdr["banreason"].ToString();
             CustomChatPrefix       = mdr["customchatprefix"].ToString();
             ChangePasswordRequired = mdr["setpwreq"].ToString();
             MachineCode_DB         = mdr["machinecode"].ToString();
             SkipMCCheck            = mdr["skipmccheck"].ToString();
         }
         mdr.Close();
         cmd.Cancel();
         if (isCharacterFound)
         {
             // 给上版本注册的用户补充注册机器码的代码
             if (MachineCode_DB == "" && MachineCode != "")
             {
                 MachineCode_DB = MachineCode;
                 MySqlManager _dbm = new MySqlManager();
                 _dbm.Connect();
                 MySqlCommand _cmd = _dbm.command;
                 _cmd.CommandText = "update users set machinecode = @MachineCode where username = @UserName";
                 _cmd.Parameters.AddWithValue("@UserName", CharacterName);
                 _cmd.Parameters.AddWithValue("@MachineCode", MachineCode);
                 _cmd.ExecuteNonQuery();
                 _cmd.Cancel();
             }
             // 校验机器码
             if (SkipMCCheck != "1")
             {
                 if (MachineCode == "")
                 {
                     return(States.LoginState.GetMCFailed);
                 }
                 else if (MachineCode != MachineCode_DB)
                 {
                     return(States.LoginState.MCCheckFailed);
                 }
             }
             // 校验绑定
             if (QQ == "" || OpenID == "")
             {
                 return(States.LoginState.Unbound);
             }
             // 校验封禁
             if (Ban != "0")
             {
                 return(States.LoginState.Banned);
             }
             // 校验改密状态
             if (ChangePasswordRequired != "0")
             {
                 MySqlManager _dbm = new MySqlManager();
                 _dbm.Connect();
                 MySqlCommand _cmd = _dbm.command;
                 _cmd.CommandText = "update users set setpwreq = 0 where username = @UserName";
                 _cmd.Parameters.AddWithValue("@UserName", CharacterName);
                 _cmd.ExecuteNonQuery();
                 _cmd.Cancel();
                 return(States.LoginState.ChangePasswordRequired);
             }
             else
             {
                 info.UserName = QQ;
                 info.OpenID   = OpenID;
                 return(States.LoginState.LoginSuccess);
             }
         }
         else
         {
             return(States.LoginState.NotFound);
         }
     }
     catch (Exception ex)
     {
         if (MySqlManager.connection != null)
         {
             MySqlManager.connection.Close();
             MySqlManager.connection.Dispose();
             MySqlManager.connection = null;
         }
         ErrorLog = ex.Message;
         return(States.LoginState.Error);
     }
 }