summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2021-06-12 21:18:42 +0200
committerSébastien Helleu <flashcode@flashtux.org>2021-06-15 18:56:41 +0200
commit70b66c4f6b708269712f71c52d7ca0c2d6766b94 (patch)
treeedaa5c72d3ce32268531237bbfbb1e15a7839652 /src
parent0525922ee4b50911c44b1c4d5b79c19a5f0660ee (diff)
downloadweechat-70b66c4f6b708269712f71c52d7ca0c2d6766b94.zip
irc: add command /setname, add support of message and capability "setname" (closes #1653)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-command.c30
-rw-r--r--src/plugins/irc/irc-command.h2
-rw-r--r--src/plugins/irc/irc-protocol.c53
3 files changed, 83 insertions, 2 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index f14f70ef2..9c8d88087 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -5670,6 +5670,27 @@ IRC_COMMAND_CALLBACK(squery)
}
/*
+ * Callback for command "/setname": set real name.
+ */
+
+IRC_COMMAND_CALLBACK(setname)
+{
+ IRC_BUFFER_GET_SERVER(buffer);
+ IRC_COMMAND_CHECK_SERVER("setname", 1, 1);
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+
+ WEECHAT_COMMAND_MIN_ARGS(2, "");
+
+ irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
+ "SETNAME :%s", argv_eol[1]);
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* Callback for command "/squit": disconnects server links.
*/
@@ -6480,7 +6501,8 @@ irc_command_init ()
"\n"
"Capabilities supported by WeeChat are: "
"account-notify, away-notify, cap-notify, chghost, extended-join, "
- "invite-notify, multi-prefix, server-time, userhost-in-names.\n"
+ "invite-notify, multi-prefix, server-time, setname, "
+ "userhost-in-names.\n"
"\n"
"The capabilities to automatically enable on servers can be set "
"in option irc.server_default.capabilities (or by server in "
@@ -7108,6 +7130,12 @@ irc_command_init ()
" text: text to send"),
NULL, &irc_command_squery, NULL, NULL);
weechat_hook_command (
+ "setname",
+ N_("set real name"),
+ N_("<realname>"),
+ N_("realname: new real name"),
+ NULL, &irc_command_setname, NULL, NULL);
+ weechat_hook_command (
"squit",
N_("disconnect server links"),
N_("<target> <comment>"),
diff --git a/src/plugins/irc/irc-command.h b/src/plugins/irc/irc-command.h
index 69d1b3f30..e9a82cdb7 100644
--- a/src/plugins/irc/irc-command.h
+++ b/src/plugins/irc/irc-command.h
@@ -56,7 +56,7 @@ struct t_irc_channel;
/* list of supported capabilities (for completion in command /cap) */
#define IRC_COMMAND_CAP_SUPPORTED_COMPLETION \
"account-notify|away-notify|cap-notify|chghost|extended-join|" \
- "invite-notify|multi-prefix|server-time|userhost-in-names|%*"
+ "invite-notify|multi-prefix|server-time|setname|userhost-in-names|%*"
/* list of supported CTCPs (for completion in command /ctcp) */
#define IRC_COMMAND_CTCP_SUPPORTED_COMPLETION \
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index acea9fd90..642f7a8e2 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -2847,6 +2847,58 @@ IRC_PROTOCOL_CALLBACK(quit)
}
/*
+ * Callback for the IRC message "SETNAME": set real name
+ * (with capability "setname").
+ *
+ * Message looks like:
+ * :nick!user@host SETNAME :the realname
+ */
+
+IRC_PROTOCOL_CALLBACK(setname)
+{
+ struct t_irc_channel *ptr_channel;
+ struct t_irc_nick *ptr_nick;
+ char *pos_realname, *realname_color;
+
+ IRC_PROTOCOL_MIN_ARGS(3);
+
+ pos_realname = (argv_eol[2][0] == ':') ? argv_eol[2] + 1 : argv_eol[2];
+
+ if (weechat_hashtable_has_key (server->cap_list, "setname"))
+ {
+ for (ptr_channel = server->channels; ptr_channel;
+ ptr_channel = ptr_channel->next_channel)
+ {
+ ptr_nick = irc_nick_search (server, ptr_channel, nick);
+ if (ptr_nick)
+ {
+ if (ptr_nick->realname)
+ free (ptr_nick->realname);
+ ptr_nick->realname = strdup (pos_realname);
+ }
+ }
+ }
+
+ if (!ignored)
+ {
+ realname_color = irc_color_decode (
+ pos_realname,
+ weechat_config_boolean (irc_config_network_colors_receive));
+ weechat_printf_date_tags (
+ irc_msgbuffer_get_target_buffer (server, NULL, command, NULL, NULL),
+ date,
+ irc_protocol_tags (command, NULL, NULL, NULL),
+ _("%sReal name set to: %s"),
+ weechat_prefix ("network"),
+ (realname_color) ? realname_color : "");
+ if (realname_color)
+ free (realname_color);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* Callback for an IRC message with mode and reason (numeric).
*/
@@ -6611,6 +6663,7 @@ irc_protocol_recv_command (struct t_irc_server *server,
IRCB(pong, 1, 0, pong), /* answer to a ping message */
IRCB(privmsg, 1, 1, privmsg), /* message received */
IRCB(quit, 1, 1, quit), /* close all connections and quit */
+ IRCB(setname, 0, 1, setname), /* set realname */
IRCB(topic, 0, 1, topic), /* get/set channel topic */
IRCB(wallops, 1, 1, wallops), /* wallops */
IRCB(warn, 1, 0, warn), /* warning received from server */