[TuT] Y_INI Reg/Log u dialogu

Započeo izgubljen u vremenu, Decembar 05, 2011, 13:58:00 POSLE PODNE

prethodna tema - sledeća tema

0 članova i 2 gostiju pregledaju ovu temu.

Dialog Login and Register System - Dialogs - Using Y_INI

Y_INI Download y_INI ----> http://forum.sa-mp.com/showthread.php?t=175565.


Trebate imati Y_INI

#include <YSI\y_ini>



Definiramo dialoge

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4


Definiramo put do accova


#define PATH "/Users/%s.ini"

Boje


#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"

Za varijable cemo koristiti enumatore


enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths
}
new PlayerInfo[MAX_PLAYERS][pInfo];




Citanje INI podataka

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}




Znaci stock za vec definirani user path
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}

Ovo je put do accova


Hash za password

/*Credits to Dracoblue*/
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;
}

Zahvala : Dracoblue


Sada radimo Reg/Log u dialogu kada se igrac spoji na server
public OnPlayerConnect(playerid)
{
    if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Upisite svoj password da se ulogirate.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registracija u toku.",""COL_WHITE"Upisite password da se registrirate.","Register","Quit");
    }
    return 1;
}


Registracija i login u dialogu :

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, ""COL_WHITE"Registracija u toku",""COL_RED"Niste upisali tocan password.\n"COL_WHITE"Upisite password da se registrirate.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Uspjsno si se registrirao ! Napravi relog da ti se sacuvaju statsi","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Uspjeh!",""COL_GREEN"Uspjesno ste se ulogirali!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"Niste upisali tocan password.\n"COL_WHITE"Upisite svoj pasword.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}[code]





Sada cemo napraviti save-anje variabla nakon izlaska iz igre
[code]public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}


Sada cemo napraviti dodavanje killova i deathova nakon smrti


public OnPlayerDeath(playerid, killerid, reason)
{
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}


Downloads:
Y_INI - http://forum.sa-mp.com/showthread.php?t=175565
Pastebin - http://pastebin.com/r4htbbcJ



Credits:
Kush - Kreacija tutoriala
Y_Less - Y_INI.
Dracoblue - udb_hash
Izvor : http://forum.sa-mp.com/showthread.php?p=1320057#post1320057[/code][/code]
Poslednja Izmena: April 17, 2012, 14:34:59 POSLE PODNE od joXy_

Mogao si objasniti svaku funkciju a ne ovako kopirati i za sve napisati 2,3 riječi.
"I'm a loser and a user so I don't need no accuser" - Billie Joe Armstrong

Izvinite sto bumpam stariju temu ali imam pitanje...

Znaci ja koristim ovaj sistem za login i register ...

Napravio sam komandu /makeadmin

Ali mi se admin ne sacuva, tacnije uopste ne stigne da promeni level, npr u .ini file-u sam sebi namestim adm lv 1 i kada ovom komandom pokusam da promenim level on ostane isti...

Moze pomoc?


CMD:makeadmin(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new string[128], ID, level;
new pname[128];
GetPlayerName(ID, pname, sizeof(pname));
if(sscanf(params, "us[128]", ID, level)) return Scm(playerid, "/makeadmin [id] [level]");
else if(ID == INVALID_PLAYER_ID) return Scm(playerid, "Krivi ID");
else
{
    PlayerInfo[playerid][pAdmin] = level;
    format(string, sizeof(string), "Dali ste igracu %s admin level %d", pname, level);
Scm(playerid, string);
return 1;
}
}
return 1;
}

Mr.Gagi

Ne mozes koristiti string-ovan text za integer varijablu ovako ide i ovde: PlayerInfo[ID][pAdmin] ti ide ID, a ne playerid
CMD:makeadmin(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new string[128], ID, level;
new pname[128];
if(sscanf(params, "ui", ID, level)) return Scm(playerid, "/makeadmin [id] [level]");
GetPlayerName(ID, pname, sizeof(pname));
else if(ID == INVALID_PLAYER_ID) return Scm(playerid, "Krivi ID");
    PlayerInfo[ID][pAdmin] = level;
    format(string, sizeof(string), "Dali ste igracu %s admin level %d", pname, level);
Scm(playerid, string);
return 1;
}
return 1;
}

Ubacim to sto si mi dao, stavim si adm level 1338, odem relog sjebe mi se pass, regam nov acc na njemu sam admin 1338 :S

Mr.Gagi

Citat: dock poslato Januar 12, 2012, 16:18:11 POSLE PODNE
Ubacim to sto si mi dao, stavim si adm level 1338, odem relog sjebe mi se pass, regam nov acc na njemu sam admin 1338 :S
Za ovo kada regas nov acc i stavi ti admina 1338 je samo do tog sto ne resetujes varijable na OnPlayerConnect
Znaci pod public OnPlayerConnect stavis
PlayerInfo[playerid][pAdmin] = 0;
A za pass sto ti sjebe nz jer nemas nigde sto bi ga moglo sjebati


CMD:makeadmin(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new string[128], ID, level;
new pname[128];
GetPlayerName(ID, pname, sizeof(pname));
if(sscanf(params, "ui", ID, level)) return Scm(playerid, "KORISTI: /makeadmin [id] [level]");
else if(ID == INVALID_PLAYER_ID) return Scm(playerid, "Krivi ID");
    PlayerInfo[ID][pAdmin] = level;
    format(string, sizeof(string), "Dali ste igracu %s admin level %d", pname, level);
Scm(playerid, string);
return 1;
}
return 1;
}


Evo resio sam problem sa passom al opet nov problem, sada mi za ovu komandu izlazi kada pokusam sebi da dam admina pise KRIVI ID.. :/

Pokusao sam na SAMP forumu naci resenje, oni kazu da update-am plugin ali ja sam skinuo najnoviji i idalje nece...

Pokusavam radit u ZCMDu a nikad pre nisam i sad se kocim ko najveci nub :P


Nece ni jedan ni drugi, oba sam pokusao opet isto...

Postoji li neka mogucnost da mi posaljes ti svoj plugin i pawno folder? :)