Login system - Simple help
#2

Download these files:
- http://dracoblue.net/download/dutils-110/30/
- http://dracoblue.net/download/dudb-24/31/
- http://dracoblue.net/download/dini-16/35/

and take the .inc files included in the download zipped file, drag and drop them to /pawno/includes/ folder in your San Andreas Multiplayer server directory.

At the top of your script:
pawn Код:
#include <dudb>
#include <dini>

new gPlayerLogged[MAX_PLAYERS];

#pragma tabsize 0
#pragma unused ret_memcpy

enum pInfo
{
    pAdminLevel,
    pKills,
    pDeaths,
    pCash,
    pScore,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Search for:
pawn Код:
OnPlayerDisconnect(playerid, reason)
Under it, add:
pawn Код:
new name[MAX_PLAYER_NAME], file[256], lastseen[64], i_dateTime[3];
    GetPlayerName(playerid, name, sizeof(name));
    getdate(i_dateTime[0], i_dateTime[1], i_dateTime[2]);
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if(gPlayerLogged[playerid] == 1)
    {
        dini_IntSet(file, "Score", GetPlayerScore(playerid));
        dini_IntSet(file, "Money", GetPlayerMoney(playerid));
        dini_IntSet(file, "AdminLevel", PlayerInfo[playerid][pAdminLevel]);
        dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills]);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths]);
    gPlayerLogged[playerid] = 0;
Search for:
pawn Код:
OnPlayerConnect(playerid)
Add under it:
pawn Код:
new name[MAX_PLAYER_NAME], file[256];
    GetPlayerName(playerid, name, sizeof(name));
    format(file, sizeof(file), SERVER_USER_FILE, name);
    if (!dini_Exists(file))
    {
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD,"Register","{FFFF00}Welcome to my server.\nPlease register your account by typing a password below.","Register","Quit");
    }
    if(fexist(file))
    {
        ShowPlayerDialog(playerid, 2, DIALOG_STYLE_PASSWORD,"Login","{FFFF00}Welcome back to my server.\nYour nickname is registered. Please enter your password below.","Login","Quit");
    }
Search for:
pawn Код:
OnPlayerDeath(playerid, killerid, reason)
Add under it:
pawn Код:
PlayerInfo[playerid][pDeaths] ++;
    PlayerInfo[killerid][pKills] ++;
Search for:
pawn Код:
if (dialogid == 1)
    {
   
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return Kick(playerid);
        dini_Create(file);
        dini_Set(file, "Password", inputtext);
        dini_IntSet(file, "Score", PlayerInfo[playerid][pScore] = 0);
        dini_IntSet(file, "Money", PlayerInfo[playerid][pCash] = 1000);
        dini_IntSet(file, "Kills", PlayerInfo[playerid][pKills] = 0);
        dini_IntSet(file, "Deaths", PlayerInfo[playerid][pDeaths] = 0);
        format(string, sizeof(string), "[SYSTEM] You succesfully registered your nickname with the password %s, you have been auto-logged in.", inputtext);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        gPlayerLogged[playerid] = 1;
    }
    if (dialogid == 2)
    {
        new name[MAX_PLAYER_NAME], file[256];
        GetPlayerName(playerid, name, sizeof(name));
        format(file, sizeof(file), SERVER_USER_FILE, name);
        if(!response) return Kick(playerid);
        if (!strlen(inputtext)) return Kick(playerid);
        if(strcmp(inputtext, dini_Get(file, "Password"), true) != 0)
        {
            SendClientMessage(playerid, COLOR_DARKRED, "[SYSTEM] You have inserted a wrong password.  In result, you have been kicked.");
            Kick(playerid);
        }
        else
        {
            PlayerInfo[playerid][pAdminLevel] = dini_Int(file, "AdminLevel");
            PlayerInfo[playerid][pKills] = dini_Int(file, "Kills");
            PlayerInfo[playerid][pDeaths] = dini_Int(file, "Deaths");
            PlayerInfo[playerid][pCash] = dini_Int(file, "Money");
         
            SetPlayerScore(playerid, dini_Int(file, "Score"));
            GivePlayerMoney(playerid, dini_Int(file, "Money"));

                format(string, sizeof(string), "[SYSTEM] You have successfully logged in.  Welcome back, %s!", name);
                SendClientMessage(playerid, COLOR_YELLOW, string);
            gPlayerLogged[playerid] = 1;
        }
    }
Credits:
- Lorenc_ (thread: here)
Reply


Messages In This Thread
Login system - Simple help - by MartinJ1 - 08.05.2012, 18:19
Re: Login system - Simple help - by Slix_ - 08.05.2012, 18:41
Re: Login system - Simple help - by MartinJ1 - 08.05.2012, 18:51
Re: Login system - Simple help - by Ballu Miaa - 08.05.2012, 19:09
Re: Login system - Simple help - by MartinJ1 - 08.05.2012, 19:12
Re: Login system - Simple help - by Ballu Miaa - 08.05.2012, 19:20
Re: Login system - Simple help - by MartinJ1 - 08.05.2012, 19:24
Re: Login system - Simple help - by MartinJ1 - 08.05.2012, 19:27
Re: Login system - Simple help - by MartinJ1 - 08.05.2012, 19:39
Re: Login system - Simple help - by Ballu Miaa - 09.05.2012, 01:38

Forum Jump:


Users browsing this thread: 2 Guest(s)