Support to amx_addban command

Here we can discuss suggestions and development of amxbans.
Nothing discussed in here are certain that it will be coded or added.
YamiKaitou
Amxbans Developer
Posts: 257
Joined: 17 Apr 2013, 14:09

Re: Support to amx_addban command

Postby YamiKaitou » 19 Nov 2013, 01:15

Feel free to add it as a Pull Request, though I prefer it to be added to the existing amx_ban command (if possible) and the extra options trashed (ie, removed as they are pointless).

kryder11
Posts: 5
Joined: 14 Jan 2014, 17:25

Re: Support to amx_addban command

Postby kryder11 » 18 Jan 2014, 22:25

Hello, I have a question for the aditional part of code that zp_ shared with us. How I can make to print the reason in console when the player is banned using amx_addban because only print in console. (You are banned. Check your console!!!) but no print the reason, steamid, name of admin...

CoLd-
Posts: 1
Joined: 25 Dec 2015, 03:02

Re: Support to amx_addban command

Postby CoLd- » 25 Dec 2015, 03:08

zp_ wrote:Since I just could not get amx_ban to ban steamid's or ip's of disconnected players to work at all for me, I decided to quickly throw together an amx_addban function that doesn't check if the player is in the server.

in cmdBan.inl

Code: Select all

public cmdAddBan(id, level, cid)
{
    /* Checking if the admin has the right access */
    if (!cmd_access(id,level,cid,3))
        return PLUGIN_HANDLED

    new text[256]
    read_args(text, 255)

    enum _:PlayerData
    {
        iPlrID,
        szName[32],
        szIP[20],
        szAuthID[35]
    }
    new chData[PlayerData]

    // get player ident and bantime depending on the ban cmd format (old or new)
    new ban_length[50]
    new plr_name[32]
    new plr_ip[20]

    parse(text, g_ident, charsmax(g_ident), ban_length, charsmax(ban_length), g_choiceReason[id], charsmax(g_choiceReason[]), plr_name, charsmax(plr_name), plr_ip, charsmax(plr_ip))

    trim(g_ident)
    trim(ban_length)
    trim(g_choiceReason[id])
    remove_quotes(g_choiceReason[id])
    trim(plr_name)
    remove_quotes(plr_name)
    trim(plr_ip)

    // Check so the ban command has the right format
    if( !is_str_num(ban_length) || read_argc() < 3 )
    {
        client_print(id,print_console,"[AMXBans] %L",LANG_PLAYER,"AMX_BAN_SYNTAX_NEW")
        return PLUGIN_HANDLED
    }

    //if the reason is empty use the default ban reason from cvar
    if(!strlen(g_choiceReason[id])) {
        get_pcvar_string(pcvar_default_banreason,g_choiceReason[id],charsmax(g_choiceReason[]))
    }

    // if player name is empty , use unknown
    if (!strlen(plr_name))
        plr_name = "unknown"

    g_choiceTime[id] = abs(str_to_num(ban_length))
    new cTimeLength[128]
    if (g_choiceTime[id] > 0)
        get_time_length(id, g_choiceTime[id], timeunit_minutes, cTimeLength, 127)
    else
        format(cTimeLength, 127, "%L", LANG_PLAYER, "TIME_ELEMENT_PERMANENTLY")

    // This stops admins from banning perm in console if not adminflag n
    if(!(get_user_flags(id) & get_higher_ban_time_admin_flag()) && g_choiceTime[id] == 0)
    {
        client_print(id,print_console,"[AMXBans] %L",LANG_PLAYER,"NOT_BAN_PERMANENT")
        return PLUGIN_HANDLED
    }

    chData[iPlrID] = id
    copy(chData[szName], charsmax(chData[szName]), plr_name)

    new pquery[1024]

    if (equal(g_ident, "STEAM_", 6))
    {
        formatex(pquery, charsmax(pquery), "SELECT player_id FROM %s%s WHERE player_id='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

        copy(chData[szAuthID], charsmax(chData[szAuthID]), g_ident)
        copy(chData[szIP], charsmax(chData[szIP]), plr_ip)
        g_ban_type[id] = "S"
    }
    else
    {
        formatex(pquery, charsmax(pquery), "SELECT player_ip FROM %s%s WHERE player_ip='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

        copy(chData[szIP], charsmax(chData[szIP]), g_ident)
        g_ban_type[id] = "SI"
    }

    SQL_ThreadQuery(g_SqlX, "cmd_addban_", pquery, chData, sizeof(chData))

    return PLUGIN_HANDLED
}

public cmd_addban_(failstate, Handle:query, error[], errnum, data[], size)
{
    enum
    {
        iPlrID,
        szName[32],
        szIP[20],
        szAuthID[35]
    }

    new id = data[iPlrID]
    new plr_name[32]
    new plr_ip[20]
    new plr_id[35]

    copy(plr_name, charsmax(plr_name), data[szName])
    copy(plr_ip, charsmax(plr_ip), data[szIP])
    copy(plr_id, charsmax(plr_id), data[szAuthID])

    new bool:serverCmd = false
    /* Determine if this was a server command or a command issued by a player in the game */
    if ( id == 0 )
        serverCmd = true

    if (failstate)
    {
        new szQuery[256]
        SQL_GetQueryString(query,szQuery,255)
        MySqlX_ThreadError( szQuery, error, errnum, failstate, 6 )
    }
    else
    {
        if (!SQL_NumResults(query))
        {
            new admin_nick[100], admin_steamid[50], admin_ip[20]
            mysql_get_username_safe(id, admin_nick, 99)
            get_user_ip(id, admin_ip, 19, 1)

            if (!serverCmd)
            {
                get_user_authid(id, admin_steamid, 49)

                if ( get_pcvar_num(pcvar_debug) >= 1 )
                    log_amx("[AMXBans cmdBan] Adminsteamid: %s, Servercmd: %s", admin_steamid, (serverCmd)?"Yes":"No")
            }
            else
            {
                /* If the server does the ban you cant get any steam_ID or team */
                admin_steamid = ""

                /* This is so you can have a shorter name for the servers hostname.
                Some servers hostname can be very long b/c of sponsors and that will make the ban list on the web bad */
                new servernick[100]
                get_pcvar_string(pcvar_server_nick, servernick, 99)
                if (strlen(servernick))
                    copy(admin_nick,charsmax(admin_nick),servernick)
            }

            /* If HLGUARD ban, the admin nick will be set to [HLGUARD] */
            if ( contain(g_choiceReason[id], "[HLGUARD]") != -1 )
                copy(admin_nick,charsmax(admin_nick),"[HLGUARD]")

            /* If ATAC ban, the admin nick will be set to [ATAC] */
            if ( contain(g_choiceReason[id], "Max Team Kill Violation") != -1 )
                copy(admin_nick,charsmax(admin_nick),"[ATAC]")

            if ( get_pcvar_num(pcvar_debug) >= 1 )
                log_amx("[AMXBans cmdBan] Admin nick: %s, Admin userid: %d", admin_nick, get_user_userid(id))

            new server_name[200]
            mysql_get_servername_safe(server_name, charsmax(server_name))

            if ( get_pcvar_num(pcvar_add_mapname) ) {
                new mapname[32]//, pre[4],post[4]
                get_mapname(mapname,31)
                format(server_name,charsmax(server_name),"%s (%s)",server_name,mapname)
            }

            new player_nick[64]
            mysql_escape_string(g_choicePlayerName[id],player_nick,charsmax(player_nick))
            new admin_nick_safe[200]
            mysql_escape_string(admin_nick,admin_nick_safe,charsmax(admin_nick_safe))

            new pquery[1024]

            format(pquery, charsmax(pquery), "INSERT INTO `%s%s` \
                (player_id, player_ip, player_nick, admin_ip, admin_id, admin_nick, ban_type, ban_reason, ban_created, ban_length, server_name, server_ip, expired) \
                VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', UNIX_TIMESTAMP(NOW()), %d, '%s', '%s:%s', 0)", \
                g_dbPrefix, tbl_bans, plr_id, plr_ip, plr_name, admin_ip, admin_steamid, admin_nick, g_ban_type[id], \
                g_choiceReason[id], g_choiceTime[id], server_name, g_ip, g_port)

            new data[3]
            data[0] = id
            SQL_ThreadQuery(g_SqlX, "insert_bandetails", pquery, data, 3)
        }
    }

    return PLUGIN_HANDLED
}


and amxbans_main.sma

Code: Select all

register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<steamID or IP> <time in mins> <reason> <name> <ip>")
register_srvcmd("amx_addban", "cmdAddBan", -1, "<steamID or IP> <time in mins> <reason> <name> <ip>")


above

Code: Select all

register_concmd("amx_unban", "cmdUnban", ADMIN_BAN, "<steamID or IP>");


format is: amx_addban <steamid/ip> <time in minutes> <reason> <name> <ip>

<name> and <ip> are optional to set players name (name defaults to "unknown" if name argument is empty) and ip (ip will automatically fill in if it's an ip ban) ... initial testing suggests that it works, though the code could be more optimized (for example it still says "Player not found: SteamID/IP" in console when banning a steamid or ip address, even though it still goes through and shows up on the banlist)

There are also no checks for client immunity or anything of that sort... (i check this in my plugin that needs to directly ban a disconnected player's steamid or ip)



Hello. Your tutorial have some bugs... so i modified that command and maked with some verifications and was tested. For me work 100% perfectly and used amxmodx 1.8.1

amxbans_main.amxx

Code: Select all

   register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<steamID or IP> <time in mins> <reason> <name> <ip>")
   register_srvcmd("amx_addban", "cmdAddBan", -1, "<steamID or IP> <time in mins> <reason> <name> <ip>")


cmdBan.inl

Code: Select all

public cmdAddBan(id, level, cid) {
   /* Checking if the admin has the right access */
   if (!cmd_access(id,level,cid,3))
      return PLUGIN_HANDLED

   new text[128]
   read_args(text, 127)

   enum _:PlayerData { iPlrID, szName[32], szIP[20], szAuthID[35], szMotiv[128] }
   new chData[PlayerData]

   // get player ident and bantime depending on the ban cmd format (old or new)
   new ban_length[50]
   new plr_name[32]
   new motivBan[128]
   new plr_ip[20]

   parse(text, g_ident, charsmax(g_ident), ban_length, charsmax(ban_length), motivBan, charsmax(motivBan), plr_name, charsmax(plr_name), plr_ip, charsmax(plr_ip))

   trim(g_ident)
   trim(ban_length)
   trim(motivBan)
   remove_quotes(motivBan)
   trim(plr_name)
   remove_quotes(plr_name)
   trim(plr_ip)

   // Check so the ban command has the right format
   if( !is_str_num(ban_length) || read_argc() < 3 ) {
      client_print(id,print_console,"[CSBans] amx_addban <steamID or IP> <time in mins> <reason> <name> <ip>")
      return PLUGIN_HANDLED
   }

   // if rason is empty, give error to complet it
   if (!strlen(motivBan)) {
      client_print(id, print_console, "[CSBans] Eroare la motivul banului. Nu lasa motivul gol.")
      return PLUGIN_HANDLED
   }

   // if player name is empty , use unknown
   if (!strlen(plr_name)) {
      plr_name = "unknown"
   }

   chData[iPlrID] = id
   copy(chData[szName], charsmax(chData[szName]), plr_name)

   new pquery[1024]

   if (equal(g_ident, "STEAM_", 6) || equal(g_ident, "VALVE_", 6)) {
   //if (containi(g_ident, "STEAM_") || contain(g_ident, "VALVE_")) {
      formatex(pquery, charsmax(pquery), "SELECT player_id FROM %s%s WHERE player_id='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

      copy(chData[szAuthID], charsmax(chData[szAuthID]), g_ident)
      copy(chData[szIP], charsmax(chData[szIP]), plr_ip)
      copy(chData[szMotiv], charsmax(chData[szMotiv]), motivBan)
      g_ban_type[id] = "SI"
   } else {
      formatex(pquery, charsmax(pquery), "SELECT player_ip FROM %s%s WHERE player_ip='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

      copy(chData[szIP], charsmax(chData[szIP]), g_ident)
      copy(chData[szMotiv], charsmax(chData[szMotiv]), motivBan)
      g_ban_type[id] = "IP"
   }


   //client_print(id,print_console,"DEBUG: IDENT: %s | LEGHT: %s | %s | %s | %s",g_ident, ban_length, motivBan, plr_name, plr_ip)
   SQL_ThreadQuery(g_SqlX, "cmd_addban_", pquery, chData, sizeof(chData))

   return PLUGIN_HANDLED
}

public cmd_addban_(failstate, Handle:query, error[], errnum, data[], size) {
   enum { iPlrID, szName[32], szIP[20], szAuthID[35], szMotiv[128] }

   new id = data[iPlrID]
   new plr_name[32]
   new plr_ip[20]
   new plr_id[35]
   new motivBan[128]

   copy(plr_name, charsmax(plr_name), data[szName])
   copy(plr_ip, charsmax(plr_ip), data[szIP])
   copy(plr_id, charsmax(plr_id), data[szAuthID])
   copy(motivBan, charsmax(motivBan), data[szMotiv])

   new bool:serverCmd = false

   /* Determine if this was a server command or a command issued by a player in the game */
   if ( id == 0 )
      serverCmd = true

   if (failstate) {
      new szQuery[256]
      SQL_GetQueryString(query,szQuery,255)
      MySqlX_ThreadError( szQuery, error, errnum, failstate, 6 )
   } else {
      if (!SQL_NumResults(query)) {
         new admin_nick[100], admin_steamid[50], admin_ip[20]
         mysql_get_username_safe(id, admin_nick, 99)
         get_user_ip(id, admin_ip, 19, 1)

         if (!serverCmd) {
            get_user_authid(id, admin_steamid, 49)

            if ( get_pcvar_num(pcvar_debug) >= 1 )
               log_amx("[AMXBans cmdBan] Adminsteamid: %s, Servercmd: %s", admin_steamid, (serverCmd)?"Yes":"No")
         } else {
            /* If the server does the ban you cant get any steam_ID or team */
            admin_steamid = ""

            /* This is so you can have a shorter name for the servers hostname.
            Some servers hostname can be very long b/c of sponsors and that will make the ban list on the web bad */
            new servernick[100]
            get_pcvar_string(pcvar_server_nick, servernick, 99)
            if (strlen(servernick))
               copy(admin_nick,charsmax(admin_nick),servernick)
         }

         /* If HLGUARD ban, the admin nick will be set to [HLGUARD] */
         if ( contain(g_choiceReason[id], "[HLGUARD]") != -1 )
            copy(admin_nick,charsmax(admin_nick),"[HLGUARD]")

         /* If ATAC ban, the admin nick will be set to [ATAC] */
         if ( contain(g_choiceReason[id], "Max Team Kill Violation") != -1 )
            copy(admin_nick,charsmax(admin_nick),"[ATAC]")

         if ( get_pcvar_num(pcvar_debug) >= 1 )
            log_amx("[AMXBans cmdBan] Admin nick: %s, Admin userid: %d", admin_nick, get_user_userid(id))

         new server_name[200]
         mysql_get_servername_safe(server_name, charsmax(server_name))

         if ( get_pcvar_num(pcvar_add_mapname) ) {
            new mapname[32]//, pre[4],post[4]
            get_mapname(mapname,31)
            format(server_name,charsmax(server_name),"%s (%s)",server_name,mapname)
         }

         new player_nick[64]
         mysql_escape_string(g_choicePlayerName[id],player_nick,charsmax(player_nick))
         new admin_nick_safe[200]
         mysql_escape_string(admin_nick,admin_nick_safe,charsmax(admin_nick_safe))


         if(!strlen(plr_ip)) {
            plr_ip = "0.0.0.0";
         }
         if(!strlen(plr_id)) {
            plr_id = "XXXX_0:0:00000000";
         }

         new pquery[1024]
         format(pquery, charsmax(pquery), "INSERT INTO `%s%s` \
                (player_id, player_ip, player_nick, admin_ip, admin_id, admin_nick, ban_type, ban_reason, ban_created, ban_length, server_name, server_ip, expired) \
                VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', UNIX_TIMESTAMP(NOW()), 0, '%s', '%s:%s', 0)", \
                g_dbPrefix, tbl_bans, plr_id, plr_ip, plr_name, admin_ip, admin_steamid, admin_nick, g_ban_type[id], \
                motivBan, server_name, g_ip, g_port)

         new data[3]
         data[0] = id
         SQL_ThreadQuery(g_SqlX, "insert_bandetails", pquery, data, 3)
      }
   }

   return PLUGIN_HANDLED
}


Add that code above public cmdBan(id, level, cid)

check_player.inl

Code: Select all

public prebanned_check(id) {
   if(is_user_bot(id) || id==0)
      return PLUGIN_HANDLED
   
   if(!get_pcvar_num(pcvar_show_prebanned))
      return PLUGIN_HANDLED
   
   if(get_user_flags(id) & ADMIN_IMMUNITY)
      return PLUGIN_HANDLED
   
   new player_steamid[35], player_ip[22], pquery[1024]
   get_user_authid(id, player_steamid, 34)
   get_user_ip(id, player_ip, 21, 1)

   //formatex(pquery, charsmax(pquery), "SELECT ban_created,admin_nick FROM `%s%s` WHERE ( (player_id='%s' AND ban_type='S') OR (player_ip='%s' AND ban_type='SI') ) AND expired=1",g_dbPrefix, tbl_bans, player_steamid, player_ip)
   formatex(pquery, charsmax(pquery), "SELECT COUNT(*) FROM `%s%s` WHERE ((player_id='%s' AND ban_type='S') OR (player_ip='%s' AND ban_type='SI')) AND expired=1",g_dbPrefix, tbl_bans, player_steamid, player_ip)
   
   new data[1]
   data[0] = id
   SQL_ThreadQuery(g_SqlX, "prebanned_check_", pquery, data, 1)
   
   return PLUGIN_HANDLED
}

replace your current code with that code.

That version it's improved.... i added that source code here because nowhere found amx_addban command for amxbans! :)
Have fun and thank you zp_

^vip^
Posts: 1
Joined: 11 Jan 2015, 16:31

Re: Support to amx_addban command

Postby ^vip^ » 27 Jan 2016, 22:18

CoLd- wrote:
zp_ wrote:Since I just could not get amx_ban to ban steamid's or ip's of disconnected players to work at all for me, I decided to quickly throw together an amx_addban function that doesn't check if the player is in the server.

in cmdBan.inl

Code: Select all

public cmdAddBan(id, level, cid)
{
    /* Checking if the admin has the right access */
    if (!cmd_access(id,level,cid,3))
        return PLUGIN_HANDLED

    new text[256]
    read_args(text, 255)

    enum _:PlayerData
    {
        iPlrID,
        szName[32],
        szIP[20],
        szAuthID[35]
    }
    new chData[PlayerData]

    // get player ident and bantime depending on the ban cmd format (old or new)
    new ban_length[50]
    new plr_name[32]
    new plr_ip[20]

    parse(text, g_ident, charsmax(g_ident), ban_length, charsmax(ban_length), g_choiceReason[id], charsmax(g_choiceReason[]), plr_name, charsmax(plr_name), plr_ip, charsmax(plr_ip))

    trim(g_ident)
    trim(ban_length)
    trim(g_choiceReason[id])
    remove_quotes(g_choiceReason[id])
    trim(plr_name)
    remove_quotes(plr_name)
    trim(plr_ip)

    // Check so the ban command has the right format
    if( !is_str_num(ban_length) || read_argc() < 3 )
    {
        client_print(id,print_console,"[AMXBans] %L",LANG_PLAYER,"AMX_BAN_SYNTAX_NEW")
        return PLUGIN_HANDLED
    }

    //if the reason is empty use the default ban reason from cvar
    if(!strlen(g_choiceReason[id])) {
        get_pcvar_string(pcvar_default_banreason,g_choiceReason[id],charsmax(g_choiceReason[]))
    }

    // if player name is empty , use unknown
    if (!strlen(plr_name))
        plr_name = "unknown"

    g_choiceTime[id] = abs(str_to_num(ban_length))
    new cTimeLength[128]
    if (g_choiceTime[id] > 0)
        get_time_length(id, g_choiceTime[id], timeunit_minutes, cTimeLength, 127)
    else
        format(cTimeLength, 127, "%L", LANG_PLAYER, "TIME_ELEMENT_PERMANENTLY")

    // This stops admins from banning perm in console if not adminflag n
    if(!(get_user_flags(id) & get_higher_ban_time_admin_flag()) && g_choiceTime[id] == 0)
    {
        client_print(id,print_console,"[AMXBans] %L",LANG_PLAYER,"NOT_BAN_PERMANENT")
        return PLUGIN_HANDLED
    }

    chData[iPlrID] = id
    copy(chData[szName], charsmax(chData[szName]), plr_name)

    new pquery[1024]

    if (equal(g_ident, "STEAM_", 6))
    {
        formatex(pquery, charsmax(pquery), "SELECT player_id FROM %s%s WHERE player_id='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

        copy(chData[szAuthID], charsmax(chData[szAuthID]), g_ident)
        copy(chData[szIP], charsmax(chData[szIP]), plr_ip)
        g_ban_type[id] = "S"
    }
    else
    {
        formatex(pquery, charsmax(pquery), "SELECT player_ip FROM %s%s WHERE player_ip='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

        copy(chData[szIP], charsmax(chData[szIP]), g_ident)
        g_ban_type[id] = "SI"
    }

    SQL_ThreadQuery(g_SqlX, "cmd_addban_", pquery, chData, sizeof(chData))

    return PLUGIN_HANDLED
}

public cmd_addban_(failstate, Handle:query, error[], errnum, data[], size)
{
    enum
    {
        iPlrID,
        szName[32],
        szIP[20],
        szAuthID[35]
    }

    new id = data[iPlrID]
    new plr_name[32]
    new plr_ip[20]
    new plr_id[35]

    copy(plr_name, charsmax(plr_name), data[szName])
    copy(plr_ip, charsmax(plr_ip), data[szIP])
    copy(plr_id, charsmax(plr_id), data[szAuthID])

    new bool:serverCmd = false
    /* Determine if this was a server command or a command issued by a player in the game */
    if ( id == 0 )
        serverCmd = true

    if (failstate)
    {
        new szQuery[256]
        SQL_GetQueryString(query,szQuery,255)
        MySqlX_ThreadError( szQuery, error, errnum, failstate, 6 )
    }
    else
    {
        if (!SQL_NumResults(query))
        {
            new admin_nick[100], admin_steamid[50], admin_ip[20]
            mysql_get_username_safe(id, admin_nick, 99)
            get_user_ip(id, admin_ip, 19, 1)

            if (!serverCmd)
            {
                get_user_authid(id, admin_steamid, 49)

                if ( get_pcvar_num(pcvar_debug) >= 1 )
                    log_amx("[AMXBans cmdBan] Adminsteamid: %s, Servercmd: %s", admin_steamid, (serverCmd)?"Yes":"No")
            }
            else
            {
                /* If the server does the ban you cant get any steam_ID or team */
                admin_steamid = ""

                /* This is so you can have a shorter name for the servers hostname.
                Some servers hostname can be very long b/c of sponsors and that will make the ban list on the web bad */
                new servernick[100]
                get_pcvar_string(pcvar_server_nick, servernick, 99)
                if (strlen(servernick))
                    copy(admin_nick,charsmax(admin_nick),servernick)
            }

            /* If HLGUARD ban, the admin nick will be set to [HLGUARD] */
            if ( contain(g_choiceReason[id], "[HLGUARD]") != -1 )
                copy(admin_nick,charsmax(admin_nick),"[HLGUARD]")

            /* If ATAC ban, the admin nick will be set to [ATAC] */
            if ( contain(g_choiceReason[id], "Max Team Kill Violation") != -1 )
                copy(admin_nick,charsmax(admin_nick),"[ATAC]")

            if ( get_pcvar_num(pcvar_debug) >= 1 )
                log_amx("[AMXBans cmdBan] Admin nick: %s, Admin userid: %d", admin_nick, get_user_userid(id))

            new server_name[200]
            mysql_get_servername_safe(server_name, charsmax(server_name))

            if ( get_pcvar_num(pcvar_add_mapname) ) {
                new mapname[32]//, pre[4],post[4]
                get_mapname(mapname,31)
                format(server_name,charsmax(server_name),"%s (%s)",server_name,mapname)
            }

            new player_nick[64]
            mysql_escape_string(g_choicePlayerName[id],player_nick,charsmax(player_nick))
            new admin_nick_safe[200]
            mysql_escape_string(admin_nick,admin_nick_safe,charsmax(admin_nick_safe))

            new pquery[1024]

            format(pquery, charsmax(pquery), "INSERT INTO `%s%s` \
                (player_id, player_ip, player_nick, admin_ip, admin_id, admin_nick, ban_type, ban_reason, ban_created, ban_length, server_name, server_ip, expired) \
                VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', UNIX_TIMESTAMP(NOW()), %d, '%s', '%s:%s', 0)", \
                g_dbPrefix, tbl_bans, plr_id, plr_ip, plr_name, admin_ip, admin_steamid, admin_nick, g_ban_type[id], \
                g_choiceReason[id], g_choiceTime[id], server_name, g_ip, g_port)

            new data[3]
            data[0] = id
            SQL_ThreadQuery(g_SqlX, "insert_bandetails", pquery, data, 3)
        }
    }

    return PLUGIN_HANDLED
}


and amxbans_main.sma

Code: Select all

register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<steamID or IP> <time in mins> <reason> <name> <ip>")
register_srvcmd("amx_addban", "cmdAddBan", -1, "<steamID or IP> <time in mins> <reason> <name> <ip>")


above

Code: Select all

register_concmd("amx_unban", "cmdUnban", ADMIN_BAN, "<steamID or IP>");


format is: amx_addban <steamid/ip> <time in minutes> <reason> <name> <ip>

<name> and <ip> are optional to set players name (name defaults to "unknown" if name argument is empty) and ip (ip will automatically fill in if it's an ip ban) ... initial testing suggests that it works, though the code could be more optimized (for example it still says "Player not found: SteamID/IP" in console when banning a steamid or ip address, even though it still goes through and shows up on the banlist)

There are also no checks for client immunity or anything of that sort... (i check this in my plugin that needs to directly ban a disconnected player's steamid or ip)



Hello. Your tutorial have some bugs... so i modified that command and maked with some verifications and was tested. For me work 100% perfectly and used amxmodx 1.8.1

amxbans_main.amxx

Code: Select all

   register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<steamID or IP> <time in mins> <reason> <name> <ip>")
   register_srvcmd("amx_addban", "cmdAddBan", -1, "<steamID or IP> <time in mins> <reason> <name> <ip>")


cmdBan.inl

Code: Select all

public cmdAddBan(id, level, cid) {
   /* Checking if the admin has the right access */
   if (!cmd_access(id,level,cid,3))
      return PLUGIN_HANDLED

   new text[128]
   read_args(text, 127)

   enum _:PlayerData { iPlrID, szName[32], szIP[20], szAuthID[35], szMotiv[128] }
   new chData[PlayerData]

   // get player ident and bantime depending on the ban cmd format (old or new)
   new ban_length[50]
   new plr_name[32]
   new motivBan[128]
   new plr_ip[20]

   parse(text, g_ident, charsmax(g_ident), ban_length, charsmax(ban_length), motivBan, charsmax(motivBan), plr_name, charsmax(plr_name), plr_ip, charsmax(plr_ip))

   trim(g_ident)
   trim(ban_length)
   trim(motivBan)
   remove_quotes(motivBan)
   trim(plr_name)
   remove_quotes(plr_name)
   trim(plr_ip)

   // Check so the ban command has the right format
   if( !is_str_num(ban_length) || read_argc() < 3 ) {
      client_print(id,print_console,"[CSBans] amx_addban <steamID or IP> <time in mins> <reason> <name> <ip>")
      return PLUGIN_HANDLED
   }

   // if rason is empty, give error to complet it
   if (!strlen(motivBan)) {
      client_print(id, print_console, "[CSBans] Eroare la motivul banului. Nu lasa motivul gol.")
      return PLUGIN_HANDLED
   }

   // if player name is empty , use unknown
   if (!strlen(plr_name)) {
      plr_name = "unknown"
   }

   chData[iPlrID] = id
   copy(chData[szName], charsmax(chData[szName]), plr_name)

   new pquery[1024]

   if (equal(g_ident, "STEAM_", 6) || equal(g_ident, "VALVE_", 6)) {
   //if (containi(g_ident, "STEAM_") || contain(g_ident, "VALVE_")) {
      formatex(pquery, charsmax(pquery), "SELECT player_id FROM %s%s WHERE player_id='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

      copy(chData[szAuthID], charsmax(chData[szAuthID]), g_ident)
      copy(chData[szIP], charsmax(chData[szIP]), plr_ip)
      copy(chData[szMotiv], charsmax(chData[szMotiv]), motivBan)
      g_ban_type[id] = "SI"
   } else {
      formatex(pquery, charsmax(pquery), "SELECT player_ip FROM %s%s WHERE player_ip='%s' AND expired=0", g_dbPrefix, tbl_bans, g_ident)

      copy(chData[szIP], charsmax(chData[szIP]), g_ident)
      copy(chData[szMotiv], charsmax(chData[szMotiv]), motivBan)
      g_ban_type[id] = "IP"
   }


   //client_print(id,print_console,"DEBUG: IDENT: %s | LEGHT: %s | %s | %s | %s",g_ident, ban_length, motivBan, plr_name, plr_ip)
   SQL_ThreadQuery(g_SqlX, "cmd_addban_", pquery, chData, sizeof(chData))

   return PLUGIN_HANDLED
}

public cmd_addban_(failstate, Handle:query, error[], errnum, data[], size) {
   enum { iPlrID, szName[32], szIP[20], szAuthID[35], szMotiv[128] }

   new id = data[iPlrID]
   new plr_name[32]
   new plr_ip[20]
   new plr_id[35]
   new motivBan[128]

   copy(plr_name, charsmax(plr_name), data[szName])
   copy(plr_ip, charsmax(plr_ip), data[szIP])
   copy(plr_id, charsmax(plr_id), data[szAuthID])
   copy(motivBan, charsmax(motivBan), data[szMotiv])

   new bool:serverCmd = false

   /* Determine if this was a server command or a command issued by a player in the game */
   if ( id == 0 )
      serverCmd = true

   if (failstate) {
      new szQuery[256]
      SQL_GetQueryString(query,szQuery,255)
      MySqlX_ThreadError( szQuery, error, errnum, failstate, 6 )
   } else {
      if (!SQL_NumResults(query)) {
         new admin_nick[100], admin_steamid[50], admin_ip[20]
         mysql_get_username_safe(id, admin_nick, 99)
         get_user_ip(id, admin_ip, 19, 1)

         if (!serverCmd) {
            get_user_authid(id, admin_steamid, 49)

            if ( get_pcvar_num(pcvar_debug) >= 1 )
               log_amx("[AMXBans cmdBan] Adminsteamid: %s, Servercmd: %s", admin_steamid, (serverCmd)?"Yes":"No")
         } else {
            /* If the server does the ban you cant get any steam_ID or team */
            admin_steamid = ""

            /* This is so you can have a shorter name for the servers hostname.
            Some servers hostname can be very long b/c of sponsors and that will make the ban list on the web bad */
            new servernick[100]
            get_pcvar_string(pcvar_server_nick, servernick, 99)
            if (strlen(servernick))
               copy(admin_nick,charsmax(admin_nick),servernick)
         }

         /* If HLGUARD ban, the admin nick will be set to [HLGUARD] */
         if ( contain(g_choiceReason[id], "[HLGUARD]") != -1 )
            copy(admin_nick,charsmax(admin_nick),"[HLGUARD]")

         /* If ATAC ban, the admin nick will be set to [ATAC] */
         if ( contain(g_choiceReason[id], "Max Team Kill Violation") != -1 )
            copy(admin_nick,charsmax(admin_nick),"[ATAC]")

         if ( get_pcvar_num(pcvar_debug) >= 1 )
            log_amx("[AMXBans cmdBan] Admin nick: %s, Admin userid: %d", admin_nick, get_user_userid(id))

         new server_name[200]
         mysql_get_servername_safe(server_name, charsmax(server_name))

         if ( get_pcvar_num(pcvar_add_mapname) ) {
            new mapname[32]//, pre[4],post[4]
            get_mapname(mapname,31)
            format(server_name,charsmax(server_name),"%s (%s)",server_name,mapname)
         }

         new player_nick[64]
         mysql_escape_string(g_choicePlayerName[id],player_nick,charsmax(player_nick))
         new admin_nick_safe[200]
         mysql_escape_string(admin_nick,admin_nick_safe,charsmax(admin_nick_safe))


         if(!strlen(plr_ip)) {
            plr_ip = "0.0.0.0";
         }
         if(!strlen(plr_id)) {
            plr_id = "XXXX_0:0:00000000";
         }

         new pquery[1024]
         format(pquery, charsmax(pquery), "INSERT INTO `%s%s` \
                (player_id, player_ip, player_nick, admin_ip, admin_id, admin_nick, ban_type, ban_reason, ban_created, ban_length, server_name, server_ip, expired) \
                VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', UNIX_TIMESTAMP(NOW()), 0, '%s', '%s:%s', 0)", \
                g_dbPrefix, tbl_bans, plr_id, plr_ip, plr_name, admin_ip, admin_steamid, admin_nick, g_ban_type[id], \
                motivBan, server_name, g_ip, g_port)

         new data[3]
         data[0] = id
         SQL_ThreadQuery(g_SqlX, "insert_bandetails", pquery, data, 3)
      }
   }

   return PLUGIN_HANDLED
}


Add that code above public cmdBan(id, level, cid)

check_player.inl

Code: Select all

public prebanned_check(id) {
   if(is_user_bot(id) || id==0)
      return PLUGIN_HANDLED
   
   if(!get_pcvar_num(pcvar_show_prebanned))
      return PLUGIN_HANDLED
   
   if(get_user_flags(id) & ADMIN_IMMUNITY)
      return PLUGIN_HANDLED
   
   new player_steamid[35], player_ip[22], pquery[1024]
   get_user_authid(id, player_steamid, 34)
   get_user_ip(id, player_ip, 21, 1)

   //formatex(pquery, charsmax(pquery), "SELECT ban_created,admin_nick FROM `%s%s` WHERE ( (player_id='%s' AND ban_type='S') OR (player_ip='%s' AND ban_type='SI') ) AND expired=1",g_dbPrefix, tbl_bans, player_steamid, player_ip)
   formatex(pquery, charsmax(pquery), "SELECT COUNT(*) FROM `%s%s` WHERE ((player_id='%s' AND ban_type='S') OR (player_ip='%s' AND ban_type='SI')) AND expired=1",g_dbPrefix, tbl_bans, player_steamid, player_ip)
   
   new data[1]
   data[0] = id
   SQL_ThreadQuery(g_SqlX, "prebanned_check_", pquery, data, 1)
   
   return PLUGIN_HANDLED
}

replace your current code with that code.

That version it's improved.... i added that source code here because nowhere found amx_addban command for amxbans! :)
Have fun and thank you zp_


Ok i use that all, worked ok but when i type only STEAM ID or if i know only IP i type amx_addban "steam id" "time" "reason" "name" And i see on web ban list but when i connected i not banned because "Ban type: SteamID and/or IP"
When i change on Steam ID than worked. What can be done to detect that no matter if you ban them on steam or ip? And thx for all

dhazz
Posts: 4
Joined: 27 May 2016, 20:57

Re: Support to amx_addban command

Postby dhazz » 27 May 2016, 21:01

Hy , i want addban but don't work


] amx_addban STEAM_0:0:25451381 1 test nk 79.112.126.239
] amx_addban
Usage: amx_addban <steamID or IP> <time in mins> <reason> <name> <ip>

register_concmd("amx_addban", "cmdAddBan", ADMIN_BAN, "<steamID or IP> <time in mins> <reason> <name> <ip>")
register_srvcmd("amx_addban", "cmdAddBan", -1, "<steamID or IP> <time in mins> <reason> <name> <ip>")

syntax :

parse(text, g_ident, charsmax(g_ident), ban_length, charsmax(ban_length), motivBan, charsmax(motivBan), plr_name, charsmax(plr_name), plr_ip, charsmax(plr_ip))


What can i do?

User avatar
indianiso1
Posts: 106
Joined: 16 Oct 2015, 01:59
Contact:

Re: Support to amx_addban command

Postby indianiso1 » 28 May 2016, 00:49

amx_addban " STEAM_0:0:25451381" 1 test nk "79.112.126.239"
use quotation marks -> "something_if_it's with space or _ or / etc."

dhazz
Posts: 4
Joined: 27 May 2016, 20:57

Re: Support to amx_addban command

Postby dhazz » 28 May 2016, 11:35

Don't work .....

User avatar
indianiso1
Posts: 106
Joined: 16 Oct 2015, 01:59
Contact:

Re: Support to amx_addban command

Postby indianiso1 » 27 Jun 2016, 20:16

what do you really want? SteamID banned or IP?

vikas
Posts: 15
Joined: 20 Nov 2016, 17:15

Re: Support to amx_addban command

Postby vikas » 23 Nov 2017, 11:48

Hi i want to add the amx_addban for my server. I tried the above code and the method but for some reason i am not able to compile the sma file. If anyone can provide me the sma and pre compiled file would be great.



Return to “Development and Suggestions”

Who is online

Users browsing this forum: No registered users and 3 guests