14.01.2019, 20:40
user system startpack
uses latest plugins and coding methods
uses latest plugins and coding methods
PHP Code:
#include <bcrypt> //https://sampforum.blast.hk/showthread.php?tid=453544
#include <easyDialog> //https://sampforum.blast.hk/showthread.php?tid=475838
#define BCRYPT_COST 12
#define easyDialogParams response, listitem, inputtext[]
enum playerStatsVars{
Name[24],
bool:LoggedIn
};
new pStats[MAX_PLAYERS][playerStatsVars];
//for delayed kick message
KickEx(playerid,msg[120]){
SendClientMessage(playerid,-1,msg);
return SetTimerEx("callKick",100,false,"d",playerid);
}
forward callKick(playerid);
public callKick(playerid){
return Kick(playerid);
}
//getting username
getUserName(playerid){
new s[24];
GetPlayerName(playerid,s,24);
return s;
}
//this must be added under onplayerconnect for example
Dialog_Show(playerid, RegisterPlayer, DIALOG_STYLE_PASSWORD, "account registration", "account with such name doesn't exsist.\nfor registration enter password.", "register", "close");
//makes dialog creation easier
Dialog:RegisterPlayer(playerid,easyDialogParams){
if(!response){
return KickEx(playerid,"you selected close option.");
}
if(!(6<=strlen(inputtext)<=30)){
SendClientMessage(playerid,-1,"password must be between 6 to 30!");
return 1;
}
//hashing password
bcrypt_hash(inputtext, BCRYPT_COST, "RegisterPlayer", "d", playerid);
return 1;
}
//thread from password bcrypt
forward RegisterPlayer(playerid);
public RegisterPlayer(playerid){
//copies player name into array, so you don't need to call GetPlayerName, native functions are slower then variables
strmid(pStats[playerid][Name],getUserName(playerid),0,24,24);
new s[400];
//no need to escape string, because user input isnt insert here
format(s,400,"insert into player_account(username,password) values('%s','%s')",pStats[playerid][Name],password);
mysql_tquery(serverCon,s,"threadRegisterPlayer","d",playerid);
return 1;
}
//thread from database
forward threadRegisterPlayer(playerid);
public threadRegisterPlayer(playerid){
SendClientMessage(playerid,-1,"account registered.");
pStats[playerid][LoggedIn]=true;
return 1;
}