Skip to content

Commit

Permalink
Add account-notify support
Browse files Browse the repository at this point in the history
  • Loading branch information
TingPing committed Mar 14, 2013
1 parent d1e2048 commit 4e88e9c
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/common/hexchat.h
Expand Up @@ -573,6 +573,7 @@ typedef struct server
unsigned int have_whox:1; /* have undernet's WHOX features */ unsigned int have_whox:1; /* have undernet's WHOX features */
unsigned int have_capab:1; /* supports CAPAB (005 tells us) */ unsigned int have_capab:1; /* supports CAPAB (005 tells us) */
unsigned int have_idmsg:1; /* freenode's IDENTIFY-MSG */ unsigned int have_idmsg:1; /* freenode's IDENTIFY-MSG */
unsigned int have_accountnotify:1;
unsigned int have_sasl:1; /* SASL capability */ unsigned int have_sasl:1; /* SASL capability */
unsigned int have_except:1; /* ban exemptions +e */ unsigned int have_except:1; /* ban exemptions +e */
unsigned int using_cp1255:1; /* encoding is CP1255/WINDOWS-1255? */ unsigned int using_cp1255:1; /* encoding is CP1255/WINDOWS-1255? */
Expand Down
36 changes: 32 additions & 4 deletions src/common/inbound.c
Expand Up @@ -137,7 +137,7 @@ static void
inbound_make_idtext (server *serv, char *idtext, int max, int id) inbound_make_idtext (server *serv, char *idtext, int max, int id)
{ {
idtext[0] = 0; idtext[0] = 0;
if (serv->have_idmsg) if (serv->have_idmsg || serv->have_accountnotify)
{ {
if (id) if (id)
{ {
Expand All @@ -156,6 +156,7 @@ inbound_privmsg (server *serv, char *from, char *ip, char *text, int id)
{ {
session *sess; session *sess;
char idtext[64]; char idtext[64];
struct User *user;


sess = find_dialog (serv, from); sess = find_dialog (serv, from);


Expand Down Expand Up @@ -188,6 +189,10 @@ inbound_privmsg (server *serv, char *from, char *ip, char *text, int id)
return; return;
} }


user = userlist_find (sess, from);
if (user && user->account)
id = TRUE;

inbound_make_idtext (serv, idtext, sizeof (idtext), id); inbound_make_idtext (serv, idtext, sizeof (idtext), id);


sess = find_session_from_nick (from, serv); sess = find_session_from_nick (from, serv);
Expand Down Expand Up @@ -373,6 +378,8 @@ inbound_action (session *sess, char *chan, char *from, char *ip, char *text, int
user = userlist_find (sess, from); user = userlist_find (sess, from);
if (user) if (user)
{ {
if (user->account)
id = TRUE;
nickchar[0] = user->prefix[0]; nickchar[0] = user->prefix[0];
user->lasttalk = time (0); user->lasttalk = time (0);
} }
Expand Down Expand Up @@ -431,6 +438,8 @@ inbound_chanmsg (server *serv, session *sess, char *chan, char *from, char *text
user = userlist_find (sess, from); user = userlist_find (sess, from);
if (user) if (user)
{ {
if (user->account)
id = TRUE;
nickchar[0] = user->prefix[0]; nickchar[0] = user->prefix[0];
user->lasttalk = time (0); user->lasttalk = time (0);
} }
Expand Down Expand Up @@ -778,6 +787,22 @@ inbound_quit (server *serv, char *nick, char *ip, char *reason)
notify_set_offline (serv, nick, was_on_front_session); notify_set_offline (serv, nick, was_on_front_session);
} }


void
inbound_account (server *serv, char *nick, char *account)
{
session *sess = NULL;
GSList *list;

list = sess_list;
while (list)
{
sess = list->data;
if (sess->server == serv)
userlist_set_account (sess, nick, account);
list = list->next;
}
}

void void
inbound_ping_reply (session *sess, char *timestring, char *from) inbound_ping_reply (session *sess, char *timestring, char *from)
{ {
Expand Down Expand Up @@ -1227,7 +1252,7 @@ inbound_user_info_start (session *sess, char *nick)
void void
inbound_user_info (session *sess, char *chan, char *user, char *host, inbound_user_info (session *sess, char *chan, char *user, char *host,
char *servname, char *nick, char *realname, char *servname, char *nick, char *realname,
unsigned int away) char *account, unsigned int away)
{ {
server *serv = sess->server; server *serv = sess->server;
session *who_sess; session *who_sess;
Expand All @@ -1240,11 +1265,14 @@ inbound_user_info (session *sess, char *chan, char *user, char *host,
sprintf (uhost, "%s@%s", user, host); sprintf (uhost, "%s@%s", user, host);
} }


if (strcmp (account, "*") == 0 || strcmp (account, ":0") == 0)
account = NULL;

if (chan) if (chan)
{ {
who_sess = find_channel (serv, chan); who_sess = find_channel (serv, chan);
if (who_sess) if (who_sess)
userlist_add_hostname (who_sess, nick, uhost, realname, servname, away); userlist_add_hostname (who_sess, nick, uhost, realname, servname, account, away);
else else
{ {
if (serv->doing_dns && nick && host) if (serv->doing_dns && nick && host)
Expand All @@ -1259,7 +1287,7 @@ inbound_user_info (session *sess, char *chan, char *user, char *host,
sess = list->data; sess = list->data;
if (sess->type == SESS_CHANNEL && sess->server == serv) if (sess->type == SESS_CHANNEL && sess->server == serv)
{ {
userlist_add_hostname (sess, nick, uhost, realname, servname, away); userlist_add_hostname (sess, nick, uhost, realname, servname, account, away);
} }
} }
} }
Expand Down
3 changes: 2 additions & 1 deletion src/common/inbound.h
Expand Up @@ -4,6 +4,7 @@
void inbound_next_nick (session *sess, char *nick); void inbound_next_nick (session *sess, char *nick);
void inbound_uback (server *serv); void inbound_uback (server *serv);
void inbound_uaway (server *serv); void inbound_uaway (server *serv);
void inbound_account (server *serv, char *nick, char *account);
void inbound_part (server *serv, char *chan, char *user, char *ip, char *reason); void inbound_part (server *serv, char *chan, char *user, char *ip, char *reason);
void inbound_upart (server *serv, char *chan, char *ip, char *reason); void inbound_upart (server *serv, char *chan, char *ip, char *reason);
void inbound_ukick (server *serv, char *chan, char *kicker, char *reason); void inbound_ukick (server *serv, char *chan, char *kicker, char *reason);
Expand All @@ -16,7 +17,7 @@ void inbound_ujoin (server *serv, char *chan, char *nick, char *ip);
void inbound_topictime (server *serv, char *chan, char *nick, time_t stamp); void inbound_topictime (server *serv, char *chan, char *nick, time_t stamp);
void inbound_topic (server *serv, char *chan, char *topic_text); void inbound_topic (server *serv, char *chan, char *topic_text);
void inbound_user_info_start (session *sess, char *nick); void inbound_user_info_start (session *sess, char *nick);
void inbound_user_info (session *sess, char *chan, char *user, char *host, char *servname, char *nick, char *realname, unsigned int away); void inbound_user_info (session *sess, char *chan, char *user, char *host, char *servname, char *nick, char *realname, char *account, unsigned int away);
void inbound_foundip (session *sess, char *ip); void inbound_foundip (session *sess, char *ip);
int inbound_banlist (session *sess, time_t stamp, char *chan, char *mask, char *banner, int is_exemption); int inbound_banlist (session *sess, time_t stamp, char *chan, char *mask, char *banner, int is_exemption);
void inbound_ping_reply (session *sess, char *timestring, char *from); void inbound_ping_reply (session *sess, char *timestring, char *from);
Expand Down
31 changes: 24 additions & 7 deletions src/common/proto-irc.c
Expand Up @@ -328,7 +328,7 @@ static void
irc_away_status (server *serv, char *channel) irc_away_status (server *serv, char *channel)
{ {
if (serv->have_whox) if (serv->have_whox)
tcp_sendf (serv, "WHO %s %%ctnf,152\r\n", channel); tcp_sendf (serv, "WHO %s %%chtsunfra,152\r\n", channel);
else else
tcp_sendf (serv, "WHO %s\r\n", channel); tcp_sendf (serv, "WHO %s\r\n", channel);
} }
Expand Down Expand Up @@ -568,7 +568,7 @@ process_numeric (session * sess, int n,
if (!serv->skip_next_whois) if (!serv->skip_next_whois)
EMIT_SIGNAL (XP_TE_WHOIS3, whois_sess, word[4], word_eol[5], NULL, NULL, 0); EMIT_SIGNAL (XP_TE_WHOIS3, whois_sess, word[4], word_eol[5], NULL, NULL, 0);
else else
inbound_user_info (sess, NULL, NULL, NULL, word[5], word[4], NULL, 0xff); inbound_user_info (sess, NULL, NULL, NULL, word[5], word[4], NULL, NULL, 0xff);
break; break;


case 311: /* WHOIS 1st line */ case 311: /* WHOIS 1st line */
Expand All @@ -579,7 +579,7 @@ process_numeric (session * sess, int n,
word[6], word_eol[8] + 1, 0); word[6], word_eol[8] + 1, 0);
else else
inbound_user_info (sess, NULL, word[5], word[6], NULL, word[4], inbound_user_info (sess, NULL, word[5], word[6], NULL, word[4],
word_eol[8][0] == ':' ? word_eol[8] + 1 : word_eol[8], 0xff); word_eol[8][0] == ':' ? word_eol[8] + 1 : word_eol[8], NULL, 0xff);
break; break;


case 314: /* WHOWAS */ case 314: /* WHOWAS */
Expand Down Expand Up @@ -724,7 +724,7 @@ process_numeric (session * sess, int n,
away = 1; away = 1;


inbound_user_info (sess, word[4], word[5], word[6], word[7], inbound_user_info (sess, word[4], word[5], word[6], word[7],
word[8], word_eol[11], away); word[8], word_eol[11], word[10], away);


/* try to show only user initiated whos */ /* try to show only user initiated whos */
if (!who_sess || !who_sess->doing_who) if (!who_sess || !who_sess->doing_who)
Expand All @@ -743,11 +743,12 @@ process_numeric (session * sess, int n,
{ {
who_sess = find_channel (serv, word[5]); who_sess = find_channel (serv, word[5]);


if (*word[7] == 'G') if (*word[10] == 'G')
away = 1; away = 1;


/* :SanJose.CA.us.undernet.org 354 z1 152 #zed1 z1 H@ */ /* :server 354 yournick 152 #channel ~ident host servname nick H account :realname */
inbound_user_info (sess, word[5], 0, 0, 0, word[6], 0, away); inbound_user_info (sess, word[5], word[6], word[7], word[8],
word[9], word_eol[12], word[11], away);


/* try to show only user initiated whos */ /* try to show only user initiated whos */
if (!who_sess || !who_sess->doing_who) if (!who_sess || !who_sess->doing_who)
Expand Down Expand Up @@ -1029,6 +1030,11 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
/* this should compile to a bunch of: CMP.L, JE ... nice & fast */ /* this should compile to a bunch of: CMP.L, JE ... nice & fast */
switch (t) switch (t)
{ {

case WORDL('A','C','C','O'):
inbound_account (serv, nick, word[3]);
return;

case WORDL('I','N','V','I'): case WORDL('I','N','V','I'):
if (ignore_check (word[1], IG_INVI)) if (ignore_check (word[1], IG_INVI))
return; return;
Expand Down Expand Up @@ -1153,6 +1159,11 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
serv->have_namesx = TRUE; serv->have_namesx = TRUE;
} }


if (strstr (word_eol[5], "account-notify") != 0)
{
serv->have_accountnotify = TRUE;
}

if (strstr (word_eol[5], "sasl") != 0) if (strstr (word_eol[5], "sasl") != 0)
{ {
serv->have_sasl = TRUE; serv->have_sasl = TRUE;
Expand Down Expand Up @@ -1180,6 +1191,12 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[])
want_cap ? strcat (buffer, " multi-prefix") : strcpy (buffer, "CAP REQ :multi-prefix"); want_cap ? strcat (buffer, " multi-prefix") : strcpy (buffer, "CAP REQ :multi-prefix");
want_cap = 1; want_cap = 1;
} }

if (strstr (word_eol[5], "account-notify") != 0)
{
want_cap ? strcat (buffer, " account-notify") : strcpy (buffer, "CAP REQ :account-notify");
want_cap = 1;
}
/* if the SASL password is set, request SASL auth */ /* if the SASL password is set, request SASL auth */
if (strstr (word_eol[5], "sasl") != 0 && strlen (sess->server->saslpassword) != 0) if (strstr (word_eol[5], "sasl") != 0 && strlen (sess->server->saslpassword) != 0)
{ {
Expand Down
1 change: 1 addition & 0 deletions src/common/server.c
Expand Up @@ -1912,6 +1912,7 @@ server_set_defaults (server *serv)
serv->have_whox = FALSE; serv->have_whox = FALSE;
serv->have_capab = FALSE; serv->have_capab = FALSE;
serv->have_idmsg = FALSE; serv->have_idmsg = FALSE;
serv->have_accountnotify = FALSE;
serv->have_sasl = FALSE; serv->have_sasl = FALSE;
serv->have_except = FALSE; serv->have_except = FALSE;
} }
Expand Down
22 changes: 21 additions & 1 deletion src/common/userlist.c
Expand Up @@ -113,9 +113,27 @@ userlist_set_away (struct session *sess, char *nick, unsigned int away)
} }
} }


void
userlist_set_account (struct session *sess, char *nick, char *account)
{
struct User *user;

user = userlist_find (sess, nick);
if (user)
{
if (strcmp (account, "*") == 0)
user->account = NULL;
else if (user->account != account)
user->account = strdup (account);

/* gui doesnt currently reflect login status, maybe later
fe_userlist_rehash (sess, user); */
}
}

int int
userlist_add_hostname (struct session *sess, char *nick, char *hostname, userlist_add_hostname (struct session *sess, char *nick, char *hostname,
char *realname, char *servername, unsigned int away) char *realname, char *servername, char *account, unsigned int away)
{ {
struct User *user; struct User *user;


Expand All @@ -128,6 +146,8 @@ userlist_add_hostname (struct session *sess, char *nick, char *hostname,
user->realname = strdup (realname); user->realname = strdup (realname);
if (!user->servername && servername) if (!user->servername && servername)
user->servername = strdup (servername); user->servername = strdup (servername);
if (!user->account && account)
user->account = strdup (account);


if (away != 0xff) if (away != 0xff)
{ {
Expand Down
4 changes: 3 additions & 1 deletion src/common/userlist.h
Expand Up @@ -9,6 +9,7 @@ struct User
char *hostname; char *hostname;
char *realname; char *realname;
char *servername; char *servername;
char *account;
time_t lasttalk; time_t lasttalk;
unsigned int access; /* axs bit field */ unsigned int access; /* axs bit field */
char prefix[2]; /* @ + % */ char prefix[2]; /* @ + % */
Expand All @@ -24,8 +25,9 @@ struct User


int userlist_add_hostname (session *sess, char *nick, int userlist_add_hostname (session *sess, char *nick,
char *hostname, char *realname, char *hostname, char *realname,
char *servername, unsigned int away); char *servername, char *account, unsigned int away);
void userlist_set_away (session *sess, char *nick, unsigned int away); void userlist_set_away (session *sess, char *nick, unsigned int away);
void userlist_set_account (session *sess, char *nick, char *account);
struct User *userlist_find (session *sess, const char *name); struct User *userlist_find (session *sess, const char *name);
struct User *userlist_find_global (server *serv, char *name); struct User *userlist_find_global (server *serv, char *name);
void userlist_clear (session *sess); void userlist_clear (session *sess);
Expand Down
7 changes: 7 additions & 0 deletions src/fe-gtk/menu.c
Expand Up @@ -636,6 +636,13 @@ menu_create_nickinfo_menu (struct User *user, GtkWidget *submenu)
g_signal_connect (G_OBJECT (item), "activate", g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (copy_to_clipboard_cb), G_CALLBACK (copy_to_clipboard_cb),
user->hostname ? user->hostname : unknown); user->hostname ? user->hostname : unknown);

snprintf (buf, sizeof (buf), fmt, _("Account:"),
user->account ? user->account : unknown);
item = menu_quick_item (0, buf, submenu, XCMENU_MARKUP, 0, 0);
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (copy_to_clipboard_cb),
user->account ? user->account : unknown);


snprintf (buf, sizeof (buf), fmt, _("Country:"), snprintf (buf, sizeof (buf), fmt, _("Country:"),
user->hostname ? country(user->hostname) : unknown); user->hostname ? country(user->hostname) : unknown);
Expand Down

0 comments on commit 4e88e9c

Please sign in to comment.