irc.c 53 KB

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