SA-MP Forums Archive
MySQL offline ban not working -_- - 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: MySQL offline ban not working -_- (/showthread.php?tid=651303)



MySQL offline ban not working -_- - insus100 - 18.03.2018

Finally I decided to post here, I have made this cmds:

PHP код:
CMD:oban(playeridparams[])
{
    new 
name[24], reason[128], Query[128];
    if(
sscanf(params"s[24]s[128]"namereason))
        return 
SCM(playeridCOR_CINZA"Use: /oban [name] [reason]");
    
/*mysql_format(sql_handle, Consulta, sizeof(Consulta), "SELECT `id` , `ip` FROM `jugadores` WHERE `nombre`='%s'", nombre);
    mysql_tquery(sql_handle, Consulta, "BanearJugadorNombre", "ds[24]s[50]", playerid, nombre, razon);*/
    
mysql_format(g_SQLQuerysizeof(Query), "SELECT `id`, `ip` FROM `players` WHERE `username` = '%e' LIMIT 1"name);
    
mysql_tquery(g_SQLQuery"OnPlayerOban""ds[24]s[128]"playeridnamereason);
    return 
1;

This is the callback:

PHP код:
forward OnPlayerOBan(playeridtarget[], offreason[]);
public 
OnPlayerOBan(playeridtarget[], offreason[])
{
    if(
cache_num_rows() > 0)
    {
        new 
obanquery[256], admin[MAX_PLAYER_NAME], banidbanip[16], yearmonthdayformatDate[10];
        
cache_get_value_name_int(0"id"banid);
        
cache_get_value_name(0"ip"banip16);
        
        
GetPlayerName(playeridadminMAX_PLAYER_NAME);
        
getdate(yearmonthday);
        
format(formatDate10"%d/%d/%d"daymonthyear);
        
mysql_format(g_SQLobanquerysizeof(obanquery), "INSERT INTO `bans` (`id`, `username`, `admin`, `ip`, `date`, `reason`) VALUES ('%d', '%s', '%s', '%s', '%s', '%s')"banidtargetadminbanipformatDateoffreason);
        
mysql_tquery(g_SQLobanquery);
        
SendClientMessageToAllEx(COLOR_LIGHTRED"AdmCmd: %s banned %s, reason: %s"pNome(playerid), targetoffreason);
    }
    else
    {
        
SendClientMessage(playeridCOLOR_LIGHTRED"[ERROR] That player isn't registered!");
    }
    return 
1;

Nothing happens when I put the cmd, and this appears on the log:
Код:
[ERROR] mysql_tquery: callback error: parameter count does not match format specifier length
If I delete
Код:
mysql_tquery(g_SQL, Query, "OnPlayerOban", "ds[24]s[128]", playerid, name, reason);
Those numbers, cmd still doesnt work and the log goes empty.

Thanks for your help, Im beginner with mysql, sorry for any noob shit.


Re: MySQL offline ban not working -_- - m1kas - 18.03.2018

Код:
CMD:oban(playerid, params[]) 
{ 
    new name[24], reason[128], Query[155]; 
    if(sscanf(params, "s[24]s[128]", name, reason)) 
        return SCM(playerid, COR_CINZA, "Use: /oban [name] [reason]"); 

    mysql_format(g_SQL, Query, sizeof(Query), "SELECT id FROM players WHERE username = '%s' LIMIT 1", name); 
    mysql_tquery(g_SQL, Query, "OnPlayerOban", "iss", playerid, name, reason); 
    return 1; 
}

forward OnPlayerOBan(playerid, target[], offreason[]); 
public OnPlayerOBan(playerid, target[], offreason[]) 
{ 
    if(cache_num_rows() > 0) 
    { 
        new obanquery[256], admin[MAX_PLAYER_NAME],  banip[16], year, month, day, formatDate[12]; 

        cache_get_value_name(0, "ip", banip, 16); 
         
        GetPlayerName(playerid, admin, MAX_PLAYER_NAME); 

        getdate(year, month, day); 
        format(formatDate, 12, "%02d/%02d/%d", day, month, year); 

        mysql_format(g_SQL, obanquery, sizeof(obanquery), "INSERT INTO bans VALUES(NULL, '%s', '%s', '%s', '%s', '%s')",  target, admin, banip, formatDate, offreason); 
        mysql_tquery(g_SQL, obanquery); 

        SendClientMessageToAllEx(COLOR_LIGHTRED, "AdmCmd: %s banned %s, reason: %s", pNome(playerid), target, offreason); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_LIGHTRED, "[ERROR] That player isn't registered!"); 
    } 
    return 1; 
}
Should work perfectly fine if you have the banid automatically incremented, also the problem is that you are specifying a query to be the length of 128 cells, while you want to send a query of combined 152 cells (128 for reason, 24 for name). So never specify string lengths in threaded queries.


Re: MySQL offline ban not working -_- - insus100 - 18.03.2018

I have it auto incremented on `players` table, and what I do is picking it from there, let me try it.


Re: MySQL offline ban not working -_- - insus100 - 18.03.2018

Quote:
Originally Posted by m1kas
Посмотреть сообщение
Код:
CMD:oban(playerid, params[]) 
{ 
    new name[24], reason[128], Query[155]; 
    if(sscanf(params, "s[24]s[128]", name, reason)) 
        return SCM(playerid, COR_CINZA, "Use: /oban [name] [reason]"); 

    mysql_format(g_SQL, Query, sizeof(Query), "SELECT id FROM players WHERE username = '%s' LIMIT 1", name); 
    mysql_tquery(g_SQL, Query, "OnPlayerOban", "iss", playerid, name, reason); 
    return 1; 
}

forward OnPlayerOBan(playerid, target[], offreason[]); 
public OnPlayerOBan(playerid, target[], offreason[]) 
{ 
    if(cache_num_rows() > 0) 
    { 
        new obanquery[256], admin[MAX_PLAYER_NAME],  banip[16], year, month, day, formatDate[12]; 

        cache_get_value_name(0, "ip", banip, 16); 
         
        GetPlayerName(playerid, admin, MAX_PLAYER_NAME); 

        getdate(year, month, day); 
        format(formatDate, 12, "%02d/%02d/%d", day, month, year); 

        mysql_format(g_SQL, obanquery, sizeof(obanquery), "INSERT INTO bans VALUES(NULL, '%s', '%s', '%s', '%s', '%s')",  target, admin, banip, formatDate, offreason); 
        mysql_tquery(g_SQL, obanquery); 

        SendClientMessageToAllEx(COLOR_LIGHTRED, "AdmCmd: %s banned %s, reason: %s", pNome(playerid), target, offreason); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_LIGHTRED, "[ERROR] That player isn't registered!"); 
    } 
    return 1; 
}
Should work perfectly fine if you have the banid automatically incremented, also the problem is that you are specifying a query to be the length of 128 cells, while you want to send a query of combined 152 cells (128 for reason, 24 for name). So never specify string lengths in threaded queries.
Nope, doesnt work. No errors on log, but when I input the cmd nothing happens.

EDIT: wait didnt seee the update, sorry ofr my stupidity.


Re: MySQL offline ban not working -_- - insus100 - 18.03.2018

Isn't there any way of using the auto incremented id from the main table 'players' and store it on the 'bans' table as I tried to?
Quote:

cache_get_value_name_int(0, "id", banid);

EDIT: I tried auto_increment & primary key on bans table, but not working too, no errors or anything.


Re: MySQL offline ban not working -_- - m1kas - 18.03.2018

You can do it that way but I have always preferred to not mix up players and bans, as it really doesn't have an impact since you still get the username when you're trying to unban someone, not the ID. Personal preference I suppose. An example of this would be to connect as a banned player, you won't know his unique ID from the players database if he hasn't logged in, but you can check for his username regardless of his ID or any other variables.


Re: MySQL offline ban not working -_- - insus100 - 18.03.2018

Quote:
Originally Posted by m1kas
Посмотреть сообщение
You can do it that way but I have always preferred to not mix up players and bans, as it really doesn't have an impact since you still get the username when you're trying to unban someone, not the ID. Personal preference I suppose. An example of this would be to connect as a banned player, you won't know his unique ID from the players database if he hasn't logged in, but you can check for his username regardless of his ID or any other variables.
Still not working, does the exact same thing (


Re: MySQL offline ban not working -_- - UFF - 18.03.2018

Quote:
Originally Posted by m1kas
Посмотреть сообщение
Код:
CMD:oban(playerid, params[]) 
{ 
    new name[24], reason[128], Query[155]; 
    if(sscanf(params, "s[24]s[128]", name, reason)) 
        return SCM(playerid, COR_CINZA, "Use: /oban [name] [reason]"); 

    mysql_format(g_SQL, Query, sizeof(Query), "SELECT id FROM players WHERE username = '%s' LIMIT 1", name); 
    mysql_tquery(g_SQL, Query, "OnPlayerOban", "iss", playerid, name, reason); 
    return 1; 
}

forward OnPlayerOBan(playerid, target[], offreason[]); 
public OnPlayerOBan(playerid, target[], offreason[]) 
{ 
    if(cache_num_rows() > 0) 
    { 
        new obanquery[256], admin[MAX_PLAYER_NAME],  banip[16], year, month, day, formatDate[12]; 

        cache_get_value_name(0, "ip", banip, 16); 
         
        GetPlayerName(playerid, admin, MAX_PLAYER_NAME); 

        getdate(year, month, day); 
        format(formatDate, 12, "%02d/%02d/%d", day, month, year); 

        mysql_format(g_SQL, obanquery, sizeof(obanquery), "INSERT INTO bans VALUES(NULL, '%s', '%s', '%s', '%s', '%s')",  target, admin, banip, formatDate, offreason); 
        mysql_tquery(g_SQL, obanquery); 

        SendClientMessageToAllEx(COLOR_LIGHTRED, "AdmCmd: %s banned %s, reason: %s", pNome(playerid), target, offreason); 
    } 
    else 
    { 
        SendClientMessage(playerid, COLOR_LIGHTRED, "[ERROR] That player isn't registered!"); 
    } 
    return 1; 
}
Should work perfectly fine if you have the banid automatically incremented, also the problem is that you are specifying a query to be the length of 128 cells, while you want to send a query of combined 152 cells (128 for reason, 24 for name). So never specify string lengths in threaded queries.

This will work but no one see the important thing in codes.

You Callback is "OnPlayerOBan" but you were using "OnPlayerOban" in your command.
Thats why it didn't respond!

it should be


Код:
    mysql_format(g_SQL, Query, sizeof(Query), "SELECT id FROM players WHERE username = '%s' LIMIT 1", name); 
    mysql_tquery(g_SQL, Query, "OnPlayerOBan", "iss", playerid, name, reason);
instead of


Код:
    mysql_format(g_SQL, Query, sizeof(Query), "SELECT id FROM players WHERE username = '%s' LIMIT 1", name); 
    mysql_tquery(g_SQL, Query, "OnPlayerOban", "iss", playerid, name, reason);



Re: MySQL offline ban not working -_- - insus100 - 18.03.2018

The worst thing is that I thought about it, but I went like naah, Im way too stupid, thanks man.


Re: MySQL offline ban not working -_- - UFF - 18.03.2018

Quote:
Originally Posted by insus100
Посмотреть сообщение
The worst thing is that I thought about it, but I went like naah, Im way too stupid, thanks man.
Haha, I do even think like that!
But its not wrong to have a try if it is wrong too!

Hope it worked!