1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
.TH "channels.h" 3 "15 Dec 2005" "Version 1.0Betareleases" "InspIRCd" \" -*- nroff -*-
.ad l
.nh
.SH NAME
channels.h \-
.SH SYNOPSIS
.br
.PP
\fC#include 'inspircd_config.h'\fP
.br
\fC#include 'base.h'\fP
.br
\fC#include <time.h>\fP
.br
\fC#include <vector>\fP
.br
\fC#include <string>\fP
.br
.SS "Classes"
.in +1c
.ti -1c
.RI "class \fBHostItem\fP"
.br
.RI "\fIHolds an entry for a ban list, exemption list, or invite list. \fP"
.ti -1c
.RI "class \fBBanItem\fP"
.br
.RI "\fIA subclass of \fBHostItem\fP designed to hold channel bans (+b). \fP"
.ti -1c
.RI "class \fBExemptItem\fP"
.br
.RI "\fIA subclass of \fBHostItem\fP designed to hold channel exempts (+e). \fP"
.ti -1c
.RI "class \fBInviteItem\fP"
.br
.RI "\fIA subclass of \fBHostItem\fP designed to hold channel invites (+I). \fP"
.ti -1c
.RI "class \fBModeParameter\fP"
.br
.RI "\fIHolds a custom parameter to a module-defined channel mode e.g. \fP"
.ti -1c
.RI "class \fBchanrec\fP"
.br
.RI "\fIHolds all relevent information for a channel. \fP"
.ti -1c
.RI "class \fBucrec\fP"
.br
.RI "\fIHolds a user's modes on a channel This class associates a users privilages with a channel by creating a pointer link between a userrec and chanrec class. \fP"
.in -1c
.SS "Defines"
.in +1c
.ti -1c
.RI "#define \fBCM_TOPICLOCK\fP 1"
.br
.ti -1c
.RI "#define \fBCM_NOEXTERNAL\fP 2"
.br
.ti -1c
.RI "#define \fBCM_INVITEONLY\fP 4"
.br
.ti -1c
.RI "#define \fBCM_MODERATED\fP 8"
.br
.ti -1c
.RI "#define \fBCM_SECRET\fP 16"
.br
.ti -1c
.RI "#define \fBCM_PRIVATE\fP 32"
.br
.ti -1c
.RI "#define \fBUCMODE_OP\fP 1"
.br
.ti -1c
.RI "#define \fBUCMODE_VOICE\fP 2"
.br
.ti -1c
.RI "#define \fBUCMODE_HOP\fP 4"
.br
.ti -1c
.RI "#define \fBUCMODE_PROTECT\fP 8"
.br
.ti -1c
.RI "#define \fBUCMODE_FOUNDER\fP 16"
.br
.in -1c
.SS "Typedefs"
.in +1c
.ti -1c
.RI "typedef std::vector< \fBBanItem\fP > \fBBanList\fP"
.br
.RI "\fIHolds a complete ban list. \fP"
.ti -1c
.RI "typedef std::vector< \fBExemptItem\fP > \fBExemptList\fP"
.br
.RI "\fIHolds a complete exempt list. \fP"
.ti -1c
.RI "typedef std::vector< \fBInviteItem\fP > \fBInviteList\fP"
.br
.RI "\fIHolds a complete invite list. \fP"
.in -1c
.SS "Functions"
.in +1c
.ti -1c
.RI "\fBchanrec\fP * \fBadd_channel\fP (\fBuserrec\fP *user, const char *cn, const char *key, bool override)"
.br
.ti -1c
.RI "\fBchanrec\fP * \fBdel_channel\fP (\fBuserrec\fP *user, const char *cname, const char *reason, bool local)"
.br
.ti -1c
.RI "void \fBkick_channel\fP (\fBuserrec\fP *src, \fBuserrec\fP *user, \fBchanrec\fP *Ptr, char *reason)"
.br
.in -1c
.SH "Define Documentation"
.PP
.SS "#define CM_INVITEONLY 4"
.PP
Definition at line 28 of file channels.h.
.PP
Referenced by add_channel().
.SS "#define CM_MODERATED 8"
.PP
Definition at line 29 of file channels.h.
.SS "#define CM_NOEXTERNAL 2"
.PP
Definition at line 27 of file channels.h.
.PP
Referenced by add_channel().
.SS "#define CM_PRIVATE 32"
.PP
Definition at line 31 of file channels.h.
.SS "#define CM_SECRET 16"
.PP
Definition at line 30 of file channels.h.
.SS "#define CM_TOPICLOCK 1"
.PP
Definition at line 26 of file channels.h.
.PP
Referenced by add_channel().
.SS "#define UCMODE_FOUNDER 16"
.PP
Definition at line 236 of file channels.h.
.SS "#define UCMODE_HOP 4"
.PP
Definition at line 234 of file channels.h.
.SS "#define UCMODE_OP 1"
.PP
Definition at line 232 of file channels.h.
.PP
Referenced by ForceChan().
.SS "#define UCMODE_PROTECT 8"
.PP
Definition at line 235 of file channels.h.
.SS "#define UCMODE_VOICE 2"
.PP
Definition at line 233 of file channels.h.
.SH "Typedef Documentation"
.PP
.SS "typedef std::vector<\fBBanItem\fP> \fBBanList\fP"
.PP
Holds a complete ban list.
.PP
Definition at line 89 of file channels.h.
.SS "typedef std::vector<\fBExemptItem\fP> \fBExemptList\fP"
.PP
Holds a complete exempt list.
.PP
Definition at line 93 of file channels.h.
.SS "typedef std::vector<\fBInviteItem\fP> \fBInviteList\fP"
.PP
Holds a complete invite list.
.PP
Definition at line 97 of file channels.h.
.SH "Function Documentation"
.PP
.SS "\fBchanrec\fP* add_channel (\fBuserrec\fP * user, const char * cn, const char * key, bool override)"
.PP
Definition at line 195 of file channels.cpp.
.PP
References chanrec::bans, chanrec::binarymodes, chanlist, userrec::chans, CM_INVITEONLY, CM_NOEXTERNAL, CM_TOPICLOCK, DEBUG, DEFAULT, connection::fd, FindChan(), ForceChan(), FOREACH_RESULT, userrec::GetFullHost(), has_channel(), userrec::IsInvited(), chanrec::key, chanrec::limit, log(), userrec::modes, chanrec::name, userrec::nick, userrec::RemoveInvite(), TIME, and WriteServ().
.PP
Referenced by Server::JoinUserToChannel().
.PP
.nf
196 {
197 if ((!user) || (!cn))
198 {
199 log(DEFAULT,'*** BUG *** add_channel was given an invalid parameter');
200 return 0;
201 }
202
203 int created = 0;
204 char cname[MAXBUF];
205 int MOD_RESULT = 0;
206 strncpy(cname,cn,CHANMAX);
207
208 log(DEBUG,'add_channel: %s %s',user->nick,cname);
209
210 chanrec* Ptr = FindChan(cname);
211
212 if (!Ptr)
213 {
214 if (user->fd > -1)
215 {
216 MOD_RESULT = 0;
217 FOREACH_RESULT(OnUserPreJoin(user,NULL,cname));
218 if (MOD_RESULT == 1)
219 return NULL;
220 }
221 /* create a new one */
222 chanlist[cname] = new chanrec();
223 strlcpy(chanlist[cname]->name, cname,CHANMAX);
224 chanlist[cname]->binarymodes = CM_TOPICLOCK | CM_NOEXTERNAL;
225 chanlist[cname]->created = TIME;
226 strcpy(chanlist[cname]->topic, '');
227 strncpy(chanlist[cname]->setby, user->nick,NICKMAX);
228 chanlist[cname]->topicset = 0;
229 Ptr = chanlist[cname];
230 log(DEBUG,'add_channel: created: %s',cname);
231 /* set created to 2 to indicate user
232 * is the first in the channel
233 * and should be given ops */
234 created = 2;
235 }
236 else
237 {
238 /* Already on the channel */
239 if (has_channel(user,Ptr))
240 return NULL;
241
242 // remote users are allowed us to bypass channel modes
243 // and bans (used by servers)
244 if (user->fd > -1)
245 {
246 MOD_RESULT = 0;
247 FOREACH_RESULT(OnUserPreJoin(user,Ptr,cname));
248 if (MOD_RESULT == 1)
249 {
250 return NULL;
251 }
252 else
253 {
254 if (*Ptr->key)
255 {
256 MOD_RESULT = 0;
257 FOREACH_RESULT(OnCheckKey(user, Ptr, key ? key : ''));
258 if (!MOD_RESULT)
259 {
260 if (!key)
261 {
262 log(DEBUG,'add_channel: no key given in JOIN');
263 WriteServ(user->fd,'475 %s %s :Cannot join channel (Requires key)',user->nick, Ptr->name);
264 return NULL;
265 }
266 else
267 {
268 if (strcasecmp(key,Ptr->key))
269 {
270 log(DEBUG,'add_channel: bad key given in JOIN');
271 WriteServ(user->fd,'475 %s %s :Cannot join channel (Incorrect key)',user->nick, Ptr->name);
272 return NULL;
273 }
274 }
275 }
276 }
277 if (Ptr->binarymodes & CM_INVITEONLY)
278 {
279 MOD_RESULT = 0;
280 FOREACH_RESULT(OnCheckInvite(user, Ptr));
281 if (!MOD_RESULT)
282 {
283 log(DEBUG,'add_channel: channel is +i');
284 if (user->IsInvited(Ptr->name))
285 {
286 /* user was invited to channel */
287 /* there may be an optional channel NOTICE here */
288 }
289 else
290 {
291 WriteServ(user->fd,'473 %s %s :Cannot join channel (Invite only)',user->nick, Ptr->name);
292 return NULL;
293 }
294 }
295 user->RemoveInvite(Ptr->name);
296 }
297 if (Ptr->limit)
298 {
299 MOD_RESULT = 0;
300 FOREACH_RESULT(OnCheckLimit(user, Ptr));
301 if (!MOD_RESULT)
302 {
303 if (usercount(Ptr) >= Ptr->limit)
304 {
305 WriteServ(user->fd,'471 %s %s :Cannot join channel (Channel is full)',user->nick, Ptr->name);
306 return NULL;
307 }
308 }
309 }
310 if (Ptr->bans.size())
311 {
312 log(DEBUG,'add_channel: about to walk banlist');
313 MOD_RESULT = 0;
314 FOREACH_RESULT(OnCheckBan(user, Ptr));
315 if (!MOD_RESULT)
316 {
317 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
318 {
319 if (match(user->GetFullHost(),i->data))
320 {
321 WriteServ(user->fd,'474 %s %s :Cannot join channel (You're banned)',user->nick, Ptr->name);
322 return NULL;
323 }
324 }
325 }
326 }
327 }
328 }
329 else
330 {
331 log(DEBUG,'Overridden checks');
332 }
333 created = 1;
334 }
335
336 log(DEBUG,'Passed channel checks');
337
338 for (unsigned int index =0; index < user->chans.size(); index++)
339 {
340 if (user->chans[index].channel == NULL)
341 {
342 return ForceChan(Ptr,user->chans[index],user,created);
343 }
344 }
345 /* XXX: If the user is an oper here, we can just extend their user->chans vector by one
346 * and put the channel in here. Same for remote users which are not bound by
347 * the channel limits. Otherwise, nope, youre boned.
348 */
349 if (user->fd < 0)
350 {
351 ucrec a;
352 chanrec* c = ForceChan(Ptr,a,user,created);
353 user->chans.push_back(a);
354 return c;
355 }
356 else if (strchr(user->modes,'o'))
357 {
358 /* Oper allows extension up to the OPERMAXCHANS value */
359 if (user->chans.size() < OPERMAXCHANS)
360 {
361 ucrec a;
362 chanrec* c = ForceChan(Ptr,a,user,created);
363 user->chans.push_back(a);
364 return c;
365 }
366 }
367 log(DEBUG,'add_channel: user channel max exceeded: %s %s',user->nick,cname);
368 WriteServ(user->fd,'405 %s %s :You are on too many channels',user->nick, cname);
369 return NULL;
370 }
.fi
.PP
.SS "\fBchanrec\fP* del_channel (\fBuserrec\fP * user, const char * cname, const char * reason, bool local)"
.PP
Definition at line 401 of file channels.cpp.
.PP
References chanlist, userrec::chans, DEBUG, DEFAULT, chanrec::DelUser(), FindChan(), FOREACH_MOD, log(), chanrec::name, userrec::nick, and WriteChannel().
.PP
Referenced by Server::PartUserFromChannel().
.PP
.nf
402 {
403 if ((!user) || (!cname))
404 {
405 log(DEFAULT,'*** BUG *** del_channel was given an invalid parameter');
406 return NULL;
407 }
408
409 chanrec* Ptr = FindChan(cname);
410
411 if (!Ptr)
412 return NULL;
413
414 FOREACH_MOD OnUserPart(user,Ptr);
415 log(DEBUG,'del_channel: removing: %s %s',user->nick,Ptr->name);
416
417 for (unsigned int i =0; i < user->chans.size(); i++)
418 {
419 /* zap it from the channel list of the user */
420 if (user->chans[i].channel == Ptr)
421 {
422 if (reason)
423 {
424 WriteChannel(Ptr,user,'PART %s :%s',Ptr->name, reason);
425 }
426 else
427 {
428 WriteChannel(Ptr,user,'PART :%s',Ptr->name);
429 }
430 user->chans[i].uc_modes = 0;
431 user->chans[i].channel = NULL;
432 log(DEBUG,'del_channel: unlinked: %s %s',user->nick,Ptr->name);
433 break;
434 }
435 }
436
437 Ptr->DelUser((char*)user);
438
439 /* if there are no users left on the channel */
440 if (!usercount(Ptr))
441 {
442 chan_hash::iterator iter = chanlist.find(Ptr->name);
443
444 log(DEBUG,'del_channel: destroying channel: %s',Ptr->name);
445
446 /* kill the record */
447 if (iter != chanlist.end())
448 {
449 log(DEBUG,'del_channel: destroyed: %s',Ptr->name);
450 delete Ptr;
451 chanlist.erase(iter);
452 }
453 }
454
455 return NULL;
456 }
.fi
.PP
.SS "void kick_channel (\fBuserrec\fP * src, \fBuserrec\fP * user, \fBchanrec\fP * Ptr, char * reason)"
.PP
Definition at line 459 of file channels.cpp.
.PP
References AC_KICK, ACR_DEFAULT, ACR_DENY, chanlist, userrec::chans, cstatus(), DEBUG, DEFAULT, chanrec::DelUser(), connection::fd, FOREACH_MOD, FOREACH_RESULT, has_channel(), is_uline(), log(), chanrec::name, userrec::nick, userrec::server, STATUS_HOP, WriteChannel(), and WriteServ().
.PP
.nf
460 {
461 if ((!src) || (!user) || (!Ptr) || (!reason))
462 {
463 log(DEFAULT,'*** BUG *** kick_channel was given an invalid parameter');
464 return;
465 }
466
467 if ((!Ptr) || (!user) || (!src))
468 {
469 return;
470 }
471
472 log(DEBUG,'kick_channel: removing: %s %s %s',user->nick,Ptr->name,src->nick);
473
474 if (!has_channel(user,Ptr))
475 {
476 WriteServ(src->fd,'441 %s %s %s :They are not on that channel',src->nick, user->nick, Ptr->name);
477 return;
478 }
479
480 int MOD_RESULT = 0;
481 FOREACH_RESULT(OnAccessCheck(src,user,Ptr,AC_KICK));
482 if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
483 return;
484
485 if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
486 {
487 if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr)))
488 {
489 if (cstatus(src,Ptr) == STATUS_HOP)
490 {
491 WriteServ(src->fd,'482 %s %s :You must be a channel operator',src->nick, Ptr->name);
492 }
493 else
494 {
495 WriteServ(src->fd,'482 %s %s :You must be at least a half-operator to change modes on this channel',src->nick, Ptr->name);
496 }
497
498 return;
499 }
500 }
501
502 if (!is_uline(src->server))
503 {
504 MOD_RESULT = 0;
505 FOREACH_RESULT(OnUserPreKick(src,user,Ptr,reason));
506 if (MOD_RESULT)
507 return;
508 }
509
510 FOREACH_MOD OnUserKick(src,user,Ptr,reason);
511
512 for (unsigned int i =0; i < user->chans.size(); i++)
513 {
514 /* zap it from the channel list of the user */
515 if (user->chans[i].channel)
516 if (!strcasecmp(user->chans[i].channel->name,Ptr->name))
517 {
518 WriteChannel(Ptr,src,'KICK %s %s :%s',Ptr->name, user->nick, reason);
519 user->chans[i].uc_modes = 0;
520 user->chans[i].channel = NULL;
521 log(DEBUG,'del_channel: unlinked: %s %s',user->nick,Ptr->name);
522 break;
523 }
524 }
525
526 Ptr->DelUser((char*)user);
527
528 /* if there are no users left on the channel */
529 if (!usercount(Ptr))
530 {
531 chan_hash::iterator iter = chanlist.find(Ptr->name);
532
533 log(DEBUG,'del_channel: destroying channel: %s',Ptr->name);
534
535 /* kill the record */
536 if (iter != chanlist.end())
537 {
538 log(DEBUG,'del_channel: destroyed: %s',Ptr->name);
539 delete Ptr;
540 chanlist.erase(iter);
541 }
542 }
543 }
.fi
.PP
.SH "Author"
.PP
Generated automatically by Doxygen for InspIRCd from the source code.
|