Current directory: C:\Users\harvey\Documents\Server test\gamemodes
rp2.pwn(115) : error 017: undefined symbol "WP_Hash"
rp2.pwn(142) : error 017: undefined symbol "WP_Hash"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Errors.
================ READY ================
WP_Hash(User[playerid][USER_PASSWORD], 129, inputtext);
WP_Hash(buf, 129, inputtext);
case DIALOG_LOGIN:
{
if (!response) return Kick(playerid);
new
buf[129];
WP_Hash(buf, 129, inputtext);
if (strcmp(buf, User[playerid][USER_PASSWORD]))
{
SendClientMessage(playerid, 0xFF0000FF, "[ERROR]: Incorrect password");
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Type in your password below to log in.", "Login", "Leave" );
return 1;
}
new
DBResult: Result;
format(buf, sizeof buf, "SELECT * FROM users WHERE username = '%q' LIMIT 1", User[playerid][USER_NAME]);
Result = db_query(Database, buf); result later
if (db_num_rows(Result))
{
User[playerid][USER_ID] = db_get_field_assoc_int(Result, "userid");
User[playerid][USER_ADMIN] = db_get_field_assoc_int(Result, "admin");
SendClientMessage(playerid, 0x00FF00FF, "[SERVER]: You have successfully logged in to your account!");
}
db_free_result(Result);
}
case DIALOG_REGISTER:
{
// if the player did not response to the dialog, meaning pressed either Esc or ckicked on "Leave" button, will be kicked
if (!response) return Kick(playerid);
if (!(3 <= strlen(inputtext) <= 20))
{ // if the length of the desired password is not beetween 3-20 characters
SendClientMessage(playerid, 0xFF0000FF, "[ERROR]: Invalid length on the password. It should be between 3-20 characters" );// send the message error for the valid lenght of the password
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", "Type in a password below to register an account.", "Register", "Leave" );// re-show the register dialog
return 1; // stop the code below from being executed
}
new // a query, remember to change the size of it if you add more stuff
Query[208];
WP_Hash(User[playerid][USER_PASSWORD], 129, inputtext); // Hash the password from the inputtext and store it to User[playerid][USER_PASSWORD]
format(Query, sizeof Query, "INSERT INTO users (username, password) VALUES ('%q', '%s')", User[playerid][USER_NAME], User[playerid][USER_PASSWORD]);// Insert into users the name and the password. The userid gets increased automatically and the admin is by default 0 value. We don't have to escape password as the hashed output provided by Whirlpool contains only alphabet characters and numbers.
db_query(Database, Query);// execute the SQL query
SendClientMessage(playerid, 0x00FF00FF, "[SERVER]: You have just registered to our server! You have been automatically logged in!");//send a message just to inform the player that he's now registered!
// We have to retrieve the value generated from the Auto Increment for the "userid" field.
// last_insert_rowid() function returns the last inserted row in the last session as its name suggests already.
new
DBResult: Result;
Result = db_query(Database, "SELECT last_insert_rowid()"); // it will return the value for field "userid" generated
User[playerid][USER_ID] = db_get_field_int(Result); // The difference in this function except that it doesn't support the name of the field but the field ID instead, it is that returns an integer directly without having to store it to a temporary string and then use strval function to convert string to integer.
// There is a second parameter "field" which is by default 0. We know that only 1 row and 1 field will be selected so we may not specify it.
// REMEMBER! Fields starts from 0.
db_free_result(Result); // Last, we free the result memory
}
native WP_Hash(buffer[], len, const str[]);
Add under includes:
pawn Код:
|