Raised This Month: $ Target: $400
 0% 

help blacklist system


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
liav319
Junior Member
Join Date: Mar 2009
Old 01-22-2013 , 07:15   Re: help blacklist system
Reply With Quote #3

PHP Code:
#define PLUGINNAME    "BlackList"
#define VERSION        "0.2"
#define AUTHOR         "JH


#include <amxmodx>
#include <dbi>
#include <amxmisc>
#include <engine>

// ---------- Adjust below settings to your liking ---------------------------------------
// nothing...
// ---------- Adjust above settings to your liking ---------------------------------------

#define CVAR_WHOST            "host"
#define CVAR_WUSER            "user"
#define CVAR_WPASS            "pass"
#define CVAR_WDB            "db"
#define CVAR_KICKNONREGGED    "kicknonregged"
#define CVAR_REGURL            "regurl"
#define CVAR_PREPEND        "prepend"
#define WWWREGTABLE            "listblack"

// Global vars below
new g_regged[33]
new 
g_names[33][32// Max length of name is 31
// Global vars above



public plugin_modules() {
    
require_module("engine")
    
require_module("dbi")
}
    


public 
client_authorized(id) {
    if (
is_user_bot(id))
        return 
PLUGIN_CONTINUE

    
const LEN 32

    
new authid[LEN 1], name[32]

    
get_user_authid(idauthidLEN)
    
get_user_name(idname31)

    
g_regged[id] = checkreg(authidname)

    if (
g_regged[id])
        
server_print("[%s] %s (%s) is registered."PLUGINNAMEnameauthid)
        if (
get_cvar_num(CVAR_KICKNONREGGED)) {
            new 
regurl[128]
            
get_cvar_string(CVAR_REGURLregurl127)
            
server_cmd("kick #%d your Steam ID %s is been blacklisted at %s ."get_user_userid(id), authidregurl
            else {
        
server_print("[%s] %s (%s) is not blacklisted."PLUGINNAMEnameauthid)
        }
    }

    return 
PLUGIN_CONTINUE
}


    
    
public 
client_infochanged(id) {
    if (
is_user_bot(id) || is_user_connecting(id))
        return 
PLUGIN_CONTINUE

    get_user_name
(idg_names[id], 31)
    new 
idd[1]
    
idd[0] = id
    set_task
(0.1"checkname"0idd1)

    return 
PLUGIN_CONTINUE
}

localtrim(stringtotrim[], const LENcharstotrim, const bool:FROMLEFT true) {
    if (
charstotrim <= 0)
        return

    if (
FROMLEFT) {
        new 
maxlen strlen(stringtotrim)
        if (
charstotrim maxlen)
            
charstotrim maxlen

        format
(stringtotrimLEN"%s"stringtotrim[charstotrim])
    }
    else {
        new 
maxlen strlen(stringtotrim) - charstotrim
        
if (maxlen 0)
            
maxlen 0

        format
(stringtotrimmaxlen"%s"stringtotrim)
    }
}

public 
checkname(idd[1]) {
    if (
is_user_bot(idd[0])) // Somehow some realbots slipped past the bot check in client_infochanged! :-(
        
return

    new 
name[32], prepend[32], prependlength
    get_user_name
(idd[0], name31)
    
get_cvar_string(CVAR_PREPENDprepend31)
    
prependlength strlen(prepend)
    if (
g_regged[idd[0]]) {
        
// Registered users shouldn't have names starting with CVAR_PREPEND
        // If length of set name is shorter than prepend string, user's name can't be prepend string. :-)
        
if (strlen(name) >= prependlength && equali(nameprependprependlength)) { // case insensitive...
            // Trim name prependlength chars from left
            
localtrim(name31prependlength)
            
entity_set_string(idd[0], EV_SZ_netnamename)
            
set_user_info(idd[0], "name"name)
            
client_print(idd[0], print_console"Sorry, you can't use the public prefix ^"%s^"in your name because you are blacklisted!"prepend)
        }
        if (!
equal(nameg_names[idd[0]])) {
            
// Update lastusedname in db if it changed
            
update_db_name(idd[0], name)
        }
    }
    else {
        if (!
equal(prependnamestrlen(prepend))) {
            
//server_print("Forcing Pub: name on %s", name)
            
format(name31"%s%s"prependname)
            
entity_set_string(idd[0], EV_SZ_netnamename)
            
set_user_info(idd[0], "name"name)
        }
    }
}

update_db_name(idname[32]) {
    const 
LEN 32
    
const LONGER 128
    
new authid[LEN 1], query[LONGER 1]

    
get_user_authid(idauthidLEN)

    new 
Sql:sql
    
if (!connect(sql)) {
        
log_amx("Error - Couldn't connect to SQL db and thus couldn't update %s to it."authid)
        return
    }

    
format(queryLONGER"UPDATE `%s` SET `lastactivity` = ^"%d^", `lastusedname` = ^"%s^" WHERE `steamid` = ^"%s^""WWWREGTABLEget_systime(), nameauthid)

    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while quering SQL server for update of %s: %s"authiderror)
    }

    
dbi_close(sql)
}

bool:checkreg(authid[], name[]) {
    new 
Sql:sql
    
if (!connect(sql))
        return 
false

    
const LONGER 128
    
new query[LONGER 1]

    
format(queryLONGER"SELECT `regtime` FROM %s WHERE `steamid` = ^"%s^" LIMIT 1"WWWREGTABLEauthid)
    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while quering SQL server for %s, can't check registration: %s"authiderror)
        
dbi_close(sql)
        return 
false
    
}
    else if (
result == RESULT_NONE) {
        
dbi_close(sql)
        return 
false
    
}

    if (!
dbi_nextrow(result)) {
        
dbi_close(sql)
        return 
false // not regged
    
}

    new 
regtime[64]
    
dbi_field(result1regtime63)
    
format_time(regtimesizeof regtime 1"%y%m%d - %H:%M:%S"str_to_num(regtime))

    
server_print("[%s] %s registered at %s"PLUGINNAMEauthidregtime)

    
format(queryLONGER"UPDATE `%s` SET `lastactivity` = ^"%d^", `lastusedname` = ^"%s^" WHERE `steamid` = ^"%s^""WWWREGTABLEget_systime(), nameauthid)

    
dbi_free_result(result)

    
result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while trying to update %s's (%s) reg info to SQL database. User is regged though."authiderror)
    }
    
dbi_close(sql)

    return 
true
}

bool:connect(&Sql:sql) {
    const 
LEN 128
    
new host[LEN], user[LEN], pass[LEN], db[LEN], error_msg[LEN]

    
get_cvar_string(CVAR_WHOSThostLEN 1)
    
get_cvar_string(CVAR_WUSERuserLEN 1)
    
get_cvar_string(CVAR_WPASSpassLEN 1)
    
get_cvar_string(CVAR_WDBdbLEN 1)

    
sql dbi_connect(hostuserpassdberror_msgLEN 1)

    if (!
sql) {
        
log_amx("ERROR - Can't connect to SQL db: %s"error_msg)
        return 
false
    
}

    return 
true
}

bool:createtable(&Sql:sql) {
    new 
query[1024] = "CREATE TABLE IF NOT EXISTS `%s` (`steamid` varchar(30) NOT NULL default '', `regtime` int(11) NOT NULL default '0', `lastactivity` int(11) default '0', `lastusedname` varchar(33) NOT NULL default '', PRIMARY KEY  (`steamid`)) TYPE=MyISAM;"
    
format(query1023queryWWWREGTABLE)

    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while trying to create tables: %s"error)
        return 
false
    
}

    return 
true
}



public 
plugin_init() {
    
register_plugin(PLUGINNAMEVERSIONAUTHOR)
    
register_cvar(CVAR_WHOST"localhost")
    
register_cvar(CVAR_WUSER"blist")
    
register_cvar(CVAR_WPASS"bpass")
    
register_cvar(CVAR_WDB"blacklist_23")

    
register_cvar(CVAR_KICKNONREGGED"1")
    
register_cvar(CVAR_REGURL"www.vsite.com")
    
register_cvar(CVAR_PREPEND"")

    new 
sqlcfgpath[128]
    
get_configsdir(sqlcfgpath127)
    
format(sqlcfgpath127"%s/sql.cfg"sqlcfgpath)
    
server_cmd("exec %s"sqlcfgpath)
    
server_exec()

    new 
Sql:sql
    
if (!connect(sql)) {
        
log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
        
pause("a")
        return
    }
    else if (!
createtable(sql)) {
        
log_amx("Failed creating tables in SQL database at plugin_init! Pausing plugin.")
        
pause("a")
        return
    }
    else
        
server_print("[%s] Connected successfully to SQL database."PLUGINNAME)
    
dbi_close(sql)

liav319 is offline
 



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:38.


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