1 /*
2  * chan.h
3  *   stuff common to chan.c and mode.c
4  *   users.h needs to be loaded too
5  */
6 /*
7  * Copyright (C) 1997 Robey Pointer
8  * Copyright (C) 1999 - 2021 Eggheads Development Team
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24 
25 #ifndef _EGG_CHAN_H
26 #define _EGG_CHAN_H
27 
28 /* Valid channel prefixes. */
29 #define CHANMETA "#&!+"
30 
31 /* Modes the bot cannot set as halfop. You can add +b, +e, and +I to this to
32  * prevent them from being set as halfop. */
33 #define NOHALFOPS_MODES "ahoq"
34 
35 /* Only send modes as op (b, e, and I excluded)? */
36 #undef NO_HALFOP_CHANMODES
37 
38 /* Hard limit of modes per line. */
39 #define MODES_PER_LINE_MAX 6
40 
41 #define HALFOP_CANTDOMODE(_a) (!me_op(chan) && (!me_halfop(chan) || (strchr(NOHALFOPS_MODES, _a) != NULL)))
42 #define HALFOP_CANDOMODE(_a)  (me_op(chan) || (me_halfop(chan) && (strchr(NOHALFOPS_MODES, _a) == NULL)))
43 
44 typedef struct memstruct {
45   char nick[NICKLEN];
46   char userhost[UHOSTLEN];
47   char account[NICKLEN];
48   time_t joined;
49   unsigned long flags;
50   time_t split; /* in case they were just netsplit */
51   time_t last;  /* for measuring idle time         */
52   time_t delay; /* for delayed autoop              */
53   struct userrec *user;
54   int tried_getuser;
55   struct memstruct *next;
56 } memberlist;
57 
58 #define CHANOP       0x00001 /* channel +o                                   */
59 #define CHANVOICE    0x00002 /* channel +v                                   */
60 #define FAKEOP       0x00004 /* op'd by server                               */
61 #define SENTOP       0x00008 /* a mode +o was already sent out for this user */
62 #define SENTDEOP     0x00010 /* a mode -o was already sent out for this user */
63 #define SENTKICK     0x00020 /* a kick was already sent out for this user    */
64 #define SENTVOICE    0x00040 /* a mode +v was already sent out for this user */
65 #define SENTDEVOICE  0x00080 /* a mode -v was already sent out for this user */
66 #define WASOP        0x00100 /* was an op before a split                     */
67 #define STOPWHO      0x00200
68 #define FULL_DELAY   0x00400
69 #define STOPCHECK    0x00800
70 #define CHANHALFOP   0x01000 /* channel +h                                   */
71 #define FAKEHALFOP   0x02000 /* halfop'd by server                           */
72 #define SENTHALFOP   0x04000 /* a mode +h was already sent out for this user */
73 #define SENTDEHALFOP 0x08000 /* a mode -h was already sent out for this user */
74 #define WASHALFOP    0x10000 /* was a halfop before a split                  */
75 #define WHO_SYNCED   0x20000 /* who reply received for this member           */
76 #define IRCAWAY      0x40000 /* is marked as away on IRC server              */
77 
78 #define chan_hasvoice(x)     (x->flags & CHANVOICE)
79 #define chan_hasop(x)        (x->flags & CHANOP)
80 #define chan_hashalfop(x)    (x->flags & CHANHALFOP)
81 #define chan_fakeop(x)       (x->flags & FAKEOP)
82 #define chan_fakehalfop(x)   (x->flags & FAKEHALFOP)
83 #define chan_sentop(x)       (x->flags & SENTOP)
84 #define chan_sentdeop(x)     (x->flags & SENTDEOP)
85 #define chan_senthalfop(x)   (x->flags & SENTHALFOP)
86 #define chan_sentdehalfop(x) (x->flags & SENTDEHALFOP)
87 #define chan_sentkick(x)     (x->flags & SENTKICK)
88 #define chan_sentvoice(x)    (x->flags & SENTVOICE)
89 #define chan_sentdevoice(x)  (x->flags & SENTDEVOICE)
90 #define chan_issplit(x)      (x->split > 0)
91 #define chan_wasop(x)        (x->flags & WASOP)
92 #define chan_washalfop(x)    (x->flags & WASHALFOP)
93 #define chan_stopcheck(x)    (x->flags & STOPCHECK)
94 #define chan_whosynced(x)    (x->flags & WHO_SYNCED)
95 #define chan_ircaway(x)       (x->flags & IRCAWAY)
96 
97 /* Why duplicate this struct for exempts and invites only under another
98  * name? <cybah>
99  */
100 typedef struct maskstruct {
101   char *mask;
102   char *who;
103   time_t timer;
104   struct maskstruct *next;
105 } masklist;
106 
107 /* Used for temporary bans, exempts and invites */
108 typedef struct maskrec {
109   struct maskrec *next;
110   char *mask,
111        *desc,
112        *user;
113   time_t expire,
114          added,
115          lastactive;
116   int flags;
117 } maskrec;
118 extern maskrec *global_bans, *global_exempts, *global_invites;
119 
120 #define MASKREC_STICKY 1
121 #define MASKREC_PERM   2
122 
123 /* For every channel i join */
124 struct chan_t {
125   memberlist *member;
126   masklist *ban;
127   masklist *exempt;
128   masklist *invite;
129   char *topic;
130   char *key;
131   unsigned int mode;
132   int maxmembers;
133   int members;
134 };
135 
136 #define CHANINV    0x0001  /* i                        */
137 #define CHANPRIV   0x0002  /* p                        */
138 #define CHANSEC    0x0004  /* s                        */
139 #define CHANMODER  0x0008  /* m                        */
140 #define CHANTOPIC  0x0010  /* t                        */
141 #define CHANNOMSG  0x0020  /* n                        */
142 #define CHANLIMIT  0x0040  /* l                        */
143 #define CHANKEY    0x0080  /* k                        */
144 #define CHANANON   0x0100  /* a - ircd 2.9             */
145 #define CHANQUIET  0x0200  /* q - ircd 2.9             */
146 #define CHANNOCLR  0x0400  /* c - Bahamut              */
147 #define CHANREGON  0x0800  /* R - Bahamut              */
148 #define CHANMODREG 0x1000  /* M - Bahamut              */
149 #define CHANNOCTCP 0x2000  /* C - QuakeNet's ircu 2.10 */
150 #define CHANLONLY  0x4000  /* r - ircu 2.10.11         */
151 #define CHANDELJN  0x8000  /* D - QuakeNet's asuka     */
152 #define CHANSTRIP  0x10000 /* u - QuakeNet's asuka     */
153 #define CHANNONOTC 0x20000 /* N - QuakeNet's asuka     */
154 #define CHANINVIS  0x40000 /* d - QuakeNet's asuka     */
155 #define CHANNOAMSG 0x80000 /* T - QuakeNet's snircd    */
156 
157 struct chanset_t {
158   struct chanset_t *next;
159   struct chan_t channel;
160   char dname[CHANNELLEN + 1]; /* display name (!foo) - THIS IS ALWAYS SET */
161   char name[CHANNELLEN + 1];  /* actual name (!BARfoo) - THIS IS SET WHEN THE BOT
162                                * ACTUALLY JOINS THE CHANNEL */
163   char need_op[121];
164   char need_key[121];
165   char need_limit[121];
166   char need_unban[121];
167   char need_invite[121];
168   int flood_pub_thr;
169   int flood_pub_time;
170   int flood_join_thr;
171   int flood_join_time;
172   int flood_deop_thr;
173   int flood_deop_time;
174   int flood_kick_thr;
175   int flood_kick_time;
176   int flood_ctcp_thr;
177   int flood_ctcp_time;
178   int flood_nick_thr;
179   int flood_nick_time;
180   int aop_min;
181   int aop_max;
182   long status;
183   int ircnet_status;
184   int idle_kick;
185   int stopnethack_mode;
186   int revenge_mode;
187   int ban_type;
188   int ban_time;
189   int invite_time;
190   int exempt_time;
191   maskrec *bans,         /* temporary channel bans            */
192           *exempts,      /* temporary channel exempts         */
193           *invites;      /* temporary channel invites         */
194   int mode_pls_prot;     /* modes to enforce                  */
195   int mode_mns_prot;     /* modes to reject                   */
196   int limit_prot;        /* desired limit                     */
197   char key_prot[121];    /* desired password                  */
198   char pls[21];          /* positive mode changes             */
199   char mns[21];          /* negative mode changes             */
200   char *key;             /* new key to set                    */
201   char *rmkey;           /* old key to remove                 */
202   int limit;             /* new limit to set                  */
203   int bytes;             /* total bytes so far                */
204   int compat;            /* prevents mixing of old/new modes  */
205   struct {
206     char *op;
207     int type;
208   } cmode[MODES_PER_LINE_MAX];
209   char floodwho[FLOOD_CHAN_MAX][81];
210   time_t floodtime[FLOOD_CHAN_MAX];
211   int floodnum[FLOOD_CHAN_MAX];
212   char deopd[NICKLEN];   /* last user deopped                 */
213 };
214 
215 #define CHAN_ENFORCEBANS    0x0001     /* +enforcebans    */
216 #define CHAN_DYNAMICBANS    0x0002     /* +dynamicbans    */
217 #define CHAN_NOUSERBANS     0x0004     /* -userbans       */
218 #define CHAN_OPONJOIN       0x0008     /* +autoop         */
219 #define CHAN_BITCH          0x0010     /* +bitch          */
220 #define CHAN_GREET          0x0020     /* +greet          */
221 #define CHAN_PROTECTOPS     0x0040     /* +protectops     */
222 #define CHAN_LOGSTATUS      0x0080     /* +statuslog      */
223 #define CHAN_REVENGE        0x0100     /* +revenge        */
224 #define CHAN_SECRET         0x0200     /* +secret         */
225 #define CHAN_AUTOVOICE      0x0400     /* +autovoice      */
226 #define CHAN_CYCLE          0x0800     /* +cycle          */
227 #define CHAN_DONTKICKOPS    0x1000     /* +dontkickops    */
228 #define CHAN_INACTIVE       0x2000     /* +inactive       */
229 #define CHAN_PROTECTFRIENDS 0x4000     /* +protectfriends */
230 #define CHAN_SHARED         0x8000     /* +shared         */
231 #define CHAN_SEEN           0x10000    /* +seen           */
232 #define CHAN_REVENGEBOT     0x20000    /* +revengebot     */
233 #define CHAN_NODESYNCH      0x40000    /* +nodesynch      */
234 #define CHAN_AUTOHALFOP     0x80000    /* +autohalfop     */
235 #define CHAN_PROTECTHALFOPS 0x100000   /* +protecthalfops */
236 #define CHAN_ACTIVE         0x200000   /* -inactive       */
237 
238 #define CHAN_WHINED         0x1000000  /* whined about opless channel      */
239 #define CHAN_PEND           0x2000000  /* waiting for end of WHO list      */
240 #define CHAN_FLAGGED        0x4000000  /* flagged for delete during rehash */
241 #define CHAN_STATIC         0x8000000  /* non-dynamic channel              */
242 #define CHAN_ASKEDBANS      0x10000000
243 #define CHAN_ASKEDMODES     0x20000000 /* find out key-info on IRCu        */
244 #define CHAN_JUPED          0x40000000 /* channel is juped                 */
245 #define CHAN_STOP_CYCLE     0x80000000 /* NO_CHANOPS_WHEN_SPLIT servers    */
246 
247 #define CHAN_ASKED_EXEMPTS  0x0001
248 #define CHAN_ASKED_INVITED  0x0002
249 
250 #define CHAN_DYNAMICEXEMPTS 0x0004
251 #define CHAN_NOUSEREXEMPTS  0x0008
252 #define CHAN_DYNAMICINVITES 0x0010
253 #define CHAN_NOUSERINVITES  0x0020
254 
255 /* prototypes */
256 memberlist *ismember(struct chanset_t *, char *);
257 struct chanset_t *findchan(const char *name);
258 struct chanset_t *findchan_by_dname(const char *name);
259 
260 #define channel_hidden(chan) (chan->channel.mode & (CHANPRIV | CHANSEC)) /* +s or +p ? */
261 #define channel_optopic(chan) (chan->channel.mode & CHANTOPIC) /* +t? */
262 #define channel_djoins(chan) (chan->status & (CHANDELJN | CHANINVIS)) /* +Dd? */
263 
264 #define channel_active(chan)  (chan->status & CHAN_ACTIVE)
265 #define channel_pending(chan)  (chan->status & CHAN_PEND)
266 #define channel_bitch(chan) (chan->status & CHAN_BITCH)
267 #define channel_nodesynch(chan) (chan->status & CHAN_NODESYNCH)
268 #define channel_autoop(chan) (chan->status & CHAN_OPONJOIN)
269 #define channel_autovoice(chan) (chan->status & CHAN_AUTOVOICE)
270 #define channel_autohalfop(chan) (chan->status & CHAN_AUTOHALFOP)
271 #define channel_greet(chan) (chan->status & CHAN_GREET)
272 #define channel_logstatus(chan) (chan->status & CHAN_LOGSTATUS)
273 #define channel_enforcebans(chan) (chan->status & CHAN_ENFORCEBANS)
274 #define channel_revenge(chan) (chan->status & CHAN_REVENGE)
275 #define channel_dynamicbans(chan) (chan->status & CHAN_DYNAMICBANS)
276 #define channel_nouserbans(chan) (chan->status & CHAN_NOUSERBANS)
277 #define channel_protectops(chan) (chan->status & CHAN_PROTECTOPS)
278 #define channel_protecthalfops(chan) (chan->status & CHAN_PROTECTHALFOPS)
279 #define channel_protectfriends(chan) (chan->status & CHAN_PROTECTFRIENDS)
280 #define channel_dontkickops(chan) (chan->status & CHAN_DONTKICKOPS)
281 #define channel_secret(chan) (chan->status & CHAN_SECRET)
282 #define channel_shared(chan) (chan->status & CHAN_SHARED)
283 #define channel_static(chan) (chan->status & CHAN_STATIC)
284 #define channel_cycle(chan) (chan->status & CHAN_CYCLE)
285 #define channel_seen(chan) (chan->status & CHAN_SEEN)
286 #define channel_inactive(chan) (chan->status & CHAN_INACTIVE)
287 #define channel_revengebot(chan) (chan->status & CHAN_REVENGEBOT)
288 #define channel_dynamicexempts(chan) (chan->ircnet_status & CHAN_DYNAMICEXEMPTS)
289 #define channel_nouserexempts(chan) (chan->ircnet_status & CHAN_NOUSEREXEMPTS)
290 #define channel_dynamicinvites(chan) (chan->ircnet_status & CHAN_DYNAMICINVITES)
291 #define channel_nouserinvites(chan) (chan->ircnet_status & CHAN_NOUSERINVITES)
292 #define channel_juped(chan) (chan->status & CHAN_JUPED)
293 #define channel_stop_cycle(chan) (chan->status & CHAN_STOP_CYCLE)
294 #define channel_whined(chan) (chan->status & CHAN_WHINED)
295 
296 struct msgq_head {
297   struct msgq *head;
298   struct msgq *last;
299   int tot;
300   int warned;
301 };
302 
303 /* Used to queue a lot of things */
304 struct msgq {
305   struct msgq *next;
306   int len;
307   char *msg;
308 };
309 
310 #endif /* _EGG_CHAN_H */
311