20.06.2017, 03:50
im new in yini.
why i create login script,the ini file is blank?
why i create login script,the ini file is blank?
PHP код:
#include <a_samp>
#include <YSI\y_ini>
#include <sscanf2>
#include <zcmd>
#define FILTERSCRIPT
#define DIALOG_REGISTER 9998
#define DIALOG_LOGIN 9999
#define UserPath "/Users/%s.ini"
#define COLOR_RED 0xFF0000FF
#define COLOR_BLUE 0x0000FFFF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_GREEN 0x00FF00FF
#define COLOR_LIGHTBLUE 0x00FFFFFF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_BLACK 0x000000FF
#define COLOR_GRAY 0x808080FF
native WP_Hash(buffer[],len,const str[]);
forward loadaccount_user(playerid, name[], value[]);
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
#endif
enum PlayerStats
{
password[128],
money,
score,
deaths,
admin,
}
new pStats[MAX_PLAYERS][PlayerStats];
public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(fexist(Path(playerid)))
{
INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{00FFFF}Login", "{00FFFF}Please enter your password to login.", "OK", "Cancel");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{00FFFF}Register", "{00FFFF}Please enter your password to register.", "OK", "Cancel");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:file = INI_Open(Path(playerid));
INI_WriteInt(file,"Money",GetPlayerMoney(playerid));
INI_WriteInt(file,"Score",GetPlayerScore(playerid));
INI_WriteInt(file,"Deaths",pStats[playerid][deaths]);
INI_WriteInt(file,"Admin",pStats[playerid][admin]);
INI_Close(file);
return 1;
}
public OnPlayerSpawn(playerid)
{
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pStats[playerid][money]);
SetPlayerScore(playerid, pStats[playerid][score]);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
pStats[killerid][score]++;
pStats[killerid][money]++;
pStats[playerid][deaths]++;
GivePlayerMoney(killerid, 1);
SetPlayerScore(killerid, pStats[killerid][score]);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(response)
{
switch(dialogid)
{
case DIALOG_REGISTER:
{
if(!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{00FFFF}Register", "{00FFFF}Please enter your password to register.\n{FF0000}You can't leave this empty.", "OK", "Cancel");
return 1;
}
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
new string[128];
new INI:file = INI_Open(Path(playerid));
INI_WriteString(file,"Password",hashpass);
INI_WriteInt(file,"Money",0);
INI_WriteInt(file,"Score",0);
INI_WriteInt(file,"Deaths",0);
INI_WriteInt(file,"Admin",0);
INI_Close(file);
format(string, sizeof(string), "You have successfully registered. Password: {00FF00)%s", inputtext);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
}
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response)
{
new hashpass[129];
WP_Hash(hashpass,sizeof(hashpass),inputtext);
if(!strcmp(hashpass, pStats[playerid][password], false))
{
INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);
SendClientMessage(playerid,COLOR_WHITE,"You have successfully logged in.");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "{00FFFF}Please enter your password to login.\n{FF0000}Incorrect password.", "OK", "Cancel");
return 1;
}
}
}
}
}
return 1;
}
public loadaccount_user(playerid, name[], value[])
{
INI_String("Password",pStats[playerid][password],128);
INI_Int("Money",pStats[playerid][money]);
INI_Int("Score",pStats[playerid][score]);
INI_Int("Deaths",pStats[playerid][deaths]);
INI_Int("Admin",pStats[playerid][admin]);
return 1;
}
stock Path(playerid)
{
new str[128],name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(str,sizeof(str),UserPath,name);
return str;
}