24.04.2015, 17:33
Since it returns 0 if the player's IP is not in the file and 1 if it is. We need to return some other value if the file was not opened to prevent any action.
An example would be:
However, I'd recommend you since you're new to scripting to try better and more efficient ways such as SQL or y_ini instead.
PHP код:
stock CheckBan(ip[])
{
new File: file = fopen("ban.cfg", io_read);
if (!file) return -1;
new string[20];
while(fread(file, string))
{
if(strcmp(ip, string, true, strlen(ip)) == 0)
{
fclose(file);
return 1;
}
}
fclose(file);
return 0;
}
PHP код:
switch (CheckBan(player_ip)) // supposed "player_ip" stores the player's IP on connect.
{
case -1:
{
// could not read from the file, send a notice to admins
}
case 1:
{
// banned; do something
}
}