Go through Server.Players Dictionary ? Ban by IP ?

Status
Not open for further replies.

coersum

Plugin Developer
Plugin Developer
Oct 9, 2014
77
5
8
47
Parts Unknown
So I have have a few ppl that I only have the IP / name of, and I need to ban them. However, it seems there is no ban by IP unless the player is online.

Is it possible to get the SteamID from the Server.Players Dictionary, and if so how ? Sorry I have never worked with dictionaries and my efforts so far with it have been fruitless.

Any help is greatly appreciated.
Thank you
 

xEnt

Retired Staff
Retired Staff
Sep 6, 2014
48
17
8
make a config file, put IPs in there, write a plugin, on client auth, disconnect if players IP is in the list
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
So I have have a few ppl that I only have the IP / name of, and I need to ban them. However, it seems there is no ban by IP unless the player is online.

Is it possible to get the SteamID from the Server.Players Dictionary, and if so how ? Sorry I have never worked with dictionaries and my efforts so far with it have been fruitless.

Any help is greatly appreciated.
Thank you
I'd do what xEnt said,
If you want you can use a Whitelist plugin I made a few days back that I made for a friend.
Convert / Change what you need
JavaScript:
//Author: Jakkee
//Version: 1.0

function On_PluginInit() {
    if (!Plugin.IniExists("Settings")){
        var ini = Plugin.CreateIni("Settings");
        ini.AddSetting("Settings", "Enabled", "true");
        ini.AddSetting("Settings", "ServerName", "WhiteList");
        ini.AddSetting("Settings", "DisconnectMSG0", "You are not whitelisted, to be whitelisted");
        ini.AddSetting("Settings", "DisconnectMSG1", "Visit: http://google.com/forums/whitelist");
    }
    var ini = Plugin.GetIni("Settings");
    DataStore.Add("WhiteList", "Enabled", ini.GetSetting("Settings", "Enabled")=="true"?true:false);
    DataStore.Add("WhiteList", "ServerName", ini.GetSetting("Settings", "ServerName"));
    DataStore.Add("WhiteList", "MSG0", ini.GetSetting("Settings", "DisconnectMSG0"));
    DataStore.Add("WhiteList", "MSG1", ini.GetSetting("Settings", "DisconnectMSG1"));
}

var WhiteList = {
    get Enabled() { return DataStore.Get("WhiteList", "Enabled");},
    get ServerName() { return DataStore.Get("WhiteList", "ServerName");},
    get MSG0() { return DataStore.Get("WhiteList", "MSG0");},
    get MSG1() { return DataStore.Get("WhiteList", "MSG1");}
}

function On_Command(Player, cmd, args){
    switch (cmd){
        case "whitelist":
            if (Player.Admin){
                if (args.Length == 0){
                    Player.MessageFrom(WhiteList.ServerName, "usage: /whitelist [enable/disable]");
                }
                else if (args.Length == 1){
                    if(args[0] == "enable"){
                        if (WhiteList.Enabled){
                            Player.MesageFrom(WhiteList.ServerName, "Already enabled");
                        }else{
                            var ini = Plugin.GetIni("Settings");
                            ini.DeleteSetting("Settings", "Enabled");
                            ini.AddSetting("Settings", "Enabled", "true");
                            DataStore.Remove("WhiteList", "Enabled");
                            DataStore.Add("WhiteList", "Enabled", "true"=="true"?true:false);
                            Player.MessageFrom(WhiteList.ServerName, "WhiteList Enabled");
                        }
                    }
                    else if(args[0] == "disable"){
                        if (WhiteList.Enabled){
                            var ini = Plugin.GetIni("Settings");
                            ini.DeleteSetting("Settings", "Enabled");
                            ini.AddSetting("Settings", "Enabled", "false");
                            DataStore.Remove("WhiteList", "Enabled");
                            DataStore.Add("WhiteList", "Enabled", "false"=="true"?true:false);
                            Player.MessageFrom(WhiteList.ServerName, "WhiteList Disabled");
                        }else{
                            Player.MesageFrom(WhiteList.ServerName, "Already disabled");
                        }
                    }else{
                        Player.MessageFrom(WhiteList.ServerName, "unknown command");
                    }
                }else{
                    Player.MessageFrom(WhiteList.ServerName, "usage: /whitelist [enable/disable]");
                }
            }else{
                Player.MessageFrom(WhiteList.ServerName, "You don't have access to that command!");
            }
        case "whitelistadd":
            if (Player.Admin){
                if(args.Length == 0){
                    Player.Message("Usage: /whitelistadd [SteamID]");
                }
                if(args.Length == 1){
                var text = argsToText(args);
                    if (!isWhiteListed(text)){
                        var Date = Plugin.GetDate();
                        var ini = getUsersIni();
                        ini.AddSetting("WhiteListed", text, "|Date: "+Date+"||By: "+Player.Name);
                        ini.Save();
                        Player.MessageFrom(WhiteList.ServerName, text + " has been whitelisted");
                    }else{
                        Player.MessageFrom(WhiteList.ServerName, text + " is already whitelist");
                    }
                }
                if(args.Length > 1) {
                    Player.MessageFrom(WhiteList.ServerName, "Too many arguments");
                }
            }else{
                Player.MessageFrom(WhiteList.ServerName, "You don't have access to that command!");
            }
        break;
        case "whitelistremove":
            if (Player.Admin){
                if(args.Length == 0){
                    Player.Message("Usage: /whitelistremove [SteamID]");
                }
                if(args.Length == 1){
                var text = argsToText(args);
                    if (isWhiteListed(text)){
                        var ini = getUsersIni();
                        ini.DeleteSetting("WhiteListed", text);
                        ini.Save();
                        Player.MessageFrom(WhiteList.ServerName, text + " has been removed from the whitelist");
                    }else{
                        Player.MessageFrom(WhiteList.ServerName, text + " is not on the whitelist");
                    }
                }
                if(args.Length > 1) {
                    Player.MessageFrom(WhiteList.ServerName, "Too many arguments");
                }
            }else{
                Player.MessageFrom(WhiteList.ServerName, "You don't have access to that command!");
            }
        break;
    }
}

function On_PlayerConnected(Player){
    if(!isWhiteListed(Player)){
        Player.Notice("You are not whitelisted");
        Player.Message(WhiteList.MSG0);
        Player.Message(WhiteList.MSG1);
        Player.Disconnect();
    }
}

function getUsersIni(){
    if (!Plugin.IniExists("WhiteList")){
        var ini = Plugin.CreateIni("WhiteList");
        ini.Save();
    }
    return Plugin.GetIni("WhiteList");
}

function isWhiteListed(Player){
    var ini = getUserIni();
    if (ini.GetSetting("WhiteList", Player.SteamID) != null){
        return true;
    }else{
        return false;
    }
}
This just gets a players ID and if that ID is on the list they are allowed in the server.
you're free to change this to what you need.

EDIT:
Commands:
/whitelist [enabled/disable]
/whitelistadd [SteamID]
/whitelistremove [SteamID]
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
So I have have a few ppl that I only have the IP / name of, and I need to ban them. However, it seems there is no ban by IP unless the player is online.

Is it possible to get the SteamID from the Server.Players Dictionary, and if so how ? Sorry I have never worked with dictionaries and my efforts so far with it have been fruitless.

Any help is greatly appreciated.
Thank you
The Server.Players is a Dictionary<ulong, Player>, which means the key is the player's id, the value is the player object. If you have a baseplayer or an ulong steamid, you don't need to find the player, just :
player = Server.Players[userID]

Also, you should look in utilizing the offlineplayers class, it stores ip, steamid and name.
 
Status
Not open for further replies.