Suggestions
#3

'kk here:

/login and /register (all the data):

pawn Code:
new logged[MAX_PLAYERS];
enum pInfo
{
    AdminLevel,
    cash,
    score,
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME];
    new file[128];
    GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"/Users/%s.ini",name);
    if(!fexist(file))
    {
    SendClientMessage(playerid, COLOR_GREEN, "[SYSTEM]:You arent registered! type /register to save your stats!");
    logged[playerid] = 0;
    }
    if(fexist(file))
    {
    SendClientMessage(playerid, COLOR_GREEN, "[SYSTEM]:You are registered! type /login [pass]!!");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new file[128];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"/Users/%s.ini",name);
    if(dini_Exists(file))
    {
  dini_IntSet(file, "score", PlayerInfo[playerid][score]);
  dini_IntSet(file, "money", PlayerInfo[playerid][cash]);
  dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][AdminLevel]);
    }
    logged[playerid] = 0;
}

dcmd_register(playerid, params[])
{
  new file[128], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(file), "\\Users\\%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: /register [password]");
  if(dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: You are already registered!");
  dini_Create(file);
  dini_IntSet(file, "hashPW", udb_hash(params));
  dini_Set(file, "password", params);
  dini_IntSet(file, "AdminLevel",PlayerInfo[playerid][AdminLevel] = 0);
  dini_IntSet(file, "score", PlayerInfo[playerid][score] = 0);
  dini_IntSet(file, "money", PlayerInfo[playerid][cash] = 500);
  new string[128];
  format(string, 128, "[SYSTEM]: You succesfully registered the nickname %s with password %s", pname, params);
  SendClientMessage(playerid, COLOR_YELLOW, string);
  logged[playerid] = 1;
  SendClientMessage(playerid, COLOR_YELLOW, "[SYSTEM]: You have been automatically logged in!");
  return 1;
}

dcmd_login(playerid, params[])
{
  new file[128];
  new string[MAX_STRING], pname[MAX_PLAYER_NAME];
  GetPlayerName(playerid, pname, sizeof(pname));
  format(file, sizeof(file), "\\Users\\%s.ini", pname);
  if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: /login [password]");
  if(!dini_Exists(file)) return SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: You are not registered!");
  if(logged[playerid]) return SendClientMessage(playerid, COLOR_RED, "[SYSTEM]: You are already logged in!");
  new tmp;
  tmp = dini_Int(file, "hashPW");
  if(udb_hash(params) != tmp)
  {
    format(string, 256, "You specified the wrong password for %s!", pname);
    SendClientMessage(playerid, COLOR_RED, string);
  }
  else
  {
    logged[playerid] = 1;
    PlayerInfo[playerid][AdminLevel] = dini_Int(file, "AdminLevel");
    SetPlayerScore(playerid, PlayerInfo[playerid][score]);
    new lebel = PlayerInfo[playerid][AdminLevel];
    GivePlayerMoney(playerid, dini_Int(file, "money")-GetPlayerMoney(playerid));
    format(string, 256, "[SYSTEM]: Successfully logged in! (level: %d)!", lebel);
    SendClientMessage(playerid,COLOR_RED, string);
    printf("%s (%i) logged in with password %s", pname, playerid, params);
  }
  return 1;
}
Reply


Messages In This Thread
Suggestions - by Rivera - 14.03.2011, 14:17
Re: Suggestions - by XFlawless - 14.03.2011, 14:19
Re: Suggestions - by Rivera - 14.03.2011, 14:22
Re: Suggestions - by Rivera - 14.03.2011, 14:25
Re: Suggestions - by XFlawless - 14.03.2011, 14:25
Re: Suggestions - by Rivera - 14.03.2011, 14:27
Re: Suggestions - by XFlawless - 14.03.2011, 14:31
Re: Suggestions - by Rivera - 14.03.2011, 14:32

Forum Jump:


Users browsing this thread: 1 Guest(s)