irc.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2008 Bryan Drewery
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /*
  21. * irc.c -- part of irc.mod
  22. * support for channels within the bot
  23. *
  24. */
  25. #include "src/common.h"
  26. #define MAKING_IRC
  27. #include "irc.h"
  28. #include "src/adns.h"
  29. #include "src/match.h"
  30. #include "src/settings.h"
  31. #include "src/base64.h"
  32. #include "src/tandem.h"
  33. #include "src/net.h"
  34. #include "src/botnet.h"
  35. #include "src/botmsg.h"
  36. #include "src/main.h"
  37. #include "src/response.h"
  38. #include "src/set.h"
  39. #include "src/userrec.h"
  40. #include "src/misc.h"
  41. #include "src/rfc1459.h"
  42. #include "src/socket.h"
  43. #include "src/adns.h"
  44. #include "src/chanprog.h"
  45. #include "src/auth.h"
  46. #include "src/userrec.h"
  47. #include "src/binds.h"
  48. #include "src/userent.h"
  49. #include "src/egg_timer.h"
  50. #include "src/mod/share.mod/share.h"
  51. #include "src/mod/server.mod/server.h"
  52. #include "src/mod/channels.mod/channels.h"
  53. #include "src/mod/ctcp.mod/ctcp.h"
  54. #include <bdlib/src/String.h>
  55. #include <bdlib/src/HashTable.h>
  56. #include <bdlib/src/base64.h>
  57. #include <stdarg.h>
  58. #define PRIO_DEOP 1
  59. #define PRIO_KICK 2
  60. #ifdef CACHE
  61. static cache_t *irccache = NULL;
  62. #endif /* CACHE */
  63. #define do_eI (((now - chan->channel.last_eI) > 30) ? 1 : 0)
  64. static int net_type = 0;
  65. static time_t wait_split = 300; /* Time to wait for user to return from
  66. * net-split. */
  67. int max_bans; /* Modified by net-type 1-4 */
  68. int max_exempts;
  69. int max_invites;
  70. int max_modes; /* Modified by net-type 1-4 */
  71. static bool bounce_bans = 0;
  72. static bool bounce_exempts = 0;
  73. static bool bounce_invites = 0;
  74. static bool bounce_modes = 0;
  75. unsigned int modesperline; /* Number of modes per line to send. */
  76. static size_t mode_buf_len = 200; /* Maximum bytes to send in 1 mode. */
  77. bool use_354 = 0; /* Use ircu's short 354 /who
  78. * responses. */
  79. static bool kick_fun = 0;
  80. static bool ban_fun = 1;
  81. static bool prevent_mixing = 1; /* To prevent mixing old/new modes */
  82. static bool include_lk = 1; /* For correct calculation
  83. * in real_add_mode. */
  84. bd::HashTable<bd::String, unsigned long> bot_counters;
  85. static unsigned long my_counter = 0;
  86. static int
  87. voice_ok(memberlist *m, struct chanset_t *chan)
  88. {
  89. if (m->flags & EVOICE)
  90. return 0;
  91. if (m->userhost[0] && !chan->voice_non_ident && m->userhost[0] == '~')
  92. return 0;
  93. return 1;
  94. }
  95. #include "chan.c"
  96. #include "mode.c"
  97. #include "cmdsirc.c"
  98. #include "msgcmds.c"
  99. static void
  100. detect_offense(memberlist* m, struct chanset_t *chan, char *msg)
  101. {
  102. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  103. struct userrec *u = m->user ? m->user : get_user_by_host(m->userhost);
  104. int i = 0;
  105. //size_t tot = strlen(msg);
  106. get_user_flagrec(u, &fr, chan->dname, chan);
  107. for (; *msg; ++msg) {
  108. if (egg_isupper(*msg))
  109. i++;
  110. }
  111. /* if ((chan->capslimit)) { */
  112. while (((msg) && *msg)) {
  113. if (egg_isupper(*msg))
  114. i++;
  115. msg++;
  116. }
  117. /*
  118. if (chan->capslimit && ((i / tot) >= chan->capslimit)) {
  119. dprintf(DP_MODE, "PRIVMSG %s :flood stats for %s: %d/%d are CAP, percentage: %d\n", chan->name, nick, i, tot, (i/tot)*100);
  120. if ((((i / tot) * 100) >= 50)) {
  121. dprintf(DP_HELP, "PRIVMSG %s :cap flood.\n", chan->dname);
  122. }
  123. */
  124. }
  125. void unlock_chan(struct chanset_t *chan)
  126. {
  127. if (chan->channel.drone_set_mode) {
  128. char buf[3] = "", *p = buf;
  129. if ((chan->channel.drone_set_mode & CHANINV) && !(chan->mode_pls_prot & CHANINV))
  130. *p++ = 'i';
  131. if ((chan->channel.drone_set_mode & CHANMODER) && !(chan->mode_pls_prot & CHANMODER))
  132. *p++ = 'm';
  133. *p = 0;
  134. dprintf(DP_MODE, "MODE %s :-%s\n", chan->name[0] ? chan->name : chan->dname, buf);
  135. }
  136. chan->channel.drone_set_mode = 0;
  137. }
  138. void detected_drone_flood(struct chanset_t* chan, memberlist* m) {
  139. egg_timeval_t howlong;
  140. chan->channel.drone_set_mode = 0;
  141. char buf[3] = "", *p = buf;
  142. if (!(chan->channel.mode & CHANINV) && !(chan->mode_mns_prot & CHANINV)) {
  143. chan->channel.drone_set_mode |= CHANINV;
  144. *p++ = 'i';
  145. }
  146. if (!(chan->channel.mode & CHANMODER) && !(chan->mode_mns_prot & CHANMODER)) {
  147. chan->channel.drone_set_mode |= CHANMODER;
  148. *p++ = 'm';
  149. }
  150. *p = 0;
  151. if (chan->channel.drone_set_mode && buf[0]) {
  152. chan->channel.drone_joins = 0;
  153. chan->channel.drone_jointime = 0;
  154. dprintf(DP_DUMP, "MODE %s +%s\n", chan->name[0] ? chan->name : chan->dname, buf);
  155. howlong.sec = chan->flood_lock_time;
  156. howlong.usec = 0;
  157. timer_create_complex(&howlong, "unlock", (Function) unlock_chan, (void *) chan, 0);
  158. putlog(LOG_MISC, "*", "Flood detected in %s! Locking for %d seconds.", chan->dname, chan->flood_lock_time);
  159. }
  160. }
  161. void notice_invite(struct chanset_t *chan, char *handle, char *nick, char *uhost, bool op) {
  162. char fhandle[21] = "";
  163. const char *ops = " (auto-op)";
  164. if (handle)
  165. simple_snprintf(fhandle, sizeof(fhandle), "\002%s\002 ", handle);
  166. putlog(LOG_MISC, "*", "Invited %s%s(%s%s%s) to %s.", handle ? handle : "", handle ? " " : "", nick, uhost ? "!" : "", uhost ? uhost : "", chan->dname);
  167. dprintf(DP_MODE, "PRIVMSG %s :\001ACTION has invited %s(%s%s%s) to %s.%s\001\n",
  168. chan->name, fhandle, nick, uhost ? "!" : "", uhost ? uhost : "", chan->dname, op ? ops : "");
  169. }
  170. #ifdef CACHE
  171. static cache_t *cache_new(char *nick)
  172. {
  173. cache_t *cache = (cache_t *) my_calloc(1, sizeof(cache_t));
  174. cache->next = NULL;
  175. strlcpy(cache->nick, nick, sizeof(cache->nick));
  176. cache->uhost[0] = 0;
  177. cache->handle[0] = 0;
  178. // cache->user = NULL;
  179. cache->timeval = now;
  180. cache->cchan = NULL;
  181. list_append((struct list_type **) &irccache, (struct list_type *) cache);
  182. return cache;
  183. }
  184. static cache_chan_t *cache_chan_add(cache_t *cache, char *chname)
  185. {
  186. cache_chan_t *cchan = (cache_chan_t *) my_calloc(1, sizeof(cache_chan_t));
  187. cchan->next = NULL;
  188. strlcpy(cchan->dname, chname, sizeof(cchan->dname));
  189. cchan->ban = 0;
  190. cchan->invite = 0;
  191. cchan->invited = 0;
  192. list_append((struct list_type **) &(cache->cchan), (struct list_type *) cchan);
  193. return cchan;
  194. }
  195. static void cache_chan_find(cache_t *cache, cache_chan_t *cchan, char *nick, char *chname)
  196. {
  197. if (!cache)
  198. cache = cache_find(nick);
  199. if (cache) {
  200. for (cchan = cache->cchan; cchan && cchan->dname[0]; cchan = cchan->next) {
  201. if (!rfc_casecmp(cchan->dname, chname)) {
  202. return;
  203. }
  204. }
  205. }
  206. return;
  207. }
  208. static void cache_chan_del(char *nick, char *chname) {
  209. cache_t *cache = NULL;
  210. cache_chan_t *cchan = NULL;
  211. cache_chan_find(cache, cchan, nick, chname);
  212. if (cchan) {
  213. list_delete((struct list_type **) &cache->cchan, (struct list_type *) cchan);
  214. free(cache);
  215. }
  216. }
  217. static cache_t *cache_find(char *nick)
  218. {
  219. cache_t *cache = NULL;
  220. for (cache = irccache; cache && cache->nick[0]; cache = cache->next)
  221. if (!rfc_casecmp(cache->nick, nick))
  222. break;
  223. return cache;
  224. }
  225. static void cache_del(char *nick, cache_t *cache)
  226. {
  227. if (!cache)
  228. cache = cache_find(nick);
  229. if (cache) {
  230. list_delete((struct list_type **) &irccache, (struct list_type *) cache);
  231. free(cache);
  232. }
  233. }
  234. static void cache_debug(void)
  235. {
  236. cache_t *cache = NULL;
  237. cache_chan_t *cchan = NULL;
  238. for (cache = irccache; cache && cache->nick[0]; cache = cache->next) {
  239. dprintf(DP_MODE, "PRIVMSG #wraith :%s!%s (%s)\n", cache->nick, cache->uhost, cache->handle);
  240. for (cchan = cache->cchan; cchan && cchan->dname[0]; cchan = cchan->next)
  241. dprintf(DP_MODE, "PRIVMSG #wraith :%s %d %d %d\n", cchan->dname, cchan->ban, cchan->invite, cchan->invited);
  242. }
  243. }
  244. #endif /* CACHE */
  245. static void cache_invite(struct chanset_t *chan, char *nick, char *host, char *handle, bool op, bool bot)
  246. {
  247. #ifdef CACHE
  248. cache_t *cache = NULL;
  249. if ((cache = cache_find(nick)) == NULL)
  250. cache = cache_new(nick);
  251. cache->bot = bot;
  252. /* if we find they have a host but it doesnt match the new host, wipe it */
  253. if (host && cache->uhost[0] && strcasecmp(cache->uhost, host))
  254. cache->uhost[0] = 0;
  255. if (host && !cache->uhost[0])
  256. strlcpy(cache->uhost, host, sizeof(cache->uhost));
  257. /* if we find they have a handle but it doesnt match the new handle, wipe it */
  258. if (handle && cache->handle[0] && strcasecmp(cache->handle, handle))
  259. cache->handle[0] = 0;
  260. if (handle && !cache->handle[0])
  261. strlcpy(cache->handle, handle, sizeof(cache->handle));
  262. cache_chan_t *cchan = cache_chan_add(cache, chan->dname);
  263. cchan->op = op;
  264. if (!host) {
  265. cchan->invite = 1;
  266. dprintf(DP_MODE, "USERHOST %s\n", nick);
  267. return;
  268. }
  269. /* if we have a uhost already, it's safe to invite them */
  270. cchan->invited = 1;
  271. cchan->invite = 0;
  272. #endif /* CACHE */
  273. dprintf(DP_SERVER, "INVITE %s %s\n", nick, chan->name);
  274. }
  275. static inline const char * cookie_hash(const char* chname, const memberlist* opper, const memberlist* opped, const char* ts, const char* randstring, const char* key) {
  276. char tohash[201] = "";
  277. const char salt2[] = SALT2;
  278. simple_snprintf(tohash, sizeof(tohash), STR("%c%s%c%c%c\n%c%c%s%s%s"),
  279. salt2[0],
  280. ts,
  281. randstring[0], randstring[1], randstring[2], randstring[3],
  282. salt2[15],
  283. opped->nick,
  284. opped->userhost,
  285. key);
  286. #ifdef DEBUG
  287. sdprintf("chname: %s ts: %s randstring: %c%c%c%c", chname, ts, randstring[0], randstring[1], randstring[2], randstring[3]);
  288. sdprintf("tohash: %s", tohash);
  289. #endif
  290. const char* md5 = MD5(tohash);
  291. OPENSSL_cleanse(tohash, sizeof(tohash));
  292. return md5;
  293. }
  294. static inline void cookie_key(char *key, size_t key_len, const char* randstring, const memberlist *opper, const char *chname) {
  295. const char salt1[] = SALT1;
  296. const char salt2[] = SALT2;
  297. simple_snprintf2(key, key_len, STR("%c%c%c%s%c%c%c%c%c%c%^s%c%c%c%c%c%c%c%s"),
  298. randstring[0],
  299. salt1[5],
  300. randstring[3],
  301. opper->user->handle,
  302. randstring[2],
  303. salt1[4],
  304. salt1[0],
  305. salt1[1],
  306. salt1[3],
  307. salt1[6],
  308. chname,
  309. salt1[10],
  310. randstring[1],
  311. salt2[15],
  312. salt2[13],
  313. salt1[10],
  314. salt2[3],
  315. salt2[1],
  316. opper->userhost
  317. );
  318. }
  319. #define HASH_INDEX1(_x) (8 + (_x))
  320. #define HASH_INDEX2(_x) (16 + (_x))
  321. #define HASH_INDEX3(_x) (18 + (_x))
  322. void makecookie(char *out, size_t len, const char *chname, const memberlist* opper, const memberlist* m1, const memberlist* m2, const memberlist* m3) {
  323. char randstring[5] = "", ts[11] = "";
  324. make_rand_str(randstring, 4);
  325. /* &ts[4] is now last 6 digits of time */
  326. simple_snprintf(ts, sizeof(ts), "%010li", (long) (now + timesync));
  327. char cookie_clear[101] = "";
  328. //Increase my counter
  329. ++my_counter;
  330. simple_snprintf2(cookie_clear, sizeof(cookie_clear), STR("%s%s%D"), randstring, &ts[3], my_counter);
  331. char key[150] = "";
  332. cookie_key(key, sizeof(key), randstring, opper, chname);
  333. const char* hash1 = cookie_hash(chname, opper, m1, &ts[4], randstring, key);
  334. const char* hash2 = m2 ? cookie_hash(chname, opper, m2, &ts[4], randstring, key) : NULL;
  335. const char* hash3 = m3 ? cookie_hash(chname, opper, m3, &ts[4], randstring, key) : NULL;
  336. bd::String cookie = encrypt_string(MD5(key), bd::String(cookie_clear));
  337. cookie = bd::base64Encode(cookie);
  338. #ifdef DEBUG
  339. sdprintf("key: %s", key);
  340. sdprintf("cookie_clear: %s", cookie_clear);
  341. sdprintf("hash1: %s", hash1);
  342. if (hash2) sdprintf("hash2: %s", hash2);
  343. if (hash3) sdprintf("hash3: %s", hash3);
  344. #endif
  345. if (m3)
  346. simple_snprintf(out, len + 1, STR("%c%c%c%c%c%c%c%c%c!%s@%s"),
  347. hash1[HASH_INDEX1(0)],
  348. hash1[HASH_INDEX2(0)],
  349. hash1[HASH_INDEX3(0)],
  350. hash2[HASH_INDEX1(1)],
  351. hash2[HASH_INDEX2(1)],
  352. hash2[HASH_INDEX3(1)],
  353. hash3[HASH_INDEX1(2)],
  354. hash3[HASH_INDEX2(2)],
  355. hash3[HASH_INDEX3(2)],
  356. randstring,
  357. cookie.c_str());
  358. else if (m2)
  359. simple_snprintf(out, len + 1, STR("%c%c%c%c%c%c!%s@%s"),
  360. hash1[HASH_INDEX1(0)],
  361. hash1[HASH_INDEX2(0)],
  362. hash1[HASH_INDEX3(0)],
  363. hash2[HASH_INDEX1(1)],
  364. hash2[HASH_INDEX2(1)],
  365. hash2[HASH_INDEX3(1)],
  366. randstring,
  367. cookie.c_str());
  368. else
  369. simple_snprintf(out, len + 1, STR("%c%c%c!%s@%s"),
  370. hash1[HASH_INDEX1(0)],
  371. hash1[HASH_INDEX2(0)],
  372. hash1[HASH_INDEX3(0)],
  373. randstring,
  374. cookie.c_str());
  375. #ifdef DEBUG
  376. sdprintf("cookie: %s", out);
  377. #endif
  378. }
  379. // Clear counter for bot
  380. void counter_clear(const char* botnick) {
  381. bot_counters[botnick] = 0;
  382. }
  383. static inline int checkcookie(const char *chname, const memberlist* opper, const memberlist* opped, const char *cookie, int indexHint) {
  384. #define HOST(_x) (6 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
  385. #define SALT(_x) (1 + (_x) + ((hashes << 1) + hashes)) /* x + (hashes * 3) */
  386. /* How many hashes are in the cookie? */
  387. const size_t hashes = cookie[3] == '!' ? 1 : (cookie[6] == '!' ? 2 : 3);
  388. char key[150] = "";
  389. const char *randstring = &cookie[SALT(0)];
  390. cookie_key(key, sizeof(key), randstring, opper, chname);
  391. bd::String ciphertext = bd::base64Decode((char*) &cookie[HOST(0)]);
  392. bd::String cleartext = decrypt_string(MD5(key), ciphertext);
  393. char ts[8] = "";
  394. strlcpy(ts, cleartext.c_str() + 4, sizeof(ts));
  395. unsigned long counter = base64_to_int(cleartext.c_str() + 4 + 7);
  396. //Lookup counter for the opper
  397. unsigned long last_counter = 0;
  398. // Don't check counter for my own ops as it may have incremented in the queue before seeing the last last counter
  399. bd::String handle;
  400. if (conf.bot->u != opper->user) {
  401. handle = opper->user->handle;
  402. if (bot_counters.contains(handle))
  403. last_counter = bot_counters[handle];
  404. else
  405. last_counter = 0;
  406. }
  407. #ifdef DEBUG
  408. sdprintf("key: %s", key);
  409. sdprintf("plaintext from cookie: %s", cleartext.c_str());
  410. sdprintf("ts from cookie: %s", ts);
  411. if (indexHint == 0) {
  412. sdprintf("last counter from %s: %lu", opper->user->handle, last_counter);
  413. sdprintf("counter from cookie: %lu", counter);
  414. }
  415. #endif
  416. const time_t optime = atol(ts);
  417. if ((((now + timesync) % 10000000) - optime) > 3900)
  418. return BC_SLACK;
  419. //Only check on the first cookie
  420. if (indexHint == 0 && conf.bot->u != opper->user) {
  421. if (counter <= last_counter)
  422. return BC_COUNTER;
  423. //Update counter for the opper
  424. bot_counters[handle] = counter;
  425. }
  426. const char *hash = cookie_hash(chname, opper, opped, &ts[1], randstring, key);
  427. #ifdef DEBUG
  428. sdprintf("hash: %s", hash);
  429. #endif
  430. /* Compare the expected hash to each of the given hashes */
  431. /* indexHint, Which position of the +ooo are we? (1) could be either index (1) or (2).. but not (0). */
  432. /* See if any of the cookies match the hash we want */
  433. for (size_t i = indexHint; i < hashes; ++i) {
  434. const char *cookie_index = cookie + ((i << 1) + i); /* i * 3 */
  435. if ((hash[HASH_INDEX1(i)] == cookie_index[0] &&
  436. hash[HASH_INDEX2(i)] == cookie_index[1] &&
  437. hash[HASH_INDEX3(i)] == cookie_index[2])) {
  438. return 0;
  439. }
  440. }
  441. /* None matched -> failure */
  442. return BC_HASH;
  443. #undef HOST
  444. #undef SALT
  445. }
  446. /*
  447. opreq = o #chan nick
  448. inreq = i #chan nick uhost
  449. inreq keyreply = K #chan key
  450. */
  451. void
  452. getin_request(char *botnick, char *code, char *par)
  453. {
  454. if (!server_online)
  455. return;
  456. if (!par[0] || !par)
  457. return;
  458. char *what = newsplit(&par), *chname = newsplit(&par);
  459. if (!chname[0] || !chname)
  460. return;
  461. char *tmp = newsplit(&par); /* nick */
  462. if (!tmp[0])
  463. return;
  464. char nick[NICKLEN] = "";
  465. strlcpy(nick, tmp, sizeof(nick));
  466. const char *type = what[0] == 'o' ? "op" : "in", *desc = what[0] == 'o' ? "on" : "for";
  467. struct chanset_t *chan = findchan_by_dname(chname);
  468. if (!chan) {
  469. putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s which is not a valid channel!", type, botnick, nick, desc, chname);
  470. return;
  471. }
  472. struct userrec *u = get_user_by_handle(userlist, botnick);
  473. if (!u) {
  474. putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - No user called %s in userlist", type, botnick, nick, desc,
  475. chan->dname, botnick);
  476. return;
  477. }
  478. if (server_lag > lag_threshold) {
  479. putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - I'm too lagged", type, botnick, nick, desc, chan->dname);
  480. return;
  481. }
  482. if (what[0] != 'K') {
  483. if (!(channel_pending(chan) || channel_active(chan))) {
  484. putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - I'm not on %s right now.", type, botnick, nick, desc,
  485. chan->dname, chan->dname);
  486. return;
  487. }
  488. }
  489. memberlist* mem = ismember(chan, nick);
  490. if (mem && chan_issplit(mem)) {
  491. putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - %s is split", type, botnick, nick, desc, chan->dname, nick);
  492. return;
  493. }
  494. if (what[0] == 'K') {
  495. if (!shouldjoin(chan)) {
  496. putlog(LOG_GETIN, "*", "Got key for %s from %s - I shouldn't be on that chan?!?", chan->dname, botnick);
  497. } else {
  498. if (!(channel_pending(chan) || channel_active(chan))) {
  499. /* Cache the key */
  500. free(chan->channel.key);
  501. chan->channel.key = strdup(nick);
  502. putlog(LOG_GETIN, "*", "Got key for %s from %s (%s) - Joining", chan->dname, botnick, chan->channel.key);
  503. dprintf(DP_MODE, "JOIN %s %s\n", chan->name[0] ? chan->name : chan->dname, chan->channel.key);
  504. chan->status |= CHAN_JOINING;
  505. } else {
  506. putlog(LOG_GETIN, "*", "Got key for %s from %s - I'm already in the channel", chan->dname, botnick);
  507. }
  508. }
  509. return;
  510. }
  511. char uhost[UHOSTLEN] = "";
  512. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  513. tmp = newsplit(&par); /* userhost */
  514. if (tmp[0])
  515. strlcpy(uhost, tmp, sizeof(uhost));
  516. if (what[0] == 'o') {
  517. if (!me_op(chan)) {
  518. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - I haven't got ops", botnick, nick, chan->dname);
  519. return;
  520. }
  521. if (!mem) {
  522. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - %s isn't on %s", botnick, nick, chan->dname, nick, chan->dname);
  523. return;
  524. }
  525. if (chan_hasop(mem)) {
  526. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - %s already has ops", botnick, nick, chan->dname, nick);
  527. return;
  528. }
  529. if (chan_sentop(mem)) {
  530. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Already sent a +o", botnick, nick, chan->dname);
  531. return;
  532. }
  533. member_getuser(mem);
  534. if (mem->user != u) {
  535. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - user mismatch: (%s)/(%s)", botnick, nick, chan->dname, u ? u->handle : "*", mem->user ? mem->user->handle : "*");
  536. return;
  537. }
  538. get_user_flagrec(u, &fr, chan->dname, chan);
  539. if (!chk_op(fr, chan)) {
  540. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - %s doesnt have +o for chan.", botnick, nick, chan->dname, botnick);
  541. return;
  542. }
  543. if (glob_kick(fr) || chan_kick(fr)) {
  544. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - %s is currently being autokicked.", botnick, nick, chan->dname, botnick);
  545. return;
  546. }
  547. if (chan->channel.no_op) {
  548. if (chan->channel.no_op > now) /* dont op until this time has passed */
  549. return;
  550. else
  551. chan->channel.no_op = 0;
  552. }
  553. do_op(nick, chan, 0, 1);
  554. putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
  555. } else if (what[0] == 'i') {
  556. if (mem) {
  557. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s is already on %s", botnick, nick, chan->dname, nick, chan->dname);
  558. return;
  559. }
  560. get_user_flagrec(u, &fr, chan->dname, chan);
  561. if (!chk_op(fr, chan) || chan_kick(fr) || glob_kick(fr)) {
  562. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s doesn't have acces for chan.", botnick, nick, chan->dname, botnick);
  563. return;
  564. }
  565. if (chan->channel.mode & CHANKEY) {
  566. char *key = chan->channel.key[0] ? chan->channel.key : chan->key_prot;
  567. size_t siz = strlen(chan->dname) + strlen(key ? key : 0) + 6 + 1;
  568. tmp = (char *) my_calloc(1, siz);
  569. simple_snprintf(tmp, siz, "gi K %s %s", chan->dname, key ? key : "");
  570. putbot(botnick, tmp);
  571. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Sent key (%s)", botnick, nick, chan->dname, key ? key : "");
  572. free(tmp);
  573. }
  574. if (!me_op(chan)) {
  575. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
  576. return;
  577. }
  578. bool sendi = 0;
  579. if (chan->channel.maxmembers) {
  580. int lim = chan->channel.members + 5, curlim = chan->channel.maxmembers;
  581. if (curlim < lim) {
  582. char s2[6] = "";
  583. sendi = 1;
  584. simple_snprintf(s2, sizeof(s2), "%d", lim);
  585. add_mode(chan, '+', 'l', s2);
  586. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit to %d", botnick, nick, chan->dname, lim);
  587. }
  588. }
  589. char uip[UHOSTLEN] = "";
  590. tmp = newsplit(&par); /* userip */
  591. if (tmp[0])
  592. simple_snprintf(uip, sizeof uip, "%s!%s", nick, tmp);
  593. struct maskrec **mr = NULL, *tmr = NULL;
  594. /* Check internal global bans */
  595. mr = &global_bans;
  596. while (*mr) {
  597. if (wild_match((*mr)->mask, uhost) ||
  598. wild_match((*mr)->mask, uip) ||
  599. match_cidr((*mr)->mask, uip)) {
  600. if (!noshare)
  601. shareout("-m b %s\n", (*mr)->mask);
  602. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Removed permanent global ban %s", botnick, nick,
  603. chan->dname, (*mr)->mask);
  604. free((*mr)->mask);
  605. if ((*mr)->desc)
  606. free((*mr)->desc);
  607. if ((*mr)->user)
  608. free((*mr)->user);
  609. tmr = *mr;
  610. *mr = (*mr)->next;
  611. free(tmr);
  612. } else {
  613. mr = &((*mr)->next);
  614. }
  615. }
  616. /* Check internal channel bans */
  617. mr = &chan->bans;
  618. while (*mr) {
  619. if (wild_match((*mr)->mask, uhost) ||
  620. wild_match((*mr)->mask, uip) ||
  621. match_cidr((*mr)->mask, uip)) {
  622. if (!noshare)
  623. shareout("-mc b %s %s\n", chan->dname, (*mr)->mask);
  624. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Removed permanent channel ban %s", botnick, nick,
  625. chan->dname, (*mr)->mask);
  626. free((*mr)->mask);
  627. if ((*mr)->desc)
  628. free((*mr)->desc);
  629. if ((*mr)->user)
  630. free((*mr)->user);
  631. tmr = *mr;
  632. *mr = (*mr)->next;
  633. free(tmr);
  634. } else {
  635. mr = &((*mr)->next);
  636. }
  637. }
  638. /* Check bans active in channel */
  639. for (struct maskstruct *b = chan->channel.ban; b->mask[0]; b = b->next) {
  640. if (wild_match(b->mask, uhost) ||
  641. wild_match(b->mask, uip) ||
  642. match_cidr(b->mask, uip)) {
  643. add_mode(chan, '-', 'b', b->mask);
  644. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Removed active ban %s", botnick, nick, chan->dname,
  645. b->mask);
  646. sendi = 1;
  647. }
  648. }
  649. if (chan->channel.mode & CHANINV) {
  650. sendi = 1;
  651. putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Invited", botnick, nick, chan->dname);
  652. }
  653. if (sendi)
  654. dprintf(DP_MODE, "INVITE %s %s\n", nick, chan->name[0] ? chan->name : chan->dname);
  655. }
  656. }
  657. static void
  658. request_op(struct chanset_t *chan)
  659. {
  660. if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan))))
  661. return;
  662. if (chan->channel.no_op) {
  663. if (chan->channel.no_op > now) /* dont op until this time has passed */
  664. return;
  665. else
  666. chan->channel.no_op = 0;
  667. }
  668. chan->channel.do_opreq = 0;
  669. /* check server lag */
  670. if (server_lag > lag_threshold) {
  671. putlog(LOG_GETIN, "*", "Not asking for ops on %s - I'm too lagged", chan->dname);
  672. chan->channel.no_op = now + 10;
  673. return;
  674. }
  675. /* Check if my hostmask is recognized (every 10th time) */
  676. static int check_hostmask_cnt = 10;
  677. if (check_hostmask_cnt++ == 10) {
  678. check_hostmask();
  679. check_hostmask_cnt = 0;
  680. }
  681. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
  682. get_user_flagrec(conf.bot->u, &fr, chan->dname, chan);
  683. if (!chk_op(fr, chan) || glob_kick(fr) || chan_kick(fr)) {
  684. putlog(LOG_GETIN, "*", "Not requesting op for %s - I do not have access to that channel.", chan->dname);
  685. chan->channel.no_op = now + 10;
  686. return;
  687. }
  688. int i = 0, my_exp = 0, first = 100;
  689. time_t n = now;
  690. /* max OPREQ_COUNT requests per OPREQ_SECONDS sec */
  691. while (i < 5) {
  692. if (n - chan->opreqtime[i] > op_requests.time) {
  693. if (first > i)
  694. first = i;
  695. my_exp++;
  696. chan->opreqtime[i] = 0;
  697. }
  698. i++;
  699. }
  700. if ((5 - my_exp) >= op_requests.count) {
  701. putlog(LOG_GETIN, "*", "Delaying opreq for %s - Maximum of %d:%d reached", chan->dname, op_requests.count,
  702. op_requests.time);
  703. chan->channel.no_op = now + op_requests.time + 1;
  704. return;
  705. }
  706. int cnt = op_bots, i2 = 0;
  707. memberlist *ml = NULL, *botops[MAX_BOTS];
  708. char s[UHOSTLEN] = "";
  709. for (i = 0, ml = chan->channel.member; (i < MAX_BOTS) && ml && ml->nick[0]; ml = ml->next) {
  710. if (!chan_hasop(ml) || chan_issplit(ml))
  711. continue;
  712. member_getuser(ml, 1);
  713. if (!ml->user || !ml->user->bot)
  714. continue;
  715. /* Is the bot linked? */
  716. if (findbot(ml->user->handle))
  717. botops[i++] = ml;
  718. }
  719. if (!i) {
  720. if (channel_active(chan) && !channel_pending(chan)) {
  721. chan->channel.no_op = now + op_requests.time;
  722. putlog(LOG_GETIN, "*", "No one to ask for ops on %s - Delaying requests for %d seconds.", chan->dname, op_requests.time);
  723. }
  724. return;
  725. }
  726. char l[1024] = "";
  727. size_t len = 0;
  728. /* first scan for bots on my server, ask first found for ops */
  729. simple_snprintf(s, sizeof(s), "gi o %s %s", chan->dname, botname);
  730. /* look for bots 0-1 hops away */
  731. for (i2 = 0; i2 < i; i2++) {
  732. if (botops[i2]->hops < 2) {
  733. putbot(botops[i2]->user->handle, s);
  734. chan->opreqtime[first] = n;
  735. if (l[0])
  736. len += strlcpy(l + len, ", ", sizeof(l) - len);
  737. len += strlcpy(l + len, botops[i2]->user->handle, sizeof(l) - len);
  738. len += strlcpy(l + len, "/", sizeof(l) - len);
  739. len += strlcpy(l + len, botops[i2]->nick, sizeof(l) - len);
  740. botops[i2] = NULL;
  741. --cnt;
  742. break;
  743. }
  744. }
  745. /* Pick random op and ask for ops */
  746. while (cnt) {
  747. i2 = randint(i);
  748. if (botops[i2]) {
  749. putbot(botops[i2]->user->handle, s);
  750. chan->opreqtime[first] = n;
  751. if (l[0])
  752. len += strlcpy(l + len, ", ", sizeof(l) - len);
  753. len += strlcpy(l + len, botops[i2]->user->handle, sizeof(l) - len);
  754. len += strlcpy(l + len, "/", sizeof(l) - len);
  755. len += strlcpy(l + len, botops[i2]->nick, sizeof(l) - len);
  756. --cnt;
  757. botops[i2] = NULL;
  758. } else {
  759. if (i < op_bots)
  760. cnt--;
  761. }
  762. }
  763. l[len] = 0;
  764. putlog(LOG_GETIN, "*", "Requested ops on %s from %s", chan->dname, l);
  765. }
  766. static void
  767. request_in(struct chanset_t *chan)
  768. {
  769. /* Lag situation */
  770. if (!shouldjoin(chan))
  771. return;
  772. /* Check if my hostmask is recognized (every 10th time) */
  773. static int check_hostmask_cnt = 10;
  774. if (check_hostmask_cnt++ == 10) {
  775. check_hostmask();
  776. check_hostmask_cnt = 0;
  777. }
  778. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
  779. get_user_flagrec(conf.bot->u, &fr, chan->dname, chan);
  780. if (!chk_op(fr, chan) || glob_kick(fr) || chan_kick(fr)) {
  781. putlog(LOG_GETIN, "*", "Not requesting help to join %s - I do not have access to that channel.", chan->dname);
  782. return;
  783. }
  784. int foundBots = 0;
  785. char* botops[MAX_BOTS];
  786. for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
  787. if (bot->hub || !bot->u)
  788. continue;
  789. get_user_flagrec(bot->u, &fr, chan->dname, chan);
  790. if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan))
  791. botops[foundBots++] = bot->bot;
  792. }
  793. if (!foundBots) {
  794. putlog(LOG_GETIN, "*", "No bots available, can't request help to join %s", chan->dname);
  795. return;
  796. }
  797. int cnt = foundBots < in_bots ? foundBots : in_bots;
  798. char s[255] = "";
  799. char l[1024] = "";
  800. size_t len = 0;
  801. simple_snprintf(s, sizeof(s), "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
  802. shuffleArray(botops, foundBots);
  803. for (int n = 0; n < cnt; ++n) {
  804. putbot(botops[n], s);
  805. if (l[0])
  806. len += strlcpy(l + len, ", ", sizeof(l) - len);
  807. len += strlcpy(l + len, botops[n], sizeof(l) - len);
  808. }
  809. l[len] = 0;
  810. putlog(LOG_GETIN, "*", "Requested help to join %s from %s", chan->dname, l);
  811. }
  812. #ifdef REVENGE
  813. /* Contains the logic to decide wether we want to punish someone. Returns
  814. * true (1) if we want to, false (0) if not.
  815. */
  816. static bool
  817. want_to_revenge(struct chanset_t *chan, struct userrec *u,
  818. struct userrec *u2, char *badnick, char *victimstr, bool mevictim)
  819. {
  820. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  821. /* Do not take revenge upon ourselves. */
  822. if (match_my_nick(badnick))
  823. return 0;
  824. get_user_flagrec(u, &fr, chan->dname, chan);
  825. /* Kickee didn't kick themself? */
  826. if (rfc_casecmp(badnick, victimstr)) {
  827. /* They kicked me? */
  828. if (mevictim) {
  829. /* ... and I'm allowed to take revenge? <snicker> */
  830. if (channel_revengebot(chan))
  831. return 1;
  832. /* Do we revenge for our users ... and do we actually know the victim? */
  833. } else if (channel_revenge(chan) && u2) {
  834. struct flag_record fr2 = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  835. get_user_flagrec(u2, &fr2, chan->dname, chan);
  836. /* Protecting friends? */
  837. /* Protecting ops? */
  838. if ((channel_protectops(chan) && chk_op(fr2, chan))
  839. return 1;
  840. }
  841. }
  842. return 0;
  843. }
  844. /* Dependant on revenge_mode, punish the offender.
  845. */
  846. static void
  847. punish_badguy(struct chanset_t *chan, char *whobad,
  848. struct userrec *u, char *badnick, char *victimstr, bool mevictim, int type)
  849. {
  850. memberlist *m = ismember(chan, badnick);
  851. if (!m)
  852. return;
  853. char reason[1024] = "", ct[81] = "", *kick_msg = NULL;
  854. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  855. get_user_flagrec(u, &fr, chan->dname, chan);
  856. /* Get current time into a string */
  857. strftime(ct, sizeof ct, "%d %b %Z", gmtime(&now));
  858. /* Put together log and kick messages */
  859. reason[0] = 0;
  860. switch (type) {
  861. case REVENGE_KICK:
  862. kick_msg = "don't kick my friends, bud";
  863. simple_snprintf(reason, sizeof(reason), "kicked %s off %s", victimstr, chan->dname);
  864. break;
  865. case REVENGE_DEOP:
  866. simple_snprintf(reason, sizeof(reason), "deopped %s on %s", victimstr, chan->dname);
  867. kick_msg = "don't deop my friends, bud";
  868. break;
  869. default:
  870. kick_msg = "revenge!";
  871. }
  872. putlog(LOG_MISC, chan->dname, "Punishing %s (%s)", badnick, reason);
  873. /* Set the offender +d */
  874. if ((chan->revenge_mode > 0) &&
  875. /* ... unless there's no more to do */
  876. !(chan_deop(fr) || glob_deop(fr))) {
  877. char s[UHOSTLEN], s1[UHOSTLEN];
  878. memberlist *mx = NULL;
  879. /* Removing op */
  880. if (chk_op(fr, chan)) {
  881. fr.match = FR_CHAN;
  882. if (chan_op(fr)) {
  883. fr.chan &= ~USER_OP;
  884. } else {
  885. fr.chan |= USER_DEOP;
  886. }
  887. set_user_flagrec(u, &fr, chan->dname);
  888. putlog(LOG_MISC, "*", "No longer opping %s[%s] (%s)", u->handle, whobad, reason);
  889. }
  890. /* ... or just setting to deop */
  891. else if (u) {
  892. /* In the user list already, cool :) */
  893. fr.match = FR_CHAN;
  894. fr.chan |= USER_DEOP;
  895. set_user_flagrec(u, &fr, chan->dname);
  896. simple_snprintf(s, sizeof(s), "(%s) %s", ct, reason);
  897. putlog(LOG_MISC, "*", "Now deopping %s[%s] (%s)", u->handle, whobad, s);
  898. }
  899. /* ... or creating new user and setting that to deop */
  900. else {
  901. strlcpy(s1, whobad, sizeof(s1));
  902. maskhost(s1, s);
  903. strlcpy(s1, badnick, sizeof(s1));
  904. /* If that handle exists use "badX" (where X is an increasing number)
  905. * instead.
  906. */
  907. while (get_user_by_handle(userlist, s1)) {
  908. if (!strncmp(s1, "bad", 3)) {
  909. int i;
  910. i = atoi(s1 + 3);
  911. simple_snprintf(s1 + 3, sizeof(s1) - 3, "%d", i + 1);
  912. } else
  913. strlcpy(s1, "bad1", sizeof(s1)); /* Start with '1' */
  914. }
  915. userlist = adduser(userlist, s1, s, "-", 0, 0);
  916. fr.match = FR_CHAN;
  917. fr.chan = USER_DEOP;
  918. u = get_user_by_handle(userlist, s1);
  919. if ((mx = ismember(chan, badnick)))
  920. mx->user = u;
  921. set_user_flagrec(u, &fr, chan->dname);
  922. simple_snprintf(s, sizeof(s), "(%s) %s (%s)", ct, reason, whobad);
  923. set_user(&USERENTRY_COMMENT, u, (void *) s);
  924. putlog(LOG_MISC, "*", "Now deopping %s (%s)", whobad, reason);
  925. }
  926. }
  927. /* Always try to deop the offender */
  928. if (!mevictim)
  929. add_mode(chan, '-', 'o', badnick);
  930. /* Ban. Should be done before kicking. */
  931. if (chan->revenge_mode > 2) {
  932. char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
  933. splitnick(&whobad);
  934. maskhost(whobad, s1);
  935. simple_snprintf(s, sizeof(s), "(%s) %s", ct, reason);
  936. u_addmask('b', chan, s1, conf.bot->nick, s, now + (60 * chan->ban_time), 0);
  937. if (!mevictim && me_op(chan)) {
  938. add_mode(chan, '+', 'b', s1);
  939. flush_mode(chan, QUICK);
  940. }
  941. }
  942. /* Kick the offender */
  943. if ((chan->revenge_mode > 1) && !chan_sentkick(m) &&
  944. /* ... and can I actually do anything about it? */
  945. me_op(chan) && !mevictim) {
  946. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, response(RES_MEAN));
  947. m->flags |= SENTKICK;
  948. }
  949. }
  950. /* Punishes bad guys under certain circumstances using methods as defined
  951. * by the revenge_mode flag.
  952. */
  953. static void
  954. maybe_revenge(struct chanset_t *chan, char *whobad, char *whovictim, int type)
  955. {
  956. if (!chan || (type < 0))
  957. return;
  958. /* Get info about offender */
  959. struct userrec *u = get_user_by_host(whobad), *u2 = NULL;
  960. char *badnick = splitnick(&whobad), *victimstr = NULL;
  961. bool mevictim;
  962. /* Get info about victim */
  963. u2 = get_user_by_host(whovictim);
  964. victimstr = splitnick(&whovictim);
  965. mevictim = match_my_nick(victimstr);
  966. /* Do we want to revenge? */
  967. if (!want_to_revenge(chan, u, u2, badnick, victimstr, mevictim))
  968. return; /* No, leave them alone ... */
  969. /* Haha! Do the vengeful thing ... */
  970. punish_badguy(chan, whobad, u, badnick, victimstr, mevictim, type);
  971. }
  972. #endif
  973. /* Set the key.
  974. */
  975. static void
  976. my_setkey(struct chanset_t *chan, char *k)
  977. {
  978. free(chan->channel.key);
  979. if (k == NULL) {
  980. chan->channel.key = (char *) my_calloc(1, 1);
  981. return;
  982. }
  983. chan->channel.key = strdup(k);
  984. }
  985. /* Adds a ban, exempt or invite mask to the list
  986. * m should be chan->channel.(exempt|invite|ban)
  987. */
  988. static bool
  989. new_mask(masklist *m, char *s, char *who)
  990. {
  991. for (; m && m->mask[0] && rfc_casecmp(m->mask, s); m = m->next) ;
  992. if (m->mask[0])
  993. return 1; /* Already existent mask */
  994. m->next = (masklist *) my_calloc(1, sizeof(masklist));
  995. m->next->next = NULL;
  996. m->next->mask = (char *) my_calloc(1, 1);
  997. free(m->mask);
  998. m->mask = strdup(s);
  999. m->who = strdup(who);
  1000. m->timer = now;
  1001. return 0;
  1002. }
  1003. /* Removes a nick from the channel member list (returns 1 if successful)
  1004. */
  1005. static bool
  1006. killmember(struct chanset_t *chan, char *nick)
  1007. {
  1008. memberlist *x = NULL, *old = NULL;
  1009. for (x = chan->channel.member; x && x->nick[0]; old = x, x = x->next)
  1010. if (!rfc_casecmp(x->nick, nick))
  1011. break;
  1012. if (!x || !x->nick[0]) {
  1013. if (!channel_pending(chan))
  1014. putlog(LOG_MISC, "*", "(!) killmember(%s, %s) -> nonexistent", chan->dname, nick);
  1015. return 0;
  1016. }
  1017. if (old)
  1018. old->next = x->next;
  1019. else
  1020. chan->channel.member = x->next;
  1021. free(x);
  1022. chan->channel.members--;
  1023. /* The following two errors should NEVER happen. We will try to correct
  1024. * them though, to keep the bot from crashing.
  1025. */
  1026. if (chan->channel.members < 0) {
  1027. chan->channel.members = 0;
  1028. for (x = chan->channel.member; x && x->nick[0]; x = x->next)
  1029. chan->channel.members++;
  1030. putlog(LOG_MISC, "*", "(!) actually I know of %d members.", chan->channel.members);
  1031. }
  1032. if (!chan->channel.member) {
  1033. chan->channel.member = (memberlist *) my_calloc(1, sizeof(memberlist));
  1034. chan->channel.member->nick[0] = 0;
  1035. chan->channel.member->next = NULL;
  1036. }
  1037. return 1;
  1038. }
  1039. /* Check if I am a chanop. Returns boolean 1 or 0.
  1040. */
  1041. bool
  1042. me_op(struct chanset_t *chan)
  1043. {
  1044. memberlist *mx = ismember(chan, botname);
  1045. if (!mx)
  1046. return 0;
  1047. if (chan_hasop(mx))
  1048. return 1;
  1049. else
  1050. return 0;
  1051. }
  1052. /* Check whether I'm voice. Returns boolean 1 or 0.
  1053. */
  1054. static bool
  1055. me_voice(struct chanset_t *chan)
  1056. {
  1057. memberlist *mx = ismember(chan, botname);
  1058. if (!mx)
  1059. return 0;
  1060. if (chan_hasvoice(mx))
  1061. return 1;
  1062. else
  1063. return 0;
  1064. }
  1065. /* Check if there are any ops on the channel. Returns boolean 1 or 0.
  1066. */
  1067. static bool
  1068. any_ops(struct chanset_t *chan)
  1069. {
  1070. memberlist *x = NULL;
  1071. for (x = chan->channel.member; x && x->nick[0]; x = x->next)
  1072. if (chan_hasop(x))
  1073. break;
  1074. if (!x || !x->nick[0])
  1075. return 0;
  1076. return 1;
  1077. }
  1078. /* Reset the channel information.
  1079. */
  1080. void
  1081. reset_chan_info(struct chanset_t *chan)
  1082. {
  1083. if (!chan) return;
  1084. if (!chan->name[0])
  1085. strlcpy(chan->name, chan->dname, 81);
  1086. /* Don't reset the channel if we're already resetting it */
  1087. if (!shouldjoin(chan)) {
  1088. dprintf(DP_MODE, "PART %s\n", chan->name);
  1089. return;
  1090. }
  1091. if (!channel_pending(chan)) {
  1092. bool opped = me_op(chan) ? 1 : 0;
  1093. free(chan->channel.key);
  1094. chan->channel.key = (char *) my_calloc(1, 1);
  1095. clear_channel(chan, 1);
  1096. chan->status |= CHAN_PEND;
  1097. chan->status &= ~(CHAN_ACTIVE | CHAN_ASKEDMODES | CHAN_JOINING);
  1098. /* don't bother checking bans if it's +take */
  1099. if (!channel_take(chan)) {
  1100. if (opped) {
  1101. if (!(chan->status & CHAN_ASKEDBANS)) {
  1102. chan->status |= CHAN_ASKEDBANS;
  1103. dprintf(DP_MODE, "MODE %s +b\n", chan->name);
  1104. }
  1105. if (do_eI) {
  1106. chan->channel.last_eI = now;
  1107. if (!(chan->ircnet_status & CHAN_ASKED_EXEMPTS) && use_exempts == 1) {
  1108. chan->ircnet_status |= CHAN_ASKED_EXEMPTS;
  1109. dprintf(DP_MODE, "MODE %s +e\n", chan->name);
  1110. }
  1111. if (!(chan->ircnet_status & CHAN_ASKED_INVITES) && use_invites == 1) {
  1112. chan->ircnet_status |= CHAN_ASKED_INVITES;
  1113. dprintf(DP_MODE, "MODE %s +I\n", chan->name);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. /* These 2 need to get out asap, so into the mode queue */
  1119. dprintf(DP_MODE, "MODE %s\n", chan->name);
  1120. send_chan_who(DP_MODE, chan);
  1121. /* clear_channel nuked the data...so */
  1122. dprintf(DP_MODE, "TOPIC %s\n", chan->name);
  1123. }
  1124. }
  1125. static void send_chan_who(int queue, struct chanset_t *chan) {
  1126. if (use_354) /* Added benefit of getting numeric IP! :) */
  1127. dprintf(queue, "WHO %s %%c%%h%%n%%u%%f%%r%%d%%i\n", chan->name);
  1128. else
  1129. dprintf(queue, "WHO %s\n", chan->name);
  1130. }
  1131. /* If i'm the only person on the channel, and i'm not op'd,
  1132. * might as well leave and rejoin. If i'm NOT the only person
  1133. * on the channel, but i'm still not op'd, demand ops.
  1134. */
  1135. static void
  1136. check_lonely_channel(struct chanset_t *chan)
  1137. {
  1138. if (channel_pending(chan) || !channel_active(chan) || me_op(chan) ||
  1139. !shouldjoin(chan) || (chan->channel.mode & CHANANON))
  1140. return;
  1141. memberlist *m = NULL;
  1142. char s[UHOSTLEN] = "";
  1143. int i = 0;
  1144. static int whined = 0;
  1145. /* Count non-split channel members */
  1146. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  1147. if (!chan_issplit(m))
  1148. i++;
  1149. if (i == 1 && channel_cycle(chan) && !channel_stop_cycle(chan)) {
  1150. if (chan->name[0] != '+') { /* Its pointless to cycle + chans for ops */
  1151. putlog(LOG_MISC, "*", "Trying to cycle %s to regain ops.", chan->dname);
  1152. dprintf(DP_MODE, "PART %s\n", chan->name);
  1153. /* If it's a !chan, we need to recreate the channel with !!chan <cybah> */
  1154. dprintf(DP_MODE, "JOIN %s%s %s\n", (chan->dname[0] == '!') ? "!" : "", chan->dname, chan->key_prot);
  1155. chan->status |= CHAN_JOINING;
  1156. whined = 0;
  1157. }
  1158. } else if (any_ops(chan)) {
  1159. whined = 0;
  1160. request_op(chan);
  1161. /* need: op */
  1162. } else {
  1163. /* Other people here, but none are ops. If there are other bots make
  1164. * them LEAVE!
  1165. */
  1166. bool ok = 1;
  1167. struct userrec *u = NULL;
  1168. if (!whined) {
  1169. /* + is opless. Complaining about no ops when without special
  1170. * help(services), we cant get them - Raist
  1171. */
  1172. if (chan->name[0] != '+')
  1173. putlog(LOG_MISC, "*", "%s is active but has no ops :(", chan->dname);
  1174. whined = 1;
  1175. }
  1176. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1177. simple_snprintf(s, sizeof(s), "%s!%s", m->nick, m->userhost);
  1178. u = get_user_by_host(s);
  1179. if (!match_my_nick(m->nick) && (!u || !u->bot)) {
  1180. ok = 0;
  1181. break;
  1182. }
  1183. }
  1184. if (ok && channel_cycle(chan)) {
  1185. /* ALL bots! make them LEAVE!!! */
  1186. /*
  1187. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  1188. if (!match_my_nick(m->nick))
  1189. dprintf(DP_SERVER, "PRIVMSG %s :go %s\n", m->nick, chan->dname);
  1190. */
  1191. } else {
  1192. /* Some humans on channel, but still op-less */
  1193. request_op(chan);
  1194. /* need: op */
  1195. }
  1196. }
  1197. }
  1198. static void
  1199. warn_pls_take(struct chanset_t *chan)
  1200. {
  1201. if (channel_take(chan) && me_op(chan))
  1202. putlog(LOG_WARN, "*", "%s is set +take, and I'm already opped! +take is insecure, try +bitch instead",
  1203. chan->dname);
  1204. }
  1205. /* FIXME: max sendq will occur. */
  1206. static void
  1207. check_servers(struct chanset_t *chan)
  1208. {
  1209. for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1210. if (!match_my_nick(m->nick) && chan_hasop(m) && (m->hops == -1)) {
  1211. putlog(LOG_DEBUG, "*", "Updating WHO for '%s' because '%s' is missing data.", chan->dname, m->nick);
  1212. send_chan_who(DP_HELP, chan);
  1213. break; /* lets just do one chan at a time to save from flooding */
  1214. }
  1215. }
  1216. }
  1217. static void
  1218. check_netfight(struct chanset_t *chan)
  1219. {
  1220. if (fight_threshold) {
  1221. if ((chan->channel.fighting) && (chan->channel.fighting > fight_threshold)) {
  1222. if (!chan_bitch(chan) || !channel_closed(chan)) {
  1223. putlog(LOG_WARN, "*", "Auto-closed %s - channel fight", chan->dname);
  1224. do_chanset(NULL, chan, "+bitch +closed +backup", DO_LOCAL | DO_NET);
  1225. enforce_closed(chan);
  1226. dprintf(DP_MODE, "TOPIC %s :Auto-closed - channel fight\n", chan->name);
  1227. }
  1228. }
  1229. }
  1230. chan->channel.fighting = 0; /* we put this here because we need to clear it once per min */
  1231. }
  1232. void
  1233. raise_limit(struct chanset_t *chan)
  1234. {
  1235. if (!chan || !me_op(chan))
  1236. return;
  1237. /* Don't bother setting limit if the user has set a protect -l */
  1238. if (chan->mode_mns_prot & CHANLIMIT)
  1239. return;
  1240. int nl = chan->channel.members + chan->limitraise; /* new limit */
  1241. int i = chan->limitraise >> 2; /* DIV 4 */
  1242. /* if the newlimit will be in the range made by these vars, dont change. */
  1243. int ul = nl + i; /* upper limit */
  1244. int ll = nl - i; /* lower limit */
  1245. if ((chan->channel.maxmembers > ll) && (chan->channel.maxmembers < ul))
  1246. return; /* the current limit is in the range, so leave it. */
  1247. if (nl != chan->channel.maxmembers) {
  1248. char s[6] = "";
  1249. simple_snprintf(s, sizeof(s), "%d", nl);
  1250. add_mode(chan, '+', 'l', s);
  1251. }
  1252. }
  1253. static void
  1254. check_expired_chanstuff(struct chanset_t *chan)
  1255. {
  1256. if ((channel_active(chan) || channel_pending(chan)) && !shouldjoin(chan)) {
  1257. dprintf(DP_MODE, "PART %s\n", chan->name[0] ? chan->name : chan->dname);
  1258. } else if (channel_active(chan)) {
  1259. masklist *b = NULL, *e = NULL;
  1260. memberlist *m = NULL, *n = NULL;
  1261. char s[UHOSTLEN] = "";
  1262. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1263. if (me_op(chan)) {
  1264. if (channel_dynamicbans(chan) && chan->ban_time)
  1265. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1266. if (now - b->timer > 60 * chan->ban_time &&
  1267. !u_sticky_mask(chan->bans, b->mask) &&
  1268. !u_sticky_mask(global_bans, b->mask) && expired_mask(chan, b->who)) {
  1269. putlog(LOG_MODES, chan->dname, "(%s) Channel ban on %s expired.", chan->dname, b->mask);
  1270. add_mode(chan, '-', 'b', b->mask);
  1271. b->timer = now;
  1272. }
  1273. if (use_exempts && channel_dynamicexempts(chan) && chan->exempt_time)
  1274. for (e = chan->channel.exempt; e->mask[0]; e = e->next)
  1275. if (now - e->timer > 60 * chan->exempt_time &&
  1276. !u_sticky_mask(chan->exempts, e->mask) &&
  1277. !u_sticky_mask(global_exempts, e->mask) && expired_mask(chan, e->who)) {
  1278. /* Check to see if it matches a ban */
  1279. int match = 0;
  1280. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1281. if (wild_match(b->mask, e->mask) || wild_match(e->mask, b->mask)) {
  1282. match = 1;
  1283. break;
  1284. }
  1285. /* Leave this extra logging in for now. Can be removed later
  1286. * Jason
  1287. */
  1288. if (match) {
  1289. putlog(LOG_MODES, chan->dname,
  1290. "(%s) Channel exemption %s NOT expired. Exempt still set!", chan->dname, e->mask);
  1291. } else {
  1292. putlog(LOG_MODES, chan->dname, "(%s) Channel exemption on %s expired.", chan->dname, e->mask);
  1293. add_mode(chan, '-', 'e', e->mask);
  1294. }
  1295. e->timer = now;
  1296. }
  1297. if (use_invites && channel_dynamicinvites(chan) && chan->invite_time && !(chan->channel.mode & CHANINV)) {
  1298. for (b = chan->channel.invite; b->mask[0]; b = b->next) {
  1299. if (now - b->timer > 60 * chan->invite_time &&
  1300. !u_sticky_mask(chan->invites, b->mask) &&
  1301. !u_sticky_mask(global_invites, b->mask) && expired_mask(chan, b->who)) {
  1302. putlog(LOG_MODES, chan->dname, "(%s) Channel invitation on %s expired.", chan->dname, b->mask);
  1303. add_mode(chan, '-', 'I', b->mask);
  1304. b->timer = now;
  1305. }
  1306. }
  1307. }
  1308. } /* me_op */
  1309. // for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1310. for (m = chan->channel.member; m && m->nick[0]; m = n) {
  1311. n = m->next;
  1312. if (m->split && now - m->split > wait_split) {
  1313. simple_snprintf(s, sizeof(s), "%s!%s", m->nick, m->userhost);
  1314. putlog(LOG_JOIN, chan->dname, "%s (%s) got lost in the net-split.", m->nick, m->userhost);
  1315. killmember(chan, m->nick);
  1316. continue;
  1317. }
  1318. //This bot is set +r, so resolve.
  1319. if (!m->userip[0] && doresolv(chan)) {
  1320. char host[UHOSTLEN] = "", *p = NULL;
  1321. p = strchr(m->userhost, '@');
  1322. if (p) {
  1323. ++p;
  1324. strlcpy(host, p, strlen(m->userhost) - (p - host));
  1325. resolve_to_member(chan, m->nick, host);
  1326. }
  1327. }
  1328. if (me_op(chan)) {
  1329. if (dovoice(chan) && !loading) { /* autovoice of +v users if bot is +y */
  1330. if (!chan_hasop(m) && !chan_hasvoice(m)) {
  1331. member_getuser(m, 1);
  1332. if (m->user) {
  1333. get_user_flagrec(m->user, &fr, chan->dname, chan);
  1334. if (!glob_bot(fr)) {
  1335. if (!chan_sentvoice(m) && !(m->flags & EVOICE) &&
  1336. (
  1337. (channel_voice(chan) && !chk_devoice(fr)) ||
  1338. (!channel_voice(chan) && !privchan(fr, chan, PRIV_VOICE) && chk_voice(fr, chan))
  1339. )
  1340. ) {
  1341. add_mode(chan, '+', 'v', m->nick);
  1342. } else if ((chk_devoice(fr) || (m->flags & EVOICE))) {
  1343. add_mode(chan, '-', 'v', m->nick);
  1344. }
  1345. }
  1346. } else if (!chan_sentvoice(m) && !m->user && channel_voice(chan) && voice_ok(m, chan)) {
  1347. add_mode(chan, '+', 'v', m->nick);
  1348. }
  1349. }
  1350. }
  1351. }
  1352. m = n;
  1353. }
  1354. check_lonely_channel(chan);
  1355. } else if (shouldjoin(chan) && !channel_pending(chan)) {
  1356. dprintf(DP_MODE, "JOIN %s %s\n",
  1357. (chan->name[0]) ? chan->name : chan->dname,
  1358. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  1359. chan->status |= CHAN_JOINING;
  1360. }
  1361. }
  1362. void
  1363. irc_minutely()
  1364. {
  1365. for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
  1366. warn_pls_take(chan);
  1367. if (server_online) {
  1368. check_netfight(chan);
  1369. check_servers(chan);
  1370. check_expired_chanstuff(chan);
  1371. }
  1372. }
  1373. }
  1374. int check_bind_authc(char *cmd, Auth *auth, char *chname, char *args)
  1375. {
  1376. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1377. int x = 0;
  1378. get_user_flagrec(auth->user, &fr, chname);
  1379. x = check_bind(BT_msgc, cmd, &fr, auth, chname, args);
  1380. if (x & BIND_RET_LOG) {
  1381. if (chname)
  1382. putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", auth->nick, auth->host,
  1383. auth->handle, chname, auth_prefix[0], cmd, args);
  1384. else
  1385. putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", auth->nick, auth->host, auth->handle, auth_prefix[0], cmd, args);
  1386. }
  1387. if (x & BIND_RET_BREAK)
  1388. return (1);
  1389. return (0);
  1390. }
  1391. /* Flush the modes for EVERY channel.
  1392. */
  1393. void
  1394. flush_modes()
  1395. {
  1396. if (!modesperline) /* Haven't received 005 yet :) */
  1397. return;
  1398. memberlist *m = NULL;
  1399. for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
  1400. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1401. if (m->delay && m->delay <= now) {
  1402. m->delay = 0L;
  1403. m->flags &= ~FULL_DELAY;
  1404. if (chan_sentop(m)) {
  1405. m->flags &= ~SENTOP;
  1406. do_op(m->nick, chan, 0, 0);
  1407. }
  1408. if (chan_sentvoice(m)) {
  1409. m->flags &= ~SENTVOICE;
  1410. add_mode(chan, '+', 'v', m->nick);
  1411. }
  1412. }
  1413. }
  1414. flush_mode(chan, NORMAL);
  1415. }
  1416. }
  1417. void
  1418. irc_report(int idx, int details)
  1419. {
  1420. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1421. char ch[1024] = "", q[160] = "";
  1422. const char *p = NULL;
  1423. int k = 10;
  1424. size_t len;
  1425. strlcpy(q, "Channels: ", sizeof(q));
  1426. for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
  1427. if (idx != DP_STDOUT)
  1428. get_user_flagrec(dcc[idx].user, &fr, chan->dname, chan);
  1429. if (!privchan(fr, chan, PRIV_OP) && (idx == DP_STDOUT || glob_master(fr) || chan_master(fr))) {
  1430. p = NULL;
  1431. if (shouldjoin(chan)) {
  1432. if (chan->status & CHAN_JUPED)
  1433. p = "juped";
  1434. else if (channel_joining(chan))
  1435. p = "joining";
  1436. else if (!(chan->status & CHAN_ACTIVE))
  1437. p = "trying";
  1438. else if (chan->status & CHAN_PEND)
  1439. p = "pending";
  1440. else if ((chan->dname[0] != '+') && !me_op(chan))
  1441. p = "want ops!";
  1442. }
  1443. len = simple_snprintf(ch, sizeof(ch), "%s%s%s%s, ", chan->dname, p ? "(" : "", p ? p : "", p ? ")" : "");
  1444. if ((k + len) > 70) {
  1445. dprintf(idx, " %s\n", q);
  1446. strlcpy(q, " ", sizeof(q));
  1447. k = 10;
  1448. }
  1449. k += my_strcpy(q + k, ch);
  1450. }
  1451. }
  1452. if (k > 10) {
  1453. q[k - 2] = 0;
  1454. dprintf(idx, " %s\n", q);
  1455. }
  1456. }
  1457. static void
  1458. do_nettype()
  1459. {
  1460. switch (net_type) {
  1461. case 0: /* Efnet */
  1462. include_lk = 0;
  1463. break;
  1464. case 1: /* Ircnet */
  1465. include_lk = 1;
  1466. break;
  1467. case 2: /* Undernet */
  1468. include_lk = 1;
  1469. break;
  1470. case 3: /* Dalnet */
  1471. include_lk = 1;
  1472. break;
  1473. case 4: /* hybrid-6+ */
  1474. include_lk = 0;
  1475. break;
  1476. default:
  1477. break;
  1478. }
  1479. }
  1480. static cmd_t irc_bot[] = {
  1481. {"gi", "", (Function) getin_request, NULL, LEAF},
  1482. {"mr", "", (Function) mass_request, NULL, LEAF},
  1483. {NULL, NULL, NULL, NULL, 0}
  1484. };
  1485. static void
  1486. getin_5secondly()
  1487. {
  1488. if (!server_online)
  1489. return;
  1490. for (register struct chanset_t *chan = chanset; chan; chan = chan->next) {
  1491. if ((!channel_pending(chan) && channel_active(chan)) && !me_op(chan))
  1492. request_op(chan);
  1493. }
  1494. }
  1495. void
  1496. irc_init()
  1497. {
  1498. timer_create_secs(60, "irc_minutely", (Function) irc_minutely);
  1499. timer_create_secs(5, "getin_5secondly", (Function) getin_5secondly);
  1500. /* Add our commands to the imported tables. */
  1501. add_builtins("dcc", irc_dcc);
  1502. add_builtins("bot", irc_bot);
  1503. add_builtins("raw", irc_raw);
  1504. add_builtins("msg", C_msg);
  1505. add_builtins("msgc", C_msgc);
  1506. do_nettype();
  1507. }