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


Raised This Month: $12 Target: $400
 3% 

[help] report with sql.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Artizy
Member
Join Date: Jun 2011
Location: Milan, Italy.
Old 11-03-2016 , 12:08   [help] report with sql.
Reply With Quote #1

Can someone fix this plugin ? Is not working

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;
}
Artizy is offline
Solokiller
Senior Member
Join Date: Sep 2015
Old 11-04-2016 , 05:57   Re: [help] report with sql.
Reply With Quote #2

Can you be more specific than "Is not working"?
Solokiller is offline
Infest
Member
Join Date: Mar 2005
Old 11-04-2016 , 07:22   Re: [help] report with sql.
Reply With Quote #3

Change this line:

PHP Code:
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
to this:

PHP Code:
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
edit; there is lots more wrong with this plugin, this was poorly coded.

replace your hook_say function with this:

PHP Code:
public hook_say(id
{
    if((
is_user_bot(id)) || (!is_user_connected(id)))
    {
        return 
PLUGIN_CONTINUE;
    }

    static 
datestr[11], authid[16], name[32], ip[16], timestr[9]

    new 
sBuffer[256], sBuffer1[32]

    
read_argv(1sBuffercharsmax(sBuffer))
    
parse(sBuffersBuffer1charsmax(sBuffer1))

    if(
equali(sBuffer1"/report"))
    {
        if(
alreadyreported[id])
        {
            
client_print(idprint_chat"Reportinti galima tik kas 5 minutes")
            return 
PLUGIN_CONTINUE
        
}
        else
        {
            
get_user_authid(id,authid,15)  
            
get_user_name(id,name,31)
            
get_user_ip(idip151)

            
get_time("%Y.%m.%d"datestr10)
            
get_time("%H:%M:%S"timestr8)

            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,sBuffer[7]) 
            
SQL_ThreadQuery(g_SqlX,"QueryHandle",query)
            
alreadyreported[id] = true;
            
set_task(300.0"report0"id)

            
client_print(idprint_chat"You have successfully submitted a report.")
            return 
PLUGIN_HANDLED;
        }
    }

    return 
PLUGIN_CONTINUE;


Last edited by Infest; 11-04-2016 at 07:39.
Infest is offline
Artizy
Member
Join Date: Jun 2011
Location: Milan, Italy.
Old 11-04-2016 , 13:13   Re: [help] report with sql.
Reply With Quote #4

Quote:
Originally Posted by Infest View Post
Change this line:

PHP Code:
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
to this:

PHP Code:
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
edit; there is lots more wrong with this plugin, this was poorly coded.

replace your hook_say function with this:

PHP Code:
public hook_say(id
{
    if((
is_user_bot(id)) || (!is_user_connected(id)))
    {
        return 
PLUGIN_CONTINUE;
    }

    static 
datestr[11], authid[16], name[32], ip[16], timestr[9]

    new 
sBuffer[256], sBuffer1[32]

    
read_argv(1sBuffercharsmax(sBuffer))
    
parse(sBuffersBuffer1charsmax(sBuffer1))

    if(
equali(sBuffer1"/report"))
    {
        if(
alreadyreported[id])
        {
            
client_print(idprint_chat"Reportinti galima tik kas 5 minutes")
            return 
PLUGIN_CONTINUE
        
}
        else
        {
            
get_user_authid(id,authid,15)  
            
get_user_name(id,name,31)
            
get_user_ip(idip151)

            
get_time("%Y.%m.%d"datestr10)
            
get_time("%H:%M:%S"timestr8)

            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,sBuffer[7]) 
            
SQL_ThreadQuery(g_SqlX,"QueryHandle",query)
            
alreadyreported[id] = true;
            
set_task(300.0"report0"id)

            
client_print(idprint_chat"You have successfully submitted a report.")
            return 
PLUGIN_HANDLED;
        }
    }

    return 
PLUGIN_CONTINUE;

Is working, thank you man !
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 22:14.


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