Long Nickname Crashes Server?
#1

Hello there, I am currently experiencing a problem with playerґs nickname length. When any player with 19 (or longer) symbol long nickname connects and starts any minigame (it shows a client message in chat with his name), my server automatically crashes. I have already banned him, but thatґs not the right solution. I tried to increase string "name[30]" to "name[128]", but i donґt think this will help, because 30 is higher than 19, so it would work previously. Knows someone what to do? Thanks in advance.
Reply
#2

Show the message code.
Reply
#3

MAX_PLAYER_NAME is equal to 24 which means that a player can use a nickname up to 24 characters. Something else is crashing your server.
Reply
#4

Here is /hitman command, which was used by that player and server crashed. It is in Czech language, hope it doesnґt mind.
PHP код:
new hitmancas[MAX_PLAYERS];
CMD:hitman(playeridparams[])
{
    new 
pIDcastkastring[128];
    if(
sscanf(params"dd"pIDcastka)) return SendClientMessage(playeridCOLOR_PINK"Pouћitн: /hitman [ID] [Čбstka]");
    if(
gettime() < hitmancas[playerid]) return InfoBoxForPlayer(playerid"~r~Na nekoho jsi jiz vypsal odmenu. Vyckej chvili.");
    if (
castka 1) return SendClientMessage(playeridCOLOR_PINK"Pouћitн: /hitman [ID] [Čбstka]");
    else if(!
IsPlayerConnected(pID)) return InfoBoxForPlayer(playerid,"~r~Zadane ID neni pripojene.");
    if(
GetPlayerMoney(playerid) < castka) return InfoBoxForPlayer(playerid,"~r~Nemate tolik penez.");
    if(
PlayerInfo[playerid][Hodin] < 2) return InfoBoxForPlayer(playerid,"~r~Musite mit nahrano minimalne 2 hodiny.");
    if(
PlayerInfo[pID][Hodin] < 2) return InfoBoxForPlayer(playerid,"~r~Nemuzete vypsat odmenu na novacka.");
    new 
jmeno[128];
    new 
jmeno2[128];
    
GetPlayerName(playeridjmeno128);
    
GetPlayerName(pIDjmeno2128);
    
GiveMoney(playerid, -castka);
    
PlayerInfo[pID][Hitman] += castka;
    
hitmancas[playerid] = gettime()+30;
    
format(string256""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno jmeno2PlayerInfo[pID][Hitman]);
    
SendClientMessageToAll(COLOR_GREEN,string);
    return 
1;

Here is also "stock pName", which is used sometimes.
PHP код:
stock pName(playerid)
{
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    return 
name;

Reply
#5

This is your problem:
PHP код:
new string[128]; 
PHP код:
format(string256""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno jmeno2PlayerInfo[pID][Hitman]); 
You are declaring a variable with 128 cells, yet you format the variable passing a much larger amount of cells as second argument (256). And once the formatted string reaches a length of 128 and more, it will crash the server.

You're much safer using sizeof:
PHP код:
format(stringsizeof(string), "%d"variable); 
Plus, it makes your code easier to maintain in the long run.

FYI: MAX_PLAYER_NAME is defined as 24, but the maximum length of a player's name is actually 20: https://sampwiki.blast.hk/wiki/GetPlayerName
Reply
#6

Thank you, Andy. It works, REP+
Reply
#7

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
This is your problem:
PHP код:
new string[128]; 
PHP код:
format(string256""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno jmeno2PlayerInfo[pID][Hitman]); 
You are declaring a variable with 128 cells, yet you format the variable passing a much larger amount of cells as second argument (256). And once the formatted string reaches a length of 128 and more, it will crash the server.

You're much safer using sizeof:
PHP код:
format(stringsizeof(string), "%d"variable); 
Plus, it makes your code easier to maintain in the long run.

FYI: MAX_PLAYER_NAME is defined as 24, but the maximum length of a player's name is actually 20: https://sampwiki.blast.hk/wiki/GetPlayerName
I still don't quite understand what's going on with MAX_PLAYER_NAME lol. So you can connect to a server with a nickname between 3 and 20 characters, however when you use SetPlayerName(https://sampwiki.blast.hk/wiki/SetPlayerName) you can choose a nickname between 1 and 24 characters, I wonder why they did that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)