• Country filter
    17 replies, posted
Hii! Some of you know about a country filter scrip / plugin for my gmod server?? Thanks for your time.
[QUOTE=kaskull;43409306]Hii! Some of you know about a country filter scrip / plugin for my gmod server?? Thanks for your time.[/QUOTE] Find a GeoIP service with an API, use http.Post/Fetch to use the API of that service, use the player's API, and then do whatever from there.
[QUOTE=Ghost_Sailor;43409341]Find a GeoIP service with an API, use http.Post/Fetch to use the API of that service, use the player's API, and then do whatever from there.[/QUOTE] Thanks for reading Ghost_Sailor, but im not a coder, i'm a big noob about that, and this is why i'm asking if you know about a done script that just allow my country users get in.
So i supose that no one know about some plugin...
Nobody will want to make it for free, and if it doesn't exist then you're out of luck.
Oh come on guys it wasn't that hard. [code] local allowedcountries = { ES = true } //ES = Spain - Check here for other codes http://www.iso.org/iso/country_names_and_code_elements hook.Add("PlayerInitialSpawn", "CheckCountry", function(ply) local ipport = ply:IPAddress() if ipport == "loopback" then return end // singleplayer local ip = string.Explode(":", ipport)[1] // Gets ip and not ip:port local function complete(jsondata) if jsondata then // Make sure we got data local jsontbl = util.JSONToTable(jsondata) // Decode it local countrycode = jsontbl["countryCode"] if countrycode and not allowedcountries[countrycode] then ply:Kick("Wrong country.") end end end http.Fetch(string.format("http://ip-api.com/json/%s", ip),complete,complete) end) [/code] This is untested, come back if it errors or doesn't work. Keep in mind that IP's are not a reliable source for where people actually are. This means that this script could kick out people who actually are in spain, or let in americans.
[QUOTE=Donkie;43441558]Oh come on guys it wasn't that hard. [code] local allowedcountries = { ES = true } //ES = Spain - Check here for other codes http://www.iso.org/iso/country_names_and_code_elements hook.Add("PlayerInitialSpawn", "CheckCountry", function(ply) local function complete(jsondata) if jsondata then // Make sure we got data local jsontbl = util.JSONToTable(jsondata) // Decode it local countrycode = jsontbl["countryCode"] if countrycode and not allowedcountries[countrycode] then ply:Kick("Wrong country.") end end end http.Fetch(string.format("http://ip-api.com/json/%s", ip),complete,complete) end)[/code] This is untested, come back if it errors or doesn't work. Keep in mind that IP's are not a reliable source for where people actually are. This means that this script could kick out people who actually are in spain, or let in americans.[/QUOTE] Please, at least have the courtesy to kick people out before they download all your content. [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url]
[QUOTE=Jarva;43441704]Please, at least have the courtesy to kick people out before they download all your content. [url]http://wiki.garrysmod.com/page/GM/CheckPassword[/url][/QUOTE] Except http.Fetch is asynchronous and gets a callback.
[QUOTE=Handsome Matt;43442257]Kicking still works whilst they're (down)loading.[/QUOTE] How do you kick them though, CheckPassword doesn't give you a player entity you can call :Kick() on?
[QUOTE=Handsome Matt;43442803]When we used to rely on gatekeeper for this sort of stuff it gave us a user id and 2 functions gatekeeper.Drop( userid, reason ) and gatekeeper.DropByIPAddress( ip, reason ). Sad to see this hasn't been replicated as well. I think.. This [I]might[/I] work ( if it accepts SteamID, documentation is little ):[/QUOTE] Yeah I didn't think the kick command accepted steamid, I'll try it out. Another option might be to ip ban them and then unban them straight away. I'm not using gatekeeper at the moment and I sorely miss the ability to get the total number of players (in game + connecting). EDIT: Yeah 'kick' requires a name... tried this with a real steamid of someone in game. [code] kick "STEAM_0:1:5xxxx" name "STEAM_0:1:5xxxx" not found [/code]
[lua] gatekeeper={} local spawning={} gameevent.Listen("player_connect") gameevent.Listen("player_disconnect") function gatekeeper.Drop(userid, reason) game.ConsoleCommand(string.format("kickid %d %s\n",userid,reason:gsub('[;|\n]',''))) end function gatekeeper.GetNumClients() local active=#player.GetAll() return {spawning=#spawning, active=active, total=#spawning+active} end function gatekeeper.GetUserByAddress(addr) for k,v in pairs(player.GetAll()) do if(v:IPAddress()==addr) then return v:UserID() end end end hook.Add("player_connect", "GateKeeper", function(data) local ret=hook.Call("PlayerPasswordAuth", GAMEMODE, data.name, "", data.networkid, data.address) print(ret) if(type(ret)=="string") then gatekeeper.Drop(data.userid, ret) return elseif(type(ret)=="boolean") then if(ret) then gatekeeper.Drop(data.userid, "Bad Password") return end end table.insert(spawning, data.userid) end) hook.Add("player_disconnect", "GateKeeper", function(data) for k,v in pairs(spawning) do if(data.userid==v) then table.remove(spawning, k) break end end end) hook.Add("PlayerInitialSpawn", "GateKeeper", function(ply) for k,v in pairs(spawning) do if(ply:UserID()==v) then table.remove(spawning, k) break end end end) function gatekeeper.DropAllClients(reason) for k,v in pairs(spawning) do gatekeeper.Drop(v, reason) end for k,v in pairs(player.GetAll()) do gatekeeper.Drop(v, reason) end end [/lua] Gatekeeper module remade in Lua. I forgot who made this.
[QUOTE=Shinycow;43443060][URL="http://facepunch.com/showthread.php?t=695636&p=38514535&viewfull=1#post38514535"]fatekeeper[/URL] [/QUOTE] Thanks, I'd seen that before but forgot it tracked connecting players.
[QUOTE=Shinycow;43443060][lua]function gatekeeper.Drop(userid, reason) game.ConsoleCommand(string.format("kickid %d %s\n",userid,reason:gsub(';|\n',''))) end[/lua][/QUOTE] That's some faulty code. Lua uses Patterns, not RegEx and thus the "|" isn't a valid operator.
[QUOTE=Shinycow;43443060][lua] gatekeeper={} local spawning={} gameevent.Listen("player_connect") gameevent.Listen("player_disconnect") function gatekeeper.Drop(userid, reason) game.ConsoleCommand(string.format("kickid %d %s\n",userid,reason:gsub(';|\n',''))) end function gatekeeper.GetNumClients() local active=#player.GetAll() return {spawning=#spawning, active=active, total=#spawning+active} end function gatekeeper.GetUserByAddress(addr) for k,v in pairs(player.GetAll()) do if(v:IPAddress()==addr) then return v:UserID() end end end hook.Add("player_connect", "GateKeeper", function(data) local ret=hook.Call("PlayerPasswordAuth", GAMEMODE, data.name, "", data.networkid, data.address) print(ret) if(type(ret)=="string") then gatekeeper.Drop(data.userid, ret) return elseif(type(ret)=="boolean") then if(ret) then gatekeeper.Drop(data.userid, "Bad Password") return end end table.insert(spawning, data.userid) end) hook.Add("player_disconnect", "GateKeeper", function(data) for k,v in pairs(spawning) do if(data.userid==v) then table.remove(spawning, k) break end end end) hook.Add("PlayerInitialSpawn", "GateKeeper", function(ply) for k,v in pairs(spawning) do if(ply:UserID()==v) then table.remove(spawning, k) break end end end) function gatekeeper.DropAllClients(reason) for k,v in pairs(spawning) do gatekeeper.Drop(v, reason) end for k,v in pairs(player.GetAll()) do gatekeeper.Drop(v, reason) end end [/lua] Gatekeeper module remade in Lua. I forgot who made this.[/QUOTE] Me. And @Evac is PARTIALLY right. Replace the gsub with "[;|\n]"
[QUOTE=Map in a box;43444033]Me. And @Evac is PARTIALLY right. Replace the gsub with "[;|\n]"[/QUOTE] Partly correct? Please tell me which part of what I said is only "partly correct". Regardless, why do you keep insisting on using |? As far as I know it has no special importance in the console so I don't see the reason for escaping it so for me it looks like you're trying to do an "; OR \n" statement and that's not how it works. [code] string:gsub( "[;\n]", "" ) [/code] Is all you need for secaping both ; and \n.
Late bump but it was to filter out the pipe symbol too
Sorry, you need to Log In to post a reply to this thread.