1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

Merge remote-tracking branch 'origin/pr/246' into irc-account-notify

This commit is contained in:
Sébastien Helleu
2015-01-25 14:56:47 +01:00
8 changed files with 215 additions and 23 deletions
+32 -9
View File
@@ -463,7 +463,7 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
WEECHAT_HASHTABLE_STRING,
NULL,
NULL);
new_channel->checking_away = 0;
new_channel->checking_whox = 0;
new_channel->away_message = NULL;
new_channel->has_quit_server = 0;
new_channel->cycle = 0;
@@ -678,6 +678,25 @@ irc_channel_get_auto_chantype (struct t_irc_server *server,
return chantype;
}
/*
* Removes account for all nicks on a channel.
*/
void
irc_channel_remove_account (struct t_irc_server *server,
struct t_irc_channel *channel)
{
struct t_irc_nick *ptr_nick;
if (channel->type == IRC_CHANNEL_TYPE_CHANNEL)
{
for (ptr_nick = channel->nicks; ptr_nick; ptr_nick = ptr_nick->next_nick)
{
ptr_nick->account = strdup ("*");
}
}
}
/*
* Removes away for all nicks on a channel.
*/
@@ -698,26 +717,30 @@ irc_channel_remove_away (struct t_irc_server *server,
}
/*
* Checks for away on a channel.
* Checks for WHOX information on a channel.
*/
void
irc_channel_check_away (struct t_irc_server *server,
irc_channel_check_whox (struct t_irc_server *server,
struct t_irc_channel *channel)
{
if ((channel->type == IRC_CHANNEL_TYPE_CHANNEL) && channel->nicks)
{
if (server->cap_away_notify
|| server->cap_account_notify
|| ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
&& ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS) == 0)
|| (channel->nicks_count <= IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS)))))
{
channel->checking_away++;
channel->checking_whox++;
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
"WHO %s", channel->name);
"WHO %s %%cuhsnfdar", channel->name);
}
else
irc_channel_remove_away (server, channel);
{
irc_channel_remove_account(server, channel);
irc_channel_remove_away(server, channel);
}
}
}
@@ -1456,7 +1479,7 @@ irc_channel_hdata_channel_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_channel, limit, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, key, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, join_msg_received, HASHTABLE, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, checking_away, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, checking_whox, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, away_message, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, has_quit_server, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_channel, cycle, INTEGER, 0, NULL, NULL);
@@ -1553,7 +1576,7 @@ irc_channel_add_to_infolist (struct t_infolist *infolist,
if (!weechat_infolist_new_var_string (ptr_item, "join_msg_received",
weechat_hashtable_get_string (channel->join_msg_received, "keys")))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "checking_away", channel->checking_away))
if (!weechat_infolist_new_var_integer (ptr_item, "checking_whox", channel->checking_whox))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "away_message", channel->away_message))
return 0;
@@ -1637,7 +1660,7 @@ irc_channel_print_log (struct t_irc_channel *channel)
channel->join_msg_received,
weechat_hashtable_get_string (channel->join_msg_received,
"keys_values"));
weechat_log_printf (" checking_away. . . . . . : %d", channel->checking_away);
weechat_log_printf (" checking_whox. . . . . . : %d", channel->checking_whox);
weechat_log_printf (" away_message . . . . . . : '%s'", channel->away_message);
weechat_log_printf (" has_quit_server. . . . . : %d", channel->has_quit_server);
weechat_log_printf (" cycle. . . . . . . . . . : %d", channel->cycle);
+4 -2
View File
@@ -50,7 +50,7 @@ struct t_irc_channel
struct t_hashtable *join_msg_received; /* messages received after join: */
/* 353=names, 366=names count, */
/* 332/333=topic, 329=creation date */
int checking_away; /* = 1 if checking away with WHO cmd */
int checking_whox; /* = 1 if checking WHOX */
char *away_message; /* to display away only once in pv */
int has_quit_server; /* =1 if nick has quit (pv only), to */
/* display message when he's back */
@@ -107,9 +107,11 @@ extern int irc_channel_is_channel (struct t_irc_server *server,
const char *string);
extern const char *irc_channel_get_auto_chantype (struct t_irc_server *server,
const char *channel_name);
extern void irc_channel_remove_account (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_remove_away (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_check_away (struct t_irc_server *server,
extern void irc_channel_check_whox (struct t_irc_server *server,
struct t_irc_channel *channel);
extern void irc_channel_set_away (struct t_irc_server *server,
struct t_irc_channel *channel,
+12 -1
View File
@@ -624,7 +624,7 @@ irc_nick_nicklist_set_color_all ()
struct t_irc_nick *
irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
const char *nickname, const char *host, const char *prefixes,
int away)
int away, char *account)
{
struct t_irc_nick *new_nick, *ptr_nick;
int length;
@@ -642,12 +642,16 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
/* save away status from existing nick (before removing it) */
away = ptr_nick->away;
/* save account from existing nick (before removing it) */
account = ptr_nick->account;
/* remove old nick from nicklist */
irc_nick_nicklist_remove (server, channel, ptr_nick);
/* update nick */
irc_nick_set_prefixes (server, ptr_nick, prefixes);
ptr_nick->away = away;
ptr_nick->account = account;
/* add new nick in nicklist */
irc_nick_nicklist_add (server, channel, ptr_nick);
@@ -662,6 +666,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
/* initialize new nick */
new_nick->name = strdup (nickname);
new_nick->host = (host) ? strdup (host) : NULL;
new_nick->account = (account) ? strdup (account) : NULL;
length = strlen (irc_server_get_prefix_chars (server));
new_nick->prefixes = malloc (length + 1);
if (!new_nick->name || !new_nick->prefixes)
@@ -670,6 +675,8 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
free (new_nick->name);
if (new_nick->host)
free (new_nick->host);
if (new_nick->account)
free (new_nick->account);
if (new_nick->prefixes)
free (new_nick->prefixes);
free (new_nick);
@@ -810,6 +817,8 @@ irc_nick_free (struct t_irc_server *server, struct t_irc_channel *channel,
free (nick->host);
if (nick->prefixes)
free (nick->prefixes);
if (nick->account)
free (nick->account);
if (nick->color)
free (nick->color);
@@ -1167,6 +1176,8 @@ irc_nick_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "away", nick->away))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "account", nick->account))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "color", nick->color))
return 0;
+3 -1
View File
@@ -38,6 +38,7 @@ struct t_irc_nick
char prefix[2]; /* current prefix (higher prefix set in */
/* prefixes) */
int away; /* 1 if nick is away */
char *account; /* account name of the user */
char *color; /* color for nickname */
struct t_irc_nick *prev_nick; /* link to previous nick on channel */
struct t_irc_nick *next_nick; /* link to next nick on channel */
@@ -64,7 +65,8 @@ extern struct t_irc_nick *irc_nick_new (struct t_irc_server *server,
const char *nickname,
const char *host,
const char *prefixes,
int away);
int away,
char *account);
extern void irc_nick_change (struct t_irc_server *server,
struct t_irc_channel *channel,
struct t_irc_nick *nick, const char *new_nick);
+152 -7
View File
@@ -294,6 +294,40 @@ IRC_PROTOCOL_CALLBACK(away)
return WEECHAT_RC_OK;
}
/*
* Callback for the IRC message "ACCOUNT": account info about a nick
* (with capability "account-notify").
*
* Message looks like:
* :nick!user@host ACCOUNT *
* :nick!user@host ACCOUNT accountname
*/
IRC_PROTOCOL_CALLBACK(account)
{
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
IRC_PROTOCOL_MIN_ARGS(3);
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->account)
free (ptr_nick->account);
if (server->cap_account_notify)
ptr_nick->account = strdup (argv[2]);
else
ptr_nick->account = strdup ("*");
}
}
return WEECHAT_RC_OK;
}
/*
* Callback for the IRC message "CAP": client capability.
*
@@ -437,6 +471,10 @@ IRC_PROTOCOL_CALLBACK(cap)
{
server->cap_away_notify = 1;
}
else if (strcmp (caps_supported[i], "account-notify") == 0)
{
server->cap_account_notify = 1;
}
}
weechat_string_free_split (caps_supported);
}
@@ -704,11 +742,14 @@ IRC_PROTOCOL_CALLBACK(join)
}
ptr_channel->limit = 0;
weechat_hashtable_remove_all (ptr_channel->join_msg_received);
ptr_channel->checking_away = 0;
ptr_channel->checking_whox = 0;
}
/* add nick in channel */
ptr_nick = irc_nick_new (server, ptr_channel, nick, address, NULL, 0);
if (pos_account)
ptr_nick = irc_nick_new (server, ptr_channel, nick, address, NULL, 0, pos_account);
else
ptr_nick = irc_nick_new (server, ptr_channel, nick, address, NULL, 0, "*");
/* rename the nick if it was in list with a different case */
irc_channel_nick_speaking_rename_if_present (server, ptr_channel, nick);
@@ -2860,9 +2901,9 @@ IRC_PROTOCOL_CALLBACK(315)
IRC_PROTOCOL_MIN_ARGS(5);
ptr_channel = irc_channel_search (server, argv[3]);
if (ptr_channel && (ptr_channel->checking_away > 0))
if (ptr_channel && (ptr_channel->checking_whox > 0))
{
ptr_channel->checking_away--;
ptr_channel->checking_whox--;
}
else
{
@@ -4023,7 +4064,7 @@ IRC_PROTOCOL_CALLBACK(352)
}
/* display output of who (manual who from user) */
if (!ptr_channel || (ptr_channel->checking_away <= 0))
if (!ptr_channel || (ptr_channel->checking_whox <= 0))
{
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
@@ -4132,7 +4173,7 @@ IRC_PROTOCOL_CALLBACK(353)
if (ptr_channel && ptr_channel->nicks)
{
if (!irc_nick_new (server, ptr_channel, nickname, pos_host,
prefixes, 0))
prefixes, 0, "*"))
{
weechat_printf (
server->buffer,
@@ -4197,6 +4238,108 @@ IRC_PROTOCOL_CALLBACK(353)
return WEECHAT_RC_OK;
}
/*
* Callback for the IRC message "354": WHOX output
*
* Message looks like:
* :server 354 mynick #channel user host server nick status hopcount account :GECOS Information
*/
IRC_PROTOCOL_CALLBACK(354)
{
char *pos_attr, *pos_hopcount, *pos_account, *pos_realname;
int length;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
IRC_PROTOCOL_MIN_ARGS(5);
/* silently ignore malformed 354 message (missing infos) */
if (argc < 11)
return WEECHAT_RC_OK;
pos_attr = argv[8];
pos_hopcount = argv[9];
pos_account = NULL;
pos_realname = (argc > 11) ?
((argv_eol[11][0] == ':') ? argv_eol[11] + 1 : argv_eol[11]) : NULL;
if (argv[10][0] != '0')
pos_account = argv[10];
ptr_channel = irc_channel_search (server, argv[3]);
ptr_nick = (ptr_channel) ?
irc_nick_search (server, ptr_channel, argv[7]) : NULL;
/* update host for nick */
if (ptr_nick)
{
if (ptr_nick->host)
free (ptr_nick->host);
length = strlen (argv[4]) + 1 + strlen (argv[5]) + 1;
ptr_nick->host = malloc (length);
if (ptr_nick->host)
snprintf (ptr_nick->host, length, "%s@%s", argv[4], argv[5]);
}
/* update away flag for nick */
if (ptr_channel && ptr_nick && pos_attr
&& (server->cap_away_notify
|| ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK) > 0)
&& ((IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS) == 0)
|| (ptr_channel->nicks_count <= IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS))))))
{
irc_nick_set_away (server, ptr_channel, ptr_nick,
(pos_attr[0] == 'G') ? 1 : 0);
}
else
{
irc_nick_set_away (server, ptr_channel, ptr_nick, 0);
}
/* update account flag for nick */
if (ptr_channel && ptr_nick && pos_account && server->cap_account_notify)
ptr_nick->account = (pos_account) ? strdup (pos_account) : strdup ("*");
else
ptr_nick->account = strdup ("*");
/* display output of who (manual who from user) */
if (!ptr_channel || (ptr_channel->checking_whox <= 0))
{
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
server, NULL, command, "who", NULL),
date,
irc_protocol_tags (command, "irc_numeric", NULL, NULL),
"%s%s[%s%s%s] %s%s %s%s%s%s%s%s(%s%s@%s%s)%s %s%s%s%s(%s)",
weechat_prefix("network"),
IRC_COLOR_CHAT_DELIMITERS,
IRC_COLOR_CHAT_CHANNEL,
argv[3],
IRC_COLOR_CHAT_DELIMITERS,
irc_nick_color_for_msg (server, 1, NULL, argv[7]),
argv[7],
IRC_COLOR_CHAT_DELIMITERS,
(pos_account) ? "[" : "",
(pos_account) ? IRC_COLOR_CHAT_HOST : "",
(pos_account) ? pos_account : "",
(pos_account) ? IRC_COLOR_CHAT_DELIMITERS : "",
(pos_account) ? "] " : "",
IRC_COLOR_CHAT_HOST,
argv[4],
argv[5],
IRC_COLOR_CHAT_DELIMITERS,
IRC_COLOR_RESET,
(pos_attr) ? pos_attr : "",
(pos_attr) ? " " : "",
(pos_hopcount) ? pos_hopcount : "",
(pos_hopcount) ? " " : "",
(pos_realname) ? pos_realname : "");
}
return WEECHAT_RC_OK;
}
/*
* Callback for the IRC message "366": end of /names list.
*
@@ -4388,7 +4531,7 @@ IRC_PROTOCOL_CALLBACK(366)
{
irc_command_mode_server (server, "MODE", ptr_channel, NULL,
IRC_SERVER_SEND_OUTQ_PRIO_LOW);
irc_channel_check_away (server, ptr_channel);
irc_channel_check_whox (server, ptr_channel);
}
}
else
@@ -5258,6 +5401,7 @@ irc_protocol_recv_command (struct t_irc_server *server,
struct t_irc_protocol_msg irc_protocol_messages[] =
{ { "authenticate", /* authenticate */ 1, 0, &irc_protocol_cb_authenticate },
{ "away", /* away (cap away-notify) */ 1, 0, &irc_protocol_cb_away },
{ "account", /* account (cap account-notify) */ 1, 0, &irc_protocol_cb_account },
{ "cap", /* client capability */ 1, 0, &irc_protocol_cb_cap },
{ "error", /* error received from IRC server */ 1, 0, &irc_protocol_cb_error },
{ "invite", /* invite a nick on a channel */ 1, 0, &irc_protocol_cb_invite },
@@ -5323,6 +5467,7 @@ irc_protocol_recv_command (struct t_irc_server *server,
{ "351", /* server version */ 1, 0, &irc_protocol_cb_351 },
{ "352", /* who */ 1, 0, &irc_protocol_cb_352 },
{ "353", /* list of nicks on channel */ 1, 0, &irc_protocol_cb_353 },
{ "354", /* whox */ 1, 0, &irc_protocol_cb_354 },
{ "366", /* end of /names list */ 1, 0, &irc_protocol_cb_366 },
{ "367", /* banlist */ 1, 0, &irc_protocol_cb_367 },
{ "368", /* end of banlist */ 1, 0, &irc_protocol_cb_368 },
+7 -1
View File
@@ -993,6 +993,7 @@ irc_server_alloc (const char *name)
new_server->nick = NULL;
new_server->nick_modes = NULL;
new_server->cap_away_notify = 0;
new_server->cap_account_notify = 0;
new_server->isupport = NULL;
new_server->prefix_modes = NULL;
new_server->prefix_chars = NULL;
@@ -4525,6 +4526,7 @@ irc_server_disconnect (struct t_irc_server *server, int switch_address,
weechat_bar_item_update ("irc_nick_modes");
}
server->cap_away_notify = 0;
server->cap_account_notify = 0;
server->is_away = 0;
server->away_time = 0;
server->lag = 0;
@@ -4795,7 +4797,7 @@ irc_server_check_away (struct t_irc_server *server)
ptr_channel = ptr_channel->next_channel)
{
if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL)
irc_channel_check_away (server, ptr_channel);
irc_channel_check_whox (server, ptr_channel);
}
server->last_away_check = time (NULL);
}
@@ -5106,6 +5108,7 @@ irc_server_hdata_server_cb (void *data, const char *hdata_name)
WEECHAT_HDATA_VAR(struct t_irc_server, nick, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, nick_modes, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_away_notify, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, cap_account_notify, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, isupport, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, prefix_modes, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, prefix_chars, STRING, 0, NULL, NULL);
@@ -5322,6 +5325,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "cap_away_notify", server->cap_away_notify))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "cap_account_notify", server->cap_account_notify))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "prefix_modes", server->prefix_modes))
@@ -5682,6 +5687,7 @@ irc_server_print_log ()
weechat_log_printf (" nick . . . . . . . . : '%s'", ptr_server->nick);
weechat_log_printf (" nick_modes . . . . . : '%s'", ptr_server->nick_modes);
weechat_log_printf (" cap_away_notify. . . : %d", ptr_server->cap_away_notify);
weechat_log_printf (" cap_account_notify . : %d", ptr_server->cap_account_notify);
weechat_log_printf (" isupport . . . . . . : '%s'", ptr_server->isupport);
weechat_log_printf (" prefix_modes . . . . : '%s'", ptr_server->prefix_modes);
weechat_log_printf (" prefix_chars . . . . : '%s'", ptr_server->prefix_chars);
+1
View File
@@ -185,6 +185,7 @@ struct t_irc_server
char *nick; /* current nickname */
char *nick_modes; /* nick modes */
int cap_away_notify; /* 1 if capability away-notify is enabled*/
int cap_account_notify; /* 1 if CAP account-notify is enabled */
char *isupport; /* copy of message 005 (ISUPPORT) */
char *prefix_modes; /* prefix modes from msg 005 (eg "ohv") */
char *prefix_chars; /* prefix chars from msg 005 (eg "@%+") */
+4 -2
View File
@@ -362,6 +362,7 @@ irc_upgrade_read_cb (void *data,
if (str)
irc_upgrade_current_server->nick_modes = strdup (str);
irc_upgrade_current_server->cap_away_notify = weechat_infolist_integer (infolist, "cap_away_notify");
irc_upgrade_current_server->cap_account_notify = weechat_infolist_integer (infolist, "cap_account_notify");
str = weechat_infolist_string (infolist, "isupport");
if (str)
irc_upgrade_current_server->isupport = strdup (str);
@@ -477,7 +478,7 @@ irc_upgrade_read_cb (void *data,
weechat_string_free_split (items);
}
}
irc_upgrade_current_channel->checking_away = weechat_infolist_integer (infolist, "checking_away");
irc_upgrade_current_channel->checking_whox = weechat_infolist_integer (infolist, "checking_whox");
str = weechat_infolist_string (infolist, "away_message");
if (str)
irc_upgrade_current_channel->away_message = strdup (str);
@@ -561,7 +562,8 @@ irc_upgrade_read_cb (void *data,
weechat_infolist_string (infolist, "name"),
weechat_infolist_string (infolist, "host"),
weechat_infolist_string (infolist, "prefixes"),
weechat_infolist_integer (infolist, "away"));
weechat_infolist_integer (infolist, "away"),
weechat_infolist_string (infolist, "account"));
if (ptr_nick)
{
/*