2021-03-19, 09:49 PM
How can I?improve this code?
PHP Code:
Account_PromptLogin(playerid) {
? ? new
? ? ? ? query[81],
? ? ? ? playerHash[62],
? ? ? ? playerDate[11],
? ? ? ? playerTime[9],
? ? ? ? playerIP[16],
? ? ? ? rows;
? ? mysql_format(MySQL_GetHandle(), query, sizeof query,
? ? "\
? ? ? ? SELECT * FROM `players` WHERE `username` = '%e' LIMIT 1\
? ? ",
? ? ? ? Player_GetName(playerid)
? ? );
? ? mysql_query(MySQL_GetHandle(), query);
? ? cache_get_row_count(rows);
? ? if (!rows) {
? ? ? ? Player_Kick(playerid);
? ? ? ? return 0;
? ? }
? ? cache_get_value_name(0, "password", playerHash, sizeof(playerHash));
? ? cache_get_value_name(0, "date_reg", playerDate, sizeof(playerDate));
? ? cache_get_value_name(0, "time_reg", playerTime, sizeof(playerTime));
? ? cache_get_value_name(0, "ip", playerIP, sizeof(playerIP));
? ? Player_SetAccountHash(playerid, playerHash);
? ? Player_SetAccountDate(playerid, playerDate);
? ? Player_SetAccountTime(playerid, playerTime);
? ? Player_SetAccountIP(playerid, playerIP);
? ? Dialog_ShowCallback(playerid,
? ? ? ? using public Account_Login<iiiis>,
? ? ? ? DIALOG_STYLE_PASSWORD,
? ? ? ? SERVER_NAME,
? ? ? ? "Welcome",
? ? ? ? "Login",
? ? ? ? "Exit"
? ? );
? ? return 1;
}
forward Account_Login(playerid, dialogid, response, listitem, string:inputtext[]);
public Account_Login(playerid, dialogid, response, listitem, string:inputtext[]) {
? ? if (response) {
? ? ? ? bcrypt_verify(playerid, "OnPasswordVerify", inputtext, Player_GetAccountHash(playerid));
? ? }
? ? else {
? ? ? ? Kick(playerid);
? ? }
? ? return 1;
}
PHP Code:
forward OnPasswordVerify(playerid, bool:success);
public OnPasswordVerify(playerid, bool:success) {
? ? if (success)
? ? {
? ? ? ? CallLocalFunction("OnPlayerLogin", "d", playerid);
? ? }
? ? else
? ? {
? ? ? ? Account_PromptLogin(playerid);
? ? }
}