AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL help? (https://forums.alliedmods.net/showthread.php?t=207777)

n0br41ner 02-06-2013 17:03

SQL help?
 
Hello,

I need help with SQL. I have a plugin that saves information to a file, more precisely it saves NAME - STEAM ID - IP of a player. Not every player, just the ones that are reported.

But I would really like to know how to save them to an SQL or whatever it is called so i can view them on my website. Any help?

Regards,
n0br41ner

eDIT:
Ok i am reading this thread atm, just found it.

But i doubt i will instantly know how to use it, so any help is also appreciated.
Thanks again.

Torge 02-07-2013 13:47

Re: SQL help?
 
So you wants us to do it to SQL? Then post code.

n0br41ner 02-07-2013 15:18

Re: SQL help?
 
PHP Code:

/*Cheater Log*/

//////////////
// Includes //
//////////////
#include < amxmodx >

///////////////
// Constants //
///////////////
new const g_strVersion[ ]    = "0.0.1";
new const 
g_strLogFile[ ]    = "CheaterReport.log";

///////////////
// Variables //
///////////////
// Integers
new g_iMaxPlayers;

// Boleans
new g_bMenuUsed;

/////////////////
// Plugin Init //
/////////////////
public plugin_init( ) {
    
register_plugin"Cheater Log"g_strVersion"n0br41ner" );
    
    
register_clcmd"say /cheater""ClCmd_CheaterReport" );
    
    
g_iMaxPlayers get_maxplayers( );
}

//////////////
// Commands //
//////////////
public ClCmd_CheaterReportiPlayerID ) {
    if( 
g_bMenuUsed ) {
        
client_printiPlayerIDprint_chat"[SM] The menu is being used by another player." );
        return 
PLUGIN_HANDLED;
    }
    
    
g_bMenuUsed true;
    
    static 
strMenuTitle128 ];
    
formatexstrMenuTitle127"\yChose The Cheater:^n\rNote: his name, steam id and ip will be logged^n" );
    
    new 
strMenu menu_createstrMenuTitle"Handle_CheaterReport" );
    
    static 
strPlayerName32 ], strNumber];
    
    for( new 
iLoop 0iLoop <= g_iMaxPlayersiLoop++ ) {
        
get_user_nameiLoopstrPlayerName31 );
        
num_to_striLoopstrNumber);
        
        
menu_additemstrMenustrPlayerNamestrNumber );
    }
    
    
menu_setpropstrMenuMPROP_NUMBER_COLOR"\y" );
    
menu_displayiPlayerIDstrMenu );
    
    return 
PLUGIN_HANDLED;
}

public 
Handle_CheaterReportiPlayerIDstrMenuiKey ) {
    if( 
iKey == MENU_EXIT ) {
        
menu_destroystrMenu );
        
g_bMenuUsed false;
        return 
PLUGIN_HANDLED;
    }
    
    static 
strData], strPlayerName64 ], iAccessiCallback;
    
menu_item_getinfostrMenuiKeyiAccessstrData5strPlayerName63iCallback );
    
    new 
iTarget str_to_numstrData );
    
    if( !
iTarget || iTarget == iPlayerID ) {
        
client_printiPlayerIDprint_chat"[SM] You did not choose a valid target." );
        
g_bMenuUsed false;
        return 
PLUGIN_HANDLED;
    }
    
    static 
strReporterName32 ], strTargetName32 ], strSteamID32 ], strIP16 ];
    
get_user_nameiPlayerIDstrReporterName31 );
    
get_user_nameiTargetstrTargetName31 );
    
get_user_authidiTargetstrSteamID31 );
    
get_user_ipiTargetstrIP15 );
    
    static 
strMessage128 ];
    
formatexstrMessage127"%s has reported %s (steam: %s - IP: %s) for cheating."strPlayerNamestrTargetNamestrSteamIDstrIP );
    
log_to_fileg_strLogFilestrMessage );
    
    return 
PLUGIN_HANDLED;


Thank you.

Torge 02-07-2013 17:00

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_hostszHostcharsmax(szHost));
    
get_pcvar_string(cvar_sql_userszUsercharsmax(szUser));
    
get_pcvar_string(cvar_sql_passszPasscharsmax(szPass));
    
get_pcvar_string(cvar_sql_dbszDbcharsmax(szDb));
    
    
g_SqlTuple SQL_MakeDbTuple(szHostszUserszPassszDb);
    
    new 
Errcode,
    
Handle:SqlConnection SQL_Connect(g_SqlTupleErrcodeg_szErrorcharsmax(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(Queryg_szErrorcharsmax(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(idszNamecharsmax(szName));
    
get_user_authid(idszAuthIDcharsmax(szAuthID));
    
get_user_ip(idszIpcharsmax(szIp), 1);
    
    new 
szQuery[256];
    
formatex(szQuerycharsmax(szQuery), "INSERT INTO cheaterlog (nick, steamid, ip) VALUES ('%s', '%s', '%s')"szNameszAuthIDszIp);
    
    
SQL_ThreadQuery(g_SqlTuple"Query_Handler"szQuery);
}

public 
Query_Handler(FailStateHandle:QueryError[], ErrcodeData[], 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_CheaterReportiPlayerID ) {
    if( 
g_bMenuUsed ) {
        
client_printiPlayerIDprint_chat"[SM] The menu is being used by another player." );
        return 
PLUGIN_HANDLED;
    }
    
    
g_bMenuUsed true;
    
    static 
strMenuTitle128 ];
    
formatexstrMenuTitle127"\yChose The Cheater:^n\rNote: his name, steam id and ip will be logged^n" );
    
    new 
strMenu menu_createstrMenuTitle"Handle_CheaterReport" );
    
    static 
strPlayerName32 ], strNumber];
    
    for( new 
iLoop 0iLoop <= g_iMaxPlayersiLoop++ ) {
        
get_user_nameiLoopstrPlayerName31 );
        
num_to_striLoopstrNumber);
        
        
menu_additemstrMenustrPlayerNamestrNumber );
    }
    
    
menu_setpropstrMenuMPROP_NUMBER_COLOR"\y" );
    
menu_displayiPlayerIDstrMenu );
    
    return 
PLUGIN_HANDLED;
}

public 
Handle_CheaterReportiPlayerIDstrMenuiKey ) {
    if( 
iKey == MENU_EXIT ) {
        
menu_destroystrMenu );
        
g_bMenuUsed false;
        return 
PLUGIN_HANDLED;
    }
    
    static 
strData], strPlayerName64 ], iAccessiCallback;
    
menu_item_getinfostrMenuiKeyiAccessstrData5strPlayerName63iCallback );
    
    new 
iTarget str_to_numstrData );
    
    if( !
iTarget || iTarget == iPlayerID ) {
        
client_printiPlayerIDprint_chat"[SM] You did not choose a valid target." );
        
g_bMenuUsed false;
        return 
PLUGIN_HANDLED;
    }
    
    static 
strReporterName32 ], strTargetName32 ], strSteamID32 ], strIP16 ];
    
get_user_nameiPlayerIDstrReporterName31 );
    
get_user_nameiTargetstrTargetName31 );
    
get_user_authidiTargetstrSteamID31 );
    
get_user_ipiTargetstrIP15 );
    
    static 
strMessage128 ];
    
formatexstrMessage127"%s has reported %s (steam: %s - IP: %s) for cheating."strPlayerNamestrTargetNamestrSteamIDstrIP );
    
log_to_fileg_strLogFilestrMessage );
    
    
Add_To_Db(iTarget);
    
    return 
PLUGIN_HANDLED;



n0br41ner 02-08-2013 17:19

Re: SQL help?
 
Thank you very much, I really appreciate your help.

I will test as soon as I get my hands on the technician guy :D
Will reply as when this is tested.

Again, thank you very much.

Torge 02-08-2013 17:38

Re: SQL help?
 
No problem.

Code updated cuz I missed a symbol..

n0br41ner 02-08-2013 17:47

Re: SQL help?
 
Thank you again.
I will try and read that piece of code and try to figure out how things work :D. I'll read it 10 times if i have to.


All times are GMT -4. The time now is 20:32.

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