viewing paste goddameit - Ban IP | Athena

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/*
Author  Goddameit
Version 2013/01/28
Web http://bit.ly/MDuQ9F
 
 
Special thanks for :
 
Euphy >>
New 'reason' and command input type
 
QQfoolsorellina >>
IP range check concept
*/
/*
SQL Table:
 
CREATE TABLE IF NOT EXISTS `ipbanlist2` (
`list` varchar(255) NOT NULL default '',
`ban_reason` varchar(255) NOT NULL default '',
`unban_reason` varchar(255) NOT NULL default '',
`status` tinyint(1) NOT NULL default '0',
`ban_id` int(11) unsigned NOT NULL default '0',
`unban_id` int(11) unsigned NOT NULL default '0',
KEY (`list`)
) ENGINE=MyISAM;
 
*/
-   script  ban_ip_atcommand    -1,{
OnInit:
    bindatcmd "banip",strnpcinfo(3)+"::OnBan";
    bindatcmd "unbanip",strnpcinfo(3)+"::OnUnBan";
    end;
OnBan:
    set .@atcmd_parameters$[0],escape_sql(.@atcmd_parameters$[0]);
    set .@atcmd_parameters$[1],escape_sql(.@atcmd_parameters$[1]);
    set .@tmp$, implode(.@atcmd_parameters$," ");
    set .@reason$, substr(.@tmp$,getstrlen(.@atcmd_parameters$[0]),getstrlen(.@tmp$)-1);
    set .@oaid, getcharid(3);
    set .@ip$, replacestr(.@atcmd_parameters$[0], "*", "%");
    for(set .@j,0;;set .@j,.@j+1)
    {
        deletearray .@aid[0],128;
        query_sql "SELECT `account_id` FROM `login` WHERE `last_ip` LIKE '"+.@ip$+"' LIMIT "+(.@j*127)+",127",.@aid;
        set .@num, getarraysize(.@aid);
        for( set .@i,0; .@i<.@num; set .@i,.@i+1 )
        {
            if( attachrid(.@aid[.@i]) )
            {
                Announce "You have been banned because GM reject IP ["+.@atcmd_parameters$[0]+"]. Reason : "+.@reason$,bc_self;
                addtimer 1000,strnpcinfo(0)+"::OnKick";
                detachrid;
            }
        }
        if( .@num < 127 )
            break;
    }
    attachrid .@oaid;
    query_sql "SELECT `ban_id` FROM `ipbanlist2` WHERE `list` = '"+.@atcmd_parameters$[0]+"'",.@c;
    if( .@c )
    {
        query_sql "UPDATE `ipbanlist2` SET `status` = 1 WHERE `list` = '"+.@atcmd_parameters$[0]+"'";
        query_sql "UPDATE `ipbanlist2` SET `ban_id` = "+getcharid(3)+" WHERE `list` = '"+.@atcmd_parameters$[0]+"'";
        query_sql "UPDATE `ipbanlist2` SET `ban_reason` = '"+.@reason$+"' WHERE `list` = '"+.@atcmd_parameters$[0]+"'"; 
    }
    else
        query_sql "INSERT `ipbanlist2` VALUES('"+.@atcmd_parameters$[0]+"','"+.@reason$+"','',1,"+.@oaid+",0)";
    message strcharinfo(0),"Ban IP:"+.@atcmd_parameters$[0];
    end;
OnUnBan:
    set .@atcmd_parameters$[0],escape_sql(.@atcmd_parameters$[0]);
    set .@atcmd_parameters$[1],escape_sql(.@atcmd_parameters$[1]);
    query_sql "UPDATE `ipbanlist2` SET `status` = 0 WHERE `list` = '"+.@atcmd_parameters$[0]+"'";
    query_sql "UPDATE `ipbanlist2` SET `unban_id` = "+getcharid(3)+" WHERE `list` = '"+.@atcmd_parameters$[0]+"'";
    query_sql "UPDATE `ipbanlist2` SET `unban_reason` = '"+.@atcmd_parameters$[1]+"' WHERE `list` = '"+.@atcmd_parameters$[0]+"'";
    message strcharinfo(0),"Unban IP:"+.@atcmd_parameters$[0];
    end;
OnPCLoginEvent:
    query_sql "SELECT `last_ip` FROM `login` WHERE `account_id` = "+getcharid(3),.@ip$;
    set .@ip$, .@ip$[0];
    deletearray .@my_array$[0],128;
    explode(.@my_array$, .@ip$, ".");
    setarray .@my_array1$[0],.@my_array$[0],.@my_array$[1],.@my_array$[2],"*";
    setarray .@my_array2$[0],.@my_array$[0],.@my_array$[1],"*","*";
    setarray .@my_array3$[0],.@my_array$[0],"*","*","*";
    setarray .@my_array4$[0],"*","*","*","*";
    set .@my_array1$,implode(.@my_array1$, ".");
    set .@my_array2$,implode(.@my_array2$, ".");
    set .@my_array3$,implode(.@my_array3$, ".");
    set .@my_array4$,implode(.@my_array4$, ".");
    query_sql "SELECT `list`,`ban_reason` FROM `ipbanlist2` WHERE `list` = '"+.@my_array1$+"' OR `list` = '"+.@my_array2$+"' OR `list` = '"+.@my_array3$+"' OR `list` = '"+.@my_array4$+"' ",.@list$,.@ban_reason$;
    set .@num, getarraysize(.@list$);
    if( .@num )
    {
        Announce "You have been banned because GM reject IP ["+.@list$[0]+"]. Reason : "+.@ban_reason$[0],bc_self;
        addtimer 5000,strnpcinfo(0)+"::OnKick";
    }
    end;    
OnKick:
    atcommand "@kick "+strcharinfo(0);
    end;
}
Viewed 655 times, submitted by Guest.