From 9206712a4455da4ae692005f4e3181fd36ba6f42 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 11 Jan 2013 12:59:24 +0000 Subject: - Add support for "away-notify" client capability git-svn-id: svn://svn.ircd-hybrid.org/svnroot/ircd-hybrid/trunk@1734 82007160-df01-0410-b94d-b575c5fd34c7 --- include/client.h | 1 + include/send.h | 4 ++-- modules/core/m_join.c | 16 ++++++++++++++++ modules/core/m_nick.c | 4 ++-- modules/core/m_sjoin.c | 5 +++++ modules/m_away.c | 29 ++++++++++++++++++++++++++--- modules/m_cap.c | 3 ++- modules/m_svsnick.c | 2 +- src/client.c | 2 +- src/send.c | 13 ++++++++++--- 10 files changed, 66 insertions(+), 13 deletions(-) diff --git a/include/client.h b/include/client.h index c8555a5..9fee4fd 100644 --- a/include/client.h +++ b/include/client.h @@ -265,6 +265,7 @@ struct Client #define CAP_MULTI_PREFIX 0x00000001 +#define CAP_AWAY_NOTIFY 0x00000002 #define HasCap(x, y) ((x)->localClient->cap_active & (y)) diff --git a/include/send.h b/include/send.h index 10eff63..e885e77 100644 --- a/include/send.h +++ b/include/send.h @@ -47,11 +47,11 @@ extern void sendto_one(struct Client *, const char *, ...); extern void sendto_channel_butone(struct Client *, struct Client *, struct Channel *, unsigned int, const char *, ...); -extern void sendto_common_channels_local(struct Client *, int, +extern void sendto_common_channels_local(struct Client *, int, unsigned int, const char *, ...); extern void sendto_channel_local(int, int, struct Channel *, const char *, ...); -extern void sendto_channel_local_butone(struct Client *, int, struct Channel *, +extern void sendto_channel_local_butone(struct Client *, int, unsigned int, struct Channel *, const char *, ...); extern void sendto_channel_remote(struct Client *, struct Client *, int, const unsigned int, const unsigned int, diff --git a/modules/core/m_join.c b/modules/core/m_join.c index badef89..569663b 100644 --- a/modules/core/m_join.c +++ b/modules/core/m_join.c @@ -233,6 +233,11 @@ m_join(struct Client *client_p, struct Client *source_p, source_p->host, chptr->chname); sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt", me.name, chptr->chname); + if (source_p->away[0]) + sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, + ":%s!%s@%s AWAY :%s", + source_p->name, source_p->username, + source_p->host, source_p->away); } else { @@ -248,6 +253,12 @@ m_join(struct Client *client_p, struct Client *source_p, sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", source_p->name, source_p->username, source_p->host, chptr->chname); + + if (source_p->away[0]) + sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, + ":%s!%s@%s AWAY :%s", + source_p->name, source_p->username, + source_p->host, source_p->away); } del_invite(chptr, source_p); @@ -415,6 +426,11 @@ ms_join(struct Client *client_p, struct Client *source_p, sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", source_p->name, source_p->username, source_p->host, chptr->chname); + if (source_p->away[0]) + sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr, + ":%s!%s@%s AWAY :%s", + source_p->name, source_p->username, + source_p->host, source_p->away); } sendto_server(client_p, CAP_TS6, NOCAPS, diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index 2f10317..1250d2c 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -148,7 +148,7 @@ change_local_nick(struct Client *source_p, const char *nick) sendto_realops_flags(UMODE_NCHANGE, L_ALL, SEND_NOTICE, "Nick change: From %s to %s [%s@%s]", source_p->name, nick, source_p->username, source_p->host); - sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s", + sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s", source_p->name, source_p->username, source_p->host, nick); add_history(source_p, 1); @@ -728,7 +728,7 @@ nick_from_server(struct Client *client_p, struct Client *source_p, int parc, source_p->tsinfo = newts ? newts : CurrentTime; } - sendto_common_channels_local(source_p, 1, ":%s!%s@%s NICK :%s", + sendto_common_channels_local(source_p, 1, 0, ":%s!%s@%s NICK :%s", source_p->name,source_p->username, source_p->host, nick); diff --git a/modules/core/m_sjoin.c b/modules/core/m_sjoin.c index a072183..c817c99 100644 --- a/modules/core/m_sjoin.c +++ b/modules/core/m_sjoin.c @@ -423,6 +423,11 @@ ms_sjoin(struct Client *client_p, struct Client *source_p, sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s", target_p->name, target_p->username, target_p->host, chptr->chname); + if (target_p->away[0]) + sendto_channel_local_butone(target_p, 0, CAP_AWAY_NOTIFY, chptr, + ":%s!%s@%s AWAY :%s", + target_p->name, target_p->username, + target_p->host, target_p->away); } if (fl & CHFL_CHANOP) diff --git a/modules/m_away.c b/modules/m_away.c index 700494f..926ff21 100644 --- a/modules/m_away.c +++ b/modules/m_away.c @@ -53,12 +53,16 @@ m_away(struct Client *client_p, struct Client *source_p, /* Marking as not away */ if (source_p->away[0]) { + source_p->away[0] = '\0'; /* we now send this only if they were away before --is */ sendto_server(client_p, CAP_TS6, NOCAPS, ":%s AWAY", ID(source_p)); sendto_server(client_p, NOCAPS, CAP_TS6, ":%s AWAY", source_p->name); - source_p->away[0] = '\0'; + sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, + ":%s!%s@%s AWAY", + source_p->name, source_p->username, + source_p->host); } sendto_one(source_p, form_str(RPL_UNAWAY), @@ -74,13 +78,21 @@ m_away(struct Client *client_p, struct Client *source_p, } source_p->localClient->last_away = CurrentTime; + sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); + + if (strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) + return; + strlcpy(source_p->away, parv[1], sizeof(source_p->away)); + sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, + ":%s!%s@%s AWAY :%s", + source_p->name, source_p->username, + source_p->host, source_p->away); sendto_server(client_p, CAP_TS6, NOCAPS, ":%s AWAY :%s", ID(source_p), source_p->away); sendto_server(client_p, NOCAPS, CAP_TS6, ":%s AWAY :%s", source_p->name, source_p->away); - sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); } static void @@ -95,19 +107,30 @@ ms_away(struct Client *client_p, struct Client *source_p, /* Marking as not away */ if (source_p->away[0]) { + source_p->away[0] = '\0'; /* we now send this only if they were away before --is */ sendto_server(client_p, CAP_TS6, NOCAPS, ":%s AWAY", ID(source_p)); sendto_server(client_p, NOCAPS, CAP_TS6, ":%s AWAY", source_p->name); - source_p->away[0] = '\0'; + sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, + ":%s!%s@%s AWAY", + source_p->name, source_p->username, + source_p->host); } return; } + if (strncmp(source_p->away, parv[1], sizeof(source_p->away) - 1)) + return; + strlcpy(source_p->away, parv[1], sizeof(source_p->away)); + sendto_common_channels_local(source_p, 1, CAP_AWAY_NOTIFY, + ":%s!%s@%s AWAY :%s", + source_p->name, source_p->username, + source_p->host, source_p->away); sendto_server(client_p, CAP_TS6, NOCAPS, ":%s AWAY :%s", ID(source_p), source_p->away); sendto_server(client_p, NOCAPS, CAP_TS6, diff --git a/modules/m_cap.c b/modules/m_cap.c index 0633da3..842c1c9 100644 --- a/modules/m_cap.c +++ b/modules/m_cap.c @@ -58,7 +58,8 @@ static struct capabilities } capab_list[] = { #define _CAP(cap, flags, name) \ { (cap), (flags), (name), sizeof(name) - 1 } - _CAP(CAP_MULTI_PREFIX, 0, "multi-prefix") + _CAP(CAP_MULTI_PREFIX, 0, "multi-prefix"), + _CAP(CAP_AWAY_NOTIFY, 0, "away-notify") #undef _CAP }; diff --git a/modules/m_svsnick.c b/modules/m_svsnick.c index ff638d7..4847cbd 100644 --- a/modules/m_svsnick.c +++ b/modules/m_svsnick.c @@ -98,7 +98,7 @@ ms_svsnick(struct Client *client_p, struct Client *source_p, send_umode(target_p, target_p, oldmodes, 0xffffffff, modebuf); } - sendto_common_channels_local(target_p, 1, ":%s!%s@%s NICK :%s", + sendto_common_channels_local(target_p, 1, 0, ":%s!%s@%s NICK :%s", target_p->name, target_p->username, target_p->host, parv[2]); diff --git a/src/client.c b/src/client.c index 721f03d..e7bb6e6 100644 --- a/src/client.c +++ b/src/client.c @@ -658,7 +658,7 @@ exit_one_client(struct Client *source_p, const char *quitmsg) * that the client can show the "**signoff" message). * (Note: The notice is to the local clients *only*) */ - sendto_common_channels_local(source_p, 0, ":%s!%s@%s QUIT :%s", + sendto_common_channels_local(source_p, 0, 0, ":%s!%s@%s QUIT :%s", source_p->name, source_p->username, source_p->host, quitmsg); DLINK_FOREACH_SAFE(lp, next_lp, source_p->channel.head) diff --git a/src/send.c b/src/send.c index 7a3a8cb..1069f99 100644 --- a/src/send.c +++ b/src/send.c @@ -506,7 +506,7 @@ sendto_server(struct Client *one, * used by m_nick.c and exit_one_client. */ void -sendto_common_channels_local(struct Client *user, int touser, +sendto_common_channels_local(struct Client *user, int touser, unsigned int cap, const char *pattern, ...) { va_list args; @@ -539,6 +539,9 @@ sendto_common_channels_local(struct Client *user, int touser, target_p->localClient->serial == current_serial) continue; + if (HasCap(target_p, cap) != cap) + continue; + target_p->localClient->serial = current_serial; send_message(target_p, buffer, len); } @@ -546,7 +549,8 @@ sendto_common_channels_local(struct Client *user, int touser, if (touser && MyConnect(user) && !IsDead(user) && user->localClient->serial != current_serial) - send_message(user, buffer, len); + if (HasCap(target_p, cap) == cap) + send_message(user, buffer, len); } /* sendto_channel_local() @@ -603,7 +607,7 @@ sendto_channel_local(int type, int nodeaf, struct Channel *chptr, * WARNING - +D clients are omitted */ void -sendto_channel_local_butone(struct Client *one, int type, +sendto_channel_local_butone(struct Client *one, int type, unsigned int cap, struct Channel *chptr, const char *pattern, ...) { va_list args; @@ -628,6 +632,9 @@ sendto_channel_local_butone(struct Client *one, int type, if (!MyConnect(target_p) || target_p == one || IsDefunct(target_p) || HasUMode(target_p, UMODE_DEAF)) continue; + + if (HasCap(target_p, cap) != cap) + continue; send_message(target_p, buffer, len); } } -- cgit