0


1

[This is for AMX2D] So as you know, I failed the first time to create a Get IP script, and I guess it was mainly because I had reformatted the whole basic.lua file (if you open it up, you'll see what I mean...) (Now I iz using Notepad++, so the format problem shouldn't happen) And is it possible for something like whitelisting USGNs? Example: Lets say I subnet banned a certain player, and someone else who had the same exact subnet gets banned. Is it possible for me to say, unban him via USGN?

flag offensive
asked 2010-04-27 20:37:17.857361
11
add comment
4 Answers:
1


alright so I guess we're going to have to do it the [LaG] way xD we ban a certain subnet, and like the LaG servers, all players using that subnet will be kicked on arrival. To whitelist a certain user, the lua script would look for the certain USGN, and instead of being kicked on arrival, they would be allowed in.

I guess this might take some work -.-

YES SUCESS. I got it to work. Apparently '"..cmd.."' is suppose to be '"..cmd..'" ^_^ also, the main.lua 92 didn't give me problems (just deleted it and it seemed to be fine) Anyways, doing this because cough servers *cough coming back up.

permanent link | flag offensive
answered 2010-04-27 21:34:52.637892
11
add comment
0


If I remember my own framework correctly (there's a good chance that I may have forgotten how it worked xD), you can copy the template from @getpos

http://svn.cs2d.org/amx2d/core/basic.lua

function adm_getip(p, typ, cmd)
     -- @getip id
     cmd = playerid(cmd)
     if not cmd then cmd = p end
     if player(cmd,"exists") then 
          msg2(p, "Player '"..cmd.."' is at IP: "..player(cmd, "ip")) 
     end
end

Example: Lets say I subnet banned a certain player, and someone else who had the same exact subnet gets banned. Is it possible for me to say, unban him via USGN?

It would be possible with a few patches to the CS2D banning system, basically we have to write a wrapper over the cs2d banning utility and then hook the USGN whitelist from there. However, there are no trivial way of doing this directly.

permanent link | flag offensive
answered 2010-04-27 21:06:32.806127
41
add comment
0


Here's a functional variation of CS2D's subnet banning "technique"

function string.split(t, b)
    local cmd = {}
    local match = "[^%s]+"
    if b then
        match = "%w+"
    end
    if type(b) == "string" then match = "[^"..b.."]+" end
    if not t then return invalid() end
    for word in string.gmatch(t, match) do
        table.insert(cmd, word)
    end
    return cmd
end
function is(t, tab)
    for _,v in ipairs(tab) do if t==v then return true end end
    return false
end

local __parse = parse

io.open("p.banlist.lst","a"):close()
_f = io.open("p.banlist.lst","r")
proxy_banlist = _f:read("*all"):split("\n")
_f:close()
_f = nil
io.open("p.whitelist.lst","a"):close()
_f = io.open("p.banlist.lst","r")
whitelist = _f:read("*all"):split("\n")
_f:close()
_f = nil

function ban_ip(ip)
    if ip then ip = {ip} else ip = proxy_banlist end
    for _ip in ipairs(ip) do
        for p in player(0, "table") do
            if check_ip(player(p, "ip"), _ip) then
                if is(player(p, "usgn"), whitelist) then return end
                return __parse("kick "..ip)
            end
        end
    end
end

function check_ip(a, b)
    local isip = "[%d*]+[.][%d*]+[.][%d*]+[.][%d*]+"
    if not a:find(isip) or not b:find(isip) then return end
    bsplit = b:split(".")
    for _,part in ipairs(a:split(".")) do
        if not (bsplit[_] == part or bsplit[_] == "*" or part == "*") then return false end
    end
    return true
end

function parse(cmd)
    cmds = cmd:split(" ")
    if not is (cmds[1],{"banip","unban", "unbanall"}) then return __parse(cmd) end
    if cmds[1] == "banip" then
        local ip = cmds[2]
        local _f = io.open("p.banlist.lst","a")
        _f:write(ip.."\n")
        table.insert(proxy_banlist, ip)
        _f:close()
        ban_ip(ip)
    elseif cmds[1] == "unbanall" then
        io.open("p.banlist.lst","w"):close()
        proxy_banlist = {}
        return __parse(cmd)
    elseif cmds[1] == "unban" then
        local key = cmds[2]
        if not key:find("[%d*]+[.][%d*]+[.][%d*]+[.][%d*]+") then return __parse(cmd) end
        local component = "[%d*]+"
        local components = {}
        for part in key:gmatch(component) do
            table.insert(components, part)
        end
        retain = {}
        for _, ip in ipairs(proxy_banlist) do
            local index = 1
            local this = true
            for part in ip:gmatch(component) do
                if (part ~= components[index] and components[index] ~= "*") or (components[index] == "*" and part == "*") then this = false end
                index = index + 1
            end
            print(ip, this)
            if not this then table.insert(retain, ip) end
        end
        _f = io.open("p.banlist.lst","w")
        _f:write(table.concat(retain, "\n").."\n")
        proxy_banlist = retain
        _f:close()
        return __parse(cmd)
    end
end

addhook("join","proxy_join")
function proxy_join()
    ban_ip()
end

Unbanall in server, run this script, close it and open up the newly created "p.whitelist.lst" and add in your whitelists. Note that this will never allow explicit "banip" unless you invoke the __parse function in place of the proxied parse.

Btw, I haven't extensively tested this code since I don't have easy access to CS2D (it's my laptop :P) so I can't be certain that this won't break down suddenly and format your entire computer, but it should hold for most cases. You may want to replace

                return __parse("kick "..ip)

with

                return __parse("banip "..ip)

in order to decrease the overhead of having to check every newjoiner's IP against the banlist, as now you can kill the

addhook("join","proxy_join")
function proxy_join()
    ban_ip()
end

lines at the end, however this will mean that anyone not present at the time of the ban will never be banned...

add comment
0


Thanks, should I create a new .lua file or should I add this code into an existing one?

permanent link | flag offensive
answered 2010-04-27 23:06:08.350648
11
add comment
Your answer:
You are now not logged in but you can answer first and then login
toggle preview



Tags:

× 2
× 1
× 1
× 1
× 1
× 1

Asked: 2 years ago

Seen: 1,347 times

Last updated: 2 years ago

Made with Django.