channels.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /*
  2. * channels.c -- part of channels.mod
  3. * support for channels within the bot
  4. *
  5. */
  6. #define MAKING_CHANNELS
  7. #include "src/common.h"
  8. #include "src/mod/share.mod/share.h"
  9. #include "src/mod/irc.mod/irc.h"
  10. #include "src/mod/server.mod/server.h"
  11. #include "src/chanprog.h"
  12. #include "src/egg_timer.h"
  13. #include "src/misc.h"
  14. #include "src/main.h"
  15. #include "src/color.h"
  16. #include "src/userrec.h"
  17. #include "src/users.h"
  18. #include "src/set.h"
  19. #include "src/rfc1459.h"
  20. #include "src/match.h"
  21. #include "src/settings.h"
  22. #include "src/tandem.h"
  23. #include "src/botnet.h"
  24. #include "src/botmsg.h"
  25. #include "src/net.h"
  26. #include "src/tclhash.h"
  27. #include "src/cmds.h"
  28. #include <sys/stat.h>
  29. static bool use_info = 1;
  30. static char glob_chanmode[64] = "nt"; /* Default chanmode (drummer,990731) */
  31. static int global_stopnethack_mode;
  32. //static int global_revenge_mode = 3;
  33. static int global_idle_kick; /* Default idle-kick setting. */
  34. static time_t global_ban_time;
  35. static time_t global_exempt_time;
  36. static time_t global_invite_time;
  37. /* Global channel settings (drummer/dw) */
  38. char glob_chanset[512];
  39. static char *lastdeletedmask = NULL;
  40. /* Global flood settings */
  41. static int gfld_chan_thr;
  42. static time_t gfld_chan_time;
  43. static int gfld_deop_thr = 8;
  44. static time_t gfld_deop_time = 10;
  45. static int gfld_kick_thr;
  46. static time_t gfld_kick_time;
  47. static int gfld_join_thr;
  48. static time_t gfld_join_time;
  49. static int gfld_ctcp_thr = 5;
  50. static time_t gfld_ctcp_time = 30;
  51. static int gfld_nick_thr;
  52. static time_t gfld_nick_time;
  53. static int killed_bots = 0;
  54. #include "channels.h"
  55. #include "cmdschan.c"
  56. #include "tclchan.c"
  57. #include "userchan.c"
  58. /* This will close channels if the HUB:leaf count is skewed from config setting */
  59. static void
  60. check_should_close()
  61. {
  62. int H = close_threshold.count, L = close_threshold.time;
  63. if ((H <= 0) || (L <= 0))
  64. return;
  65. int hc = 1, lc = 0;
  66. struct userrec *u = NULL;
  67. for (tand_t *bot = tandbot; bot; bot = bot->next) {
  68. if ((u = get_user_by_handle(userlist, bot->bot))) {
  69. if (bot_hublevel(u) < 999)
  70. hc++;
  71. else
  72. lc++;
  73. }
  74. }
  75. if ((hc >= H) && (lc <= L)) {
  76. for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
  77. if (!channel_closed(chan)) {
  78. do_chanset(NULL, chan, "+closed chanmode +stni", DO_LOCAL | DO_NET);
  79. #ifdef G_BACKUP
  80. chan->channel.backup_time = now + 30;
  81. #endif /* G_BACKUP */
  82. }
  83. }
  84. }
  85. }
  86. static void got_cset(char *botnick, char *code, char *par)
  87. {
  88. if (!par || !par[0])
  89. return;
  90. bool all = 0;
  91. char *chname = NULL;
  92. struct chanset_t *chan = NULL;
  93. if (par[0] == '*' && par[1] == ' ') {
  94. all = 1;
  95. newsplit(&par);
  96. } else {
  97. if (!strchr(CHANMETA, par[0])) {
  98. putlog(LOG_ERROR, "*", "Got bad cset: bot: %s code: %s par: %s", botnick, code, par);
  99. return;
  100. }
  101. chname = newsplit(&par);
  102. if (!(chan = findchan_by_dname(chname)))
  103. return;
  104. }
  105. if (all)
  106. chan = chanset;
  107. while (chan) {
  108. chname = chan->dname;
  109. do_chanset(NULL, chan, par, DO_LOCAL);
  110. if (!conf.bot->hub && chan->status & CHAN_BITCH)
  111. recheck_channel(chan, 0);
  112. if (!all)
  113. chan = NULL;
  114. else
  115. chan = chan->next;
  116. }
  117. }
  118. /* returns 1 if botn is in bots */
  119. static int
  120. parsebots(char *bots, char *botn) {
  121. if (!strcmp(bots, "*")) {
  122. return 1;
  123. } else {
  124. char *list = strdup(bots), *bot = strtok(list, ",");
  125. while(bot && *bot) {
  126. if (!egg_strcasecmp(bot, botn))
  127. return 1;
  128. bot = strtok((char*) NULL, ",");
  129. }
  130. free(list);
  131. }
  132. return 0;
  133. }
  134. static void got_cpart(char *botnick, char *code, char *par)
  135. {
  136. if (!par[0])
  137. return;
  138. char *chname = newsplit(&par);
  139. struct chanset_t *chan = NULL;
  140. if (!(chan = findchan_by_dname(chname)))
  141. return;
  142. char *bots = newsplit(&par);
  143. int match = 0;
  144. /* if bots is '*' just remove_channel */
  145. if (!strcmp(bots, "*"))
  146. match = 0;
  147. else
  148. match = parsebots(bots, conf.bot->nick);
  149. if (match)
  150. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  151. else
  152. remove_channel(chan);
  153. if (conf.bot->hub)
  154. write_userfile(-1);
  155. }
  156. static void got_chans(char *botnick, char *code, char *par)
  157. {
  158. struct chanset_t *chan = NULL;
  159. char buf[1024] = "";
  160. for (chan = chanset; chan; chan = chan->next) {
  161. if (shouldjoin(chan) && !channel_active(chan)) {
  162. simple_snprintf(buf, sizeof(buf), "%s%s%s", buf[0] ? buf : "", buf[0] ? " " : "", chan->dname);
  163. }
  164. }
  165. if (buf[0])
  166. putlog(LOG_MISC, "*", "I am not in: %s", buf);
  167. }
  168. static void got_cjoin(char *botnick, char *code, char *par)
  169. {
  170. if (!par[0])
  171. return;
  172. char *chname = newsplit(&par), *options = NULL;
  173. struct chanset_t *chan = findchan_by_dname(chname);
  174. int match = 0;
  175. if (conf.bot->hub) {
  176. newsplit(&par); /* hubs ignore the botmatch param */
  177. options = par;
  178. } else {
  179. /* ALL hubs should add the channel, leaf should check the list for a match */
  180. bool inactive = 0;
  181. char *bots = newsplit(&par);
  182. match = parsebots(bots, conf.bot->nick);
  183. if (strstr(par, "+inactive"))
  184. inactive = 1;
  185. if (chan && !match)
  186. return;
  187. if (!match) {
  188. size_t size = strlen(par) + 12 + 1;
  189. options = (char *) my_calloc(1, size);
  190. egg_snprintf(options, size, "%s +inactive", par);
  191. } else if (match && chan && !shouldjoin(chan)) {
  192. if (!inactive)
  193. do_chanset(NULL, chan, "-inactive", DO_LOCAL);
  194. return;
  195. } else
  196. options = par;
  197. }
  198. if (chan)
  199. return;
  200. sdprintf("OPTIONS: %s", options);
  201. char result[RESULT_LEN] = "";
  202. if (channel_add(result, chname, options) == ERROR) /* drummer */
  203. putlog(LOG_BOTS, "@", "Invalid channel or channel options from %s for %s: %s", botnick, chname, result);
  204. if (conf.bot->hub)
  205. write_userfile(-1);
  206. if (!match && !conf.bot->hub)
  207. free(options);
  208. }
  209. static void got_cycle(char *botnick, char *code, char *par)
  210. {
  211. if (!par[0])
  212. return;
  213. char *chname = newsplit(&par);
  214. struct chanset_t *chan = NULL;
  215. if (!(chan = findchan_by_dname(chname)))
  216. return;
  217. time_t delay = 10;
  218. if (par[0])
  219. delay = atoi(newsplit(&par));
  220. do_chanset(NULL, chan, "+inactive", DO_LOCAL);
  221. dprintf(DP_SERVER, "PART %s\n", chan->name);
  222. chan->channel.jointime = ((now + delay) - server_lag); /* rejoin in 10 seconds */
  223. }
  224. static void got_down(char *botnick, char *code, char *par)
  225. {
  226. if (!par[0])
  227. return;
  228. char *chname = newsplit(&par);
  229. struct chanset_t *chan = NULL;
  230. if (!(chan = findchan_by_dname(chname)))
  231. return;
  232. chan->channel.no_op = (now + 10);
  233. add_mode(chan, '-', 'o', botname);
  234. }
  235. static void got_role(char *botnick, char *code, char *par)
  236. {
  237. role = atoi(newsplit(&par));
  238. putlog(LOG_DEBUG, "@", "Got role index %d", role);
  239. }
  240. void got_kl(char *botnick, char *code, char *par)
  241. {
  242. killed_bots++;
  243. if (kill_threshold && (killed_bots == kill_threshold)) {
  244. for (struct chanset_t *ch = chanset; ch; ch = ch->next)
  245. do_chanset(NULL, ch, "+closed +bitch +backup", DO_LOCAL | DO_NET);
  246. /* FIXME: we should randomize nick here ... */
  247. }
  248. }
  249. static void rebalance_roles()
  250. {
  251. struct bot_addr *ba = NULL;
  252. int r[5] = { 0, 0, 0, 0, 0 };
  253. unsigned int hNdx, lNdx, i;
  254. char tmp[10] = "";
  255. for (i = 0; i < (unsigned) dcc_total; i++) {
  256. if (dcc[i].type && dcc[i].user && dcc[i].user->bot && bot_hublevel(dcc[i].user) == 999) {
  257. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, dcc[i].user);
  258. if (ba && (ba->roleid > 0) && (ba->roleid < 5))
  259. r[(ba->roleid - 1)]++;
  260. }
  261. }
  262. /*
  263. Find high & low
  264. while (high-low) > 2
  265. move from highNdx to lowNdx
  266. */
  267. hNdx = 0;
  268. lNdx = 0;
  269. for (i = 1; i <= 4; i++) {
  270. if (r[i] < r[lNdx])
  271. lNdx = i;
  272. if (r[i] > r[hNdx])
  273. hNdx = i;
  274. }
  275. while (r[hNdx] - r[lNdx] >= 2) {
  276. for (i = 0; i < (unsigned) dcc_total; i++) {
  277. if (dcc[i].type && dcc[i].user && dcc[i].user->bot && bot_hublevel(dcc[i].user) == 999) {
  278. ba = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, dcc[i].user);
  279. if (ba && (ba->roleid == (hNdx + 1))) {
  280. ba->roleid = lNdx + 1;
  281. simple_sprintf(tmp, "rl %d", lNdx + 1);
  282. putbot(dcc[i].nick, tmp);
  283. }
  284. }
  285. }
  286. r[hNdx]--;
  287. r[lNdx]++;
  288. hNdx = 0;
  289. lNdx = 0;
  290. for (i = 1; i <= 4; i++) {
  291. if (r[i] < r[lNdx])
  292. lNdx = i;
  293. if (r[i] > r[hNdx])
  294. hNdx = i;
  295. }
  296. }
  297. }
  298. static int
  299. check_slowjoinpart(struct chanset_t *chan)
  300. {
  301. /* slowpart */
  302. if (channel_active(chan) && (chan->channel.parttime) && (chan->channel.parttime < now)) {
  303. chan->channel.parttime = 0;
  304. dprintf(DP_MODE, "PART %s\n", chan->name);
  305. if (chan) /* this should NOT be necesary, but some unforseen bug requires it.. */
  306. remove_channel(chan);
  307. return 1; /* if we keep looping, we'll segfault. */
  308. /* slowjoin */
  309. } else if ((chan->channel.jointime) && (chan->channel.jointime < now)) {
  310. chan->status &= ~CHAN_INACTIVE;
  311. chan->channel.jointime = 0;
  312. if (shouldjoin(chan) && !channel_active(chan) && !channel_joining(chan)) {
  313. dprintf(DP_MODE, "JOIN %s %s\n", chan->dname, chan->key_prot);
  314. chan->status |= CHAN_JOINING;
  315. }
  316. } else if (channel_closed(chan)) {
  317. enforce_closed(chan);
  318. }
  319. return 0;
  320. }
  321. static void
  322. check_limitraise(struct chanset_t *chan) {
  323. /* only check every other time for now */
  324. chan->checklimit++;
  325. if (chan->checklimit == 2) {
  326. chan->checklimit = 0;
  327. if (chan->limitraise && dolimit(chan))
  328. raise_limit(chan);
  329. }
  330. }
  331. static void
  332. channels_timers()
  333. {
  334. static int cnt = 0;
  335. struct chanset_t *chan_n = NULL, *chan = NULL;
  336. bool reset = 0;
  337. cnt += 10; /* function is called every 10 seconds */
  338. for (chan = chanset; chan; chan = chan_n) {
  339. chan_n = chan->next;
  340. if ((cnt % 10) == 0) {
  341. /* 10 seconds */
  342. if (!conf.bot->hub && check_slowjoinpart(chan)) /* if 1 is returned, chan was removed. */
  343. continue;
  344. }
  345. if ((cnt % 60) == 0) {
  346. /* 60 seconds */
  347. reset = 1;
  348. if (!conf.bot->hub)
  349. check_limitraise(chan);
  350. }
  351. }
  352. if (reset)
  353. cnt = 0;
  354. }
  355. static void got_sj(int idx, char *code, char *par)
  356. {
  357. struct chanset_t *chan = findchan_by_dname(newsplit(&par));
  358. if (chan) {
  359. if (conf.bot->hub) {
  360. chan->status &= ~CHAN_INACTIVE;
  361. write_userfile(-1);
  362. } else
  363. chan->channel.jointime = ((atoi(par) + now) - server_lag);
  364. }
  365. }
  366. static void got_sp(int idx, char *code, char *par)
  367. {
  368. struct chanset_t *chan = findchan_by_dname(newsplit(&par));
  369. if (chan) {
  370. if (conf.bot->hub) {
  371. remove_channel(chan);
  372. write_userfile(-1);
  373. } else
  374. chan->channel.parttime = ((atoi(par) + now) - server_lag);
  375. }
  376. }
  377. #ifdef no
  378. /* got_jn
  379. * We get this when a bot is opped in a +take chan
  380. * we are to set -inactive, jointime = 0, and join.
  381. */
  382. static void got_jn(int idx, char *code, char *par)
  383. {
  384. char *chname = newsplit(&par);
  385. if (!chname || !chname[0])
  386. return;
  387. struct chanset_t *chan = NULL;
  388. if (!(chan = findchan_by_dname(chname))) return;
  389. if (chan->channel.jointime && channel_inactive(chan)) {
  390. chan->status &= ~CHAN_INACTIVE;
  391. chan->channel.jointime = 0;
  392. if (!conf.bot->hub && shouldjoin(chan) && !channel_active(chan) && !channel_joining(chan)) {
  393. dprintf(DP_MODE, "JOIN %s %s\n", chan->name, chan->key_prot);
  394. chan->status |= CHAN_JOINING;
  395. }
  396. }
  397. }
  398. #endif
  399. static void set_mode_protect(struct chanset_t *chan, char *set)
  400. {
  401. int i, pos = 1;
  402. char *s = NULL, *s1 = NULL;
  403. /* Clear old modes */
  404. chan->mode_mns_prot = chan->mode_pls_prot = 0;
  405. chan->limit_prot = 0;
  406. chan->key_prot[0] = 0;
  407. for (s = newsplit(&set); *s; s++) {
  408. i = 0;
  409. switch (*s) {
  410. case '+':
  411. pos = 1;
  412. break;
  413. case '-':
  414. pos = 0;
  415. break;
  416. case 'i':
  417. i = CHANINV;
  418. break;
  419. case 'p':
  420. i = CHANPRIV;
  421. break;
  422. case 's':
  423. i = CHANSEC;
  424. break;
  425. case 'm':
  426. i = CHANMODER;
  427. break;
  428. case 'c':
  429. i = CHANNOCLR;
  430. break;
  431. case 'C':
  432. i = CHANNOCTCP;
  433. break;
  434. case 'R':
  435. i = CHANREGON;
  436. break;
  437. case 'M':
  438. i = CHANMODR;
  439. break;
  440. case 'r':
  441. i = CHANLONLY;
  442. break;
  443. case 't':
  444. i = CHANTOPIC;
  445. break;
  446. case 'n':
  447. i = CHANNOMSG;
  448. break;
  449. case 'a':
  450. i = CHANANON;
  451. break;
  452. case 'q':
  453. i = CHANQUIET;
  454. break;
  455. case 'l':
  456. i = CHANLIMIT;
  457. chan->limit_prot = 0;
  458. if (pos) {
  459. s1 = newsplit(&set);
  460. if (s1[0] && !chan->limitraise)
  461. chan->limit_prot = atoi(s1);
  462. }
  463. break;
  464. case 'k':
  465. i = CHANKEY;
  466. chan->key_prot[0] = 0;
  467. if (pos) {
  468. s1 = newsplit(&set);
  469. if (s1[0])
  470. strcpy(chan->key_prot, s1);
  471. }
  472. break;
  473. }
  474. if (i) {
  475. if (pos) {
  476. chan->mode_pls_prot |= i;
  477. chan->mode_mns_prot &= ~i;
  478. } else {
  479. chan->mode_pls_prot &= ~i;
  480. chan->mode_mns_prot |= i;
  481. }
  482. }
  483. }
  484. /* Prevents a +s-p +p-s flood (fixed by drummer) */
  485. if (chan->mode_pls_prot & CHANSEC)
  486. chan->mode_pls_prot &= ~CHANPRIV;
  487. if (chan->mode_mns_prot & CHANPRIV && chan->closed_private)
  488. chan->closed_private = 0;
  489. if (chan->mode_mns_prot & CHANINV && chan->closed_invite)
  490. chan->closed_invite = 0;
  491. }
  492. static void get_mode_protect(struct chanset_t *chan, char *s)
  493. {
  494. char *p = s, s1[121] = "";
  495. int tst;
  496. bool ok = 0;
  497. for (int i = 0; i < 2; i++) {
  498. ok = 0;
  499. if (i == 0) {
  500. tst = chan->mode_pls_prot;
  501. if ((tst) || (chan->limit_prot != 0) || (chan->key_prot[0]))
  502. *p++ = '+';
  503. if (chan->limit_prot != 0) {
  504. *p++ = 'l';
  505. simple_sprintf(&s1[strlen(s1)], "%d ", chan->limit_prot);
  506. }
  507. if (chan->key_prot[0]) {
  508. *p++ = 'k';
  509. simple_sprintf(&s1[strlen(s1)], "%s ", chan->key_prot);
  510. }
  511. } else {
  512. tst = chan->mode_mns_prot;
  513. if (tst)
  514. *p++ = '-';
  515. if (tst & CHANKEY)
  516. *p++ = 'k';
  517. if (tst & CHANLIMIT)
  518. *p++ = 'l';
  519. }
  520. if (tst & CHANINV)
  521. *p++ = 'i';
  522. if (tst & CHANPRIV)
  523. *p++ = 'p';
  524. if (tst & CHANSEC)
  525. *p++ = 's';
  526. if (tst & CHANMODER)
  527. *p++ = 'm';
  528. if (tst & CHANNOCLR)
  529. *p++ = 'c';
  530. if (tst & CHANNOCTCP)
  531. *p++ = 'C';
  532. if (tst & CHANREGON)
  533. *p++ = 'R';
  534. if (tst & CHANMODR)
  535. *p++ = 'M';
  536. if (tst & CHANLONLY)
  537. *p++ = 'r';
  538. if (tst & CHANTOPIC)
  539. *p++ = 't';
  540. if (tst & CHANNOMSG)
  541. *p++ = 'n';
  542. if (tst & CHANANON)
  543. *p++ = 'a';
  544. if (tst & CHANQUIET)
  545. *p++ = 'q';
  546. }
  547. *p = 0;
  548. if (s1[0]) {
  549. s1[strlen(s1) - 1] = 0;
  550. strcat(s, " ");
  551. strcat(s, s1);
  552. }
  553. }
  554. /* Returns true if this is one of the channel masks
  555. */
  556. bool ismodeline(masklist *m, const char *username)
  557. {
  558. for (; m && m->mask[0]; m = m->next)
  559. if (!rfc_casecmp(m->mask, username))
  560. return 1;
  561. return 0;
  562. }
  563. /* Returns true if user matches one of the masklist -- drummer
  564. */
  565. bool ismasked(masklist *m, const char *username)
  566. {
  567. for (; m && m->mask[0]; m = m->next)
  568. if (wild_match(m->mask, (char *) username))
  569. return 1;
  570. return 0;
  571. }
  572. /* Unlink chanset element from chanset list.
  573. */
  574. static inline bool chanset_unlink(struct chanset_t *chan)
  575. {
  576. struct chanset_t *c_old = NULL;
  577. for (struct chanset_t *c = chanset; c; c_old = c, c = c->next) {
  578. if (c == chan) {
  579. if (c_old)
  580. c_old->next = c->next;
  581. else
  582. chanset = c->next;
  583. return 1;
  584. }
  585. }
  586. return 0;
  587. }
  588. /* Completely removes a channel.
  589. *
  590. * This includes the removal of all channel-bans, -exempts and -invites, as
  591. * well as all user flags related to the channel.
  592. */
  593. void remove_channel(struct chanset_t *chan)
  594. {
  595. int i;
  596. irc_log(chan, "Parting");
  597. /* Remove the channel from the list, so that noone can pull it
  598. away from under our feet during the check_part() call. */
  599. chanset_unlink(chan);
  600. /* Using chan->name is important here, especially for !chans <cybah> */
  601. if (!conf.bot->hub && shouldjoin(chan) && chan->name[0])
  602. dprintf(DP_SERVER, "PART %s\n", chan->name);
  603. clear_channel(chan, 0);
  604. noshare = 1;
  605. /* Remove channel-bans */
  606. while (chan->bans)
  607. u_delmask('b', chan, chan->bans->mask, 1);
  608. /* Remove channel-exempts */
  609. while (chan->exempts)
  610. u_delmask('e', chan, chan->exempts->mask, 1);
  611. /* Remove channel-invites */
  612. while (chan->invites)
  613. u_delmask('I', chan, chan->invites->mask, 1);
  614. /* Remove channel specific user flags */
  615. user_del_chan(chan->dname);
  616. noshare = 0;
  617. free(chan->channel.key);
  618. for (i = 0; i < MODES_PER_LINE_MAX && chan->cmode[i].op; i++)
  619. free(chan->cmode[i].op);
  620. for (i = 0; i < (MODES_PER_LINE_MAX - 1) && chan->ccmode[i].op; i++)
  621. free(chan->ccmode[i].op);
  622. if (chan->key)
  623. free(chan->key);
  624. if (chan->rmkey)
  625. free(chan->rmkey);
  626. free(chan);
  627. }
  628. /* Bind this to chon and *if* the users console channel == ***
  629. * then set it to a specific channel
  630. */
  631. static int channels_chon(char *handle, int idx)
  632. {
  633. struct flag_record fr = {FR_CHAN | FR_ANYWH | FR_GLOBAL, 0, 0, 0 };
  634. int find;
  635. bool found = 0;
  636. struct chanset_t *chan = chanset;
  637. if (dcc[idx].type == &DCC_CHAT) {
  638. if (!findchan_by_dname(dcc[idx].u.chat->con_chan) &&
  639. ((dcc[idx].u.chat->con_chan[0] != '*') ||
  640. (dcc[idx].u.chat->con_chan[1] != 0))) {
  641. get_user_flagrec(dcc[idx].user, &fr, NULL);
  642. if (glob_op(fr))
  643. found = 1;
  644. if (chan_owner(fr))
  645. find = USER_OWNER;
  646. else if (chan_master(fr))
  647. find = USER_MASTER;
  648. else
  649. find = USER_OP;
  650. fr.match = FR_CHAN;
  651. while (chan && !found) {
  652. get_user_flagrec(dcc[idx].user, &fr, chan->dname);
  653. if (fr.chan & find)
  654. found = 1;
  655. else
  656. chan = chan->next;
  657. }
  658. if (!chan)
  659. chan = chanset;
  660. if (chan)
  661. strcpy(dcc[idx].u.chat->con_chan, chan->dname);
  662. else
  663. strcpy(dcc[idx].u.chat->con_chan, "*");
  664. }
  665. }
  666. return 0;
  667. }
  668. static cmd_t my_chon[] =
  669. {
  670. {"*", "", (Function) channels_chon, "channels:chon", 0},
  671. {NULL, NULL, NULL, NULL, 0}
  672. };
  673. void channels_report(int idx, int details)
  674. {
  675. int i;
  676. char s[1024] = "", s2[100] = "";
  677. struct flag_record fr = {FR_CHAN | FR_GLOBAL, 0, 0, 0 };
  678. for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
  679. if (idx != DP_STDOUT)
  680. get_user_flagrec(dcc[idx].user, &fr, chan->dname);
  681. if (!privchan(fr, chan, PRIV_OP) && ((idx == DP_STDOUT) || glob_master(fr) || chan_master(fr))) {
  682. s[0] = 0;
  683. if (chan_bitch(chan))
  684. strcat(s, "bitch, ");
  685. if (s[0])
  686. s[strlen(s) - 2] = 0;
  687. if (!s[0])
  688. strcpy(s, "lurking");
  689. get_mode_protect(chan, s2);
  690. if (channel_closed(chan)) {
  691. if (chan->closed_invite)
  692. strcat(s2, "i");
  693. if (chan->closed_private)
  694. strcat(s2, "p");
  695. }
  696. if (shouldjoin(chan)) {
  697. if (channel_active(chan)) {
  698. /* If it's a !chan, we want to display it's unique name too <cybah> */
  699. if (chan->dname[0]=='!') {
  700. dprintf(idx, " %-10s: %2d member%s enforcing \"%s\" (%s), "
  701. "unique name %s\n", chan->dname, chan->channel.members,
  702. (chan->channel.members==1) ? "," : "s,", s2, s, chan->name);
  703. } else {
  704. dprintf(idx, " %-10s: %2d member%s enforcing \"%s\" (%s)\n",
  705. chan->dname, chan->channel.members,
  706. chan->channel.members == 1 ? "," : "s,", s2, s);
  707. }
  708. } else {
  709. if (!conf.bot->hub)
  710. dprintf(idx, " %-10s: (%s), enforcing \"%s\" (%s)\n", chan->dname,
  711. channel_pending(chan) ? "pending" : "not on channel", s2, s);
  712. else
  713. dprintf(idx, " %-10s: (%s), enforcing \"%s\" (%s)\n", chan->dname,
  714. "limbo", s2, s);
  715. }
  716. } else {
  717. dprintf(idx, " %-10s: channel is set +inactive\n",
  718. chan->dname);
  719. }
  720. if (details) {
  721. s[0] = 0;
  722. i = 0;
  723. i += my_strcpy(s + i, "dynamic ");
  724. if (channel_enforcebans(chan))
  725. i += my_strcpy(s + i, "enforcebans ");
  726. if (channel_dynamicbans(chan))
  727. i += my_strcpy(s + i, "dynamicbans ");
  728. if (!channel_nouserbans(chan))
  729. i += my_strcpy(s + i, "userbans ");
  730. if (channel_bitch(chan))
  731. i += my_strcpy(s + i, "bitch ");
  732. if (channel_protectops(chan))
  733. i += my_strcpy(s + i, "protectops ");
  734. /*
  735. if (channel_revenge(chan))
  736. i += my_strcpy(s + i, "revenge ");
  737. if (channel_revenge(chan))
  738. i += my_strcpy(s + i, "revengebot ");
  739. */
  740. if (channel_secret(chan))
  741. i += my_strcpy(s + i, "secret ");
  742. if (channel_cycle(chan))
  743. i += my_strcpy(s + i, "cycle ");
  744. if (channel_dynamicexempts(chan))
  745. i += my_strcpy(s + i, "dynamicexempts ");
  746. if (!channel_nouserexempts(chan))
  747. i += my_strcpy(s + i, "userexempts ");
  748. if (channel_dynamicinvites(chan))
  749. i += my_strcpy(s + i, "dynamicinvites ");
  750. if (!channel_nouserinvites(chan))
  751. i += my_strcpy(s + i, "userinvites ");
  752. if (!shouldjoin(chan))
  753. i += my_strcpy(s + i, "inactive ");
  754. if (channel_nodesynch(chan))
  755. i += my_strcpy(s + i, "nodesynch ");
  756. if (channel_closed(chan))
  757. i += my_strcpy(s + i, "closed ");
  758. if (have_take && channel_take(chan))
  759. i += my_strcpy(s + i, "take ");
  760. if (channel_voice(chan))
  761. i += my_strcpy(s + i, "voice ");
  762. if (channel_autoop(chan))
  763. i += my_strcpy(s + i, "autoop ");
  764. /* Chanflag template
  765. * if (channel_temp(chan))
  766. * i += my_strcpy(s + i, "temp ");
  767. */
  768. if (channel_botbitch(chan))
  769. i += my_strcpy(s + i, "botbitch ");
  770. if (channel_fastop(chan))
  771. i += my_strcpy(s + i, "fastop ");
  772. if (channel_privchan(chan))
  773. i += my_strcpy(s + i, "private ");
  774. dprintf(idx, " Options: %s\n", s);
  775. if (chan->idle_kick)
  776. dprintf(idx, " Kicking idle users after %d min\n",
  777. chan->idle_kick);
  778. if (chan->limitraise)
  779. dprintf(idx, " Raising limit +%d every 2 minutes\n", chan->limitraise);
  780. if (chan->stopnethack_mode)
  781. dprintf(idx, " stopnethack-mode %d\n",
  782. chan->stopnethack_mode);
  783. /*
  784. if (chan->revenge_mode)
  785. dprintf(idx, " revenge-mode %d\n",
  786. chan->revenge_mode);
  787. */
  788. dprintf(idx, " Bans last %lu mins.\n", chan->ban_time);
  789. dprintf(idx, " Exemptions last %lu mins.\n", chan->exempt_time);
  790. dprintf(idx, " Invitations last %lu mins.\n", chan->invite_time);
  791. }
  792. }
  793. }
  794. }
  795. cmd_t channels_bot[] = {
  796. {"chans", "", (Function) got_chans, NULL, LEAF},
  797. {"cjoin", "", (Function) got_cjoin, NULL, 0},
  798. {"cpart", "", (Function) got_cpart, NULL, 0},
  799. {"cset", "", (Function) got_cset, NULL, 0},
  800. {"cycle", "", (Function) got_cycle, NULL, LEAF},
  801. {"down", "", (Function) got_down, NULL, LEAF},
  802. {"rl", "", (Function) got_role, NULL, 0},
  803. {"kl", "", (Function) got_kl, NULL, 0},
  804. {"sj", "", (Function) got_sj, NULL, 0},
  805. {"sp", "", (Function) got_sp, NULL, 0},
  806. // {"jn", "", (Function) got_jn, NULL, 0},
  807. /*
  808. #ifdef HUB
  809. {"o1", "", (Function) got_o1, NULL, 0},
  810. {"kl", "", (Function) got_kl, NULL, 0},
  811. #endif
  812. {"ltp", "", (Function) got_locktopic, NULL, 0},
  813. */
  814. {NULL, NULL, NULL, NULL, 0}
  815. };
  816. void channels_init()
  817. {
  818. timer_create_secs(60, "check_expired_masks", (Function) check_expired_masks);
  819. if (conf.bot->hub) {
  820. timer_create_secs(30, "rebalance_roles", (Function) rebalance_roles);
  821. timer_create_secs(30, "check_should_close", (Function) check_should_close);
  822. #ifdef G_BACKUP
  823. timer_create_secs(30, "check_should_backup", (Function) check_should_backup);
  824. #endif /* G_BACKUP */
  825. }
  826. timer_create_secs(10, "channels_timers", (Function) channels_timers);
  827. add_builtins("dcc", C_dcc_channels);
  828. add_builtins("bot", channels_bot);
  829. add_builtins("chon", my_chon);
  830. }