]> jfr.im git - irc/quakenet/newserv.git/blob - chanserv/chanserv.h
More chanserv refactoring
[irc/quakenet/newserv.git] / chanserv / chanserv.h
1 /*
2 * chanserv.h:
3 * Top level data structures and function prototypes for the
4 * channel service module
5 */
6
7 #ifndef __CHANSERV_H
8 #define __CHANSERV_H
9
10 #include <time.h>
11 #include "../lib/sstring.h"
12 #include "../core/schedule.h"
13 #include "../lib/flags.h"
14 #include "../nick/nick.h"
15 #include "../channel/channel.h"
16 #include "../parser/parser.h"
17 #include "../localuser/localuserchannel.h"
18
19 #define CS_PARANOID
20
21 #ifdef CS_PARANOID
22 #include <assert.h>
23 #endif
24
25 /* Mini-hash of known users on channels to make lookups faster;
26 * how big do we make it? */
27 #define REGCHANUSERHASHSIZE 5
28 #define PASSLEN 10
29 #define WELCOMELEN 250
30 #define INFOLEN 100
31 #define AUTOLIMIT_INTERVAL 60
32 #define COUNTERSYNCINTERVAL 600
33 #define LINGERTIME 300
34 #define DUMPINTERVAL 300
35 #define EMAILLEN 60
36 #define CHANTYPES 7
37
38 /* Suspension and g-line hit count limits */
39 #define MAXGLINEUSERS 50
40 #define MAXSUSPENDHIT 500
41
42 /* Maximum number of times a user may attempt to auth */
43 #define MAXAUTHATTEMPT 3
44
45 /* Maximum number of times a user may actually be authed */
46 #define MAXAUTHCOUNT 2
47
48 /* Sizes of the main hashes */
49 #define REGUSERHASHSIZE 60000
50
51 /* Number of languages and messages */
52 #define MAXLANG 50
53 #define MAXMESSAGES 200
54
55 /* The list of messages */
56 #define QM_PROTECTED 0
57 #define QM_UNKNOWNCMD 1
58 #define QM_SECUREONLY 2
59 #define QM_AUTHEDONLY 3
60 #define QM_UNAUTHEDONLY 4
61 #define QM_COMMANDLIST 5
62 #define QM_ENDOFLIST 6
63 #define QM_DONE 7
64 #define QM_NOTENOUGHPARAMS 8
65 #define QM_UNKNOWNCHAN 9
66 #define QM_NOACCESSONCHAN 10
67 #define QM_CURCHANFLAGS 11
68 #define QM_CURFORCEMODES 12
69 #define QM_NOACCESS 13
70 #define QM_UNKNOWNUSER 14
71 #define QM_USERNOTAUTHED 15
72 #define QM_CHANLEVHEADER 16
73 #define QM_CHANLEVCOLSHORT 17
74 #define QM_CHANLEVCOLFULL 18
75 #define QM_NOUSERSONCHANLEV 19
76 #define QM_CHANUSERFLAGS 20
77 #define QM_CHANUSERUNKNOWN 21
78 #define QM_INVALIDCHANLEVCHANGE 22
79 #define QM_USERISAUTHEDAS 23
80 #define QM_USERISHELPER 24
81 #define QM_USERISOPER 25
82 #define QM_USERISADMIN 26
83 #define QM_USERISDEV 27
84 #define QM_WHOISHEADER 28
85 #define QM_WHOISCOLS 29
86 #define QM_USERONNOCHANS 30
87 #define QM_CHANAUTOLIMIT 31
88 #define QM_CHANBANAUTOREMOVE 32
89 #define QM_NOCHANBANAUTOREMOVE 33
90 #define QM_INVALIDCHANNAME 34
91 #define QM_ALREADYREGISTERED 35
92 #define QM_CURUSERFLAGS 36
93 #define QM_WELCOMEMESSAGEIS 37
94 #define QM_GLOBALINFO 38
95 #define QM_CHANNELINFO 39
96 #define QM_PROTECTEDNICK 40
97 #define QM_NICKWASFAKED 41
98 #define QM_NOTPROTECTED 42
99 #define QM_SAMEAUTH 43
100 #define QM_AUTHFAIL 44
101 #define QM_AUTHOK 45
102 #define QM_NEWACCOUNT 46
103 #define QM_AUTHNAMEINUSE 47
104 #define QM_ALREADYONCHAN 48
105 #define QM_NOTONCHAN 49
106 #define QM_ALREADYOPPED 50
107 #define QM_USERNOTONCHAN 51
108 #define QM_USEROPPEDONCHAN 52
109 #define QM_CANTOP 53
110 #define QM_NOTOPPED 54
111 #define QM_ALREADYVOICED 55
112 #define QM_NOTVOICED 56
113 #define QM_USERVOICEDONCHAN 57
114 #define QM_REGBANHEADER 58
115 #define QM_NOBANS 59
116 #define QM_REMOVEDCHANBAN 60
117 #define QM_NOTREMOVEDPERMBAN 61
118 #define QM_REMOVEDPERMBAN 62
119 #define QM_CANTVOICE 63
120 #define QM_NOHELP 64
121 #define QM_WHOISHEADER_NICK 65
122 #define QM_WHOISHEADER_AUTH 66
123 #define QM_WHOIS_USERS 67
124 #define QM_WHOIS_LASTAUTH 68
125 #define QM_WHOIS_LASTUSERHOST 69
126 #define QM_WHOIS_USERID 70
127 #define QM_WHOIS_INFO 71
128 #define QM_WHOIS_COMMENT 72
129 #define QM_WHOIS_FLAGS 73
130 #define QM_WHOIS_CREATED 74
131 #define QM_WHOIS_CHANHEADER 75
132 #define QM_WHOIS_EMAIL 76
133 #define QM_WHOIS_EMAILSET 77
134 #define QM_COMMENT 78
135 #define QM_NOCOMMENT 79
136 #define QM_BADAUTH 80
137 #define QM_USERHASBADAUTH 81
138 #define QM_BADEMAIL 82
139 #define QM_MAILTHROTTLED 83
140 #define QM_MAILQUEUED 84
141 #define QM_PWDONTMATCH 85
142 #define QM_PWTOSHORT 86
143 #define QM_PWCHANGED 87
144 #define QM_MASTERPWCHANGED 88
145 #define QM_EMAILCHANGED 89
146 #define QM_EMAILDONTMATCH 90
147 #define QM_INVALIDEMAIL 91
148 #define QM_EMAILTOOSHORT 92
149 #define QM_NOTYOUREMAIL 93
150 #define QM_EMAILNOAT 94
151 #define QM_EMAILATEND 95
152 #define QM_EMAILINVCHR 96
153 #define QM_CHANNELNOTSUSPENDED 97
154 #define QM_CHANNELALREADYSUSPENDED 98
155 #define QM_CHANTYPE 99
156 #define QM_UNKNOWNCHANTYPE 100
157 #define QM_FOUNDER 101
158 #define QM_ADDEDBY 102
159 #define QM_ALREADYKNOWNONCHAN 103
160 #define QM_CANNOTREMOVEOWNER 104
161 #define QM_CANNOTREMOVEMASTER 105
162 #define QM_UNKNOWNBAN 106
163 #define QM_YOURLANGUAGE 107
164 #define QM_LANGUAGELIST 108
165 #define QM_UNKNOWNLANGUAGE 109
166 #define QM_WHOIS_USERLANG 110
167 #define QM_CHANTYPEIS 111
168 #define QM_STATSHEADER 112
169 #define QM_STATSADDED 113
170 #define QM_STATSJOINS 114
171 #define QM_STATSLASTACTIVE 115
172 #define QM_AUTHSUSPENDED 116
173 #define QM_REASON 117
174 #define QM_EXPIRES 118
175 #define QM_TOOMANYAUTHS 119
176 #define QM_INVALIDDURATION 120
177 #define QM_DISCONNECTINGUSER 121
178 #define QM_USERALREADYSUSPENDED 122
179 #define QM_USERNOTSUSPENDED 123
180 #define QM_SPEWHEADER 124
181 #define QM_TOOMANYRESULTS 125
182 #define QM_RESULTCOUNT 126
183 #define QM_SUSPENDKILL 127
184 #define QM_LISTFLAGSHEADER 128
185 #define QM_SUSPENDUSERLISTHEADER 129
186 #define QM_SUSPENDCHANLISTHEADER 130
187
188 /* List of privileged operations */
189
190 #define QPRIV_SUSPENDBYPASS 1
191 #define QPRIV_VIEWCHANFLAGS 100
192 #define QPRIV_VIEWFULLCHANLEV 101
193 #define QPRIV_VIEWFULLWHOIS 102
194 #define QPRIV_VIEWCHANMODES 103
195 #define QPRIV_VIEWAUTOLIMIT 104
196 #define QPRIV_VIEWBANTIMER 105
197 #define QPRIV_VIEWUSERFLAGS 106
198 #define QPRIV_VIEWWELCOME 107
199 #define QPRIV_VIEWCOMMENTS 108
200 #define QPRIV_VIEWEMAIL 109
201
202 #define QPRIV_CHANGECHANFLAGS 200
203 #define QPRIV_CHANGECHANLEV 201
204 #define QPRIV_CHANGECHANMODES 202
205 #define QPRIV_CHANGEAUTOLIMIT 203
206 #define QPRIV_CHANGEBANTIMER 204
207 #define QPRIV_CHANGEUSERFLAGS 205
208 #define QPRIV_CHANGEWELCOME 206
209
210 /* List of access checks */
211
212 #define CA_AUTHED 0x0001
213 #define CA_TOPICPRIV 0x0008
214 #define CA_KNOWN 0x0010
215 #define CA_VOICEPRIV 0x0020
216 #define CA_OPPRIV 0x0040
217 #define CA_MASTERPRIV 0x0080
218 #define CA_OWNERPRIV 0x0100
219 /* SPARE 0x0200 */
220 #define CA_ONCHAN 0x0400
221 #define CA_OFFCHAN 0x0800
222 #define CA_OPPED 0x1000
223 #define CA_DEOPPED 0x2000
224 #define CA_VOICED 0x4000
225 #define CA_DEVOICED 0x8000
226
227 #define CA_NEEDKNOWN (CA_KNOWN|CA_OPPRIV|CA_MASTERPRIV|CA_TOPICPRIV|CA_OWNERPRIV)
228 #define CA_ONCHANREQ (CA_ONCHAN|CA_OPPED|CA_DEOPPED|CA_VOICED|CA_DEVOICED)
229
230
231 /* User flags */
232 #define QUFLAG_NEEDAUTH 0x0001 /* +l */
233 #define QUFLAG_GLINE 0x0002 /* +g */
234 #define QUFLAG_NOTICE 0x0004 /* +n */
235 #define QUFLAG_RESTRICTED 0x0008 /* +r */
236 #define QUFLAG_SUSPENDED 0x0010 /* +z */
237 #define QUFLAG_OPER 0x0020 /* +o */
238 #define QUFLAG_DEV 0x0040 /* +d */
239 #define QUFLAG_PROTECT 0x0080 /* +p */
240 #define QUFLAG_HELPER 0x0100 /* +h */
241 #define QUFLAG_ADMIN 0x0200 /* +a */
242 #define QUFLAG_INFO 0x0400 /* +i */
243 #define QUFLAG_DELAYEDGLINE 0x0800 /* +G */
244 #define QUFLAG_NOAUTHLIMIT 0x1000 /* +L */
245 #define QUFLAG_ALL 0x1fff
246
247 #define UIsNeedAuth(x) ((x)->flags & QUFLAG_NEEDAUTH)
248 #define UIsGline(x) ((x)->flags & QUFLAG_GLINE)
249 #define UIsNotice(x) ((x)->flags & QUFLAG_NOTICE)
250 #define UIsRestricted(x) ((x)->flags & QUFLAG_RESTRICTED)
251 #define UIsSuspended(x) ((x)->flags & QUFLAG_SUSPENDED)
252 #define UIsOper(x) ((x)->flags & QUFLAG_OPER)
253 #define UIsDev(x) ((x)->flags & QUFLAG_DEV)
254 #define UIsProtect(x) ((x)->flags & QUFLAG_PROTECT)
255 #define UIsHelper(x) ((x)->flags & QUFLAG_HELPER)
256 #define UIsAdmin(x) ((x)->flags & QUFLAG_ADMIN)
257 #define UIsInfo(x) ((x)->flags & QUFLAG_INFO)
258 #define UIsDelayedGline(x) ((x)->flags & QUFLAG_DELAYEDGLINE)
259 #define UIsNoAuthLimit(x) ((x)->flags & QUFLAG_NOAUTHLIMIT)
260
261 #define UHasSuspension(x) ((x)->flags & (QUFLAG_GLINE|QUFLAG_DELAYEDGLINE|QUFLAG_SUSPENDED|QUFLAG_NEEDAUTH))
262
263 #define UHasHelperPriv(x) ((x)->flags & (QUFLAG_HELPER | QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
264 #define UHasOperPriv(x) ((x)->flags & (QUFLAG_OPER | QUFLAG_ADMIN | QUFLAG_DEV))
265 #define UHasAdminPriv(x) ((x)->flags & (QUFLAG_ADMIN | QUFLAG_DEV))
266
267 /* email */
268 #define MAX_RESEND_TIME 2*3600L /* cooling off period */
269 #define VALID_EMAIL "^[-_.+[:alpha:][:digit:]]+(\\.[-_[:digit:][:alpha:]]+)*@([[:digit:][:alpha:]](-?[[:digit:][:alpha:]])*\\.)+[[:alpha:]]{2}([zmuvtgo]|fo|me|seum|op|ro)?$"
270
271 #define QMAIL_NEWACCOUNT 1 /* new account */
272 #define QMAIL_REQPW 2 /* requestpassword */
273 #define QMAIL_NEWPW 3 /* new password */
274 #define QMAIL_NEWMASTERPW 4 /* new master password */
275 #define QMAIL_NEWEMAIL 5 /* new email address */
276
277 /* USet... */
278 /* UClear... */
279
280 /* Channel flags */
281 #define QCFLAG_AUTOOP 0x0001 /* +a */
282 #define QCFLAG_BITCH 0x0002 /* +b */
283 #define QCFLAG_AUTOLIMIT 0x0004 /* +c */
284 #define QCFLAG_ENFORCE 0x0008 /* +e */
285 #define QCFLAG_FORCETOPIC 0x0010 /* +f */
286 #define QCFLAG_AUTOVOICE 0x0020 /* +g */
287 #define QCFLAG_INFO 0x0040 /* +i */
288 #define QCFLAG_JOINED 0x0080 /* +j */
289 #define QCFLAG_KNOWNONLY 0x0100 /* +k */
290 #define QCFLAG_PROTECT 0x0200 /* +p */
291 #define QCFLAG_SPAMPROT 0x0400 /* +s */
292 #define QCFLAG_TOPICSAVE 0x0800 /* +t */
293 #define QCFLAG_VOICEALL 0x1000 /* +v */
294 #define QCFLAG_WELCOME 0x2000 /* +w */
295 #define QCFLAG_SUSPENDED 0x4000 /* +z */
296
297 #define CIsAutoOp(x) ((x)->flags & QCFLAG_AUTOOP)
298 #define CIsBitch(x) ((x)->flags & QCFLAG_BITCH)
299 #define CIsAutoLimit(x) ((x)->flags & QCFLAG_AUTOLIMIT)
300 #define CIsEnforce(x) ((x)->flags & QCFLAG_ENFORCE)
301 #define CIsForceTopic(x) ((x)->flags & QCFLAG_FORCETOPIC)
302 #define CIsAutoVoice(x) ((x)->flags & QCFLAG_AUTOVOICE)
303 #define CIsJoined(x) ((x)->flags & QCFLAG_JOINED)
304 #define CIsKnownOnly(x) ((x)->flags & QCFLAG_KNOWNONLY)
305 #define CIsProtect(x) ((x)->flags & QCFLAG_PROTECT)
306 #define CIsSpamProt(x) ((x)->flags & QCFLAG_SPAMPROT)
307 #define CIsTopicSave(x) ((x)->flags & QCFLAG_TOPICSAVE)
308 #define CIsVoiceAll(x) ((x)->flags & QCFLAG_VOICEALL)
309 #define CIsWelcome(x) ((x)->flags & QCFLAG_WELCOME)
310 #define CIsSuspended(x) ((x)->flags & QCFLAG_SUSPENDED)
311 #define CIsInfo(x) ((x)->flags & QCFLAG_INFO)
312
313 #define CSetAutoOp(x) ((x)->flags |= QCFLAG_AUTOOP)
314 #define CSetBitch(x) ((x)->flags |= QCFLAG_BITCH)
315 #define CSetAutoLimit(x) ((x)->flags |= QCFLAG_AUTOLIMIT)
316 #define CSetEnforce(x) ((x)->flags |= QCFLAG_ENFORCE)
317 #define CSetForceTopic(x) ((x)->flags |= QCFLAG_FORCETOPIC)
318 #define CSetAutoVoice(x) ((x)->flags |= QCFLAG_AUTOVOICE)
319 #define CSetJoined(x) ((x)->flags |= QCFLAG_JOINED)
320 #define CSetKnownOnly(x) ((x)->flags |= QCFLAG_KNOWNONLY)
321 #define CSetProtect(x) ((x)->flags |= QCFLAG_PROTECT)
322 #define CSetSpamProt(x) ((x)->flags |= QCFLAG_SPAMPROT)
323 #define CSetTopicSave(x) ((x)->flags |= QCFLAG_TOPICSAVE)
324 #define CSetVoiceAll(x) ((x)->flags |= QCFLAG_VOICEALL)
325 #define CSetWelcome(x) ((x)->flags |= QCFLAG_WELCOME)
326 #define CSetSuspended(x) ((x)->flags |= QCFLAG_SUSPENDED)
327
328 #define CClearAutoOp(x) ((x)->flags &= ~QCFLAG_AUTOOP)
329 #define CClearBitch(x) ((x)->flags &= ~QCFLAG_BITCH)
330 #define CClearAutoLimit(x) ((x)->flags &= ~QCFLAG_AUTOLIMIT)
331 #define CClearEnforce(x) ((x)->flags &= ~QCFLAG_ENFORCE)
332 #define CClearForceTopic(x) ((x)->flags &= ~QCFLAG_FORCETOPIC)
333 #define CClearAutoVoice(x) ((x)->flags &= ~QCFLAG_AUTOVOICE)
334 #define CClearJoined(x) ((x)->flags &= ~QCFLAG_JOINED)
335 #define CClearKnownOnly(x) ((x)->flags &= ~QCFLAG_KNOWNONLY)
336 #define CClearProtect(x) ((x)->flags &= ~QCFLAG_PROTECT)
337 #define CClearSpamProt(x) ((x)->flags &= ~QCFLAG_SPAMPROT)
338 #define CClearTopicSave(x) ((x)->flags &= ~QCFLAG_TOPICSAVE)
339 #define CClearVoiceAll(x) ((x)->flags &= ~QCFLAG_VOICEALL)
340 #define CClearWelcome(x) ((x)->flags &= ~QCFLAG_WELCOME)
341 #define CClearSuspended(x) ((x)->flags &= ~QCFLAG_SUSPENDED)
342
343 #define QCFLAG_USERCONTROL (QCFLAG_AUTOOP|QCFLAG_BITCH|QCFLAG_AUTOLIMIT| \
344 QCFLAG_ENFORCE|QCFLAG_FORCETOPIC|QCFLAG_AUTOVOICE| \
345 QCFLAG_JOINED|QCFLAG_PROTECT|QCFLAG_INFO| \
346 QCFLAG_SPAMPROT|QCFLAG_TOPICSAVE|QCFLAG_VOICEALL| \
347 QCFLAG_WELCOME|QCFLAG_KNOWNONLY)
348
349 #define QCFLAG_ALL 0x7fff
350
351
352 /* Channel user ("chanlev") flags */
353 /* Slightly funny order here: list the "biggest" flags at the
354 * top so we can do sorted "chanlev" output more easily */
355 #define QCUFLAG_OWNER 0x8000 /* +n */
356 #define QCUFLAG_MASTER 0x4000 /* +m */
357 #define QCUFLAG_OP 0x2000 /* +o */
358 #define QCUFLAG_VOICE 0x1000 /* +v */
359 #define QCUFLAG_AUTOOP 0x0001 /* +a */
360 #define QCUFLAG_BANNED 0x0002 /* +b */
361 #define QCUFLAG_DENY 0x0004 /* +d */
362 #define QCUFLAG_AUTOVOICE 0x0008 /* +g */
363 #define QCUFLAG_QUIET 0x0010 /* +q */
364 #define QCUFLAG_SPAMCON 0x0020 /* +s */
365 #define QCUFLAG_TOPIC 0x0040 /* +t */
366 #define QCUFLAG_HIDEWELCOME 0x0080 /* +w */
367 #define QCUFLAG_PROTECT 0x0100 /* +p */
368 #define QCUFLAG_HIDEINFO 0x0200 /* +i */
369 #define QCUFLAG_KNOWN 0x0400 /* +k */
370 #define QCUFLAG_AUTOINVITE 0x0800 /* +j */
371
372 #define QCUFLAG_SIGNIFICANT (QCUFLAG_MASTER|QCUFLAG_OWNER|QCUFLAG_OP)
373
374 #define QCUFLAG_MASTERCON (QCUFLAG_AUTOOP|QCUFLAG_BANNED|QCUFLAG_DENY| \
375 QCUFLAG_GIVE|QCUFLAG_OP|QCUFLAG_QUIET|QCUFLAG_TOPIC| \
376 QCUFLAG_VOICE|QCUFLAG_PROTECT)
377
378 #define QCUFLAG_SELFCON (QCUFLAG_OP | QCUFLAG_VOICE | QCUFLAG_AUTOOP | QCUFLAG_AUTOVOICE | \
379 QCUFLAG_SPAMCON | QCUFLAG_TOPIC | QCUFLAG_HIDEINFO)
380
381 #define QCUFLAG_ALL 0xffff
382
383 #define CUIsOwner(x) ((x)->flags & QCUFLAG_OWNER)
384 #define CUIsMaster(x) ((x)->flags & QCUFLAG_MASTER)
385 #define CUIsOp(x) ((x)->flags & QCUFLAG_OP)
386 #define CUIsVoice(x) ((x)->flags & QCUFLAG_VOICE)
387 #define CUIsAutoOp(x) ((x)->flags & QCUFLAG_AUTOOP)
388 #define CUIsBanned(x) ((x)->flags & QCUFLAG_BANNED)
389 #define CUIsDeny(x) ((x)->flags & QCUFLAG_DENY)
390 #define CUIsAutoVoice(x) ((x)->flags & QCUFLAG_AUTOVOICE)
391 #define CUIsQuiet(x) ((x)->flags & QCUFLAG_QUIET)
392 #define CUIsSpamCon(x) ((x)->flags & QCUFLAG_SPAMCON)
393 #define CUIsTopic(x) ((x)->flags & QCUFLAG_TOPIC)
394 #define CUIsHideWelcome(x) ((x)->flags & QCUFLAG_HIDEWELCOME)
395 #define CUIsProtect(x) ((x)->flags & QCUFLAG_PROTECT)
396 #define CUIsHideInfo(x) ((x)->flags & QCUFLAG_HIDEINFO)
397 #define CUIsKnown(x) ((x)->flags & QCUFLAG_KNOWN)
398 #define CUIsAutoInvite(x) ((x)->flags & QCUFLAG_AUTOINVITE)
399
400 #define CUKnown(x) (CUIsKnown(x) || CUHasVoicePriv(x))
401 #define CUHasVoicePriv(x) ((x)->flags & (QCUFLAG_VOICE | QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
402 #define CUHasOpPriv(x) ((x)->flags & (QCUFLAG_OP | QCUFLAG_MASTER | QCUFLAG_OWNER))
403 #define CUHasMasterPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER))
404 #define CUHasTopicPriv(x) ((x)->flags & (QCUFLAG_MASTER | QCUFLAG_OWNER | QCUFLAG_TOPIC))
405
406 #define CUSetOwner(x) ((x)->flags |= QCUFLAG_OWNER)
407 #define CUSetMaster(x) ((x)->flags |= QCUFLAG_MASTER)
408 #define CUSetOp(x) ((x)->flags |= QCUFLAG_OP)
409 #define CUSetVoice(x) ((x)->flags |= QCUFLAG_VOICE)
410 #define CUSetAutoOp(x) ((x)->flags |= QCUFLAG_AUTOOP)
411 #define CUSetBanned(x) ((x)->flags |= QCUFLAG_BANNED)
412 #define CUSetDeny(x) ((x)->flags |= QCUFLAG_DENY)
413 #define CUSetAutoVoice(x) ((x)->flags |= QCUFLAG_AUTOVOICE)
414 #define CUSetQuiet(x) ((x)->flags |= QCUFLAG_QUIET)
415 #define CUSetSpamCon(x) ((x)->flags |= QCUFLAG_SPAMCON)
416 #define CUSetTopic(x) ((x)->flags |= QCUFLAG_TOPIC)
417 #define CUSetHideWelcome(x) ((x)->flags |= QCUFLAG_HIDEWELCOME)
418 #define CUSetKnown(x) ((x)->flags |= QCUFLAG_KNOWN)
419 #define CUSetAutoInvite(x) ((x)->flags |= QCUFLAG_AUTOINVITE)
420
421 #define CUClearOwner(x) ((x)->flags &= ~QCUFLAG_OWNER)
422 #define CUClearMaster(x) ((x)->flags &= ~QCUFLAG_MASTER)
423 #define CUClearOp(x) ((x)->flags &= ~QCUFLAG_OP)
424 #define CUClearVoice(x) ((x)->flags &= ~QCUFLAG_VOICE)
425 #define CUClearAutoOp(x) ((x)->flags &= ~QCUFLAG_AUTOOP)
426 #define CUClearBanned(x) ((x)->flags &= ~QCUFLAG_BANNED)
427 #define CUClearDeny(x) ((x)->flags &= ~QCUFLAG_DENY)
428 #define CUClearAutoVoice(x) ((x)->flags &= ~QCUFLAG_AUTOVOICE)
429 #define CUClearQuiet(x) ((x)->flags &= ~QCUFLAG_QUIET)
430 #define CUClearSpamCon(x) ((x)->flags &= ~QCUFLAG_SPAMCON)
431 #define CUClearTopic(x) ((x)->flags &= ~QCUFLAG_TOPIC)
432 #define CUClearHideWelcome(x) ((x)->flags &= ~QCUFLAG_HIDEWELCOME)
433 #define CUClearKnown(x) ((x)->flags &= ~QCUFLAG_KNOWN)
434 #define CUClearAutoInvite(x) ((x)->flags &= ~QCUFLAG_AUTOINVITE)
435
436 #define QCSTAT_OPCHECK 0x0001 /* Do op check */
437 #define QCSTAT_MODECHECK 0x0002 /* Do mode check */
438 #define QCSTAT_BANCHECK 0x0004 /* Do ban check */
439
440 #define QUSTAT_DEAD 0x8000 /* User has been deleted.. */
441
442 #define QCMD_SECURE 0x0001 /* Must use "user@server" to use this command */
443 #define QCMD_AUTHED 0x0002 /* Only available to authed users */
444 #define QCMD_NOTAUTHED 0x0004 /* Only available to NON-authed users */
445
446 #define QCMD_HELPER 0x0010 /* Only available to helpers */
447 #define QCMD_OPER 0x0020 /* Only available to opers */
448 #define QCMD_ADMIN 0x0040 /* Only available to admins */
449 #define QCMD_DEV 0x0080 /* Only available to developers */
450
451 #define QCMD_ALIAS 0x0100 /* Don't list on SHOWCOMMANDS */
452
453 #define CS_INIT_DB 0x1 /* Loading database.. */
454 #define CS_INIT_NOUSER 0x2 /* Loaded DB, waiting for user to be created */
455 #define CS_INIT_READY 0x3 /* Ready for action! */
456
457 struct regchanuser;
458 struct reguser;
459
460 /* "Q" ban */
461 typedef struct regban {
462 #ifdef CS_PARANOID
463 unsigned int regchanban_magic;
464 #endif
465 unsigned int ID; /* ID in the database */
466 struct chanban *cbp; /* Standard chanban struct */
467 unsigned int setby; /* Who set the ban */
468 time_t expiry; /* When the ban expires */
469 sstring *reason; /* Reason to attach to related kicks */
470 struct regban *next; /* Next ban on this channel */
471 } regban;
472
473 /* Registered channel */
474 typedef struct regchan {
475 #ifdef CS_PARANOID
476 unsigned int regchan_magic;
477 #endif
478 unsigned int ID; /* Unique number from database */
479 chanindex *index; /* Pointer to the channel index record */
480 time_t ltimestamp; /* The last timestamp we saw on this channel */
481
482 flag_t flags; /* Chanflags */
483 flag_t status; /* Runtime status codes */
484 flag_t forcemodes; /* Forced modes */
485 flag_t denymodes; /* Denied modes */
486
487 short limit; /* Limit to enforce if +l is set */
488 short autolimit; /* How many slots to leave when autolimiting */
489 short banstyle; /* Ban style for +b type bans */
490
491 time_t created; /* When the service was added */
492 time_t lastactive; /* When the channel was last "active" */
493 time_t statsreset; /* When the users stats were last reset */
494 time_t ostatsreset; /* When the oper stats were last reset */
495 time_t banduration; /* How long to remove bans after (0=don't) */
496 time_t autoupdate; /* When the autolimit next needs checking */
497 time_t lastbancheck; /* Timestamp of last ban check */
498 time_t lastcountersync; /* When the counters were last synced.. */
499 time_t lastpart; /* When the last user left the channel */
500
501 unsigned int founder; /* founder */
502 unsigned int addedby; /* oper adding chan */
503 unsigned int suspendby; /* who suspended chan */
504
505 short chantype; /* What "type" the channel is */
506
507 unsigned int totaljoins; /* Total joins since created */
508 unsigned int tripjoins; /* Total joins since last stats reset */
509 unsigned int otripjoins; /* Total joins since last oper stats reset */
510 unsigned int maxusers; /* Max users since created */
511 unsigned int tripusers; /* Max users since last stats reset */
512 unsigned int otripusers; /* Max users since last oper stats reset */
513
514 sstring *welcome; /* Welcome message */
515 sstring *topic; /* "default" topic set by settopic */
516 sstring *key; /* Key as enforced by +k */
517 sstring *suspendreason; /* Suspend reason */
518 sstring *comment; /* Oper-settable channel comment */
519
520 void *checksched; /* Handle for channel check schedule */
521
522 struct regchanuser *regusers[REGCHANUSERHASHSIZE];
523 struct regban *bans; /* List of bans on the channel */
524 } regchan;
525
526 /* Little list thing: which network users are authed
527 * as this user */
528 typedef struct nicklist {
529 nick *np;
530 struct nicklist *next;
531 } nicklist;
532
533 /* Registered user */
534 typedef struct reguser {
535 #ifdef CS_PARANOID
536 unsigned int reguser_magic;
537 #endif
538
539 unsigned int ID; /* From the database */
540
541 char username[NICKLEN+1];
542
543 time_t created;
544 time_t lastauth;
545 time_t lastemailchange;
546
547 flag_t flags; /* user flags */
548 flag_t status; /* runtime status */
549 short languageid; /* what language to speak to the user */
550
551 unsigned int suspendby; /* Userid of oper who suspended this user */
552 time_t suspendexp; /* Expiry date of suspension */
553
554 char password[PASSLEN+1];
555 char masterpass[PASSLEN+1];
556
557 sstring *email; /* Registered e-mail */
558 sstring *lastuserhost; /* Last user@host */
559 sstring *suspendreason; /* Why the account is suspended */
560 sstring *comment; /* Oper-settable user comment */
561 sstring *info; /* User-settable info line */
562
563 struct regchanuser *knownon; /* Which channels this user is known on */
564
565 struct nicklist *nicks; /* Which nicks are authed as this user */
566
567 /* These fields are for the nick protection system */
568 void *checkshd; /* When we're going to check for an imposter */
569 int stealcount; /* How many times we've had to free the nick up */
570 nick *fakeuser; /* If we had to "take" the nick, here's the pointer */
571
572 struct reguser *nextbyname;
573 struct reguser *nextbyID;
574 } reguser;
575
576 /* Registered channel user */
577 typedef struct regchanuser {
578 #ifdef CS_PARANOID
579 unsigned int regchanuser_magic;
580 #endif
581 struct reguser *user;
582 struct regchan *chan;
583 flag_t flags;
584 time_t changetime; /* Timestamp of last "significant" change */
585 time_t usetime; /* Timestamp of last use */
586 sstring *info; /* User-settable info line */
587 struct regchanuser *nextbyuser;
588 struct regchanuser *nextbychan;
589 } regchanuser;
590
591 typedef struct cslang {
592 char code[3];
593 sstring *name;
594 } cslang;
595
596 typedef struct cmdsummary {
597 sstring *def;
598 sstring *bylang[MAXLANG];
599 } cmdsummary;
600
601 typedef struct activeuser {
602 #ifdef CS_PARANOID
603 unsigned int activeuser_magic;
604 #endif
605 reguser* rup; /* pointer to auth data */
606 int authattempts; /* number of times user has attempted to auth */
607 struct activeuser *next; /* purely for keeping track of free, but not free'd structures */
608 } activeuser;
609
610 #ifdef CS_PARANOID
611
612 #define REGUSERMAGIC 0x4d42de03
613 #define REGCHANMAGIC 0x5bf2aa30
614 #define REGCHANUSERMAGIC 0x19628b63
615 #define REGCHANBANMAGIC 0x5a6f555a
616 #define ACTIVEUSERMAGIC 0x897f98a0
617
618 #define verifyreguser(x) assert((x)->reguser_magic == REGUSERMAGIC)
619 #define verifyregchan(x) assert((x)->regchan_magic == REGCHANMAGIC)
620 #define verifyregchanuser(x) assert((x)->regchanuser_magic == REGCHANUSERMAGIC)
621 #define verifyregchanban(x) assert((x)->regchanban_magic == REGCHANBANMAGIC)
622 #define verifyactiveuser(x) assert((x)->activeuser_magic == ACTIVEUSERMAGIC)
623
624 #define tagreguser(x) ((x)->reguser_magic = REGUSERMAGIC)
625 #define tagregchan(x) ((x)->regchan_magic = REGCHANMAGIC)
626 #define tagregchanuser(x) ((x)->regchanuser_magic = REGCHANUSERMAGIC)
627 #define tagregchanban(x) ((x)->regchanban_magic = REGCHANBANMAGIC)
628 #define tagactiveuser(x) ((x)->activeuser_magic = ACTIVEUSERMAGIC)
629
630 #else
631
632 #define verifyreguser(x)
633 #define verifyregchan(x)
634 #define verifyregchanuser(x)
635 #define verifyregchanban(x)
636 #define verifyactiveuser(x)
637
638 #define tagreguser(x)
639 #define tagregchan(x)
640 #define tagregchanuser(x)
641 #define tagregchanban(x)
642 #define tagactiveuser(x)
643
644 #endif
645
646 #define getactiveuserfromnick(x) ((activeuser*)(x)->exts[chanservnext])
647 #define getreguserfromnick(x) (getactiveuserfromnick(x)?getactiveuserfromnick(x)->rup:NULL)
648
649 /* Global variables for chanserv module */
650 extern unsigned int lastuserID;
651 extern unsigned int lastchannelID;
652 extern unsigned int lastbanID;
653
654 extern int chanserv_init_status;
655 extern int chanservdb_ready;
656
657 extern reguser *regusernicktable[REGUSERHASHSIZE];
658 extern reguser *deadusers;
659
660 extern nick *chanservnick;
661 extern int chanservext;
662 extern int chanservnext;
663 extern int chanservaext;
664
665 extern cslang *cslanguages[MAXLANG];
666 extern unsigned int cslangcount;
667
668 extern sstring *csmessages[MAXLANG][MAXMESSAGES];
669 extern char *defaultmessages[MAXMESSAGES];
670
671 extern const flag rcflags[];
672 extern const flag rcuflags[];
673 extern const flag ruflags[];
674
675 extern CommandTree *cscommands;
676
677 extern sstring **chantypes;
678
679 /* Function prototypes */
680
681 /* chanserv.c */
682 void chanserv_finalinit();
683
684 /* chanservalloc.c */
685 void chanservallocinit();
686 void csfreeall();
687 regchan *getregchan();
688 void freeregchan(regchan *rcp);
689 reguser *getreguser();
690 void freereguser(reguser *rup);
691 regchanuser *getregchanuser();
692 void freeregchanuser(regchanuser *rcup);
693 nicklist *getnicklist();
694 void freenicklist(nicklist *nlp);
695 regban *getregban();
696 void freeregban(regban *rbp);
697 activeuser *getactiveuser();
698 void freeactiveuser(activeuser *aup);
699
700 /* chanservhash.c */
701 void chanservhashinit();
702 void addregusertohash(reguser *rup);
703 reguser *findreguserbyID(unsigned int ID);
704 reguser *findreguserbynick(const char *nick);
705 reguser *findreguser(nick *sender, const char *str);
706 void removereguserfromhash(reguser *rup);
707 void addregchantohash(regchan *rcp);
708 regchan *findregchanbyID(unsigned int ID);
709 regchan *findregchanbyname(const char *name);
710 void removeregchanfromhash(regchan *rcp);
711 void addregusertochannel(regchanuser *rcup);
712 regchanuser *findreguseronchannel(regchan *rcp, reguser *rup);
713 void delreguserfromchannel(regchan *rcp, reguser *rup);
714
715 /* chanservdb.c */
716 int chanservdbinit();
717 void loadmessages();
718 void loadcommandsummary(Command *cmd);
719 void chanservdbclose();
720 void csdb_updatetopic(regchan *rcp);
721 void csdb_updatelastjoin(regchanuser *rcup);
722 void csdb_updateauthinfo(reguser *rup);
723 void csdb_updatechannel(regchan *rcp);
724 void csdb_createchannel(regchan *rcp);
725 void csdb_deletechannel(regchan *rcp);
726 void csdb_deleteuser(reguser *rup);
727 void csdb_updatechannelcounters(regchan *rcp);
728 void csdb_updatechanneltimestamp(regchan *rcp);
729 void csdb_updatechanuser(regchanuser *rcup);
730 void csdb_createchanuser(regchanuser *rcup);
731 void csdb_deletechanuser(regchanuser *rcup);
732 void csdb_createuser(reguser *rup);
733 void csdb_updateuser(reguser *rup);
734 void csdb_createban(regchan *rcp, regban *rbp);
735 void csdb_deleteban(regban *rbp);
736 char *csdb_gethelpstr(char *command, int language);
737 void csdb_createmail(reguser *rup, int type);
738 void csdb_dohelp(nick *np, Command *cmd);
739
740 /* chanservuser.c */
741 void chanservreguser(void *arg);
742 void chanservjoinchan(channel *cp);
743 void chanservsendmessage(nick *np, char *message, ... );
744 void chanservwallmessage(char *message, ... );
745 void chanservcommandinit();
746 void chanservcommandclose();
747 void chanservstdmessage(nick *np, int messageid, ... );
748 void chanservaddcommand(char *command, int flags, int maxparams, CommandHandler handler, char *description);
749 void chanservremovecommand(char *command, CommandHandler handler);
750 void chanservaddctcpcommand(char *command, CommandHandler hander);
751 void chanservremovectcpcommand(char *command, CommandHandler handler);
752 void chanservkillstdmessage(nick *target, int messageid, ... );
753 int checkmasterpassword(reguser *rup, const char *pass);
754 int checkpassword(reguser *rup, const char *pass);
755 int setmasterpassword(reguser *rup, const char *pass);
756 int setpassword(reguser *rup, const char *pass);
757 /*reguser *getreguserfromnick(nick *np);
758 activeuser *getactiveuserfromnick(nick *np);*/
759 void cs_checknick(nick *np);
760 void cs_checkchanmodes(channel *cp);
761 void cs_docheckchanmodes(channel *cp, modechanges *changes);
762 void cs_docheckopvoice(channel *cp, modechanges *changes);
763 void cs_checkbans(channel *cp);
764 void cs_schedupdate(chanindex *cip, int mintime, int maxtime);
765 void cs_timerfunc(void *arg);
766 void cs_removechannel(regchan *rcp);
767 void cs_doallautomodes(nick *np);
768 void cs_checknickbans(nick *np);
769 void cs_setregban(chanindex *cip, regban *rbp);
770 int cs_bancheck(nick *np, channel *cp);
771 void cs_banuser(modechanges *changes, chanindex *cip, nick *np, const char *reason);
772 void cs_removeuser(reguser *rup);
773
774 /* chanservstdcmds.c */
775 int cs_doshowcommands(void *source, int cargc, char **cargv);
776 int cs_dohelp(void *source, int cargc, char **cargv);
777 int cs_doquit(void *source, int cargc, char **cargv);
778 int cs_dorename(void *source, int cargc, char **cargv);
779 int cs_dorehash(void *source, int cargc, char **cargv);
780 int cs_doctcpping(void *source, int cargc, char **cargv);
781 int cs_doctcpversion(void *source, int cargc, char **cargv);
782 int cs_doctcpgender(void *source, int cargc, char **cargv);
783
784 /* chanservnetevents.c */
785 void cs_handlenick(int hooknum, void *arg);
786 void cs_handlesethost(int hooknum, void *arg);
787 void cs_handlelostnick(int hooknum, void *arg);
788 void cs_handlenewchannel(int hooknum, void *arg);
789 void cs_handlelostchannel(int hooknum, void *arg);
790 void cs_handlejoin(int hooknum, void *arg);
791 void cs_handlemodechange(int hooknum, void *arg);
792 void cs_handleburst(int hooknum, void *arg);
793 void cs_handletopicchange(int hooknum, void *arg);
794 void cs_handleopchange(int hooknum, void *arg);
795 void cs_handlenewban(int hooknum, void *arg);
796 void cs_handlechanlostuser(int hooknum, void *arg);
797
798 /* chanservmessages.c */
799 void initmessages();
800
801 /* chanservprivs.c */
802 int cs_privcheck(int privnum, nick *np);
803 chanindex *cs_checkaccess(nick *np, const char *chan, unsigned int flags, chanindex *cip, const char *cmdname, int priv, int quiet);
804
805 /* chanservlog.c */
806 void cs_initlog();
807 void cs_closelog();
808 void cs_log(nick *np, char *event, ...);
809
810 /* chanservdump.c */
811 int dumplastjoindata(const char *filename);
812 int readlastjoindata(const char *filename);
813
814 /* chanservschedule.c */
815 void chanservdgline(void *arg);
816
817 /* authlib.c */
818 int csa_checkeboy(nick *sender, char *eboy);
819 void csa_createrandompw(char *pw, int n);
820 int csa_checkthrottled(nick *sender, reguser *rup, char *s);
821
822 #endif