Raised This Month: $ Target: $400
 0% 

SQLite save & load problem


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 12-18-2011 , 05:20   Re: SQLite save & load problem
Reply With Quote #3

It won't work with mysql either because there are errors. Anyway what's the point of using this plugin? Except for blocking name change, it does nothing.

Fixed:
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <hamsandwich> 
#include <fakemeta> 
#include <sqlx> 

#define PLUGIN "Creacion cuenta + pw" 
#define VERSION "1.2" 
#define AUTHOR ";SoNNy" 
#define AUTO_TEAM_JOIN_DELAY 0.1 

#define DisabledChoiseMenu // Sacarle los "//" para desavilitar el uso de la M ocea choseteam. 

new Connected[33
new 
cvar_password_prefijo 
new cvar_usuario_prefijo 
new Cuenta[33
new 
g_MsgSync 

/*================================================================================ 
                [MySQLx Vars, other] 
=================================================================================*/ 
new Handle:g_hTuple
new 
LogeadoUSR[33]; 
new 
passwordSQl[33]; 
new 
NickSQL[33]; 
new 
usuarioNEW[32
new 
passwordNEW[32
new 
mysqlx_hostmysqlx_usermysqlx_dbmysqlx_pass

/*================================================================================ 
                [Iniciacion Plugin] 
=================================================================================*/ 
public plugin_init()  

    
register_plugin(PLUGINVERSIONAUTHOR

    
// Comandos en say 
    
register_clcmd("ingresar_usuario""LoadCuenta"
    
register_clcmd("ingresar_password""LoadPassword"
    
register_clcmd("_usuario""crear_cuenta"
    
register_clcmd("_password""crear_password"
    
register_message(get_user_msgid("ShowMenu"), "message_show_menu"
     
    
#if defined DisabledChoiseMenu 
    
register_clcmd("jointeam","cmdtopin"
    
register_clcmd("chooseteam","cmdtopin"
    
#endif 
     
    // PCVARS 
    
cvar_password_prefijo register_cvar("account_password_prefijo""_twbpw"
    
cvar_usuario_prefijo register_cvar("account_usuario_prefijo""_twbusr"

    
// Event 
    
register_forwardFM_ClientUserInfoChanged"FWClientUserInfoChanged" 
    
//register_event("TeamInfo", "HookJoinTeam", "a", "2!UNASSIGNED") 
     
    //Hud 
    
g_MsgSync CreateHudSyncObj() 
     
    
/*=================================================================================*/ 
    // SQLx cvars 
    
mysqlx_host register_cvar ("gxm_host""127.0.0.1");  
    
mysqlx_user register_cvar ("gxm_user""root");  
    
mysqlx_pass register_cvar ("gxm_pass""");  
    
mysqlx_db   register_cvar ("gxm_dbname""test");  
    
/*=================================================================================*/ 
    
MySQLx_Init() 


/*=================================================================================*/ 
#if defined DisabledChoiseMenu 
public cmdtopin(id

    static 
Team
    
Team get_user_team(id
     
    if (
Team == || Team == 4
        return 
PLUGIN_HANDLED
         
    if (
LogeadoUSR[id]) 
        return 
PLUGIN_CONTINUE
     
    
HookJoinTeam(id); 
     
    return 
PLUGIN_HANDLED_MAIN

#endif     

/*=================================================================================*/ 
public client_putinserver(id

    
LogeadoUSR[id] = 0
    
Connected[id] = 
    passwordSQl
[id] = 0
     
     
    
#if defined DisabledChoiseMenu 
    
set_task(0.1"cmdtopin"id
    
#endif 

public 
client_connect(id

    
LogeadoUSR[id] = 0
    
Connected[id] = 
    passwordSQl
[id] = 0
    
HookJoinTeam(id); 
     

/*=================================================================================*/ 
public client_disconnect(id

    
Connected[id] = 

/*=================================================================================*/ 
public FWClientUserInfoChangedIndexBuffer 

    if( !
is_user_connectedIndex ) ) 
        return 
FMRES_IGNORED
     
    static 
NickName[32], NickOld[32]; get_user_nameIndexNickOld31 
    
engfuncEngFunc_InfoKeyValueBuffer"name"NickName31 // Si tampoco me confundo, esto obtiene el valor "name" de su setinfo. 
     
    
if( equalNickNameNickOld ) ) 
        return 
FMRES_IGNORED
     
    
engfuncEngFunc_SetClientKeyValueIndexBuffer"name"NickOld // Le volvemos a poner el nick viejo para que no se lo pueda cambiar. 
     
    
client_cmdIndex"name ^"%s^"; setinfo name ^"%s^""NickOldNickOld 
     
    return 
FMRES_SUPERCEDE
}   
/*================================================================================ 
                [MENU Join] 
=================================================================================*/ 
public HookJoinTeam(id)  
{  

    if(!
is_user_connected(id)) 
        return 
FMRES_IGNORED 
     
    
switch(CheckCuentaMenu(id)) 
    { 
        case 
0..3
        { 
            if(!
Connected[id]) 
            { 
                new 
Menu menu_create("\yMenu de Login/Registro""showMenuLoginReg")  
                
menu_additem(Menu"\wLogin"            "1"0)  
                
menu_additem(Menu"\wRegistrar Cuenta"    "2"0)  
                  
                
menu_setprop(Menu,MPROP_EXITNAME,"Salir")  
                
menu_setprop(MenuMPROP_EXITMEXIT_ALL)  
                  
                
menu_display(idMenu0)  
            } 
        } 
    } 

    return 
PLUGIN_HANDLED  
}  
/*=================================================================================*/ 
public showMenuLoginReg(idMenuitem)  
{  
    if (
item == MENU_EXIT)  
    {  
        
menu_destroy(Menu)  
        return 
PLUGIN_HANDLED  
    
}  
      
    new 
iData[6];  
    new 
iAccess;  
    new 
iCallback;  
    new 
iName[64];  
    
menu_item_getinfo(MenuitemiAccessiData5iName63iCallback)  
       
    switch (
str_to_num(iData))  
    {  
        case 
1:  
        {  
            
client_cmd(id"messagemode ingresar_usuario"); 
             
            
mensajes_cuenta(id2
        }  
        case 
2:  
        {  
            
client_cmd(id"messagemode _usuario"); 
             
            
mensajes_cuenta(id2
        }  
    }  
      
    return 
PLUGIN_HANDLED  
}  

/*================================================================================ 
                [Func Login y Create Cuenta] 
=================================================================================*/ 
public crear_cuenta(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 

    
new say[300
    
// Obtenemos en un string lo que escribio como usuario 
    
read_args(saycharsmax(say)) 
    
// Lo preparamos para analizar 
    
remove_quotes(say), trim(say
     
    
mensajes_cuenta(id1
     
    
// Si solamente apreto enter lo omitiremos 
    
if(equal(say"")) 
    return 
PLUGIN_HANDLED 
    
// Verificamos que la usuario solo contenga una palabra 
    
if(contain(say" ") != -1
    { 
        
ChatColor(id"!g[ZP]!y El usuario debe ser 1 (una) palabra"
        return 
PLUGIN_HANDLED 
    

     
    
copy(Cuenta[id], charsmax(Cuenta), say
     
    
crear_contrasenia(id
     
    
/*static szQuery[ 128 ], iData[ 1 ]; 
         
    formatex( szQuery, 127, "SELECT `usuario` FROM `account` WHERE ( `usuario` = '%s' );", zwname );   

    iData[ 0 ] = id; 
    SQL_ThreadQuery( g_hTuple, "QuerySelectData2", szQuery, iData, 1 ); 
    */ 
     
    
return PLUGIN_HANDLED 


public 
crear_contrasenia(id
{             
    if(
LogeadoUSR[id] != 0
        return; 
     
    
client_cmd(id"messagemode _password"
    
mensajes_cuenta(id3


public 
crear_password(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 

    
new say[300
    
// Obtenemos en un string lo que escribio como password 
    
read_args(saycharsmax(say)) 
    
// Lo preparamos para analizar 
    
remove_quotes(say), trim(say
     
    
mensajes_cuenta(id1
     
    
// Si solamente apreto enter lo omitiremos 
    
if(equal(say"")) 
    return 
PLUGIN_HANDLED 
    
// Verificamos que la password solo contenga una palabra 
    
if(contain(say" ") != -1
    { 
        
ChatColor(id"!g[ZP]!y La contrasenia debe ser 1 (una) palabra"
        return 
PLUGIN_HANDLED 
    

     
    
copy(passwordSQl[id], charsmax(passwordSQl), say
     
    static 
szQuery128 ], iData]; 
     
    
formatexszQuery127"SELECT `usuario`, `password` FROM `account` WHERE ( `usuario` = '%s' );"Cuenta[id] );   

    
iData] = id
    
SQL_ThreadQueryg_hTuple"QuerySelectData2"szQueryiData); 
    return 
PLUGIN_HANDLED 


public 
QuerySelectData2iFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime )  
{  
    if( 
iFailState == TQUERY_CONNECT_FAILED  
    
|| iFailState == TQUERY_QUERY_FAILED )  
    {  
        
log_amx"%s"szError ); 
         
        return; 
    }  
    else  
    {  
        new 
id iData]; 
         
        new 
prefijo_u[8], prefijo_p[8
         
        if(
SQL_NumResults(hQuery) < 1
        { 
            
SaveCuenta(id); 
            
get_pcvar_string(cvar_usuario_prefijoprefijo_ucharsmax(prefijo_u)) 
            
get_pcvar_string(cvar_password_prefijoprefijo_pcharsmax(prefijo_p)) 
            
client_cmd(id"setinfo %s %s"prefijo_uCuenta[id]) 
            
client_cmd(id"setinfo %s %s"prefijo_ppasswordSQl[id]) 
            
client_cmd(id"writecfg config"
            
ChatColor(id"!g[ZP]!y Has sido registrado!. Usuario: %s - Password: %s"Cuenta[id], passwordSQl[id]) 
            
engclient_cmd(id"joinclass""5"); 
            
Connected[id] = 
            LogeadoUSR
[id] = 1
        } 
        else 
        { 
            
ChatColor(id"!g[ZP]!y El Usuario ya existe Por favor elija otro O Logeece."
        } 
    }  

/*=================================================================================*/ 

/*=================================================================================*/ 
CheckCuentaMenu(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
if(!LogeadoUSR[id]) 
    {     
        
// Al no existir, cancelamos 
        
Connected[id] = 0
        
LogeadoUSR[id] = 0
        return 

    

    if(!
Connected[id])  
    {  
        
Connected[id] = 0
        
LogeadoUSR[id] = 0
        return 

    
}  

    return 
PLUGIN_HANDLED 


/*================================================================================ 
                [Auto Join] 
=================================================================================*/ 
public message_show_menu(msgiddestid)  

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
static team_select[] = "#Team_Select" 
    
static menu_text_code[sizeof team_select
    
get_msg_arg_string(4menu_text_codesizeof menu_text_code 1
    if (!
equal(menu_text_codeteam_select)) 
        return 
PLUGIN_CONTINUE 

    set_force_team_join_task
(idmsgid

    return 
PLUGIN_HANDLED 

/*=================================================================================*/ 
set_force_team_join_task(idmenu_msgid

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
static param_menu_msgid[2
    
param_menu_msgid[0] = menu_msgid 
    set_task
(AUTO_TEAM_JOIN_DELAY"task_force_team_join"idparam_menu_msgidsizeof param_menu_msgid
    return 
PLUGIN_HANDLED

/*=================================================================================*/ 
public task_force_team_join(menu_msgid[], id)  

    if (
get_user_team(id)) 
        return  

    
force_team_join(id



/*================================================================================ 
                [MySQLx] 
=================================================================================*/ 
public MySQLx_Init() 

    
SQL_SetAffinity("sqlite")
    new 
szHost[64], szUser[32], szPass[32], szDB[128]; 
     
    
get_pcvar_stringmysqlx_hostszHostcharsmaxszHost ) ); 
    
get_pcvar_stringmysqlx_userszUsercharsmaxszUser ) ); 
    
get_pcvar_stringmysqlx_passszPasscharsmaxszPass ) ); 
    
get_pcvar_stringmysqlx_dbszDBcharsmaxszDB ) ); 
     
    
g_hTuple SQL_MakeDbTupleszHostszUserszPassszDB ); 
     

/*=================================================================================*/ 
SaveCuenta(id
{  
    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
static szQuery128 ];  
    
formatexszQuery127"REPLACE INTO `account` (`usuario`, `password`) VALUES ('%s', '%s');"Cuenta[id] , passwordSQl[id] ); 
    
SQL_ThreadQueryg_hTuple"QuerySetData"szQuery); 
     
    return 
PLUGIN_HANDLED

/*=================================================================================*/ 

public LoadCuenta(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
new say[300

    
read_args(saycharsmax(say)) 
    
remove_quotes(say), trim(say
     
    
mensajes_cuenta(id1

    if(
equal(say"")) 
    return 
PLUGIN_HANDLED 

    
if(contain(say" ") != -1
    { 
        
ChatColor(id"!g[ZP]!y El usuario debe ser 1 (una) palabra"
        return 
PLUGIN_HANDLED 
    

     
    
copy(usuarioNEW[id], charsmax(usuarioNEW), say
     
    
login_contrasenia(id
    return 
PLUGIN_HANDLED 
     


public 
login_contrasenia(id

    if(
LogeadoUSR[id] != 0
        return; 
         
    
client_cmd(id"messagemode ingresar_password")     
    
mensajes_cuenta(id3)         


public 
LoadPassword(id

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
new say[300

    
read_args(saycharsmax(say)) 
    
remove_quotes(say), trim(say
     
    
mensajes_cuenta(id1

    if(
equal(say"")) 
    return 
PLUGIN_HANDLED 

    
if(contain(say" ") != -1
    { 
        
ChatColor(id"!g[ZP]!y La contrasenia debe ser 1 (una) palabra"
        return 
PLUGIN_HANDLED 
    

     
    
copy(passwordNEW[id], charsmax(passwordNEW), say
     
    static 
szQuery128 ], iData]; 
         
    
formatexszQuery127"SELECT `usuario`, `password` FROM `account` WHERE ( `usuario` = '%s' );"usuarioNEW[id] );   

    
iData] = id
    
SQL_ThreadQueryg_hTuple"QuerySelectData"szQueryiData); 
    return 
PLUGIN_HANDLED 
     


/*=================================================================================*/ 

public QuerySelectDataiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime )  
{  
     
    if( 
iFailState == TQUERY_CONNECT_FAILED  
    
|| iFailState == TQUERY_QUERY_FAILED )  
    {  
        
log_amx"%s"szError ); 
         
        return 
PLUGIN_HANDLED
    }  
    else  
    {  
        new 
id iData]; 
         
        if(!
is_user_connected(id)) 
            return 
PLUGIN_HANDLED
         
        new 
password2SQL[32]; 
        new 
ColPass SQL_FieldNameToNum(hQuery"password")  
         
        new 
prefijo_u[8], prefijo_p[8
        
get_pcvar_string(cvar_password_prefijoprefijo_pcharsmax(prefijo_p)) 
        
get_pcvar_string(cvar_usuario_prefijoprefijo_ucharsmax(prefijo_u)) 
         
         
     
        if(
SQL_NumResults(hQuery) > 0
        { 
            
SQL_ReadResult(hQueryColPasspassword2SQLcharsmax(password2SQL)) 
            
//copy(passwordSQl[id], charsmax(passwordSQl), password2SQL) 
             
             
            
if(equali(password2SQLpasswordNEW[id]))  
            {  
                
ChatColor(id"!g[ZP]!y Contrasenia Aceptada")  
                
client_print(idprint_center"Login Exitoso!"
                
client_cmd(id"setinfo ^"%s^" ^"%s^"",prefijo_p,password2SQL
                
client_cmd(id"setinfo ^"%s^" ^"%s^"",prefijo_u,usuarioNEW[id]) 
                
client_cmd(id"writecfg config"
                
engclient_cmd(id"joinclass""5");  
                
Connected[id] = 1
                
LogeadoUSR[id] = 1
            }  
            else  
            {  
                
client_cmd(id"messagemode ingresar_password"); 
                
mensajes_cuenta(id3
                
ChatColor(id"!g[ZP]!y Contrasena Incorrecta. Escriba nuevamente su contrasena")  
                
Connected[id] = 0
                
LogeadoUSR[id] = 0
                
HookJoinTeam(id); 
            }  
             
        } 
        else 
        { 
            
// Al no existir, cancelamos 
            
ChatColor(id"!g[ZP]!y La cuenta !team NO EXISTE!y Debes Registrarte!... Ingresa una Contrasenia para registrar nueva cuenta."); 
            
client_cmd(id"messagemode _usuario"); 
            
mensajes_cuenta(id2)     
            
LogeadoUSR[id] = 0
        } 
    }  
    return 
PLUGIN_HANDLED

/*=================================================================================*/ 
public QuerySetDataiFailStateHandle:hQueryszError[ ], iErroriData[ ], iDataSizeFloat:fQueueTime )  
{  
     
    if( 
iFailState == TQUERY_CONNECT_FAILED  
    
|| iFailState == TQUERY_QUERY_FAILED )  
    {  
        
log_amx"%s"szError );  
        return; 
    }  
}  

/*================================================================================ 
                [Stocks] 
=================================================================================*/ 
stock force_team_join(id)  

    if(!
is_user_connected(id)) 
        return 
PLUGIN_HANDLED 
     
    
static jointeam[] = "jointeam" 
    
engclient_cmd(idjointeam"5"
    
HookJoinTeam(id)  
     
    return 
PLUGIN_HANDLED

/*=================================================================================*/ 
stock check_user_name(id, const name[32] = ""

    new 
plrname[32
    
    if(
equal(name"")) 
    { 
        
get_user_name(idplrname31
    } 
    else 
    { 
        
plrname name 
    

    
//load_cuentas(id) 

/*=================================================================================*/ 
stock ChatColor(const id, const input[], any:...) 

    new 
count 1players[32
    static 
msg[191
    
vformat(msg190input3
     
    
replace_all(msg190"!g""^4"// Green Color 
    
replace_all(msg190"!y""^1"// Default Color 
    
replace_all(msg190"!team""^3"// Team Color 
    
replace_all(msg190"!team2""^0"// Team2 Color 
     
    
if (idplayers[0] = id; else get_players(playerscount"ch"
    { 
         for (new 
0counti++) 
         { 
        if (
is_user_connected(players[i])) 
        { 
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i]) 
            
write_byte(players[i]); 
            
write_string(msg); 
            
message_end(); 
         } 
         } 
      
    } 

/*=================================================================================*/   
public mensajes_cuenta(idmensaje

    
set_hudmessage(255000.010.0310.1100.00.10.1
     
    if(
mensaje == 1
        
ShowSyncHudMsg(idg_MsgSync""
     
    if(
mensaje == 2)     
        
ShowSyncHudMsg(idg_MsgSync"Ingresa tu cuenta"

    if(
mensaje == 3)     
        
ShowSyncHudMsg(idg_MsgSync"Ingresa tu contraseA±a")     
     
    if(
mensaje == 4)     
        
ShowSyncHudMsg(idg_MsgSync"Vuelve a ingresar tu contraseA±a")         
     
    if(
mensaje == 5)     
        
ShowSyncHudMsg(idg_MsgSync"Ingresa tu nueva contraseA±a")     
     
    if(
mensaje == 6)     
        
ShowSyncHudMsg(idg_MsgSync"Vuelve a ingresar tu nueva contraseA±a")                 
         
    
client_cmd(id"spk Ui/buttonclickrelease"
         

__________________
Impossible is Nothing
Sylwester is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode