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