server.cc 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2014 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. * server.c -- part of server.mod
  22. * basic irc server support
  23. *
  24. */
  25. #include "src/common.h"
  26. #include "src/set.h"
  27. #include "src/botmsg.h"
  28. #include "src/rfc1459.h"
  29. #include "src/settings.h"
  30. #include "src/match.h"
  31. #include "src/binds.h"
  32. #include "src/users.h"
  33. #include "src/userrec.h"
  34. #include "src/main.h"
  35. #include "src/response.h"
  36. #include "src/misc.h"
  37. #include "src/chanprog.h"
  38. #include "src/net.h"
  39. #include "src/auth.h"
  40. #include "src/adns.h"
  41. #include "src/socket.h"
  42. #include "src/egg_timer.h"
  43. #include "src/mod/channels.mod/channels.h"
  44. #include "src/mod/ctcp.mod/ctcp.h"
  45. #include "src/mod/irc.mod/irc.h"
  46. #include <bdlib/src/Stream.h>
  47. #include <bdlib/src/String.h>
  48. #include <bdlib/src/Array.h>
  49. #include "server.h"
  50. #include <stdarg.h>
  51. int default_alines = 5; /* How many mode lines are assumed will work before throttling */
  52. bool floodless = 0; /* floodless iline? */
  53. int ctcp_mode;
  54. int serv = -1; /* sock # of server currently */
  55. int servidx = -1; /* idx of server */
  56. char newserver[121] = ""; /* new server? */
  57. in_port_t newserverport = 0; /* new server port? */
  58. char newserverpass[121] = ""; /* new server password? */
  59. static char serverpass[121] = "";
  60. static time_t trying_server; /* trying to connect to a server right now? */
  61. int curserv = 999; /* current position in server list: */
  62. in_port_t curservport = 0;
  63. rate_t flood_msg = { 5, 60 };
  64. rate_t flood_ctcp = { 3, 60 };
  65. char botuserhost[UHOSTLEN] = ""; /* bot's user@host (refreshed whenever the bot joins a channel) */
  66. /* may not be correct user@host BUT it's how the server sees it */
  67. char botuserip[UHOSTLEN] = ""; /* bot's user@host with the ip. */
  68. time_t release_time = 0;
  69. bool keepnick = 1; /* keep trying to regain my intended
  70. nickname? */
  71. static int nick_juped = 0; /* True if origbotname is juped(RPL437) (dw) (1 = RESV, 2 = NETSPLIT) */
  72. static int jnick_juped = 0; /* True if jupenick is juped (1 = RESV, 2 = NETSPLIT) */
  73. time_t tried_jupenick = 0;
  74. time_t tried_nick = 0;
  75. bool use_monitor = 0;
  76. static bool waiting_for_awake; /* set when i unidle myself, cleared when I get the response */
  77. time_t server_online = 0; /* server connection time */
  78. char botrealname[121] = "A deranged product of evil coders."; /* realname of bot */
  79. static interval_t server_timeout = 15; /* server timeout for connecting */
  80. static const interval_t stoned_timeout = 500;
  81. struct server_list *serverlist = NULL; /* old-style queue, still used by
  82. server list */
  83. interval_t cycle_time; /* cycle time till next server connect */
  84. in_port_t default_port = 6667; /* default IRC port */
  85. in_port_t default_port_ssl = 6697; /* default IRC SSL port */
  86. bool trigger_on_ignore; /* trigger bindings if user is ignored ? */
  87. int answer_ctcp = 1; /* answer how many stacked ctcp's ? */
  88. static bool resolvserv; /* in the process of resolving a server host */
  89. static time_t lastpingtime; /* IRCNet LAGmeter support -- drummer */
  90. static char stackablecmds[511] = "";
  91. static char stackable2cmds[511] = "";
  92. static egg_timeval_t last_time;
  93. time_t connect_bursting = 0;
  94. static int real_msgburst = 0;
  95. static int real_msgrate = 0;
  96. int flood_count = 0;
  97. int burst = 0;
  98. static bool use_flood_count = 0;
  99. static egg_timeval_t flood_time = {0, 0};
  100. static bool use_penalties;
  101. static int use_fastdeq;
  102. size_t nick_len = 9; /* Maximal nick length allowed on the network. */
  103. char deaf_char = 0;
  104. bool in_deaf = 0;
  105. char callerid_char = 0;
  106. bool in_callerid = 0;
  107. bool have_cprivmsg = 0;
  108. bool have_cnotice = 0;
  109. bd::HashTable<bd::String, fish_data_t*> FishKeys;
  110. static bool double_warned = 0;
  111. static void empty_msgq(void);
  112. static void disconnect_server(int);
  113. static void calc_penalty(char *, size_t);
  114. static bool fast_deq(int);
  115. static char *splitnicks(char **);
  116. static void msgq_clear(struct msgq_head *qh);
  117. static int stack_limit = 4;
  118. static bool replaying_cache = 0;
  119. /* New bind tables. */
  120. static bind_table_t *BT_raw = NULL, *BT_msg = NULL;
  121. bind_table_t *BT_ctcr = NULL, *BT_ctcp = NULL;
  122. // Ratbox is (5*8):30, ircd-seven is (5*8):20, try to not push th elimits.
  123. #define SERVER_CONNECT_BURST_TIME 18
  124. #define SERVER_CONNECT_BURST_RATE 5 * 7
  125. #include "servmsg.cc"
  126. #define MAXPENALTY 10
  127. // If use_flood_count, don't bother with msgrate, otherwise use the user specified msgrate
  128. #define MSGRATE (use_flood_count ? DEQ_RATE : msgrate)
  129. /* Maximum messages to store in each queue. */
  130. static struct msgq_head mq, hq, modeq, aq, cacheq;
  131. static const struct {
  132. struct msgq_head* const q;
  133. const int idx;
  134. const char* name;
  135. const char pfx;
  136. const bool double_msg;
  137. const bool burst;
  138. const bool connect_burst;
  139. const size_t maxqmsg;
  140. } qdsc[5] = {
  141. { &modeq, DP_MODE, "MODE", 'm', 0, 1, 1, 300 },
  142. { &mq, DP_SERVER, "SERVER", 's', 0, 1, 1, 300 },
  143. { &hq, DP_HELP, "HELP", 'h', 0, 0, 0, 300 },
  144. { &aq, DP_PLAY, "PLAY", 'p', 1, 1, 0, 10000 },
  145. { &cacheq, DP_CACHE, "CACHE", 'c', 0, 0, 0, 1000 },
  146. };
  147. #define Q_MODE 0
  148. #define Q_SERVER 1
  149. #define Q_HELP 2
  150. #define Q_PLAY 3
  151. #define Q_CACHE 4
  152. #include "cmdsserv.cc"
  153. /*
  154. * Bot server queues
  155. */
  156. static bool burst_mode_ok(const char *msg, size_t len) {
  157. bd::String mode(msg, len);
  158. bd::Array<bd::String> list(mode.split(' '));
  159. if (list.length() == 2) return 1;
  160. if (list.length() == 3) {
  161. if (!strchr(CHANMETA, bd::String(list[1]).at(0))) return 1;
  162. else if (bd::String(list[2]).at(0) == 'b') return 1;
  163. }
  164. return 0;
  165. }
  166. // Hybrid/ratbox allows bursting 5*8 lines on connect until certain commands are sent, for up to 30 seconds
  167. /*
  168. BAD:
  169. JOIN 0
  170. MODE #chan b
  171. NICK
  172. PART
  173. KICK
  174. CPRIVMSG
  175. CNOTICE
  176. WHO 0/mask
  177. TIME
  178. TOPIC
  179. INVITE
  180. AWAY
  181. OPER
  182. OK:
  183. WHO *
  184. WHO !
  185. WHO #Chan
  186. WHO NICK
  187. */
  188. static bool burst_ok(const char* msg, size_t len) {
  189. if (strstr(msg, "JOIN 0") ||
  190. (strstr(msg, "MODE") && !burst_mode_ok(msg, len)) ||
  191. strstr(msg, "NICK") ||
  192. strstr(msg, "PRIVMSG") ||
  193. strstr(msg, "NOTICE") ||
  194. strstr(msg, "PART") ||
  195. strstr(msg, "KICK") ||
  196. strstr(msg, "INVITE") ||
  197. strstr(msg, "AWAY")) {
  198. sdprintf("BURST MODE VIOLATION!!!: %s\n", msg);
  199. return 0;
  200. }
  201. return 1;
  202. }
  203. /* Called periodically to shove out another queued item.
  204. *
  205. * 'mode' queue gets priority now.
  206. *
  207. * Most servers will allow 'busts' of upto 5 msgs, so let's put something
  208. * in to support flushing modeq a little faster if possible.
  209. * Will send upto 4 msgs from modeq, and then send 1 msg every time
  210. * it will *not* send anything from hq until the 'burst' value drops
  211. * down to 0 again (allowing a sudden mq flood to sneak through).
  212. *
  213. * ratbox:
  214. * Every msg sent is added to a count, every second this count decreases by 2.
  215. * Typical max count is 20, then excess flood is triggered.
  216. * So after 1 bursts:
  217. * Count = 5
  218. * Decaying by 1 every second
  219. */
  220. void deq_msg()
  221. {
  222. if (serv < 0)
  223. return;
  224. if (timeval_diff(&egg_timeval_now, &flood_time) >= 1000) {
  225. // Increase flood_count by 1 every msg, but decrease by 2 every second, use this to determine an acceptable burst rate
  226. if (flood_count > 1)
  227. flood_count -= 2;
  228. else if (flood_count == 1)
  229. flood_count = 0;
  230. flood_time.sec = egg_timeval_now.sec;
  231. flood_time.usec = egg_timeval_now.usec;
  232. }
  233. /* now < last_time tested 'cause clock adjustments could mess it up */
  234. if (timeval_diff(&egg_timeval_now, &last_time) >= MSGRATE || now < (last_time.sec - 90)) {
  235. last_time.sec = egg_timeval_now.sec;
  236. last_time.usec = egg_timeval_now.usec;
  237. if (burst > 0) {
  238. if (use_flood_count) {
  239. if (flood_count < 5)
  240. burst = 0;
  241. else if (flood_count < 10)
  242. burst -= 4;
  243. else if (flood_count < 13)
  244. burst -= 3;
  245. else if (flood_count < 15)
  246. burst -= 2;
  247. else
  248. --burst;
  249. if (burst < 0)
  250. burst = 0;
  251. } else
  252. --burst;
  253. }
  254. } else
  255. return;
  256. struct msgq *q = NULL;
  257. /* Send upto 'set msgburst' msgs to server if the *critical queue* has anything in it;
  258. * otherwise, dequeue and burst up to 'set msgburst' messages from the `normal' message
  259. * queue.
  260. */
  261. egg_timeval_t last_time_save = { last_time.sec, last_time.usec };
  262. #ifdef DEBUG
  263. bool bursted = 0;
  264. #endif
  265. // -1 here to avoid DP_CACHE
  266. for(size_t nq = 0; nq < (sizeof(qdsc) / sizeof(qdsc[0])) - 1; ++nq) {
  267. while (qdsc[nq].q->head &&
  268. // If burstable queue and can burst, or not a burstable queue and not connect bursting
  269. ((qdsc[nq].burst && (burst < msgburst && (!connect_bursting || (connect_bursting && qdsc[nq].connect_burst)))) || (!qdsc[nq].burst && !connect_bursting)) &&
  270. ((last_time.sec - now) < MAXPENALTY)) {
  271. #ifdef not_implemented
  272. if (deq_kick(qdsc[nq].idx)) {
  273. ++burst;++flood_count;
  274. break;
  275. }
  276. #endif
  277. if (fast_deq(nq))
  278. break;
  279. write_to_server(qdsc[nq].q->head->msg, qdsc[nq].q->head->len);
  280. ++burst;++flood_count;
  281. if (debug_output)
  282. putlog(LOG_SRVOUT, "*", "[%c->] %s", qdsc[nq].pfx, qdsc[nq].q->head->msg);
  283. --(qdsc[nq].q->tot);
  284. calc_penalty(qdsc[nq].q->head->msg, qdsc[nq].q->head->len);
  285. // Shift off dequeued message
  286. q = qdsc[nq].q->head->next;
  287. free(qdsc[nq].q->head->msg);
  288. free(qdsc[nq].q->head);
  289. qdsc[nq].q->head = q;
  290. if (!qdsc[nq].burst) {
  291. // Help Queue does not burst, push out 1 line then go to next queue.
  292. break;
  293. }
  294. #ifdef DEBUG
  295. bursted = 1;
  296. #endif
  297. }
  298. if (!qdsc[nq].q->head)
  299. qdsc[nq].q->last = NULL;
  300. }
  301. // Do this penalty calc here as it's dependant on burst/flood_count
  302. if (use_flood_count && !connect_bursting) {
  303. // The penalty includes a length-based penalty from calc_penalty
  304. last_time.sec -= (MSGRATE / 1000); // Remove normal msgrate
  305. // Add 150ms for each current burst
  306. last_time.usec += (150*burst) * 1000;
  307. // Add some penalty for each flood_count
  308. last_time.usec += (40*flood_count) * 1000;
  309. // Cap the penalty at 1800 and depend more on flood_count
  310. if (timeval_diff(&last_time, &last_time_save) > 1800) {
  311. last_time.sec = last_time_save.sec;
  312. last_time.usec = 1800 * 1000;
  313. }
  314. // If lagging, raise the penalty up to avoid TCP burst/excess flood
  315. if (server_lag > 5)
  316. last_time.sec += 2;
  317. #ifdef DEBUG
  318. if (timeval_diff(&last_time, &last_time_save))
  319. sdprintf("PENALTY (%d): %lims", flood_count, timeval_diff(&last_time, &last_time_save));
  320. #endif
  321. }
  322. #ifdef DEBUG
  323. else if (connect_bursting && bursted)
  324. sdprintf("BURSTING!!!!!\n");
  325. #endif
  326. }
  327. static void calc_penalty(char * msg, size_t len)
  328. {
  329. if (connect_bursting)
  330. return;
  331. char *cmd = NULL, *par1 = NULL, *par2 = NULL, *par3 = NULL;
  332. int penalty, i, ii;
  333. cmd = newsplit(&msg);
  334. if (msg)
  335. i = strlen(msg);
  336. else
  337. i = strlen(cmd);
  338. if (!use_penalties) {
  339. // Add some penalty for large messages
  340. if (use_flood_count)
  341. last_time.usec += long(((double)i / 300.0) * (1000*1000));
  342. else
  343. last_time.usec += long(((double)i / 120.0) * (1000*1000));
  344. return;
  345. }
  346. last_time.sec -= (MSGRATE / 1000); // Remove normal msgrate
  347. penalty = (1 + i / 100);
  348. if (!strcasecmp(cmd, "KICK")) {
  349. par1 = newsplit(&msg); /* channel */
  350. par2 = newsplit(&msg); /* victim(s) */
  351. par3 = splitnicks(&par2);
  352. penalty++;
  353. while (strlen(par3) > 0) {
  354. par3 = splitnicks(&par2);
  355. penalty++;
  356. }
  357. ii = penalty;
  358. par3 = splitnicks(&par1);
  359. while (strlen(par1) > 0) {
  360. par3 = splitnicks(&par1);
  361. penalty += ii;
  362. }
  363. } else if (!strcasecmp(cmd, "MODE")) {
  364. i = 0;
  365. par1 = newsplit(&msg); /* channel */
  366. par2 = newsplit(&msg); /* mode(s) */
  367. if (!strlen(par2))
  368. i++;
  369. while (strlen(par2) > 0) {
  370. if (strchr("ntimps", par2[0]))
  371. i += 3;
  372. else if (!strchr("+-", par2[0]))
  373. i += 1;
  374. par2++;
  375. }
  376. while (strlen(msg) > 0) {
  377. newsplit(&msg);
  378. i += 2;
  379. }
  380. ii = 0;
  381. while (strlen(par1) > 0) {
  382. splitnicks(&par1);
  383. ii++;
  384. }
  385. penalty += (ii * i);
  386. } else if (!strcasecmp(cmd, "TOPIC")) {
  387. penalty++;
  388. par1 = newsplit(&msg); /* channel */
  389. par2 = newsplit(&msg); /* topic */
  390. if (strlen(par2) > 0) { /* topic manipulation => 2 penalty points */
  391. penalty += 2;
  392. par3 = splitnicks(&par1);
  393. while (strlen(par1) > 0) {
  394. par3 = splitnicks(&par1);
  395. penalty += 2;
  396. }
  397. }
  398. } else if (!strcasecmp(cmd, "PRIVMSG") ||
  399. !strcasecmp(cmd, "NOTICE")) {
  400. par1 = newsplit(&msg); /* channel(s)/nick(s) */
  401. /* Add one sec penalty for each recipient */
  402. while (strlen(par1) > 0) {
  403. splitnicks(&par1);
  404. penalty++;
  405. }
  406. } else if (!strcasecmp(cmd, "WHO")) {
  407. par1 = newsplit(&msg); /* masks */
  408. par2 = par1;
  409. while (strlen(par1) > 0) {
  410. par2 = splitnicks(&par1);
  411. if (strlen(par2) > 4) /* long WHO-masks receive less penalty */
  412. penalty += 3;
  413. else
  414. penalty += 5;
  415. }
  416. } else if (!strcasecmp(cmd, "AWAY")) {
  417. if (msg && strlen(msg) > 0)
  418. penalty += 2;
  419. else
  420. penalty += 1;
  421. } else if (!strcasecmp(cmd, "INVITE")) {
  422. /* Successful invite receives 2 or 3 penalty points. Let's go
  423. * with the maximum.
  424. */
  425. penalty += 3;
  426. } else if (!strcasecmp(cmd, "JOIN")) {
  427. penalty += 2;
  428. } else if (!strcasecmp(cmd, "PART")) {
  429. penalty += 4;
  430. } else if (!strcasecmp(cmd, "VERSION")) {
  431. penalty += 2;
  432. } else if (!strcasecmp(cmd, "TIME")) {
  433. penalty += 2;
  434. } else if (!strcasecmp(cmd, "TRACE")) {
  435. penalty += 2;
  436. } else if (!strcasecmp(cmd, "NICK")) {
  437. penalty += 3;
  438. } else if (!strcasecmp(cmd, "ISON")) {
  439. penalty += 1;
  440. } else if (!strcasecmp(cmd, "WHOIS")) {
  441. penalty += 2;
  442. } else if (!strcasecmp(cmd, "DNS")) {
  443. penalty += 2;
  444. } else
  445. penalty++; /* just add standard-penalty */
  446. /* Shouldn't happen, but you never know... */
  447. if (penalty > 99)
  448. penalty = 99;
  449. if (penalty < 2) {
  450. putlog(LOG_SRVOUT, "*", "Penalty < 2sec, that's impossible!");
  451. penalty = 2;
  452. }
  453. if (debug_output && penalty != 0)
  454. putlog(LOG_SRVOUT, "*", "Adding penalty: %i", penalty);
  455. last_time.sec += penalty;
  456. }
  457. char *splitnicks(char **rest)
  458. {
  459. if (!rest)
  460. return *rest = "";
  461. char *o = *rest, *r = NULL;
  462. while (*o == ' ')
  463. o++;
  464. r = o;
  465. while (*o && *o != ',')
  466. o++;
  467. if (*o)
  468. *o++ = 0;
  469. *rest = o;
  470. return r;
  471. }
  472. void replay_cache(int idx, bd::Stream* stream) {
  473. if (!cacheq.head) return;
  474. struct msgq *r = NULL;
  475. char *p_ptr = NULL, *p = NULL;
  476. replaying_cache = 1;
  477. for (r = cacheq.head; r; r = r->next) {
  478. if (stream) {
  479. *stream << bd::String::printf(STR("+serv_cache %s\n"), r->msg);
  480. } else {
  481. //Create temporary buffer since server_activity may squash the buffer
  482. p_ptr = p = strdup(r->msg);
  483. server_activity(idx, p, r->len);
  484. free(p_ptr);
  485. }
  486. }
  487. replaying_cache = 0;
  488. }
  489. static bool fast_deq(int which)
  490. {
  491. if (!use_fastdeq)
  492. return 0;
  493. struct msgq_head *h = qdsc[which].q;
  494. struct msgq *m = NULL, *nm = NULL;
  495. char msgstr[511] = "", nextmsgstr[511] = "", tosend[511] = "", stackable[511] = "",
  496. *msg = NULL, *nextmsg = NULL, *cmd = NULL, *nextcmd = NULL, *to = NULL, *nextto = NULL, *stckbl = NULL;
  497. int cmd_count = 0;
  498. char stack_delim = ',';
  499. size_t len;
  500. bool found = 0, doit = 0;
  501. bd::String victims;
  502. m = h->head;
  503. strlcpy(msgstr, m->msg, sizeof msgstr);
  504. msg = msgstr;
  505. cmd = newsplit(&msg);
  506. if (use_fastdeq > 1) {
  507. strlcpy(stackable, stackablecmds, sizeof stackable);
  508. stckbl = stackable;
  509. while (strlen(stckbl) > 0)
  510. if (!strcasecmp(newsplit(&stckbl), cmd)) {
  511. found = 1;
  512. break;
  513. }
  514. /* If use_fastdeq is 2, only commands in the list should be stacked. */
  515. if (use_fastdeq == 2 && !found)
  516. return 0;
  517. /* If use_fastdeq is 3, only commands that are _not_ in the list
  518. * should be stacked.
  519. */
  520. if (use_fastdeq == 3 && found)
  521. return 0;
  522. /* we check for the stacking method (default=1) */
  523. strlcpy(stackable, stackable2cmds, sizeof stackable);
  524. stckbl = stackable;
  525. while (strlen(stckbl) > 0)
  526. if (!strcasecmp(newsplit(&stckbl), cmd)) {
  527. stack_delim = ' ';
  528. break;
  529. }
  530. }
  531. to = newsplit(&msg);
  532. victims = to;
  533. while (m) {
  534. nm = m->next;
  535. if (!nm)
  536. break;
  537. strlcpy(nextmsgstr, nm->msg, sizeof nextmsgstr);
  538. nextmsg = nextmsgstr;
  539. nextcmd = newsplit(&nextmsg);
  540. nextto = newsplit(&nextmsg);
  541. if ( strcmp(to, nextto) /* we don't stack to the same recipients */
  542. && !strcmp(cmd, nextcmd) && !strcmp(msg, nextmsg)
  543. && ((strlen(cmd) + victims.length() + strlen(nextto)
  544. + strlen(msg) + 2) < 510)
  545. && (!stack_limit || cmd_count < stack_limit - 1)) {
  546. ++cmd_count;
  547. victims += stack_delim + nextto;
  548. doit = 1;
  549. m->next = nm->next;
  550. if (!nm->next)
  551. h->last = m;
  552. free(nm->msg);
  553. free(nm);
  554. --(h->tot);
  555. } else
  556. m = m->next;
  557. }
  558. if (doit) {
  559. len = simple_snprintf(tosend, sizeof(tosend), "%s %s %s", cmd, victims.c_str(), msg);
  560. write_to_server(tosend, len);
  561. ++burst;++flood_count;
  562. m = h->head->next;
  563. free(h->head->msg);
  564. free(h->head);
  565. h->head = m;
  566. if (!h->head)
  567. h->last = 0;
  568. --(h->tot);
  569. if (debug_output)
  570. putlog(LOG_SRVOUT, "*", "[%c=>] %s", qdsc[which].pfx, tosend);
  571. calc_penalty(tosend, len);
  572. return 1;
  573. }
  574. return 0;
  575. }
  576. /* Clean out the msg queues (like when changing servers).
  577. */
  578. static void empty_msgq()
  579. {
  580. for (size_t i = 0; i < (sizeof(qdsc) / sizeof(qdsc[0])); ++i)
  581. msgq_clear(qdsc[i].q);
  582. burst = 0;
  583. flood_count = 0;
  584. flood_time.sec = flood_time.usec = 0;
  585. }
  586. /* Use when sending msgs... will spread them out so there's no flooding.
  587. */
  588. void queue_server(int which, char *buf, int len)
  589. {
  590. /* Don't even BOTHER if there's no server online. */
  591. if (serv < 0)
  592. return;
  593. // If connect bursting, hold off any commands which would end the gracetime (flood_endgrace)
  594. if (connect_bursting && (which == DP_MODE || which == DP_MODE_NEXT || which == DP_SERVER || which == DP_SERVER_NEXT)) {
  595. if (!burst_ok(buf, len))
  596. which = DP_HELP;
  597. }
  598. int qnext = 0;
  599. int which_q = 0;
  600. switch (which) {
  601. case DP_MODE_NEXT:
  602. qnext = 1;
  603. case DP_MODE:
  604. which_q = Q_MODE;
  605. break;
  606. case DP_SERVER_NEXT:
  607. qnext = 1;
  608. case DP_SERVER:
  609. which_q = Q_SERVER;
  610. break;
  611. case DP_HELP_NEXT:
  612. qnext = 1;
  613. case DP_HELP:
  614. which_q = Q_HELP;
  615. break;
  616. case DP_PLAY:
  617. which_q = Q_PLAY;
  618. break;
  619. case DP_CACHE:
  620. which_q = Q_CACHE;
  621. break;
  622. default:
  623. putlog(LOG_MISC, "*", "!!! queuing unknown type to server!!");
  624. return;
  625. }
  626. struct msgq_head *h = qdsc[which_q].q;
  627. if (h->tot < qdsc[which_q].maxqmsg) {
  628. /* Don't queue msg if it's already queued? */
  629. if (!qdsc[which_q].double_msg) {
  630. for (struct msgq* tq = qdsc[which_q].q->head; tq; tq = tq->next) {
  631. if (!strcasecmp(tq->msg, buf)) {
  632. if (!double_warned) {
  633. if (buf[len - 1] == '\n')
  634. buf[len - 1] = 0;
  635. putlog(LOG_DEBUG, "*", "msg already queued. skipping: %s", buf);
  636. double_warned = 1;
  637. }
  638. return;
  639. }
  640. }
  641. }
  642. struct msgq *q = (struct msgq *) calloc(1, sizeof(struct msgq));
  643. if (h->head) {
  644. if (!qnext) { //Not next, add to end of queue
  645. h->last->next = q;
  646. h->last = q;
  647. } else if (qnext) { //Should be next, insert into front of queue
  648. q->next = h->head;
  649. h->head = q;
  650. }
  651. } else
  652. h->head = h->last = q;
  653. q->len = len;
  654. q->msg = (char *) calloc(1, len + 1);
  655. strlcpy(q->msg, buf, len + 1);
  656. ++(h->tot);
  657. h->warned = 0;
  658. double_warned = 0;
  659. } else {
  660. if (!h->warned)
  661. putlog(LOG_MISC, "*", "!!! OVER MAXIMUM %s QUEUE", qdsc[which_q].name);
  662. h->warned = 1;
  663. }
  664. if (debug_output && !h->warned)
  665. putlog(LOG_SRVOUT, "@", "[%s%c] %s", qnext ? "!!" : "!", qdsc[which_q].pfx, buf);
  666. /* Try flushing immediately */
  667. deq_msg();
  668. }
  669. /* Add a new server to the server_list.
  670. */
  671. void add_server(char *ss)
  672. {
  673. struct server_list *x = NULL, *z = NULL;
  674. char *p = NULL, *q = NULL;
  675. for (z = serverlist; z && z->next; z = z->next)
  676. ;
  677. while (ss) {
  678. p = strchr(ss, ',');
  679. if (p)
  680. *p++ = 0;
  681. x = (struct server_list *) calloc(1, sizeof(struct server_list));
  682. x->next = 0;
  683. x->port = 0;
  684. if (z)
  685. z->next = x;
  686. else
  687. serverlist = x;
  688. z = x;
  689. q = strchr(ss, ':');
  690. if (!q) {
  691. x->pass = 0;
  692. x->name = strdup(ss);
  693. } else {
  694. #ifdef USE_IPV6
  695. if (ss[0] == '[') {
  696. ++ss;
  697. q = strchr(ss, ']');
  698. *q++ = 0; /* intentional */
  699. }
  700. #endif /* USE_IPV6 */
  701. *q++ = 0;
  702. x->name = (char *) calloc(1, q - ss);
  703. strlcpy(x->name, ss, q - ss);
  704. ss = q;
  705. q = strchr(ss, ':');
  706. if (!q) {
  707. x->pass = 0;
  708. } else {
  709. *q++ = 0;
  710. x->pass = strdup(q);
  711. }
  712. if (!x->port) {
  713. x->port = atoi(ss);
  714. }
  715. }
  716. ss = p;
  717. }
  718. }
  719. /* Clear out the given server_list.
  720. */
  721. void clearq(struct server_list *xx)
  722. {
  723. struct server_list *x = NULL;
  724. while (xx) {
  725. x = xx->next;
  726. if (xx->name)
  727. free(xx->name);
  728. if (xx->pass)
  729. free(xx->pass);
  730. free(xx);
  731. xx = x;
  732. }
  733. }
  734. /* Set botserver to the next available server.
  735. *
  736. * -> if (*ptr == -1) then jump to that particular server
  737. */
  738. void next_server(int *ptr, char *servname, in_port_t *port, char *pass)
  739. {
  740. struct server_list *x = serverlist;
  741. if (x == NULL)
  742. return;
  743. int i = 0;
  744. /* -1 --> Go to specified server */
  745. if (*ptr == (-1)) {
  746. for (; x; x = x->next) {
  747. if (x->port == *port) {
  748. if (!strcasecmp(x->name, servname)) {
  749. *ptr = i;
  750. return;
  751. }
  752. }
  753. i++;
  754. }
  755. /* Gotta add it: */
  756. x = (struct server_list *) calloc(1, sizeof(struct server_list));
  757. x->next = 0;
  758. x->name = strdup(servname);
  759. x->port = *port ? *port : (ssl_use ? default_port_ssl : default_port);
  760. if (pass && pass[0]) {
  761. x->pass = strdup(pass);
  762. } else
  763. x->pass = NULL;
  764. list_append((struct list_type **) (&serverlist), (struct list_type *) x);
  765. *ptr = i;
  766. return;
  767. }
  768. /* Find where i am and boogie */
  769. i = (*ptr);
  770. while (i > 0 && x != NULL) {
  771. x = x->next;
  772. i--;
  773. }
  774. if (x != NULL) {
  775. x = x->next;
  776. (*ptr)++;
  777. } /* Go to next server */
  778. if (x == NULL) {
  779. x = serverlist;
  780. *ptr = 0;
  781. } /* Start over at the beginning */
  782. strcpy(servname, x->name);
  783. *port = x->port ? x->port : (ssl_use ? default_port_ssl : default_port);
  784. if (x->pass)
  785. strcpy(pass, x->pass);
  786. else
  787. pass[0] = 0;
  788. }
  789. /*
  790. * CTCP DCC CHAT functions
  791. */
  792. static int sanitycheck_dcc(char *nick, char *from, char *ipaddy, char *port)
  793. {
  794. /* According to the latest RFC, the clients SHOULD be able to handle
  795. * DNS names that are up to 255 characters long. This is not broken.
  796. */
  797. char badaddress[16];
  798. in_addr_t ip = my_atoul(ipaddy);
  799. int prt = atoi(port);
  800. if (prt < 1) {
  801. putlog(LOG_MISC, "*", "ALERT: (%s!%s) specified an impossible port of %u!",
  802. nick, from, prt);
  803. return 0;
  804. }
  805. simple_snprintf(badaddress, sizeof(badaddress), "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff,
  806. (ip >> 8) & 0xff, ip & 0xff);
  807. if (ip < (1 << 24)) {
  808. putlog(LOG_MISC, "*", "ALERT: (%s!%s) specified an impossible IP of %s!",
  809. nick, from, badaddress);
  810. return 0;
  811. }
  812. return 1;
  813. }
  814. static void dcc_chat_hostresolved(int);
  815. /* This only handles CHAT requests, otherwise it's handled in filesys.
  816. */
  817. static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object, char *keyword, char *text)
  818. {
  819. if (!ischanhub())
  820. return BIND_RET_LOG;
  821. char *action = NULL, *param = NULL, *ip = NULL, *prt = NULL;
  822. action = newsplit(&text);
  823. param = newsplit(&text);
  824. ip = newsplit(&text);
  825. prt = newsplit(&text);
  826. if (strcasecmp(action, "CHAT") || strcasecmp(object, botname) || !u)
  827. return BIND_RET_LOG;
  828. int i;
  829. bool ok = 1;
  830. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  831. get_user_flagrec(u, &fr, NULL);
  832. if (ischanhub() && !glob_chuba(fr))
  833. ok = 0;
  834. if (dcc_total == max_dcc) {
  835. putlog(LOG_MISC, "*", "DCC connections full: %s %s (%s!%s)", "CHAT", param, nick, from);
  836. } else if (!ok) {
  837. putlog(LOG_MISC, "*", "%s: %s!%s", ischanhub() ? "Refused DCC chat (no access)" : "Refused DCC chat (I'm not a chathub (+c))", nick, from);
  838. } else if (u_pass_match(u, "-")) {
  839. putlog(LOG_MISC, "*", "%s: %s!%s", "Refused DCC chat (no password)", nick, from);
  840. } else if (atoi(prt) < 1024 || atoi(prt) > 65535) {
  841. /* Invalid port */
  842. putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", "DCC invalid port", nick, from);
  843. } else {
  844. if (!sanitycheck_dcc(nick, from, ip, prt))
  845. return 1;
  846. i = new_dcc(&DCC_CHAT_PASS, sizeof(struct chat_info));
  847. if (i < 0) {
  848. putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", nick, ip);
  849. return BIND_RET_BREAK;
  850. }
  851. dcc[i].addr = my_atoul(ip);
  852. dcc[i].port = atoi(prt);
  853. dcc[i].sock = -1;
  854. strlcpy(dcc[i].nick, u->handle, sizeof(dcc[i].nick));
  855. strlcpy(dcc[i].host, from, sizeof(dcc[i].host));
  856. dcc[i].timeval = now;
  857. dcc[i].user = u;
  858. dcc_chat_hostresolved(i);
  859. // egg_dns_reverse(dcc[i].addr, 20, dcc_chat_dns_callback, (void *) i);
  860. }
  861. return BIND_RET_BREAK;
  862. }
  863. //static void tandem_relay_dns_callback(void *client_data, const char *host, char **ips)
  864. static void dcc_chat_hostresolved(int i)
  865. {
  866. char buf[512] = "", ip[512] = "";
  867. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  868. simple_snprintf(buf, sizeof buf, "%d", dcc[i].port);
  869. simple_snprintf(ip, sizeof ip, "%lu", (0xffffffff & ((long) dcc[i].addr)));
  870. #ifdef USE_IPV6
  871. dcc[i].sock = getsock(0, AF_INET);
  872. #else
  873. dcc[i].sock = getsock(0);
  874. #endif /* USE_IPV6 */
  875. int open_telnet_return = 0;
  876. if (dcc[i].sock < 0 || (open_telnet_return = open_telnet_dcc(dcc[i].sock, ip, buf)) < 0) {
  877. if (open_telnet_return == -1)
  878. dcc[i].sock = -1;
  879. strlcpy(buf, strerror(errno), sizeof(buf));
  880. putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", "DCC connection failed", dcc[i].nick, dcc[i].host);
  881. putlog(LOG_MISC, "*", " (%s)", buf);
  882. if (dcc[i].sock != -1)
  883. killsock(dcc[i].sock);
  884. lostdcc(i);
  885. } else {
  886. bool ok = 1;
  887. dcc[i].status = STAT_ECHO;
  888. get_user_flagrec(dcc[i].user, &fr, NULL);
  889. if (ischanhub() && !glob_chuba(fr))
  890. ok = 0;
  891. if (ok)
  892. dcc[i].status |= STAT_PARTY;
  893. struct chat_info dummy;
  894. strlcpy(dcc[i].u.chat->con_chan, (chanset) ? chanset->dname : "*", sizeof(dummy.con_chan));
  895. dcc[i].timeval = now;
  896. /* Ok, we're satisfied with them now: attempt the connect */
  897. putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", dcc[i].nick, dcc[i].host);
  898. dprintf(i, "%s\n", response(RES_USERNAME));
  899. }
  900. return;
  901. }
  902. /*
  903. * Server timer functions
  904. */
  905. static void end_burstmode() {
  906. if (connect_bursting) {
  907. connect_bursting = 0;
  908. msgburst = real_msgburst;
  909. msgrate = real_msgrate;
  910. }
  911. }
  912. static void server_secondly()
  913. {
  914. if (cycle_time)
  915. --cycle_time;
  916. if (!resolvserv && serv < 0 && !trying_server)
  917. connect_server();
  918. else if (server_online) {
  919. if (keepnick && !use_monitor) {
  920. static int ison_cnt = 0;
  921. if (ison_time == 0) //If someone sets this to 0, all hell will break loose!
  922. ison_time = 10;
  923. if (ison_cnt >= ison_time) {
  924. server_send_ison();
  925. ison_cnt = 0;
  926. } else
  927. ++ison_cnt;
  928. } else if (!keepnick && release_time && ((now - release_time) >= RELEASE_TIME)) {
  929. release_time = 0;
  930. keepnick = 1;
  931. /* The release time has expired, try to regain the jupenick. */
  932. nick_available(1, 0);
  933. }
  934. static int cnt_10 = 0;
  935. // Every 10 seconds
  936. if (cnt_10 == 9) {
  937. // Ensure that +D/+f are not conflicting
  938. if (!loading && deaf_char) {
  939. // +f or auth bots in used need to see channel chatter.
  940. bool need_chatter = doflood(NULL) || (Auth::ht_host.size() && auth_chan && strlen(auth_prefix));
  941. // In +D but am +f, need to -D
  942. if (in_deaf && (need_chatter || !use_deaf)) {
  943. dprintf(DP_SERVER, "MODE %s -%c\n", botname, deaf_char);
  944. in_deaf = 0;
  945. } else if (!in_deaf && use_deaf && !need_chatter) {
  946. // Not +D but should be, probably had +f removed.
  947. dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
  948. in_deaf = 1;
  949. }
  950. }
  951. // Clear expired key exchanges that aren't finished (7 seconds)
  952. const bd::Array<bd::String> fish_targets(FishKeys.keys());
  953. for (size_t i = 0; i < fish_targets.length(); ++i) {
  954. const bd::String target(fish_targets[i]);
  955. fish_data_t* fishData = FishKeys[target];
  956. bool should_delete = false;
  957. if (fishData->key_created_at && !fishData->sharedKey && ((now - 7) >= fishData->key_created_at)) {
  958. putlog(LOG_DEBUG, "*", "Deleting expired DH1080 FiSH exchange with %s", target.c_str());
  959. should_delete = true;
  960. } else if (fishData->key_created_at && fishData->sharedKey.length() && ((now - 3600) >= fishData->key_created_at)) {
  961. putlog(LOG_DEBUG, "*", "Deleting expired (60 min) FiSH key with %s", target.c_str());
  962. should_delete = true;
  963. }
  964. if (should_delete) {
  965. FishKeys.remove(target);
  966. delete fishData;
  967. }
  968. }
  969. cnt_10 = 0;
  970. } else {
  971. ++cnt_10;
  972. }
  973. if (connect_bursting && (now - SERVER_CONNECT_BURST_TIME) >= connect_bursting) {
  974. end_burstmode();
  975. putlog(LOG_DEBUG, "*", "Ending server burst mode");
  976. }
  977. }
  978. }
  979. static void server_check_lag()
  980. {
  981. if (server_online && !waiting_for_awake && !trying_server) {
  982. dprintf(DP_MODE, "PING :%li\n", (long)now);
  983. lastpingtime = now;
  984. waiting_for_awake = 1;
  985. } else if (servidx != -1 && waiting_for_awake && ((now - lastpingtime) >= stoned_timeout)) {
  986. // Not checking server_online as this will handle connect timeouts as well where the connect() works, but the server gets stoned afterwards
  987. disconnect_server(servidx);
  988. lostdcc(servidx);
  989. putlog(LOG_SERV, "*", "Server got stoned; jumping...");
  990. }
  991. }
  992. void reset_flood()
  993. {
  994. flood_time.sec = last_time.sec = now - 100;
  995. flood_time.usec = last_time.usec = 0;
  996. }
  997. static void server_minutely()
  998. {
  999. if (server_online) {
  1000. // Ratbox sets a nick_delay (default:15min) timer when a nick splits off to prevent collisions,
  1001. // We must check periodically to see if the local server has unjuped our wanted nicks.
  1002. if (keepnick && (jnick_juped == 2 || nick_juped == 2)) {
  1003. nick_available(jnick_juped == 2, nick_juped == 2);
  1004. }
  1005. }
  1006. }
  1007. void server_die()
  1008. {
  1009. cycle_time = 100;
  1010. if (server_online) {
  1011. dprintf(-serv, "QUIT :%s\n", quit_msg[0] ? quit_msg : "");
  1012. sleep(2); /* Give the server time to understand */
  1013. }
  1014. nuke_server(NULL);
  1015. }
  1016. /* A report on the module status.
  1017. */
  1018. void server_report(int idx, int details)
  1019. {
  1020. char s1[64] = "", s[128] = "";
  1021. if (server_online) {
  1022. dprintf(idx, " Online as: %s%s%s (%s)\n", botname,
  1023. botuserhost[0] ? "!" : "", botuserhost[0] ? botuserhost : "",
  1024. botrealname);
  1025. dprintf(idx, " My userip: %s!%s\n", botname, botuserip);
  1026. if (nick_juped)
  1027. dprintf(idx, " NICK IS JUPED: %s %s\n", origbotname, keepnick ? "(trying)" : "");
  1028. if (jnick_juped)
  1029. dprintf(idx, " JUPENICK IS JUPED: %s %s\n", jupenick, keepnick ? "(trying)" : "");
  1030. nick_juped = jnick_juped = 0;
  1031. daysdur(now, server_online, s1, sizeof(s1));
  1032. simple_snprintf(s, sizeof s, "(connected %s)", s1);
  1033. if (server_lag && !waiting_for_awake) {
  1034. if (server_lag == (-1))
  1035. simple_snprintf(s1, sizeof s1, " (bad pong replies)");
  1036. else
  1037. simple_snprintf(s1, sizeof s1, " (lag: %ds)", server_lag);
  1038. strlcat(s, s1, sizeof(s));
  1039. }
  1040. }
  1041. if ((trying_server || server_online) && (servidx != (-1))) {
  1042. dprintf(idx, " Server %s:%d %s\n", dcc[servidx].host, dcc[servidx].port,
  1043. trying_server ? "(trying)" : s);
  1044. } else
  1045. dprintf(idx, " No server currently.\n");
  1046. if (server_online)
  1047. dprintf(idx, " burst: %d flood_count: %d\n", burst, flood_count);
  1048. for (size_t i = 0; i < (sizeof(qdsc) / sizeof(qdsc[0])); ++i) {
  1049. if (qdsc[i].q->tot)
  1050. dprintf(idx, " %s queue is at %d%%, %d msgs\n",
  1051. qdsc[i].name,
  1052. (int) ((float) (qdsc[i].q->tot * 100.0) / (float) qdsc[i].maxqmsg),
  1053. (int) qdsc[i].q->tot);
  1054. }
  1055. if (details) {
  1056. dprintf(idx, " Flood is: %d msg/%ds, %d ctcp/%ds\n",
  1057. flood_msg.count, flood_msg.time, flood_ctcp.count, flood_ctcp.time);
  1058. }
  1059. }
  1060. static void msgq_clear(struct msgq_head *qh)
  1061. {
  1062. struct msgq *qq = NULL;
  1063. for (struct msgq *q = qh->head; q; q = qq) {
  1064. qq = q->next;
  1065. free(q->msg);
  1066. free(q);
  1067. }
  1068. qh->head = qh->last = NULL;
  1069. qh->tot = qh->warned = 0;
  1070. }
  1071. static cmd_t my_ctcps[] =
  1072. {
  1073. {"DCC", "", (Function) ctcp_DCC_CHAT, "server:DCC", LEAF},
  1074. {NULL, NULL, NULL, NULL, 0}
  1075. };
  1076. void server_init()
  1077. {
  1078. strlcpy(botrealname, "A deranged product of evil coders", sizeof(botrealname));
  1079. /*
  1080. * Init of all the variables *must* be done in _start rather than
  1081. * globally.
  1082. */
  1083. BT_msg = bind_table_add("msg", 4, "ssUs", MATCH_FLAGS, 0);
  1084. BT_raw = bind_table_add("raw", 2, "ss", 0, BIND_STACKABLE);
  1085. BT_ctcr = bind_table_add("ctcr", 6, "ssUsss", 0, BIND_STACKABLE);
  1086. BT_ctcp = bind_table_add("ctcp", 6, "ssUsss", 0, BIND_STACKABLE);
  1087. add_builtins("raw", my_raw_binds);
  1088. add_builtins("dcc", C_dcc_serv);
  1089. add_builtins("ctcp", my_ctcps);
  1090. egg_timeval_t howlong;
  1091. howlong.sec = 0;
  1092. howlong.usec = DEQ_RATE * 1000;
  1093. timer_create_repeater(&howlong, "server_queue", (Function) deq_msg);
  1094. timer_create_secs(1, "server_secondly", (Function) server_secondly);
  1095. timer_create_secs(30, "server_check_lag", (Function) server_check_lag);
  1096. timer_create_secs(60, "server_minutely", (Function) server_minutely);
  1097. // timer_create_secs(60, "minutely_checks", (Function) minutely_checks);
  1098. }
  1099. /* vim: set sts=2 sw=2 ts=8 et: */