SAMP server keeps closing down when i connect
#10

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.

PHP код:
stock CheckBan(ip[])
{
    new 
Filefile fopen("ban.cfg"io_read);
    if (!
file) return -1;
    new 
string[20];
    while(
fread(filestring))
    {
        if(
strcmp(ipstringtruestrlen(ip)) == 0)
        {
            
fclose(file);
            return 
1;
        }
    }
    
fclose(file);
    return 
0;

An example would be:
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
    
}

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.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)