Mysql connection
#1

Hi!

When i try to connect to my server,then i type the password at login (not register), my password is wrong,but the mysql data is ok.

Gamemode:

Код:
#include <a_samp>
#include <a_mysql>
#include <zcmd>

//==============================Define's==============================//
#define mysql_host "127.0.0.1" 
#define mysql_db "pear"
#define mysql_user "root"
#define mysql_pass ""

#define COLOR_YELLOW 0xFFFF00AA
//==============================Enum's==============================//
enum
{
    DIALOG_LOGIN, 
    DIALOG_REGISTER,
    DIALOG_UNUSED
};

enum pInfo 
{
    pPass,
    pID,
    pSkin,
    pAdmin,
    pCash,
    pLevel
};

//==============================New==============================//
new PlayerInfo[MAX_PLAYERS][pInfo];
new handle;
//==============================Forward==============================//
forward MySQLConnect();
forward OnPlayerLogin(playerid);
forward OnLogin(playerid);
//==============================MAIN==================================//
main()
{
	print("GameMode Pear incarcat...");
}
//==============================Public==============================//
public MySQLConnect()
{
    handle = mysql_connect(mysql_host, mysql_user, mysql_db, mysql_pass);
    if(mysql_errno() != 0)
    {
        printf("Conexiunea la baza de date %s a esuat ---> Server Inchis ~~~", mysql_db);
        SendRconCommand("exit");
    }
    else
    {
        printf("Conexiunea la baza de date '%s' cu user-ul '%s' a reusit!!!", mysql_db, mysql_user);
    }
    return 1;
}

public OnGameModeInit()
{
    MySQLConnect();
    SetGameModeText("Pear 0.1");
    print("Serverul se incarca!");
	return 1;
}

public OnGameModeExit()
{
    mysql_close(handle);
	return 1;
}

public OnPlayerConnect(playerid)
{
    PlayerInfo[playerid][pID] = 0;
    PlayerInfo[playerid][pSkin] = 0;
    PlayerInfo[playerid][pAdmin] = 0;
    PlayerInfo[playerid][pCash] = 0;
    PlayerInfo[playerid][pLevel] = 0;
    new query[100];
    
    mysql_format(handle, query, sizeof(query), "SELECT * FROM conturi WHERE Nume = '%s'", GetName(playerid));
    mysql_tquery(handle, query, "OnPlayerLogin", "i", playerid);
    
	return 1;
}
public OnPlayerLogin(playerid)
{
    new rows, fields, stringul[128];
    cache_get_data(rows, fields);
    if(rows)
    {
        format(stringul, 128, "%s,bine ai venit inapoi pe serverul Pear!", GetName(playerid));
        SendClientMessage(playerid, COLOR_YELLOW, stringul);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "{daf94d}Te rog sa-ti introduci parola contului mai jos!", "Logare", "Iesire");
    }
    else
    {
        format(stringul, 128, "%s,bine ai venit pe serverul Pear!", GetName(playerid));
        SendClientMessage(playerid, COLOR_YELLOW, stringul);
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Inregistrare", "{daf94d}Trebuie sa iti creezi un cont ca sa joci pe server. \n{daf94d}Tasteaza mai jos o parola, pentru a te inregistra!", "Inregistreaza", "Iesire");
    }
    return 1;
}

public OnLogin(playerid)
{
    new rows, fields,temporar[200];
    cache_get_data(rows, fields);
    if(rows)
    {
        PlayerInfo[playerid][pPass] = cache_get_field_content(0, "Parola",temporar);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        PlayerInfo[playerid][pSkin] = cache_get_field_content_int(0, "Skin");
        PlayerInfo[playerid][pAdmin] = cache_get_field_content_int(0, "Admin");
        PlayerInfo[playerid][pCash] = cache_get_field_content_int(0, "Bani");
        PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Nivel");
        SpawnPlayer(playerid);
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "{daf94d}Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Iesire");
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new strlevel[15];
    format(strlevel, 15, "Nivel: %d", PlayerInfo[playerid][pLevel]);
    new Text3D:label = Create3DTextLabel(strlevel, 0x00FF00FF, 30.0, 40.0, 50.0, 40.0, 0);
    Attach3DTextLabelToPlayer(label, playerid, 0.0, 0.0, 0.7);
    SetPlayerPos(playerid, 1479.6548, -1725.2207, 13.5469);
    SetPlayerInterior(playerid,0);
    SetPlayerVirtualWorld(playerid, 0);
    SetPlayerSkinEx(playerid, PlayerInfo[playerid][pSkin]);
    SetPlayerMoney(playerid, PlayerInfo[playerid][pCash]);
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new query[128], ip[25];
    
    switch(dialogid)
    {
        case DIALOG_REGISTER:
        {
            if(!response)
                    return Kick(playerid);
                    
            if(response)
            {
                if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "{daf94d}Introdu-ti o parola pentru a te inregistra pe server!", "Inregistreaza", "Iesire");

                GetPlayerIp(playerid, ip, sizeof(ip));
                mysql_format(handle, query, sizeof(query), "INSERT INTO conturi (Nume, Parola, IP, Bani, Nivel) VALUES ('%s', '%s', '%s')", GetName(playerid), inputtext, ip);
                SetPlayerMoney(playerid, 50);
                PlayerInfo[playerid][pLevel] = 1;
                SetPlayerSkinEx(playerid, 170);
                mysql_query(handle, query);
                
				ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Logheaza-te!", "{daf94d}Te rog sa-ti introduci parola contului mai jos!", "Logare", "Iesire");
            }
            return 1;
        }
        case DIALOG_LOGIN:
        {
            if(!response)
					return Kick(playerid);
					
            if(response)
            {
                if(!strlen(inputtext))
                        return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Parola incorecta!", "{daf94d}Te rog sa iti introduci parola corecta, pentru a te loga pe server.", "Logare", "Iesire");
                
                mysql_format(handle, query, sizeof(query), "SELECT * FROM conturi WHERE Parola = '%e' LIMIT 0,1", inputtext);
                mysql_tquery(handle, query, "OnLogin", "i", playerid);
            }
            return 1;
        }
        case DIALOG_UNUSED:
        {
            if(response)
            {
                return 1;
            }
        }
    }
    return 1;
}

//==============================Stock==============================//
stock GetName(playerid)
{
	new Name[MAX_PLAYER_NAME];

	GetPlayerName(playerid, Name, sizeof(Name));
	return Name;
}

stock SetPlayerMoney(playerid,money) 
{
     ResetPlayerMoney (playerid); 
     GivePlayerMoney (playerid,money);
     PlayerInfo[playerid][pCash] = money;
}

stock SetPlayerSkinEx(playerid,skin)
{
    PlayerInfo[playerid][pSkin] = skin;
    SetPlayerSkin(playerid, skin);
}
//==============================Comenzi==============================//

CMD:help(playerid, params[])
{
    new srdialog[500];
    format(srdialog, 500, "{50f442}/Help - Afiseaza lista comenzilor,\n");
    format(srdialog, 500, "%s{50f442}/Stats - Afiseaza statusurile tale.",srdialog);
    ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Comenzi", srdialog, "Ok", "");
    return 1;
}

CMD:stats(playerid, params[])
{
    new srdialog[500];
    format(srdialog, 500, "{fffa00}Nume\t%s [%d]\n", GetName(playerid), playerid);
    format(srdialog, 500, "%s{fffa00}Bani\t%d de lei",srdialog, PlayerInfo[playerid][pCash]);
    ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Status", srdialog, "Ok", "");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)