01.01.2010, 20:54
I need to someone that can make me automatic login.
pawn Код:
#include <a_samp>
#include <dutils>
#include <dudb>
#include <dini>
#include <core>
#include <float>
////////////////////////////////////////////////////////////////////////////////
#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
////////////////////////////////////////////////////////////////////////////////
forward UpdateStats();
forward OnPlayerRegister(playerid);
forward OnPlayerLogin(playerid);
////////////////////////////////////////////////////////////////////////////////
enum player_account_info
{
logged,
name[MAX_PLAYER_NAME],
money,
score,
perfect,
level,
}
new pInfo[MAX_PLAYERS][player_account_info];
new Kills[MAX_PLAYERS];
////////////////////////////////////////////////////////////////////////////////
public OnPlayerConnect(playerid)
{
pInfo[playerid][logged] = 0;
pInfo[playerid][level] = 0;
pInfo[playerid][money] = 0;
pInfo[playerid][score] = 0;
pInfo[playerid][perfect] = 0;
GetPlayerName(playerid,pInfo[playerid][name],128);
}
////////////////////////////////////////////////////////////////////////////////
public OnPlayerDisconnect(playerid, reason)
{
pInfo[playerid][logged] = 0;
pInfo[playerid][level] = 0;
pInfo[playerid][money] = 0;
pInfo[playerid][score] = 0;
pInfo[playerid][perfect] = 0;
}
////////////////////////////////////////////////////////////////////////////////
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(login,5,cmdtext);
dcmd(REGISTER,8,cmdtext);
////////////////////////////////////////////////////////////////////////////////
dcmd_login(playerid,params[])
{
new string[265];
new tmp[265];
if(pInfo[playerid][logged] == 1)return SendMsg(playerid, 5000, "~r~Information: ~w~You are already ~r~logged~w~ in!");
if(!strlen(params))return SendMsg(playerid, 5000, "~b~USAGE: ~w~/login [password]");
if (dini_Exists(udb_encode(pInfo[playerid][name])))
{
tmp = dini_Get(udb_encode(pInfo[playerid][name]), "password");
if (udb_hash(params) != strval(tmp))
{
SendMsg(playerid, 5000, "~r~Information: ~w~Wrong password!");
}
else
{
OnPlayerLogin(playerid);
}
}
else
{
format(string, sizeof(string), "The Account %s does not exist in our Database yet, use /register password to register it!", pInfo[playerid][name]);
SendMsg(playerid, 5000, string);
}
return 1;
}
dcmd_REGISTER(playerid,params[])
{
new string[128];
if(pInfo[playerid][logged] == 1)return SendMsg(playerid, 5000, "~r~Information: ~w~You are already logged in");
if(!strlen(params))return SendMsg(playerid, 5000, "~r~Information:~w~ Use /register password");
if (!dini_Exists(udb_encode(pInfo[playerid][name])))
{
format(string, sizeof(string), "The Account %s has been Succesfully registered! You have been automaticly logged in - Password: %s]", pInfo[playerid][name], params);
SendClientMessage(playerid, COLOR_NOTICE, string);
dini_Create(udb_encode(pInfo[playerid][name]));
dini_IntSet(udb_encode(pInfo[playerid][name]), "password", udb_hash(params));
OnPlayerRegister(playerid);
OnPlayerLogin(playerid);
}
else
{
format(string, sizeof(string), "~r~Information: ~w~%s is already registered!", pInfo[playerid][name]);
SendMsg(playerid, 5000, string);
}
return 1;
}
public OnPlayerLogin(playerid)
{
new string[265];
pInfo[playerid][logged] = 1;
pInfo[playerid][money] = dini_Int(udb_encode(pInfo[playerid][name]), "money");
pInfo[playerid][score] = dini_Int(udb_encode(pInfo[playerid][name]), "score");
pInfo[playerid][level] = dini_Int(udb_encode(pInfo[playerid][name]), "level");
pInfo[playerid][perfect] = dini_Int(udb_encode(pInfo[playerid][name]), "perfect");
format(string, sizeof(string), "~r~Information: ~w~your now logged in! [~r~Score: ~w~%d] [~r~Admin Level: ~w~%d] [~r~Premium Member:~w~ %d] [~r~Money: ~w~%d]", pInfo[playerid][score], pInfo[playerid][level], pInfo[playerid][perfect], pInfo[playerid][money]);
SendMsg(playerid, 5000, string);
GivePlayerMoney(playerid,pInfo[playerid][money]);
SetPlayerScore(playerid,pInfo[playerid][score]+GetPlayerScore(playerid));
}
////////////////////////////////////////////////////////////////////////////////
public OnPlayerRegister(playerid)
{
dini_IntSet(udb_encode(pInfo[playerid][name]), "money", pInfo[playerid][money]);
dini_IntSet(udb_encode(pInfo[playerid][name]), "score", pInfo[playerid][score]);
dini_IntSet(udb_encode(pInfo[playerid][name]), "level", 0);
dini_IntSet(udb_encode(pInfo[playerid][name]), "perfect", 0);
}
////////////////////////////////////////////////////////////////////////////////
public UpdateStats()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
pInfo[i][money] = GetPlayerMoney(i);
pInfo[i][score] = GetPlayerScore(i);
if(pInfo[i][logged] == 1)
{
dini_IntSet(udb_encode(pInfo[i][name]), "perfect", pInfo[i][perfect]);
dini_IntSet(udb_encode(pInfo[i][name]), "money", pInfo[i][money]);
dini_IntSet(udb_encode(pInfo[i][name]), "score", pInfo[i][score]);
dini_IntSet(udb_encode(pInfo[i][name]), "level", pInfo[i][level]);
}
}
}