05.04.2014, 12:39
I was making a MySQL Register and Login system, it inserts data into the databse but crashes when the player logs in.
This inserts data into the database.
OnPlayerConnect:
THEAD_USERNAME_LOOKUP:
pawn Код:
case THREAD_REGISTER_SPAWN:
{
PlayerInfo[extraid][pDBID] = mysql_insert_id(iConnectionHandle);
mysql_store_result(iConnectionHandle);
mysql_retrieve_row();
mysql_fetch_field_row(GlobalString, "PosX", connectionHandle);
PlayerInfo[extraid][pPos][0] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "PosY", connectionHandle);
PlayerInfo[extraid][pPos][1] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "PosZ", connectionHandle);
PlayerInfo[extraid][pPos][2] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "PosA", connectionHandle);
PlayerInfo[extraid][pPos][3] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "Health", connectionHandle);
PlayerInfo[extraid][pHealth] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "Armour", connectionHandle);
PlayerInfo[extraid][pArmour] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "Skin", connectionHandle);
PlayerInfo[extraid][pSkin] = strval(GlobalString);
mysql_free_result(iConnectionHandle);
PlayerInfo[extraid][pStatus] = 1;
SendClientMessage(extraid, -1, "Registered successful, no spawn set!"); // This was debugging!
}
pawn Код:
case DIALOG_LOGIN:
{
new HashedPassword[129];
if(!response) return Kick(playerid);
WP_Hash(HashedPassword, 129, inputtext);
if(!strcmp(PlayerInfo[playerid][pPassword], HashedPassword, true, 128))
{
PlayerInfo[playerid][pStatus] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You're now logged into the server.");
}
else
{
format(GlobalString, sizeof(GlobalString), "This account (%s) is registered.\n\nPlease enter the account password to login.\n\nIf you did not register this account beforehand, please pick another name.", PlayerInfo[playerid][pUsername]);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Registeration: Login", GlobalString, "Login", "Cancel");
}
return true;
}
pawn Код:
format(GlobalQuery, sizeof(GlobalQuery), "SELECT * FROM players WHERE Username = '%s'", PlayerInfo[playerid][pUsername]);
mysql_query(GlobalQuery, THREAD_USERNAME_LOOKUP, playerid, iConnectionHandle);
pawn Код:
case THREAD_USERNAME_LOOKUP:
{
mysql_store_result(connectionHandle);
if(mysql_num_rows(connectionHandle) > 0)
{
mysql_retrieve_row();
mysql_fetch_field_row(PlayerInfo[extraid][pPassword], "Password", connectionHandle);
mysql_fetch_field_row(GlobalString, "ID", connectionHandle);
PlayerInfo[extraid][pDBID] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "PosX", connectionHandle);
PlayerInfo[extraid][pPos][0] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "PosY", connectionHandle);
PlayerInfo[extraid][pPos][1] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "PosZ", connectionHandle);
PlayerInfo[extraid][pPos][2] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "PosA", connectionHandle);
PlayerInfo[extraid][pPos][3] = floatstr(GlobalString);
mysql_fetch_field_row(GlobalString, "Health", connectionHandle);
PlayerInfo[extraid][pHealth] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "Armour", connectionHandle);
PlayerInfo[extraid][pArmour] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "Interior", connectionHandle);
PlayerInfo[extraid][pInterior] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "VirtualWorld", connectionHandle);
PlayerInfo[extraid][pVirtualWorld] = strval(GlobalString);
mysql_fetch_field_row(GlobalString, "Skin", connectionHandle);
PlayerInfo[extraid][pSkin] = strval(GlobalString);
PlayerInfo[extraid][pStatus] = 2;
mysql_free_result(connectionHandle);
format(GlobalString, sizeof(GlobalString), "The account %s is registered.\n\nPlease enter the account password to login.\n\nIf you did not register this account beforehand, please pick another name.", PlayerInfo[extraid][pUsername]);
ShowPlayerDialog(extraid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Registration: Login", GlobalString, "Login", "Cancel");
}
else
{
format(GlobalString, sizeof(GlobalString), "This account (%s) is not yet registered. Please enter a password to register a new account.", PlayerInfo[extraid][pUsername]);
ShowPlayerDialog(extraid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "SERVER: Register", GlobalString, "Register", "Cancel");
}
}