04.06.2015, 21:40
(
Последний раз редактировалось Battlezone; 05.06.2015 в 14:16.
)
I got this warning in the mysql log file whenever I try to login into my account (ingame),
+the registration works however there is something wrong with the login system, I can't login.
Below you can check the codes I used from this tutorial
First part:
Second part: Functions part
Dialogs part:
OnGameModeInit part:
And finally this on player class selection:
Im totally new to MySQL, appreciate your help.
Код:
[13:58:50] [WARNING] CMySQLHandle::Create - connection already exists
Below you can check the codes I used from this tutorial
First part:
PHP код:
//MYSQL*********************************//
#define SQL_HOST "localhost"
#define SQL_USER "root"
#define SQL_PASS ""
#define SQL_DB "test"
static mysql;
//MYSQL*********************************//
//ACCOUNT INFO VARIABLES ***************//
enum PDATA
{
Password[129], //We will load player's password into this varible from database
userid,
}
new pInfo[MAX_PLAYERS][PDATA];
#define dlogin 0
#define dregister 1
forward OnAccountLoad(playerid);
forward OnAccountRegister(playerid);
native WP_Hash(buffer[], len, const str[]);
//***************************************//
PHP код:
forward ConnectMySQL();
public ConnectMySQL()
{
if(mysql_errno(mysql) == 0)
{
mysql_log(LOG_ERROR | LOG_WARNING, LOG_TYPE_TEXT);
printf("[MYSQL]: Connected to `%s`.",SQL_DB);
}
else printf("[MYSQL]: Failed to connect to `%s`.",SQL_DB);
return 1;
}
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows)
{
cache_get_field_content(0, "password", pInfo[playerid][Password], mysql, 129);
pInfo[playerid][userid] = cache_get_field_content_int(0, "userid");
ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "login bitch", "Login", "Leave");
}
else
{
ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Registration", "You must be new fool", "Register", "Quit");
}
return 1;
}
public OnAccountLoad(playerid)
{
SendClientMessage(playerid, -1, "Successfully logged in");
return 1;
}
public OnAccountRegister(playerid)
{
pInfo[playerid][userid] = cache_insert_id();
printf("New account registered. ID: %d", pInfo[playerid][userid]);
return 1;
}
PHP код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case dlogin:
{
if(!response) Kick(playerid);
new query[100], hpass[129];
WP_Hash(hpass, 129, inputtext);
if(!strcmp(hpass, pInfo[playerid][Password]))
{
new Name[28];
GetPlayerName(playerid, Name, 28);
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%e' LIMIT 1", Name);
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
}
else ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "login bitch\nWrong password!", "Login", "Quit");
}
case dregister:
{
if(!response) return Kick(playerid);
if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "You must be new here fool .\nYour password must be at least 6 characters long!", "Register", "Quit");
new query[300], Name[28];
GetPlayerName(playerid, Name, 28);
WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
mysql_format(mysql, query, sizeof(query), "INSERT INTO `users` (`name`, `password`) VALUES ('%e', '%s')", Name, pInfo[playerid][Password]);
mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
}
}
return 1;
}
PHP код:
mysql = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS);
ConnectMySQL();
PHP код:
new query[128], name[50];
GetPlayerName(playerid, name, 50);
mysql_format(mysql, query, sizeof(query),"SELECT `password`, `userid` FROM `users` WHERE `name` = '%e' LIMIT 1", name);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);