04.04.2016, 11:24
So, i made a register/login system, i requested so many help here but it turned out not well.
I need someone good at script to help me, when you register at this system then logging in again with the same password it causes a problem, it won't let you login even though your password is the same as you put in the dialog that you registered at.
Please guys help me, i'll +rep. And thanks to those who tried to help me.
PHP код:
// -------------------- = INCLUDES = -------------------- //
#include <a_samp>
#include <YSI\y_ini>
// -------------------- = COLOR DEFINES = -------------------- //
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_BLUE 0x0000BBAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIME 0x10F441AA
#define COLOR_MAGENTA 0xFF00FFFF
#define COLOR_NAVY 0x000080AA
#define COLOR_AQUA 0xF0F8FFAA
#define COLOR_CRIMSON 0xDC143CAA
#define COLOR_FLBLUE 0x6495EDAA
#define COLOR_BISQUE 0xFFE4C4AA
#define COLOR_BLACK 0x000000AA
#define COLOR_CHARTREUSE 0x7FFF00AA
#define COLOR_BROWN 0XA52A2AAA
#define COLOR_CORAL 0xFF7F50AA
#define COLOR_GOLD 0xB8860BAA
#define COLOR_GREENYELLOW 0xADFF2FAA
#define COLOR_INDIGO 0x4B00B0AA
#define COLOR_IVORY 0xFFFF82AA
#define COLOR_LAWNGREEN 0x7CFC00AA
#define COLOR_LIMEGREEN 0x32CD32AA //<--- Dark lime
#define COLOR_MIDNIGHTBLUE 0X191970AA
#define COLOR_MAROON 0x800000AA
#define COLOR_OLIVE 0x808000AA
#define COLOR_ORANGERED 0xFF4500AA
#define COLOR_PINK 0xFFC0CBAA // - Light light pink
#define COLOR_SEAGREEN 0x2E8B57AA
#define COLOR_SPRINGGREEN 0x00FF7FAA
#define COLOR_TOMATO 0xFF6347AA // - Tomato >:/ sounds wrong lol... well... :P
#define COLOR_YELLOWGREEN 0x9ACD32AA //- like military green
#define COLOR_MEDIUMAQUA 0x83BFBFAA
#define COLOR_MEDIUMMAGENTA 0x8B008BAA // dark magenta ^^
// -------------------- = COLOR DEFINES = -------------------- //
// -------------------- = REGISTER SYSTEM = -------------------- //
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
#define PATH "/Users/%s.ini"
#pragma tabsize 0
enum pInfo
{
pPass,
pCash,
pAdmin,
pKills,
pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
INI_Int("Password", PlayerInfo[playerid][pPass]);
INI_Int("Cash", PlayerInfo[playerid][pCash]);
INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
INI_Int("Kills", PlayerInfo[playerid][pKills]);
INI_Int("Deaths", PlayerInfo[playerid][pDeaths]);
return 1;
}
stock UserPath(playerid)
{
new String[128], playername[MAX_PLAYER_NAME];
GetPlayerName(playerid, playername, sizeof(playername));
format(String, sizeof(String), PATH, playername);
return String;
}
stock udb_hash(buf[])
{
new length=strlen(buf);
new s1 = 1;
new s2 = 0;
new n;
for (n=0; n<length; n++)
{
s1 = (s1 + buf[n]) % 65521;
s2 = (s2 + s1) % 65521;
}
return (s2 << 16) + s1;
}
main()
{
print("\n----------------------------------");
print(" LG:RP v.1 by Raisollah");
print("----------------------------------\n");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("LG:RP v.1");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login", "Type your password below.", "Login", "Cancel");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register", "Type your password below", "Register", "Cancel");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File, "Data");
INI_WriteInt(File, "Cash", GetPlayerMoney(playerid));
INI_WriteInt(File, "Admin", PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File, "Kills", PlayerInfo[playerid][pKills]);
INI_WriteInt(File, "Deaths", PlayerInfo[playerid][pDeaths]);
INI_Close(File);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
PlayerInfo[killerid][pKills]++;
PlayerInfo[playerid][pDeaths]++;
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, "Register", "You have entered an invalid password.\n Type your password below.", "Register", "Cancel");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"Data");
INI_WriteInt(File, "Password", udb_hash(inputtext));
INI_WriteInt(File, "Cash", 0);
INI_WriteInt(File, "Kills", 0);
INI_WriteInt(File, "Deaths", 0);
INI_Close(File);
SendClientMessage(playerid, COLOR_WHITE, "Well done, you have successfully registered.");
}
}
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response)
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
SendClientMessage(playerid, COLOR_WHITE, "You have successfully logged in.");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type your password below.", "Login", "Cancel");
}
}
}
}
return 1;
}