PHP Code:
#include <a_samp>
#include <YSI\y_ini>
#include <zcmd>
#define spd ShowPlayerDialog
#define max_players 40
enum {
d_log,
d_reg,
d_age,
d_gender,
};
enum uEnum{
PW,
Age,
Gender,
};
new uInfo[max_players][uEnum];
new bool:LoggedIn[max_players];
UserName(pid){
new str[24];
GetPlayerName(pid,str,sizeof(str));
return str;
}
UserPath(pid){
new str[60];
format(str,sizeof(str),"users/%s.ini",UserName(pid));
return str;
}
udb_hash(buf[]) {
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++){
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
main(){}
public OnGameModeInit(){
for(new i; i < 20; i++)AddPlayerClass(10+i, 1958.3783, 1343.1572, 15.3746, 269.1425, 0,0,0,0,0,0);
return 1;
}
public OnPlayerConnect(playerid){
LoggedIn[playerid]=false;
if(fexist( UserPath(playerid) )){
INI_ParseFile( UserPath(playerid),"load_user_%s",.bExtra = true, .extra = playerid );
spd(playerid,d_log,DIALOG_STYLE_PASSWORD,"Login","{ffffff}You own account, to login just enter your password.","Login","Kick");
}else{
spd(playerid,d_gender,DIALOG_STYLE_MSGBOX,"Register","{ffffff}Choose your gender.","Male","Female");
}
return 1;
}
public OnPlayerRequestClass(playerid, classid){
if(LoggedIn[playerid]==false){
SendClientMessage(playerid,-1,"You must be logged in!");
return 0;
}
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerRequestSpawn(playerid){
if(LoggedIn[playerid]==false){
SendClientMessage(playerid,-1,"You must be logged in!");
return 0;
}
return 1;
}
forward load_user_info(pid,name[],value[]);
public load_user_info(pid,name[],value[]){
INI_Int("pw",uInfo[pid][PW]);
INI_Int("age",uInfo[pid][Age]);
INI_Int("gender",uInfo[pid][Gender]);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
switch(dialogid){
case d_log:{
if(!response)return Kick(playerid);
if(uInfo[playerid][PW]!=udb_hash(inputtext))return spd(playerid,d_log,DIALOG_STYLE_PASSWORD,"Login","{FF0000}You entered wrong password!\n{FFFFFF}You own account, to login just enter your password.","Login","Kick");
LoggedIn[playerid]=true;
SendClientMessage(playerid,-1,"You successfully logged in!");
}
case d_gender:{
uInfo[playerid][Gender]=response;
spd(playerid,d_age,DIALOG_STYLE_INPUT,"Register","{ffffff}Enter your character age.","Okey","Kick");
}
case d_age:{
if(!response)return Kick(playerid);
if(strval(inputtext)<18||strval(inputtext)>99)return spd(playerid,d_age,DIALOG_STYLE_INPUT,"Register","{ff0000}Age must be between 18 to 99!\n{ffffff}Enter your character age.","Okey","Kick");
uInfo[playerid][Age]=strval(inputtext);
spd(playerid,d_reg,DIALOG_STYLE_PASSWORD,"Register","{ffffff}Enter your future password.","Register","Kick");
}
case d_reg:{
if(!response)return Kick(playerid);
if(strlen(inputtext)<3||strlen(inputtext)>20)return spd(playerid,d_reg,DIALOG_STYLE_MSGBOX,"Register","{ff00000}Pw must contain 3 to 20 characters!\n{ffffff}Enter your future password.","Register","Kick");
new INI:file = INI_Open(UserPath(playerid));
INI_SetTag(file,"info");
INI_WriteInt(file,"pw",udb_hash(inputtext));
INI_WriteInt(file,"gender",uInfo[playerid][Gender]);
INI_WriteInt(file,"age",uInfo[playerid][Age]);
INI_Close(file);
LoggedIn[playerid]=true;
SendClientMessage(playerid,-1,"You successfully registered your account!");
}
}
return 1;
}
CMD:stats(pid){
new str[30];
format(str,sizeof(str),"Gender: %s | Age: %d",(uInfo[pid][Gender])?("Male"):("Female"),uInfo[pid][Age]);
SendClientMessage(pid,-1,str);
return 1;
}