AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help: A small bansync script (ala AMXBans) using SQL (https://forums.alliedmods.net/showthread.php?t=25994)

Skarbo 03-25-2006 07:37

Help: A small bansync script (ala AMXBans) using SQL
 
arcticgaming.no is a norewegian CS community with about 10 servers. We are trying to sync our ban lists by using SQL. We have used AMXBans but found out that 90% of the scripting is useless (and crashed our servers sometimes).

Here is the script so far:
Code:
#include <amxmodx> #include <dbi> #include <amxmisc> #define TIME_BEFORE_KICK 20.0 #define MAXPLAYERS 32 new Sql:dbc new Result:result new agError[36] new bool:arctic_sql = false new bool:arctic_con = false new bool:arctic_kick = false new arctic_ban = 0 new ag_BlockPlayer[MAXPLAYERS+1] public plugin_init() {     register_plugin("Arcticbans", "0.1", "ArcticGaming")     set_task(Float:10.0,"sql_init")     register_concmd("arctic_ban","ag_ban",ADMIN_BAN,"<nickname | steamid> [minutes] [reason]")     register_srvcmd("arctic_ban","ag_ban",-1,"<nickname | steamid> [minutes] [reason]") } public sql_init() {     new host[64], username[32], password[32], dbname[32], error[32]         get_cvar_string("amx_sql_host",host,64)     get_cvar_string("amx_sql_user",username,32)     get_cvar_string("amx_sql_pass",password,32)     get_cvar_string("amx_sql_db",dbname,32)         dbc = dbi_connect(host,username,password,dbname,error,32)         if (dbc == SQL_FAILED)         {         log_amx("[ArcticBans] SQL Connection Failed (MySQL ArcticBans plugin)")         arctic_sql = false         dbi_close(dbc)         return     }     dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `arctic_bans` (`bid` INT( 0 ) NOT NULL AUTO_INCREMENT, `steamid` TEXT NOT NULL, `nick` TEXT NOT NULL, `ip` TEXT NOT NULL, `reason` TEXT NOT NULL, `cur_time` INT(90) NOT NULL, `length` INT( 0 ) NOT NULL, `admin` TEXT NOT NULL, `server` TEXT NOT NULL, PRIMARY KEY ( `bid` ))")     arctic_sql = true     return } public ag_ban (id, level, cid) {     /* Check access, sql and arguments */     if (!cmd_access(id,level,cid,1)) {         client_print(id, print_console, "[ArcticBans] CMD access error")         return PLUGIN_HANDLED     }     if (dbc == SQL_FAILED) {         client_print(id, print_console, "[ArcticBans] SQL Failed")         return PLUGIN_HANDLED     }     if (read_argc() < 2)         {         client_print(id,print_console,"Usage: arctic_ban <nickname | steamid> [minutes] [reason]")         return PLUGIN_HANDLED     }         /* variables */     new player_id[34]   // player steamid or nickname     new player_id2[34]     new ban_length[90]  // ban length     new ban_length2[90]     new ban_reason[120] // ban reason     new player_steamid[50]  // player steamid     new player_nick[100]    // player nick     new player_ip[50]   // player ip         /* Split Arguments */     read_argv(1, player_id, 34)     read_argv(2, ban_length, 90)     read_argv(3, ban_reason, 120)     ban_length2[0] = str_to_num(ban_length) // string to number         /* check if its steamid or nickname */     player_id2[0] = find_player("cl",player_id) // checks steamid, ignore C.S.         if (!player_id2[0])         {         player_id2[0] = find_player("bl",player_id) // check part nickname, ignore case s.     }         if (player_id2[0]) {         if (get_user_flags(player_id2[0])&ADMIN_IMMUNITY)             {             client_print(id,print_console,"[ArcticBan] Player has immunity")             return PLUGIN_HANDLED         }         else if (is_user_bot(player_id2[0]))             {             client_print(id,print_console,"[ArcticBan] Player is a bot")             return PLUGIN_HANDLED         }         else if (is_user_hltv(player_id2[0]))             {             client_print(id,print_console,"[ArcticBan] Player is HLTV")             return PLUGIN_HANDLED         }         /* GET PLAYER INFO */         get_user_authid(player_id2[0], player_steamid, 50)         get_user_name(player_id2[0], player_nick, 100)         get_user_ip(player_id2[0], player_ip, 50, 1)                 arctic_con = true// continue with saving     }     else {         client_print(id,print_console,"Could not find %s^nUsage: arctic_ban <nickname | steamid> [minutes] [reason]", player_id)     }         /* GET ADMIN INFO AND SAVE TO SQL */     if (arctic_con) {                 /* variables */         new admin_steamid[34]   // admin steamid         new server_ip[32]                   /* get info */         get_user_authid(id , admin_steamid , 34)    // admin steamid         get_cvar_string("ip", server_ip, 32)    // server ip                 /* Insert into SQL */         sql_ban(id,player_id2[0],admin_steamid[0],server_ip[0],player_steamid[0],player_nick[0],player_ip[0],ban_length2[0],ban_reason[0])             }     return PLUGIN_HANDLED } /* SQL BAN */ public sql_ban (id,player_id2,admin_steamid[],server_ip[],player_steamid[],player_nick[],player_ip[],ban_length2[],ban_reason[]) {         new cur_time = get_systime(0)   // systemtime         client_print(id,print_console,"id %d - player_id2 %d ^nadmin_steamid %s - server_ip %s - cur_time %i", id, player_id2, admin_steamid, server_ip, cur_time)     client_print(id,print_console,"player_steamid %s - player_nick %s ^nplayer_ip %s - ban_length %d - ban_reason %s",player_steamid, player_nick, player_ip, ban_length2, ban_reason)         if (equal(player_steamid,"STEAM_ID_LAN")) {         /* lan steamid, only save IP */         result = dbi_query(dbc,"INSERT INTO arctic_bans (nick,ip,reason,cur_time,length,admin,server) VALUES('%s','%s','%s',%i,'%d','%s','%s')",         player_nick, player_ip, ban_reason, cur_time, ban_length2, admin_steamid, server_ip)     }     else {         /* internett */     }         /* INSERT THE SQL */     if(result == RESULT_FAILED) {         dbi_error(dbc,agError,125)         server_print("[ArcticBans] Couldn't insert new row.^nError:^n^"%s^"^n",agError)         server_print("[ArcticBans] Stopping continuation of Command Logging.")         client_print(id, print_chat, "[ArcticBans] Error inserting SQL row")     }     dbi_free_result(result)     dbi_close(dbc)         /* KICK AND BAN PLAYER */     client_print(0, print_chat, "[ArcticBans] Banning ^"%s^" for %d minutes.", player_nick, ban_length2)     server_cmd("kick #%d ^nYou are BANNED for %d minutes.^nReason: %s.",get_user_userid(player_id2),ban_length2,ban_reason)         return PLUGIN_CONTINUE } public client_putinserver(id)     {     new player_steamid[35], player_ip[50]     get_user_authid(id,player_steamid,34)     get_user_ip(id, player_ip, 50, 1)     if(task_exists(id))         remove_task(id)         /* KICK PLAYER IF STEAM PENDING */     if(equal(player_steamid,"STEAM_ID_PENDING"))         {         set_task(TIME_BEFORE_KICK,"Task_CheckAuthId",id,_,_,"a",1)         ag_BlockPlayer[id] = 1         client_print(id,print_chat,"For some reason your steamid has not been authenticaded, you will be kicked within 20 seconds")     }     /* CHECK IF BANNED */     else {                 new player_steamid[35], player_ip[50], query[1024]         get_user_authid(id,player_steamid,34)         get_user_ip(id, player_ip, 50, 1)                 if (equal(player_steamid,"STEAM_ID_LAN")) {             /* IF LAN */             format(query,1024,"SELECT * FROM arctic_bans WHERE ip='%s'", player_ip)         }         else {             //         }         result = dbi_query(dbc,query)                 /* THIS IS WHERE IM STUCK */             } } /* KICK PLAYER IF STEAM PENDING */ public Task_CheckAuthId(id)     {     new Authid[35]     get_user_authid(id,Authid,34)       if(equal(Authid,"STEAM_ID_PENDING"))         {         ag_BlockPlayer[id] = 0         new Name[32],IP[40]         get_user_name(id,Name,31)         get_user_ip(id,IP,39)                 client_print(0,print_chat,"[ArcticBans] %s was kicked for having STEAM_ID_PENDING",Name)         log_amx("%s (IP: %s ) was kicked for having STEAM_ID_PENDING",Name,IP)         server_cmd("kick #%d Because of STEAM_ID_PENDING",get_user_userid(id))     } }

Error
Code:

[MYSQL] Invalid database handle 0
[AMXX] Displaying debug trace (plugin "arcticbans.amxx")
[AMXX] Run time error 10: native error (native "dbi_query")
[AMXX]    [0] arcticbans.sma::Task_CheckUser (line 200)

Code:
new player_steamid[35], player_ip[50], query[1024]         get_user_authid(id,player_steamid,34)         get_user_ip(id, player_ip, 50, 1)                 if (equal(player_steamid,"STEAM_ID_LAN")) {             /* IF LAN */             format(query,1024,"SELECT * FROM arctic_bans WHERE ip='%s'", player_ip)         }         else {             //         } Line 200:       result = dbi_query(dbc,query)

Quote:

Q: I get "Run time error 10!"
A: This an error that is extremely vague. It usually means a function failed to operate the way it should, or that there is a logic error in a plugin. For example, if a plugin tries to access a MySQL connection that does not exist, you will get a run time error 10. You should contact the plugin author to let him know what's failing.
I am able to ban players and inserting it to SQL works.
I need help with checking the SQL when the player joins the server. Notice "/* THIS IS WHERE IM STUCK */" in client_putinserver(id)

And, while i got ur attention. When the player joins the server it checks if he is banned. If he is banned check the length of the ban and compare it with current time. I need help with that also.

Thx!

GHW_Chronic 03-25-2006 07:51

its obviously going into the else statement
Code:
        if (equal(player_steamid,"STEAM_ID_LAN")) {         else {

so thus you are then trying to send a blank query to MySQL. Put it in the if statement.

And you have
Code:
new query[1024] format(query,1024,"SELECT * FROM arctic_bans WHERE ip='%s'", player_ip)
should be
Code:
format(query,1023,"SELECT * FROM arctic_bans WHERE ip='%s'", player_ip)
and also 1024 characters long might be a bit too long for this. I would use 64:
Code:
new query[64] format(query,63,"SELECT * FROM arctic_bans WHERE ip='%s'", player_ip)

Skarbo 03-26-2006 10:33

Thanks but its still not working, same error.
Its on a local computer btw and local SQL with all privileges.

-- edit
changed the SQL
Code:
dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `arctic_bans` (`bid` INT( 11 ) NOT NULL AUTO_INCREMENT, `steamid` VARCHAR( 50 ), `nick` VARCHAR( 100 ), `ip` VARCHAR( 100 ), `reason` VARCHAR( 255 ), `cur_time` INT( 11 ) NOT NULL, `length` VARCHAR( 100 ) DEFAULT '0' NOT NULL, `admin` VARCHAR( 50 ), `server` VARCHAR( 100 ), PRIMARY KEY ( `bid` ))")

-- edit2
Ok figured out the problem, when i restarted the server i had a client that joined the server right away and the SQL username, password etc. dint get the time to load..

What i need help with now
Now i have to write either arctic_ban [steamid] or [nickname], how can i do it with #[userid]? (like all the other amx commands: amx_slay #[userid])

If the player is banned it checks the length and compares it with the current time, and kicks him if he is still banned.


All times are GMT -4. The time now is 16:44.

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