Raised This Month: $ Target: $400
 0% 

sqlx help


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-01-2018 , 10:36   Re: sqlx help
Reply With Quote #2

1. You should always show which error you are getting when asking for help. Since you didn't, I need to look at your entire plugin instead of looking for something specific. Enable debug mode in plugins.ini when developing your plugin.
2. Is login the only SQL query you are using ReadInfo() to process? If so then you are ok, if not then you need to do additional work to make it know which transaction you are doing.
3. You are sending a query to get all records from vip_users and then assuming the first one returned is the player you are looking for. You should specify additional conditions in your query to get data for only the player you want. I am not sure what field names you are using, replace 'username' and 'pwd' accordingly. Also, you should be sending steam-id, not name since any player can use any name, you cannot base security off of a name.

Untested
Code:
#include < amxmodx > #include < amxmisc > #include < sqlx > #define PLUGIN  "VIP SQL" #define VERSION "1.0" #define AUTHOR  "LondoN eXtream" // SQL Stuff new g_CvarHost, g_CvarUser, g_CvarPass, g_CvarDB; new g_pGlobalQuery [ 256 ]; new Handle: Tuple; // VIP Stuff new g_pName [ 33 ] [ 32 ]; new g_pPass [ 33 ] [ 32 ]; new bool: is_user_vip [ 33 ]; public plugin_precache ( ) {     server_print ( "[VIP] Pluginul a pornit cu success" );     g_CvarHost      =   register_cvar ( "vip_sqlx_host", "35.190.179.72" );     g_CvarUser      =   register_cvar ( "vip_sqlx_user", "gamezeer_vip" );     g_CvarPass      =   register_cvar ( "vip_sqlx_pass", "undercoveR123" );     g_CvarDB        =   register_cvar ( "vip_sqlx_db""gamezeer_vip" );     SQLX_Connect ( ); }     public plugin_init ( ) {     register_plugin ( PLUGIN, VERSION, AUTHOR );     register_cvar ( "vip_sqlx_london", VERSION, FCVAR_SERVER|FCVAR_SPONLY );     set_cvar_string ( "vip_sqlx_london", VERSION ); } public SQLX_Connect ( ) {     new szHost [ 32 ], szUser [ 32 ], szPass [ 32 ], szDB [ 32 ];     get_pcvar_string ( g_CvarHost, szHost, charsmax ( szHost ) );     get_pcvar_string ( g_CvarUser, szUser, charsmax ( szUser ) );     get_pcvar_string ( g_CvarPass, szPass, charsmax ( szPass ) );     get_pcvar_string ( g_CvarDB, szDB, charsmax ( szDB ) );     Tuple = SQL_MakeDbTuple ( szHost, szUser, szPass, szDB, 10 ); } public client_connect ( id ) {     if ( is_user_bot ( id ) || is_user_hltv ( id ) )         return;     get_user_name ( id, g_pName [ id ], charsmax ( g_pName ) );     get_user_info ( id, "_pass", g_pPass [ id ], charsmax ( g_pPass ) );         //This query is getting every player in vip_users when you only want data for 1 player.     //You technically can do it this way, but then you would need to cycle through every result in your query handler using SQL_NextRow(), which is inefficient.     //formatex ( g_pGlobalQuery, charsmax ( g_pGlobalQuery ), "SELECT * FROM vip_users" );         //Query for records for those that have matching name and password only.     formatex ( g_pGlobalQuery, charsmax ( g_pGlobalQuery ), "SELECT * FROM vip_users WHERE username=^"%s^" AND pwd=^"%s^"" , g_pName [ id ] , g_pPass [ id ] );         //In your query handler, you are assuming Data[0] holds the player ID but you are never setting this before executing the query. This results in player id always being 0 in the handler.     //SQL_ThreadQuery( Tuple, "ReadInfo", g_pGlobalQuery );     //This is where to can specify the data passed in Data[] so that it can be used in the query result.     new queryData[ 1 ];     queryData[ 0 ] = id;     SQL_ThreadQuery( Tuple, "ReadInfo", g_pGlobalQuery , queryData , sizeof( queryData ) ); } public ReadInfo ( FailState, Handle: Query, szError, Errcode, Data [ ], DataSize ) {     if ( FailState == TQUERY_CONNECT_FAILED )     {         log_amx ( "Nu ne putem conecta la %d [%s]", Errcode, szError );         return;     }     else if ( FailState == TQUERY_QUERY_FAILED )     {         log_amx ( "Query Error: %d [%s]", Errcode, szError );         return;     }     new Player = Data [ 0 ];         //This should be a check for > 0 instead of > 1     //if ( SQL_NumResults ( Query ) > 1 )     if ( SQL_NumResults ( Query ) > 0 )     {         //new TempUser [ 32 ];         //new TempPass [ 32 ];                 //SQL_ReadResult ( Query, 1, TempUser, charsmax ( TempUser ) );         //SQL_ReadResult ( Query, 2, TempPass, charsmax ( TempPass ) );         //if ( equal ( g_pName [ Player ], TempUser ) )         //{         //if ( equal ( g_pPass [ Player ], TempPass ) )         //{             is_user_vip [ Player ] = true;             server_print ( "[VIP] %s connected with success", g_pName [ Player ] );         //}         //else         //{         //  server_cmd ( "kick #%d", get_user_userid ( Player ) );         //  server_print ( "[VIP] %s Kicked due to Invalid Password", g_pName [ Player ] );         //}         //}     }     else     {         //No records returned which means there was no username + password match         server_cmd ( "kick #%d", get_user_userid ( Player ) );         server_print ( "[VIP] %s Kicked due to Invalid Password", g_pName [ Player ] );     }         }
__________________

Last edited by Bugsy; 12-01-2018 at 10:40.
Bugsy 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 07:33.


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