This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[REQ] Report command with sql.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Artizy
Member
Join Date: Jun 2011
Location: Milan, Italy.
Old 11-01-2016 , 13:23   [REQ] Report command with sql.
Reply With Quote #1

Hello, i need a plugin, when someone write in chat /report, send to sql database name of player reporter and HOSTNAME.
Artizy is offline
Artizy
Member
Join Date: Jun 2011
Location: Milan, Italy.
Old 11-02-2016 , 12:52   Re: [REQ] Report command with sql.
Reply With Quote #2

Code:
#include <amxmodx>
#include <sqlx>


#define PLUGINNAME    "Report system"
#define VERSION        "1.0"
#define AUTHOR        "addinol"
#define table           "amx_report_log"

new Handle:g_SqlX
new Handle:g_SqlConnection
new g_error[512]

new bool:alreadyreported[33] = false;

public plugin_init()
{
    register_plugin(PLUGINNAME, VERSION, AUTHOR)

    register_clcmd("say", "hook_say")
    register_clcmd("say_team", "hook_say")
    set_task(0.1, "check_sql")
    return PLUGIN_CONTINUE 
}

public check_sql()
{

    new host[64], user[64], pass[64], db[64],errorcode

    get_cvar_string("amx_sql_host", host, 63)
    get_cvar_string("amx_sql_user", user, 63)
    get_cvar_string("amx_sql_pass", pass, 63)
    get_cvar_string("amx_sql_db", db, 63)

    g_SqlX = SQL_MakeDbTuple(host, user, pass, db)
    g_SqlConnection = SQL_Connect(g_SqlX,errorcode,g_error,511);
  
    if (!g_SqlConnection) {
        return log_amx("Chat log SQL: Could not connect to SQL database.")
    }
    
    new query_create[1001]
    format(query_create,1000,"CREATE TABLE IF NOT EXISTS `%s`(`id` int(11) NOT NULL auto_increment,`name` varchar(100) NOT NULL default '',`authid` varchar(100) NOT NULL default '',`ip` varchar(100) NOT NULL default ''`date` date NOT NULL default '0000-00-00',`time` time NOT NULL default '00:00:00', `message` text NOT NULL,PRIMARY KEY  (`id`));",table)
    SQL_ThreadQuery(g_SqlX,"QueryHandle",query_create)
    
    return PLUGIN_CONTINUE 
}

public hook_say(id) 
{
    if(is_user_bot(id)){
    return PLUGIN_CONTINUE;
    }
    
    static datestr[11]
    new authid[16],name[32],ip[16],timestr[9]
    new cmd[9] 
    
    if(!is_user_connected(id)){
    return PLUGIN_CONTINUE;
    }
    
    read_argv(0,cmd,8) 
    
    new message[192] 
    read_args(message,191)
    remove_quotes(message)
    if(containi(message, "/report")){
        if(alreadyreported[id]){
        client_print(id, print_chat, "Reportinti galima tik kas 5 minutes")
    }else{
        get_user_authid(id,authid,15)  
        get_user_name(id,name,31)
        get_user_ip(id, ip, 15, 1)
         
        get_time("%Y.%m.%d", datestr, 10)
        get_time("%H:%M:%S", timestr, 8)
    
        new query[1001]
        format(query,1000,"INSERT into %s (name,authid,ip,date,time,message) values ('%s','%s','%s','%s','%s','%s')",table,name,authid,ip,datestr,timestr,message) 
        SQL_ThreadQuery(g_SqlX,"QueryHandle",query)
        alreadyreported[id] = true;
        set_task(300.0, "report0", id)
    }
    return PLUGIN_HANDLED_MAIN;
    }
    return PLUGIN_HANDLED;
} 

public report0(id){
    alreadyreported[id] = false;
}

public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)
    return log_amx("Chat log SQL: Could not connect to SQL database.")
    
    else if(FailState == TQUERY_QUERY_FAILED)
        return log_amx("Chat log SQL: Query failed")
        
    if(Errcode)
        return log_amx("Chat log SQL: Error on query: %s",Error)
    
    return PLUGIN_CONTINUE
}

public plugin_end() 
{ 
    SQL_FreeHandle(g_SqlConnection)
    return;
}
Can someone fix tis plugin ?
Artizy 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 09:45.


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