12.02.2013, 19:43
Ok i'm converting my r6 mysql system ( no bugs ) to r7 edition with cache functions and I have stumbled across problem. Everything is fine apart from logging in. Even when I am in the database it still says I have to register. I have to go now so I will leave you some time to work it out and get back to me
Everything of mysql:
Everything of mysql:
pawn Код:
if(LoggedIn[playerid] == 0) {
new Query[500];
format(Query, 500, "SELECT `password` FROM `users` WHERE `username`='%s'", PlayerName(playerid));
mysql_function_query(Gconnection, Query, true, "", "");
new rows, fields;
cache_get_data(rows, fields, Gconnection);
if(!rows) { // query returned no rows = player is not registered.
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FF0000}[SFCNR]{FFFFFF} You are not registered!", "{FFFFFF}Please enter a password to register an account with us", "Ok", "Quit");
} else { // query returned 1 row = player is registered.
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FF0000}[SFCNR]{FFFFFF} You are registered!", "{FFFFFF}Please enter a password to login to your account", "Ok", "Quit");
}
}
switch(dialogid) {
case DIALOG_REGISTER: {
if(!response) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FF0000}[SFCNR]{FFFFFF} You are not registered!", "{FFFFFF}Please enter a password to register an account with us", "Ok", "Quit");
Mysql_Register(playerid, inputtext);
}
case DIALOG_LOGIN: {
if(!response) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FF0000}[SFCNR]{FFFFFF} You are registered!", "{FFFFFF}Please enter your password to login", "Ok", "Quit");
Mysql_Login(playerid, inputtext);
}
}
public Mysql_Register(playerid, password[])
{
mysql_real_escape_string(PlayerName(playerid), PlayerName(playerid), Gconnection);
new hashedpass[129];
format(hashedpass, 129, "%s%s", SALT, password);
mysql_real_escape_string(password, password, Gconnection);
WP_Hash(hashedpass, 129, hashedpass);
new Year, Month, Day;
getdate(Year, Month, Day);
new Query[500];
format(Query, 500, "INSERT INTO `users` (username, password, regdate) VALUES ('%s', '%s', '%02d/%02d/%d')", PlayerName(playerid), hashedpass, Day, Month, Year);
mysql_function_query(Gconnection, Query, true, "OnPlayerRegister", "d", playerid);
return 1;
}
public Mysql_Login(playerid, password[])
{
mysql_real_escape_string(PlayerName(playerid), PlayerName(playerid), Gconnection);
new hashedpass[129];
format(hashedpass, 129, "%s%s", SALT, password);
mysql_real_escape_string(password, password, Gconnection);
WP_Hash(hashedpass, 129, hashedpass);
new Query[200];
format(Query, 200, "SELECT `score` FROM `users` WHERE `username`='%s' AND `password`='%s'", PlayerName(playerid), hashedpass);
mysql_function_query(Gconnection, Query, true, "", "");
new rows, fields;
cache_get_data(rows, fields, Gconnection);
if(rows) {
new Querys[700];
format(Querys, 700, "SELECT * FROM `users` WHERE `username`='%s'", PlayerName(playerid));
mysql_function_query(Gconnection, Querys, true, "OnPlayerLogin", "d", playerid);
} else {
MaxPassAttempts[playerid]++;
if(MaxPassAttempts[playerid] == 4) {
format(G_String, 128, "[SERVER MESSAGE] :{FFFFFF}%s has been kicked for max password attempts.", PlayerName(playerid));
SendClientMessageToAll(COLOR_RED2, G_String);
Kick(playerid);
}
}
return 1;
}
public OnPlayerLogin(playerid)
{
new rows, fields;
cache_get_data(rows, fields, Gconnection);
if(rows) {
new temp[12];
cache_get_row(0, 2, temp); PlayerInfo[playerid][Pscore] = strval(temp);
cache_get_row(0, 3, temp); PlayerInfo[playerid][Pmoney] = strval(temp);
cache_get_row(0, 4, temp); PlayerInfo[playerid][Pbank] = strval(temp);
cache_get_row(0, 5, temp); PlayerInfo[playerid][Pstat] = strval(temp);
cache_get_row(0, 6, temp); PlayerInfo[playerid][Parmy] = strval(temp);
cache_get_row(0, 7, temp); PlayerInfo[playerid][Pswat] = strval(temp);
cache_get_row(0, 8, temp); PlayerInfo[playerid][Padmin] = strval(temp);
cache_get_row(0, 9, temp); PlayerInfo[playerid][Pcop] = strval(temp);
cache_get_row(0, 10, temp); PlayerInfo[playerid][Pscore] = strval(temp);
cache_get_row(0, 12, temp); PlayerInfo[playerid][Pprison] = strval(temp);
cache_get_row(0, 13, temp); PlayerInfo[playerid][Pvip] = strval(temp);
cache_get_row(0, 14, temp); PlayerInfo[playerid][Parrest] = strval(temp);
cache_get_row(0, 15, temp); PlayerInfo[playerid][Psurender] = strval(temp);
cache_get_row(0, 16, temp); PlayerInfo[playerid][Prob] = strval(temp);
cache_get_row(0, 17, temp); PlayerInfo[playerid][Prape] = strval(temp);
cache_get_row(0, 18, temp); PlayerInfo[playerid][Pheal] = strval(temp);
cache_get_row(0, 19, temp); PlayerInfo[playerid][Phitman] = strval(temp);
cache_get_row(0, 20, temp); PlayerInfo[playerid][Psales] = strval(temp);
cache_get_row(0, 21, temp); PlayerInfo[playerid][Pwep] = strval(temp);
cache_get_row(0, 22, temp); PlayerInfo[playerid][Pdrug] = strval(temp);
cache_get_row(0, 23, temp); PlayerInfo[playerid][Ptaze] = strval(temp);
cache_get_row(0, 24, temp); PlayerInfo[playerid][Ptruck] = strval(temp);
LoggedIn[playerid] = 1;
} else {
printf("Oops something went wrong! callback: OnPlayerLogin Player: %s Rows: %d", PlayerName(playerid), rows);
}
return 1;
}
public OnPlayerRegister(playerid)
{
SendClientMessage(playerid, COLOR_RED2, "[SERVER MESSAGE] :{FFFFFF} Thankyou for registering at our server. Please use /commands and /help for help");
total_users++;
UpdateTotalUsers();
LoggedIn[playerid] = 1;
return 1;
}