PDA

View Full Version : Check ip ban table



Ni3ls
26th April 2016, 11:59
I got 2 scripts that check for bans, 1 using GUID and the other using IP
My problem is, that the GUID script works without lag, while when I thread the ban on IP, it gives everybody a ping 999 for a second.
Scripts are almost identical and it doesnt show any errors with dev 1 and logfile 2

checkipbanlist(ip)
{
ipresult = readipbanfile();
if(!isdefined(ipresult))
ipresult[0]= 999999999999;

//iprintlnbold("ipsize:" +ipresult.size);
if(ipresult.size>0)
{
for(i = 0; i < ipresult.size; i++)
{
if(IsSubStr( ip, ipresult[i] ))
{
//iprintlnbold("Match IP!");
f = openfile("bans/ip/bans.txt", "read");
if(f == -1)
return;
name=fgetarg(f,i+1);
reden=fgetarg(f,i+2);
admin=fgetarg(f,i+3);
//banip=fgetarg(f,i+4);
closefile(f);
admin = GetSubStr( admin, 0, admin.size-5);
self iprintlnbold("Reden: "+reden);
self iprintlnbold("name: "+name);
self iprintlnbold("admin: "+admin);
id = self getEntityNumber();

/*self setClientCvar("com_errorTitle", "BANNED");
self setClientCvar("com_errorMessage", "You are banned by: " +admin +"\n" + "^7Reason: "+reden +"\n" + "^7IP: "+ip +"\n" + "^7Website: www.myevilclan.tk");*/
iprintln("Banned player: "+self.name + "^7tried to join. Reason: "+reden);
wait 1;
message = "\nYou are banned by: " +admin +"\n" + "^7Reason: "+reden +"\n" + "^7IP: "+ip +"\n" + "^7Website: www.myevilclan.tk";
kick2(id, message);
}
}
}
}
readipbanfile()
{
f = openfile("bans/ip/bans.txt", "read");
if(f == -1)
return;
argcount = freadln(f);
if(argcount == -1) //end of file
return;
//iprintlnbold("Argcount:"+argcount);
ipresult = [];
for(i = 0; i < argcount; i++)
{
ipresult[i] = fgetarg(f, i);
//iprintlnbold("ipresult"+i+ ":" +ipresult[i]);
}
closefile(f);
return ipresult;
}

checkguidbanlist(guid)
{
banresult = readguidbanfile();
if(!isdefined(banresult))
banresult[0]= 999999999999;
//iprintlnbold("guidsize:" +banresult.size);
if(banresult.size>0)
{
for(i = 0; i < banresult.size; i++)
{
if(guid == banresult[i] )
{
//iprintlnbold("Match GUID!");
f = openfile("bans/guid/bans.txt", "read");
if(f == -1)
return;
name=fgetarg(f,i+1);
reden=fgetarg(f,i+2);
admin=fgetarg(f,i+3);
//banip=fgetarg(f,i+4);
closefile(f);
admin = GetSubStr( admin, 0, admin.size-5);
self iprintlnbold("Reden: "+reden);
self iprintlnbold("name: "+name);
self iprintlnbold("admin: "+admin);
id = self getEntityNumber();

/*self setClientCvar("com_errorTitle", "BANNED");
self setClientCvar("com_errorMessage", "You are banned by: " +admin +"\n" + "^7Reason: "+reden +"\n" + "^7GUID: "+guid +"\n" + "^7Website: www.myevilclan.tk");*/
iprintln("Banned player: "+self.name + "^7tried to join. Reason: "+reden);
wait 1;
message = "\nYou are banned by: " +admin +"\n" + "^7Reason: "+reden +"\n" + "^7GUID: "+guid +"\n" + "^7Website: www.myevilclan.tk";
kick2(id, message);
/*self setClientCvar ("clientcmd", "disconnect");
self openMenu ("clientcmd");
self closeMenu ("clientcmd");*/
}
}
}
}
readguidbanfile()
{
f = openfile("bans/guid/bans.txt", "read");
if(f == -1)
return;
argcount = freadln(f);
if(argcount == -1) //end of file
return;
//iprintlnbold("Argcount:"+argcount);
banresult = [];
for(i = 0; i < argcount; i++)
{
banresult[i] = int(fgetarg(f, i));
//iprintlnbold("banresult"+i+ ":" +banresult[i]);
}
closefile(f);
return banresult;
}

IzNoGoD
26th April 2016, 12:41
How big is your ip ban file.

Ni3ls
26th April 2016, 13:20
size: 31Kb
Length: 31020

maxdamage99
26th April 2016, 13:48
I make in mysql database:


CallBack_PlayerConnect()
{
//CHECK_BAN
login="I_DONT_KNOW";
if(isDefined(self.stats["login"])) login=self.stats["login"];
if(isBan(self getip()))
{
ban=info_ipban(self getip());
saychat(-1, "^7: Player: "+self.name+" ^7banned from this server. ^5Reason^7: "+ban["reason"]+"^7; ^1ID^7: "+ban["id"]+"^4.");
self setClientCvar("com_errorTitle", "^7You are ^1BANNED^7!!!");
self setClientCvar("com_errorMessage", self.name + " \n^4|| ^7BAN ID^5: ^3"+ban["id"]+" ^4||\n^4|| ^7ADMIN^5:^7 "+ban["admin"]+" ^4||\n^4|| ^7Date (Moscow)^5:^7 "+ban["date"]+"^4 ||\n^4|| ^7Reason^5:^7 "+ban["reason"]+" ^4||\n");
self closeMenu();
self closeInGameMenu();
msgconsole(self.name+" KICKED BY IP_BAN "+self getip()+" | "+login);
self exec("disconnect");
return;
}
//CHECK_BAN
/*...*/
}
/////////////////////////////////////
isBan(ip)
{
if(!isDefined(ip)) return;
sql = "SELECT * FROM `table_bans` WHERE `ban_ip`='" + ip + "'";
msgconsole(ip+" isBan(190) "+sql);
mysql_query(level.mysql, sql);
result = mysql_store_result(level.mysql);
if(mysql_num_rows(result) >= 1)
{mysql_free_result(result);return 1;}
mysql_free_result(result);
return 0;
}
info_ipban(ip)
{
if(!isDefined(ip)) return;
info=[];
info["id"]=999;
info["admin"]="Unknown Soldier";
info["date"]=readRealTime();
info["reason"]="undefined";
sql = "SELECT `id`, `ban_reason`, `ban_date`, `admin_name` FROM `table_bans` WHERE `ban_ip`='" + ip + "'";
msgconsole(ip+" info_ipban(207) "+sql);
mysql_query(level.mysql, sql);
result = mysql_store_result(level.mysql);
if(!isDefined(result)) {mysql_free_result(result);return info;}
if(mysql_num_rows(result) != 1)
return info;
row = mysql_fetch_row(result);
info["id"] = int(row[0]);
info["admin"] = row[3];
info["date"] = row[2];
info["reason"] = row[1];
mysql_free_result(result);
return info;
}

Ni3ls
26th April 2016, 13:52
Yes I want to switch to mysql, but first I need to get this working

Whiskas
26th April 2016, 14:50
I make in mysql database:


CallBack_PlayerConnect()
{
//CHECK_BAN
login="I_DONT_KNOW";
if(isDefined(self.stats["login"])) login=self.stats["login"];
if(isBan(self getip()))
{
ban=info_ipban(self getip());
saychat(-1, "^7: Player: "+self.name+" ^7banned from this server. ^5Reason^7: "+ban["reason"]+"^7; ^1ID^7: "+ban["id"]+"^4.");
self setClientCvar("com_errorTitle", "^7You are ^1BANNED^7!!!");
self setClientCvar("com_errorMessage", self.name + " \n^4|| ^7BAN ID^5: ^3"+ban["id"]+" ^4||\n^4|| ^7ADMIN^5:^7 "+ban["admin"]+" ^4||\n^4|| ^7Date (Moscow)^5:^7 "+ban["date"]+"^4 ||\n^4|| ^7Reason^5:^7 "+ban["reason"]+" ^4||\n");
self closeMenu();
self closeInGameMenu();
msgconsole(self.name+" KICKED BY IP_BAN "+self getip()+" | "+login);
self exec("disconnect");
return;
}
//CHECK_BAN
/*...*/
}
/////////////////////////////////////
isBan(ip)
{
if(!isDefined(ip)) return;
sql = "SELECT * FROM `table_bans` WHERE `ban_ip`='" + ip + "'";
msgconsole(ip+" isBan(190) "+sql);
mysql_query(level.mysql, sql);
result = mysql_store_result(level.mysql);
if(mysql_num_rows(result) >= 1)
{mysql_free_result(result);return 1;}
mysql_free_result(result);
return 0;
}
info_ipban(ip)
{
if(!isDefined(ip)) return;
info=[];
info["id"]=999;
info["admin"]="Unknown Soldier";
info["date"]=readRealTime();
info["reason"]="undefined";
sql = "SELECT `id`, `ban_reason`, `ban_date`, `admin_name` FROM `table_bans` WHERE `ban_ip`='" + ip + "'";
msgconsole(ip+" info_ipban(207) "+sql);
mysql_query(level.mysql, sql);
result = mysql_store_result(level.mysql);
if(!isDefined(result)) {mysql_free_result(result);return info;}
if(mysql_num_rows(result) != 1)
return info;
row = mysql_fetch_row(result);
info["id"] = int(row[0]);
info["admin"] = row[3];
info["date"] = row[2];
info["reason"] = row[1];
mysql_free_result(result);
return info;
}


Why not using kick2 instead of error messages?

voron00
26th April 2016, 15:29
The file is proably too big to parse it in a single frame, use mysql.