1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 15:26:37 +02:00

irc: use redirection to get channel modes after update of modes on channel, display output of /mode #channel

This commit is contained in:
Sebastien Helleu
2012-01-06 11:24:01 +01:00
parent 4e870c71cb
commit 4cde51a27f
7 changed files with 141 additions and 54 deletions
+3 -1
View File
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
v0.3.7-dev, 2012-01-03
v0.3.7-dev, 2012-01-06
Version 0.3.7 (under dev!)
@@ -42,6 +42,8 @@ Version 0.3.7 (under dev!)
* api: add new functions strcasecmp_range, strncasecmp_range,
hashtable_map_string, hdata_check_pointer, hdata_char, hdata_hashtable and
nicklist_get_next_item
* irc: use redirection to get channel modes after update of modes on channel,
display output of /mode #channel
* irc: do not use option irc.look.nick_color_stop_chars for forced nick colors
(bug #33480)
* irc: add optional server in info "irc_is_channel" (before channel name)
+13 -5
View File
@@ -266,7 +266,6 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
new_channel->has_quit_server = 0;
new_channel->cycle = 0;
new_channel->part = 0;
new_channel->display_creation_date = 0;
new_channel->nick_completion_reset = 0;
new_channel->pv_remote_nick_color = NULL;
new_channel->hook_autorejoin = NULL;
@@ -346,6 +345,19 @@ irc_channel_set_topic (struct t_irc_channel *channel, const char *topic)
(channel->topic) ? channel->topic : "");
}
/*
* irc_channel_set_modes: set modes for a channel
*/
void
irc_channel_set_modes (struct t_irc_channel *channel, const char *modes)
{
if (channel->modes)
free (channel->modes);
channel->modes = (modes) ? strdup (modes) : NULL;
}
/*
* irc_channel_search: returns pointer on a channel with name
*/
@@ -870,7 +882,6 @@ irc_channel_hdata_channel_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_channel, has_quit_server, INTEGER, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, cycle, INTEGER, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, part, INTEGER, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, display_creation_date, INTEGER, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, nick_completion_reset, INTEGER, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, pv_remote_nick_color, STRING, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, hook_autorejoin, POINTER, NULL);
@@ -969,8 +980,6 @@ irc_channel_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "part", channel->part))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "display_creation_date", channel->display_creation_date))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "nick_completion_reset", channel->nick_completion_reset))
return 0;
for (i = 0; i < 2; i++)
@@ -1038,7 +1047,6 @@ irc_channel_print_log (struct t_irc_channel *channel)
weechat_log_printf (" has_quit_server. . . . . : %d", channel->has_quit_server);
weechat_log_printf (" cycle. . . . . . . . . . : %d", channel->cycle);
weechat_log_printf (" part . . . . . . . . . . : %d", channel->part);
weechat_log_printf (" display_creation_date. . : %d", channel->display_creation_date);
weechat_log_printf (" nick_completion_reset. . : %d", channel->nick_completion_reset);
weechat_log_printf (" pv_remote_nick_color . . : '%s'", channel->pv_remote_nick_color);
weechat_log_printf (" hook_autorejoin. . . . . : 0x%lx", channel->hook_autorejoin);
+2 -1
View File
@@ -53,7 +53,6 @@ struct t_irc_channel
/* display message when he's back */
int cycle; /* currently cycling (/part + /join) */
int part; /* /part done on channel? */
int display_creation_date; /* 1 for displaying creation date */
int nick_completion_reset; /* 1 for resetting nick completion */
/* there was some join/part on chan */
char *pv_remote_nick_color; /* color for remote nick in pv */
@@ -82,6 +81,8 @@ extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server,
int auto_switch);
extern void irc_channel_set_topic (struct t_irc_channel *channel,
const char *topic);
extern void irc_channel_set_modes (struct t_irc_channel *channel,
const char *modes);
extern void irc_channel_free (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_free_all (struct t_irc_server *server);
+116 -46
View File
@@ -487,12 +487,9 @@ IRC_PROTOCOL_CALLBACK(join)
}
}
/* remove topic and display channel creation date if joining new channel */
/* remove topic if joining new channel */
if (!ptr_channel->nicks)
{
irc_channel_set_topic (ptr_channel, NULL);
ptr_channel->display_creation_date = 1;
}
/* add nick in channel */
ptr_nick = irc_nick_new (server, ptr_channel, nick, NULL, 0);
@@ -731,6 +728,7 @@ IRC_PROTOCOL_CALLBACK(mode)
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
struct t_gui_buffer *ptr_buffer;
struct t_hashtable *hashtable;
/*
* MODE message looks like:
@@ -747,10 +745,36 @@ IRC_PROTOCOL_CALLBACK(mode)
ptr_channel = irc_channel_search (server, argv[2]);
if (ptr_channel)
{
if (irc_mode_channel_set (server, ptr_channel, pos_modes))
if (ptr_channel->modes)
{
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
"MODE %s", ptr_channel->name);
if (irc_mode_channel_set (server, ptr_channel, pos_modes))
{
hashtable = weechat_hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
if (hashtable)
{
weechat_hashtable_set (hashtable, "server", server->name);
weechat_hashtable_set (hashtable, "pattern", "mode_channel");
weechat_hashtable_set (hashtable, "signal", "mode");
weechat_hashtable_set (hashtable, "string", ptr_channel->name);
weechat_hook_hsignal_send ("irc_redirect_command", hashtable);
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW,
NULL, "MODE %s", ptr_channel->name);
weechat_hashtable_free (hashtable);
}
else
{
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW,
NULL, "MODE %s", ptr_channel->name);
}
}
}
else
{
(void) irc_mode_channel_set (server, ptr_channel, pos_modes);
}
}
ptr_nick = irc_nick_search (server, ptr_channel, nick);
@@ -2605,39 +2629,26 @@ IRC_PROTOCOL_CALLBACK(324)
ptr_channel = irc_channel_search (server, argv[3]);
if (ptr_channel)
{
irc_channel_set_modes (ptr_channel, ((argc > 4) ? argv_eol[4] : NULL));
if (argc > 4)
{
if (ptr_channel->modes)
free (ptr_channel->modes);
ptr_channel->modes = strdup (argv_eol[4]);
irc_mode_channel_set (server, ptr_channel,
ptr_channel->modes);
}
else
{
if (ptr_channel->modes)
{
free (ptr_channel->modes);
ptr_channel->modes = NULL;
}
}
}
else
{
weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL,
NULL),
irc_protocol_tags (command, "irc_numeric", NULL),
_("%sMode %s%s %s[%s%s%s]"),
weechat_prefix ("network"),
IRC_COLOR_CHAT_CHANNEL,
argv[3],
IRC_COLOR_CHAT_DELIMITERS,
IRC_COLOR_RESET,
(argc > 4) ?
((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : "",
IRC_COLOR_CHAT_DELIMITERS);
}
weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL,
(ptr_channel) ? ptr_channel->buffer : NULL),
irc_protocol_tags (command, "irc_numeric", NULL),
_("%sMode %s%s %s[%s%s%s]"),
weechat_prefix ("network"),
IRC_COLOR_CHAT_CHANNEL,
argv[3],
IRC_COLOR_CHAT_DELIMITERS,
IRC_COLOR_RESET,
(argc > 4) ?
((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : "",
IRC_COLOR_CHAT_DELIMITERS);
return WEECHAT_RC_OK;
}
@@ -2757,18 +2768,14 @@ IRC_PROTOCOL_CALLBACK(329)
if (ptr_channel)
{
if (ptr_channel->display_creation_date)
{
weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL,
ptr_channel->buffer),
irc_protocol_tags (command, "irc_numeric", NULL),
/* TRANSLATORS: "%s" after "created on" is a date */
_("%sChannel created on %s"),
weechat_prefix ("network"),
weechat_util_get_time_string (&datetime));
ptr_channel->display_creation_date = 0;
}
weechat_printf_tags (irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL,
ptr_channel->buffer),
irc_protocol_tags (command, "irc_numeric", NULL),
/* TRANSLATORS: "%s" after "created on" is a date */
_("%sChannel created on %s"),
weechat_prefix ("network"),
weechat_util_get_time_string (&datetime));
}
else
{
@@ -4208,6 +4215,69 @@ IRC_PROTOCOL_CALLBACK(sasl_end)
return WEECHAT_RC_OK;
}
/*
* irc_protocol_redirection_mode_cb: callback for redirection of "mode" command
*/
int
irc_protocol_redirection_mode_cb (void *data, const char *signal,
struct t_hashtable *hashtable)
{
const char *output, *server;
char **messages, *command, *arguments, **argv, **argv_eol;
int num_messages, argc, i;
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
/* make C compiler happy */
(void) data;
(void) signal;
output = weechat_hashtable_get (hashtable, "output");
server = weechat_hashtable_get (hashtable, "server");
if (!output || !server)
return WEECHAT_RC_OK;
ptr_server = irc_server_search (server);
if (!ptr_server)
return WEECHAT_RC_OK;
messages = weechat_string_split (output, "\n", 0, 0, &num_messages);
if (messages)
{
for (i = 0; i < num_messages; i++)
{
irc_message_parse (ptr_server, messages[i], NULL, NULL,
&command, NULL, &arguments);
if (command && (strcmp (command, "324") == 0) && arguments)
{
argv = weechat_string_split (arguments, " ", 0, 0, &argc);
argv_eol = weechat_string_split (arguments, " ", 1, 0, NULL);
if (argv && argv_eol && (argc >= 2))
{
ptr_channel = irc_channel_search (ptr_server, argv[1]);
if (ptr_channel)
{
irc_channel_set_modes (ptr_channel,
(argc >= 3) ? argv_eol[2] : NULL);
if (argc >= 3)
{
irc_mode_channel_set (ptr_server, ptr_channel,
ptr_channel->modes);
}
}
}
if (argv)
weechat_string_free_split (argv);
if (argv_eol)
weechat_string_free_split (argv_eol);
}
}
weechat_string_free_split (messages);
}
return WEECHAT_RC_OK;
}
/*
* irc_protocol_recv_command: executes action when receiving IRC command
* return: 0 = all ok, command executed
+2
View File
@@ -79,6 +79,8 @@ struct t_irc_protocol_msg
extern const char *irc_protocol_tags (const char *command, const char *tags,
const char *nick);
extern int irc_protocol_redirection_mode_cb (void *data, const char *signal,
struct t_hashtable *hashtable);
extern void irc_protocol_recv_command (struct t_irc_server *server,
const char *irc_message,
const char *msg_command,
-1
View File
@@ -423,7 +423,6 @@ irc_upgrade_read_cb (void *data,
irc_upgrade_current_channel->has_quit_server = weechat_infolist_integer (infolist, "has_quit_server");
irc_upgrade_current_channel->cycle = weechat_infolist_integer (infolist, "cycle");
irc_upgrade_current_channel->part = weechat_infolist_integer (infolist, "part");
irc_upgrade_current_channel->display_creation_date = weechat_infolist_integer (infolist, "display_creation_date");
irc_upgrade_current_channel->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset");
for (i = 0; i < 2; i++)
{
+5
View File
@@ -40,6 +40,7 @@
#include "irc-input.h"
#include "irc-nick.h"
#include "irc-notify.h"
#include "irc-protocol.h"
#include "irc-raw.h"
#include "irc-redirect.h"
#include "irc-server.h"
@@ -184,6 +185,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_hsignal ("irc_redirect_pattern", &irc_redirect_pattern_hsignal_cb, NULL);
weechat_hook_hsignal ("irc_redirect_command", &irc_redirect_command_hsignal_cb, NULL);
/* hook hsignal for redirection of "mode" output */
weechat_hook_hsignal ("irc_redirection_mode_mode_channel",
&irc_protocol_redirection_mode_cb, NULL);
/* modifiers */
weechat_hook_modifier ("irc_color_decode", &irc_color_modifier_cb, NULL);
weechat_hook_modifier ("irc_color_encode", &irc_color_modifier_cb, NULL);