Raised This Month: $ Target: $400
 0% 

SQL help?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-06-2013 , 17:03   SQL help?
Reply With Quote #1

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.
__________________

Last edited by n0br41ner; 02-06-2013 at 17:15.
n0br41ner is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 02-07-2013 , 13:47   Re: SQL help?
Reply With Quote #2

So you wants us to do it to SQL? Then post code.
Torge is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-07-2013 , 15:18   Re: SQL help?
Reply With Quote #3

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.
__________________
n0br41ner is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 02-07-2013 , 17:00   Re: SQL help?
Reply With Quote #4

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;


Last edited by Torge; 02-08-2013 at 18:16. Reason: Updated (again).
Torge is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-08-2013 , 17:19   Re: SQL help?
Reply With Quote #5

Thank you very much, I really appreciate your help.

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

Again, thank you very much.
__________________
n0br41ner is offline
Torge
Veteran Member
Join Date: Oct 2011
Old 02-08-2013 , 17:38   Re: SQL help?
Reply With Quote #6

No problem.

Code updated cuz I missed a symbol..
Torge is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-08-2013 , 17:47   Re: SQL help?
Reply With Quote #7

Thank you again.
I will try and read that piece of code and try to figure out how things work . I'll read it 10 times if i have to.
__________________
n0br41ner is offline
Reply



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 20:32.


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