26.07.2011, 19:16
pawn Код:
#include <a_samp>
#include <YSI/y_ini>
#pragma tabsize 0
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"
#define COL_ORANGE "{FFAF00}"
#define COL_BLUE "{0025E1}"
#define COL_PURPLE "{FF00FF}"
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define PATH "/Users/%s.ini"
enum pInfo
{
pPass,
pAdmin
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password",PlayerInfo[playerid][pPass]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
return 1;
}
stock UserPath(playerid)
{
new string[128],name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
format(string,sizeof(string),PATH,name);
return string;
}
main()
{
print("\n=====================================");
print("OK");
print("=====================================\n");
}
public OnPlayerConnect(playerid)
{
gPlayerLogged[playerid] = 0;
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(gPlayerLogged[playerid] == 1)
{
new INI:iFile = INI_Open(UserPath(playerid));
INI_SetTag(iFile,"data");
INI_Close(iFile);
}
gPlayerLogged[playerid] = 0;
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if (response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:iFile = INI_Open(UserPath(playerid));
INI_WriteString(iFile,"Password", inputtext);
INI_Close(iFile);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
}
}
case DIALOG_LOGIN:
{
if (!response) return Kick(playerid);
if (response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""COL_WHITE"Login",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
if(strcmp(PlayerInfo[playerid][pPass], inputtext, true))
{
SendClientMessage(playerid, COL_WHITE, "GOOD!");
}
else
{
SendClientMessage(playerid, COL_RED, "BAD!");
}
}
}
}
return 1;
}
First time using y_ini and everything works, but it's my Login reponse dialog. If I go in-game, type the 'correct' password, I receive the 'BAD!' message. I was thinking that maybe it isn't searching for the file properly, or it could just be my incorrect usage of strcmp. But it looks fine (in my opinion :S) and everything should work.