Beispiel #1
0
        bool CanLootPlayer(BasePlayer target, BasePlayer looter)
        {
            //Check if we have Friends plugin and then if admin or mod
            if (Friends == null || (ServerUsers.Is(looter.userID, ServerUsers.UserGroup.Owner) || ServerUsers.Is(looter.userID, ServerUsers.UserGroup.Moderator)))
            {
                return(true);
            }

            return((bool)Friends.Call("HasFriend", target.userID, looter.userID));
        }
Beispiel #2
0
        /// <summary>
        /// Unbans the player by user ID
        /// </summary>
        public void Unban(ulong id)
        {
            if (!IsBanned(id))
            {
                return;
            }

            ServerUsers.Remove(id);
            ServerUsers.Save();
        }
Beispiel #3
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string id, string reason, TimeSpan duration = default(TimeSpan))
        {
            if (IsBanned(id))
            {
                return;
            }

            ServerUsers.Set(ulong.Parse(id), ServerUsers.UserGroup.Banned, Name, reason);
            ServerUsers.Save();
        }
 void LoadBansFile_CMD(ConsoleSystem.Arg arg)
 {
     if (!arg.IsAdmin)
     {
         return;
     }
     LoadingServerUsers = true;
     ServerUsers.Load();
     LoadingServerUsers = false;
     Puts("Loaded Bans From File");
 }
 public void OnNewConnection(Connection connection)
 {
     connection.connected = false;
     if (connection.token == null || (int)connection.token.Length < 32)
     {
         ConnectionAuth.Reject(connection, "Invalid Token");
         return;
     }
     if (connection.userid == 0)
     {
         ConnectionAuth.Reject(connection, "Invalid SteamID");
         return;
     }
     if (connection.protocol != 2177)
     {
         if (!DeveloperList.Contains(connection.userid))
         {
             ConnectionAuth.Reject(connection, "Incompatible Version");
             return;
         }
         DebugEx.Log(string.Concat("Not kicking ", connection.userid, " for incompatible protocol (is a developer)"), StackTraceLogType.None);
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Banned))
     {
         ConnectionAuth.Reject(connection, "You are banned from this server");
         return;
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Moderator))
     {
         DebugEx.Log(string.Concat(connection.ToString(), " has auth level 1"), StackTraceLogType.None);
         connection.authLevel = 1;
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Owner))
     {
         DebugEx.Log(string.Concat(connection.ToString(), " has auth level 2"), StackTraceLogType.None);
         connection.authLevel = 2;
     }
     if (DeveloperList.Contains(connection.userid))
     {
         DebugEx.Log(string.Concat(connection.ToString(), " is a developer"), StackTraceLogType.None);
         connection.authLevel = 3;
     }
     if (this.IsConnected(connection.userid))
     {
         ConnectionAuth.Reject(connection, "You are already connected!");
         return;
     }
     if (Interface.CallHook("IOnUserApprove", connection) != null)
     {
         return;
     }
     ConnectionAuth.m_AuthConnection.Add(connection);
     base.StartCoroutine(this.AuthorisationRoutine(connection));
 }
Beispiel #6
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string id, string reason, TimeSpan duration = default(TimeSpan))
        {
            if (IsBanned(id))
            {
                return;
            }

            ServerUsers.Set(ulong.Parse(id), ServerUsers.UserGroup.Banned, Name, reason);
            ServerUsers.Save();
            //if (IsConnected) Kick(reason); // TODO: Implement if possible
        }
Beispiel #7
0
        /// <summary>
        /// Unbans the user
        /// </summary>
        public void Unban()
        {
            // Check not banned
            if (!IsBanned)
            {
                return;
            }

            // Set to unbanned
            ServerUsers.Remove(steamId);
            ServerUsers.Save();
        }
Beispiel #8
0
        /// <summary>
        /// Unbans the player
        /// </summary>
        public void Unban(BasePlayer player)
        {
            // Check if unbanned already
            if (!IsBanned(player))
            {
                return;
            }

            // Set to unbanned
            ServerUsers.Remove(player.userID);
            ServerUsers.Save();
        }
Beispiel #9
0
        /// <summary>
        /// Unbans the user
        /// </summary>
        /// <param name="id"></param>
        public void Unban(string id)
        {
            // Check if unbanned already
            if (!IsBanned(id))
            {
                return;
            }

            // Set to unbanned
            ServerUsers.Remove(ulong.Parse(id));
            ServerUsers.Save();
        }
Beispiel #10
0
        /// <summary>
        /// Bans the player for the specified reason and duration
        /// </summary>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string reason, TimeSpan duration = default(TimeSpan))
        {
            // Check already banned
            if (IsBanned)
            {
                return;
            }

            // Set to banned
            ServerUsers.Set(steamId, ServerUsers.UserGroup.Banned, Name, reason);
            ServerUsers.Save();
        }
Beispiel #11
0
        /// <summary>
        /// Unbans this player
        /// </summary>
        public void Unban()
        {
            // Check not banned
            if (!IsBanned)
            {
                return;
            }

            // Set to unbanned
            ServerUsers.Set(steamid, ServerUsers.UserGroup.None, Nickname, string.Empty);
            ServerUsers.Save();
        }
    public static string BanListStringEx()
    {
        string str = "";
        int    num = 1;

        foreach (ServerUsers.User all in ServerUsers.GetAll(ServerUsers.UserGroup.Banned))
        {
            str = string.Concat(new string[] { str, num.ToString(), " ", all.steamid.ToString(), " ", all.username.QuoteSafe(), " ", all.notes.QuoteSafe(), "\n" });
            num++;
        }
        return(str);
    }
    public static string BanListStringEx()
    {
        IEnumerable <ServerUsers.User> all = ServerUsers.GetAll(ServerUsers.UserGroup.Banned);
        string str = "";
        int    num = 1;

        foreach (ServerUsers.User user in all)
        {
            str = str + num.ToString() + " " + user.steamid.ToString() + " " + StringExtensions.QuoteSafe(user.username) + " " + StringExtensions.QuoteSafe(user.notes) + "\n";
            ++num;
        }
        return(str);
    }
Beispiel #14
0
        /// <summary>
        /// Bans this player for the specified reason and duration
        /// </summary>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string reason, TimeSpan duration)
        {
            // Check already banned
            if (IsBanned)
            {
                return;           // TODO: Extend ban duration?
            }
            // Set to banned
            ServerUsers.Set(steamid, ServerUsers.UserGroup.Banned, Nickname, reason);
            ServerUsers.Save();

            // TODO: Set a duration somehow
        }
 public static void Set(ulong uid, ServerUsers.UserGroup group, string username, string notes)
 {
     ServerUsers.Remove(uid);
     ServerUsers.User user = new ServerUsers.User()
     {
         steamid  = uid,
         group    = group,
         username = username,
         notes    = notes
     };
     Interface.CallHook("IOnServerUsersSet", (object)uid, (object)group, (object)username, (object)notes);
     ServerUsers.users.Add(uid, user);
 }
Beispiel #16
0
 private void IOnServerUsersRemove(ulong steamId)
 {
     if (serverInitialized)
     {
         string  id      = steamId.ToString();
         IPlayer iplayer = Covalence.PlayerManager.FindPlayerById(id);
         if (ServerUsers.Is(steamId, ServerUsers.UserGroup.Banned))
         {
             Interface.CallHook("OnPlayerUnbanned", iplayer?.Name ?? "Unnamed", steamId, iplayer?.Address ?? "0");
             Interface.CallHook("OnUserUnbanned", iplayer?.Name ?? "Unnamed", id, iplayer?.Address ?? "0");
         }
     }
 }
Beispiel #17
0
 public void OnNewConnection(Connection connection)
 {
     connection.connected = false;
     if (connection.token == null || connection.token.Length < 32)
     {
         Reject(connection, "Invalid Token");
         return;
     }
     if (connection.userid == 0L)
     {
         Reject(connection, "Invalid SteamID");
         return;
     }
     if (connection.protocol != 2306)
     {
         if (!DeveloperList.Contains(connection.userid))
         {
             Reject(connection, "Incompatible Version");
             return;
         }
         DebugEx.Log("Not kicking " + connection.userid + " for incompatible protocol (is a developer)");
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Banned))
     {
         ServerUsers.User user  = ServerUsers.Get(connection.userid);
         string           text  = user?.notes ?? "no reason given";
         string           text2 = ((user != null && user.expiry > 0) ? (" for " + (user.expiry - Epoch.Current).FormatSecondsLong()) : "");
         Reject(connection, "You are banned from this server" + text2 + " (" + text + ")");
         return;
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Moderator))
     {
         DebugEx.Log(connection.ToString() + " has auth level 1");
         connection.authLevel = 1u;
     }
     if (ServerUsers.Is(connection.userid, ServerUsers.UserGroup.Owner))
     {
         DebugEx.Log(connection.ToString() + " has auth level 2");
         connection.authLevel = 2u;
     }
     if (DeveloperList.Contains(connection.userid))
     {
         DebugEx.Log(connection.ToString() + " is a developer");
         connection.authLevel = 3u;
     }
     if (Interface.CallHook("IOnUserApprove", connection) == null)
     {
         m_AuthConnection.Add(connection);
         StartCoroutine(AuthorisationRoutine(connection));
     }
 }
Beispiel #18
0
        /// <summary>
        /// Bans the player from the server
        /// </summary>
        /// <param name="player"></param>
        /// <param name="reason"></param>
        public void Ban(BasePlayer player, string reason = "")
        {
            if (IsBanned(player))
            {
                return;
            }

            ServerUsers.Set(player.userID, ServerUsers.UserGroup.Banned, player.displayName, reason);
            ServerUsers.Save();
            if (IsConnected(player))
            {
                Kick(player, reason);
            }
        }
Beispiel #19
0
 void ClearLocalBans(ConsoleSystem.Arg arg)
 {
     if (!arg.IsAdmin)
     {
         return;
     }
     LoadingServerUsers = true;
     foreach (var ban in ServerUsers.GetAll(ServerUsers.UserGroup.Banned).ToList())
     {
         ServerUsers.Remove(ban.steamid);
     }
     LoadingServerUsers = false;
     Puts($"Cleared Server Bans");
 }
Beispiel #20
0
        private IEnumerator SaveBansToDatabase()
        {
            var bans = ServerUsers.GetAll(ServerUsers.UserGroup.Banned).ToList();

            yield return(null); //Gotta have that debug message show when you first load the plguin

            Puts($"Starting To Push {bans.Count} Bans To Database");
            foreach (var user in bans)
            {
                UpdateUserGroup(user.steamid, user.group, user.username, user.notes);
                yield return(null);
            }
            Puts("Finished Saving All Bans To The Database");
            yield return(null);
        }
    private bool CanJumpQueue(Connection connection)
    {
        object obj = Interface.CallHook("CanBypassQueue", (object)connection);

        if (obj is bool)
        {
            return((bool)obj);
        }
        if (DeveloperList.Contains((ulong)connection.userid))
        {
            return(true);
        }
        ServerUsers.User user = ServerUsers.Get((ulong)connection.userid);
        return(user != null && user.group == ServerUsers.UserGroup.Moderator || user != null && user.group == ServerUsers.UserGroup.Owner);
    }
Beispiel #22
0
        void ToggleAdmin(BasePlayer player)
        {
            if (!CheckPermission(player))
            {
                return;
            }

            if (!data.AdminData.ContainsKey(player.userID.ToString()))
            {
                data.AdminData.Add(player.userID.ToString(), new AdminData(player));
            }

            if (data.AdminData[player.userID.ToString()].PlayerName == "")
            {
                SendChatMessage(player, "AdminToggle", "You did not set up your player name yet. Set it up using /setplayername");
                return;
            }

            displayname.SetValue(player, data.AdminData[player.userID.ToString()].EnabledPlayerMode ? data.AdminData[player.userID.ToString()].AdminName : data.AdminData[player.userID.ToString()].PlayerName);

            if (data.AdminData[player.userID.ToString()].EnabledPlayerMode)
            {
                ServerUsers.Set(player.userID, ServerUsers.UserGroup.Owner, player.displayName, "");
                ConVar.Server.writecfg(new ConsoleSystem.Arg(""));

                permission.AddUserGroup(player.userID.ToString(), Config["Groups", "Admin Group"].ToString());
                permission.RemoveUserGroup(player.userID.ToString(), Config["Groups", "Player Group"].ToString());

                SendChatMessage(player, "AdminToggle", "You switched to admin mode!");
            }
            else
            {
                ServerUsers.Set(player.userID, ServerUsers.UserGroup.None, player.displayName, "");
                ConVar.Server.writecfg(new ConsoleSystem.Arg(""));

                permission.AddUserGroup(player.userID.ToString(), Config["Groups", "Player Group"].ToString());
                permission.RemoveUserGroup(player.userID.ToString(), Config["Groups", "Admin Group"].ToString());


                SendChatMessage(player, "AdminToggle", "You switched to player mode!");
            }

            data.AdminData[player.userID.ToString()].EnabledPlayerMode = !data.AdminData[player.userID.ToString()].EnabledPlayerMode;
            SaveData();

            SendChatMessage(player, "AdminToggle", "You will be kicked in 5 seconds to update your status. Please reconnect!");
            timer.Once(5, () => player.SendConsoleCommand("client.disconnect"));
        }
Beispiel #23
0
        /// <summary>
        /// Bans the player from the server based on user ID
        /// </summary>
        /// <param name="id"></param>
        /// <param name="reason"></param>
        public void Ban(ulong id, string reason = "")
        {
            if (IsBanned(id))
            {
                return;
            }

            var player = FindById(id);

            ServerUsers.Set(id, ServerUsers.UserGroup.Banned, player?.displayName ?? "Unknown", reason);
            ServerUsers.Save();
            if (player != null && IsConnected(player))
            {
                Kick(player, reason);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Bans the player from the server
        /// </summary>
        /// <param name="player"></param>
        /// <param name="reason"></param>
        public void Ban(BasePlayer player, string reason = "")
        {
            // Check if already banned
            if (IsBanned(player))
            {
                return;
            }

            // Ban and kick user
            ServerUsers.Set(player.userID, ServerUsers.UserGroup.Banned, player.displayName, reason);
            ServerUsers.Save();
            if (IsConnected(player))
            {
                Kick(player, reason);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Bans the user for the specified reason and duration
        /// </summary>
        /// <param name="reason"></param>
        /// <param name="duration"></param>
        public void Ban(string reason, TimeSpan duration = default(TimeSpan))
        {
            // Check if already banned
            if (IsBanned)
            {
                return;
            }

            // Ban and kick user
            ServerUsers.Set(steamId, ServerUsers.UserGroup.Banned, Name, reason);
            ServerUsers.Save();
            if (IsConnected)
            {
                Kick(reason);
            }
        }
Beispiel #26
0
 //Hook Load (Load from DB instead of File)
 void OnServerLoadUsers()
 {
     //NOW DO YOUR LOAD STUFF HERE
     LoadingServerUsers = true;
     foreach (var row in banDB.Query($"SELECT * FROM {TableName}"))
     {
         //https://stackoverflow.com/questions/11226448/invalidcastexception-long-to-ulong
         //Never knew you had to cast to long then ulong in a specific situation
         ulong steamID = (ulong)((long)row.Value["steamid"]);
         ServerUsers.UserGroup group = (ServerUsers.UserGroup)row.Value.GetInt("usergroup");
         string name   = row.Value.GetString("username") ?? "";
         string reason = row.Value.GetString("notes") ?? "";
         ServerUsers.Set(steamID, group, name, reason);
     }
     LoadingServerUsers = false;
 }
        private void cmdChatDroplimit(BasePlayer player, string command, string[] args)
        {
            var usage = _("Usage: /droplimit \"ITEMNAME\" [LIMIT]");

            if (!initialized)
            {
                return;
            }
            if (!ServerUsers.Is(player.userID, ServerUsers.UserGroup.Owner))
            {
                SendReply(player, _("You are not authorized to modify drop limits"));
                return;
            }
            if (args.Length < 1)
            {
                SendReply(player, usage);
                return;
            }
            string name = args[0];
            int    currentLimit;

            if (!dropLimits.TryGetValue(name, out currentLimit))
            {
                SendReply(player, _("No such item:") + " " + name);
                return;
            }
            if (args.Length == 1)
            {
                SendReply(player, _("Drop limit of '%NAME%' is %LIMIT%", new Dictionary <string, string>()
                {
                    { "ITEM", name },
                    { "LIMIT", currentLimit.ToString() }
                }));
                return;
            }
            int limit = Convert.ToInt32(args[1]);

            dropLimits[name] = limit;
            SaveConfig();
            SendReply(player, "Drop limit of '%NAME%' has been changed from %LIMIT% to %NEWLIMIT%", new Dictionary <string, string>()
            {
                { "NAME", name },
                { "LIMIT", currentLimit.ToString() },
                { "NEWLIMIT", limit.ToString() }
            });
        }
Beispiel #28
0
        public static void unban(ConsoleSystem.Arg arg)
        {
            ulong num = arg.GetUInt64(0, (ulong)0);

            if (num < 70000000000000000L)
            {
                arg.ReplyWith(string.Concat("This doesn't appear to be a 64bit steamid: ", num));
                return;
            }
            ServerUsers.User user = ServerUsers.Get(num);
            if (user == null || user.@group != ServerUsers.UserGroup.Banned)
            {
                arg.ReplyWith(string.Concat("User ", num, " isn't banned"));
                return;
            }
            ServerUsers.Remove(num);
            arg.ReplyWith(string.Concat("Unbanned User: ", num));
        }
Beispiel #29
0
        public static void removeowner(Arg arg)
        {
            ulong uInt = arg.GetUInt64(0, 0uL);

            if (uInt < 70000000000000000L)
            {
                arg.ReplyWith("This doesn't appear to be a 64bit steamid: " + uInt);
                return;
            }
            ServerUsers.User user = ServerUsers.Get(uInt);
            if (user == null || user.group != ServerUsers.UserGroup.Owner)
            {
                arg.ReplyWith("User " + uInt + " isn't an owner");
                return;
            }
            ServerUsers.Remove(uInt);
            arg.ReplyWith("Removed Owner: " + uInt);
        }
Beispiel #30
0
        public static void unban(Arg arg)
        {
            ulong uInt = arg.GetUInt64(0, 0uL);

            if (uInt < 70000000000000000L)
            {
                arg.ReplyWith($"This doesn't appear to be a 64bit steamid: {uInt}");
                return;
            }
            ServerUsers.User user = ServerUsers.Get(uInt);
            if (user == null || user.group != ServerUsers.UserGroup.Banned)
            {
                arg.ReplyWith($"User {uInt} isn't banned");
                return;
            }
            ServerUsers.Remove(uInt);
            arg.ReplyWith("Unbanned User: " + uInt);
        }