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