Country Blacklist

justcyber

New Member
Member
Jan 3, 2015
13
0
1
56
Can someone make a country blacklist?? I use to use Oxide and converted to Fougerite. Here is the LUA version of the file... PLEASE!!!





Code:
PLUGIN.Title = "Countries Filter - Geolocalisation"
PLUGIN.Description = "Filter Countries or/and get the localisation of a player"
PLUGIN.Version = "1.1.1"
PLUGIN.Author = "Reneb"

function PLUGIN:Init()
    local b, res = config.Read( "countriesfilter" )
    self.Config = res or {}
    if (not b) then
        self:LoadDefaultConfig()
        if (res) then config.Save( "countriesfilter" ) end
    end
    if(self.Config.whitelist and self.Config.blacklist) then
        print("Error Whitelist and Blacklist set to true, shutting down the script")
        return
    end
    self:AddChatCommand( "from", self.fromCmd )
end

function PLUGIN:LoadDefaultConfig()
    self.Config.whitelist             =    false
    self.Config.blacklist             =    false
    self.Config.list = {
    "FR",
    "DE"
    }
    self.Config.cmdforAdminonly = true
    self.Config.showCountryOnJoin = true
end
function PLUGIN:OnUserConnect( netuser )
    local ip = netuser.networkPlayer.ipAddress
    local url = "http://ip-api.com/json/" .. ip
    local b = webrequest.Send( url, function( code, response )
        self:callbackWebrequest( code, response, netuser )
end )
    if (not b) then print( "Webrequest send failed!" ) end
   
end
function PLUGIN:callbackWebrequest( code, response, netuser)
    local isinlist = false
    local rejected = false
    local resp = json.decode(response)
    if(not resp) then print("couldn't find location for " .. netuser.displayName) return end
    if(not resp["countryCode"]) then print("couldn't find location for " .. netuser.displayName) return end
    for i = 1, #self.Config.list do
        if(self.Config.list[i]==resp["countryCode"]) then
            isinlist = true
        end
    end
    if(self.Config.whitelist) and (not isinlist) then
        rejected = true
    elseif(self.Config.blacklist) and (isinlist) then
        rejected = true
    end
    if(resp["countryCode"] == "XX") then rejected = false end
    if(rejected) then
        netuser:Kick(NetError.Facepunch_Kick_Ban, true)
        return
    end
    if(self.Config.showCountryOnJoin) and (response ~= "XX") then
        rust.BroadcastChat("Oxmin", netuser.displayName .. " comes from " .. resp["country"])
    end
end
function PLUGIN:fromCmd(netuser, cmd, args)
    if (not(args[1])) then
        return
    end
    if( self.Config.cmdforAdminonly and not netuser:canadmin() ) then
        return
    end
    local b, targetuser = rust.FindNetUsersByName( args[1] )
    if (not b) then
        if (targetuser == 0) then
            rust.Notice( netuser, "No players found with that name!" )
        else
            rust.Notice( netuser, "Multiple players found with that name!" )
        end
        return
    end
    local ip = targetuser.networkPlayer.ipAddress
    local url = "http://ip-api.com/json/" .. ip
    local b = webrequest.Send( url, function( code, response )
        self:fromTell( netuser, targetuser, code, response  )
end )
    if (not b) then print( "Webrequest send failed!" ) end
end
function PLUGIN:fromTell(netuser,targetuser,code,response)
    local resp = json.decode(response)
    if(not resp["countryCode"]) then
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " couldn't be located")
    elseif(resp["countryCode"] == "XX") then
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " couldn't be located")
    else
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " is from " .. resp["country"])
    end
end
 
Should be fairly easy to convert to python or js. Any specific reason you want to prevent ppl from other countries from joining your server?
 
Can someone make a country blacklist?? I use to use Oxide and converted to Fougerite. Here is the LUA version of the file... PLEASE!!!





Code:
PLUGIN.Title = "Countries Filter - Geolocalisation"
PLUGIN.Description = "Filter Countries or/and get the localisation of a player"
PLUGIN.Version = "1.1.1"
PLUGIN.Author = "Reneb"

function PLUGIN:Init()
    local b, res = config.Read( "countriesfilter" )
    self.Config = res or {}
    if (not b) then
        self:LoadDefaultConfig()
        if (res) then config.Save( "countriesfilter" ) end
    end
    if(self.Config.whitelist and self.Config.blacklist) then
        print("Error Whitelist and Blacklist set to true, shutting down the script")
        return
    end
    self:AddChatCommand( "from", self.fromCmd )
end

function PLUGIN:LoadDefaultConfig()
    self.Config.whitelist             =    false
    self.Config.blacklist             =    false
    self.Config.list = {
    "FR",
    "DE"
    }
    self.Config.cmdforAdminonly = true
    self.Config.showCountryOnJoin = true
end
function PLUGIN:OnUserConnect( netuser )
    local ip = netuser.networkPlayer.ipAddress
    local url = "http://ip-api.com/json/" .. ip
    local b = webrequest.Send( url, function( code, response )
        self:callbackWebrequest( code, response, netuser )
end )
    if (not b) then print( "Webrequest send failed!" ) end

end
function PLUGIN:callbackWebrequest( code, response, netuser)
    local isinlist = false
    local rejected = false
    local resp = json.decode(response)
    if(not resp) then print("couldn't find location for " .. netuser.displayName) return end
    if(not resp["countryCode"]) then print("couldn't find location for " .. netuser.displayName) return end
    for i = 1, #self.Config.list do
        if(self.Config.list[i]==resp["countryCode"]) then
            isinlist = true
        end
    end
    if(self.Config.whitelist) and (not isinlist) then
        rejected = true
    elseif(self.Config.blacklist) and (isinlist) then
        rejected = true
    end
    if(resp["countryCode"] == "XX") then rejected = false end
    if(rejected) then
        netuser:Kick(NetError.Facepunch_Kick_Ban, true)
        return
    end
    if(self.Config.showCountryOnJoin) and (response ~= "XX") then
        rust.BroadcastChat("Oxmin", netuser.displayName .. " comes from " .. resp["country"])
    end
end
function PLUGIN:fromCmd(netuser, cmd, args)
    if (not(args[1])) then
        return
    end
    if( self.Config.cmdforAdminonly and not netuser:canadmin() ) then
        return
    end
    local b, targetuser = rust.FindNetUsersByName( args[1] )
    if (not b) then
        if (targetuser == 0) then
            rust.Notice( netuser, "No players found with that name!" )
        else
            rust.Notice( netuser, "Multiple players found with that name!" )
        end
        return
    end
    local ip = targetuser.networkPlayer.ipAddress
    local url = "http://ip-api.com/json/" .. ip
    local b = webrequest.Send( url, function( code, response )
        self:fromTell( netuser, targetuser, code, response  )
end )
    if (not b) then print( "Webrequest send failed!" ) end
end
function PLUGIN:fromTell(netuser,targetuser,code,response)
    local resp = json.decode(response)
    if(not resp["countryCode"]) then
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " couldn't be located")
    elseif(resp["countryCode"] == "XX") then
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " couldn't be located")
    else
        rust.SendChatToUser( netuser, "From", targetuser.displayName .. " is from " .. resp["country"])
    end
end

Here is a Python version.
Not sure if it works.
[EDIT: Removed the ZIP file. Download from here: [url]http://fougerite.com/resources/countryblacklist.90/[/URL]]
Python:
__title__ = 'CountryBlackList'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr
clr.AddReferenceByPartialName("UnityEngine")
clr.AddReferenceByPartialName("Fougerite")
import UnityEngine
import Fougerite


class CountryBlackList:
    def On_PluginInit(self):
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "BlackListedCountries", "AU, NZ, DK, HK, KR, KP, RU")
            ini.AddSetting("Config", "JoinMessage", "%player% has connected from: %country%")
            ini.AddSetting("Config", "DisconnectMessage", "Your country is on the servers blacklist")
            ini.AddSetting("Config", "OtherDisconnectMessage", "%player% is trying to connect from: %country% but is black listed")
            ini.AddSetting("Config", "LogBlackListedConnection", "true")
            ini.AddSetting("Config", "LogAcceptedConnection", "true")
            ini.AddSetting("Config", "LogTimedOutConnection", "true")
            ini.Save()
        ini = Plugin.GetIni("Settings")
        DataStore.Add("BlackList", "Counties", ini.GetSetting("Config", "BlackListedCountries"))
        DataStore.Add("BlackList", "JoinMSG", ini.GetSetting("Config", "JoinMessage"))
        DataStore.Add("BlackList", "DisMSG", ini.GetSetting("Config", "DisconnectMessage"))
        DataStore.Add("BlackList", "OtherDisMSG", ini.GetSetting("Config", "OtherDisconnectMessage"))
        DataStore.Add("BlackList", "LogB", ini.GetSetting("Config", "LogBlackListedConnection"))
        DataStore.Add("BlackList", "LogA", ini.GetSetting("Config", "LogAcceptedConnection"))
        DataStore.Add("BlackList", "LogT", ini.GetSetting("Config", "LogTimedOutConnection"))

    def On_PlayerConnected(self, Player):
        try:
            country = Web.GET("http://ipinfo.io/" + Player.IP + "/country")
            bl = DataStore.Get("BlackList", "Counties")
            if bl.find(country):
                pdis = DataStore.Get("BlackList", "DisMSG")
                Player.Message(pdis)
                Player.Disconnect()
                a = DataStore.Get("BlackList", "OtherDisMSG")
                a = a.replace("%player%", Player.Name)
                a = a.replace("%country%", country)
                Server.Broadcast(a)
                if DataStore.Get("BlackList", "LogB") == "true":
                    log = self.GetLog()
                    log.AddSetting("BlackListed Connection", Player.SteamID, "[" +Player.IP + "=" + Player.Name + "]")
                    log.Save()
            else:
                a = DataStore.Get("BlackList", "JoinMSG")
                a = a.replace("%player%", Player.Name)
                a = a.replace("%country%", country)
                Server.Broadcast(a)
                if DataStore.Get("BlackList", "LogA") == "true":
                    log = self.GetLog()
                    log.AddSetting("Accepted Connection", Player.SteamID, "[" +Player.IP + "=" + Player.Name + "]")
                    log.Save()
        except:
            a = DataStore.Get("BlackList", "JoinMSG")
            a = a.replace("%player%", Player.Name)
            a = a.replace("%country%", "unknown")
            Server.Broadcast(a)
            if DataStore.Get("BlackList", "LogT") == "true":
                log = self.GetLog()
                log.AddSetting("TimedOut Connection", Player.SteamID, "[" +Player.IP + "=" + Player.Name + "]")
                log.Save()

    def GetLog(self):
        if not Plugin.IniExists("ConnectionLog"):
            Plugin.CreateIni("ConnectionLog")
            ini = Plugin.GetIni("ConnectionLog")
            ini.AddSetting("TimedOut Connection", "", "")
            ini.AddSetting("BlackListed Connection", "", "")
            log.AddSetting("Accepted Connection", "", "")
            ini.Save()
        return Plugin.GetIni("ConnectionLog")
 
Last edited:
  • Like
Reactions: justcyber
Should be fairly easy to convert to python or js. Any specific reason you want to prevent ppl from other countries from joining your server?

Yes I am having problems with on Country in particular. All I needed was to blacklist that one country :)
 
Yes I am having problems with on Country in particular. All I needed was to blacklist that one country :)

That's xenophobia ! Nah just joking :p

But that won't stop players from using proxy and "virtualizing" their country.
 
I know they can use a VPN and start playing the game, but they only have so many VPN IP addresses. Are Sock5 proxies being used as well?