stock UserPath(playerid) { new string[128],playername[MAX_PLAYER_NAME]; GetPlayerName(playerid,playername,sizeof(playername)); format(string,sizeof(string),PATH,playername); return string; } stock CheckAccount(playerid) { if(fexist(UserPath(playerid))) { INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{00FF00}Login","{FFFFFF}Account status:{00FF00} REGISTERED\n{FFFFFF}Put your password to login.","Login","Quit"); } else { ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD,"{00FF00}Register","{FFFFFF}Account status:{FF0000} NOT-REGISTERED\n{FFFFFF}Put your desired password to register.","Register","Quit"); } return 1; }
forward loadUserData(playerid,name[],value[]); public loadUserData(playerid,name[],value[]) { INI_Int("Key", PlayerInfo[playerid][pKey]); INI_Int("Admin", PlayerInfo[playerid][pAdmin]); INI_Int("Banned", PlayerInfo[playerid][pBanned]); INI_Int("PermBand", PlayerInfo[playerid][pPermBand]); INI_Int("BanReason", PlayerInfo[playerid][pBanReason]); INI_Int("PrisonReason", PlayerInfo[playerid][pPrisonReason]); INI_Int("AdminJailed", PlayerInfo[playerid][pAdminJailed]); INI_Int("PrisonedBy", PlayerInfo[playerid][pPrisonedBy]); INI_Int("Donor", PlayerInfo[playerid][pDonor]); INI_Int("XP", PlayerInfo[playerid][pExp]); INI_Int("Cash", PlayerInfo[playerid][pCash]); INI_Int("Kills", PlayerInfo[playerid][pKills]); INI_Int("Deaths", PlayerInfo[playerid][pDeaths]); INI_Int("Skin", PlayerInfo[playerid][pSkin]); INI_Int("Tikis", PlayerInfo[playerid][pTikis]); INI_Int("MinigunAccess", PlayerInfo[playerid][pMinigunAccess]); return 1; }
stock SaveAccount(playerid) { new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File, "data"); INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]); INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]); INI_WriteInt(File, "PermBand", PlayerInfo[playerid][pPermBand]); INI_WriteInt(File, "BanReason", PlayerInfo[playerid][pBanReason]); INI_WriteInt(File, "PrisonReason", PlayerInfo[playerid][pPrisonReason]); INI_WriteInt(File, "AdminJailed", PlayerInfo[playerid][pAdminJailed]); INI_WriteInt(File, "PrisonedBy",PlayerInfo[playerid][pPrisonedBy]); INI_WriteInt(File, "Donor",PlayerInfo[playerid][pDonor]); INI_WriteInt(File, "XP", PlayerInfo[playerid][pExp]); INI_WriteInt(File, "Cash", GetPlayerMoney(playerid)); INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]); INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]); INI_WriteInt(File, "Skin", PlayerInfo[playerid][pSkin]); INI_WriteInt(File, "Tikis", PlayerInfo[playerid][pTikis]); INI_WriteInt(File, "MinigunAccess", PlayerInfo[playerid][pMinigunAccess]); INI_Close(File); return 1; }
public OnPlayerDisconnect(playerid, reason) { new string[512]; SaveAccount(playerid); if(reason == 0) { format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Timeout{FFFFFF}", PlayerName(playerid)); SendClientMessageToAll(-1, string); } else if(reason == 1) { format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Quit{FFFFFF}", PlayerName(playerid)); SendClientMessageToAll(-1, string); } else if(reason == 2) { format(string, 256, "{00BFFF}%s{FFFFFF}has left the server. Reason:{00BFFF}Kicked/Banned{FFFFFF}", PlayerName(playerid)); SendClientMessageToAll(-1, string); } PlayerInfo[playerid][pAdmin] = 0; PlayerInfo[playerid][pBanned] = 0; PlayerInfo[playerid][pPermBand] = 0; PlayerInfo[playerid][pBanReason] = 0; PlayerInfo[playerid][pPrisonReason] = 0; PlayerInfo[playerid][pAdminJailed] = 0; PlayerInfo[playerid][pPrisonedBy] = 0; PlayerInfo[playerid][pDonor] = 0; PlayerInfo[playerid][pExp] = 0; PlayerInfo[playerid][pCash] = 0; PlayerInfo[playerid][pKills] = 0; PlayerInfo[playerid][pDeaths] = 0; PlayerInfo[playerid][pSkin] = 0; PlayerInfo[playerid][pTikis] = 0; PlayerInfo[playerid][pMinigunAccess] = 0; return 1; }
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case DIALOG_REGISTER: { if (!response) return PKick(playerid); if(response) { WP_Hash(PlayerInfo[playerid][pKey], 129, inputtext); if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n{FFFFFF}Type your password below to register a new account.","Register","Quit"); new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteString(File, "Key", PlayerInfo[playerid][pKey]); INI_WriteInt(File, "Admin",0); INI_WriteInt(File, "Banned", 0); INI_WriteInt(File, "PermBand",0); INI_WriteInt(File, "BanReason",0); INI_WriteInt(File, "PrisonReason",0); INI_WriteInt(File, "AdminJailed",0); INI_WriteInt(File, "PrisonedBy",0); INI_WriteInt(File, "Donor",0); INI_WriteInt(File, "Exp", 0); INI_WriteInt(File, "Cash", 0); INI_WriteInt(File, "Kills",0); INI_WriteInt(File, "Deaths", 0); INI_WriteInt(File, "Skin", 0); INI_WriteInt(File, "Tikis", 0); INI_WriteInt(File, "MinigunAccess", 0); INI_Close(File); } } case DIALOG_LOGIN: { new pwhash[129]; WP_Hash(pwhash, sizeof(pwhash), inputtext); if (!response) return PKick(playerid); if(response) { if(!strcmp(pwhash, PlayerInfo[playerid][pKey])) { INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); } } else { SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this."); PKick(playerid); } return 1; }
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
forward loadUserData(playerid,name[],value[]); public loadUserData(playerid,name[],value[])
INI_ParseFile("myfile.ini", "Callback_%s", .bFileFirst = true, .bPassTag = true); public Callback_myfile_ini(tag[], identifier[], text[]) { if (!strcmp(tag, "some_tag")) { ... } }
INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid);
Awww but I thought you are an INI expert :3
OT: You are not using the callback you created anywhere, why create a callback for a small function? just make a normal function and use it on the player login dialog. |
I have not worked with a Y_INI, but I think it is worth paying attention to these lines:
Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); Код:
forward loadUserData(playerid,name[],value[]); public loadUserData(playerid,name[],value[]) Код:
INI_ParseFile("myfile.ini", "Callback_%s", .bFileFirst = true, .bPassTag = true); public Callback_myfile_ini(tag[], identifier[], text[]) { if (!strcmp(tag, "some_tag")) { ... } } Код:
INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid); |
native WP_Hash(buffer[], len, const str[]);
case DIALOG_REGISTER: { if (!response) return PKick(playerid); if(response) { WP_Hash(PlayerInfo[playerid][pKey], 129, inputtext); if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFFFF}Registering...","{FF0000}You have entered an invalid password.\n{FFFFFF}Type your password below to register a new account.","Register","Quit"); new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File,"data"); INI_WriteString(File, "Key", PlayerInfo[playerid][pKey]); INI_WriteInt(File, "Admin",0); INI_WriteInt(File, "Banned", 0); INI_WriteInt(File, "PermBand",0); INI_WriteInt(File, "BanReason",0); INI_WriteInt(File, "PrisonReason",0); INI_WriteInt(File, "AdminJailed",0); INI_WriteInt(File, "PrisonedBy",0); INI_WriteInt(File, "Donor",0); INI_WriteInt(File, "Exp", 0); INI_WriteInt(File, "Cash", 0); INI_WriteInt(File, "Kills",0); INI_WriteInt(File, "Deaths", 0); INI_WriteInt(File, "Skin", 0); INI_WriteInt(File, "Tikis", 0); INI_WriteInt(File, "MinigunAccess", 0); INI_Close(File); } }
case DIALOG_LOGIN: { new pwhash[129]; WP_Hash(pwhash, sizeof(pwhash), inputtext); if (!response) return PKick(playerid); if(response) { if(!strcmp(pwhash, PlayerInfo[playerid][pKey])) { INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid); GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); } } else { SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this."); PKick(playerid); } return 1; }
case DIALOG_LOGIN: { new pwhash[129]; WP_Hash(pwhash, sizeof(pwhash), inputtext); if (!response) return PKick(playerid); if(response) { if(!strcmp(pwhash, PlayerInfo[playerid][pKey])) { INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid); GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); } } else { SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this."); PKick(playerid); } return 1; }
Код:
case DIALOG_LOGIN: { new pwhash[129]; WP_Hash(pwhash, sizeof(pwhash), inputtext); if (!response) return PKick(playerid); if(response) { if(!strcmp(pwhash, PlayerInfo[playerid][pKey])) { INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid); GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); } } else { SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this."); PKick(playerid); } return 1; } |
forward loadUserData(playerid,name[],value[]); public loadUserData(playerid,name[],value[]) { new filepassword[129]; INI_String("Password",filepassword,129); if(strcmp(filepassword, PlayerInfo[playerid][pKey], true) == 0) { //INI_Int("Key", PlayerInfo[playerid][pKey]); - password not is a integer! INI_Int("Admin", PlayerInfo[playerid][pAdmin]); INI_Int("Banned", PlayerInfo[playerid][pBanned]); INI_Int("PermBand", PlayerInfo[playerid][pPermBand]); INI_Int("BanReason", PlayerInfo[playerid][pBanReason]); INI_Int("PrisonReason", PlayerInfo[playerid][pPrisonReason]); INI_Int("AdminJailed", PlayerInfo[playerid][pAdminJailed]); INI_Int("PrisonedBy", PlayerInfo[playerid][pPrisonedBy]); INI_Int("Donor", PlayerInfo[playerid][pDonor]); INI_Int("XP", PlayerInfo[playerid][pExp]); INI_Int("Cash", PlayerInfo[playerid][pCash]); INI_Int("Kills", PlayerInfo[playerid][pKills]); INI_Int("Deaths", PlayerInfo[playerid][pDeaths]); INI_Int("Skin", PlayerInfo[playerid][pSkin]); INI_Int("Tikis", PlayerInfo[playerid][pTikis]); INI_Int("MinigunAccess", PlayerInfo[playerid][pMinigunAccess]); GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); } else { SendClientMessage(playerid, -1, "{FF0000}Your password is incorrect. Please, talk to an administrator regarding this."); PKick(playerid); } return 1; } case DIALOG_LOGIN: { new pwhash[129]; WP_Hash(pwhash, sizeof(pwhash), inputtext); if (!response) return PKick(playerid); strmid(PlayerInfo[playerid][pKey], pwhash, 0, strlen(pwhash), 129); INI_ParseFile(UserPath(playerid), "loadUserData", .bExtra = true, .extra = playerid); return 1; }
new gPlayerLogged[MAX_PLAYERS]; On OnPlyerConnect: public OnPlyerConnect(playerid) { gPlayerLogged[playerid] = 0; //code..... return 1; } On loadUserData: public loadUserData(playerid,name[],value[]) { // code... if(strcmp(filepassword, PlayerInfo[playerid][pKey], true) == 0) { // code... GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerScore(playerid, PlayerInfo[playerid][pExp]); gPlayerLogged[playerid] = 1; } else { // code... } return 1; } stock SaveAccount(playerid) { if(gPlayerLogged[playerid]) { new INI:File = INI_Open(UserPath(playerid)); INI_SetTag(File, "data"); INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]); INI_WriteInt(File, "Banned", PlayerInfo[playerid][pBanned]); INI_WriteInt(File, "PermBand", PlayerInfo[playerid][pPermBand]); INI_WriteInt(File, "BanReason", PlayerInfo[playerid][pBanReason]); INI_WriteInt(File, "PrisonReason", PlayerInfo[playerid][pPrisonReason]); INI_WriteInt(File, "AdminJailed", PlayerInfo[playerid][pAdminJailed]); INI_WriteInt(File, "PrisonedBy",PlayerInfo[playerid][pPrisonedBy]); INI_WriteInt(File, "Donor",PlayerInfo[playerid][pDonor]); INI_WriteInt(File, "XP", PlayerInfo[playerid][pExp]); INI_WriteInt(File, "Cash", GetPlayerMoney(playerid)); INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]); INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]); INI_WriteInt(File, "Skin", PlayerInfo[playerid][pSkin]); INI_WriteInt(File, "Tikis", PlayerInfo[playerid][pTikis]); INI_WriteInt(File, "MinigunAccess", PlayerInfo[playerid][pMinigunAccess]); INI_Close(File); } return 1; }
INI_Int("Key", PlayerInfo[playerid][pKey]);