Quote:
Originally Posted by dusk
This should work. For banning check the functions BanIp and BanName.
pawn Код:
public OnPlyerConnect(playerid) { if(IsPlayerNameBanned(playerid)) { SendClientMessage(playerid, -1, "Your name is banned"); Kick(playerid); } else if(IsPlayerIpBanned(playerid)) { SendClientMessage(playerid, -1, "Your ip is banned"); Kick(playerid); } }
IsPlayerNameBanned(playerid) { new name[ MAX_PLAYER_NAME +1 ], File:file = fopen("bans_name.txt", io_read), buffer[256];
GetPlayerName(playerid, name, sizeof(name)); if(file) { while(fread(file, buffer)) // this will read 1 line. { StripNewLine(buffer); // This removes the symbols \r and \n if(!strcmp(buffer, name)) { fclose(file); return true; } } fclose(file); } return false; }
IsPlayerNameBanned(playerid) { new ip[ 16 ], File:file = fopen("bans_ip.txt", io_read), buffer[256];
GetPlayerIp(playerid, ip, sizeof(ip)); if(file) { while(fread(file, buffer)) // this will read 1 line. { StripNewLine(buffer); // This removes the symbols \r and \n if(!strcmp(buffer, ip)) { fclose(file); return true; } } fclose(file); } return false; }
BanIp(playerid, name[]) { new File:file = fopen("bans_name.txt", io_append); // io_append will create the file it does not exist if(file) { fwrite(file, name); fwrite(file, "\r\n"); // a new line } fclose(file); }
BanName(playerid, ip[]) { new File:file = fopen("bans_ip.txt", io_append); // io_append will create the file it does not exist if(file) { fwrite(file, ip); fwrite(file, "\r\n"); // a new line } fclose(file); }
StripNewLine(string[]) { new len = strlen(string); if(!string[0]) return;
if((string[len - 1] == '\n') || (string[len - 1] == '\r')) { string[len - 1] = 0; if(string[0]==0) return ; if((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0; } }
|
Very appreciated help!
i got 2 errors:
error 017: undefined symbol "IsPlayerIpBanned"
error 021: symbol already defined: "IsPlayerNameBanned"
Do You know how to solve them?
This is my filterscript:
HERE
But if i ban someone, him details will automatically get saved or i need to modify my ban CMD?