summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/alias/alias-config.c1
-rw-r--r--src/plugins/irc/irc-command.c535
-rw-r--r--src/plugins/irc/irc-ctcp.c99
-rw-r--r--src/plugins/irc/irc-ctcp.h4
-rw-r--r--src/plugins/irc/irc-input.c337
-rw-r--r--src/plugins/irc/irc-input.h10
-rw-r--r--src/plugins/irc/irc-message.c41
-rw-r--r--src/plugins/irc/irc-message.h2
-rw-r--r--src/plugins/irc/irc-protocol.c15
9 files changed, 520 insertions, 524 deletions
diff --git a/src/plugins/alias/alias-config.c b/src/plugins/alias/alias-config.c
index 5aaf0206a..7d65a1c1b 100644
--- a/src/plugins/alias/alias-config.c
+++ b/src/plugins/alias/alias-config.c
@@ -34,7 +34,6 @@ struct t_config_section *alias_config_section_completion = NULL;
char *alias_default[][3] =
{ { "aaway", "allserv /away", NULL },
- { "action", "ctcp $1 action $2-", NULL },
{ "anick", "allserv /nick", NULL },
{ "beep", "print -beep", NULL },
{ "bye", "quit", NULL },
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 707c4bd60..56c49ee10 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -355,6 +355,165 @@ irc_command_mode_masks (struct t_irc_server *server,
}
/*
+ * Sends a CTCP ACTION to a channel for a single message
+ * (internal function called by irc_command_me_channel).
+ */
+
+void
+irc_command_me_channel_message (struct t_irc_server *server,
+ const char *channel_name,
+ const char *message)
+{
+ struct t_arraylist *list_messages;
+ int i, list_size;
+
+ list_messages = irc_server_sendf (
+ server,
+ IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_LIST,
+ NULL,
+ "PRIVMSG %s :\01ACTION%s%s\01",
+ channel_name,
+ (message && message[0]) ? " " : "",
+ (message && message[0]) ? message : "");
+ if (list_messages)
+ {
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (server->cap_list, "echo-message"))
+ {
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
+ {
+ irc_input_user_message_display (
+ server,
+ channel_name,
+ NULL, /* address */
+ "privmsg",
+ "action",
+ (const char *)weechat_arraylist_get (list_messages, i),
+ 1); /* decode_colors */
+ }
+ }
+ weechat_arraylist_free (list_messages);
+ }
+}
+
+/*
+ * Sends a CTCP ACTION to a channel.
+ */
+
+void
+irc_command_me_channel (struct t_irc_server *server,
+ const char *channel_name,
+ const char *arguments)
+{
+ char **list_arguments;
+ int i, count_arguments;
+
+ list_arguments = weechat_string_split ((arguments) ? arguments : "",
+ "\n", NULL, 0, 0, &count_arguments);
+ if (list_arguments)
+ {
+ for (i = 0; i < count_arguments; i++)
+ {
+ irc_command_me_channel_message (server, channel_name,
+ list_arguments[i]);
+ }
+ }
+ else
+ {
+ irc_command_me_channel_message (server, channel_name, "");
+ }
+
+ weechat_string_free_split (list_arguments);
+}
+
+/*
+ * Sends a CTCP ACTION to all channels of a server.
+ */
+
+void
+irc_command_me_all_channels (struct t_irc_server *server, const char *arguments)
+{
+ struct t_irc_channel *ptr_channel;
+
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ irc_command_me_channel (server, ptr_channel->name, arguments);
+ }
+}
+
+/*
+ * Callback for command "/action": sends an action message to a nick or channel.
+ */
+
+IRC_COMMAND_CALLBACK(action)
+{
+ char **targets;
+ int num_targets, i, arg_target, arg_text;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+
+ WEECHAT_COMMAND_MIN_ARGS(2, "");
+
+ arg_target = 1;
+ arg_text = 2;
+
+ if ((argc >= 5) && (weechat_strcmp (argv[1], "-server") == 0))
+ {
+ ptr_server = irc_server_search (argv[2]);
+ ptr_channel = NULL;
+ arg_target = 3;
+ arg_text = 4;
+ }
+
+ IRC_COMMAND_CHECK_SERVER("action", 1, 1);
+
+ targets = weechat_string_split (argv[arg_target], ",", NULL,
+ WEECHAT_STRING_SPLIT_STRIP_LEFT
+ | WEECHAT_STRING_SPLIT_STRIP_RIGHT
+ | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
+ 0, &num_targets);
+ if (!targets)
+ WEECHAT_COMMAND_ERROR;
+
+ for (i = 0; i < num_targets; i++)
+ {
+ if (strcmp (targets[i], "*") == 0)
+ {
+ if (!ptr_channel
+ || ((ptr_channel->type != IRC_CHANNEL_TYPE_CHANNEL)
+ && (ptr_channel->type != IRC_CHANNEL_TYPE_PRIVATE)))
+ {
+ weechat_printf (
+ ptr_server->buffer,
+ _("%s%s: \"%s\" command can only be executed in a channel "
+ "or private buffer"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME, "action *");
+ }
+ else
+ {
+ irc_command_me_channel (ptr_server, ptr_channel->name,
+ argv_eol[arg_text]);
+ }
+ }
+ else
+ {
+ irc_command_me_channel (ptr_server, targets[i], argv_eol[arg_text]);
+ }
+ }
+
+ weechat_string_free_split (targets);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* Callback for command "/admin": finds information about the administrator of
* the server.
*/
@@ -1061,130 +1220,6 @@ end:
}
/*
- * Displays a ctcp action on a channel.
- */
-
-void
-irc_command_me_channel_display (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *arguments)
-{
- char *string;
- struct t_irc_nick *ptr_nick;
-
- /*
- * if capability "echo-message" is enabled, we don't display anything,
- * the message will be displayed when server sends it back to us
- */
- if (weechat_hashtable_has_key (server->cap_list, "echo-message"))
- return;
-
- string = (arguments && arguments[0]) ?
- irc_color_decode (arguments,
- weechat_config_boolean (irc_config_network_colors_send)) : NULL;
- ptr_nick = irc_nick_search (server, channel, server->nick);
- weechat_printf_date_tags (
- channel->buffer,
- 0,
- irc_protocol_tags (server,
- "privmsg",
- NULL,
- "irc_action,self_msg,notify_none,no_highlight",
- server->nick, NULL),
- "%s%s%s%s%s%s%s",
- weechat_prefix ("action"),
- irc_nick_mode_for_display (server, ptr_nick, 0),
- IRC_COLOR_CHAT_NICK_SELF,
- server->nick,
- (string) ? IRC_COLOR_RESET : "",
- (string) ? " " : "",
- (string) ? string : "");
- if (string)
- free (string);
-}
-
-/*
- * Sends a ctcp action to a channel for a single message
- * (internal function called by irc_command_me_channel).
- */
-
-void
-irc_command_me_channel_message (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *message)
-{
- struct t_arraylist *list_messages;
- int i, list_size;
-
- list_messages = irc_server_sendf (
- server,
- IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_LIST,
- NULL,
- "PRIVMSG %s :\01ACTION%s%s\01",
- channel->name,
- (message && message[0]) ? " " : "",
- (message && message[0]) ? message : "");
- if (list_messages)
- {
- list_size = weechat_arraylist_size (list_messages);
- for (i = 0; i < list_size; i++)
- {
- irc_command_me_channel_display (
- server,
- channel,
- (const char *)weechat_arraylist_get (list_messages, i));
- }
- weechat_arraylist_free (list_messages);
- }
-}
-
-/*
- * Sends a ctcp action to a channel.
- */
-
-void
-irc_command_me_channel (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *arguments)
-{
- char **list_arguments;
- int i, count_arguments;
-
- list_arguments = weechat_string_split ((arguments) ? arguments : "",
- "\n", NULL, 0, 0, &count_arguments);
- if (list_arguments)
- {
- for (i = 0; i < count_arguments; i++)
- {
- irc_command_me_channel_message (server, channel, list_arguments[i]);
- }
- }
- else
- {
- irc_command_me_channel_message (server, channel, "");
- }
-
- weechat_string_free_split (list_arguments);
-}
-
-/*
- * Sends a ctcp action to all channels of a server.
- */
-
-void
-irc_command_me_all_channels (struct t_irc_server *server, const char *arguments)
-{
- struct t_irc_channel *ptr_channel;
-
- for (ptr_channel = server->channels; ptr_channel;
- ptr_channel = ptr_channel->next_channel)
- {
- if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
- irc_command_me_channel (server, ptr_channel, arguments);
- }
-}
-
-/*
* Displays away on all channels of all servers.
*/
@@ -1851,7 +1886,6 @@ IRC_COMMAND_CALLBACK(connect)
IRC_COMMAND_CALLBACK(ctcp)
{
- struct t_irc_channel *ptr_channel_target;
char **targets, *ctcp_type, str_time[512];
const char *ctcp_target, *ctcp_args;
int num_targets, arg_target, arg_type, arg_args, i;
@@ -1931,17 +1965,17 @@ IRC_COMMAND_CALLBACK(ctcp)
if (ctcp_target)
{
- /* display message only if capability "echo-message" is NOT enabled */
+ /* display only if capability "echo-message" is NOT enabled */
if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
{
- ptr_channel_target = irc_channel_search (
+ irc_input_user_message_display (
ptr_server,
- (irc_server_prefix_char_statusmsg (ptr_server,
- ctcp_target[0])
- && irc_channel_is_channel (ptr_server, ctcp_target + 1)) ?
- ctcp_target + 1 : ctcp_target);
- irc_ctcp_display_send (ptr_server, ptr_channel_target,
- ctcp_target, NULL, ctcp_type, ctcp_args);
+ ctcp_target,
+ NULL, /* address */
+ "privmsg",
+ ctcp_type,
+ ctcp_args,
+ 1); /* decode_colors */
}
irc_ctcp_send (ptr_server, ctcp_target, ctcp_type, ctcp_args);
}
@@ -3501,7 +3535,7 @@ IRC_COMMAND_CALLBACK(map)
}
/*
- * Callback for command "/me": sends a ctcp action to the current channel.
+ * Callback for command "/me": sends a CTCP ACTION to the current channel.
*/
IRC_COMMAND_CALLBACK(me)
@@ -3523,7 +3557,7 @@ IRC_COMMAND_CALLBACK(me)
return WEECHAT_RC_OK;
}
- irc_command_me_channel (ptr_server, ptr_channel,
+ irc_command_me_channel (ptr_server, ptr_channel->name,
(argc > 1) ? argv_eol[1] : NULL);
return WEECHAT_RC_OK;
@@ -3648,10 +3682,8 @@ IRC_COMMAND_CALLBACK(motd)
IRC_COMMAND_CALLBACK(msg)
{
- char **targets, *msg_pwd_hidden, *string;
- int num_targets, i, j, arg_target, arg_text, is_channel, status_msg;
- int hide_password;
- struct t_irc_channel *ptr_channel2;
+ char **targets;
+ int num_targets, i, arg_target, arg_text;
IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
@@ -3698,9 +3730,18 @@ IRC_COMMAND_CALLBACK(msg)
}
else
{
- irc_input_user_message_display (ptr_channel->buffer,
- 0, 0, NULL, 0,
- argv_eol[arg_text]);
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
+ {
+ irc_input_user_message_display (
+ ptr_server,
+ ptr_channel->name,
+ NULL, /* address */
+ "privmsg",
+ NULL, /* ctcp_type */
+ argv_eol[arg_text],
+ 1); /* decode_colors */
+ }
irc_server_sendf (ptr_server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"PRIVMSG %s :%s",
@@ -3709,135 +3750,22 @@ IRC_COMMAND_CALLBACK(msg)
}
else
{
- is_channel = 0;
- ptr_channel2 = NULL;
- status_msg = 0;
- if (irc_server_prefix_char_statusmsg (ptr_server,
- targets[i][0])
- && irc_channel_is_channel (ptr_server, targets[i] + 1))
- {
- ptr_channel2 = irc_channel_search (ptr_server, targets[i] + 1);
- is_channel = 1;
- status_msg = 1;
- }
- else
- {
- ptr_channel2 = irc_channel_search (ptr_server, targets[i]);
- if (ptr_channel2)
- is_channel = 1;
- }
- if (is_channel)
- {
- if (ptr_channel2)
- {
- irc_input_user_message_display (
- ptr_channel2->buffer,
- 0, /* action */
- 0, /* notice */
- (status_msg) ? targets[i] : NULL,
- is_channel,
- argv_eol[arg_text]);
- }
- irc_server_sendf (ptr_server,
- IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
- "PRIVMSG %s :%s",
- targets[i], argv_eol[arg_text]);
- }
- else
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
{
- /* check if the password must be hidden for this nick */
- hide_password = 0;
- if (irc_config_nicks_hide_password)
- {
- for (j = 0; j < irc_config_num_nicks_hide_password; j++)
- {
- if (weechat_strcasecmp (irc_config_nicks_hide_password[j],
- targets[i]) == 0)
- {
- hide_password = 1;
- break;
- }
- }
- }
- if (hide_password)
- {
- /* hide password in message displayed using modifier */
- msg_pwd_hidden = weechat_hook_modifier_exec (
- "irc_message_auth",
- ptr_server->name,
- argv_eol[arg_text]);
- string = irc_color_decode (
- (msg_pwd_hidden) ? msg_pwd_hidden : argv_eol[arg_text],
- weechat_config_boolean (irc_config_network_colors_send));
- weechat_printf (
- ptr_server->buffer,
- "%sMSG%s(%s%s%s)%s: %s",
- weechat_prefix ("network"),
- IRC_COLOR_CHAT_DELIMITERS,
- irc_nick_color_for_msg (ptr_server, 0, NULL,
- targets[i]),
- targets[i],
- IRC_COLOR_CHAT_DELIMITERS,
- IRC_COLOR_RESET,
- (string) ?
- string : ((msg_pwd_hidden) ?
- msg_pwd_hidden : argv_eol[arg_text]));
- if (string)
- free (string);
- if (msg_pwd_hidden)
- free (msg_pwd_hidden);
- }
- else
- {
- ptr_channel2 = irc_channel_search (ptr_server,
- targets[i]);
- if (ptr_channel2)
- {
- irc_input_user_message_display (ptr_channel2->buffer,
- 0, 0, NULL, 0,
- argv_eol[arg_text]);
- }
- else
- {
- /*
- * display message only if capability "echo-message"
- * is NOT enabled
- */
- if (!weechat_hashtable_has_key (ptr_server->cap_list,
- "echo-message"))
- {
- string = irc_color_decode (
- argv_eol[arg_text],
- weechat_config_boolean (
- irc_config_network_colors_send));
- weechat_printf_date_tags (
- ptr_server->buffer,
- 0,
- irc_protocol_tags (
- ptr_server,
- "privmsg",
- NULL,
- "self_msg,notify_none,no_highlight",
- ptr_server->nick, NULL),
- "%sMSG%s(%s%s%s)%s: %s",
- weechat_prefix ("network"),
- IRC_COLOR_CHAT_DELIMITERS,
- irc_nick_color_for_msg (
- ptr_server, 0, NULL, targets[i]),
- targets[i],
- IRC_COLOR_CHAT_DELIMITERS,
- IRC_COLOR_RESET,
- (string) ? string : argv_eol[arg_text]);
- if (string)
- free (string);
- }
- }
- }
- irc_server_sendf (ptr_server,
- IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
- "PRIVMSG %s :%s",
- targets[i], argv_eol[arg_text]);
+ irc_input_user_message_display (
+ ptr_server,
+ targets[i],
+ NULL, /* address */
+ "privmsg",
+ NULL, /* ctcp_type */
+ argv_eol[arg_text],
+ 1); /* decode_colors */
}
+ irc_server_sendf (ptr_server,
+ IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
+ "PRIVMSG %s :%s",
+ targets[i], argv_eol[arg_text]);
}
}
@@ -3943,8 +3871,7 @@ IRC_COMMAND_CALLBACK(nick)
IRC_COMMAND_CALLBACK(notice)
{
const char *ptr_message;
- int i, arg_target, arg_text, is_channel, list_size;
- struct t_irc_channel *ptr_channel;
+ int i, arg_target, arg_text, list_size;
struct t_arraylist *list_messages;
IRC_BUFFER_GET_SERVER(buffer);
@@ -3965,19 +3892,7 @@ IRC_COMMAND_CALLBACK(notice)
}
IRC_COMMAND_CHECK_SERVER("notice", 1, 1);
- is_channel = 0;
- if (irc_server_prefix_char_statusmsg (ptr_server, argv[arg_target][0])
- && irc_channel_is_channel (ptr_server, argv[arg_target] + 1))
- {
- ptr_channel = irc_channel_search (ptr_server, argv[arg_target] + 1);
- is_channel = 1;
- }
- else
- {
- ptr_channel = irc_channel_search (ptr_server, argv[arg_target]);
- if (ptr_channel)
- is_channel = 1;
- }
+
list_messages = irc_server_sendf (
ptr_server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH | IRC_SERVER_SEND_RETURN_LIST,
@@ -3986,19 +3901,22 @@ IRC_COMMAND_CALLBACK(notice)
argv[arg_target], argv_eol[arg_text]);
if (list_messages)
{
- list_size = weechat_arraylist_size (list_messages);
- for (i = 0; i < list_size; i++)
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
{
- ptr_message = (const char *)weechat_arraylist_get (list_messages, i);
- irc_input_user_message_display (
- irc_msgbuffer_get_target_buffer (
- ptr_server, argv[arg_target], "notice", NULL,
- (ptr_channel) ? ptr_channel->buffer : NULL),
- 0, /* action */
- 1, /* notice */
- argv[arg_target],
- is_channel,
- ptr_message);
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
+ {
+ ptr_message = (const char *)weechat_arraylist_get (list_messages, i);
+ irc_input_user_message_display (
+ ptr_server,
+ argv[arg_target],
+ NULL, /* address */
+ "notice",
+ NULL, /* ctcp_type */
+ ptr_message,
+ 1); /* decode_colors */
+ }
}
weechat_arraylist_free (list_messages);
}
@@ -4516,9 +4434,18 @@ IRC_COMMAND_CALLBACK(query)
/* display text if given */
if (argv_eol[arg_text])
{
- irc_input_user_message_display (ptr_channel->buffer,
- 0, 0, NULL, 0,
- argv_eol[arg_text]);
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
+ {
+ irc_input_user_message_display (
+ ptr_server,
+ ptr_channel->name,
+ NULL, /* address */
+ "privmsg",
+ NULL, /* ctcp_type */
+ argv_eol[arg_text],
+ 1); /* decode_colors */
+ }
irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH,
NULL,
"PRIVMSG %s :%s",
@@ -6762,6 +6689,16 @@ void
irc_command_init ()
{
weechat_hook_command (
+ "action",
+ N_("send a CTCP action to a nick or channel"),
+ N_("[-server <server>] <target>[,<target>...] <text>"),
+ N_("server: send to this server (internal name)\n"
+ "target: nick or channel (may be mask, '*' = current channel)\n"
+ " text: text to send"),
+ "-server %(irc_servers) %(nicks)|*"
+ " || %(nicks)|*",
+ &irc_command_action, NULL, NULL);
+ weechat_hook_command (
"admin",
N_("find information about the administrator of the server"),
N_("[<target>]"),
diff --git a/src/plugins/irc/irc-ctcp.c b/src/plugins/irc/irc-ctcp.c
index 92e50dfa3..0deeb6017 100644
--- a/src/plugins/irc/irc-ctcp.c
+++ b/src/plugins/irc/irc-ctcp.c
@@ -33,6 +33,7 @@
#include "irc-channel.h"
#include "irc-color.h"
#include "irc-config.h"
+#include "irc-input.h"
#include "irc-msgbuffer.h"
#include "irc-nick.h"
#include "irc-protocol.h"
@@ -1291,104 +1292,6 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date,
}
/*
- * Displays an outgoing CTCP.
- */
-
-void
-irc_ctcp_display_send (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *target, const char *address,
- const char *type, const char *args)
-{
- struct t_irc_nick *ptr_nick;
- int is_channel;
-
- if (weechat_strcasecmp (type, "action") == 0)
- {
- if (!channel || irc_server_prefix_char_statusmsg (server, target[0]))
- {
- /* no buffer or STATUSMSG action */
- is_channel = ((irc_server_prefix_char_statusmsg (server, target[0])
- && irc_channel_is_channel (server, target + 1))
- || irc_channel_is_channel (server, target));
- ptr_nick = irc_nick_search (server, channel, server->nick);
- weechat_printf_date_tags (
- (channel) ? channel->buffer : irc_msgbuffer_get_target_buffer (
- server, target, NULL, "ctcp", NULL),
- 0,
- irc_protocol_tags (
- server,
- "privmsg",
- NULL,
- "irc_action,self_msg,notify_none,no_highlight",
- server->nick,
- address),
- "%s%s -> %s%s%s: %s%s%s%s%s%s",
- weechat_prefix ("network"),
- /* TRANSLATORS: "Action" is an IRC CTCP "ACTION" sent with /me */
- _("Action"),
- (is_channel) ?
- IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (server, 0, NULL, target),
- target,
- IRC_COLOR_RESET,
- irc_nick_mode_for_display (server, ptr_nick, 0),
- IRC_COLOR_CHAT_NICK_SELF,
- server->nick,
- (args && args[0]) ? IRC_COLOR_RESET : "",
- (args && args[0]) ? " " : "",
- (args && args[0]) ? args : "");
- }
- else
- {
- /* standard action */
- weechat_printf_date_tags (
- (channel) ? channel->buffer : irc_msgbuffer_get_target_buffer (
- server, target, NULL, "ctcp", NULL),
- 0,
- irc_protocol_tags (
- server,
- "privmsg",
- NULL,
- "irc_action,self_msg,notify_none,no_highlight",
- server->nick,
- address),
- "%s%s%s%s%s%s",
- weechat_prefix ("action"),
- IRC_COLOR_CHAT_NICK_SELF,
- server->nick,
- (args && args[0]) ? IRC_COLOR_RESET : "",
- (args && args[0]) ? " " : "",
- (args && args[0]) ? args : "");
- }
- }
- else
- {
- weechat_printf_date_tags (
- irc_msgbuffer_get_target_buffer (
- server, target, NULL, "ctcp", NULL),
- 0,
- irc_protocol_tags (
- server,
- "privmsg",
- NULL,
- "irc_ctcp,self_msg,notify_none,no_highlight",
- NULL,
- address),
- _("%sCTCP query to %s%s%s: %s%s%s%s%s"),
- weechat_prefix ("network"),
- (channel) ?
- IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (server, 0, NULL, target),
- target,
- IRC_COLOR_RESET,
- IRC_COLOR_CHAT_CHANNEL,
- type,
- IRC_COLOR_RESET,
- (args && args[0]) ? " " : "",
- (args && args[0]) ? args : "");
- }
-}
-
-/*
* Sends a CTCP to a target.
*/
diff --git a/src/plugins/irc/irc-ctcp.h b/src/plugins/irc/irc-ctcp.h
index 830bd038a..57a7ecb67 100644
--- a/src/plugins/irc/irc-ctcp.h
+++ b/src/plugins/irc/irc-ctcp.h
@@ -49,10 +49,6 @@ extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
const char *address, const char *nick,
const char *remote_nick, const char *arguments,
const char *message);
-extern void irc_ctcp_display_send (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *target, const char *address,
- const char *type, const char *args);
extern void irc_ctcp_send (struct t_irc_server *server,
const char *target, const char *type,
const char *args);
diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c
index 2c4e244e2..78fe45aa5 100644
--- a/src/plugins/irc/irc-input.c
+++ b/src/plugins/irc/irc-input.c
@@ -28,9 +28,11 @@
#include "irc-buffer.h"
#include "irc-server.h"
#include "irc-channel.h"
+#include "irc-message.h"
#include "irc-nick.h"
#include "irc-color.h"
#include "irc-config.h"
+#include "irc-msgbuffer.h"
#include "irc-protocol.h"
#include "irc-raw.h"
@@ -42,170 +44,272 @@
* If action == 0, but message is detected as an action (beginning with
* "\01ACTION "), then action is forced.
*
- * If notice == 1, the message is a notice, otherwise it's a privmsg.
- *
- * If target is NULL, the message is displayed like this (standard message
- * then action):
+ * If target is a channel or a nick, the message is displayed like this
+ * (message, action):
*
* nick | test
* * | nick is testing
*
- * If target is not NULL, the message is displayed with the target, like this
- * (privmsg then notice):
+ * If target is a channel with STATUSMSG (for example "@#test"), the message
+ * is displayed with the target, like this (message, action, notice):
*
* Msg(nick) -> @#test: test message for ops
+ * Action -> @#test: nick is testing
* Notice(nick) -> @#test: test notice for ops
*/
void
-irc_input_user_message_display (struct t_gui_buffer *buffer,
- int action, int notice,
- const char *target, int target_is_channel,
- const char *text)
+irc_input_user_message_display (struct t_irc_server *server,
+ const char *target,
+ const char *address,
+ const char *command,
+ const char *ctcp_type,
+ const char *text,
+ int decode_colors)
{
+ struct t_irc_channel *ptr_channel;
+ struct t_gui_buffer *ptr_buffer;
struct t_irc_nick *ptr_nick;
- char *pos, *text2, *text_decoded, str_tags[256], *str_color;
+ const char *ptr_target;
+ char *pos, *text2, *text3, *text_decoded, str_tags[256], *str_color;
const char *ptr_text;
+ int is_notice, is_action, is_channel, display_target;
- if (!buffer || !text)
+ if (!server || !target)
return;
- IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
+ is_notice = (weechat_strcasecmp (command, "notice") == 0);
+ is_action = (ctcp_type && (weechat_strcasecmp (ctcp_type, "action") == 0));
- /*
- * if capability "echo-message" is enabled, we don't display anything,
- * the message will be displayed when server sends it back to us
- */
- if (weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
- return;
+ is_channel = 0;
+ ptr_channel = NULL;
+ display_target = is_notice || (ctcp_type && !is_action);
+ ptr_target = target;
+ if (irc_server_prefix_char_statusmsg (server, target[0])
+ && irc_channel_is_channel (server, target + 1))
+ {
+ ptr_channel = irc_channel_search (server, target + 1);
+ is_channel = 1;
+ display_target = 1;
+ ptr_target = target + 1;
+ }
+ else
+ {
+ ptr_channel = irc_channel_search (server, target);
+ if (irc_channel_is_channel (server, target))
+ is_channel = 1;
+ }
- /* if message is an action, force "action" to 1 and extract message */
- if (strncmp (text, "\01ACTION ", 8) == 0)
+ if (ptr_channel)
{
- action = 1;
- pos = strrchr (text + 8, '\01');
- if (pos)
- text2 = weechat_strndup (text + 8, pos - text - 8);
- else
- text2 = strdup (text + 8);
+ ptr_buffer = ptr_channel->buffer;
}
else
- text2 = strdup (text);
+ {
+ ptr_buffer = irc_msgbuffer_get_target_buffer (
+ server, ptr_target, command, NULL, NULL);
+ if (!ptr_buffer)
+ ptr_buffer = server->buffer;
+ }
- text_decoded = irc_color_decode (
- (text2) ? text2 : text,
- weechat_config_boolean (irc_config_network_colors_send));
+ if (ptr_buffer == server->buffer)
+ display_target = 1;
- if (ptr_channel)
+ /* if message is an action, force "action" to 1 and extract message */
+ if (text)
{
- ptr_nick = NULL;
- if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
+ if (strncmp (text, "\01ACTION ", 8) == 0)
+ {
+ is_action = 1;
+ pos = strrchr (text + 8, '\01');
+ if (pos)
+ text2 = weechat_strndup (text + 8, pos - text - 8);
+ else
+ text2 = strdup (text + 8);
+ }
+ else
{
- ptr_nick = irc_nick_search (ptr_server, ptr_channel,
- ptr_server->nick);
+ text2 = strdup (text);
}
+ text3 = irc_message_hide_password (server, target, (text2) ? text2 : text);
+ text_decoded = (decode_colors) ?
+ irc_color_decode (
+ (text3) ? text3 : ((text2) ? text2 : text),
+ weechat_config_boolean (irc_config_network_colors_send)) : NULL;
+ }
+ else
+ {
+ text2 = NULL;
+ text3 = NULL;
+ text_decoded = NULL;
+ }
+
+ ptr_nick = NULL;
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ ptr_nick = irc_nick_search (server, ptr_channel, server->nick);
- if (action)
+ if (is_action)
+ {
+ snprintf (str_tags, sizeof (str_tags),
+ "irc_action,self_msg,notify_none,no_highlight");
+ }
+ else
+ {
+ if (display_target)
{
snprintf (str_tags, sizeof (str_tags),
- "irc_action,self_msg,notify_none,no_highlight");
+ "%sself_msg,notify_none,no_highlight",
+ (ctcp_type) ? "irc_ctcp," : "");
}
else
{
str_color = irc_color_for_tags (
weechat_config_color (
weechat_config_get ("weechat.color.chat_nick_self")));
- if (target)
- {
- snprintf (str_tags, sizeof (str_tags),
- "self_msg,notify_none,no_highlight");
- }
- else
- {
- snprintf (str_tags, sizeof (str_tags),
- "self_msg,notify_none,no_highlight,prefix_nick_%s",
- (str_color) ? str_color : "default");
- }
+ snprintf (str_tags, sizeof (str_tags),
+ "%sself_msg,notify_none,no_highlight,prefix_nick_%s",
+ (ctcp_type) ? "irc_ctcp," : "",
+ (str_color) ? str_color : "default");
if (str_color)
free (str_color);
}
- ptr_text = (text_decoded) ? text_decoded : ((text2) ? text2 : text);
- if (action)
- {
- weechat_printf_date_tags (
- buffer,
- 0,
- irc_protocol_tags (
- ptr_server,
- (notice) ? "notice" : "privmsg",
- NULL,
- str_tags,
- (ptr_nick) ? ptr_nick->name : ptr_server->nick,
- NULL),
- "%s%s%s%s%s %s",
- weechat_prefix ("action"),
- irc_nick_mode_for_display (ptr_server, ptr_nick, 0),
- IRC_COLOR_CHAT_NICK_SELF,
- ptr_server->nick,
- IRC_COLOR_RESET,
- ptr_text);
- }
- else if (target)
+ }
+
+ ptr_text = (text_decoded) ?
+ text_decoded : ((text3) ? text3 : ((text2) ? text2 : text));
+
+ if (is_action)
+ {
+ if (display_target)
{
weechat_printf_date_tags (
- buffer,
+ ptr_buffer,
0,
irc_protocol_tags (
- ptr_server,
- (notice) ? "notice" : "privmsg",
+ server,
+ command,
NULL,
str_tags,
- (ptr_nick) ? ptr_nick->name : ptr_server->nick,
- NULL),
- "%s%s%s%s%s(%s%s%s%s)%s -> %s%s%s: %s",
+ (ptr_nick) ? ptr_nick->name : server->nick,
+ address),
+ "%s%s -> %s%s%s: %s%s%s%s%s%s",
weechat_prefix ("network"),
- (notice) ? IRC_COLOR_NOTICE : "",
- (notice) ?
- /* TRANSLATORS: "Notice" is command name in IRC protocol (translation is frequently the same word) */
- _("Notice") :
- "Msg",
- (notice) ? IRC_COLOR_RESET : "",
- IRC_COLOR_CHAT_DELIMITERS,
- irc_nick_mode_for_display (ptr_server, ptr_nick, 0),
- IRC_COLOR_CHAT_NICK_SELF,
- ptr_server->nick,
- IRC_COLOR_CHAT_DELIMITERS,
- IRC_COLOR_RESET,
- (target_is_channel) ?
- IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (ptr_server, 0, NULL, target),
+ /* TRANSLATORS: "Action" is an IRC CTCP "ACTION" sent with /me or /action */
+ _("Action"),
+ (is_channel) ?
+ IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (server, 0, NULL, target),
target,
IRC_COLOR_RESET,
- ptr_text);
+ irc_nick_mode_for_display (server, ptr_nick, 0),
+ IRC_COLOR_CHAT_NICK_SELF,
+ server->nick,
+ (ptr_text && ptr_text[0]) ? IRC_COLOR_RESET : "",
+ (ptr_text && ptr_text[0]) ? " " : "",
+ (ptr_text && ptr_text[0]) ? ptr_text : "");
}
else
{
weechat_printf_date_tags (
- buffer,
+ ptr_buffer,
0,
irc_protocol_tags (
- ptr_server,
- "privmsg",
+ server,
+ command,
NULL,
str_tags,
- (ptr_nick) ? ptr_nick->name : ptr_server->nick,
- NULL),
- "%s%s",
- irc_nick_as_prefix (
- ptr_server,
- (ptr_nick) ? ptr_nick : NULL,
- (ptr_nick) ? NULL : ptr_server->nick,
- IRC_COLOR_CHAT_NICK_SELF),
- ptr_text);
+ (ptr_nick) ? ptr_nick->name : server->nick,
+ address),
+ "%s%s%s%s%s%s%s",
+ weechat_prefix ("action"),
+ irc_nick_mode_for_display (server, ptr_nick, 0),
+ IRC_COLOR_CHAT_NICK_SELF,
+ server->nick,
+ IRC_COLOR_RESET,
+ (ptr_text && ptr_text[0]) ? " " : "",
+ (ptr_text && ptr_text[0]) ? ptr_text : "");
}
}
+ else if (ctcp_type)
+ {
+ weechat_printf_date_tags (
+ ptr_buffer,
+ 0,
+ irc_protocol_tags (
+ server,
+ command,
+ NULL,
+ str_tags,
+ (ptr_nick) ? ptr_nick->name : server->nick,
+ address),
+ _("%sCTCP query to %s%s%s: %s%s%s%s%s"),
+ weechat_prefix ("network"),
+ (is_channel) ?
+ IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (server, 0, NULL, target),
+ target,
+ IRC_COLOR_RESET,
+ IRC_COLOR_CHAT_CHANNEL,
+ ctcp_type,
+ IRC_COLOR_RESET,
+ (ptr_text && ptr_text[0]) ? " " : "",
+ (ptr_text && ptr_text[0]) ? ptr_text : "");
+ }
+ else if (display_target)
+ {
+ weechat_printf_date_tags (
+ ptr_buffer,
+ 0,
+ irc_protocol_tags (
+ server,
+ command,
+ NULL,
+ str_tags,
+ (ptr_nick) ? ptr_nick->name : server->nick,
+ address),
+ "%s%s%s%s%s(%s%s%s%s)%s -> %s%s%s: %s",
+ weechat_prefix ("network"),
+ (is_notice) ? IRC_COLOR_NOTICE : "",
+ (is_notice) ?
+ /* TRANSLATORS: "Notice" is command name in IRC protocol (translation is frequently the same word) */
+ _("Notice") :
+ "Msg",
+ (is_notice) ? IRC_COLOR_RESET : "",
+ IRC_COLOR_CHAT_DELIMITERS,
+ irc_nick_mode_for_display (server, ptr_nick, 0),
+ IRC_COLOR_CHAT_NICK_SELF,
+ server->nick,
+ IRC_COLOR_CHAT_DELIMITERS,
+ IRC_COLOR_RESET,
+ (is_channel) ?
+ IRC_COLOR_CHAT_CHANNEL : irc_nick_color_for_msg (server, 0, NULL, target),
+ target,
+ IRC_COLOR_RESET,
+ (ptr_text) ? ptr_text : "");
+ }
+ else
+ {
+ weechat_printf_date_tags (
+ ptr_buffer,
+ 0,
+ irc_protocol_tags (
+ server,
+ command,
+ NULL,
+ str_tags,
+ (ptr_nick) ? ptr_nick->name : server->nick,
+ address),
+ "%s%s",
+ irc_nick_as_prefix (
+ server,
+ (ptr_nick) ? ptr_nick : NULL,
+ (ptr_nick) ? NULL : server->nick,
+ IRC_COLOR_CHAT_NICK_SELF),
+ (ptr_text) ? ptr_text : "");
+ }
if (text2)
free (text2);
+ if (text3)
+ free (text3);
if (text_decoded)
free (text_decoded);
}
@@ -243,17 +347,22 @@ irc_input_send_user_message (struct t_gui_buffer *buffer, int flags,
ptr_channel->name, message);
if (list_messages)
{
- action = (strncmp (message, "\01ACTION ", 8) == 0);
- list_size = weechat_arraylist_size (list_messages);
- for (i = 0; i < list_size; i++)
+ /* display only if capability "echo-message" is NOT enabled */
+ if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
{
- irc_input_user_message_display (
- buffer,
- action,
- 0, /* notice */
- NULL, /* target */
- 0, /* target_is_channel */
- (const char *)weechat_arraylist_get (list_messages, i));
+ action = (strncmp (message, "\01ACTION ", 8) == 0);
+ list_size = weechat_arraylist_size (list_messages);
+ for (i = 0; i < list_size; i++)
+ {
+ irc_input_user_message_display (
+ ptr_server,
+ ptr_channel->name,
+ NULL, /* address */
+ "privmsg",
+ (action) ? "action" : NULL,
+ (const char *)weechat_arraylist_get (list_messages, i),
+ 1); /* decode_colors */
+ }
}
weechat_arraylist_free (list_messages);
}
diff --git a/src/plugins/irc/irc-input.h b/src/plugins/irc/irc-input.h
index fef8e93e7..f4f43c139 100644
--- a/src/plugins/irc/irc-input.h
+++ b/src/plugins/irc/irc-input.h
@@ -22,11 +22,13 @@
struct t_gui_buffer;
-extern void irc_input_user_message_display (struct t_gui_buffer *buffer,
- int action, int notice,
+extern void irc_input_user_message_display (struct t_irc_server *server,
const char *target,
- int target_is_channel,
- const char *text);
+ const char *address,
+ const char *command,
+ const char *ctcp_type,
+ const char *text,
+ int decode_colors);
extern int irc_input_data_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
const char *input_data);
diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c
index d6fc572b0..a44b0f080 100644
--- a/src/plugins/irc/irc-message.c
+++ b/src/plugins/irc/irc-message.c
@@ -894,6 +894,47 @@ irc_message_replace_vars (struct t_irc_server *server,
}
/*
+ * Hides password in text, if the target is a nick configured in option
+ * irc.look.nicks_hide_password.
+ *
+ * Note: result must be freed after use.
+ */
+
+char *
+irc_message_hide_password (struct t_irc_server *server, const char *target,
+ const char *text)
+{
+ int i, hide_password;
+
+ if (!text)
+ return NULL;
+
+ /* check if the password must be hidden for this nick */
+ hide_password = 0;
+ if (irc_config_nicks_hide_password)
+ {
+ for (i = 0; i < irc_config_num_nicks_hide_password; i++)
+ {
+ if (weechat_strcasecmp (irc_config_nicks_hide_password[i],
+ target) == 0)
+ {
+ hide_password = 1;
+ break;
+ }
+ }
+ }
+
+ /* hide password in message displayed using modifier */
+ if (hide_password)
+ {
+ return weechat_hook_modifier_exec ("irc_message_auth", server->name,
+ text);
+ }
+
+ return strdup (text);
+}
+
+/*
* Adds a message + arguments in hashtable.
*/
diff --git a/src/plugins/irc/irc-message.h b/src/plugins/irc/irc-message.h
index b0670fba5..5b73d4565 100644
--- a/src/plugins/irc/irc-message.h
+++ b/src/plugins/irc/irc-message.h
@@ -58,6 +58,8 @@ extern int irc_message_ignored (struct t_irc_server *server,
extern char *irc_message_replace_vars (struct t_irc_server *server,
const char *channel_name,
const char *string);
+extern char *irc_message_hide_password (struct t_irc_server *server,
+ const char *target, const char *text);
extern struct t_hashtable *irc_message_split (struct t_irc_server *server,
const char *message);
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index e62ad6d1e..951239815 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -49,6 +49,7 @@
#include "irc-config.h"
#include "irc-ctcp.h"
#include "irc-ignore.h"
+#include "irc-input.h"
#include "irc-join.h"
#include "irc-message.h"
#include "irc-mode.h"
@@ -2959,7 +2960,6 @@ IRC_PROTOCOL_CALLBACK(pong)
void
irc_protocol_privmsg_display_ctcp_send (struct t_irc_server *server,
- struct t_irc_channel *channel,
const char *target,
const char *address,
const char *arguments)
@@ -2983,7 +2983,14 @@ irc_protocol_privmsg_display_ctcp_send (struct t_irc_server *server,
ctcp_args = (pos_space) ?
weechat_strndup (pos_space + 1, pos_end - pos_space - 1) : NULL;
- irc_ctcp_display_send (server, channel, target, address, ctcp_type, ctcp_args);
+ irc_input_user_message_display (
+ server,
+ target,
+ address,
+ "privmsg",
+ ctcp_type,
+ ctcp_args,
+ 0); /* decode_colors */
if (ctcp_type)
free (ctcp_type);
@@ -3055,7 +3062,7 @@ IRC_PROTOCOL_CALLBACK(privmsg)
if (nick_is_me)
{
irc_protocol_privmsg_display_ctcp_send (
- server, ptr_channel, params[0], address, msg_args);
+ server, params[0], address, msg_args);
}
else
{
@@ -3163,7 +3170,7 @@ IRC_PROTOCOL_CALLBACK(privmsg)
if (nick_is_me)
{
irc_protocol_privmsg_display_ctcp_send (
- server, ptr_channel, remote_nick, address, msg_args);
+ server, remote_nick, address, msg_args);
}
else
{