ircd: import hidden channel modes framework, from ircd-seven

This allows for modules to define channel modes which are only visible to opers.
This commit is contained in:
William Pitcock 2016-01-13 16:34:27 -06:00
parent 88c48be58c
commit be29ec793d
5 changed files with 69 additions and 2 deletions

View file

@ -147,6 +147,7 @@ typedef int (*ExtbanFunc)(const char *data, struct Client *client_p,
#define CHFL_BANNED 0x0008 /* cached as banned */ #define CHFL_BANNED 0x0008 /* cached as banned */
#define CHFL_QUIETED 0x0010 /* cached as being +q victim */ #define CHFL_QUIETED 0x0010 /* cached as being +q victim */
#define ONLY_SERVERS 0x0020 #define ONLY_SERVERS 0x0020
#define ONLY_OPERS 0x0040
#define ALL_MEMBERS CHFL_PEON #define ALL_MEMBERS CHFL_PEON
#define ONLY_CHANOPS CHFL_CHANOP #define ONLY_CHANOPS CHFL_CHANOP
#define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE) #define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE)

View file

@ -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, extern void chm_ban(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type); 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, extern void chm_staff(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
const char **parv, int *errors, int dir, char c, long mode_type); const char **parv, int *errors, int dir, char c, long mode_type);

View file

@ -1190,8 +1190,12 @@ channel_modes(struct Channel *chptr, struct Client *client_p)
*pbuf = '\0'; *pbuf = '\0';
for (i = 0; i < 256; i++) 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]) if(chptr->mode.mode & chmode_flags[i])
*mbuf++ = i; *mbuf++ = i;
}
if(chptr->mode.limit) if(chptr->mode.limit)
{ {

View file

@ -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 void
chm_staff(struct Client *source_p, struct Channel *chptr, chm_staff(struct Client *source_p, struct Channel *chptr,
int alevel, int parc, int *parn, int alevel, int parc, int *parn,
@ -1644,6 +1697,7 @@ set_channel_mode(struct Client *client_p, struct Client *source_p,
char c; char c;
struct Client *fakesource_p; 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 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; mask_pos = 0;
removed_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->name, source_p->username,
source_p->host, chptr->chname); 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; cur_len = mlen;
mbuf = modebuf + mlen; mbuf = modebuf + mlen;

View file

@ -646,7 +646,12 @@ sendto_channel_local(int type, struct Channel *chptr, const char *pattern, ...)
if(IsIOError(target_p)) if(IsIOError(target_p))
continue; continue;
if(type && ((msptr->flags & type) == 0)) if(type == ONLY_OPERS)
{
if (!IsOper(target_p))
continue;
}
else if(type && ((msptr->flags & type) == 0))
continue; continue;
_send_linebuf(target_p, &linebuf); _send_linebuf(target_p, &linebuf);