Jump to content
  • 0

Am o problema cu sistemul de register/logi.


Stan Catalin

Question

Salut, de ore tot caut pe internet tutorial despre sistemul de register/login, dar nu pot sa-mi dau seama ce gresec. Ma puteti ajuta?

Problema esentiala este ca nu-mi apar text-boxurile.

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include <a_mysql>
#include <easyDialog>

#define host "localhost"
#define db "samp"
#define user "root"
#define pass ""

enum
{
    DIALOG_LOGIN,
    DIALOG_REGISTER
};

enum pinfo
{
   id,
   passw[129],
   name[30],
   money,
   level
};

new PData[MAX_PLAYERS][pinfo];
new playername[MAX_PLAYERS][30];
new MySQL:dbhandle;
new PlayerIP[MAX_PLAYERS][17];

forward OnPlayerLogin(playerid);
forward SavePlayer(playerid);
forward RegisterPlayer(playerid);
forward LoadPlayer(playerid);
native WP_Hash(buffer[], len, const str[]);

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    mysql_log(ALL);
    dbhandle = mysql_connect(host,user,pass,db);
    if (dbhandle == MYSQL_INVALID_HANDLE || mysql_errno(dbhandle) != 0)

    {

        print("MySQL connection failed. Server is shutting down."); // Read below

        SendRconCommand("exit"); // close the server if there is no connection

        return 1;

    }
    print("eokboss\n");
    SetGameModeText("Blank Script");
    return 1;
}

public OnGameModeExit()
{
    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 OnPlayerLogin(playerid)
{
   new rows,string[150];
   cache_get_row_count(rows);
   if (rows)
   {
       cache_get_value_name(0, "password", PData[playerid][passw], 129); // Load the player's password
       cache_get_value_name_int(0, "id", PData[playerid][id]);
       format(string,sizeof(string),"Welcome back to the server.\nPlease type your password below to login to your account.");
       Dialog_Show(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", string, "Login", "Exit");
   }
   else
   {
       format(string, sizeof(string), "Welcome to our server.\nIf you want to play here, you must register an account. Type a strong password below to register.");
       Dialog_Show(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register", string, "Register", "Exit");
   }
}

public OnPlayerConnect(playerid)
{
    new query[140];
    GetPlayerName(playerid,playername[playerid],30);
    GetPlayerIp(playerid, PlayerIP[playerid], 16);
    mysql_format(dbhandle,query,sizeof(query),"SELECT 'password','Id' FROM 'user' WHERE 'username' = '%e' LIMIT 0, 1",playername[playerid]);
    mysql_tquery(dbhandle,query,"OnPlayerLogin", "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    SavePlayer(playerid);
    return 1;
}

public SavePlayer(playerid)
{
    new query[140];
    mysql_format(dbhandle, query, sizeof(query), "UPDATE `user` SET `cash` = '%d' WHERE `ID` = '%d'", PData[playerid][money], PData[playerid][id]);
    mysql_tquery(dbhandle,query);
}

public RegisterPlayer(playerid)
{
    PData[playerid][id] = cache_insert_id();
    printf("A new account with the id of %d has been registered!", PData[playerid][id]); // You can remove this if you want, I just used it to debug.
    return 1;

}

public LoadPlayer(playerid)
{
    cache_get_value_name_int(0, "cash", PData[playerid][money]);
    GivePlayerMoney(playerid,PData[playerid][money]); //Load the player's cash and give it to them.
    return 1;

}

Dialog:DIALOG_LOGIN(playerid,response,listitem,inputtext[])
{
     if(!response) return Kick(playerid);
     new password[129], query[100];
     WP_Hash(password, 129, inputtext);
     if(!strcmp(password, PData[playerid][passw]))
     {
          mysql_format(dbhandle, query, sizeof(query), "SELECT * FROM `user` WHERE `username` = '%e' LIMIT 0, 1", playername[playerid]);
          mysql_tquery(dbhandle, query, "LoadPlayer", "i", playerid);
     }
     else
     {
          Dialog_Show(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login", "{FF0000}Wrong Password!\n{FFFFFF}Type your correct password below to continue and sign in to your account", "Login", "Exit");
     }
     return 1;
}

Dialog:DIALOG_REGISTER(playerid,response,listitem,inputtext[])
{
    if (!response) return Kick(playerid);
    if (strlen(inputtext) < 3) return Dialog_Show(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register", "{FF0000}Short Password!\n{FFFFFF}Type a 3+ characters password if you want to register and play on this server", "Register", "Exit");
    new query[300];
    WP_Hash(PData[playerid][passw], 129, inputtext);
    mysql_format(dbhandle, query, sizeof(query), "INSERT INTO `user` (`username`, `password`, `level`, `cash`, `admin`, `ip` , `vip`) VALUES ('%e', '%e', 0, 0, 0,'%e', 0)", playername[playerid], PData[playerid][passw], PlayerIP[playerid]);
    mysql_pquery(dbhandle, query, "RegisterPlayer", "i", playerid);
    return 1;
}

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.