29.10.2012, 18:22
Hey I am making a mysql login/register system however I am having a problem where when I login it says my account exists however there is no accounts in the table.
Here is the OnPlayerConnect:
Here is the rest of the login /register script as I do not feel it is working properly or the most efficient method of storing a large quantity of data.
The login and register dialog's
The stocks.
Here is the OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
new Query[512], name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE Username='%s'", name);
mysql_function_query(dbconnect, Query, false, "OnQueryFinish", "");
mysql_store_result();
if(mysql_num_rows() != 0)
{
ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login","Login","Cancel");
}
else
{
ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Register","Enter your password below to register:","Register","Cancel");
}
mysql_free_result();
return 1;
}
The login and register dialog's
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch (dialogid)
{
case LOGIN_DIALOG:
{
if(!response)
{
SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
Kick(playerid);
}
LoginPlayer(playerid, inputtext);
}
case REGISTER_DIALOG:
{
if(!response)
{
SendClientMessage(playerid, COLOR_LIGHTRED,"You need to be logged in!");
Kick(playerid);
}
new query[512], username[MAX_PLAYER_NAME];
GetPlayerName(playerid, username, sizeof(username));
format(query, sizeof(query),"INSERT INTO `Users` (Username,Password) VALUES ('%s',md5('%s'))",username, inputtext);
mysql_function_query(dbconnect, query, false, "OnQueryFinish", "");
ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login","Enter your password below to login:","Login","Cancel");
}
}
return 1;
}
pawn Код:
stock LoginPlayer(playerid, pass[])
{
new query[1000], username[MAX_PLAYER_NAME];
GetPlayerName(playerid, username, sizeof(username));
format(query, sizeof(query),"SELECT * FROM `Users` WHERE Username = '%s' AND password = md5('%s')",username, pass);
mysql_function_query(dbconnect, query, false, "OnQueryFinish", "");
mysql_store_result();
if(mysql_num_rows() != 0)
{
if(mysql_fetch_row_format(query, "|"))
{
sscanf(query,"e<p<|>s[24]s[32]iiiiiiiiiiiiiifffiii>", PlayerInfo[playerid]);
new str[80];
format(str, sizeof(str),"Welcome %s, you have been loged to your account",username);
SendClientMessage(playerid, COLOR_BLUE, str);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SpawnPlayer(playerid);
}
}
else
{
ShowPlayerDialog(playerid,LOGIN_DIALOG,DIALOG_STYLE_PASSWORD,"SpectralRP: Login.","Wrong password:","Login","Cancel");
}
}
stock SavePlayerStats(playerid)
{
new squery[1000];
GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
PlayerInfo[playerid][pMoney] = GetPlayerMoney(playerid);
format(squery, sizeof(squery), "UPDATE Users SET Sex = %d,Age = %d, Origin = %d, Warns = %d, Money = %d, Level = %d, VIP = %d, Admin = %d, Tester = %d, Kills = %d, Deaths = %d, Muted = %d, Jailed = %d, Banned = %d, X = %f, Y = %f, Z = %f, Job = %d, Faction = %d, Rank = %d, WHERE username='%s'", PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pOrigin], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIP], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pTester], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank]);
mysql_function_query(dbconnect, squery, false, "OnQueryFinish", "");
mysql_free_result();
}