20.11.2015, 09:14
I have a decent and perfectly working ban system.
The problem is... It only bans the player with the name but not the IP itself.
How can i make a ban system which bans the IP too (storing them on a file text). For instence
If i am unbanned, 192.168.1.1 will be removed but the original content of .txt will remain the same (except the IP of the unbanned user is gone/wiped off).
I am using SQLite to do these stuffs.
PAWN Code:
Don't mind the indentation, the PAWN tag fucks it up. Apologize to my poor habit of using huge amount of useless string sizes.
The problem is... It only bans the player with the name but not the IP itself.
How can i make a ban system which bans the IP too (storing them on a file text). For instence
Код:
127.0.0.1 192.168.1.1
I am using SQLite to do these stuffs.
PAWN Code:
Don't mind the indentation, the PAWN tag fucks it up. Apologize to my poor habit of using huge amount of useless string sizes.
pawn Код:
// OnFilterScriptInit
db_query(Database,
"CREATE TABLE IF NOT EXISTS `bans` (`username` TEXT, `ip` TEXT, `banby` TEXT, `banreason` TEXT, `banwhen` TEXT)");
// OnPlayerConnect
new
bQuery[128+90],
reason[128],
admin[128],
when[128],
jip[20],
jname[24],
DBResult:jResult
;
format(bQuery, 600, "SELECT * FROM `bans` WHERE `username` = '%s'", GetName(playerid));
jResult = db_query(Database, bQuery);
if(db_num_rows(jResult))
{
db_get_field_assoc(jResult, "username", jname, 24);
db_get_field_assoc(jResult, "ip", jip, 20);
db_get_field_assoc(jResult, "banby", admin, 128);
db_get_field_assoc(jResult, "banreason", reason, 128);
db_get_field_assoc(jResult, "banwhen", when, 128);
ShowBanEx(playerid, jname, admin, reason, jip, when);
KickDelay(playerid);
return 1;
}
db_free_result(jResult);
// Stocks
stock BanAccountEx(name[], ip[], admin[] = "Server AC", reason[] = "None") // bans the offline player
{
new
Query[500],
DBResult:result,
ban_hr, ban_min, ban_sec, ban_month, ban_days, ban_years, when[128]
;
gettime(ban_hr, ban_min, ban_sec);
getdate(ban_years, ban_month, ban_days);
format(when, 128, "%02d/%02d/%d %02d:%02d:%02d", ban_month, ban_days, ban_years, ban_hr, ban_min, ban_sec);
format(Query, 500, "INSERT INTO `bans` (`username`, `ip`, `banby`, `banreason`, `banwhen`) VALUES ('%s', '%s', '%s', '%s', '%s')", DB_Escape(name), DB_Escape(ip), DB_Escape(admin), DB_Escape(reason), DB_Escape(when));
result = db_query(Database, Query);
db_free_result(result);
return 1;
}
stock BanAccount(playerid, admin[] = "Server AC", reason[] = "None") // online player function
{
new
Query[500],
DBResult:result,
ban_hr, ban_min, ban_sec, ban_month, ban_days, ban_years, when[128]
;
gettime(ban_hr, ban_min, ban_sec);
getdate(ban_years, ban_month, ban_days);
format(when, 128, "%02d/%02d/%d %02d:%02d:%02d", ban_month, ban_days, ban_years, ban_hr, ban_min, ban_sec);
format(Query, 500, "INSERT INTO `bans` (`username`, `ip`, `banby`, `banreason`, `banwhen`) VALUES ('%s', '%s', '%s', '%s', '%s')", DB_Escape(GetName(playerid)), DB_Escape(User[playerid][accountIP]), DB_Escape(admin), DB_Escape(reason), DB_Escape(when));
result = db_query(Database, Query);
db_free_result(result);
KickDelay(playerid);
return 1;
}
stock ShowBanEx(playerid, player[], admin[] = "Server AC", reason[] = "None", ip[], when[] = "01/01/1970 00:00:00")
{
new string[256], string2[1500];
for(new i=0; i<100; i++)
{
SendClientMessage(playerid, -1, " ");
}
format(string, sizeof string, "Sorry %s, but you are banned from this server.", GetName(playerid));
SendClientMessage(playerid, COLOR_JACKPOT, string);
SendClientMessage(playerid, -1, "Please read the dialouge on your screen regarding the ban details.");
strcat(string2, ""white"");
strcat(string2, "Information regardless of the ban:\n\n");
format(string, 256, ""red"Name: "white"%s\n", player);
strcat(string2, string);
format(string, 256, ""red"Banned By: "white"%s\n", admin);
strcat(string2, string);
format(string, 256, ""red"Reason: "white"%s\n", reason);
strcat(string2, string);
format(string, 256, ""red"IP Address: "white"%s\n", ip);
strcat(string2, string);
format(string, 256, ""red"Date: "white"%s\n\n", when);
strcat(string2, string);
strcat(string2, ""lightblue"Your current information (server-client):\n\n");
format(string, 256, ""red"Name: "white"%s\n", GetName(playerid));
strcat(string2, string);
format(string, 256, ""red"IP Address: "white"%s\n\n", User[playerid][accountIP]);
strcat(string2, string);
strcat(string2, ""white"");
strcat(string2, ""orange"You can appeal this ban by heading to our forums."white"\n");
strcat(string2, "Make sure to take a picture of this by pressing "green"F8"white".");
ShowPlayerDialog(playerid, DIALOG_NULL, DIALOG_STYLE_MSGBOX, ""red"Banned!", string2, "Close", "");
return 1;
}
stock ShowBan(playerid, admin[] = "Server AC", reason[] = "None", when[] = "01/01/1970 00:00:00")
{
new string[256], string2[1500];
for(new i=0; i<100; i++)
{
SendClientMessage(playerid, -1, " ");
}
format(string, sizeof string, "Sorry %s, but you are banned from this server.", GetName(playerid));
SendClientMessage(playerid, COLOR_JACKPOT, string);
SendClientMessage(playerid, -1, "Please read the dialouge on your screen regarding the ban details.");
strcat(string2, ""white"");
strcat(string2, "Information regardless of the ban:\n\n");
format(string, 256, ""red"Name: "white"%s\n", GetName(playerid));
strcat(string2, string);
format(string, 256, ""red"Banned By: "white"%s\n", admin);
strcat(string2, string);
format(string, 256, ""red"Reason: "white"%s\n", reason);
strcat(string2, string);
format(string, 256, ""red"IP Address: "white"%s\n", User[playerid][accountIP]);
strcat(string2, string);
format(string, 256, ""red"Date: "white"%s\n\n", when);
strcat(string2, string);
strcat(string2, ""white"");
strcat(string2, ""orange"You can appeal this ban by heading to our forums."white"\n");
strcat(string2, "Make sure to take a picture of this by pressing "green"F8"white".");
ShowPlayerDialog(playerid, DIALOG_NULL, DIALOG_STYLE_MSGBOX, ""red"Banned!", string2, "Close", "");
return 1;
}