|
Junior Member
|

03-02-2006
, 15:45
|
#3
|
Well, i've got the same errors with this plugin (SQLBAN for AMXX), that should work right? Approved plugin.
See below SQLBAN (amxbans.sma)
Code:
/*
*
* Mysql Ban Management for STEAM
*
* Author: kaksi
* Email: <a href="mailto:[email protected]">[email protected]</a>
* Web: <a href="http://www.gbgonline.net/" target="_blank" rel="nofollow noopener">http://www.gbgonline.net/</a>
*
* Thanks to:
* JustinHoMi - A lot of code comes from his MySQL Ban Management plugin
* n1ghtmr - I got a lot of inspiration from his MYSQL Ban control - By Wonid/ip and Rcon plugin
* Neurosis - Beta testing and debugging
*
* INSTALLATION
*
* ->Create the database by using the schema below
* ->Add the following line to amx.cfg with you database info:
*
* amx_sqlban_host "127.0.0.1" - Adress to the SQL server
* amx_sqlban_user "root" - SQL Server username
* amx_sqlban_pass "" - SQL server password
* amx_sqlban_db "amx" - The database where you created the table
*
* -> Compile the plugin and put in amx plugin folder
* -> Add the plugin to plugins.ini
* -> Restart you server and you are good to go
*
*
* INSTRUCTIONS
*
* You can only ban players that are on the server
*
* Ban EITHER SteamID or IP adress by typing:
* amx_ban1 <time> <name, userid, or ip> <reason>
* If ban is entered by name or userid the player is banned by steamid
* If ban is entered by IP adress the player is banned by ipaddres
*
* Ban BOTH SteamID AND IP Adress by typing:
* xban <time> <name, userid or ip> <reason>
* If ban is enterd by name, userid or IP BOTH SteamID AND IP adress will be banned
*
*/
/* SQL Schema
CREATE TABLE `xbans` (
`player_steamid` varchar(100) NOT NULL default '',
`player_name` varchar(100) NOT NULL default '',
`player_ip` varchar(100) NOT NULL default '',
`reason` varchar(128) NOT NULL default '',
`bantype` varchar(50) NOT NULL default '',
`admin_steamid` varchar(100) NOT NULL default '',
`admin_name` varchar(100) NOT NULL default '',
`admin_ip` varchar(100) NOT NULL default '',
`length` int(10) unsigned NOT NULL default '0',
`time_created` timestamp(14) NOT NULL,
`server` varchar(25) NOT NULL default '',
PRIMARY KEY (`player_steamid`)
) TYPE=MyISAM;
*/
#include <amxmodx>
#include <amxmisc>
#include <dbi>
new Sql :sql
new merror [128]
new mhost [64]
new muser [32]
new mpass [32]
new mdb [32]
new server [128]
//------------------------------------------------- START Plugin initilize ----------------------------------------//
public plugin_init (){
register_plugin("SQLBan Mgr", "0.1", "kaksi")
register_concmd("amx_ban", "sql_ban",ADMIN_BAN, "<mins> <nick|userid|> [reason]")
register_cvar("amx_sqlban_host", "127.0.0.1")
register_cvar("amx_sqlban_user", "user")
register_cvar("amx_sqlban_pass", "pass")
register_cvar("amx_sqlban_db", "amx")
register_cvar("amx_sqlban_prefix", "")
return PLUGIN_CONTINUE
}
//------------------------------------------------- END Plugin initilize ----------------------------------------//
//------------------------------------------------- START CONNECT TO DATABASAE ----------------------------------------//
public sql_init (){
//Get server and database info...
get_cvar_string("hostname",server, 127)
get_cvar_string("amx_sql_host",mhost, 64)
get_cvar_string("amx_sql_user",muser, 32)
get_cvar_string("amx_sql_pass",mpass, 32)
get_cvar_string("amx_sql_db",mdb, 32)
sql = dbi_connect (mhost,muser,mpass,mdb,merror, 128)
if(sql < = SQL_FAILED )
server_print("[AMXX][SQLBAN] MySQL error: could not connect : '%s'",merror )
else
server_print("[AMXX][SQLBAN] Successfully connected to the database.")
return PLUGIN_CONTINUE
}
//------------------------------------------------- END CONNECT TO DATABASAE ----------------------------------------//
//------------------------------------------------- START Player Connects Player ----------------------------------------//
public client_connect (id ){
new parm [1]
parm [0] = id
//Delay check, wait for steamid to be set
set_task(5.0, "check_delayed", 0,parm, 1)
return PLUGIN_HANDLED
}
//------------------------------------------------- End Player connects Player ----------------------------------------//
//------------------------------------------------- START Delayed check connecting player ----------------------------------------//
public check_delayed (parm []){
//Load database connection function
sql_init ()
//Get connecting clients steamid and ipadress
new client_steamid [40]
get_user_authid(parm [0],client_steamid, 50)
new client_ip [16]
get_user_ip(parm [0],client_ip, 15, 1)
new client_name [40]
get_user_name(parm [0],client_name, 40)
//Send a message to the server that a check is starting
server_print("[AMXX][SQLBAN] Checking if %s is in the databaase.",client_name )
//Format the database querry
new query [256]
format(query, 255, "SELECT player_steamid,player_ip,reason,bantype,length,now()-time_created FROM xbans WHERE player_steamid='%s' OR player_ip='%s'",client_steamid,client_ip )
//Execute querry
dbi_query (mysql,query )
new merror [64]
dbi_error (mysql,merror, 63)
//If an error occured
if (merror [0]){
server_print("[AMXX][SQLBAN] MYSQL error: %s",merror )
return PLUGIN_CONTINUE
}
//If a player was found in the database, fetch data and define
if(dbi_nextrow (mysql )> 0){
new player_steamid [40],player_ip [20],reason [128],bantype [50],ban_length_s [10],ban_time_s [32]
dbi_field (mysql, 1,player_steamid, 39)
dbi_field (mysql, 2,player_ip, 19)
dbi_field (mysql, 3,reason, 127)
dbi_field (mysql, 4,bantype, 49)
dbi_field (mysql, 5,ban_length_s, 9)
dbi_field (mysql, 6,ban_time_s, 31)
//Get the new ban_lengt and bantime
new ban_length = str_to_num(ban_length_s )
new ban_time = str_to_num(ban_time_s )
//If the players bantime isn't up...
if ((ban_time < ban_length ) || (ban_length == 0)){
//If the ban_length is permanent, format the time message
new time_msg [32]
if (ban_length == 0){
time_msg = "Permanent"
}
//If the time is not permanent, format the time message
else{
new ban_left = (ban_length - ban_time ) / 60
format(time_msg, 31, "%i minutes",ban_left )
}
//If the player is banned by steamid, send a message and disconnect the player
if(equal(bantype, "steamid")){
//Check if the players SteamID is the same as in the dataase
if(equal(client_steamid,player_steamid )){
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Your SteamID has been banned from this server. ^"")
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(parm [0], "disconnect")
server_print("servern hittade steamid i databasen")
return PLUGIN_CONTINUE
}
}
//If the player is banned by IP, send a message and disconnect the player
if(equal(bantype, "ip")){
//Check if the players ip adress is the same as in the database
if(equal(client_ip,player_ip )){
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Your IP adress has been banned from this server. ^"")
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(parm [0], "disconnect")
return PLUGIN_CONTINUE
}
}
//If the player is banned by BOTH SteamID and IP Adress, send a message and disconnect the player
if(equal(bantype, "all")){
//Check if The players steamid is the same as in the database
if(equal(client_steamid,player_steamid )){
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Your SteamID and IP Adress has been banned from this server. ^"")
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(parm [0], "disconnect")
server_print("servern hittade steamid i databasen")
return PLUGIN_CONTINUE
}
//If the steamid doesnt math then check if the ip adress match
else if(equal(client_ip,player_ip )){
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Your SteamID and IP Adress has been banned from this server. ^"")
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(parm [0], "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(parm [0], "disconnect")
server_print("servern hittade steamid i databasen")
return PLUGIN_CONTINUE
}
}
}
//If the bantime has expired
else{
//Remove the expired ban from the database
//Format the querry
format(query, 255, "DELETE from xbans where player_steamid='%s'",client_steamid )
//Execute the querry
dbi_query (mysql,query )
dbi_error (mysql,merror, 63)
//If an error uccures
if (merror [0]){
server_print("[AMXX][SQLBAN] MYSQL error: %s",merror )
return PLUGIN_HANDLED
}
//If the expired ban is removed completely
else{
console_print(parm [0], "[AMXX][SQLBAN] Ban on steamid %s removed.",client_steamid )
}
}
}
//If player wasn't in the database...
else{
server_print("[AMXX][SQLBAN] %s wans't in the database. Let him in...",client_name )
}
return PLUGIN_CONTINUE
}
//------------------------------------------------- END Delayed check connecting player ----------------------------------------//
//------------------------------------------------- START Ban Player by SteamID OR IP Adress ----------------------------------------//
public sql_ban (id,level,cid ){
//Load database connection function
sql_init ()
//If the player you are trying to ban has admin rights the stop
if (!cmd_access(id,level,cid, 4))
return PLUGIN_HANDLED
//Define the player identifier and read it from the given command
new player_ident [40]
read_argv(2,player_ident, 39)
//Define the bantype variable
new bantype [20]
//See if you can find a matching player by nickname
new player = find_player("bl",player_ident )
//If a player was found, check to see if there are more than one match
if (player ){
new player2 = find_player("blj",player_ident )
//If more than one match, then stop
if (player !=player2 ){
console_print(id, "There are more than one players matching your argument.")
return PLUGIN_CONTINUE
}
//If all went well and only one player was found, set bantype to steamid
bantype = "steamid"
}
//If no player was found by nickname, check if there is a match with userid
if (!player && player_ident [0]=='#' && player_ident [1])
player = find_player("k", str_to_num(player_ident [1]))
//If there was a player match with userid set bantype to steamid
bantype = "steamid"
//If no matching player with userid either, then check if there is a match with IP adress
if (!player ){
player = find_player("d",player_ident )
//If there was a match with IP adress set bantype to IP
bantype = "ip"
}
//If no match was found, abort...
if (!player ){
console_print(id, "Client with that authid, nick, userid, or ip not found.")
return PLUGIN_CONTINUE
}
//Make sure we don't ban bots
if (is_user_bot(player )){
new imname [32]
get_user_name(player,imname, 31)
console_print(id, "You can not ban bots.")
return PLUGIN_CONTINUE
}
//Get ban length and convert to seconds
new ban_length_s [10],ban_length_s2 [10]
read_argv(1,ban_length_s, 9)
new multiplier = 60
new carg
if(contain(ban_length_s, "h") != -1){
multiplier = 60 * 60
carg = 'h'
}else
if(contain(ban_length_s, "d") != -1){
multiplier = 60 * 60 * 24
carg = 'd'
}else
if(contain(ban_length_s, "w") != -1){
multiplier = 60 * 60 * 24 * 7
carg = 'w'
}
copyc(ban_length_s2, 9,ban_length_s,carg )
new ban_length = str_to_num(ban_length_s2 ) * multiplier
//Get reason and get ready to format it
new text [64],temp [10],temp2 [33]
read_args(text, 63)
parse(text,temp, 9,temp2, 32)
new length1 = strlen(temp )
new length2 = strlen(temp2 )
new length = length1 + length2
length +=2
new reason [64]
read_args(reason, 63)
//Get user and admin info to put in table
new player_steamid [40],player_name [33],player_ip [20],admin_steamid [40],admin_name [33],admin_ip [20]
get_user_authid(player,player_steamid, 39)
get_user_name(player,player_name, 32)
get_user_ip(player,player_ip, 19, 1)
get_user_authid(id,admin_steamid, 39)
get_user_name(id,admin_name, 32)
get_user_ip(id,admin_ip, 19, 1)
//Format the query
new query [512]
format(query, 511, "INSERT into xbans (player_steamid,player_name,player_ip,reason,bantype,admin_steamid,admin_name,admin_ip,length,server) values('%s','%s','%s','%s','%s','%s','%s','%s','%i','%s')",player_steamid,player_name,player_ip,reason [length ],bantype,admin_steamid,admin_name,admin_ip,ban_length,server )
// connect to database and insert data
dbi_query (mysql,query )
new merror [64]
dbi_error (mysql,merror, 63)
//If an error uccures
if (merror [0]){
server_print("[AMXX][SQLBAN] MYSQL error: %s",merror )
return PLUGIN_HANDLED
}
// convert ban length back to minutes for display
ban_length = ban_length / 60
//Print ban to server
console_print(id, "[AMXX][SQLBAN] Banning %s for %i",player_name,ban_length )
//Format time message
new time_msg [32]
//If the ban length is 0 (permanent)
if (ban_length == 0)
time_msg = "Permanent"
//Else, formate the time message
else
format(time_msg, 31, "%i minutes",ban_length )
//If the user is banned by steamid, print the message to the user
if(equal(bantype, "steamid")){
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Your SetamID has been banned from this server. ^"")
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(player, "disconnect")
return PLUGIN_CONTINUE
}
//If the user is banned by IP, print the message to the user
if(equal(bantype, "ip")){
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Your IP adress has been banned from this server. ^"")
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Reason : %s. ^"",reason )
client_cmd(player, "echo ^"[AMXX ][SQLBAN ] Time left : %s. ^"",time_msg )
client_cmd(player, "disconnect")
return PLUGIN_CONTINUE
}
//If there is a database connection, close it
if (mysql > 0)
dbi_close (mysql )
return PLUGIN_HANDLED
}
//------------------------------------------------- END Ban Player by SteamID OR IP Adress ----------------------------------------//
//If there is a database connection, close it
if (mysql > 0)
dbi_close (mysql )
return PLUGIN_HANDLED
}
//------------------------------------------------- END Ban Player by BOTH SteamID AND IP Adress ----------------------------------------//
|
|