02.01.2012, 16:15
Ok, the problem is that even AFTER I have registered an account, when I return to the server, it show's the dialog "Register". I'm doing something wrong somewhere and it's probably an easy fix. Could on of you help please?
Here's the code.
Thank's in advance.
Here's the code.
pawn Код:
/*
____ ______ ____ ___ __ __
/\ _`\ /\ _ \ /\ _`\ /\_ \ __ /\ \ /\ \__
\ \,\L\_\ \ \L\ \ \ \ \L\_\//\ \ /\_\ __\ \ \___\ \ ,_\
\/_\__ \\ \ __ \ \ \ _\/ \ \ \ \/\ \ /'_ `\ \ _ `\ \ \/
/\ \L\ \ \ \/\ \ \ \ \/ \_\ \_\ \ \/\ \L\ \ \ \ \ \ \ \_
\ `\____\ \_\ \_\ \ \_\ /\____\\ \_\ \____ \ \_\ \_\ \__\
\/_____/\/_/\/_/ \/_/ \/____/ \/_/\/___L\ \/_/\/_/\/__/
/\____/
\_/__/
____ ___ __
/\ _`\ /\_ \ /\ \
\ \ \/\_\//\ \ __ __\ \ \____
\ \ \/_/_\ \ \ /\ \/\ \\ \ '__`\
\ \ \L\ \\_\ \_\ \ \_\ \\ \ \L\ \
\ \____//\____\\ \____/ \ \_,__/
\/___/ \/____/ \/___/ \/___/
*/
//-------------------------------------------//
// Includes
//-------------------------------------------//
//////////////////////////////////////////////
#include <a_samp>
#include <fixes>
//////////////////////////////////////////////
#include <sscanf2>
#include <foreach>
#include <zcmd>
#include <streamer>
#include <AdvancedBan>
#include <Double-O-Files2>
//////////////////////////////////////////////
//-------------------------------------------//
// Defines
//-------------------------------------------//
//////////////////////////////////////////////
#define COLOR_GREEN 0x80FF00FF
#define COLOR_ORANGE 0xFF8000FF
#define COLOR_BLUE 0x00FFFFFF
#define COLOR_RED 0xFF0000FF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_ACCOUNT 0x00FFFFFF //Blue
#define COLOR_ADMIN 0xFFFF00FF //Yellow
#define COLOR_VEHICLE 0xFF00FFFF //Pink
#define COLOR_ANNOUNCEMENT 0x0080C0FF //Dark Blue
#define COLOR_RADIO 0xAFAFAFFF //Grey
//////////////////////////////////////////////
#define RegisterDialog 5
#define LoginDialog 10
//////////////////////////////////////////////
#define UserFile "Database/Users/%s.ini"
//////////////////////////////////////////////
#define GameVersion "Indev v1.0"
//////////////////////////////////////////////
native WP_Hash(buffer[], len, const str[]);
//////////////////////////////////////////////
enum pData
{
PlayerName[MAX_PLAYER_NAME],
Password[200],
Score,
Cash,
AdminLevel,
bool:VIP,
bool:Jailed,
bool:Muted,
bool:Frozen,
}
new PlayerData[MAX_PLAYERS][pData];
//////////////////////////////////////////////
//-------------------------------------------//
// Main entry of script
//-------------------------------------------//
main()
{
}
//-------------------------------------------//
// OnGameModeInit
//-------------------------------------------//
public OnGameModeInit()
{
//////////////////////////////////////////////
print("+-+-+ +-+-+-+-+-+-+ +-+-+-+-+");
print("|S|A| |F|l|i|g|h|t| |C|l|u|b|");
print("+-+-+ +-+-+-+-+-+-+ +-+-+-+-+");
printf("San Andreas Flight Club - Version: %s - has loaded!", GameVersion);
//////////////////////////////////////////////
return 1;
}
//-------------------------------------------//
// OnGameModeExit
//-------------------------------------------//
public OnGameModeExit()
{
//////////////////////////////////////////////
print("+-+-+ +-+-+-+-+-+-+ +-+-+-+-+");
print("|S|A| |F|l|i|g|h|t| |C|l|u|b|");
print("+-+-+ +-+-+-+-+-+-+ +-+-+-+-+");
printf("San Andreas Flight Club - Version: %s - has unloaded!", GameVersion);
//////////////////////////////////////////////
DOF2_Exit();
//////////////////////////////////////////////
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
return 1;
}
public OnPlayerConnect(playerid)
{
//////////////////////////////////////////////
new Name[MAX_PLAYER_NAME], File[256];
GetPlayerName(playerid, Name, sizeof(Name));
format(File, sizeof(File), UserFile, Name);
//////////////////////////////////////////////
if(DOF2_FileExists(UserFile))
{
//////////////////////////////////////////////
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Login", "Enter your password below:", "Login", "Cancel");
//////////////////////////////////////////////
}
else if(!DOF2_FileExists(UserFile))
{
//////////////////////////////////////////////
ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Register", "Enter a password below to register:", "Register", "Cancel");
//////////////////////////////////////////////
}
//////////////////////////////////////////////
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//Stat saving will be added here, hasn't been made yet.
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
//////////////////////////////////////////////
if(dialogid == RegisterDialog)
{
//////////////////////////////////////////////
if(!response)
{
//////////////////////////////////////////////
Kick(playerid);
//////////////////////////////////////////////
}
//////////////////////////////////////////////
else if(!strlen(inputtext))
{
//////////////////////////////////////////////
SendError(playerid, "You must input a password!");
ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_PASSWORD, "Register", "Enter a password below to register:", "Register", "Cancel");
//////////////////////////////////////////////
}
//////////////////////////////////////////////
else
{
//////////////////////////////////////////////
new Name[MAX_PLAYER_NAME], File[256], WelcomeMessage[128], PasswordBuf[200];
GetPlayerName(playerid, Name, sizeof(Name));
format(File, sizeof(File), UserFile, Name);
WP_Hash(PasswordBuf, sizeof(PasswordBuf), inputtext);
//////////////////////////////////////////////
DOF2_CreateFile(File);
DOF2_SetString(File, "Name", Name);
DOF2_SetString(File, "Password", PasswordBuf);
DOF2_SetInt(File, "Score", 0);
DOF2_SetInt(File, "Cash", 0);
DOF2_SetInt(File, "AdminLevel", 0);
DOF2_SetBool(File, "VIP", false);
DOF2_SetBool(File, "Jailed", false);
DOF2_SetBool(File, "Muted", false);
DOF2_SetBool(File, "Frozen", false);
DOF2_SaveFile();
//////////////////////////////////////////////
printf("[ACCOUNT]: %s(Id:%i) has just created an account!", Name, playerid);
SendClientMessage(playerid, COLOR_ACCOUNT, "[ACCOUNT]:{FFFFFF} You have just sucsessfully made an account!");
//////////////////////////////////////////////
format(WelcomeMessage, sizeof(WelcomeMessage), "[JOIN]:{FFFFFF} %s(Id:%i) has joined the server for the first time!", Name, playerid);
SendClientMessageToAll(COLOR_ORANGE, WelcomeMessage);
//////////////////////////////////////////////
}
//////////////////////////////////////////////
}
//////////////////////////////////////////////
if(dialogid == LoginDialog)
{
//////////////////////////////////////////////
if(!response)
{
//////////////////////////////////////////////
Kick(playerid);
//////////////////////////////////////////////
}
//////////////////////////////////////////////
else if(!strlen(inputtext))
{
//////////////////////////////////////////////
SendError(playerid, "You must input a password!");
ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_PASSWORD, "Login", "Enter your password below:", "Login", "Cancel");
//////////////////////////////////////////////
}
//////////////////////////////////////////////
else
{
//////////////////////////////////////////////
new Name[MAX_PLAYER_NAME], File[256], PasswordBuf[200], PassFromFile[200];
GetPlayerName(playerid, Name, sizeof(Name));
format(File, sizeof(File), UserFile, Name);
DOF2_GetStringEx(File, "Password", PassFromFile, sizeof(PassFromFile));
WP_Hash(PasswordBuf, sizeof(PasswordBuf), inputtext);
//////////////////////////////////////////////
if(!strcmp(PasswordBuf, PassFromFile, false))
{
//////////////////////////////////////////////
SetPlayerScore(playerid, DOF2_GetInt(File, "Score"));
SetPlayerMoney(playerid, DOF2_GetInt(File, "Cash"));
PlayerData[playerid][AdminLevel] = DOF2_GetInt(File, "AdminLevel");
PlayerData[playerid][VIP] = DOF2_GetBool(File, "VIP");
PlayerData[playerid][Jailed] = DOF2_GetBool(File, "Jailed");
PlayerData[playerid][Muted] = DOF2_GetBool(File, "Muted");
PlayerData[playerid][Frozen] = DOF2_GetBool(File, "Frozen");
//////////////////////////////////////////////
}
//////////////////////////////////////////////
else
{
//////////////////////////////////////////////
SendError(playerid, "Incorrect password!");
Kick(playerid);
//////////////////////////////////////////////
}
//////////////////////////////////////////////
}
//////////////////////////////////////////////
}
//////////////////////////////////////////////
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
//-------------------------------------------//
// Added Functions
//-------------------------------------------//
//SendError
stock SendError(playerid, error[])
{
new Msg[128];
format(Msg, sizeof(Msg), "Error:{FFFFFF} %s", error);
SendClientMessage(playerid, COLOR_RED, Msg);
return 1;
}
//SendUsage
stock SendUsage(playerid, usage[])
{
new Msg[128];
format(Msg, sizeof(Msg), "Usage:{FFFFFF} %s", usage);
SendClientMessage(playerid, COLOR_BLUE, Msg);
return 1;
}
//SetPlayerCash
stock SetPlayerMoney(playerid, cash)
{
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, cash);
return 1;
}