Check Ban CMD - Not working
#1

Hello,

I've recently finished making a command which checks the ban information for the player name provided. When I input a name which was not found in the ban database, it works fine, it outputs the "Ban not found within the database" error. However, when I do input the name of a banned player, it just outputs the "Unknown Command" error.

Код:
CMD:baninfo(playerid, params[])
{
	new name;
	
    if( sscanf( params, "s", name ) )
 		return SendUsageError( playerid, "/baninfo [Name]");
 		
	new query[128];
	
	mysql_format(mysql, query, sizeof(query), "SELECT * FROM `"BanTable"` WHERE `Name` = '%s'", name);
	mysql_tquery(mysql, query, "BanInfo", "i", playerid);
	return 1;
}

forward BanInfo(playerid);
public BanInfo(playerid)
{
	new rows, fields, reason[128], bannedby[128], date[50], ip[30], str[128], name[24];
	cache_get_data(rows, fields, mysql);
	if(rows)
	{
	    cache_get_field_content(0, "Reason", reason, mysql, 128);
	    cache_get_field_content(0, "BannedBy", bannedby, mysql, 128);
        cache_get_field_content(0, "Date", date, mysql, 50);
        cache_get_field_content(0, "IP", ip, mysql, 30);
        
        format(str, sizeof(str), "[BANINFO] {FFFFFF}%s was banned by %s on %s. IP: %s", name, bannedby, date, ip);
        SendClientMessage(playerid, RED, str);
        return 1;
	}
	else Error(playerid, "Ban was not found in the database");
	return 1;
}
I've checked the MySQL error log, and the ban seems to come up fine.


Код:
[13:53:02] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `bans` WHERE `Name` = 'itsDanny'", callback: "BanInfo", format: "i"
[13:53:02] [DEBUG] CMySQLQuery::Execute[BanInfo] - starting query execution
[13:53:02] [DEBUG] CMySQLQuery::Execute[BanInfo] - query was successfully executed within 4.324 milliseconds
[13:53:02] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[13:53:02] [DEBUG] Calling callback "BanInfo"..
[13:53:02] [DEBUG] cache_get_data - connection: 1
[13:53:02] [DEBUG] cache_get_field_content - row: 0, field_name: "Reason", connection: 1, max_len: 128
[13:53:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Reason", data: "test"
[13:53:02] [DEBUG] cache_get_field_content - row: 0, field_name: "BannedBy", connection: 1, max_len: 128
[13:53:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "BannedBy", data: "itsDanny"
[13:53:02] [DEBUG] cache_get_field_content - row: 0, field_name: "Date", connection: 1, max_len: 50
[13:53:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "Date", data: "2015-11-29 16:03:08"
[13:53:02] [DEBUG] cache_get_field_content - row: 0, field_name: "IP", connection: 1, max_len: 30
[13:53:02] [DEBUG] CMySQLResult::GetRowDataByName - row: '0', field: "IP", data: "127.0.0.1"
[13:53:02] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
Reply
#2

//del
Reply
#3

MySQL R39
Reply
#4

Can anyone help me?
Reply
#5

PHP код:
    new name;
    
    if( 
sscanfparams"s"name ) ) 
Do these lines even work ?! without array size ? Well if this is your actual code and the result, it seems to be working and I didn't know it.
Anyway as you can see in mysql log, everything works perfectly up until your format, so I guess maybe format fails cuz str is too small so try increasing it's size and trying again ? probably if you put a printf there you'll see that it fetches the result but fails to format and send the SCM.
Reply
#6

PHP код:
CMD:baninfo(playeridparams[])
{
    new 
name[25];
    
    if(
sscanf params"s[25]"name ) )
         return 
SendUsageError(playerid"/baninfo [Name]");
         
    new 
query[128];
    
    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `BanTable` WHERE Name = '%e'"name);
    
mysql_tquery(mysqlquery"BanInfo""s"name);
    return 
1;

Could try that ^^
Reply
#7

He was faster. ^
Why are you using integer (non-array) variable to store player's name which needs array variable?
Reply
#8

Quote:
Originally Posted by itsCody
Посмотреть сообщение
PHP код:
CMD:baninfo(playeridparams[])
{
    new 
name[25];
    
    if(
sscanf params"s[25]"name ) )
         return 
SendUsageError(playerid"/baninfo [Name]");
         
    new 
query[128];
    
    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `BanTable` WHERE Name = '%e'"name);
    
mysql_tquery(mysqlquery"BanInfo""s"name);
    return 
1;

Could try that ^^
I've tried that, but now it just keeps showing me the usage message even when I typed something in, it's not even showing me the 'Ban not found' error or the 'Unknown command' error.

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
PHP код:
    new name;
    
    if( 
sscanfparams"s"name ) ) 
Do these lines even work ?! without array size ? Well if this is your actual code and the result, it seems to be working and I didn't know it.
Anyway as you can see in mysql log, everything works perfectly up until your format, so I guess maybe format fails cuz str is too small so try increasing it's size and trying again ? probably if you put a printf there you'll see that it fetches the result but fails to format and send the SCM.
I've tried that and still nothing changed.
Reply
#9

oops...
PHP код:
if(sscanf(params"s[25]"name)) 
sorry.
Reply
#10

pawn Код:
CMD:baninfo(playerid, params[])
{
    new name[25];
   
    if(sscanf(params, "s[25]", name ))return SendUsageError(playerid, "/baninfo [Name]");
       
    new query[128];
   
    mysql_format(mysql, query, sizeof(query), "SELECT * FROM `BanTable` WHERE Name = '%e'", name);
    mysql_tquery(mysql, query, "BanInfo", "s", name);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)