Exemple #1
0
        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);
            }
        }
Exemple #2
0
        private void OnCommand(Fougerite.Player player, string cmd, string[] args)
        {
            if (cmd == "authme")
            {
                if (args.Length == 0)
                {
                    player.MessageFrom("AuthMe", orange + "AuthMe V" + Version + " By " + Author);
                    player.MessageFrom("AuthMe", yellow + "-- Passwords are stored using SHA1 hashes --");
                    player.MessageFrom("AuthMe", yellow + "-- Always use a different password than your emails, etc. --");
                    player.MessageFrom("AuthMe", orange + "/authme register username password");
                    player.MessageFrom("AuthMe", orange + "/authme login username password");
                    player.MessageFrom("AuthMe", orange + "/authme changepw username newpassword");
                    if (player.Admin || player.Moderator)
                    {
                        player.MessageFrom("AuthMe", orange + "/authme resetuser ingamename");
                        player.MessageFrom("AuthMe", orange + "/authme reload");
                    }
                }
                else if (args.Length == 1)
                {
                    string subcmd = args[0];
                    switch (subcmd)
                    {
                    case "reload":
                        if (player.Admin || player.Moderator)
                        {
                            ReloadConfig();
                            player.MessageFrom("AuthMe", 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("AuthMe", 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("AuthMe", 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("AuthMe", 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("AuthMe", orange + "Sorry, no special characters or space! Only: a-zA-Z0-9_&@%!+<>");
                            return;
                        }

                        if (username.Length > 25 || password.Length > 25)
                        {
                            player.MessageFrom("AuthMe", 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("AuthMe", 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("AuthMe", orange + "You are logged in already.");
                            return;
                        }

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

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

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

                        Credential cred = Credentials[player.UID];
                        if (cred.Username.ToLower() != username2.ToLower())
                        {
                            player.MessageFrom("AuthMe", 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("AuthMe", 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("AuthMe", green + "Successfully logged in!");
                        }
                        break;

                    case "changepw":
                        if (WaitingUsers.ContainsKey(player.UID))
                        {
                            player.MessageFrom("AuthMe", 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("AuthMe", orange + "This steamid is not registered yet!");
                            return;
                        }

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

                        if (username3.Length > 25 || password3.Length > 25)
                        {
                            player.MessageFrom("AuthMe", 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("AuthMe", green + "Password successfully changed!");
                        break;

                    default:
                        player.MessageFrom("AuthMe", orange + "Invalid command. Type /authme for help.");
                        break;
                    }
                }
            }
        }
Exemple #3
0
        private void OnRustBusterUserMessage(API.RustBusterUserAPI user, Message msgc)
        {
            if (msgc.PluginSender == "AuthMe")
            {
                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("AuthMe", orange + "You are logged in already.");
                        msgc.ReturnMessage = "DisApproved";
                        return;
                    }

                    if (!Credentials.ContainsKey(player.UID))
                    {
                        player.MessageFrom("AuthMe", orange + "This steamid is not registered yet!");
                        player.MessageFrom("AuthMe", 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("AuthMe", 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("AuthMe", 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("AuthMe", 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("AuthMe", green + "Successfully logged in!");
                        msgc.ReturnMessage = "Approved";
                    }
                }
                else if (evt == "AuthMeRegister")
                {
                    if (Credentials.ContainsKey(player.UID))
                    {
                        player.MessageFrom("AuthMe",
                                           red + "This STEAMID is already protected using password authentication!");
                        msgc.ReturnMessage = "InvalidRegistration";
                        return;
                    }

                    if (username.ToLower() == "username" || password.ToLower() == "password")
                    {
                        player.MessageFrom("AuthMe", 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("AuthMe", 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("AuthMe", 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("AuthMe",
                                       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";
                }
            }
        }