Bug in the system of registration and login. -
RafaelOsio - 06.03.2015
Hello guys, my question is this , I have a login and registration system. So far so good . The problem is that when the player "X" enters the server , there okay , it registers and enters normally. But when the player "Z" enters the server, and the "X" is already connected , the system actions rather than happen to the player "Z" , which came last, is going to the "X" player . For example , John enters the server first , so it goes through the registration process and enters the server. From there, John begins to play and is on the server. After two minutes , Maire enters the server, also for the first time , make your registration and when you login, the actions that should happen to Marie , happens to John . The welcome message , instead of being sent to Marie , is sent to John , and John is born again. Someone could understand my problem ? And it was understood , knows how to solve ? I await answers . Thank U.
Re: Bug in the system of registration and login. -
Nicker - 06.03.2015
Post some of the fundamental parts of your registration code. Help us to help you!
Re: Bug in the system of registration and login. -
BeesSi - 06.03.2015
Can you show me the enumator and OnPlayerConnect ?
Re: Bug in the system of registration and login. -
Vince - 06.03.2015
Sounds like classic SetTimer instead of SetTimerEx mistake, or a MySQL callback that has a playerid parameter while no such parameter is passed by the calling function. In that case id 0 will always be used by the function.
Re: Bug in the system of registration and login. -
Nenzittow - 06.03.2015
Hey guys, i'm working in the same project with him.
» OnPlayerConnect
pawn Код:
public OnPlayerConnect(playerid)
{
GetPlayerName(playerid, name, 30);
if(strlen(name) > 10)
{
pMessage(playerid, Red "Use a nick with a maximum of 10 characters);
SetTimer("TimerKick", 500, 0);
return 1;
}
GetPlayerName(playerid, name, 30);
TextDrawSetString(TextInicial[11], name);
TextDrawShowForPlayer(playerid, TextInicial[11]);
for(new nMsg = 0; nMsg < 20; nMsg++) SendClientMessage(playerid, -1, " ");
SelectTextDraw(playerid, 0xFFFFFFFF);
for(new i = 0; i < sizeof(TextInicial); i++)
{
TextDrawShowForPlayer(playerid, TextInicial[i]);
}
GetPlayerName(playerid, name, 30);
mysql_format(conexao, query, sizeof(query), "SELECT * FROM `players` WHERE `Nick` = '%s' LIMIT 1", name);
return 1;
}
Where can we search to find the bug?
Re: Bug in the system of registration and login. -
PowerPC603 - 06.03.2015
You didn't give SetTimer a playerid parameter, so anyone logging in with a name longer than 10 characters would kick player 0, whoever he is.
A player connects at id 15 for example, with a name of 18 characters.
Playerid 15 will see the error-message, but the timer will kick player 0, not 15.
Use SetTimerEx instead and supply the playerid like this:
pawn Код:
SetTimerEx("TimerKick", 500, 0, "i", playerid);
Also, you're using global textdraws for all players.
When you update the string of such textdraws, they are modified for all players at once.
You're setting the text of TextInicial[11] to the newly connected player's name, but that textdraw is shown for anyone.
So it will always display the last logged in player's name.
So, first John connects, his name will be set as text in that textdraw.
Then Marie connects, the textdraw is updated again.
Now both John and Marie will see Marie's name on that textdraw.
Use PlayerTextDraws instead to keep them separate.
Other than that, I can't see anything else wrong here in that part of the code.
Re: Bug in the system of registration and login. -
Nenzittow - 06.03.2015
@PowerPC603: Thanks man! Now i understood the Textdraws names bug.
But, it's not just that.
See this:
pawn Код:
SetSpawnInfo(playerid, 0, Player[playerid][Skin], 822.5340, -1340.8425, 13.5182, 5.3207, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
pMessage(playerid, Green, "Connected to the server. Enjoy.");
That is what appear when, for example, John connect, and this appears again to John when Marie connect.
So, John will receive that message and will spawn again.
I don't know why this happens...
Now, see this:
pawn Код:
forward LoginPlayer(playerid);
Login dialog:
[...]
pawn Код:
if(dialogid == 02)
{
if(response)
{
if(!strlen(inputtext))
{
new string[123];
GetPlayerName(playerid, name, 30);
format(string, sizeof(string), "{FFFFFF}Nick:{FFAC17} %s\n\n{FFFFFF}Enter your password to login.", name);
ShowPlayerDialog(playerid, 02, DIALOG_STYLE_PASSWORD, "{FFAC17}Login", string, "Confirm", "Cancel");
return 1;
}
else
{
GetPlayerName(playerid, name, 30);
format(query, sizeof(query), "SELECT * FROM `players` WHERE `Nick` = '%s' AND `Password` = '%s'", name, inputtext);
mysql_tquery(conexao, query, "LoginPlayer");
}
}
}
pawn Код:
public LoginPlayer(playerid)
{
if(cache_num_rows() > 0)
{
Player[playerid][Money] = cache_get_field_content_int(0, "Money", conexao);
Player[playerid][Skin] = cache_get_field_content_int(0, "Skin", conexao);
Player[playerid][Level] = cache_get_field_content_int(0, "Level", conexao);
Player[playerid][Ip] = cache_get_field_content_int(0, "IP", conexao);
Player[playerid][Wanted] = cache_get_field_content_int(0, "Wanted", conexao);
Player[playerid][LevelAdm] = cache_get_field_content_int(0, "AdmLvL", conexao);
Player[playerid][Vip] = cache_get_field_content_int(0, "Vip", conexao);
Player[playerid][House] = cache_get_field_content_int(0, "House", conexao);
Player[playerid][Job] = cache_get_field_content_int(0, "Job", conexao);
Player[playerid][Vehicle] = cache_get_field_content_int(0, "Vehicle", conexao);
CancelSelectTextDraw(playerid);
for(new i = 0; i < sizeof(TextInicial); i ++) { TextDrawHideForPlayer(playerid, TextInicial[i]); }
for(new i = 0; i < sizeof(TextRodape); i ++) { TextDrawShowForPlayer(playerid, TextRodape[i]); }
ResetPlayerWeapons(playerid);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, Player[playerid][Money]);
SetPlayerScore(playerid, Player[playerid][Level]);
SetPlayerWantedLevel(playerid, Player[playerid][Wanted]);
SetSpawnInfo(playerid, 0, Player[playerid][Skin], 822.5340, -1340.8425, 13.5182, 5.3207, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
pMessage(playerid, Green, "Connected to the server. Enjoy.");
}
else
{
new string[123];
errors++;
if(errors>= 5)
{
pMessage(playerid, Red, "You were kicked from the server by exceed the maximum errors limit.");
SetTimer("TimerKick", 500, 0);
}
if(5 - errors == 0) return 0;
format(string, sizeof(string), "Incorrect password. If you miss more %i you will be kicked from the server.", 5 - errors);
ShowPlayerDialog(playerid, 03, DIALOG_STYLE_MSGBOX, "Error", string, "OK", "");
}
return 1;
}
I am portuguese, so i translated some things to English, but i think there is no problem. And yeah, i know that we have a board in this forum too, but you (global forum members) have more experience and qualities than just the portuguese/brazilian forum members.
Sorry for the bad english, i didn't used ****** Translator
Re: Bug in the system of registration and login. -
maramizo - 07.03.2015
Quote:
Originally Posted by Vince
Sounds like classic SetTimer instead of SetTimerEx mistake
|
Quote:
Originally Posted by Nenzittow
pawn Код:
public OnPlayerConnect(playerid) { SetTimer("TimerKick", 500, 0); }
|
Honestly lol'd.
Re: Bug in the system of registration and login. -
Vince - 07.03.2015
Quote:
Originally Posted by Vince
or a MySQL callback that has a playerid parameter while no such parameter is passed by the calling function. In that case id 0 will always be used by the function.
|
Quote:
Originally Posted by Nenzittow
pawn Код:
mysql_tquery(conexao, query, "LoginPlayer");
pawn Код:
public LoginPlayer(playerid)
|
That's embarrassing.
See the example here:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery