SA-MP Forums Archive
Unbanip crashes the server - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Unbanip crashes the server (/showthread.php?tid=609941)



Unbanip crashes the server - NeXoR - 18.06.2016

Hey guys, when I execute the command, it simply closes my server

PHP код:
CMD:unbanip(playerid, param[])
{
    if(!
IsAuth(playerid, 3)) return NoAuth(playerid);
    if(
sscanf(param, "s[16]", param)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /unbanip [IP]");
    if(!
IsIP(param)) return SendClientMessage(playerid, COLOR_WHITE, "Invalid IP Address.");
    new 
File:ban = fopen("samp.ban", io_read);
    new 
idx = 1, string[128];
    while(
fread(ban, string))
    {
        if(
strfind(string, param, true) != -1)
        {
            
fdeleteline("samp.ban", idx);
            
format(string, sizeof(string), "AdmWarn: %s %s has unbanned IP Address %s", RPARN(playerid), RPN(playerid), param);
            
SendAMessage(1, string);
            
format(string, sizeof(string), "AdmWarn: %s (%s) has unbanned IP %s", RPN(playerid), RPIP(playerid), param);
            
Log("logs/unban.log", string);
            
fclose(ban);
            print(
"Success.");
            return 
1;
        }
        
printf("IDX: %d", idx);
        
idx++;
    }
    
fclose(ban);
    print(
"Fail.");
    
SendClientMessage(playerid, COLOR_WHITE, "IP Address is not banned.");
    return 
1;
} 
fdeleteline (found somewhere on the forums)
PHP код:
fdeleteline(filename[], line)
{
  new 
count, string[256], File:file, File:temp;
  
file= fopen(filename, io_read);
  
temp = fopen("tmpfile.tmp", io_write);
  while (
fread(file, string))
    if (++
count != line)
      
fwrite(temp, string);
  
fclose(file);
  
fclose(temp);
  
file= fopen(filename, io_write);
  
temp = fopen("tmpfile.tmp", io_read);
  while (
fread(temp, string))
    
fwrite(file, string);
  
fclose(file);
  
fclose(temp);
  
fremove("tmpfile.tmp");
} 
Anyone ?


Re: Unbanip crashes the server - DTV - 18.06.2016

Why not use SendRconCommand to unban the ip in the .ban file?


Re: Unbanip crashes the server - NeXoR - 18.06.2016

Quote:
Originally Posted by DTV
Посмотреть сообщение
Why not use SendRconCommand to unban the ip in the .ban file?
Well, I can use it for sure, but then I can't verify if the IP is banned
Also, I would like to make an /unban CMD for a username, not an IP address, and the RCON command is made for IP Addresses


Re: Unbanip crashes the server - Konstantinos - 18.06.2016

If the file handle fopen returns is 0, do NOT use file functions because they will crash the server. Check if it's not equal to 0 first to prevent this.


Re: Unbanip crashes the server - Vince - 18.06.2016

Also see ftemp().