10.01.2012, 16:40
Today I am learning how to use the y_ini to save player's statistics, but when I login, every password I enter it's correct. ****** told me to use tags with y_ini, but I don't know how. What should I do?
pawn Код:
#include <a_samp>
#include <YSI\y_ini>
#include <foreach>
#define PlayerFile "Admin_YSI/Users/%s.ini"
#define DIALOG_REGISTER 6050
#define DIALOG_LOGIN 6100
#define COLOR_GREEN 0x00FF00AA
#define COLOR_RED 0xFF0000AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_CYAN 0x96FFFFAA
#define COLOR_PURPLE 0x960096AA
#define COLOR_BLUE 0x0000FFAA
#define COLOR_ORANGE 0xFF9600AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_GREY 0xC8C8C8AA
native WP_Hash(buffer[], len, const str[]);
enum PLAYER_MAIN
{
PLAYER_REGISTERED,
PLAYER_LOGGED,
PLAYER_PASSWORD[129],
PLAYER_LEVEL,
PLAYER_SCORE,
PLAYER_MONEY,
PLAYER_KILLS,
PLAYER_DEATHS,
PLAYER_COLOR
}
new PlayerInfo[MAX_PLAYERS][PLAYER_MAIN];
new LoginAttempts[MAX_PLAYERS];
stock UserPath(playerid)
{
new string[128], PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), PlayerFile, PlayerName);
return string;
}
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
INI_String("Password", PlayerInfo[playerid][PLAYER_PASSWORD], 129);
INI_Int("Registered", PlayerInfo[playerid][PLAYER_REGISTERED]);
INI_Int("Logged", PlayerInfo[playerid][PLAYER_LOGGED]);
INI_Int("Level", PlayerInfo[playerid][PLAYER_LEVEL]);
INI_Int("Score", PlayerInfo[playerid][PLAYER_SCORE]);
INI_Int("Money", PlayerInfo[playerid][PLAYER_MONEY]);
INI_Int("Kills", PlayerInfo[playerid][PLAYER_KILLS]);
INI_Int("Deaths", PlayerInfo[playerid][PLAYER_DEATHS]);
INI_Int("Color", PlayerInfo[playerid][PLAYER_COLOR]);
return 1;
}
public OnFilterScriptInit()
{
return 1;
}
public OnFilterScriptExit()
{
foreach(Player, i) {
new INI:File = INI_Open(UserPath(i));
INI_SetTag(File, "Statistics");
INI_WriteInt(File, "Registered", PlayerInfo[i][PLAYER_REGISTERED]);
INI_WriteInt(File, "Level", PlayerInfo[i][PLAYER_LEVEL]);
INI_WriteInt(File, "Score", GetPlayerScore(i));
INI_WriteInt(File, "Money", GetPlayerMoney(i));
INI_WriteInt(File, "Kills", PlayerInfo[i][PLAYER_KILLS]);
INI_WriteInt(File, "Deaths", PlayerInfo[i][PLAYER_DEATHS]);
INI_WriteInt(File, "Color", GetPlayerColor(i));
INI_Close(File);
}
return 1;
}
public OnPlayerConnect(playerid)
{
PlayerInfo[playerid][PLAYER_REGISTERED] = 0;
PlayerInfo[playerid][PLAYER_LOGGED] = 0;
PlayerInfo[playerid][PLAYER_LEVEL] = 0;
PlayerInfo[playerid][PLAYER_COLOR] = 0;
PlayerInfo[playerid][PLAYER_SCORE] = 0;
PlayerInfo[playerid][PLAYER_MONEY] = 0;
PlayerInfo[playerid][PLAYER_KILLS] = 0;
PlayerInfo[playerid][PLAYER_DEATHS] = 0;
if(fexist(UserPath(playerid))) {
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "{FFFF00}Login", "Your account is registered.\nPlease enter the password to log in!", "Login", "Leave");
}
else {
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFF00}Register", "Your account is not registered. \nPlease register to continue!", "Register", "");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "Statistics");
INI_WriteInt(File, "Registered", 1);
INI_WriteInt(File, "Level", PlayerInfo[playerid][PLAYER_LEVEL]);
INI_WriteInt(File, "Score", GetPlayerScore(playerid));
INI_WriteInt(File, "Money", GetPlayerMoney(playerid));
INI_WriteInt(File, "Kills", PlayerInfo[playerid][PLAYER_KILLS]);
INI_WriteInt(File, "Deaths", PlayerInfo[playerid][PLAYER_DEATHS]);
INI_WriteInt(File, "Color", GetPlayerColor(playerid));
INI_Close(File);
PlayerInfo[playerid][PLAYER_LEVEL] = 0;
return 1;
}
public OnPlayerSpawn(playerid)
{
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SendDeathMessage(killerid, playerid, reason);
PlayerInfo[playerid][PLAYER_DEATHS]++;
if(killerid != INVALID_PLAYER_ID) {
PlayerInfo[killerid][PLAYER_KILLS]++;
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid) {
case DIALOG_REGISTER:
{
if(response) {
if(!strlen(inputtext)) return SendClientMessage(playerid, COLOR_RED, "You have entered an invalid password") && ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FFFF00}Register","{FFFFFF}Your account is not registered. \nPlease register to continue!", "Register", "");
new buf[129], string[128], PlayerName[MAX_PLAYER_NAME], Ip[16];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
GetPlayerIp(playerid, Ip, sizeof(Ip));
WP_Hash(buf, sizeof(buf), inputtext);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "Statistics");
INI_WriteString(File, "Name", PlayerName);
INI_WriteString(File, "Password", buf);
INI_WriteString(File, "IP", Ip);
INI_WriteInt(File, "Registered", 1);
INI_WriteInt(File, "Level", 0);
INI_WriteInt(File, "Score", 0);
INI_WriteInt(File, "Money", 0);
INI_WriteInt(File, "Kills", 0);
INI_WriteInt(File, "Deaths", 0);
INI_WriteInt(File, "Color", 0);
INI_Close(File);
format(string, sizeof(string), "You have successfully registered your account with the password \'%s\'. You have been automatically logged in.", inputtext);
SendClientMessage(playerid, COLOR_GREEN, string);
PlayerInfo[playerid][PLAYER_LOGGED] = 1;
PlayerInfo[playerid][PLAYER_REGISTERED] = 1;
}
}
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response) {
new buf[129];
WP_Hash(buf, sizeof(buf), inputtext);
if(!strcmp(buf, PlayerInfo[playerid][PLAYER_PASSWORD])) {
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
PlayerInfo[playerid][PLAYER_LOGGED] = 1;
PlayerInfo[playerid][PLAYER_REGISTERED] = 1;
SetPlayerScore(playerid, PlayerInfo[playerid][PLAYER_SCORE]);
GivePlayerMoney(playerid, PlayerInfo[playerid][PLAYER_MONEY]);
SetPlayerColor(playerid, PlayerInfo[playerid][PLAYER_COLOR]);
}
else {
if(LoginAttempts[playerid] < 2) {
SendClientMessage(playerid, COLOR_RED, "Incorrect password.");
LoginAttempts[playerid] ++;
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "{FFFFFF}Your account is registered.\nPlease enter the password to log in!", "Login", "Leave");
}
else {
SendClientMessage(playerid, COLOR_RED, "Incorrect password.");
LoginAttempts[playerid] = 0;
Kick(playerid);
}
}
}
}
}
return 0;
}