2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* channel.h: The ircd channel header.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2004 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_channel_h
|
|
|
|
#define INCLUDED_channel_h
|
|
|
|
|
|
|
|
#define MODEBUFLEN 200
|
|
|
|
|
|
|
|
/* Maximum mode changes allowed per client, per server is different */
|
|
|
|
#define MAXMODEPARAMS 4
|
|
|
|
#define MAXMODEPARAMSSERV 10
|
|
|
|
|
2016-03-08 10:52:31 +00:00
|
|
|
#include <setup.h>
|
2021-04-17 18:43:59 +00:00
|
|
|
#include "hook.h"
|
2016-03-08 10:52:31 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Client;
|
|
|
|
|
|
|
|
/* mode structure for channels */
|
|
|
|
struct Mode
|
|
|
|
{
|
|
|
|
unsigned int mode;
|
|
|
|
int limit;
|
|
|
|
char key[KEYLEN];
|
|
|
|
unsigned int join_num;
|
|
|
|
unsigned int join_time;
|
|
|
|
char forward[LOC_CHANNELLEN + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* channel structure */
|
|
|
|
struct Channel
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node node;
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Mode mode;
|
2010-04-30 21:01:21 +00:00
|
|
|
char *mode_lock;
|
2007-01-25 06:40:21 +00:00
|
|
|
char *topic;
|
|
|
|
char *topic_info;
|
|
|
|
time_t topic_time;
|
|
|
|
time_t last_knock; /* don't allow knock to flood */
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_list members; /* channel members */
|
|
|
|
rb_dlink_list locmembers; /* local channel members */
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-07-06 17:35:11 +00:00
|
|
|
rb_dlink_list invites;
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_list banlist;
|
|
|
|
rb_dlink_list exceptlist;
|
|
|
|
rb_dlink_list invexlist;
|
|
|
|
rb_dlink_list quietlist;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
time_t first_received_message_time; /* channel flood control */
|
|
|
|
int received_number_of_privmsgs;
|
|
|
|
int flood_noticed;
|
|
|
|
|
|
|
|
unsigned int join_count; /* joins within delta */
|
|
|
|
unsigned int join_delta; /* last ts of join */
|
|
|
|
|
2016-03-23 02:53:56 +00:00
|
|
|
time_t bants;
|
2007-01-25 06:40:21 +00:00
|
|
|
time_t channelts;
|
|
|
|
char *chname;
|
2015-12-13 14:13:52 +00:00
|
|
|
|
|
|
|
struct Client *last_checked_client;
|
|
|
|
time_t last_checked_ts;
|
|
|
|
unsigned int last_checked_type;
|
|
|
|
int last_checked_result;
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct membership
|
|
|
|
{
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node channode;
|
|
|
|
rb_dlink_node locchannode;
|
|
|
|
rb_dlink_node usernode;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
struct Channel *chptr;
|
|
|
|
struct Client *client_p;
|
|
|
|
unsigned int flags;
|
|
|
|
|
2016-03-23 02:53:56 +00:00
|
|
|
time_t bants;
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
|
2007-11-07 23:45:14 +00:00
|
|
|
#define BANLEN 195
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Ban
|
|
|
|
{
|
|
|
|
char *banstr;
|
|
|
|
char *who;
|
|
|
|
time_t when;
|
2011-08-13 00:33:10 +00:00
|
|
|
char *forward;
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node node;
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
|
2007-12-25 00:00:20 +00:00
|
|
|
struct mode_letter
|
|
|
|
{
|
|
|
|
int mode;
|
|
|
|
char letter;
|
|
|
|
};
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
struct ChModeChange
|
|
|
|
{
|
|
|
|
char letter;
|
|
|
|
const char *arg;
|
|
|
|
const char *id;
|
|
|
|
int dir;
|
|
|
|
int mems;
|
|
|
|
};
|
|
|
|
|
2020-11-08 00:45:12 +00:00
|
|
|
typedef void ChannelModeFunc(struct Client *source_p, struct Channel *chptr,
|
2020-11-05 16:31:57 +00:00
|
|
|
int alevel, const char *arg, int *errors, int dir, char c, long mode_type);
|
|
|
|
|
|
|
|
enum chm_flags
|
|
|
|
{
|
|
|
|
CHM_CAN_QUERY = 1 << 0,
|
|
|
|
CHM_OPS_QUERY = 1 << 1,
|
|
|
|
CHM_ARG_SET = 1 << 2,
|
|
|
|
CHM_ARG_DEL = 1 << 3,
|
|
|
|
CHM_ARGS = CHM_ARG_SET | CHM_ARG_DEL,
|
|
|
|
CHM_QUERYABLE = CHM_ARGS | CHM_CAN_QUERY,
|
|
|
|
};
|
2010-03-31 23:16:16 +00:00
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
struct ChannelMode
|
|
|
|
{
|
2020-11-08 00:45:12 +00:00
|
|
|
ChannelModeFunc *set_func;
|
2007-01-25 06:40:21 +00:00
|
|
|
long mode_type;
|
2020-11-05 16:31:57 +00:00
|
|
|
enum chm_flags flags;
|
2007-01-25 06:40:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (*ExtbanFunc)(const char *data, struct Client *client_p,
|
|
|
|
struct Channel *chptr, long mode_type);
|
|
|
|
|
|
|
|
/* can_send results */
|
|
|
|
#define CAN_SEND_NO 0
|
|
|
|
#define CAN_SEND_NONOP 1
|
|
|
|
#define CAN_SEND_OPV 2
|
|
|
|
|
|
|
|
/* channel status flags */
|
|
|
|
#define CHFL_PEON 0x0000 /* normal member of channel */
|
2010-12-07 06:11:53 +00:00
|
|
|
#define CHFL_VOICE 0x0001 /* the power to speak */
|
|
|
|
#define CHFL_CHANOP 0x0002 /* Channel operator */
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
#define CHFL_BANNED 0x0008 /* cached as banned */
|
|
|
|
#define CHFL_QUIETED 0x0010 /* cached as being +q victim */
|
|
|
|
#define ONLY_SERVERS 0x0020
|
2016-01-13 22:34:27 +00:00
|
|
|
#define ONLY_OPERS 0x0040
|
2007-01-25 06:40:21 +00:00
|
|
|
#define ALL_MEMBERS CHFL_PEON
|
|
|
|
#define ONLY_CHANOPS CHFL_CHANOP
|
|
|
|
#define ONLY_CHANOPSVOICED (CHFL_CHANOP|CHFL_VOICE)
|
|
|
|
|
|
|
|
#define is_chanop(x) ((x) && (x)->flags & CHFL_CHANOP)
|
|
|
|
#define is_voiced(x) ((x) && (x)->flags & CHFL_VOICE)
|
|
|
|
#define is_chanop_voiced(x) ((x) && (x)->flags & (CHFL_CHANOP|CHFL_VOICE))
|
|
|
|
#define can_send_banned(x) ((x) && (x)->flags & (CHFL_BANNED|CHFL_QUIETED))
|
|
|
|
|
|
|
|
/* channel modes ONLY */
|
|
|
|
#define MODE_PRIVATE 0x0001
|
|
|
|
#define MODE_SECRET 0x0002
|
|
|
|
#define MODE_MODERATED 0x0004
|
|
|
|
#define MODE_TOPICLIMIT 0x0008
|
|
|
|
#define MODE_INVITEONLY 0x0010
|
|
|
|
#define MODE_NOPRIVMSGS 0x0020
|
|
|
|
#define MODE_REGONLY 0x0040
|
|
|
|
#define MODE_EXLIMIT 0x0100 /* exempt from list limits, +b/+e/+I/+q */
|
|
|
|
#define MODE_PERMANENT 0x0200 /* permanant channel, +P */
|
|
|
|
#define MODE_OPMODERATE 0x0400 /* send rejected messages to ops */
|
|
|
|
#define MODE_FREEINVITE 0x0800 /* allow free use of /invite */
|
|
|
|
#define MODE_FREETARGET 0x1000 /* can be forwarded to without authorization */
|
|
|
|
#define MODE_DISFORWARD 0x2000 /* disable channel forwarding */
|
|
|
|
|
|
|
|
#define CHFL_BAN 0x10000000 /* ban channel flag */
|
|
|
|
#define CHFL_EXCEPTION 0x20000000 /* exception to ban channel flag */
|
|
|
|
#define CHFL_INVEX 0x40000000
|
|
|
|
#define CHFL_QUIET 0x80000000
|
|
|
|
|
|
|
|
/* mode flags for direction indication */
|
|
|
|
#define MODE_QUERY 0
|
|
|
|
#define MODE_ADD 1
|
|
|
|
#define MODE_DEL -1
|
2020-11-05 22:19:00 +00:00
|
|
|
#define MODE_OP_QUERY 2
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
#define SecretChannel(x) ((x) && ((x)->mode.mode & MODE_SECRET))
|
|
|
|
#define HiddenChannel(x) ((x) && ((x)->mode.mode & MODE_PRIVATE))
|
|
|
|
#define PubChannel(x) ((!x) || ((x)->mode.mode &\
|
|
|
|
(MODE_PRIVATE | MODE_SECRET)) == 0)
|
|
|
|
|
|
|
|
/* channel visible */
|
|
|
|
#define ShowChannel(v,c) (PubChannel(c) || IsMember((v),(c)))
|
|
|
|
|
|
|
|
#define IsMember(who, chan) ((who && who->user && \
|
|
|
|
find_channel_membership(chan, who)) ? 1 : 0)
|
|
|
|
|
2016-09-16 19:02:41 +00:00
|
|
|
#define IsChannelName(name) ((name) && (IsChanPrefix(*(name))))
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/* extban function results */
|
|
|
|
#define EXTBAN_INVALID -1 /* invalid mask, false even if negated */
|
|
|
|
#define EXTBAN_NOMATCH 0 /* valid mask, no match */
|
|
|
|
#define EXTBAN_MATCH 1 /* matches */
|
|
|
|
|
2020-10-18 12:20:15 +00:00
|
|
|
int iter_comm_channels_step(rb_dlink_node *pos1, rb_dlink_node *pos2,
|
|
|
|
struct membership **ms1, struct membership **ms2,
|
|
|
|
struct Channel **chptr);
|
|
|
|
|
2020-10-21 19:29:26 +00:00
|
|
|
|
|
|
|
/* Iterate two sorted linked lists of channels, with heads headN, in lockstep.
|
|
|
|
At each iteration, chptr will be a channel in at least one of the lists,
|
|
|
|
and each msN will be non-null iff the channel is in its corresponding list.
|
|
|
|
|
|
|
|
head1 and head2 must be linked list heads.
|
|
|
|
pos1, pos2, ms1, ms2 must be names of modifiable variables, and should not
|
|
|
|
be modified during iteration. It is safe to break or continue at any point
|
|
|
|
without any special cleanup.
|
|
|
|
|
|
|
|
rb_dlink_node_t *pos1, *pos2, *head1, *head2;
|
|
|
|
struct membership *ms1, *ms2;
|
|
|
|
struct Channel *chptr;
|
|
|
|
*/
|
|
|
|
#define ITER_COMM_CHANNELS(pos1, pos2, head1, head2, ms1, ms2, chptr) \
|
|
|
|
for ((pos1) = (head1), (pos2) = (head2); \
|
|
|
|
iter_comm_channels_step((pos1), (pos2), &(ms1), &(ms2), &(chptr)); \
|
|
|
|
(ms1) && ((pos1) = (pos1)->next), (ms2) && ((pos2) = (pos2)->next))
|
2020-10-18 12:20:15 +00:00
|
|
|
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
extern rb_dlink_list global_channel_list;
|
2007-01-25 06:40:21 +00:00
|
|
|
void init_channels(void);
|
|
|
|
|
|
|
|
struct Channel *allocate_channel(const char *chname);
|
|
|
|
void free_channel(struct Channel *chptr);
|
2011-08-13 00:33:10 +00:00
|
|
|
struct Ban *allocate_ban(const char *, const char *, const char *);
|
2007-01-25 06:40:21 +00:00
|
|
|
void free_ban(struct Ban *bptr);
|
|
|
|
|
|
|
|
|
|
|
|
extern void destroy_channel(struct Channel *);
|
|
|
|
|
2014-03-03 04:25:47 +00:00
|
|
|
extern int can_send(struct Channel *chptr, struct Client *who,
|
2007-01-25 06:40:21 +00:00
|
|
|
struct membership *);
|
2021-04-17 18:43:59 +00:00
|
|
|
extern bool flood_attack_channel(enum message_type msgtype, struct Client *source_p,
|
2010-12-09 23:29:56 +00:00
|
|
|
struct Channel *chptr, char *chname);
|
2020-04-12 01:07:17 +00:00
|
|
|
struct matchset;
|
2007-01-25 06:40:21 +00:00
|
|
|
extern int is_banned(struct Channel *chptr, struct Client *who,
|
2020-04-12 01:07:17 +00:00
|
|
|
struct membership *msptr, const struct matchset *ms,
|
|
|
|
const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
extern int is_quieted(struct Channel *chptr, struct Client *who,
|
2020-04-12 01:07:17 +00:00
|
|
|
struct membership *msptr, const struct matchset *ms);
|
2012-01-08 15:25:34 +00:00
|
|
|
extern int can_join(struct Client *source_p, struct Channel *chptr,
|
|
|
|
const char *key, const char **forward);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
extern struct membership *find_channel_membership(struct Channel *, struct Client *);
|
|
|
|
extern const char *find_channel_status(struct membership *msptr, int combine);
|
|
|
|
extern void add_user_to_channel(struct Channel *, struct Client *, int flags);
|
|
|
|
extern void remove_user_from_channel(struct membership *);
|
|
|
|
extern void remove_user_from_channels(struct Client *);
|
|
|
|
extern void invalidate_bancache_user(struct Client *);
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
extern void free_channel_list(rb_dlink_list *);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-24 05:54:39 +00:00
|
|
|
extern bool check_channel_name(const char *name);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
extern void channel_member_names(struct Channel *chptr, struct Client *,
|
|
|
|
int show_eon);
|
|
|
|
|
|
|
|
extern void del_invite(struct Channel *chptr, struct Client *who);
|
|
|
|
|
2010-05-02 20:29:22 +00:00
|
|
|
const char *channel_modes(struct Channel *chptr, struct Client *who);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
extern struct Channel *find_bannickchange_channel(struct Client *client_p);
|
|
|
|
|
|
|
|
extern void check_spambot_warning(struct Client *source_p, const char *name);
|
|
|
|
|
|
|
|
extern void check_splitmode(void *);
|
|
|
|
|
|
|
|
void set_channel_topic(struct Channel *chptr, const char *topic,
|
|
|
|
const char *topic_info, time_t topicts);
|
|
|
|
|
|
|
|
extern void init_chcap_usage_counts(void);
|
|
|
|
extern void set_chcap_usage_counts(struct Client *serv_p);
|
|
|
|
extern void unset_chcap_usage_counts(struct Client *serv_p);
|
|
|
|
extern void send_cap_mode_changes(struct Client *client_p, struct Client *source_p,
|
|
|
|
struct Channel *chptr, struct ChModeChange foo[], int);
|
|
|
|
|
2010-03-27 15:13:57 +00:00
|
|
|
void resv_chan_forcepart(const char *name, const char *reason, int temp_time);
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
extern void set_channel_mode(struct Client *client_p, struct Client *source_p,
|
|
|
|
struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]);
|
2010-03-08 05:13:39 +00:00
|
|
|
extern void set_channel_mlock(struct Client *client_p, struct Client *source_p,
|
2016-03-08 10:52:31 +00:00
|
|
|
struct Channel *chptr, const char *newmlock, bool propagate);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
extern struct ChannelMode chmode_table[256];
|
|
|
|
|
2022-08-20 00:35:54 +00:00
|
|
|
extern struct Ban * add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
|
2011-08-13 00:33:10 +00:00
|
|
|
const char *forward, rb_dlink_list * list, long mode_type);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2011-08-13 00:33:10 +00:00
|
|
|
extern struct Ban * del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list,
|
|
|
|
long mode_type);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
extern ExtbanFunc extban_table[256];
|
|
|
|
|
|
|
|
extern int match_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
|
|
|
|
extern int valid_extban(const char *banstr, struct Client *client_p, struct Channel *chptr, long mode_type);
|
|
|
|
const char * get_extban_string(void);
|
|
|
|
|
2016-01-14 04:16:44 +00:00
|
|
|
extern int get_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2010-12-16 06:09:29 +00:00
|
|
|
extern void send_channel_join(struct Channel *chptr, struct Client *client_p);
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
#endif /* INCLUDED_channel_h */
|