server.cc 34 KB

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