server.cc 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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, 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. nick_available(1, 0);
  932. }
  933. static int cnt_10 = 0;
  934. // Every 10 seconds
  935. if (cnt_10 == 9) {
  936. // Ensure that +D/+f are not conflicting
  937. if (!loading && deaf_char) {
  938. // +f or auth bots in used need to see channel chatter.
  939. bool need_chatter = doflood(NULL) || (Auth::ht_host.size() && auth_chan && strlen(auth_prefix));
  940. // In +D but am +f, need to -D
  941. if (in_deaf && (need_chatter || !use_deaf)) {
  942. dprintf(DP_SERVER, "MODE %s -%c\n", botname, deaf_char);
  943. in_deaf = 0;
  944. } else if (!in_deaf && use_deaf && !need_chatter) {
  945. // Not +D but should be, probably had +f removed.
  946. dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
  947. in_deaf = 1;
  948. }
  949. }
  950. // Clear expired key exchanges that aren't finished (7 seconds)
  951. const bd::Array<bd::String> fish_targets(FishKeys.keys());
  952. for (size_t i = 0; i < fish_targets.length(); ++i) {
  953. const bd::String target(fish_targets[i]);
  954. fish_data_t* fishData = FishKeys[target];
  955. bool should_delete = false;
  956. if (fishData->key_created_at && !fishData->sharedKey && ((now - 7) >= fishData->key_created_at)) {
  957. putlog(LOG_DEBUG, "*", "Deleting expired DH1080 FiSH exchange with %s", target.c_str());
  958. should_delete = true;
  959. } else if (fishData->key_created_at && fishData->sharedKey.length() && ((now - 3600) >= fishData->key_created_at)) {
  960. putlog(LOG_DEBUG, "*", "Deleting expired (60 min) FiSH key with %s", target.c_str());
  961. should_delete = true;
  962. }
  963. if (should_delete) {
  964. FishKeys.remove(target);
  965. delete fishData;
  966. }
  967. }
  968. cnt_10 = 0;
  969. } else {
  970. ++cnt_10;
  971. }
  972. if (connect_bursting && (now - SERVER_CONNECT_BURST_TIME) >= connect_bursting) {
  973. end_burstmode();
  974. putlog(LOG_DEBUG, "*", "Ending server burst mode");
  975. }
  976. }
  977. }
  978. static void server_check_lag()
  979. {
  980. if (server_online && !waiting_for_awake && !trying_server) {
  981. dprintf(DP_MODE, "PING :%li\n", (long)now);
  982. lastpingtime = now;
  983. waiting_for_awake = 1;
  984. } else if (servidx != -1 && waiting_for_awake && ((now - lastpingtime) >= stoned_timeout)) {
  985. // Not checking server_online as this will handle connect timeouts as well where the connect() works, but the server gets stoned afterwards
  986. disconnect_server(servidx, DO_LOST);
  987. putlog(LOG_SERV, "*", "Server got stoned; jumping...");
  988. }
  989. }
  990. void reset_flood()
  991. {
  992. flood_time.sec = last_time.sec = now - 100;
  993. flood_time.usec = last_time.usec = 0;
  994. }
  995. static void server_minutely()
  996. {
  997. if (server_online) {
  998. // Ratbox sets a nick_delay (default:15min) timer when a nick splits off to prevent collisions,
  999. // We must check periodically to see if the local server has unjuped our wanted nicks.
  1000. if (keepnick && (jnick_juped == 2 || nick_juped == 2)) {
  1001. nick_available(1, 1);
  1002. }
  1003. }
  1004. }
  1005. void server_die()
  1006. {
  1007. cycle_time = 100;
  1008. if (server_online) {
  1009. dprintf(-serv, "QUIT :%s\n", quit_msg[0] ? quit_msg : "");
  1010. sleep(2); /* Give the server time to understand */
  1011. }
  1012. nuke_server(NULL);
  1013. }
  1014. /* A report on the module status.
  1015. */
  1016. void server_report(int idx, int details)
  1017. {
  1018. char s1[64] = "", s[128] = "";
  1019. if (server_online) {
  1020. dprintf(idx, " Online as: %s%s%s (%s)\n", botname,
  1021. botuserhost[0] ? "!" : "", botuserhost[0] ? botuserhost : "",
  1022. botrealname);
  1023. dprintf(idx, " My userip: %s!%s\n", botname, botuserip);
  1024. if (nick_juped)
  1025. dprintf(idx, " NICK IS JUPED: %s %s\n", origbotname, keepnick ? "(trying)" : "");
  1026. if (jnick_juped)
  1027. dprintf(idx, " JUPENICK IS JUPED: %s %s\n", jupenick, keepnick ? "(trying)" : "");
  1028. nick_juped = jnick_juped = 0;
  1029. daysdur(now, server_online, s1, sizeof(s1));
  1030. simple_snprintf(s, sizeof s, "(connected %s)", s1);
  1031. if (server_lag && !waiting_for_awake) {
  1032. if (server_lag == (-1))
  1033. simple_snprintf(s1, sizeof s1, " (bad pong replies)");
  1034. else
  1035. simple_snprintf(s1, sizeof s1, " (lag: %ds)", server_lag);
  1036. strlcat(s, s1, sizeof(s));
  1037. }
  1038. }
  1039. if ((trying_server || server_online) && (servidx != (-1))) {
  1040. dprintf(idx, " Server %s:%d %s\n", dcc[servidx].host, dcc[servidx].port,
  1041. trying_server ? "(trying)" : s);
  1042. } else
  1043. dprintf(idx, " No server currently.\n");
  1044. if (server_online)
  1045. dprintf(idx, " burst: %d flood_count: %d\n", burst, flood_count);
  1046. for (size_t i = 0; i < (sizeof(qdsc) / sizeof(qdsc[0])); ++i) {
  1047. if (qdsc[i].q->tot)
  1048. dprintf(idx, " %s queue is at %d%%, %d msgs\n",
  1049. qdsc[i].name,
  1050. (int) ((float) (qdsc[i].q->tot * 100.0) / (float) qdsc[i].maxqmsg),
  1051. (int) qdsc[i].q->tot);
  1052. }
  1053. if (details) {
  1054. dprintf(idx, " Flood is: %d msg/%ds, %d ctcp/%ds\n",
  1055. flood_msg.count, flood_msg.time, flood_ctcp.count, flood_ctcp.time);
  1056. }
  1057. }
  1058. static void msgq_clear(struct msgq_head *qh)
  1059. {
  1060. struct msgq *qq = NULL;
  1061. for (struct msgq *q = qh->head; q; q = qq) {
  1062. qq = q->next;
  1063. free(q->msg);
  1064. free(q);
  1065. }
  1066. qh->head = qh->last = NULL;
  1067. qh->tot = qh->warned = 0;
  1068. }
  1069. static cmd_t my_ctcps[] =
  1070. {
  1071. {"DCC", "", (Function) ctcp_DCC_CHAT, "server:DCC", LEAF},
  1072. {NULL, NULL, NULL, NULL, 0}
  1073. };
  1074. void server_init()
  1075. {
  1076. strlcpy(botrealname, "A deranged product of evil coders", sizeof(botrealname));
  1077. /*
  1078. * Init of all the variables *must* be done in _start rather than
  1079. * globally.
  1080. */
  1081. BT_msg = bind_table_add("msg", 4, "ssUs", MATCH_FLAGS, 0);
  1082. BT_raw = bind_table_add("raw", 2, "ss", 0, BIND_STACKABLE);
  1083. BT_ctcr = bind_table_add("ctcr", 6, "ssUsss", 0, BIND_STACKABLE);
  1084. BT_ctcp = bind_table_add("ctcp", 6, "ssUsss", 0, BIND_STACKABLE);
  1085. add_builtins("raw", my_raw_binds);
  1086. add_builtins("dcc", C_dcc_serv);
  1087. add_builtins("ctcp", my_ctcps);
  1088. egg_timeval_t howlong;
  1089. howlong.sec = 0;
  1090. howlong.usec = DEQ_RATE * 1000;
  1091. timer_create_repeater(&howlong, "server_queue", (Function) deq_msg);
  1092. timer_create_secs(1, "server_secondly", (Function) server_secondly);
  1093. timer_create_secs(30, "server_check_lag", (Function) server_check_lag);
  1094. timer_create_secs(60, "server_minutely", (Function) server_minutely);
  1095. // timer_create_secs(60, "minutely_checks", (Function) minutely_checks);
  1096. }
  1097. /* vim: set sts=2 sw=2 ts=8 et: */