Ban Command
#1

Hey guys my ban system is crashing my server. I can ban a player fine, but anything else crashes it.
Код:
[08:47:42] [Command]: [vR]Yottabyte has used the command /banreason.
[08:47:46] [debug] Server crashed while executing vR.amx
[08:47:46] [debug] AMX backtrace:
[08:47:46] [debug] #0 00000061 in ?? () at <unknown file>:0
[08:47:46] [debug] #1 00000061 in public cmd_banreason () at <unknown file>:0
[08:47:46] [debug] #2 native CallLocalFunction () from samp03svr
[08:47:46] [debug] #3 00000a58 in public OnPlayerCommandText (playerid=0, cmdtext[]=@016e8090 "/banreason dwa") at E:\All Folders\Hobbies\Server Hosting\SA-MP\__VR\pawno\include\zcmd.inc:108
Happens with all commands

Here is my ban command that works fine.
PHP код:
CMD:ban(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 1) return 0;
    {
         new 
IDreason[128], str[128], plrIP[16], query[1024], bannedby[50];
         if(
sscanf(params"us[100]"IDreason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /ban [PlayerID] [Reason]");
        if(
PlayerInfo[ID][pAdmin] >= PlayerInfo[playerid][pAdmin] && PlayerInfo[ID][pUCAdmin] == && PlayerInfo[playerid][pAdmin] != 6) return SendClientFormattedMessage(playeridCOLOR_RED"Error: Not enough privilages to ban %s."GetName(ID), "");
        if(!
IsPlayerConnected(ID)) return SendClientMessage(playeridCOLOR_GREY"Error: That player is not found.");
        
format(strsizeof(str), "[Admin Log]: %s has been banned by Administrator %s. [Reason: %s]"GetName(ID), GetName(playerid), reason);
        
ABroadCast(COLOR_ADMINstr1);
        print(
str);
        
GetPlayerIp(IDplrIPsizeof(plrIP));
        
SaveToFile("BanLog"str);
        
SendClientMessage(ID,COLOR_RED,"|___________[BAN INFO]___________|");
        
format(strsizeof(str), "Your name: %s.",GetName(ID));
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "Your ip is: %s."plrIP);
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "You were banned by: %s.",GetName(playerid));
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "You were banned for: %s. Make an ban appeal on: www.vexed-rp.com",reason);
        
SendClientMessage(IDCOLOR_REDstr);
        
SendClientMessage(ID,COLOR_RED,"|___________[BAN INFO]___________|");
        
SetTimerEx("UnsetBan"5000"i"ID);
        
bannedby GetName(playerid);
        
PlayerInfo[ID][pBanned] = 1;
        
PlayerInfo[ID][pReason] = reason;
        
PlayerInfo[ID][pBannedBy] = bannedby;
        
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s', WHERE Name='%s'",1,GetName(playerid),reasonGetName(ID));
        
mysql_tquery(ServerMySQLquery"""");
    }
    return 
1;

And here is the rest of the commands that are broken

PHP код:
CMD:oban(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] < 3) return 0;
    {
        new 
IDname[128], query[250], reason[128], string[128];
        if(
sscanf(params"s[24]s[24]"namereason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /offlineban [Player Name] [Reason]");
        
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s' WHERE Name='%s'"1GetName(playerid), reasonname);
        
mysql_tquery(ServerMySQLquery"""");
        if (!
cache_affected_rows(ServerMySQL)) return SendClientMessage(playeridCOLOR_RED"Error: That player doesn't exist"); 
        
format(string,sizeof(string), "*You have successfully banned player %s."name);
        
SendClientMessage(playeridCOLOR_ADMINstring);
        
format(amsgsizeof(amsg), "[Admin Log]: %s has offline banned player %s [Reason: %s]"GetName(playerid), namereason);
        
ABroadCast(COLOR_ADMIN,amsg1);
        if(
IsPlayerConnected(ID))
        {
            
SetTimerEx("UnsetBan"5000"i"ID);
        }
    }
    return 
1;
}
CMD:unban(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new 
namequery[300], cmdstring[44], string[128];
    if(
sscanf(params"s[24]"name)) return SendClientMessage(playeridCOLOR_WHITE,"Usage: /unban [Player Name]");
    
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s' WHERE Name='%s'"1GetName(playerid), ""GetName(name));
    
mysql_tquery(ServerMySQLquery"""");
    if(!
cache_affected_rows(ServerMySQL)) return SendClientMessage(playeridCOLOR_RED"Error: That player doesn't exist"); 
    
format(cmdstringsizeof(cmdstring), "unbanip %s"PlayerInfo[name][pIP]);
    
SendRconCommand(cmdstring);
    
SendRconCommand("reloadbans");
    
format(string,sizeof(string), "*You have successfully unbanned %s."name);
    
SendClientMessage(playeridCOLOR_ADMINstring);
    
format(amsgsizeof(amsg), "[Admin Log]: %s has unbanned player %s"GetName(playerid), name);
    
ABroadCast(COLOR_ADMIN,amsg1);
    
//UnBlockIpAddress( ip_address );
    
return 1;
}
CMD:banreason(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new 
namequery[128], string[128], reason[128];
    if(
sscanf(params"s[24]"name)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /banreason [Player Name]");
    
format(querysizeof(query), "SELECT `pReason` FROM `Users` WHERE `Name` = '%s'"GetName(name));
    
mysql_query(ServerMySQLquery);
    if(
cache_num_rows())
    {
        
cache_get_field_content(0"pReason"reason);
        if(!
strcmp(reason""false1))
        {
            
format(string,sizeof(string), "[BAN REASON]: %s was banned for: %s",GetName(name), reason);
            
SendClientMessage(playeridCOLOR_YELLOWstring);
            
format(amsg,sizeof(amsg), "[Admin Log]: %s is requesting ban information on %s"GetName(playerid), GetName(name));
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"Error: That player isn't banned.");
        }
    }
    return 
1;

Reply
#2

'name' variable is an integer, but you treated it as string.
I think this code will fix your crash.
Код:
CMD:banreason(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new name[24], query[128], string[128], reason[128];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /banreason [Player Name]");
    format(query, sizeof(query), "SELECT `pReason` FROM `Users` WHERE `Name` = '%s'", name);
    mysql_query(ServerMySQL, query);
    if(cache_num_rows())
    {
        cache_get_field_content(0, "pReason", reason);
        if(!strcmp(reason, "", false, 1))
        {
            format(string,sizeof(string), "[BAN REASON]: %s was banned for: %s", name, reason);
            SendClientMessage(playerid, COLOR_YELLOW, string);
            format(amsg,sizeof(amsg), "[Admin Log]: %s is requesting ban information on %s", GetName(playerid), name);
            // Rest of code here
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Error: That player isn't banned.");
        }
    }
    return 1;
}
and dont forget to escape any string input in mysql query
Reply
#3

Actually "name" (misleading variable name) would need to be integer and you'd have to use "r" or "u" specifier in sscanf. GetName function accepts an integer, not a string so that'd give error 035.

Is that the whole code in the command? If not, post the whole command.
All are natives except GetName which is still not reported even if you have -d3 flag.

And remove the cache from memory otherwise you're going to have memory leaks.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Actually "name" (misleading variable name) would need to be integer and you'd have to use "r" or "u" specifier in sscanf. GetName function accepts an integer, not a string so that'd give error 035.

Is that the whole code in the command? If not, post the whole command.
All are natives except GetName which is still not reported even if you have -d3 flag.

And remove the cache from memory otherwise you're going to have memory leaks.
How do I remove the cache?

Also I changed everything to "u" specifier however now whenever I type the command it doesn't crash. But nothing is displayed no error message or success message.

PHP код:
 CMD:oban(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] < 3) return 0;
    {
        new 
IDquery[250], reason[128], string[128];
        if(
sscanf(params"us[24]"IDreason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /offlineban [Player Name] [Reason]");
        
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s' WHERE Name='%s'"1GetName(playerid), reasonGetName(ID));
        
mysql_tquery(ServerMySQLquery"""");
        if (!
cache_affected_rows(ServerMySQL)) return SendClientMessage(playeridCOLOR_RED"Error: That player doesn't exist"); 
        
format(string,sizeof(string), "*You have successfully banned player %s."GetName(ID));
        
SendClientMessage(playeridCOLOR_ADMINstring);
        
format(amsgsizeof(amsg), "[Admin Log]: %s has offline banned player %s [Reason: %s]"GetName(playerid), GetName(ID), reason);
        
ABroadCast(COLOR_ADMIN,amsg1);
        if(
IsPlayerConnected(ID))
        {
            
SetTimerEx("UnsetBan"5000"i"ID);
        }
    }
    return 
1;
}
CMD:unban(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new 
IDquery[300], cmdstring[44], string[128];
    if(
sscanf(params"u"ID)) return SendClientMessage(playeridCOLOR_WHITE,"Usage: /unban [Player Name]");
    
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s' WHERE Name='%s'"1GetName(playerid), ""GetName(ID));
    
mysql_tquery(ServerMySQLquery"""");
    if(!
cache_affected_rows(ServerMySQL)) return SendClientMessage(playeridCOLOR_RED"Error: That player doesn't exist"); 
    
format(cmdstringsizeof(cmdstring), "unbanip %s"PlayerInfo[ID][pIP]);
    
SendRconCommand(cmdstring);
    
SendRconCommand("reloadbans");
    
format(string,sizeof(string), "*You have successfully unbanned %s."GetName(ID));
    
SendClientMessage(playeridCOLOR_ADMINstring);
    
format(amsgsizeof(amsg), "[Admin Log]: %s has unbanned player %s"GetName(playerid), GetName(ID));
    
ABroadCast(COLOR_ADMIN,amsg1);
    
//UnBlockIpAddress( ip_address );
    
return 1;
}
CMD:banreason(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new 
IDquery[128], string[128], reason[128];
    if(
sscanf(params"u"ID)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /banreason [Player Name]");
    
format(querysizeof(query), "SELECT `pReason` FROM `Users` WHERE `Name` = '%s'"GetName(ID));
    
mysql_query(ServerMySQLquery);
    if(
cache_num_rows())
    {
        
cache_get_field_content(0"pReason"reason);
        if(!
strcmp(reason""false1))
        {
            
format(string,sizeof(string), "[BAN REASON]: %s was banned for: %s",GetName(ID), reason);
            
SendClientMessage(playeridCOLOR_YELLOWstring);
            
format(amsg,sizeof(amsg), "[Admin Log]: %s is requesting ban information on %s"GetName(playerid), GetName(ID));
        }
        else
        {
            
SendClientMessage(playeridCOLOR_RED"Error: That player isn't banned.");
        }
    }
    return 
1;

Reply
#5

Using "u" specifier in /banreason command is imposibble because banned players can't login into the game.
Try this, i already removed GetName() because name variable is a player name already.
And use cache_delete() to remove cache
Код:
CMD:banreason(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new name[24], query[128], string[128], reason[128];
    if(sscanf(params, "s[24]", name)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /banreason [Player Name]");
    format(query, sizeof(query), "SELECT `pReason` FROM `Users` WHERE `Name` = '%s'", name);
    new Cache:cquery;
    cquery = mysql_query(ServerMySQL, query);
    if(cache_num_rows())
    {
        cache_get_field_content(0, "pReason", reason);
        if(!strcmp(reason, "", false, 1))
        {
            format(string,sizeof(string), "[BAN REASON]: %s was banned for: %s", name, reason);
            SendClientMessage(playerid, COLOR_YELLOW, string);
            format(amsg,sizeof(amsg), "[Admin Log]: %s is requesting ban information on %s", GetName(playerid), name);
            // Rest of code here
        }
        else
        {
            SendClientMessage(playerid, COLOR_RED, "Error: That player isn't banned.");
        }
    }
    cache_delete(cquery);
    return 1;
}
Reply
#6

Hi thanks for your input. I added your code, but I get
Код:
../gamemodes/inc/admincommands.pwn(314) : error 021: symbol already defined: "query"
../gamemodes/inc/admincommands.pwn(315) : error 035: argument type mismatch (argument 2)
PHP код:
    new Cache:query;// 314
    
query mysql_query(ServerMySQLquery); //315 
I tried removing query[128]; but that gave me more errors.
Reply
#7

Sorry, i've updated the code
I didn't noticed that there's a variable named "query" already
Reply
#8

Haha all goods thanks for offering your time.
Код:
../gamemodes/inc/admincommands.pwn(315) : error 033: array must be indexed (variable "query")
PHP код:
 query mysql_query(ServerMySQLquery); //315 
Also with removing cache when should I be doing it?

Also with my other ban commands, /oban and /unban I get "Error: That player doesn't exist"
Reply
#9

Quote:
Originally Posted by Tass007
Посмотреть сообщение
Haha all goods thanks for offering your time.
Код:
../gamemodes/inc/admincommands.pwn(315) : error 033: array must be indexed (variable "query")
PHP код:
 query mysql_query(ServerMySQLquery); //315 
Also with removing cache when should I be doing it?

Also with my other ban commands, /oban and /unban I get "Error: That player doesn't exist"
Actually, that should be:
Код:
 cquery = mysql_query(ServerMySQL, query); //315
for /oban and /unban commands, you should use mysql_query or mysql_tquery with callback to get cache_affected_rows()
for /unban command, you must fetch banned player's IP first, before unban their IP.
Here are /oban and /unban commands, hope it will work
Код:
CMD:oban(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3) return 0;
    {
        new name[24], query[250], reason[128], string[128];
        if(sscanf(params, "s[24]s[24]", name, reason)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /offlineban [Player Name] [Reason]");
        mysql_format(ServerMySQL, query, sizeof(query), "UPDATE `Users` SET pBanned = 1, pBannedBy = '%s', pReason = '%s' WHERE Name='%s'", GetName(playerid), reason, name);
        new Cache:c = mysql_query(ServerMySQL, query);
        if (!cache_affected_rows(ServerMySQL))
        {
            cache_delete©;
            return SendClientMessage(playerid, COLOR_RED, "Error: That player doesn't exist"); 
        }
        format(string,sizeof(string), "*You have successfully banned player %s.", name);
        SendClientMessage(playerid, COLOR_ADMIN, string);
        format(amsg, sizeof(amsg), "[Admin Log]: %s has offline banned player %s [Reason: %s]", GetName(playerid), name, reason);
        ABroadCast(COLOR_ADMIN,amsg, 1);
        foreach(new i : Player)
        {
            GetPlayerName(i, string, 24);
            if(!strcmp(string, name, true))
            {
                SetTimerEx("UnsetBan", 500, 0, "i", i);
                break;
            }
        }
        cache_delete©;
    }
    return 1;
}

CMD:unban(playerid,params[])
{
    if(PlayerInfo[playerid][pAdmin] <= 3) return 0;
    new name[24], query[300], cmdstring[44], string[128];
    if(sscanf(params, "s", name)) return SendClientMessage(playerid, COLOR_WHITE,"Usage: /unban [Player Name]");
    mysql_format(ServerMySQL, query, sizeof(query), "UPDATE `Users` SET pBanned = 0, pBannedBy = '%s', pReason = '' WHERE Name='%s'", GetName(playerid), name);
    new Cache:c = mysql_query(ServerMySQL, query);
    if(!cache_affected_rows(ServerMySQL)) 
    {
        cache_delete©;
        return SendClientMessage(playerid, COLOR_RED, "Error: That player doesn't exist"); 
    }
    cache_delete©;
    mysql_format(ServerMySQL, query, sizeof(query), "SELECT `IP_COLUMN_NAME_HERE` FROM `Users` WHERE Name='%s'", name); // You need to fetch player IP first
    c = mysql_query(ServerMySQL, query);
    if(cache_num_rows())
    {
        new playerip[16];
        cache_get_field_content(0, 'IP_COLUMN_NAME_HERE', playerip, ServerMySQL, 16);
        format(cmdstring, sizeof(cmdstring), "unbanip %s", playerip);
        SendRconCommand(cmdstring);
        SendRconCommand("reloadbans");
    }
    format(string,sizeof(string), "*You have successfully unbanned %s.", name);
    SendClientMessage(playerid, COLOR_ADMIN, string);
    format(amsg, sizeof(amsg), "[Admin Log]: %s has unbanned player %s", GetName(playerid), name);
    ABroadCast(COLOR_ADMIN,amsg, 1);
    cache_delete©;
    return 1;
}
Reply
#10

Thank you that all works awesome! However now my ban command isn't working. It bans the player but it doesn't save in the database.

PHP код:
CMD:ban(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] <= 1) return 0;
    {
         new 
IDreason[128], str[128], plrIP[16], query[1024], bannedby[50];
         if(
sscanf(params"us[100]"IDreason)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /ban [PlayerID] [Reason]");
        if(
PlayerInfo[ID][pAdmin] >= PlayerInfo[playerid][pAdmin] && PlayerInfo[ID][pUCAdmin] == && PlayerInfo[playerid][pAdmin] != 6) return SendClientFormattedMessage(playeridCOLOR_RED"Error: Not enough privilages to ban %s."GetName(ID), "");
        if(!
IsPlayerConnected(ID)) return SendClientMessage(playeridCOLOR_GREY"Error: That player is not found.");
        
format(strsizeof(str), "[Admin Log]: %s has been banned by Administrator %s. [Reason: %s]"GetName(ID), GetName(playerid), reason);
        
ABroadCast(COLOR_ADMINstr1);
        print(
str);
        
GetPlayerIp(IDplrIPsizeof(plrIP));
        
SaveToFile("BanLog"str);
        
SendClientMessage(ID,COLOR_RED,"|___________[BAN INFO]___________|");
        
format(strsizeof(str), "Your name: %s.",GetName(ID));
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "Your ip is: %s."plrIP);
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "You were banned by: %s.",GetName(playerid));
        
SendClientMessage(IDCOLOR_REDstr);
        
format(strsizeof(str), "You were banned for: %s. Make an ban appeal on: www.vexed-rp.com",reason);
        
SendClientMessage(IDCOLOR_REDstr);
        
SendClientMessage(ID,COLOR_RED,"|___________[BAN INFO]___________|");
        
SetTimerEx("UnsetBan"5000"i"ID);
        
bannedby GetName(playerid);
        
PlayerInfo[ID][pBanned] = 1;
        
PlayerInfo[ID][pReason] = reason;
        
PlayerInfo[ID][pBannedBy] = bannedby;
        
mysql_format(ServerMySQLquerysizeof(query), "UPDATE `Users` SET pBanned = %d, pBannedBy = '%s', pReason = '%s', WHERE Name='%s'",1,GetName(playerid),reasonGetName(ID));
        
mysql_tquery(ServerMySQLquery"""");
    }
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)