Help with crash
#1

Hello, I'm having some problems with commands. I have make a command to check for user in DB.

Код:
CMD:checkuserdb(playerid, params[])
{
    new id[MAX_PLAYER_NAME];
   	if(sscanf(params, "s", id)) return SendClientMessage(playerid, -1, "Use: /checkuserdb [Name_Surname]");
   	if(!PlayerExist(id)) return SendClientMessage(playerid, green, "This name is not registred.");
   	if(IsPlayerConnected(GetPlayerIdFromName(id))) return SendClientMessage(playerid, red, "Player exist and is connected.");
        if(PlayerExist(id)) return SendClientMessage(playerid, red, "This name is registred.");
   	return 1;
It works fine if I do /checkuserdb Name_Surname (if exists shows me success, if not, shows me that is not registred.)
But the server crashes when I do, for example: /checkuserdb testforstringblabla
Or if I exceed the MAX_PLAYER_NAME (I think it's the problem).

I have used:

Код:
if(strlen(id) > MAX_PLAYER_NAME) return SendClientMessage(playerid, -1, "Error with string");
But still crashing and don't send that message.

Anyone?
Reply
#2

sscanf would give a warning in the console for no size specified and the default (32) would be used. Aside from that, you haven't post the two functions or even install crashdetect and provide some logs to help us more.

For now, I can write two examples of those two that will probably fix it:
PHP код:
CMD:checkuserdb(playeridparams[])
{
    if (
isnull(params)) return SendClientMessage(playerid, -1"Use: /checkuserdb [Name_Surname]");
    if (
strlen(params) > MAX_PLAYER_NAME) return SendClientMessage(playeridgreen"This name is not registred.");
    new 
id;
    if (
sscanf(params"r"id)) return SendClientMessage(playerid, -1"Use: /checkuserdb [Name_Surname]");
    if (
id != INVALID_PLAYER_ID) return SendClientMessage(playeridred"Player exist and is connected.");
    if (!
PlayerExist(params)) SendClientMessage(playeridgreen"This name is not registred.");
    else 
SendClientMessage(playeridred"This name is registred.");
    return 
1;
}
PlayerExist(const player_name[])
{
    new 
query[66], DBResultresultrows;
    
format(querysizeof query"SELECT COUNT(*) FROM users WHERE name='%q'"player_name);
    
result db_query(dbquery);
    
rows db_get_field_int(result);
    
db_free_result(result);
    return 
rows;

Modify it to fit your table structures and variables.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)