Re: SQL help?
Try this, never tested SQL somewhere:
PHP Code:
/*Cheater Log*/
////////////// // Includes // ////////////// #include < amxmodx > #include < sqlx >
/////////////// // Constants // /////////////// new const g_strVersion[ ] = "0.0.1"; new const g_strLogFile[ ] = "CheaterReport.log";
/////////////// // Variables // /////////////// new Handle:g_SqlTuple;
new g_szError[512];
// Integers new g_iMaxPlayers;
// Boleans new g_bMenuUsed;
// Cvars new cvar_sql_host; new cvar_sql_user; new cvar_sql_pass; new cvar_sql_db;
///////////////// // Plugin Init // ///////////////// public plugin_init( ) { register_plugin( "Cheater Log", g_strVersion, "n0br41ner" ); cvar_sql_host = register_cvar("amx_cvar_sql_host", ""); cvar_sql_user = register_cvar("amx_cvar_sql_user", ""); cvar_sql_pass = register_cvar("amx_cvar_sql_pass", ""); cvar_sql_db = register_cvar("amx_cvar_sql_db", ""); register_clcmd( "say /cheater", "ClCmd_CheaterReport" ); g_iMaxPlayers = get_maxplayers( ); MySQL_Init(); }
public MySQL_Init() { new szHost[64], szUser[64], szPass[64], szDb[64]; get_pcvar_string(cvar_sql_host, szHost, charsmax(szHost)); get_pcvar_string(cvar_sql_user, szUser, charsmax(szUser)); get_pcvar_string(cvar_sql_pass, szPass, charsmax(szPass)); get_pcvar_string(cvar_sql_db, szDb, charsmax(szDb)); g_SqlTuple = SQL_MakeDbTuple(szHost, szUser, szPass, szDb); new Errcode, Handle:SqlConnection = SQL_Connect(g_SqlTuple, Errcode, g_szError, charsmax(g_szError)); if (SqlConnection == Empty_Handle) set_fail_state(g_szError); new Handle:Query = SQL_PrepareQuery(SqlConnection, "CREATE TABLE IF NOT EXISTS cheaterlog (nick VARCHAR(32), steamid VARCHAR(32), ip VARCHAR(32))"); if (!SQL_Execute(Query)) { SQL_QueryError(Query, g_szError, charsmax(g_szError)); set_fail_state(g_szError); } SQL_FreeHandle(Query); SQL_FreeHandle(SqlConnection); }
public plugin_end() { SQL_FreeHandle(g_SqlTuple); }
Add_To_Db(id) { new szName[32], szAuthID[32], szIp[32]; get_user_name(id, szName, charsmax(szName)); get_user_authid(id, szAuthID, charsmax(szAuthID)); get_user_ip(id, szIp, charsmax(szIp), 1); new szQuery[256]; formatex(szQuery, charsmax(szQuery), "INSERT INTO cheaterlog (nick, steamid, ip) VALUES ('%s', '%s', '%s')", szName, szAuthID, szIp); SQL_ThreadQuery(g_SqlTuple, "Query_Handler", szQuery); }
public Query_Handler(FailState, Handle:Query, Error[], Errcode, Data[], DataSize) { if (FailState == TQUERY_CONNECT_FAILED) log_amx("Could not connect to SQL database."); else if (FailState == TQUERY_QUERY_FAILED) log_amx("Query failed."); if (Errcode) return log_amx("Error on query: %s.", Error); return PLUGIN_CONTINUE; }
////////////// // Commands // ////////////// public ClCmd_CheaterReport( iPlayerID ) { if( g_bMenuUsed ) { client_print( iPlayerID, print_chat, "[SM] The menu is being used by another player." ); return PLUGIN_HANDLED; } g_bMenuUsed = true; static strMenuTitle[ 128 ]; formatex( strMenuTitle, 127, "\yChose The Cheater:^n\rNote: his name, steam id and ip will be logged^n" ); new strMenu = menu_create( strMenuTitle, "Handle_CheaterReport" ); static strPlayerName[ 32 ], strNumber[ 3 ]; for( new iLoop = 0; iLoop <= g_iMaxPlayers; iLoop++ ) { get_user_name( iLoop, strPlayerName, 31 ); num_to_str( iLoop, strNumber, 2 ); menu_additem( strMenu, strPlayerName, strNumber ); } menu_setprop( strMenu, MPROP_NUMBER_COLOR, "\y" ); menu_display( iPlayerID, strMenu ); return PLUGIN_HANDLED; }
public Handle_CheaterReport( iPlayerID, strMenu, iKey ) { if( iKey == MENU_EXIT ) { menu_destroy( strMenu ); g_bMenuUsed = false; return PLUGIN_HANDLED; } static strData[ 6 ], strPlayerName[ 64 ], iAccess, iCallback; menu_item_getinfo( strMenu, iKey, iAccess, strData, 5, strPlayerName, 63, iCallback ); new iTarget = str_to_num( strData ); if( !iTarget || iTarget == iPlayerID ) { client_print( iPlayerID, print_chat, "[SM] You did not choose a valid target." ); g_bMenuUsed = false; return PLUGIN_HANDLED; } static strReporterName[ 32 ], strTargetName[ 32 ], strSteamID[ 32 ], strIP[ 16 ]; get_user_name( iPlayerID, strReporterName, 31 ); get_user_name( iTarget, strTargetName, 31 ); get_user_authid( iTarget, strSteamID, 31 ); get_user_ip( iTarget, strIP, 15 ); static strMessage[ 128 ]; formatex( strMessage, 127, "%s has reported %s (steam: %s - IP: %s) for cheating.", strPlayerName, strTargetName, strSteamID, strIP ); log_to_file( g_strLogFile, strMessage ); Add_To_Db(iTarget); return PLUGIN_HANDLED; }
|