Jump to content
  • 0

pomoc registrácia


RoBiK

Dotaz

Čaute, neviete aky je problem v tejto registrácii ? :) Errory nehádže, prídem na server(localhost) registrujem sa, dám heslo, napíše niečo že ini funguje správne alebo tak, napíše aj že relog a uložia sa mi stats, dám relog a idem sa lognut, dam heslo a ze nespravne

kukam sa tam kde to ma ukladat(scriptfiles/Users/nick.ini) a nič tam nieje napísane. KOD

 

 

#include <a_samp>
#include <YSI\y_ini>
#include <dini>

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

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

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

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

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;
}

stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}

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

main()
{
}

public OnGameModeInit()
{
        SetGameModeText("Freeroam");
return 1;
}

public OnPlayerConnect(playerid)
{
SetPlayerPos(playerid, 836.3251, -2065.5061, 14.5936);
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"Type your password below to login.","Login","Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
}
return 1;
}

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;
}

public OnPlayerSpawn(playerid)
{
return 1;
}

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

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"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","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);

SetPlayerPos(playerid, 836.3251, -2065.5061, 14.5936);
SpawnPlayer(playerid);
ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","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]);
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
}
return 1;
}
}
}
return 1;
}

 

 

predom diky :)

Edited by RoBiK
Link to comment
Share on other sites

13 odpovědí na tuto otázku

Recommended Posts

  • 0

presne ako je napísané v prvej odpovedi...

 

ukladáš to heslo ako integer...musíš ho ukladať ako string :) napr cez format

 

udb_hash vracia integer, nie string...

 

-------------------------------------------

 

ako povedal Wallet, musíš niekde načítať PlayerInfo[playerid][pPass]

INI_Int("Password",PlayerInfo[playerid][pPass]); // do publicu OnPlayerConnect

Link to comment
Share on other sites

  • 0

zkus toto dát do OnConnect

INI_Int("Password",PlayerInfo[playerid][pPass]);

 

 

presne ako je napísané v prvej odpovedi...

 

INI_Int("Password",PlayerInfo[playerid][pPass]); // do publicu OnPlayerConnect

~> Ne, ne a ne. y_ini, má funkci na načítáni údajů ze souboru. Údaje, které má načíst se musí vepisovat do callbacku s parametry, který se pak vyvolá přes tu fci, jinak vám to hodí chyby, že nezná name a value.

Link to comment
Share on other sites

  • 0

 

 

 

~> Ne, ne a ne. y_ini, má funkci na načítáni údajů ze souboru. Údaje, které má načíst se musí vepisovat do callbacku s parametry, který se pak vyvolá přes tu fci, jinak vám to hodí chyby, že nezná name a value.

Ne, ne a ne. pokud nemá IQ zmrznuté makrely. tak by nato došel sám... pokud né tak at nedělá s y_ini... btw když už je tu debata otomhle jaké má výhody oproti dof2? 

Link to comment
Share on other sites

  • 0

btw když už je tu debata otomhle jaké má výhody oproti dof2?

~> Rychlost, efektivnost, přehlednost a více možností.

Link to comment
Share on other sites

  • 0

~> Rychlost, efektivnost, přehlednost a více možností.

y_ini je o kolik přesněji ? :) mám zato že u dof2 trvá zápis tak 10 ms? a read snad taky 10ms.. + těch více možností povídej bud konkrétní.

Link to comment
Share on other sites

  • 0

takže stiahol som si inu a tu som sa nedostal ani na server

 

 

 

//=========================Login & Register system==============================
//=========================Login & Register system by Navroopsingh==============
//=========================Please Do not remove the Credits=====================
 
#include <a_samp>
#pragma tabsize 0
#include <YSI\y_ini>
#define dregister 2011 //Defining register dialog so it won't mixed up with other dialog
#define dlogin 2012 //Defining login dialog so it won't mixed up with other dialog
#define UserPath "Users/%s.ini" //Will define user account path. In this case, will store in Scriptfiles/Users. So create a file inside of your Scriptfiles folder called Users
native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes
 
//JOB
#define NEZAMESTNANY 0
#define POLICIE 1
#define AUTOBUS 2
#define ZAVOD 3
 
new Pracuje[MAX_PLAYERS];
 
new Text:JobA;
new Text:JobAs;
forward JobAss(playerid);
 
forward UkoncitPracovnuDobu(playerid);
forward LeaveJ(playerid);
new Text:Leave;
//
 
enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo]; //This will create a new variable so we can later use it to saving/loading user's info.
 
stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}
 
main()
{
print("main");
}
 
public OnGameModeInit()
{       //
SetGameModeText("Freeroam");
//textdraw
JobA = TextDrawCreate(30 ,184,"~b~Stlacenim + zapnes~n~~b~misiu autobusara.");
TextDrawFont(JobA , 1);
TextDrawLetterSize(JobA , 0.4, 2.8000000000000003);
TextDrawUseBox(JobA, 1);
    TextDrawAlignment(JobA,1);
 
Leave = TextDrawCreate(236 ,417 , "~r~Odisiel si z vozidla.");
    //-car
    CreateVehicle(431, 815.3325, -1754.4459, 13.5994, 179.4862, -1, -1, 100);
    CreateVehicle(411, 849.0712, -1763.6434, 13.2545, 269.3997, -1, -1, 100);
    print("OnGameModInit");
        return 1;
}
 
public OnGameModeExit()
{
print("GameExit");
        return 1;
}
 
forward loadaccount_user(playerid, name[], value[]); //forwarding a new function to load user's data
//Now we will use our own function that we have created above
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length or hashed user's password. Whirlpool will hash 128 characters + NULL*/
    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}
 
 
 
public OnPlayerRequestClass(playerid, classid)
{
        SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
        SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
        SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
        return 1;
}
 
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_user", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
                return 1;
        }
        return 1;
}
 
public OnPlayerDisconnect(playerid, reason)
{
        //Same as OnDialogResponse, we will save their stats inside of their user's account
        if(fexist(Path(playerid)))//Will check if the file is exit or not inside of User's folder that we have created.
        {
                new INI:file = INI_Open(Path(playerid)); //will open their their file
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
                INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
                INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
                INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his score inside of his account
                INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//As explained above
                INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
                INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
                INI_Close(file);//Now after we've done saving their data, we now need to close the file
                return 1;
        }
        return 1;
}
 
public OnPlayerSpawn(playerid)
{
        return 1;
}
 
public OnPlayerDeath(playerid, killerid, reason)
{
        pInfo[killerid][Kills]++;//Will give 1 score to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 deaths each time they die and it will be saved inside of his/her account
        return 1;
}
 
public OnVehicleSpawn(vehicleid)
{
        return 1;
}
 
public OnVehicleDeath(vehicleid, killerid)
{
        return 1;
}
 
public OnPlayerText(playerid, text[])
{
        return 1;
}
 
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(IsPlayerInVehicle(playerid,431))
{
    TextDrawShowForPlayer(playerid,JobA);
}
        return 1;
}
 
public OnPlayerExitVehicle(playerid, vehicleid)
{
if(Pracuje[playerid] == 2)
{
Pracuje[playerid]=0;
TextDrawShowForPlayer(playerid,Leave);
SetTimer("LeaveJ",4000,false);
}
        return 1;
}
 
public OnPlayerCommandText(playerid, cmdtext[])
{
        if (strcmp("/kill", cmdtext, true, 10) == 0)
        {
                SetPlayerHealth(playerid,0);
                SetPlayerArmour(playerid,0);
                return 1;
        }
        return 0;
}
 
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_SUBMISSION)
{
if (IsPlayerInAnyVehicle(playerid))
{
if (IsPlayerInVehicle(playerid,431))
{
TextDrawHideForPlayer(playerid,JobA);
JobAs = TextDrawCreate(30 ,184,"~b~Spustil si misiu.~n~~b~Chod na checkpointy.");
TextDrawUseBox(JobAs, 1);
    TextDrawAlignment(JobAs,1);
    TextDrawShowForPlayer(playerid,JobAs);
Pracuje[playerid]=2;
SetTimer("JobAss",4000,false);
}
}
}
        return 1;
}
 
public OnPlayerStateChange(playerid, newstate, oldstate)
{
        return 1;
}
 
public OnPlayerEnterCheckpoint(playerid)
{
        return 1;
}
 
public OnPlayerLeaveCheckpoint(playerid)
{
        return 1;
}
 
public OnPlayerEnterRaceCheckpoint(playerid)
{
        return 1;
}
 
public OnPlayerLeaveRaceCheckpoint(playerid)
{
        return 1;
}
 
public OnRconCommand(cmd[])
{
        return 1;
}
 
public OnPlayerRequestSpawn(playerid)
{
        return 1;
}
 
public OnObjectMoved(objectid)
{
        return 1;
}
 
public OnPlayerObjectMoved(playerid, objectid)
{
        return 1;
}
 
public OnPlayerPickUpPickup(playerid, pickupid)
{
        return 1;
}
 
public OnVehicleMod(playerid, vehicleid, componentid)
{
        return 1;
}
 
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
        return 1;
}
 
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
        return 1;
}
 
public OnPlayerSelectedMenuRow(playerid, row)
{
        return 1;
}
 
public OnPlayerExitedMenu(playerid)
{
        return 1;
}
 
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
        return 1;
}
 
public OnRconLoginAttempt(ip[], password[], success)
{
        return 1;
}
 
public OnPlayerUpdate(playerid)
{
        return 1;
}
 
public OnPlayerStreamIn(playerid, forplayerid)
{
        return 1;
}
 
public OnPlayerStreamOut(playerid, forplayerid)
{
        return 1;
}
 
public OnVehicleStreamIn(vehicleid, forplayerid)
{
       return 1;
}
 
public OnVehicleStreamOut(vehicleid, forplayerid)
{
        return 1;
}
 
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        if(dialogid == dregister) //If dialog id is a register dialog
        {//then
            if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
                if(response) //if they clicked the first button "Register"
                {//then
                        if(!strlen(inputtext)) //If they didn't enter any password
                        {// then we will tell to them to enter the password to register
                                ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                                return 1;
                        }
                        //If they has entered a password for his account...
                        new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to has their password
            new INI:file = INI_Open(Path(playerid)); //will create a new variable to register their acount inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
                        INI_WriteString(file,"Password",hashpass);//This will write a hashed password in of user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
                        INI_WriteInt(file,"VIPLevel",0);//As explained above
                        INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
                        INI_WriteInt(file,"Scores",0);//As explained above
                        INI_WriteInt(file,"Kills",0);//As explained above
                        INI_WriteInt(file,"Deaths",0);//As explained above
                        INI_Close(file);//Now after we've done saving their data, we now need to close the file
                        SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
                        return 1;
                }
        }
        if(dialogid == dlogin) //If dialog id is a login dialog
        {//then
            if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
                if(response) //if they clicked the first button "Register"
                {//then
                        new hashpass[129]; //Will create a new variable to hash his/her password
                        WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
                        if(!strcmp(hashpass,pInfo[playerid][Pass])) //If they have entered a correct password
                        {//then
                INI_ParseFile(Path(playerid),"loadaccount_user",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                                SetPlayerScore(playerid,pInfo[playerid][scores]);//We will get their score inside of his user's account and we will set it here
                                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
                        }
                        else //If they've entered an incorrect password
                        {//then
                                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
                        }
                }
        }
        return 1;
}
 
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
        return 1;
}
 
public JobAss(playerid)
{
    TextDrawHideForPlayer(playerid,JobAs);
    return 1;
}
 
public LeaveJ(playerid)
{
TextDrawHideForPlayer(playerid,Leave);
return 1;
}

 
errory nehádže, (localhost) samp-server.exe ukazuje niečo takéto:
 

 

Script[gamemodes/menomodu.amx]: Run time error 19: "File or function is not found"

 

 

diky

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...