00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 static int tcl_chanlist STDVAR
00028 {
00029 char nuh[1024];
00030 int f;
00031 memberlist *m;
00032 struct chanset_t *chan;
00033 struct flag_record plus = { FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0 },
00034 minus = { FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0},
00035 user = { FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0 };
00036
00037 BADARGS(2, 3, " channel ?flags?");
00038
00039 chan = findchan_by_dname(argv[1]);
00040 if (!chan) {
00041 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
00042 return TCL_ERROR;
00043 }
00044 if (argc == 2) {
00045
00046 for (m = chan->channel.member; m && m->nick[0]; m = m->next)
00047 Tcl_AppendElement(irp, m->nick);
00048 return TCL_OK;
00049 }
00050 break_down_flags(argv[2], &plus, &minus);
00051 f = (minus.global || minus.udef_global || minus.chan || minus.udef_chan ||
00052 minus.bot);
00053
00054 if (!plus.global && !plus.udef_global && !plus.chan && !plus.udef_chan &&
00055 !plus.bot && !f)
00056 return TCL_OK;
00057 minus.match = plus.match ^ (FR_AND | FR_OR);
00058
00059 for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
00060 if (!m->user) {
00061 egg_snprintf(nuh, sizeof nuh, "%s!%s", m->nick, m->userhost);
00062 m->user = get_user_by_host(nuh);
00063 }
00064 get_user_flagrec(m->user, &user, argv[1]);
00065 user.match = plus.match;
00066 if (flagrec_eq(&plus, &user)) {
00067 if (!f || !flagrec_eq(&minus, &user))
00068 Tcl_AppendElement(irp, m->nick);
00069 }
00070 }
00071 return TCL_OK;
00072 }
00073
00074 static int tcl_botisop STDVAR
00075 {
00076 struct chanset_t *chan, *thechan = NULL;
00077
00078 BADARGS(1, 2, " ?channel?");
00079
00080 if (argc > 1) {
00081 chan = findchan_by_dname(argv[1]);
00082 thechan = chan;
00083 if (!thechan) {
00084 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00085 return TCL_ERROR;
00086 }
00087 } else
00088 chan = chanset;
00089
00090 while (chan && (thechan == NULL || thechan == chan)) {
00091 if (me_op(chan)) {
00092 Tcl_AppendResult(irp, "1", NULL);
00093 return TCL_OK;
00094 }
00095 chan = chan->next;
00096 }
00097 Tcl_AppendResult(irp, "0", NULL);
00098 return TCL_OK;
00099 }
00100
00101 static int tcl_botishalfop STDVAR
00102 {
00103 struct chanset_t *chan, *thechan = NULL;
00104
00105 BADARGS(1, 2, " ?channel?");
00106
00107 if (argc > 1) {
00108 chan = findchan_by_dname(argv[1]);
00109 thechan = chan;
00110 if (!thechan) {
00111 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00112 return TCL_ERROR;
00113 }
00114 } else
00115 chan = chanset;
00116
00117 while (chan && (thechan == NULL || thechan == chan)) {
00118 if (me_halfop(chan)) {
00119 Tcl_AppendResult(irp, "1", NULL);
00120 return TCL_OK;
00121 }
00122 chan = chan->next;
00123 }
00124 Tcl_AppendResult(irp, "0", NULL);
00125 return TCL_OK;
00126 }
00127
00128 static int tcl_ischanjuped STDVAR
00129 {
00130 struct chanset_t *chan;
00131
00132 BADARGS(2, 2, " channel");
00133
00134 chan = findchan_by_dname(argv[1]);
00135 if (chan == NULL) {
00136 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00137 return TCL_ERROR;
00138 }
00139 if (channel_juped(chan))
00140 Tcl_AppendResult(irp, "1", NULL);
00141 else
00142 Tcl_AppendResult(irp, "0", NULL);
00143 return TCL_OK;
00144 }
00145
00146 static int tcl_botisvoice STDVAR
00147 {
00148 struct chanset_t *chan, *thechan = NULL;
00149 memberlist *mx;
00150
00151 BADARGS(1, 2, " ?channel?");
00152
00153 if (argc > 1) {
00154 chan = findchan_by_dname(argv[1]);
00155 thechan = chan;
00156 if (!thechan) {
00157 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00158 return TCL_ERROR;
00159 }
00160 } else
00161 chan = chanset;
00162
00163 while (chan && (thechan == NULL || thechan == chan)) {
00164 if ((mx = ismember(chan, botname)) && chan_hasvoice(mx)) {
00165 Tcl_AppendResult(irp, "1", NULL);
00166 return TCL_OK;
00167 }
00168 chan = chan->next;
00169 }
00170 Tcl_AppendResult(irp, "0", NULL);
00171 return TCL_OK;
00172 }
00173
00174 static int tcl_botonchan STDVAR
00175 {
00176 struct chanset_t *chan, *thechan = NULL;
00177
00178 BADARGS(1, 2, " ?channel?");
00179
00180 if (argc > 1) {
00181 chan = findchan_by_dname(argv[1]);
00182 thechan = chan;
00183 if (!thechan) {
00184 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00185 return TCL_ERROR;
00186 }
00187 } else
00188 chan = chanset;
00189
00190 while (chan && (thechan == NULL || thechan == chan)) {
00191 if (ismember(chan, botname)) {
00192 Tcl_AppendResult(irp, "1", NULL);
00193 return TCL_OK;
00194 }
00195 chan = chan->next;
00196 }
00197 Tcl_AppendResult(irp, "0", NULL);
00198 return TCL_OK;
00199 }
00200
00201 static int tcl_isop STDVAR
00202 {
00203 struct chanset_t *chan, *thechan = NULL;
00204 memberlist *mx;
00205
00206 BADARGS(2, 3, " nick ?channel?");
00207
00208 if (argc > 2) {
00209 chan = findchan_by_dname(argv[2]);
00210 thechan = chan;
00211 if (!thechan) {
00212 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00213 return TCL_ERROR;
00214 }
00215 } else
00216 chan = chanset;
00217
00218 while (chan && (thechan == NULL || thechan == chan)) {
00219 if ((mx = ismember(chan, argv[1])) && chan_hasop(mx)) {
00220 Tcl_AppendResult(irp, "1", NULL);
00221 return TCL_OK;
00222 }
00223 chan = chan->next;
00224 }
00225 Tcl_AppendResult(irp, "0", NULL);
00226 return TCL_OK;
00227 }
00228
00229 static int tcl_ishalfop STDVAR
00230 {
00231 struct chanset_t *chan, *thechan = NULL;
00232 memberlist *mx;
00233
00234 BADARGS(2, 3, " nick ?channel?");
00235
00236 if (argc > 2) {
00237 chan = findchan_by_dname(argv[2]);
00238 thechan = chan;
00239 if (!thechan) {
00240 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00241 return TCL_ERROR;
00242 }
00243 } else
00244 chan = chanset;
00245
00246 while (chan && (thechan == NULL || thechan == chan)) {
00247 if ((mx = ismember(chan, argv[1])) && chan_hashalfop(mx)) {
00248 Tcl_AppendResult(irp, "1", NULL);
00249 return TCL_OK;
00250 }
00251 chan = chan->next;
00252 }
00253 Tcl_AppendResult(irp, "0", NULL);
00254 return TCL_OK;
00255 }
00256
00257 static int tcl_isvoice STDVAR
00258 {
00259 struct chanset_t *chan, *thechan = NULL;
00260 memberlist *mx;
00261
00262 BADARGS(2, 3, " nick ?channel?");
00263
00264 if (argc > 2) {
00265 chan = findchan_by_dname(argv[2]);
00266 thechan = chan;
00267 if (!thechan) {
00268 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00269 return TCL_ERROR;
00270 }
00271 } else
00272 chan = chanset;
00273
00274 while (chan && (thechan == NULL || thechan == chan)) {
00275 if ((mx = ismember(chan, argv[1])) && chan_hasvoice(mx)) {
00276 Tcl_AppendResult(irp, "1", NULL);
00277 return TCL_OK;
00278 }
00279 chan = chan->next;
00280 }
00281 Tcl_AppendResult(irp, "0", NULL);
00282 return TCL_OK;
00283 }
00284
00285 static int tcl_wasop STDVAR
00286 {
00287 struct chanset_t *chan;
00288 memberlist *mx;
00289
00290 BADARGS(3, 3, " nick channel");
00291
00292 chan = findchan_by_dname(argv[2]);
00293 if (chan == NULL) {
00294 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00295 return TCL_ERROR;
00296 }
00297 if ((mx = ismember(chan, argv[1])) && chan_wasop(mx))
00298 Tcl_AppendResult(irp, "1", NULL);
00299 else
00300 Tcl_AppendResult(irp, "0", NULL);
00301 return TCL_OK;
00302 }
00303
00304 static int tcl_washalfop STDVAR
00305 {
00306 struct chanset_t *chan;
00307 memberlist *mx;
00308
00309 BADARGS(3, 3, " nick channel");
00310
00311 chan = findchan_by_dname(argv[2]);
00312 if (chan == NULL) {
00313 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00314 return TCL_ERROR;
00315 }
00316 if ((mx = ismember(chan, argv[1])) && chan_washalfop(mx))
00317 Tcl_AppendResult(irp, "1", NULL);
00318 else
00319 Tcl_AppendResult(irp, "0", NULL);
00320 return TCL_OK;
00321 }
00322
00323 static int tcl_onchan STDVAR
00324 {
00325 struct chanset_t *chan, *thechan = NULL;
00326
00327 BADARGS(2, 3, " nickname ?channel?");
00328
00329 if (argc > 2) {
00330 chan = findchan_by_dname(argv[2]);
00331 thechan = chan;
00332 if (!thechan) {
00333 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00334 return TCL_ERROR;
00335 }
00336 } else
00337 chan = chanset;
00338
00339 while (chan && (thechan == NULL || thechan == chan)) {
00340 if (ismember(chan, argv[1])) {
00341 Tcl_AppendResult(irp, "1", NULL);
00342 return TCL_OK;
00343 }
00344 chan = chan->next;
00345 }
00346 Tcl_AppendResult(irp, "0", NULL);
00347 return TCL_OK;
00348 }
00349
00350 static int tcl_handonchan STDVAR
00351 {
00352 char nuh[1024];
00353 struct chanset_t *chan, *thechan = NULL;
00354 memberlist *m;
00355
00356 BADARGS(2, 3, " handle ?channel?");
00357
00358 if (argc > 2) {
00359 chan = findchan_by_dname(argv[2]);
00360 thechan = chan;
00361 if (!thechan) {
00362 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00363 return TCL_ERROR;
00364 }
00365 } else
00366 chan = chanset;
00367
00368 while (chan && (thechan == NULL || thechan == chan)) {
00369 for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
00370 if (!m->user) {
00371 egg_snprintf(nuh, sizeof nuh, "%s!%s", m->nick, m->userhost);
00372 m->user = get_user_by_host(nuh);
00373 }
00374 if (m->user && !rfc_casecmp(m->user->handle, argv[1])) {
00375 Tcl_AppendResult(irp, "1", NULL);
00376 return TCL_OK;
00377 }
00378 }
00379 chan = chan->next;
00380 }
00381 Tcl_AppendResult(irp, "0", NULL);
00382 return TCL_OK;
00383 }
00384
00385 static int tcl_ischanban STDVAR
00386 {
00387 struct chanset_t *chan;
00388
00389 BADARGS(3, 3, " ban channel");
00390
00391 chan = findchan_by_dname(argv[2]);
00392 if (chan == NULL) {
00393 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00394 return TCL_ERROR;
00395 }
00396 if (ischanban(chan, argv[1]))
00397 Tcl_AppendResult(irp, "1", NULL);
00398 else
00399 Tcl_AppendResult(irp, "0", NULL);
00400 return TCL_OK;
00401 }
00402
00403 static int tcl_ischanexempt STDVAR
00404 {
00405 struct chanset_t *chan;
00406
00407 BADARGS(3, 3, " exempt channel");
00408
00409 chan = findchan_by_dname(argv[2]);
00410 if (chan == NULL) {
00411 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00412 return TCL_ERROR;
00413 }
00414 if (ischanexempt(chan, argv[1]))
00415 Tcl_AppendResult(irp, "1", NULL);
00416 else
00417 Tcl_AppendResult(irp, "0", NULL);
00418 return TCL_OK;
00419 }
00420
00421 static int tcl_ischaninvite STDVAR
00422 {
00423 struct chanset_t *chan;
00424
00425 BADARGS(3, 3, " invite channel");
00426
00427 chan = findchan_by_dname(argv[2]);
00428 if (chan == NULL) {
00429 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00430 return TCL_ERROR;
00431 }
00432 if (ischaninvite(chan, argv[1]))
00433 Tcl_AppendResult(irp, "1", NULL);
00434 else
00435 Tcl_AppendResult(irp, "0", NULL);
00436 return TCL_OK;
00437 }
00438
00439 static int tcl_getchanhost STDVAR
00440 {
00441 struct chanset_t *chan, *thechan = NULL;
00442 memberlist *m;
00443
00444 BADARGS(2, 3, " nickname ?channel?");
00445
00446 if (argc > 2) {
00447 chan = findchan_by_dname(argv[2]);
00448 thechan = chan;
00449 if (!thechan) {
00450 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00451 return TCL_ERROR;
00452 }
00453 } else
00454 chan = chanset;
00455
00456 while (chan && (thechan == NULL || thechan == chan)) {
00457 m = ismember(chan, argv[1]);
00458 if (m) {
00459 Tcl_AppendResult(irp, m->userhost, NULL);
00460 return TCL_OK;
00461 }
00462 chan = chan->next;
00463 }
00464 return TCL_OK;
00465 }
00466
00467 static int tcl_onchansplit STDVAR
00468 {
00469 struct chanset_t *chan, *thechan = NULL;
00470 memberlist *m;
00471
00472 BADARGS(2, 3, " nickname ?channel?");
00473
00474 if (argc > 2) {
00475 chan = findchan_by_dname(argv[2]);
00476 thechan = chan;
00477 if (!thechan) {
00478 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00479 return TCL_ERROR;
00480 }
00481 } else
00482 chan = chanset;
00483
00484 while (chan && (thechan == NULL || thechan == chan)) {
00485 m = ismember(chan, argv[1]);
00486 if (m && chan_issplit(m)) {
00487 Tcl_AppendResult(irp, "1", NULL);
00488 return TCL_OK;
00489 }
00490 chan = chan->next;
00491 }
00492 Tcl_AppendResult(irp, "0", NULL);
00493 return TCL_OK;
00494 }
00495
00496 static int tcl_maskhost STDVAR
00497 {
00498 char *new;
00499
00500 BADARGS(2, 3, " nick!user@host ?type?");
00501
00502 new = nmalloc(strlen(argv[1]) + 5);
00503 if (argc == 3)
00504 maskaddr(argv[1], new, atoi(argv[2]));
00505 else
00506 maskban(argv[1], new);
00507 Tcl_AppendResult(irp, new, NULL);
00508 nfree(new);
00509 return TCL_OK;
00510 }
00511
00512 static int tcl_getchanidle STDVAR
00513 {
00514 memberlist *m;
00515 struct chanset_t *chan;
00516 char s[20];
00517 int x;
00518
00519 BADARGS(3, 3, " nickname channel");
00520
00521 if (!(chan = findchan_by_dname(argv[2]))) {
00522 Tcl_AppendResult(irp, "invalid channel: ", argv[2], NULL);
00523 return TCL_ERROR;
00524 }
00525 m = ismember(chan, argv[1]);
00526
00527 if (m) {
00528 x = (now - (m->last)) / 60;
00529 simple_sprintf(s, "%d", x);
00530 Tcl_AppendResult(irp, s, NULL);
00531 return TCL_OK;
00532 }
00533 Tcl_AppendResult(irp, "0", NULL);
00534 return TCL_OK;
00535 }
00536
00537 static inline int tcl_chanmasks(masklist *m, Tcl_Interp *irp)
00538 {
00539 char work[20], *p;
00540 EGG_CONST char *list[3];
00541
00542 for (; m && m->mask && m->mask[0]; m = m->next) {
00543 list[0] = m->mask;
00544 list[1] = m->who;
00545 simple_sprintf(work, "%d", now - m->timer);
00546 list[2] = work;
00547 p = Tcl_Merge(3, list);
00548 Tcl_AppendElement(irp, p);
00549 Tcl_Free((char *) p);
00550 }
00551 return TCL_OK;
00552 }
00553
00554 static int tcl_chanbans STDVAR
00555 {
00556 struct chanset_t *chan;
00557
00558 BADARGS(2, 2, " channel");
00559
00560 chan = findchan_by_dname(argv[1]);
00561 if (chan == NULL) {
00562 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00563 return TCL_ERROR;
00564 }
00565 return tcl_chanmasks(chan->channel.ban, irp);
00566 }
00567
00568 static int tcl_chanexempts STDVAR
00569 {
00570 struct chanset_t *chan;
00571
00572 BADARGS(2, 2, " channel");
00573
00574 chan = findchan_by_dname(argv[1]);
00575 if (chan == NULL) {
00576 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00577 return TCL_ERROR;
00578 }
00579 return tcl_chanmasks(chan->channel.exempt, irp);
00580 }
00581
00582 static int tcl_chaninvites STDVAR
00583 {
00584 struct chanset_t *chan;
00585
00586 BADARGS(2, 2, " channel");
00587
00588 chan = findchan_by_dname(argv[1]);
00589 if (chan == NULL) {
00590 Tcl_AppendResult(irp, "illegal channel: ", argv[2], NULL);
00591 return TCL_ERROR;
00592 }
00593 return tcl_chanmasks(chan->channel.invite, irp);
00594 }
00595
00596 static int tcl_getchanmode STDVAR
00597 {
00598 struct chanset_t *chan;
00599
00600 BADARGS(2, 2, " channel");
00601
00602 chan = findchan_by_dname(argv[1]);
00603 if (chan == NULL) {
00604 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
00605 return TCL_ERROR;
00606 }
00607 Tcl_AppendResult(irp, getchanmode(chan), NULL);
00608 return TCL_OK;
00609 }
00610
00611 static int tcl_getchanjoin STDVAR
00612 {
00613 struct chanset_t *chan;
00614 char s[21];
00615 memberlist *m;
00616
00617 BADARGS(3, 3, " nick channel");
00618
00619 chan = findchan_by_dname(argv[2]);
00620 if (chan == NULL) {
00621 Tcl_AppendResult(irp, "invalid channel: ", argv[2], NULL);
00622 return TCL_ERROR;
00623 }
00624 m = ismember(chan, argv[1]);
00625
00626 if (m == NULL) {
00627 Tcl_AppendResult(irp, argv[1], " is not on ", argv[2], NULL);
00628 return TCL_ERROR;
00629 }
00630 sprintf(s, "%lu", (unsigned long) m->joined);
00631 Tcl_AppendResult(irp, s, NULL);
00632 return TCL_OK;
00633 }
00634
00635 static int tcl_channame2dname STDVAR
00636 {
00637 struct chanset_t *chan;
00638
00639 BADARGS(2, 2, " channel-name");
00640
00641 chan = findchan(argv[1]);
00642 if (chan) {
00643 Tcl_AppendResult(irp, chan->dname, NULL);
00644 return TCL_OK;
00645 } else {
00646 Tcl_AppendResult(irp, "invalid channel-name: ", argv[1], NULL);
00647 return TCL_ERROR;
00648 }
00649 }
00650
00651 static int tcl_chandname2name STDVAR
00652 {
00653 struct chanset_t *chan;
00654
00655 BADARGS(2, 2, " channel-dname");
00656
00657 chan = findchan_by_dname(argv[1]);
00658 if (chan) {
00659 Tcl_AppendResult(irp, chan->name, NULL);
00660 return TCL_OK;
00661 } else {
00662 Tcl_AppendResult(irp, "invalid channel-dname: ", argv[1], NULL);
00663 return TCL_ERROR;
00664 }
00665 }
00666
00667 static int tcl_flushmode STDVAR
00668 {
00669 struct chanset_t *chan;
00670
00671 BADARGS(2, 2, " channel");
00672
00673 chan = findchan_by_dname(argv[1]);
00674 if (chan == NULL) {
00675 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
00676 return TCL_ERROR;
00677 }
00678 flush_mode(chan, NORMAL);
00679 return TCL_OK;
00680 }
00681
00682 static int tcl_pushmode STDVAR
00683 {
00684 struct chanset_t *chan;
00685 char plus, mode;
00686
00687 BADARGS(3, 4, " channel mode ?arg?");
00688
00689 chan = findchan_by_dname(argv[1]);
00690 if (chan == NULL) {
00691 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
00692 return TCL_ERROR;
00693 }
00694 plus = argv[2][0];
00695
00696 mode = argv[2][1];
00697 if ((plus != '+') && (plus != '-')) {
00698 mode = plus;
00699 plus = '+';
00700 }
00701 if (argc == 4)
00702 add_mode(chan, plus, mode, argv[3]);
00703 else
00704 add_mode(chan, plus, mode, "");
00705 return TCL_OK;
00706 }
00707
00708 static int tcl_resetbans STDVAR
00709 {
00710 struct chanset_t *chan;
00711
00712 BADARGS(2, 2, " channel");
00713
00714 chan = findchan_by_dname(argv[1]);
00715 if (chan == NULL) {
00716 Tcl_AppendResult(irp, "invalid channel ", argv[1], NULL);
00717 return TCL_ERROR;
00718 }
00719 resetbans(chan);
00720 return TCL_OK;
00721 }
00722
00723 static int tcl_resetexempts STDVAR
00724 {
00725 struct chanset_t *chan;
00726
00727 BADARGS(2, 2, " channel");
00728
00729 chan = findchan_by_dname(argv[1]);
00730 if (chan == NULL) {
00731 Tcl_AppendResult(irp, "invalid channel ", argv[1], NULL);
00732 return TCL_ERROR;
00733 }
00734 resetexempts(chan);
00735 return TCL_OK;
00736 }
00737
00738 static int tcl_resetinvites STDVAR
00739 {
00740 struct chanset_t *chan;
00741
00742 BADARGS(2, 2, " channel");
00743
00744 chan = findchan_by_dname(argv[1]);
00745 if (chan == NULL) {
00746 Tcl_AppendResult(irp, "invalid channel ", argv[1], NULL);
00747 return TCL_ERROR;
00748 }
00749 resetinvites(chan);
00750 return TCL_OK;
00751 }
00752
00753 static int tcl_resetchanidle STDVAR
00754 {
00755 memberlist *m;
00756 struct chanset_t *chan;
00757
00758 BADARGS(2, 3, " ?nick? channel");
00759
00760 chan = findchan_by_dname((argc == 2) ? argv[1] : argv[2]);
00761 if (chan == NULL) {
00762 Tcl_AppendResult(irp, "invalid channel ",
00763 (argc == 2) ? argv[1] : argv[2], NULL);
00764 return TCL_ERROR;
00765 }
00766
00767 if (argc == 2)
00768 for (m = chan->channel.member; m; m = m->next)
00769 m->last = now;
00770 else {
00771 if (!(m = ismember(chan, argv[1]))) {
00772 Tcl_AppendResult(irp, argv[1], " is not on ", argv[2], NULL);
00773 return TCL_ERROR;
00774 }
00775 m->last = now;
00776 }
00777 return TCL_OK;
00778 }
00779
00780 static int tcl_resetchanjoin STDVAR
00781 {
00782 memberlist *m;
00783 struct chanset_t *chan;
00784
00785 BADARGS(2, 3, " ?nick? channel");
00786
00787 chan = findchan_by_dname((argc == 2) ? argv[1] : argv[2]);
00788 if (chan == NULL) {
00789 Tcl_AppendResult(irp, "invalid channel ",
00790 (argc == 2) ? argv[1] : argv[2], NULL);
00791 return TCL_ERROR;
00792 }
00793
00794 if (argc == 2)
00795 for (m = chan->channel.member; m; m = m->next)
00796 m->joined = now;
00797 else {
00798 if (!(m = ismember(chan, argv[1]))) {
00799 Tcl_AppendResult(irp, argv[1], " is not on ", argv[2], NULL);
00800 return TCL_ERROR;
00801 }
00802 m->joined = now;
00803 }
00804 return TCL_OK;
00805 }
00806
00807 static int tcl_resetchan STDVAR
00808 {
00809 char *c;
00810 int flags = 0;
00811 struct chanset_t *chan;
00812
00813 BADARGS(2, 3, " channel ?flags?");
00814
00815 chan = findchan_by_dname(argv[1]);
00816 if (chan == NULL) {
00817 Tcl_AppendResult(irp, "invalid channel ", argv[1], NULL);
00818 return TCL_ERROR;
00819 }
00820
00821 if (argc == 2) {
00822 reset_chan_info(chan, CHAN_RESETALL);
00823 return TCL_OK;
00824 }
00825 for (c = argv[2]; *c; c++) {
00826 switch(*c) {
00827 case 'w':
00828 flags |= CHAN_RESETWHO;
00829 break;
00830 case 'm':
00831 flags |= CHAN_RESETMODES;
00832 break;
00833 case 'b':
00834 flags |= CHAN_RESETBANS;
00835 break;
00836 case 'e':
00837 flags |= CHAN_RESETEXEMPTS;
00838 break;
00839 case 'I':
00840 flags |= CHAN_RESETINVITED;
00841 break;
00842 case 't':
00843 flags |= CHAN_RESETTOPIC;
00844 break;
00845 default:
00846 Tcl_AppendResult(irp, "invalid reset flags: ", argv[2], NULL);
00847 return TCL_ERROR;
00848 }
00849 }
00850 if (flags)
00851 reset_chan_info(chan, flags);
00852 return TCL_OK;
00853 }
00854
00855 static int tcl_topic STDVAR
00856 {
00857 struct chanset_t *chan;
00858
00859 BADARGS(2, 2, " channel");
00860
00861 chan = findchan_by_dname(argv[1]);
00862 if (chan == NULL) {
00863 Tcl_AppendResult(irp, "invalid channel ", argv[1], NULL);
00864 return TCL_ERROR;
00865 }
00866 Tcl_AppendResult(irp, chan->channel.topic, NULL);
00867 return TCL_OK;
00868 }
00869
00870 static int tcl_hand2nick STDVAR
00871 {
00872 char nuh[1024];
00873 memberlist *m;
00874 struct chanset_t *chan, *thechan = NULL;
00875
00876 BADARGS(2, 3, " handle ?channel?");
00877
00878 if (argc > 2) {
00879 chan = findchan_by_dname(argv[2]);
00880 thechan = chan;
00881 if (chan == NULL) {
00882 Tcl_AppendResult(irp, "invalid channel: ", argv[2], NULL);
00883 return TCL_ERROR;
00884 }
00885 } else
00886 chan = chanset;
00887
00888 while (chan && (thechan == NULL || thechan == chan)) {
00889 for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
00890 if (!m->user && !m->tried_getuser) {
00891 egg_snprintf(nuh, sizeof nuh, "%s!%s", m->nick, m->userhost);
00892 m->tried_getuser = 1;
00893 m->user = get_user_by_host(nuh);
00894 }
00895 if (m->user && !rfc_casecmp(m->user->handle, argv[1])) {
00896 Tcl_AppendResult(irp, m->nick, NULL);
00897 return TCL_OK;
00898 }
00899 }
00900 chan = chan->next;
00901 }
00902 return TCL_OK;
00903 }
00904
00905 static int tcl_nick2hand STDVAR
00906 {
00907 char nuh[1024];
00908 memberlist *m;
00909 struct chanset_t *chan, *thechan = NULL;
00910
00911 BADARGS(2, 3, " nick ?channel?");
00912
00913 if (argc > 2) {
00914 chan = findchan_by_dname(argv[2]);
00915 thechan = chan;
00916 if (chan == NULL) {
00917 Tcl_AppendResult(irp, "invalid channel: ", argv[2], NULL);
00918 return TCL_ERROR;
00919 }
00920 } else
00921 chan = chanset;
00922
00923 while (chan && (thechan == NULL || thechan == chan)) {
00924 m = ismember(chan, argv[1]);
00925 if (m) {
00926 if (!m->user) {
00927 egg_snprintf(nuh, sizeof nuh, "%s!%s", m->nick, m->userhost);
00928 m->user = get_user_by_host(nuh);
00929 }
00930 Tcl_AppendResult(irp, m->user ? m->user->handle : "*", NULL);
00931 return TCL_OK;
00932 }
00933 chan = chan->next;
00934 }
00935 return TCL_OK;
00936 }
00937
00938 static int tcl_putkick STDVAR
00939 {
00940 struct chanset_t *chan;
00941 int k = 0, l;
00942 char kicknick[512], *nick, *p, *comment = NULL;
00943 memberlist *m;
00944
00945 BADARGS(3, 4, " channel nick?s? ?comment?");
00946
00947 chan = findchan_by_dname(argv[1]);
00948 if (chan == NULL) {
00949 Tcl_AppendResult(irp, "illegal channel: ", argv[1], NULL);
00950 return TCL_ERROR;
00951 }
00952 if (argc == 4)
00953 comment = argv[3];
00954 else
00955 comment = "";
00956 if (!me_op(chan) && !me_halfop(chan)) {
00957 Tcl_AppendResult(irp, "need op or halfop", NULL);
00958 return TCL_ERROR;
00959 }
00960
00961 kicknick[0] = 0;
00962 p = argv[2];
00963
00964 while (p) {
00965 nick = p;
00966 p = strchr(nick, ',');
00967 if (p) {
00968 *p = 0;
00969 p++;
00970 }
00971
00972 m = ismember(chan, nick);
00973 if (!me_op(chan) && !(me_halfop(chan) && !chan_hasop(m))) {
00974 Tcl_AppendResult(irp, "need op", NULL);
00975 return TCL_ERROR;
00976 }
00977 if (!m)
00978 continue;
00979 m->flags |= SENTKICK;
00980 if (kicknick[0])
00981 strcat(kicknick, ",");
00982 strcat(kicknick, nick);
00983 k++;
00984
00985
00986 l = strlen(chan->name) + strlen(kicknick) + strlen(comment);
00987 if (((kick_method != 0) && (k == kick_method)) || (l > 480)) {
00988 dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, kicknick, comment);
00989 k = 0;
00990 kicknick[0] = 0;
00991 }
00992 }
00993
00994 if (k > 0)
00995 dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, kicknick, comment);
00996 return TCL_OK;
00997 }
00998
00999 static tcl_cmds tclchan_cmds[] = {
01000 {"chanlist", tcl_chanlist},
01001 {"botisop", tcl_botisop},
01002 {"botishalfop", tcl_botishalfop},
01003 {"botisvoice", tcl_botisvoice},
01004 {"isop", tcl_isop},
01005 {"wasop", tcl_wasop},
01006 {"ishalfop", tcl_ishalfop},
01007 {"washalfop", tcl_washalfop},
01008 {"isvoice", tcl_isvoice},
01009 {"onchan", tcl_onchan},
01010 {"handonchan", tcl_handonchan},
01011 {"ischanban", tcl_ischanban},
01012 {"ischanexempt", tcl_ischanexempt},
01013 {"ischaninvite", tcl_ischaninvite},
01014 {"ischanjuped", tcl_ischanjuped},
01015 {"getchanhost", tcl_getchanhost},
01016 {"onchansplit", tcl_onchansplit},
01017 {"maskhost", tcl_maskhost},
01018 {"getchanidle", tcl_getchanidle},
01019 {"chanbans", tcl_chanbans},
01020 {"chanexempts", tcl_chanexempts},
01021 {"chaninvites", tcl_chaninvites},
01022 {"hand2nick", tcl_hand2nick},
01023 {"nick2hand", tcl_nick2hand},
01024 {"getchanmode", tcl_getchanmode},
01025 {"getchanjoin", tcl_getchanjoin},
01026 {"flushmode", tcl_flushmode},
01027 {"pushmode", tcl_pushmode},
01028 {"resetbans", tcl_resetbans},
01029 {"resetexempts", tcl_resetexempts},
01030 {"resetinvites", tcl_resetinvites},
01031 {"resetchanidle", tcl_resetchanidle},
01032 {"resetchanjoin", tcl_resetchanjoin},
01033 {"resetchan", tcl_resetchan},
01034 {"topic", tcl_topic},
01035 {"botonchan", tcl_botonchan},
01036 {"putkick", tcl_putkick},
01037 {"channame2dname", tcl_channame2dname},
01038 {"chandname2name", tcl_chandname2name},
01039 {NULL, NULL}
01040 };