Long Nickname Crashes Server? -
Daveosss - 09.04.2016
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.
Re: Long Nickname Crashes Server? -
Abagail - 09.04.2016
Show the message code.
Re: Long Nickname Crashes Server? -
]Rafaellos[ - 09.04.2016
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.
Re: Long Nickname Crashes Server? -
Daveosss - 09.04.2016
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(playerid, params[])
{
new pID, castka, string[128];
if(sscanf(params, "dd", pID, castka)) return SendClientMessage(playerid, COLOR_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(playerid, COLOR_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(playerid, jmeno, 128);
GetPlayerName(pID, jmeno2, 128);
GiveMoney(playerid, -castka);
PlayerInfo[pID][Hitman] += castka;
hitmancas[playerid] = gettime()+30;
format(string, 256, ""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno , jmeno2, PlayerInfo[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(playerid, name, MAX_PLAYER_NAME);
return name;
}
Re: Long Nickname Crashes Server? -
AndySedeyn - 09.04.2016
This is your problem:
PHP код:
new string[128];
PHP код:
format(string, 256, ""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno , jmeno2, PlayerInfo[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(string, sizeof(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
Re: Long Nickname Crashes Server? -
Daveosss - 09.04.2016
Thank you, Andy. It works, REP+
Re: Long Nickname Crashes Server? -
MartinSwag - 09.04.2016
Quote:
Originally Posted by AndySedeyn
This is your problem:
PHP код:
new string[128];
PHP код:
format(string, 256, ""p"Hrбč "w"%s"p" vypsal odměnu na hrбče "w"%s"p" . Vypsanб odměna - "w"$%d",jmeno , jmeno2, PlayerInfo[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(string, sizeof(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.