diff --git a/ChangeLog b/ChangeLog index 4a54e0328..a616e8143 100644 --- a/ChangeLog +++ b/ChangeLog @@ -49,6 +49,7 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] * aspell: fix detection of nicks with non-alphanumeric chars * guile: disable guile gmp allocator (fix crash on unload of relay plugin) (bug #40628) +* irc: add option irc.look.ban_mask_default (bug #26571) * irc: add option irc.network.lag_max * irc: fix ignore on a host without nick * irc: use color code 0x1F (`ctrl-_`) for underlined text in input line (same diff --git a/doc/de/autogen/user/irc_options.txt b/doc/de/autogen/user/irc_options.txt index c1a1530de..7452e8321 100644 --- a/doc/de/autogen/user/irc_options.txt +++ b/doc/de/autogen/user/irc_options.txt @@ -63,6 +63,11 @@ ** Typ: Farbe ** Werte: ein Farbname für WeeChat (default, black, (dark)gray, white, (light)red, (light)green, brown, yellow, (light)blue, (light)magenta, (light)cyan), eine Terminal-Farbnummer oder ein Alias; Attribute können vor eine Farbe gesetzt werden (gilt ausschließlich für die Textfarbe und nicht für den Hintergrund): "*" für fett, "!" für invertiert, "/" für kursiv, "_" für unterstrichen (Standardwert: `darkgray`) +* [[option_irc.look.ban_mask_default]] *irc.look.ban_mask_default* +** Beschreibung: `default ban mask for commands /ban, /unban and /kickban; variables $nick, $user and $host are replaced by their values (extracted from "nick!user@host"); this default mask is used only if WeeChat knows the host for the nick` +** Typ: Zeichenkette +** Werte: beliebige Zeichenkette (Standardwert: `"*!$user@$host"`) + * [[option_irc.look.buffer_switch_autojoin]] *irc.look.buffer_switch_autojoin* ** Beschreibung: `wechselt automatisch zum Channel-Buffer falls dieser automatisch betreten wurde (mittels der Serveroption "autojoin")` ** Typ: boolesch diff --git a/doc/en/autogen/user/irc_options.txt b/doc/en/autogen/user/irc_options.txt index f439b5ae5..c947af84b 100644 --- a/doc/en/autogen/user/irc_options.txt +++ b/doc/en/autogen/user/irc_options.txt @@ -63,6 +63,11 @@ ** type: color ** values: a WeeChat color name (default, black, (dark)gray, white, (light)red, (light)green, brown, yellow, (light)blue, (light)magenta, (light)cyan), a terminal color number or an alias; attributes are allowed before color (for text color only, not background): "*" for bold, "!" for reverse, "/" for italic, "_" for underline (default value: `darkgray`) +* [[option_irc.look.ban_mask_default]] *irc.look.ban_mask_default* +** description: `default ban mask for commands /ban, /unban and /kickban; variables $nick, $user and $host are replaced by their values (extracted from "nick!user@host"); this default mask is used only if WeeChat knows the host for the nick` +** type: string +** values: any string (default value: `"*!$user@$host"`) + * [[option_irc.look.buffer_switch_autojoin]] *irc.look.buffer_switch_autojoin* ** description: `auto switch to channel buffer when it is auto joined (with server option "autojoin")` ** type: boolean diff --git a/doc/fr/autogen/user/irc_options.txt b/doc/fr/autogen/user/irc_options.txt index f499ed562..e5552b5ca 100644 --- a/doc/fr/autogen/user/irc_options.txt +++ b/doc/fr/autogen/user/irc_options.txt @@ -63,6 +63,11 @@ ** type: couleur ** valeurs: un nom de couleur WeeChat (default, black, (dark)gray, white, (light)red, (light)green, brown, yellow, (light)blue, (light)magenta, (light)cyan), un numéro de couleur du terminal ou un alias; des attributs sont autorisés avant la couleur (seulement pour la couleur du texte, pas le fond) : "*" pour le gras, "!" pour la vidéo inverse, "/" pour l'italique, "_" pour le souligné (valeur par défaut: `darkgray`) +* [[option_irc.look.ban_mask_default]] *irc.look.ban_mask_default* +** description: `masque de bannissement par défaut pour les commandes /ban, /unban et /kickban; les variables $nick, $user et $host sont remplacées par leurs valeurs (extraites de "nick!user@host"); ce masque par défaut est utilisé seulement si WeeChat connaît l'hôte pour le pseudo` +** type: chaîne +** valeurs: toute chaîne (valeur par défaut: `"*!$user@$host"`) + * [[option_irc.look.buffer_switch_autojoin]] *irc.look.buffer_switch_autojoin* ** description: `basculer automatiquement vers le tampon du canal lorsqu'il est automatiquement rejoint (avec l'option du serveur "autojoin")` ** type: booléen diff --git a/doc/it/autogen/user/irc_options.txt b/doc/it/autogen/user/irc_options.txt index 28ceabed6..dab77c34d 100644 --- a/doc/it/autogen/user/irc_options.txt +++ b/doc/it/autogen/user/irc_options.txt @@ -63,6 +63,11 @@ ** tipo: colore ** valori: a WeeChat color name (default, black, (dark)gray, white, (light)red, (light)green, brown, yellow, (light)blue, (light)magenta, (light)cyan), a terminal color number or an alias; attributes are allowed before color (for text color only, not background): "*" for bold, "!" for reverse, "/" for italic, "_" for underline (valore predefinito: `darkgray`) +* [[option_irc.look.ban_mask_default]] *irc.look.ban_mask_default* +** descrizione: `default ban mask for commands /ban, /unban and /kickban; variables $nick, $user and $host are replaced by their values (extracted from "nick!user@host"); this default mask is used only if WeeChat knows the host for the nick` +** tipo: stringa +** valori: qualsiasi stringa (valore predefinito: `"*!$user@$host"`) + * [[option_irc.look.buffer_switch_autojoin]] *irc.look.buffer_switch_autojoin* ** descrizione: `passa automaticamente al buffer del canale con l'ingresso automatico abilitato (con l'opzione del server "autojoin")` ** tipo: bool diff --git a/doc/ja/autogen/user/irc_options.txt b/doc/ja/autogen/user/irc_options.txt index ea8012f9f..24c93000f 100644 --- a/doc/ja/autogen/user/irc_options.txt +++ b/doc/ja/autogen/user/irc_options.txt @@ -63,6 +63,11 @@ ** タイプ: 色 ** 値: a WeeChat color name (default, black, (dark)gray, white, (light)red, (light)green, brown, yellow, (light)blue, (light)magenta, (light)cyan), a terminal color number or an alias; attributes are allowed before color (for text color only, not background): "*" for bold, "!" for reverse, "/" for italic, "_" for underline (デフォルト値: `darkgray`) +* [[option_irc.look.ban_mask_default]] *irc.look.ban_mask_default* +** 説明: `default ban mask for commands /ban, /unban and /kickban; variables $nick, $user and $host are replaced by their values (extracted from "nick!user@host"); this default mask is used only if WeeChat knows the host for the nick` +** タイプ: 文字列 +** 値: 未制約文字列 (デフォルト値: `"*!$user@$host"`) + * [[option_irc.look.buffer_switch_autojoin]] *irc.look.buffer_switch_autojoin* ** 説明: `自動で参加した場合に、自動的にチャンネルバッファを移動 (サーバオプション "autojoin" と共に使用)` ** タイプ: ブール diff --git a/po/cs.po b/po/cs.po index be700a2fc..b88797fe7 100644 --- a/po/cs.po +++ b/po/cs.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -6217,6 +6217,12 @@ msgstr "%s%s: chyba při vytváření serveru \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: chyba při vytváření volby serveru \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/de.po b/po/de.po index 4f7d4ff56..cbb6cec75 100644 --- a/po/de.po +++ b/po/de.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.4.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-20 15:12+0100\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -6953,6 +6953,12 @@ msgstr "%s%s: Fehler bei der Erstellung des Servers \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: Fehler bei der Erstellung der Serveroption \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/es.po b/po/es.po index 6aa8ec260..75d655e4f 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -6452,6 +6452,12 @@ msgstr "%s%s: error al crear el servidor \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: error al crear la opción \"%s\" del servidor" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/fr.po b/po/fr.po index 3daa6805a..62223a1fe 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" -"PO-Revision-Date: 2013-12-07 17:08+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" +"PO-Revision-Date: 2013-12-07 18:17+0100\n" "Last-Translator: Sebastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -6779,6 +6779,16 @@ msgstr "%s%s: erreur de création du serveur \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: erreur de création de l'option serveur \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" +"masque de bannissement par défaut pour les commandes /ban, /unban et /" +"kickban; les variables $nick, $user et $host sont remplacées par leurs " +"valeurs (extraites de \"nick!user@host\"); ce masque par défaut est utilisé " +"seulement si WeeChat connaît l'hôte pour le pseudo" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/hu.po b/po/hu.po index 7f3c47fb6..b91b2858a 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -5754,6 +5754,12 @@ msgstr "%s nincs elég memória az információs pult üzenethez\n" msgid "%s%s: error creating server option \"%s\"" msgstr "%s nincs elég memória az információs pult üzenethez\n" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/it.po b/po/it.po index 22a408c96..97c017769 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -6578,6 +6578,12 @@ msgstr "%s%s: errore durante la creazione del server \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: errore durante la creazione dell'opzione del server \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/ja.po b/po/ja.po index 298276999..f8e46f0f5 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" @@ -6508,6 +6508,12 @@ msgstr "%s%s: サーバ \"%s\" 作成中のエラー" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: サーバオプション \"%s\" 作成中にエラー" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/pl.po b/po/pl.po index f66759ab8..4dca9b995 100644 --- a/po/pl.po +++ b/po/pl.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-11 09:07+0100\n" "Last-Translator: Krzysztof Korościk \n" "Language-Team: weechat-dev \n" @@ -6663,6 +6663,12 @@ msgstr "%s%s: błąd podczas tworzenia serwera \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: błąd podczas tworzenia opcji dla serwera \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/pt_BR.po b/po/pt_BR.po index 8823dc5b8..6d45b8ce4 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Sergio Durigan Junior \n" "Language-Team: weechat-dev \n" @@ -5966,6 +5966,12 @@ msgstr "%s%s: erro ao criar servidor \"%s\"" msgid "%s%s: error creating server option \"%s\"" msgstr "%s%s: erro ao criar opção do servidor \"%s\"" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/ru.po b/po/ru.po index c719cf356..db51c7628 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:18+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -5778,6 +5778,12 @@ msgstr "%s недостаточно памяти для сообщения в с msgid "%s%s: error creating server option \"%s\"" msgstr "%s недостаточно памяти для сообщения в строке информации\n" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/tr.po b/po/tr.po index 5dec40943..5fcc64c72 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-11-09 10:13+0100\n" "Last-Translator: Hasan Kiran \n" "Language-Team: weechat-dev \n" @@ -5079,6 +5079,12 @@ msgstr "" msgid "%s%s: error creating server option \"%s\"" msgstr "" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/po/weechat.pot b/po/weechat.pot index e751d21d8..662590b68 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.4.1-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2013-12-07 15:14+0100\n" +"POT-Creation-Date: 2013-12-07 18:16+0100\n" "PO-Revision-Date: 2013-02-14 18:20+0100\n" "Last-Translator: FULL NAME \n" "Language-Team: weechat-dev \n" @@ -5037,6 +5037,12 @@ msgstr "" msgid "%s%s: error creating server option \"%s\"" msgstr "" +msgid "" +"default ban mask for commands /ban, /unban and /kickban; variables $nick, " +"$user and $host are replaced by their values (extracted from \"nick!user@host" +"\"); this default mask is used only if WeeChat knows the host for the nick" +msgstr "" + msgid "" "auto switch to channel buffer when it is auto joined (with server option " "\"autojoin\")" diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 7e86d35dd..a188aa93d 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -839,6 +839,45 @@ irc_command_run_away (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } +/* + * Sends a ban/unban command to the server, as "MODE [+/-]b nick". + * + * Argument "mode" can be "+b" for ban or "-b" for unban. + */ + +void +irc_command_send_ban (struct t_irc_server *server, + const char *channel_name, + const char *mode, + const char *nick) +{ + struct t_irc_channel *ptr_channel; + struct t_irc_nick *ptr_nick; + char *mask; + + mask = NULL; + + if (!strchr (nick, '!') && !strchr (nick, '@')) + { + ptr_channel = irc_channel_search (server, channel_name); + if (ptr_channel) + { + ptr_nick = irc_nick_search (server, ptr_channel, nick); + if (ptr_nick) + mask = irc_nick_default_ban_mask (ptr_nick); + } + } + + irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "MODE %s %s %s", + channel_name, + mode, + (mask) ? mask : nick); + + if (mask) + free (mask); +} + /* * Callback for command "/ban": bans nicks or hosts. */ @@ -891,9 +930,8 @@ irc_command_ban (void *data, struct t_gui_buffer *buffer, int argc, /* loop on users */ while (argv[pos_args]) { - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "MODE %s +b %s", - pos_channel, argv[pos_args]); + irc_command_send_ban (ptr_server, pos_channel, "+b", + argv[pos_args]); pos_args++; } } @@ -2522,10 +2560,8 @@ irc_command_kickban (void *data, struct t_gui_buffer *buffer, int argc, } else { - irc_server_sendf (ptr_server, - IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "MODE %s +b %s", - pos_channel, pos_nick); + irc_command_send_ban (ptr_server, pos_channel, "+b", + pos_nick); } /* kick nick */ @@ -5332,9 +5368,8 @@ irc_command_unban (void *data, struct t_gui_buffer *buffer, int argc, /* loop on users */ while (argv[pos_args]) { - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "MODE %s -b %s", - pos_channel, argv[pos_args]); + irc_command_send_ban (ptr_server, pos_channel, "-b", + argv[pos_args]); pos_args++; } } diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 84e5d0938..ff02d9385 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -48,6 +48,7 @@ struct t_config_section *irc_config_section_server = NULL; /* IRC config, look section */ +struct t_config_option *irc_config_look_ban_mask_default; struct t_config_option *irc_config_look_buffer_switch_autojoin; struct t_config_option *irc_config_look_buffer_switch_join; struct t_config_option *irc_config_look_color_nicks_in_names; @@ -2193,6 +2194,15 @@ irc_config_init () return 0; } + irc_config_look_ban_mask_default = weechat_config_new_option ( + irc_config_file, ptr_section, + "ban_mask_default", "string", + N_("default ban mask for commands /ban, /unban and /kickban; variables " + "$nick, $user and $host are replaced by their values (extracted " + "from \"nick!user@host\"); this default mask is used only if " + "WeeChat knows the host for the nick"), + NULL, 0, 0, "*!$user@$host", NULL, 0, NULL, NULL, + NULL, NULL, NULL, NULL); irc_config_look_buffer_switch_autojoin = weechat_config_new_option ( irc_config_file, ptr_section, "buffer_switch_autojoin", "boolean", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 89c29d06b..86bf03044 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -96,6 +96,7 @@ extern struct t_config_section *irc_config_section_ctcp; extern struct t_config_section *irc_config_section_server_default; extern struct t_config_section *irc_config_section_server; +extern struct t_config_option *irc_config_look_ban_mask_default; extern struct t_config_option *irc_config_look_buffer_switch_autojoin; extern struct t_config_option *irc_config_look_buffer_switch_join; extern struct t_config_option *irc_config_look_color_nicks_in_names; diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 4146775a7..0968d4b4d 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -1045,6 +1045,62 @@ irc_nick_color_for_pv (struct t_irc_channel *channel, const char *nickname) return IRC_COLOR_CHAT_NICK_OTHER; } +/* + * Returns default ban mask for the nick. + * + * Note: result must be freed after use (if not NULL). + */ + +char * +irc_nick_default_ban_mask (struct t_irc_nick *nick) +{ + static char ban_mask[128]; + const char *ptr_ban_mask; + char *pos_hostname, user[64], *res, *temp; + + if (!nick) + return NULL; + + ptr_ban_mask = weechat_config_string (irc_config_look_ban_mask_default); + + pos_hostname = (nick->host) ? strchr (nick->host, '@') : NULL; + + if (!nick->host || !pos_hostname || !ptr_ban_mask || !ptr_ban_mask[0]) + { + snprintf (ban_mask, sizeof (ban_mask), "%s!*@*", nick->name); + return strdup (ban_mask); + } + + if (pos_hostname - nick->host > (int)sizeof (user) - 1) + return NULL; + + strncpy (user, nick->host, pos_hostname - nick->host); + user[pos_hostname - nick->host] = '\0'; + pos_hostname++; + + /* replace nick */ + temp = weechat_string_replace (ptr_ban_mask, "$nick", nick->name); + if (!temp) + return NULL; + res = temp; + + /* replace user */ + temp = weechat_string_replace (res, "$user", user); + free (res); + if (!temp) + return NULL; + res = temp; + + /* replace hostname */ + temp = weechat_string_replace (res, "$host", pos_hostname); + free (res); + if (!temp) + return NULL; + res = temp; + + return res; +} + /* * Returns hdata for nick. */ diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h index fa50caf4c..a77b1a1ab 100644 --- a/src/plugins/irc/irc-nick.h +++ b/src/plugins/irc/irc-nick.h @@ -101,6 +101,7 @@ extern const char *irc_nick_color_for_server_message (struct t_irc_server *serve const char *nickname); extern const char * irc_nick_color_for_pv (struct t_irc_channel *channel, const char *nickname); +extern char *irc_nick_default_ban_mask (struct t_irc_nick *nick); extern struct t_hdata *irc_nick_hdata_nick_cb (void *data, const char *hdata_name); extern int irc_nick_add_to_infolist (struct t_infolist *infolist,