07.01.2013, 18:57
(
Последний раз редактировалось Kittylol; 07.01.2013 в 19:30.
)
Hi,i have problem with register system.My problem is like i connect to server and register/login okay,i play and earn money and that money what i earn in next server restart or connect what i earned i have (-) all money.
I have like this i connect and earn 1332 than i reconnect and i have (-)1332.
I have like this i connect and earn 1332 than i reconnect and i have (-)1332.
pawn Код:
#include <a_samp>
#include <dini>
//Must login to spawn
// 1 = yes, 0 = no
new lspawn = 1;
new Logged[MAX_PLAYERS] = 0;
//Defines
#define COLOUR_GREEN 0x33AA33AA
#define COLOUR_RED 0xAA3333AA
#define COLOUR_YELLOW 0xFFFF00AA
#define COLOUR_LIGHTBLUE 0x33CCFFAA
#define COLOUR_ORANGE 0xFF9900AA
#define SKIN_POS 1958.3783, 1343.1572, 15.3746, 269.1425
//Dcmd, youl love dcmd...
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
//Hasher
adler32_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;
}
public OnFilterScriptInit()
{
//Credits
print("Simple Register / Login by Epic-Matrix");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], file[200];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), "\\users\\%s.ini", name);
dini_IntSet(file, "cash", GetPlayerMoney(playerid));
dini_IntSet(file, "score", GetPlayerScore(playerid));
Logged[playerid] = 0;
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
//Can't spawn if your not logged in or registered...
if(lspawn == 1 && Logged[playerid] == 0)
{
SendClientMessage(playerid, COLOUR_RED, "You must login or register to spawn!");
return 0;
}else{
return 1;
}
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(register, 8, cmdtext);
dcmd(login, 5, cmdtext);
return false;
}
//Register
dcmd_register(playerid, params[])
{
//Varibles
new name[MAX_PLAYER_NAME], file[200];
//Get there name
GetPlayerName(playerid, name, sizeof(name));
//Build the file name
format(file, sizeof(file), "\\users\\%s.ini", name);
//No registering if your logged in!
if(Logged[playerid] == 1) return SendClientMessage(playerid, COLOUR_RED, "You are already logged in!");
//Make shure there not registered!
if(dini_Exists(file)) return SendClientMessage(playerid, COLOUR_RED, "This name is already registered! Please login!");
//Can't forget a password!
else if(strlen(params) == 0) return SendClientMessage(playerid, COLOUR_RED, "You must enter a password to register!");
else
{
//Make there file
dini_Create(file);
//Store a encrypted copy of there password in it
dini_IntSet(file, "password", adler32_hash(params));
//Save there money
dini_IntSet(file, "cash", GetPlayerMoney(playerid));
//Save there score
dini_IntSet(file, "score", GetPlayerScore(playerid));
//Make them logged
Logged[playerid] = 1;
//Sucess
SendClientMessage(playerid, COLOUR_YELLOW, "Your now registered, and have been automaticly logged in!");
}
return 1;
}
//Login
dcmd_login(playerid, params[])
{
//Varibles
new name[MAX_PLAYER_NAME], file[200];
//Get there name
GetPlayerName(playerid, name, sizeof(name));
//Build there file name
format(file, sizeof(file), "\\users\\%s.ini", name);
//No /login abuse
if(Logged[playerid] == 1) return SendClientMessage(playerid, COLOUR_RED, "You are already logged in!");
//Make shure there registered!
if(!dini_Exists(file)) return SendClientMessage(playerid, COLOUR_RED, "This name isn't registered! Please register now!");
//Can't forget a password!
else if(strlen(params) == 0) return SendClientMessage(playerid, COLOUR_RED, "You must enter a password to login!");
//Hash there password so it can be compaired
else if(adler32_hash(params) != dini_Int(file, "password")) return SendClientMessage(playerid, COLOUR_RED, "Login failed!");
else
{
//Get there cash
GivePlayerMoney(playerid, GetPlayerMoney(playerid) - dini_Int(file, "cash"));
//Get there score
SetPlayerScore(playerid, dini_Int(file, "score"));
//Make them logged
Logged[playerid] = 1;
//Sucess
SendClientMessage(playerid, COLOUR_YELLOW, "You are now logged in, and your stats were automaticly loaded!");
}
return 1;
}