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