private void OnPlayerSpawned(Fougerite.Player player, SpawnEvent se)
        {
            if (SpawnedUsers.Contains(player.UID))
            {
                foreach (var x in RestrictedCommands)
                {
                    player.RestrictCommand(x);
                }

                Dictionary <string, object> Data    = new Dictionary <string, object>();
                PrivilegeStorage            storage = new PrivilegeStorage(player.Admin, player.Moderator);

                if (player.Admin)
                {
                    player.ForceAdminOff(true);
                }

                if (player.Moderator)
                {
                    player.ForceModeratorOff(true);
                }

                Data["Player"] = player;
                CreateParallelTimer(TimeToLogin * 1000, Data).Start();
                WaitingUsers.Add(player.UID, storage);
                DataStore.GetInstance().Add("AuthMeLogin", player.UID, true);
                SpawnedUsers.Remove(player.UID);
            }
        }
        private void OnCommand(Fougerite.Player player, string cmd, string[] args)
        {
            if (cmd == "authme")
            {
                if (args.Length == 0)
                {
                    player.MessageFrom("仙域授权", yellow + "-- Passwords are stored using SHA1 hashes --");
                    player.MessageFrom("仙域授权", yellow + "-- Always use a different password than your emails, etc. --");
                    player.MessageFrom("仙域授权", orange + "/authme register username password");
                    player.MessageFrom("仙域授权", orange + "/authme login username password");
                    player.MessageFrom("仙域授权", orange + "/authme changepw username newpassword");
                    if (player.Admin || player.Moderator)
                    {
                        player.MessageFrom("仙域授权", orange + "/authme resetuser ingamename");
                        player.MessageFrom("仙域授权", orange + "/authme reload");
                    }
                }
                else if (args.Length == 1)
                {
                    string subcmd = args[0];
                    switch (subcmd)
                    {
                    case "reload":
                        if (player.Admin || player.Moderator)
                        {
                            ReloadConfig();
                            player.MessageFrom("仙域授权", green + "Config reloaded!");
                        }

                        break;
                    }
                }
                else if (args.Length == 2)
                {
                    string subcmd = args[0];
                    switch (subcmd)
                    {
                    case "resetuser":
                        if (player.Admin || player.Moderator)
                        {
                            Fougerite.Player plr = Fougerite.Server.GetServer().FindPlayer(args[1]);
                            if (plr != null)
                            {
                                if (Auths.GetSetting("Login", plr.SteamID) != null)
                                {
                                    Auths.DeleteSetting("Login", plr.SteamID);
                                    Auths.Save();
                                }

                                if (Credentials.ContainsKey(plr.UID))
                                {
                                    Credentials.Remove(plr.UID);
                                }

                                player.MessageFrom("仙域授权", green + "User: "******" reset! He can now register a new account for that steamid.");
                                plr.MessageFrom("AuthMe", green + CredsReset);
                                AuthLogger.Log("[USER RESET] " + player.Name + " - " + player.SteamID
                                               + " - " + player.IP + " reset credetials for: " + plr.Name + " - " + plr.SteamID + " - " + plr.IP);
                            }
                        }

                        break;
                    }
                }
                else if (args.Length == 3)
                {
                    string subcmd = args[0];
                    switch (subcmd)
                    {
                    case "register":
                        if (Credentials.ContainsKey(player.UID))
                        {
                            player.MessageFrom("仙域授权", red + "This STEAMID is already protected using password authentication!");
                            return;
                        }

                        string username = args[1];
                        string password = args[2];

                        if (username.ToLower() == "username" || password.ToLower() == "password")
                        {
                            player.MessageFrom("仙域授权", orange + "Type /authme register username password");
                            return;
                        }

                        bool b  = Regex.IsMatch(username, @"^[a-zA-Z0-9_&@%!+<>]+$");
                        bool b2 = Regex.IsMatch(password, @"^[a-zA-Z0-9_&@%!+<>]+$");

                        if (!b || !b2)
                        {
                            player.MessageFrom("仙域授权", orange + "Sorry, no special characters or space! Only: a-zA-Z0-9_&@%!+<>");
                            return;
                        }

                        if (username.Length > 25 || password.Length > 25)
                        {
                            player.MessageFrom("仙域授权", orange + "Sorry, username and password length must be below 25.");
                            return;
                        }

                        string hash = SHA1Hash(password);
                        Auths.AddSetting("Login", player.SteamID, username.ToLower() + "---##---" + hash);
                        Auths.Save();
                        Credentials.Add(player.UID, new Credential(username.ToLower(), hash));
                        player.MessageFrom("仙域授权", orange + "You have registered with: " + username + " - " + password + " (Your console has this info now too.)");
                        player.SendConsoleMessage(orange + "You have registered with: " + username + " - " + password);

                        WaitingUsers.Remove(player.UID);
                        DataStore.GetInstance().Remove("AuthMeLogin", player.UID);
                        uLink.NetworkView.Get(player.PlayerClient.networkView)
                        .RPC("DestroyFreezeAuthMe", player.NetworkPlayer);

                        foreach (var x in RestrictedCommands)
                        {
                            player.UnRestrictCommand(x);
                        }

                        AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " registered an account: " + username);
                        break;

                    case "login":
                        if (!WaitingUsers.ContainsKey(player.UID))
                        {
                            player.MessageFrom("仙域授权", orange + "You are logged in already.");
                            return;
                        }

                        string username2 = args[1];
                        string password2 = args[2];

                        if (username2.Length > 25 || password2.Length > 25)
                        {
                            player.MessageFrom("仙域授权", orange + "Sorry, username and password length must be below 25.");
                            return;
                        }

                        if (!Credentials.ContainsKey(player.UID))
                        {
                            player.MessageFrom("仙域授权", orange + "This steamid is not registered yet!");
                            player.MessageFrom("仙域授权", orange + "Type /authme register username password");
                            return;
                        }

                        Credential cred = Credentials[player.UID];
                        if (cred.Username.ToLower() != username2.ToLower())
                        {
                            player.MessageFrom("仙域授权", orange + "Invalid username!");
                            AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " tried to login using: " + username2);
                            return;
                        }

                        if (cred.HashedPassword != SHA1Hash(password2))
                        {
                            AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " tried to login using: " + username2);
                            player.MessageFrom("仙域授权", orange + "Invalid password! Seek admin for help on their social site.");
                        }
                        else
                        {
                            PrivilegeStorage storage = WaitingUsers[player.UID];
                            if (storage.WasAdmin)
                            {
                                player.ForceAdminOff(false);
                                player.PlayerClient.netUser.SetAdmin(true);
                            }

                            if (storage.WasModerator)
                            {
                                player.ForceModeratorOff(false);
                            }

                            WaitingUsers.Remove(player.UID);
                            DataStore.GetInstance().Remove("AuthMeLogin", player.UID);
                            uLink.NetworkView.Get(player.PlayerClient.networkView)
                            .RPC("DestroyFreezeAuthMe", player.NetworkPlayer);

                            foreach (var x in RestrictedCommands)
                            {
                                player.UnRestrictCommand(x);
                            }
                            AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " logged in using: " + username2);
                            player.MessageFrom("仙域授权", green + "Successfully logged in!");
                        }
                        break;

                    case "changepw":
                        if (WaitingUsers.ContainsKey(player.UID))
                        {
                            player.MessageFrom("仙域授权", orange + "Nice try. You need to be logged in to do that.");
                            return;
                        }

                        string username3 = args[1];
                        string password3 = args[2];
                        if (!Credentials.ContainsKey(player.UID))
                        {
                            player.MessageFrom("仙域授权", orange + "This steamid is not registered yet!");
                            return;
                        }

                        Credential cred2 = Credentials[player.UID];
                        if (!string.Equals(cred2.Username, username3, StringComparison.CurrentCultureIgnoreCase))
                        {
                            player.MessageFrom("仙域授权", orange + "Invalid username!");
                            return;
                        }

                        if (username3.Length > 25 || password3.Length > 25)
                        {
                            player.MessageFrom("仙域授权", orange + "Sorry, username and password length must be below 25.");
                            return;
                        }

                        Credentials.Remove(player.UID);

                        string hash3 = SHA1Hash(password3);
                        Auths.SetSetting("Login", player.SteamID, username3.ToLower() + "---##---" + hash3);
                        Auths.Save();
                        Credentials.Add(player.UID, new Credential(username3.ToLower(), hash3));
                        AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " changed password using: " + username3);

                        player.MessageFrom("仙域授权", green + "Password successfully changed!");
                        break;

                    default:
                        player.MessageFrom("仙域授权", orange + "Invalid command. Type /authme for help.");
                        break;
                    }
                }
            }
        }
        public void OnRustBusterUserMessage(API.RustBusterUserAPI user, Message msgc)
        {
            if (msgc.PluginSender == "JianxianC")
            {
                Fougerite.Player player = user.Player;

                string[] spl = msgc.MessageByClient.Split('-');
                if (spl.Length != 3)
                {
                    return;
                }

                string evt      = spl[0];
                string username = spl[1];
                string password = spl[2];
                if (evt == "AuthMeLogin")
                {
                    if (!WaitingUsers.ContainsKey(player.UID))
                    {
                        player.MessageFrom("仙域授权", orange + "You are logged in already.");
                        msgc.ReturnMessage = "DisApproved";
                        return;
                    }
                    if (!Credentials.ContainsKey(player.UID))
                    {
                        player.MessageFrom("仙域授权", orange + "This steamid is not registered yet!");
                        player.MessageFrom("仙域授权", orange + "Type /authme register username password");
                        msgc.ReturnMessage = "DisApproved";
                        return;
                    }

                    Credential cred = Credentials[player.UID];
                    if (!string.Equals(cred.Username, username, StringComparison.CurrentCultureIgnoreCase))
                    {
                        player.MessageFrom("仙域授权", orange + "Invalid username!");
                        AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP +
                                       " tried to login using: " + username);
                        msgc.ReturnMessage = "DisApproved";
                        return;
                    }

                    if (username.Length > 25 || password.Length > 25)
                    {
                        player.MessageFrom("仙域授权", orange + "Sorry, username and password length must be below 25.");
                        msgc.ReturnMessage = "DisApproved";
                        return;
                    }

                    if (cred.HashedPassword != SHA1Hash(password))
                    {
                        AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP +
                                       " tried to login using: " + username);
                        player.MessageFrom("仙域授权", red + "Invalid password! Seek help here: " + yellow + " " + SocialSiteForHelp);
                        msgc.ReturnMessage = "DisApproved";
                    }
                    else
                    {
                        PrivilegeStorage storage = WaitingUsers[player.UID];
                        if (storage.WasAdmin)
                        {
                            player.ForceAdminOff(false);
                            player.PlayerClient.netUser.SetAdmin(true);
                        }

                        if (storage.WasModerator)
                        {
                            player.ForceModeratorOff(false);
                        }

                        WaitingUsers.Remove(player.UID);
                        DataStore.GetInstance().Remove("AuthMeLogin", player.UID);
                        uLink.NetworkView.Get(player.PlayerClient.networkView)
                        .RPC("DestroyFreezeAuthMe", player.NetworkPlayer);

                        foreach (var x in RestrictedCommands)
                        {
                            player.UnRestrictCommand(x);
                        }

                        AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP + " logged in using: " +
                                       username);
                        player.MessageFrom("仙域授权", green + "Successfully logged in!");
                        msgc.ReturnMessage = "Approved";
                    }
                }
                else if (evt == "AuthMeRegister")
                {
                    if (Credentials.ContainsKey(player.UID))
                    {
                        player.MessageFrom("仙域授权",
                                           red + "This STEAMID is already protected using password authentication!");
                        msgc.ReturnMessage = "InvalidRegistration";
                        return;
                    }

                    if (username.ToLower() == "username" || password.ToLower() == "password")
                    {
                        player.MessageFrom("仙域授权", orange + "Type /authme register username password");
                        msgc.ReturnMessage = "InvalidRegistration";
                        return;
                    }

                    bool b  = Regex.IsMatch(username, @"^[a-zA-Z0-9_&@%!+<>]+$");
                    bool b2 = Regex.IsMatch(password, @"^[a-zA-Z0-9_&@%!+<>]+$");

                    if (!b || !b2)
                    {
                        player.MessageFrom("仙域授权", orange + "Sorry, no special characters or space! Only: a-zA-Z0-9_&@%!+<>");
                        msgc.ReturnMessage = "InvalidRegistration";
                        return;
                    }

                    if (username.Length > 25 || password.Length > 25)
                    {
                        player.MessageFrom("仙域授权", orange + "Sorry, username and password length must be below 25.");
                        msgc.ReturnMessage = "InvalidRegistration";
                        return;
                    }

                    string hash = SHA1Hash(password);
                    Auths.AddSetting("Login", player.SteamID, username.ToLower() + "---##---" + hash);
                    Auths.Save();
                    Credentials.Add(player.UID, new Credential(username.ToLower(), hash));
                    player.MessageFrom("仙域授权",
                                       orange + "You have registered with: " + username + " - " + password +
                                       " (Your console has this info now too.)");
                    player.SendConsoleMessage(orange + "You have registered with: " + username + " - " + password);
                    WaitingUsers.Remove(player.UID);
                    DataStore.GetInstance().Remove("AuthMeLogin", player.UID);
                    uLink.NetworkView.Get(player.PlayerClient.networkView)
                    .RPC("DestroyFreezeAuthMe", player.NetworkPlayer);

                    foreach (var x in RestrictedCommands)
                    {
                        player.UnRestrictCommand(x);
                    }

                    AuthLogger.Log(player.Name + " - " + player.SteamID + " - " + player.IP +
                                   " registered an account: " + username);
                    msgc.ReturnMessage = "ValidRegistration";
                }
            }
        }