From be29ec793d7efd234292d91231e7366b158a85ea Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 13 Jan 2016 16:34:27 -0600 Subject: [PATCH] ircd: import hidden channel modes framework, from ircd-seven This allows for modules to define channel modes which are only visible to opers. --- include/channel.h | 1 + include/chmode.h | 3 +++ ircd/channel.c | 4 ++++ ircd/chmode.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++- ircd/send.c | 7 +++++- 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/include/channel.h b/include/channel.h index 9cf00023..0999a964 100644 --- a/include/channel.h +++ b/include/channel.h @@ -147,6 +147,7 @@ typedef int (*ExtbanFunc)(const char *data, struct Client *client_p, #define CHFL_BANNED 0x0008 /* cached as banned */ #define CHFL_QUIETED 0x0010 /* cached as being +q victim */ #define ONLY_SERVERS 0x0020 +#define ONLY_OPERS 0x0040 #define ALL_MEMBERS CHFL_PEON #define ONLY_CHANOPS CHFL_CHANOP #define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE) diff --git a/include/chmode.h b/include/chmode.h index ae1345e2..ba79ca0d 100644 --- a/include/chmode.h +++ b/include/chmode.h @@ -48,6 +48,9 @@ extern void chm_simple(struct Client *source_p, struct Channel *chptr, extern void chm_ban(struct Client *source_p, struct Channel *chptr, int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, long mode_type); +extern void chm_hidden(struct Client *source_p, struct Channel *chptr, + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type); extern void chm_staff(struct Client *source_p, struct Channel *chptr, int alevel, int parc, int *parn, const char **parv, int *errors, int dir, char c, long mode_type); diff --git a/ircd/channel.c b/ircd/channel.c index 180a4507..9bc684b4 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -1190,8 +1190,12 @@ channel_modes(struct Channel *chptr, struct Client *client_p) *pbuf = '\0'; for (i = 0; i < 256; i++) + { + if(chmode_table[i].set_func == chm_hidden && (!IsOper(client_p) || !IsClient(client_p))) + continue; if(chptr->mode.mode & chmode_flags[i]) *mbuf++ = i; + } if(chptr->mode.limit) { diff --git a/ircd/chmode.c b/ircd/chmode.c index f63e74e5..dc7a3c98 100644 --- a/ircd/chmode.c +++ b/ircd/chmode.c @@ -661,6 +661,59 @@ chm_orphaned(struct Client *source_p, struct Channel *chptr, } } +void +chm_hidden(struct Client *source_p, struct Channel *chptr, + int alevel, int parc, int *parn, + const char **parv, int *errors, int dir, char c, long mode_type) +{ + if(!IsOper(source_p) && !IsServer(source_p)) + { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); + *errors |= SM_ERR_NOPRIVS; + return; + } + if(MyClient(source_p) && !IsOperAdmin(source_p)) + { + if(!(*errors & SM_ERR_NOPRIVS)) + sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, + source_p->name, "admin"); + *errors |= SM_ERR_NOPRIVS; + return; + } + + if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) + return; + + /* setting + */ + if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) + { + chptr->mode.mode |= mode_type; + + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_ADD; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].mems = ONLY_OPERS; + mode_changes[mode_count].override = 0; + mode_changes[mode_count++].arg = NULL; + } + else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) + { + chptr->mode.mode &= ~mode_type; + + mode_changes[mode_count].letter = c; + mode_changes[mode_count].dir = MODE_DEL; + mode_changes[mode_count].caps = 0; + mode_changes[mode_count].nocaps = 0; + mode_changes[mode_count].mems = ONLY_OPERS; + mode_changes[mode_count].id = NULL; + mode_changes[mode_count].override = 0; + mode_changes[mode_count++].arg = NULL; + } +} + void chm_staff(struct Client *source_p, struct Channel *chptr, int alevel, int parc, int *parn, @@ -1644,6 +1697,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p, char c; struct Client *fakesource_p; int reauthorized = 0; /* if we change from MODE_QUERY to MODE_ADD/MODE_DEL, then reauth once, ugly but it works */ + int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; mask_pos = 0; removed_mask_pos = 0; @@ -1702,7 +1756,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p, source_p->name, source_p->username, source_p->host, chptr->chname); - for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS) + for(j = 0, flags = flags_list[0]; j < 3; j++, flags = flags_list[j]) { cur_len = mlen; mbuf = modebuf + mlen; diff --git a/ircd/send.c b/ircd/send.c index a15d9d64..959938f8 100644 --- a/ircd/send.c +++ b/ircd/send.c @@ -646,7 +646,12 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...) if(IsIOError(target_p)) continue; - if(type && ((msptr->flags & type) == 0)) + if(type == ONLY_OPERS) + { + if (!IsOper(target_p)) + continue; + } + else if(type && ((msptr->flags & type) == 0)) continue; _send_linebuf(target_p, &linebuf);