Add MONITOR support

This commit is contained in:
TingPing 2013-04-03 18:51:54 -04:00
parent 86cf7de430
commit 496ed18e85
6 changed files with 38 additions and 10 deletions

View File

@ -587,6 +587,7 @@ typedef struct server
unsigned int reconnect_away:1; /* whether to reconnect in is_away state */ unsigned int reconnect_away:1; /* whether to reconnect in is_away state */
unsigned int dont_use_proxy:1; /* to proxy or not to proxy */ unsigned int dont_use_proxy:1; /* to proxy or not to proxy */
unsigned int supports_watch:1; /* supports the WATCH command */ unsigned int supports_watch:1; /* supports the WATCH command */
unsigned int supports_monitor:1; /* supports the MONITOR command */
unsigned int bad_prefix:1; /* gave us a bad PREFIX= 005 number */ unsigned int bad_prefix:1; /* gave us a bad PREFIX= 005 number */
unsigned int have_namesx:1; /* 005 tokens NAMESX and UHNAMES */ unsigned int have_namesx:1; /* 005 tokens NAMESX and UHNAMES */
unsigned int have_awaynotify:1; unsigned int have_awaynotify:1;

View File

@ -1391,7 +1391,7 @@ inbound_login_end (session *sess, char *text)
check_autojoin_channels, serv); check_autojoin_channels, serv);
else else
check_autojoin_channels (serv); check_autojoin_channels (serv);
if (serv->supports_watch) if (serv->supports_watch || serv->supports_monitor)
notify_send_watches (serv); notify_send_watches (serv);
serv->end_of_motd = TRUE; serv->end_of_motd = TRUE;
} }

View File

@ -776,6 +776,9 @@ inbound_005 (server * serv, char *word[])
} else if (strncmp (word[w], "WATCH=", 6) == 0) } else if (strncmp (word[w], "WATCH=", 6) == 0)
{ {
serv->supports_watch = TRUE; serv->supports_watch = TRUE;
} else if (strncmp (word[w], "MONITOR=", 8) == 0)
{
serv->supports_monitor = TRUE;
} else if (strncmp (word[w], "NETWORK=", 8) == 0) } else if (strncmp (word[w], "NETWORK=", 8) == 0)
{ {
/* if (serv->networkname) /* if (serv->networkname)

View File

@ -283,10 +283,18 @@ static void
notify_watch (server * serv, char *nick, int add) notify_watch (server * serv, char *nick, int add)
{ {
char tbuf[256]; char tbuf[256];
char addchar = '+';
snprintf (tbuf, sizeof (tbuf), "WATCH +%s", nick);
if (!add) if (!add)
tbuf[6] = '-'; addchar = '-';
if (serv->supports_monitor)
snprintf (tbuf, sizeof (tbuf), "MONITOR %c %s", addchar, nick);
else if (serv->supports_watch)
snprintf (tbuf, sizeof (tbuf), "WATCH %c%s", addchar, nick);
else
return;
serv->p_raw (serv, tbuf); serv->p_raw (serv, tbuf);
} }
@ -298,8 +306,7 @@ notify_watch_all (struct notify *notify, int add)
while (list) while (list)
{ {
serv = list->data; serv = list->data;
if (serv->connected && serv->end_of_motd && serv->supports_watch && if (serv->connected && serv->end_of_motd && notify_do_network (notify, serv))
notify_do_network (notify, serv))
notify_watch (serv, notify->name, add); notify_watch (serv, notify->name, add);
list = list->next; list = list->next;
} }
@ -312,13 +319,13 @@ notify_flush_watches (server * serv, GSList *from, GSList *end)
GSList *list; GSList *list;
struct notify *notify; struct notify *notify;
strcpy (tbuf, "WATCH"); serv->supports_monitor ? strcpy (tbuf, "MONITOR + ") : strcpy (tbuf, "WATCH");
list = from; list = from;
while (list != end) while (list != end)
{ {
notify = list->data; notify = list->data;
strcat (tbuf, " +"); serv->supports_monitor ? strcat (tbuf, ",") : strcat (tbuf, " +");
strcat (tbuf, notify->name); strcat (tbuf, notify->name);
list = list->next; list = list->next;
} }
@ -343,11 +350,11 @@ notify_send_watches (server * serv)
if (notify_do_network (notify, serv)) if (notify_do_network (notify, serv))
{ {
len += strlen (notify->name) + 2 /* + and space */; len += strlen (notify->name) + serv->supports_monitor ? 1 : 2; /* just , for monitor or + and space for watch */;
if (len > 500) if (len > 500)
{ {
notify_flush_watches (serv, point, list); notify_flush_watches (serv, point, list);
len = strlen (notify->name) + 2; len = strlen (notify->name) + serv->supports_monitor ? 1 : 2;
point = list; point = list;
} }
} }
@ -450,7 +457,7 @@ notify_checklist (void) /* check ISON list */
while (list) while (list)
{ {
serv = list->data; serv = list->data;
if (serv->connected && serv->end_of_motd && !serv->supports_watch) if (serv->connected && serv->end_of_motd && !serv->supports_watch && !serv->supports_monitor)
{ {
notify_checklist_for_server (serv); notify_checklist_for_server (serv);
} }

View File

@ -466,6 +466,8 @@ process_numeric (session * sess, int n,
if (prefs.hex_irc_whois_front) if (prefs.hex_irc_whois_front)
whois_sess = serv->front_session; whois_sess = serv->front_session;
char *ex;
switch (n) switch (n)
{ {
case 1: case 1:
@ -898,6 +900,20 @@ process_numeric (session * sess, int n,
goto def; goto def;
break; break;
case 730: /* RPL_MONONLINE */
ex = strchr (word[4], '!'); /* only send the nick */
if (ex)
ex[0] = 0;
notify_set_online (serv, word[4] + 1);
break;
case 731: /* RPL_MONOFFLINE */
ex = strchr (word[4], '!'); /* only send the nick */
if (ex)
ex[0] = 0;
notify_set_offline (serv, word[4] + 1, FALSE);
break;
case 903: /* successful SASL auth */ case 903: /* successful SASL auth */
case 904: /* aborted SASL auth */ case 904: /* aborted SASL auth */
case 905: /* failed SASL auth */ case 905: /* failed SASL auth */

View File

@ -1881,6 +1881,7 @@ server_set_defaults (server *serv)
serv->end_of_motd = FALSE; serv->end_of_motd = FALSE;
serv->is_away = FALSE; serv->is_away = FALSE;
serv->supports_watch = FALSE; serv->supports_watch = FALSE;
serv->supports_monitor = FALSE;
serv->bad_prefix = FALSE; serv->bad_prefix = FALSE;
serv->use_who = TRUE; serv->use_who = TRUE;
serv->have_namesx = FALSE; serv->have_namesx = FALSE;