mirror of
https://github.com/weechat/weechat.git
synced 2026-06-27 05:16:38 +02:00
irc: add option irc.look.ban_mask_default (bug #26571)
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user