[Ajuda] SQLite
#1

Comeзei a usar esse sistema hoje e entгo ainda estou aprendendo pois antes eu armazenava os dados do jogador em .ini usando a Include DOF2, entгo procurando no forum eu achei esse sistema aqui https://sampforum.blast.hk/showthread.php?tid=364392 um sistema de registrar e logar em SQLite e partir dele eu criei o meu sistema de login e registro e depois adaptei ao meu gamemode principal
PHP код:
#include <a_samp>
new DB:Contas;
#define D_Login (0)
#define D_Registro (1)
main()
{
    print(
"SQL BASE - STARTED! 20");
}
public 
OnGameModeInit()
{
    
Contas db_open("contas.db");
    return 
1;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid)
{
    
Autenticar(playerid);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
SalvarUsuario(playerid);
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    new 
DBResult:ResultQuery[120];
    if(
dialogid == D_Login)
    {
        if(
response)
        {
            
format(Querysizeof(Query), "SELECT * FROM `Usuarios` WHERE `Nome` = '%s' AND `Senha` = '%s'"DB_Escape(PegarNome(playerid)), DB_Escape(inputtext));
            
Result db_query(ContasQuery);
            if(
db_num_rows(Result))
            {
                
CarregarUsuario(playerid);
                
SpawnPlayer(playerid);
            }
            
db_free_result(Result);
        }
        else 
Kick(playerid);
    }
    if(
dialogid == D_Registro)
    {
        if(
response)
        {
            if(
strlen(inputtext) < || strlen(inputtext) > 10) { ShowPlayerDialog(playeridD_RegistroDIALOG_STYLE_INPUT"[Register]""Your pass must be bigger than 5 and smaller than 10 characters.""Register""Cancel"); }
            else
            {
                
format(Querysizeof(Query), "INSERT INTO `Usuarios` (`Nome`, `Senha`, `Dinheiro`) VALUES ('%s','%s','1000')"DB_Escape(PegarNome(playerid)), DB_Escape(inputtext));
                
db_query(ContasQuery);
                
ShowPlayerDialog(playeridD_LoginDIALOG_STYLE_PASSWORD"[Login]""Your Account has been sucessfully Created!\nInsert your Password to Login.""Login""Cancel");
            }
        }
    }
    return 
1;
}
stock Autenticar(playerid)
{
    
    new 
Query[120], DBResult:Result;
    
format(Querysizeof(Query), "SELECT * FROM `Usuarios` WHERE `Nome` = '%s'"DB_Escape(PegarNome(playerid)));
    
Result db_query(ContasQuery);
    if(
db_num_rows(Result)) ShowPlayerDialog(playeridD_LoginDIALOG_STYLE_PASSWORD"[Login]""Account Status: Registred\nInsert your Password to Login!""Login""Cancel");
    else 
ShowPlayerDialog(playeridD_RegistroDIALOG_STYLE_INPUT"[Register]""Account Status: Unregistred\nInsert a Password to Register!""Register""Cancel");
    
db_free_result(Result);
    return 
1;
}
stock SalvarUsuario(playerid)
{
    new 
Query[120];
    
format(Querysizeof(Query), "UPDATE `Usuarios` SET Dinheiro = %i"GetPlayerMoney(playerid));
    
db_query(ContasQuery);
    return 
1;
}
stock CarregarUsuario(playerid)
{    
    new 
Dados[30], DBResult:ResultQuery[120];
    
format(Querysizeof(Query), "SELECT * FROM `Usuarios` WHERE `Nome` = '%s'"DB_Escape(PegarNome(playerid)));
    
Result db_query(ContasQuery);
    
db_get_field_assoc(Result,"Dinheiro"Dadossizeof(Dados)), GivePlayerMoney(playeridstrval(Dados));
    return 
1;
}
stock PegarNome(playerid)
{
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    return 
name;
}
stock DB_Escape(text[])
{
    new
    
ret[80 2],
    
ch,
    
i,
    
j;
    while ((
ch text[i++]) && sizeof (ret))
    {
        if (
ch == '\'')
        {
            if (
sizeof (ret) - 2)
            {
                
ret[j++] = '\'';
                
ret[j++] = '\'';
            }
        }
        else if (
sizeof (ret))
        {
            
ret[j++] = ch;
        }
        else
        {
            
j++;
        }
    }
    
ret[sizeof (ret) - 1] = '\0';
    return 
ret;

porem eu estou tendo alguns problemas e eu gostaria que alguem me ajudasse, entгo eu nгo sei se й algum problema no script acima ou й algum problema no Database, o que acontece й que quando eu entro no servidor com uma conta tudo funciona perfeitamente, consigo efetuar o cadastro eo login e quando eu relogo no servidor os dados ficam salvos certinhos, o problema й que quando eu entro com outra conta, os dados da conta anterior exceto a senha sгo setados na conta atual e vice-versa, entгo nгo sei se o problema й no database ou no script

OBS: O Database abaixo й da minha outra gamemode onde eu adaptei o sistema acima e estou tendo problemas

Database anexado abaixo \/
Reply


Messages In This Thread
SQLite - by JPedro - 30.12.2015, 01:00
Re: SQLite - by PT - 30.12.2015, 01:38
Re: SQLite - by JPedro - 30.12.2015, 01:53
Re: SQLite - by PT - 30.12.2015, 01:59
Re: SQLite - by JPedro - 30.12.2015, 02:05
Re: SQLite - by JPedro - 30.12.2015, 02:42
Re: SQLite - by MultiKill - 30.12.2015, 03:07
Re: SQLite - by arakuta - 30.12.2015, 03:16

Forum Jump:


Users browsing this thread: 1 Guest(s)