24.03.2018, 20:08
PHP код:
#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
// DEFINES
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define PATH "/Akauntovi.%s.ini"
#pragma tabsize 0
enum pInfo
{
pSifra,
pNovac,
pAdmin,
pScore,
pBankanovac,
pBanovan
}
new PlayerInfo[MAX_PLAYERS][pInfo];
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Lozinka",PlayerInfo[playerid][pSifra]);
INI_Int("Novac",PlayerInfo[playerid][pNovac]);
INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
INI_Int("Score",PlayerInfo[playerid][pScore]);
INI_Int("Bankanovac",PlayerInfo[playerid][pBankanovac]);
INI_Int("Banovan",PlayerInfo[playerid][pBanovan]);
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("<==============================>");
print(" MOD OD 0 ");
print(" BY ME. ");
print("<==============================>");
}
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("MJR v1.0.0");
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:","Molimo unesite vaљu lozinku!","Login","Napusti");
}
else
{
ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,"Register:","Molimo da se registrujete na server!\nUnesite lozinku koju ћelite koristiti na serveru!","Register","Napusti");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Novac",GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Score",GetPlayerScore(playerid));
INI_WriteInt(File,"Bankanovac",PlayerInfo[playerid][pBankanovac]);
INI_WriteInt(File,"Banovan",PlayerInfo[playerid][pBanovan]);
INI_Close(File);
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:","Lozinka koju ste unijeli nije validna!\nMolimo unesite novu!","Register","Napusti");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Lozinka",udb_hash(inputtext));
INI_WriteInt(File,"Novac",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"Score",0);
INI_WriteInt(File,"Bankanovac",0);
INI_WriteInt(File,"Banovan",0);
INI_Close(File);
}
}
case DIALOG_LOGIN:
{
if(!response) return Kick(playerid);
if(response)
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pSifra])
{
INI_ParseFile(UserPath(playerid),"LoadUser_%s",.bExtra = true,.extra = playerid);
GivePlayerMoney(playerid,PlayerInfo[playerid][pNovac]);
SetPlayerScore(playerid,PlayerInfo[playerid][pScore]);
SendClientMessage(playerid,-1,"Uspjesno si se ulogovao u svoj korisnicki racun!");
}
else
{
ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,"Login:","Lozinka koju ste unijeli nije tačna,pokuљajte ponovo!","Login","Napusti");
}
}
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}