Raised This Month: $ Target: $400
 0% 

Help with the new dbi...


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Zor
Veteran Member
Join Date: Mar 2004
Location: Toronto, ON
Old 09-27-2004 , 16:08  
Reply With Quote #5

Ok here is a good copy of the file. I only get one warning and I dont know why. Now I would pay attention to the coding style, its using a convention and one that you should use. Its not the only one but its one that is EASY to read. Your code was very difficult and hard to comprehend. It took about 1/2 an hour just to decifer. But as JGHG has stated you should learn to use a convention of some such:

Code:
/* amx_auth script by lowe *   1.0 First Working Version *   1.2 amxx-0.20 *   *       */ // Includes the include-files #include <amxmodx> #include <dbi> // DBI new Sql:dbiSqL new errormsg[256] // Adds a variable used to check if a user is regged new g_regged[33] public plugin_init() {     //register the pluginname, version, and creator     register_plugin("DB.se - Script","1.2","lowe")         // Registers the DB.se dictionary     register_dictionary("db.se.txt")         // amx_auth commando, to register your steamid into the database     register_clcmd("amx_auth","auth_me",0,"<nick> <password> Registers your STEAM ID in the Disturbed.se database")     return PLUGIN_CONTINUE } public plugin_modules() {     require_module("DBI")         return PLUGIN_CONTINUE } public plugin_cfg() {     new sqlhost[64], sqluser[64], sqlpass[64], sqldbname[64]         // Fetch the database info stated in sql.cfg     get_cvar_string("amx_sql_host",sqlhost,64)     get_cvar_string("amx_sql_user",sqluser,32)         get_cvar_string("amx_sql_pass",sqlpass,32)     get_cvar_string("amx_sql_db",sqldbname,32)         dbiSqL = dbi_connect(sqlhost,sqluser,sqlpass,sqldbname,errormsg,255)         if(dbiSqL <= SQL_FAILED)     {         // If there is an error Show the errormessage         server_print("[Disturbed] %L",LANG_SERVER,"SQL_CANT_CON",errormsg)                 // Close the connection         dbi_close(dbiSqL)             return PLUGIN_HANDLED     }         // If Connected Successfuly and Show the Connected message     server_print("[Disturbed] %L",LANG_SERVER,"SQL_CONNECTED")         return PLUGIN_CONTINUE } public auth_me(id) {     // reads the number of arguments     new iargs = read_argc()     // if there is to few or to many...     if(iargs != 3)     {         // echo an errormessage to users console and finish the auther function         console_print(id,"[AMXX] %L", LANG_PLAYER, "AUTH_MISS_ARGS")         return PLUGIN_CONTINUE     }         // Variabels for users nick + pass + steamid     new aname[32],apassword[64],asteamid[32]     // Save name in variable     read_argv(1,aname,32)     // save password in variable     read_argv(2,apassword,64)     // save steamid to variable     get_user_authid(id,asteamid,31)         // execute the auther boolesk function     g_regged[id] = auther(asteamid, aname, apassword)     // if auther() returns 1     if(g_regged[id])     {         // Write a confirmation in the console         console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGGED",asteamid)     }         // if not     else     {         // Echo Failure Msg         console_print(id,"[Disturbed] %L",LANG_SERVER,"AUTH_REGG_FAIL",asteamid,aname)     }         return PLUGIN_CONTINUE } // the auther() function bool:auther(asteamid[], aname[], apassword[]) {     // Create variables for query     new query[128], Result:theResult     // Formate Query to check if user is registered     format(query, 127, "SELECT 'id' FROM members WHERE nick = '%s' AND pass = ENCODE('%s','Secret :P)", aname, apassword)     // Execute the query     theResult = dbi_query(dbiSqL, query)     // If nothing is returned     if(theResult == RESULT_NONE)     {         return false       }         // If there is a error...     if(theResult == RESULT_FAILED)     {         // save error in sqlerrormsg         dbi_error(dbiSqL,errormsg,255)                   // and echo the errormessage to the console         server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)         return false     }         // save the users userid     new aid = dbi_field(dbiSqL, 1)     dbi_free_result(theResult)     // Formate Query to check if user has a registered steamid     format(query, 127, "SELECT 'gid' FROM gamelink where game = 'cstrike' AND id = '%s'", aid)         // Execute the query     theResult = dbi_query(dbiSqL, query)     // If there is a error...     if( theResult == RESULT_FAILED )     {         dbi_error(dbiSqL,errormsg,255)         server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)                 return false     }     // If nothing is returned (aka. First time to set steamid)       if(theResult == RESULT_NONE)     {         dbi_free_result(theResult)         format(query, 127, "insert into gamelink(gid,id,game) VALUES('%s','%s','cstrike')",asteamid,aid)         theResult = dbi_query(dbiSqL, query)                 if(theResult == RESULT_FAILED)         {             dbi_error(dbiSqL,errormsg,255)             server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)             return false         }     }         // if things are returned (aka. not first time the query is executed)     else     {         dbi_free_result(theResult)         format(query, 127, "update gamelink set gid = '%s' WHERE id = '%s' AND game = 'cstrike' LIMIT 1",asteamid,aid)         theResult = dbi_query(dbiSqL, query)         if(theResult == RESULT_FAILED)         {             dbi_error(dbiSqL,errormsg,255)             server_print("[Disturbed] %L",LANG_SERVER,"SQL_ERROR", errormsg)             return false         }     }         return true }

Cheers! And Luck.
__________________
Zor is offline
Send a message via AIM to Zor Send a message via MSN to Zor Send a message via Yahoo to Zor
 



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 17:21.


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