29.01.2018, 08:39
PHP код:
if(sscanf, "u[30]", password) return SendClientMessage(playerid, COLOR_RED, "* USAGE: /login [password]");
if(sscanf, "u[30]", password) return SendClientMessage(playerid, COLOR_RED, "* USAGE: /login [password]");
Specifier(s) Name Example values i, d Integer 1, 42, -10 c Character a, o, * l Logical true, false b Binary 01001, 0b1100 h, x Hex 1A, 0x23 o Octal 045 12 n Number 42, 0b010, 0xAC, 045 f Float 0.7, -99.5 g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E u User name/id (bots and players) ******, 0 q Bot name/id ShopBot, 27 r Player name/id ******, 42
Код:
Specifier(s) Name Example values i, d Integer 1, 42, -10 c Character a, o, * l Logical true, false b Binary 01001, 0b1100 h, x Hex 1A, 0x23 o Octal 045 12 n Number 42, 0b010, 0xAC, 045 f Float 0.7, -99.5 g IEEE Float 0.7, -99.5, INFINITY, -INFINITY, NAN, NAN_E u User name/id (bots and players) ******, 0 q Bot name/id ShopBot, 27 r Player name/id ******, 42 |
new thepass[30];
CMD:login(playerid, params[])
{
if(IsPlayerRegistered[playerid] == 1 && MLogin[playerid] == false)
{
new query[280];
if(sscanf(params, "u", thepass)) return SendClientMessage(playerid, COLOR_RED, "* USAGE: /login [password]");
mysql_format(mysql, query, sizeof(query),"SELECT `IP`, `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", GetName(playerid));
mysql_tquery(mysql, query, "Login", "iu", playerid, thepass);
}
return 1;
}
forward Login(playerid, password);
public Login(playerid, password)
{
if(IsPlayerRegistered[playerid] == 1 && MLogin[playerid] == true)
{
SendClientMessage(playerid, COLOR_RED, "* You are already logged in.");
}
if(cache_num_rows() >= 1)
{
cache_get_value_name(0, "Password", pData[playerid][Password], 129);
cache_get_value_name_int(0, "ID", pData[playerid][ID]);
new hpass[129]; //for password hashing
new query[100]; // for formatting our query.
WP_Hash(hpass, 129, thepass);
if(!strcmp(hpass, pData[playerid][Password])) //remember we have loaded player's password into this variable, pData[playerid][Password] earlier. Now let's use it to compare the hashed password with password that we load
{
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GetName(playerid));
mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
MLogin[playerid] = true;
}
else //if the hashed password didn't match with the loaded password(pData[playerid][Password])
{
new tmp[128], str[280];
pInfo[playerid][WrongPass]++;
format(tmp, sizeof(tmp), "9,2%s (ID: %d) tried to login using a wrong password", GetName(playerid), playerid);
IRC_GroupSay(groupID, IRC_aCHANNEL, tmp);
IRC_GroupSay(groupID, IRC_CHANNEL, tmp);
format(str, sizeof(str), "* %s (ID: %d) tried to login using a wrong password", GetName(playerid), playerid);
SendClientMessage(playerid, COLOR_RED, str);
}
}
else
{
SendClientMessage(playerid, COLOR_RED, "* You are not registered, use /register.");
}
return 1;
}