irc.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. #ifdef LEAF
  2. /*
  3. * irc.c -- part of irc.mod
  4. * support for channels within the bot
  5. *
  6. */
  7. #define MODULE_NAME "irc"
  8. #define MAKING_IRC
  9. #include "src/mod/module.h"
  10. #include "irc.h"
  11. #include "server.mod/server.h"
  12. #undef serv
  13. #include "channels.mod/channels.h"
  14. #ifdef HAVE_UNAME
  15. #include <sys/utsname.h>
  16. #endif
  17. #define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)
  18. #define IN_BOTS (CFG_INBOTS.gdata ? atoi(CFG_INBOTS.gdata) : 1)
  19. #define LAG_THRESHOLD (CFG_LAGTHRESHOLD.gdata ? atoi(CFG_LAGTHRESHOLD.gdata) : 15)
  20. #define OPREQ_COUNT (CFG_OPREQUESTS.gdata ? atoi( CFG_OPREQUESTS.gdata ) : 2)
  21. #define OPREQ_SECONDS (CFG_OPREQUESTS.gdata ? atoi( strchr(CFG_OPREQUESTS.gdata, ':') + 1 ) : 5)
  22. #define OP_TIME_SLACK (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
  23. #define msgop CFG_MSGOP.ldata ? CFG_MSGOP.ldata : CFG_MSGOP.gdata ? CFG_MSGOP.gdata : ""
  24. #define msgpass CFG_MSGPASS.ldata ? CFG_MSGPASS.ldata : CFG_MSGPASS.gdata ? CFG_MSGPASS.gdata : ""
  25. #define msginvite CFG_MSGINVITE.ldata ? CFG_MSGINVITE.ldata : CFG_MSGINVITE.gdata ? CFG_MSGINVITE.gdata : ""
  26. #define PRIO_DEOP 1
  27. #define PRIO_KICK 2
  28. int host_synced = 0;
  29. struct cfg_entry CFG_OPBOTS,
  30. CFG_INBOTS,
  31. CFG_LAGTHRESHOLD,
  32. CFG_OPTIMESLACK,
  33. #ifdef S_AUTOLOCK
  34. CFG_FIGHTTHRESHOLD,
  35. #endif /* S_AUTOLOCK */
  36. CFG_OPREQUESTS;
  37. static Function *global = NULL, *channels_funcs = NULL, *server_funcs = NULL;
  38. static int ctcp_mode;
  39. static int net_type = 0;
  40. static int strict_host;
  41. static int wait_split = 300; /* Time to wait for user to return from
  42. net-split. */
  43. static int max_bans = 25; /* Modified by net-type 1-4 */
  44. static int max_exempts = 20;
  45. static int max_invites = 20;
  46. static int max_modes = 20; /* Modified by net-type 1-4 */
  47. static int bounce_bans = 0;
  48. static int bounce_exempts = 0;
  49. static int bounce_invites = 0;
  50. static int bounce_modes = 0;
  51. static int learn_users = 0;
  52. static int wait_info = 180;
  53. static int invite_key = 1;
  54. static int no_chanrec_info = 0;
  55. static int modesperline = 4; /* Number of modes per line to send. */
  56. static int mode_buf_len = 200; /* Maximum bytes to send in 1 mode. */
  57. static int use_354 = 0; /* Use ircu's short 354 /who
  58. responses. */
  59. static int kick_method = 1; /* How many kicks does the irc network
  60. support at once?
  61. 0 = as many as possible.
  62. (Ernst 18/3/1998) */
  63. static int kick_fun = 0;
  64. static int ban_fun = 1;
  65. static int keepnick = 1; /* Keep nick */
  66. static int prevent_mixing = 1; /* To prevent mixing old/new modes */
  67. static int rfc_compliant = 1; /* net-type changing modifies this */
  68. static int include_lk = 1; /* For correct calculation
  69. in real_add_mode. */
  70. #include "chan.c"
  71. #include "mode.c"
  72. #include "cmdsirc.c"
  73. #include "msgcmds.c"
  74. #include "tclirc.c"
  75. static void detect_autokick(char *nick, char *uhost, struct chanset_t *chan, char *msg)
  76. {
  77. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0};
  78. struct userrec *u = NULL;
  79. int i = 0, tot = 0;
  80. if (!nick || !nick[0] || !uhost || !uhost[0] || !chan || !msg || !msg[0])
  81. return;
  82. tot = strlen(msg);
  83. u = get_user_by_host(uhost);
  84. get_user_flagrec(u, &fr, chan->dname);
  85. for(; *msg; ++msg) {
  86. if (egg_isupper(*msg))
  87. i++;
  88. }
  89. // if ((chan->capslimit)) {
  90. while (((msg) && *msg)) {
  91. if (egg_isupper(*msg))
  92. i++;
  93. msg++;
  94. }
  95. // if (chan->capslimit && ((i / tot) >= chan->capslimit)) {
  96. //dprintf(DP_MODE, "PRIVMSG %s :flood stats for %s: %d/%d are CAP, percentage: %d\n", chan->name, nick, i, tot, (i/tot)*100);
  97. // if ((((i / tot) * 100) >= 50)) {
  98. //dprintf(DP_HELP, "PRIVMSG %s :cap flood.\n", chan->dname);
  99. // }
  100. }
  101. void makeopline(struct chanset_t *chan, char *nick, char *buf)
  102. {
  103. char plaincookie[20], enccookie[48], *p, nck[20], key[200];
  104. memberlist * m;
  105. m=ismember(chan, nick);
  106. if (m)
  107. strcpy(nck, m->nick);
  108. else
  109. strcpy(nck, nick);
  110. makeplaincookie(chan->dname, nck, plaincookie);
  111. strcpy(key, botname);
  112. strcat(key, SALT2);
  113. // putlog(LOG_DEBUG, "*", "Encrypting opline for %s with cookie %s and key %s", nck, plaincookie, key);
  114. p = encrypt_string(key, plaincookie);
  115. strcpy(enccookie, p);
  116. nfree(p);
  117. sprintf(buf, STR("MODE %s +o-b %s *!*@<%s>\n"), chan->name, nck, enccookie);
  118. }
  119. void getin_request(char *botnick, char *code, char *par)
  120. {
  121. /*
  122. opreq = o #chan nick
  123. inreq = i #chan nick uhost
  124. inreq keyreply = K #chan key
  125. */
  126. char *tmp = NULL,
  127. *chname,
  128. *nck = NULL,
  129. *hst = NULL,
  130. *ip4 = NULL,
  131. *ip6 = NULL,
  132. *what = NULL,
  133. *p,
  134. *p2,
  135. *p3;
  136. struct chanset_t *chan;
  137. memberlist *mem = NULL;
  138. struct userrec *user;
  139. char nick[NICKLEN];
  140. char host[UHOSTLEN];
  141. char ip4host[UHOSTLEN];
  142. char ip6host[UHOSTLEN];
  143. char s[256],
  144. s2[16];
  145. int lim,
  146. curlim,
  147. sendi = 0;
  148. struct maskrec **mr,
  149. *tmr;
  150. struct maskstruct *b;
  151. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
  152. if (!server_online)
  153. return;
  154. if (!par[0] || !par)
  155. return;
  156. what = newsplit(&par);
  157. chname = newsplit(&par);
  158. if (!chname[0] || !chname)
  159. return;
  160. if (!(chan = findchan_by_dname(chname))) {
  161. putlog(LOG_GETIN, "*", STR("getin req from %s for %s which is not a valid channel!"), botnick, chname);
  162. return;
  163. }
  164. nck = newsplit(&par);
  165. if (!nck[0])
  166. return;
  167. hst = newsplit(&par);
  168. if (nck[0]) {
  169. strncpyz(nick, nck, sizeof(nick));
  170. } else
  171. nick[0] = 0;
  172. if (hst[0]) {
  173. strncpyz(host, hst, sizeof(host));
  174. ip4 = newsplit(&par);
  175. if (ip4[0]) {
  176. char *tmp2;
  177. tmp = nmalloc(strlen(host) + 1);
  178. strcpy(tmp, host);
  179. tmp2 = strtok(tmp, "@");
  180. egg_snprintf(ip4host, sizeof ip4host, "%s@%s", strtok(tmp2, "@") ,ip4);
  181. nfree(tmp);
  182. } else {
  183. ip4host[0] = 0;
  184. }
  185. ip6 = newsplit(&par);
  186. if (ip6[0]) {
  187. char *tmp2;
  188. tmp = nmalloc(strlen(host) + 1);
  189. strcpy(tmp, host);
  190. tmp2 = strtok(tmp, "@");
  191. egg_snprintf(ip6host, sizeof ip6host, "%s@%s", strtok(tmp2, "@") ,ip6);
  192. nfree(tmp);
  193. } else {
  194. ip6host[0] = 0;
  195. }
  196. } else
  197. host[0] = 0;
  198. Context;
  199. /*
  200. if (!ismember(chan, botname)) {
  201. putlog(LOG_GETIN, "*", STR("getin req from %s for %s - I'm not on %s!"), botnick, chname, chname);
  202. return;
  203. }
  204. */
  205. user = get_user_by_handle(userlist, botnick);
  206. if (nick[0])
  207. mem = ismember(chan, nick);
  208. if (what[0] == 'o') {
  209. if (!nick[0]) {
  210. putlog(LOG_GETIN, "*", STR("opreq from %s/??? on %s - No nick specified - SHOULD NOT HAPPEN"), botnick, chname);
  211. return;
  212. }
  213. if (!chan) {
  214. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - Channel %s doesn't exist"), botnick, nick, chname, chname);
  215. return;
  216. }
  217. if (!mem) {
  218. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - %s isn't on %s"), botnick, nick, chan->dname, nick, chan->dname);
  219. return;
  220. }
  221. if (!user) {
  222. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - No user called %s in userlist"), botnick, nick, chan->dname, botnick);
  223. return;
  224. }
  225. if (mem->user != user) {
  226. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - %s doesn't match %s"), botnick, nick, chan->dname, nick, botnick);
  227. return;
  228. }
  229. get_user_flagrec(user, &fr, chan->dname);
  230. if ((!chan_op(fr) && !glob_op(fr)) || (glob_deop(fr) && !chan_op(fr))) {
  231. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - %s doesnt have +o for chan."), botnick, nick, chan->dname, botnick);
  232. return;
  233. }
  234. if (chan_hasop(mem)) {
  235. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - %s already has ops"), botnick, nick, chan->dname, nick);
  236. return;
  237. }
  238. if (chan_issplit(mem)) {
  239. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - %s is split"), botnick, nick, chan->dname, nick);
  240. return;
  241. }
  242. if (!me_op(chan)) {
  243. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - I haven't got ops"), botnick, nick, chan->dname);
  244. return;
  245. }
  246. if (chan_sentop(mem)) {
  247. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - Already sent a +o"), botnick, nick, chan->dname);
  248. return;
  249. }
  250. if (server_lag > LAG_THRESHOLD) {
  251. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - I'm too lagged"), botnick, nick, chan->dname);
  252. return;
  253. }
  254. if (getting_users()) {
  255. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - I'm getting userlist right now"), botnick, nick, chan->dname);
  256. return;
  257. }
  258. if (chan->channel.no_op) {
  259. if (chan->channel.no_op > now) /* dont op until this time has passed */
  260. return;
  261. else
  262. chan->channel.no_op = 0;
  263. }
  264. do_op(nick, chan, 1);
  265. mem->flags |= SENTOP;
  266. putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - Opped"), botnick, nick, chan->dname);
  267. } else if (what[0] == 'i') {
  268. Context;
  269. strcpy(s, getchanmode(chan));
  270. p = (char *) &s;
  271. p2 = newsplit(&p);
  272. p3 = newsplit(&p);
  273. if (!nick[0]) {
  274. putlog(LOG_GETIN, "*", STR("inreq from %s/??? for %s - No nick specified - SHOULD NOT HAPPEN"), botnick, chname);
  275. return;
  276. }
  277. if (!chan) {
  278. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Channel %s doesn't exist"), botnick, nick, chname, chname);
  279. return;
  280. }
  281. if (mem) {
  282. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - %s is already on %s"), botnick, nick, chan->dname, nick, chan->dname);
  283. return;
  284. }
  285. if (!user) {
  286. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - No user called %s in userlist"), botnick, nick, chan->dname, botnick);
  287. return;
  288. }
  289. get_user_flagrec(user, &fr, chan->dname);
  290. if ((!chan_op(fr) && !glob_op(fr)) || (glob_deop(fr) && !chan_op(fr))) {
  291. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - %s doesn't have acces for chan."), botnick, nick, chan->dname, botnick);
  292. return;
  293. }
  294. if (server_lag > LAG_THRESHOLD) {
  295. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - I'm too lagged"), botnick, nick, chan->dname);
  296. return;
  297. }
  298. if (getting_users()) {
  299. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - I'm getting userlist right now"), botnick, nick, chan->dname);
  300. return;
  301. }
  302. if (!(channel_pending(chan) || channel_active(chan))) {
  303. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - I'm not on %s now"), botnick, nick, chan->dname, chan->dname);
  304. return;
  305. }
  306. if (strchr(p2, 'l')) {
  307. if (!me_op(chan))
  308. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - I haven't got ops"), botnick, nick, chan->dname);
  309. else {
  310. lim = chan->channel.members + 5;
  311. if (!*p)
  312. curlim = atoi(p3);
  313. else
  314. curlim = atoi(p);
  315. if (curlim > 0 && curlim < lim) {
  316. sendi = 1;
  317. simple_sprintf(s2, STR("%d"), lim);
  318. add_mode(chan, '+', 'l', s2);
  319. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Raised limit to %d"), botnick, nick, chan->dname, lim, nick);
  320. }
  321. }
  322. }
  323. mr = &global_bans;
  324. while (*mr) {
  325. if (wild_match((*mr)->mask, host) || wild_match((*mr)->mask, ip4host) || wild_match((*mr)->mask, ip6host)) {
  326. if (!noshare) {
  327. shareout(NULL, STR("-b %s\n"), (*mr)->mask);
  328. }
  329. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Removed permanent global ban %s"), botnick, nick, chan->dname, (*mr)->mask);
  330. //gban_total--;
  331. nfree((*mr)->mask);
  332. if ((*mr)->desc)
  333. nfree((*mr)->desc);
  334. if ((*mr)->user)
  335. nfree((*mr)->user);
  336. tmr = *mr;
  337. *mr = (*mr)->next;
  338. nfree(tmr);
  339. } else {
  340. mr = &((*mr)->next);
  341. }
  342. }
  343. mr = &chan->bans;
  344. while (*mr) {
  345. if (wild_match((*mr)->mask, host) || wild_match((*mr)->mask, ip4host) || wild_match((*mr)->mask, ip6host)) {
  346. if (!noshare) {
  347. shareout(NULL, STR("-bc %s %s\n"), chan->dname, (*mr)->mask);
  348. }
  349. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Removed permanent channel ban %s"), botnick, nick, chan->dname, (*mr)->mask);
  350. nfree((*mr)->mask);
  351. if ((*mr)->desc)
  352. nfree((*mr)->desc);
  353. if ((*mr)->user)
  354. nfree((*mr)->user);
  355. tmr = *mr;
  356. *mr = (*mr)->next;
  357. nfree(tmr);
  358. } else {
  359. mr = &((*mr)->next);
  360. }
  361. }
  362. for (b = chan->channel.ban; b->mask[0]; b = b->next) {
  363. if (wild_match(b->mask, host) || wild_match(b->mask, ip4host) || wild_match(b->mask, ip6host)) {
  364. add_mode(chan, '-', 'b', b->mask);
  365. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Removed active ban %s"), botnick, nick, chan->dname, b->mask);
  366. sendi = 1;
  367. }
  368. }
  369. if (strchr(p2, 'k')) {
  370. sendi = 0;
  371. tmp = nmalloc(strlen(chan->dname) + strlen(p3) + 7);
  372. sprintf(tmp, STR("gi K %s %s"), chan->dname, p3);
  373. botnet_send_zapf(nextbot(botnick), botnetnick, botnick, tmp);
  374. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Sent key (%s)"), botnick, nick, chan->dname, p3);
  375. nfree(tmp);
  376. }
  377. if (strchr(p2, 'i')) {
  378. if (!me_op(chan))
  379. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - I haven't got ops"), botnick, nick, chan->dname);
  380. else {
  381. sendi = 1;
  382. putlog(LOG_GETIN, "*", STR("inreq from %s/%s for %s - Invited"), botnick, nick, chan->dname);
  383. }
  384. }
  385. if (sendi && me_op(chan))
  386. dprintf(DP_MODE, STR("INVITE %s %s\n"), nick, chan->name);
  387. } else if (what[0] == 'K') {
  388. if (!chan) {
  389. putlog(LOG_GETIN, "*", STR("Got key for nonexistant channel %s from %s"), chname, botnick);
  390. return;
  391. }
  392. if (!shouldjoin(chan)) {
  393. putlog(LOG_GETIN, "*", STR("Got key for %s from %s - I shouldn't be on that chan?!?"), chan->dname, botnick);
  394. } else {
  395. if (!(channel_pending(chan) || channel_active(chan))) {
  396. putlog(LOG_GETIN, "*", STR("Got key for %s from %s (%s) - Joining"), chan->dname, botnick, nick);
  397. dprintf(DP_MODE, STR("JOIN %s %s\n"), chan->dname, nick);
  398. } else {
  399. putlog(LOG_GETIN, "*", STR("Got key for %s from %s - I'm already in the channel"), chan->dname, botnick);
  400. }
  401. }
  402. }
  403. }
  404. void check_hostmask()
  405. {
  406. char s[UHOSTLEN + 2], *tmp = NULL;
  407. struct userrec *u = get_user_by_handle(userlist, botnetnick);
  408. struct list_type *q;
  409. if (!server_online || !botuserhost[0])
  410. return;
  411. tmp = botuserhost;
  412. if (!tmp[0] || !tmp[1]) return;
  413. if (tmp[0] != '~')
  414. sprintf(s, STR("*!%s"), tmp);
  415. else {
  416. tmp++;
  417. sprintf(s, STR("*!*%s"), tmp);
  418. }
  419. for (q = get_user(&USERENTRY_HOSTS, u); q; q = q->next) {
  420. if (!strcasecmp(q->extra, s))
  421. return;
  422. }
  423. addhost_by_handle(botnetnick, s);
  424. putlog(LOG_GETIN, "*", STR("Updated my hostmask: %s"), s);
  425. }
  426. static void request_op(struct chanset_t *chan)
  427. {
  428. int i = 0, exp = 0, first = 100, n, cnt, i2;
  429. memberlist *ml;
  430. memberlist *botops[MAX_BOTS];
  431. char s[100], *l, myserv[SERVLEN];
  432. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
  433. Context;
  434. if (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan))
  435. return;
  436. chan->channel.do_opreq = 0;
  437. if (me_op(chan))
  438. return;
  439. /* check server lag */
  440. if (server_lag > LAG_THRESHOLD) {
  441. putlog(LOG_GETIN, "*", STR("Not asking for ops on %s - I'm too lagged"), chan->dname);
  442. return;
  443. }
  444. /* max OPREQ_COUNT requests per OPREQ_SECONDS sec */
  445. n = time(NULL);
  446. while (i < 5) {
  447. if (n - chan->opreqtime[i] > OPREQ_SECONDS) {
  448. if (first > i)
  449. first = i;
  450. exp++;
  451. chan->opreqtime[i] = 0;
  452. }
  453. i++;
  454. }
  455. if ((5 - exp) >= OPREQ_COUNT) {
  456. putlog(LOG_GETIN, "*", STR("Delaying opreq for %s - Maximum of %d:%d reached"), chan->dname, OPREQ_COUNT, OPREQ_SECONDS);
  457. return;
  458. }
  459. check_hostmask(); /* check, and update hostmask */
  460. i = 0;
  461. ml = chan->channel.member;
  462. myserv[0] = 0;
  463. while ((i < MAX_BOTS) && (ml) && ml->nick[0]) {
  464. /* If bot, linked, global op & !split & chanop & (chan is reserver | bot isn't +a) ->
  465. add to temp list */
  466. if ((i < MAX_BOTS) && (ml->user)) {
  467. get_user_flagrec(ml->user, &fr, NULL);
  468. if (bot_hublevel(ml->user) == 999 && glob_bot(fr) && glob_op(fr)
  469. && !glob_deop(fr) && chan_hasop(ml) && !chan_issplit(ml)
  470. && nextbot(ml->user->handle) >= 0)
  471. botops[i++] = ml;
  472. }
  473. if (!strcmp(ml->nick, botname))
  474. if (ml->server)
  475. strcpy(myserv, ml->server);
  476. ml = ml->next;
  477. }
  478. if (!i) {
  479. putlog(LOG_GETIN, "@", STR("No one to ask for ops on %s"), chan->dname);
  480. return;
  481. }
  482. if (chan->channel.no_op) {
  483. if (chan->channel.no_op > now) /* dont op until this time has passed */
  484. return;
  485. else
  486. chan->channel.no_op = 0;
  487. }
  488. /* first scan for bots on my server, ask first found for ops */
  489. cnt = OP_BOTS;
  490. sprintf(s, STR("gi o %s %s"), chan->dname, botname);
  491. l = nmalloc(cnt * 50);
  492. l[0] = 0;
  493. for (i2 = 0; i2 < i; i2++) {
  494. if (botops[i2]->server && (!strcmp(botops[i2]->server, myserv))) {
  495. putbot(botops[i2]->user->handle, s);
  496. chan->opreqtime[first] = n;
  497. if (l[0]) {
  498. strcat(l, ", ");
  499. strcat(l, botops[i2]->user->handle);
  500. } else {
  501. strcpy(l, botops[i2]->user->handle);
  502. }
  503. strcat(l, "/");
  504. strcat(l, botops[i2]->nick);
  505. botops[i2] = NULL;
  506. cnt--;
  507. break;
  508. }
  509. }
  510. /* Pick random op and ask for ops */
  511. while (cnt) {
  512. i2 = random() % i;
  513. if (botops[i2]) {
  514. putbot(botops[i2]->user->handle, s);
  515. chan->opreqtime[first] = n;
  516. if (l[0]) {
  517. strcat(l, ", ");
  518. strcat(l, botops[i2]->user->handle);
  519. } else {
  520. strcpy(l, botops[i2]->user->handle);
  521. }
  522. strcat(l, "/");
  523. strcat(l, botops[i2]->nick);
  524. cnt--;
  525. botops[i2] = NULL;
  526. } else {
  527. if (i < OP_BOTS)
  528. cnt--;
  529. }
  530. }
  531. putlog(LOG_GETIN, "*", STR("Requested ops on %s from %s"), chan->dname, l);
  532. nfree(l);
  533. }
  534. static void request_in(struct chanset_t *chan)
  535. {
  536. char s[255],
  537. *l;
  538. int i = 0;
  539. int cnt,
  540. n;
  541. struct userrec *botops[MAX_BOTS];
  542. struct userrec *user;
  543. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
  544. for (user = userlist; user && (i < MAX_BOTS); user = user->next) {
  545. get_user_flagrec(user, &fr, NULL);
  546. if (bot_hublevel(user) == 999 && glob_bot(fr) && glob_op(fr)
  547. #ifdef G_BACKUP
  548. && (!glob_backupbot(fr) || channel_backup(chan))
  549. #endif
  550. && nextbot(user->handle) >= 0)
  551. botops[i++] = user;
  552. }
  553. if (!i) {
  554. putlog(LOG_GETIN, "*", STR("No bots linked, can't request help to join %s"), chan->dname);
  555. return;
  556. }
  557. check_hostmask(); /* check, and update hostmask */
  558. cnt = IN_BOTS;
  559. sprintf(s, STR("gi i %s %s %s!%s %s %s"), chan->dname, botname, botname, botuserhost, myipstr(4) ? myipstr(4) : "."
  560. , myipstr(6) ? myipstr(6) : ".");
  561. l = nmalloc(cnt * 30);
  562. l[0] = 0;
  563. while (cnt) {
  564. n = random() % i;
  565. if (botops[n]) {
  566. botnet_send_zapf(nextbot(botops[n]->handle), botnetnick, botops[n]->handle, s);
  567. if (l[0]) {
  568. strcat(l, ", ");
  569. strcat(l, botops[n]->handle);
  570. } else {
  571. strcpy(l, botops[n]->handle);
  572. }
  573. botops[n] = NULL;
  574. cnt--;
  575. } else {
  576. if (i < IN_BOTS)
  577. cnt--;
  578. }
  579. }
  580. putlog(LOG_GETIN, "*", STR("Requesting help to join %s from %s"), chan->dname, l);
  581. nfree(l);
  582. }
  583. /* Contains the logic to decide wether we want to punish someone. Returns
  584. * true (1) if we want to, false (0) if not.
  585. */
  586. static int want_to_revenge(struct chanset_t *chan, struct userrec *u,
  587. struct userrec *u2, char *badnick, char *victim,
  588. int mevictim)
  589. {
  590. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
  591. /* Do not take revenge upon ourselves. */
  592. if (match_my_nick(badnick))
  593. return 0;
  594. get_user_flagrec(u, &fr, chan->dname);
  595. /* Kickee didn't kick themself? */
  596. if (rfc_casecmp(badnick, victim)) {
  597. /* They kicked me? */
  598. if (mevictim) {
  599. /* ... and I'm allowed to take revenge? <snicker> */
  600. if (channel_revengebot(chan))
  601. return 1;
  602. /* Do we revenge for our users ... and do we actually know the victim? */
  603. } else if (channel_revenge(chan) && u2) {
  604. struct flag_record fr2 = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
  605. get_user_flagrec(u2, &fr2, chan->dname);
  606. /* Protecting friends? */
  607. /* Protecting ops? */
  608. if ((channel_protectops(chan) &&
  609. /* ... and kicked is valid op? */
  610. (chan_op(fr2) || (glob_op(fr2) && !chan_deop(fr2)))))
  611. return 1;
  612. }
  613. }
  614. return 0;
  615. }
  616. /* Dependant on revenge_mode, punish the offender.
  617. */
  618. static void punish_badguy(struct chanset_t *chan, char *whobad,
  619. struct userrec *u, char *badnick, char *victim,
  620. int mevictim, int type)
  621. {
  622. char reason[1024], ct[81], *kick_msg;
  623. memberlist *m;
  624. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
  625. m = ismember(chan, badnick);
  626. if (!m)
  627. return;
  628. get_user_flagrec(u, &fr, chan->dname);
  629. /* Get current time into a string */
  630. #ifdef S_UTCTIME
  631. egg_strftime(ct, sizeof ct, "%d %b %Z", gmtime(&now));
  632. #else /* !S_UTCTIME */
  633. egg_strftime(ct, sizeof ct, "%d %b %Z", localtime(&now));
  634. #endif /* S_UTCTIME */
  635. /* Put together log and kick messages */
  636. reason[0] = 0;
  637. switch (type) {
  638. case REVENGE_KICK:
  639. kick_msg = IRC_KICK_PROTECT;
  640. simple_sprintf(reason, "kicked %s off %s", victim, chan->dname);
  641. break;
  642. case REVENGE_DEOP:
  643. simple_sprintf(reason, "deopped %s on %s", victim, chan->dname);
  644. kick_msg = IRC_DEOP_PROTECT;
  645. break;
  646. default:
  647. kick_msg = "revenge!";
  648. }
  649. putlog(LOG_MISC, chan->dname, "Punishing %s (%s)", badnick, reason);
  650. /* Set the offender +d */
  651. if ((chan->revenge_mode > 0) &&
  652. /* ... unless there's no more to do */
  653. !(chan_deop(fr) || glob_deop(fr))) {
  654. char s[UHOSTLEN], s1[UHOSTLEN];
  655. memberlist *mx = NULL;
  656. /* Removing op */
  657. if (chan_op(fr) || (glob_op(fr) && !chan_deop(fr))) {
  658. fr.match = FR_CHAN;
  659. if (chan_op(fr)) {
  660. fr.chan &= ~USER_OP;
  661. } else {
  662. fr.chan |= USER_DEOP;
  663. }
  664. set_user_flagrec(u, &fr, chan->dname);
  665. putlog(LOG_MISC, "*", "No longer opping %s[%s] (%s)", u->handle, whobad,
  666. reason);
  667. }
  668. /* ... or just setting to deop */
  669. else if (u) {
  670. /* In the user list already, cool :) */
  671. fr.match = FR_CHAN;
  672. fr.chan |= USER_DEOP;
  673. set_user_flagrec(u, &fr, chan->dname);
  674. simple_sprintf(s, "(%s) %s", ct, reason);
  675. putlog(LOG_MISC, "*", "Now deopping %s[%s] (%s)", u->handle, whobad, s);
  676. }
  677. /* ... or creating new user and setting that to deop */
  678. else {
  679. strcpy(s1, whobad);
  680. maskhost(s1, s);
  681. strcpy(s1, badnick);
  682. /* If that handle exists use "badX" (where X is an increasing number)
  683. * instead.
  684. */
  685. while (get_user_by_handle(userlist, s1)) {
  686. if (!strncmp(s1, "bad", 3)) {
  687. int i;
  688. i = atoi(s1 + 3);
  689. simple_sprintf(s1 + 3, "%d", i + 1);
  690. } else
  691. strcpy(s1, "bad1"); /* Start with '1' */
  692. }
  693. userlist = adduser(userlist, s1, s, "-", 0);
  694. fr.match = FR_CHAN;
  695. fr.chan = USER_DEOP;
  696. fr.udef_chan = 0;
  697. u = get_user_by_handle(userlist, s1);
  698. if ((mx = ismember(chan, badnick)))
  699. mx->user = u;
  700. set_user_flagrec(u, &fr, chan->dname);
  701. simple_sprintf(s, "(%s) %s (%s)", ct, reason, whobad);
  702. set_user(&USERENTRY_COMMENT, u, (void *) s);
  703. putlog(LOG_MISC, "*", "Now deopping %s (%s)", whobad, reason);
  704. }
  705. }
  706. /* Always try to deop the offender */
  707. if (!mevictim)
  708. add_mode(chan, '-', 'o', badnick);
  709. /* Ban. Should be done before kicking. */
  710. if (chan->revenge_mode > 2) {
  711. char s[UHOSTLEN], s1[UHOSTLEN];
  712. splitnick(&whobad);
  713. maskhost(whobad, s1);
  714. simple_sprintf(s, "(%s) %s", ct, reason);
  715. u_addban(chan, s1, botnetnick, s, now + (60 * chan->ban_time), 0);
  716. if (!mevictim && me_op(chan)) {
  717. add_mode(chan, '+', 'b', s1);
  718. flush_mode(chan, QUICK);
  719. }
  720. }
  721. /* Kick the offender */
  722. if ((chan->revenge_mode > 1) &&
  723. !chan_sentkick(m) &&
  724. /* ... and can I actually do anything about it? */
  725. me_op(chan) && !mevictim) {
  726. dprintf(DP_MODE, STR("KICK %s %s :%s%s\n"), chan->name, m->nick, bankickprefix, kickreason(KICK_MEAN));
  727. m->flags |= SENTKICK;
  728. }
  729. }
  730. /* Punishes bad guys under certain circumstances using methods as defined
  731. * by the revenge_mode flag.
  732. */
  733. static void maybe_revenge(struct chanset_t *chan, char *whobad,
  734. char *whovictim, int type)
  735. {
  736. char *badnick, *victim;
  737. int mevictim;
  738. struct userrec *u, *u2;
  739. if (!chan || (type < 0))
  740. return;
  741. /* Get info about offender */
  742. u = get_user_by_host(whobad);
  743. badnick = splitnick(&whobad);
  744. /* Get info about victim */
  745. u2 = get_user_by_host(whovictim);
  746. victim = splitnick(&whovictim);
  747. mevictim = match_my_nick(victim);
  748. /* Do we want to revenge? */
  749. if (!want_to_revenge(chan, u, u2, badnick, victim, mevictim))
  750. return; /* No, leave them alone ... */
  751. /* Haha! Do the vengeful thing ... */
  752. punish_badguy(chan, whobad, u, badnick, victim, mevictim, type);
  753. }
  754. /* Set the key.
  755. */
  756. static void my_setkey(struct chanset_t *chan, char *k)
  757. {
  758. nfree(chan->channel.key);
  759. if (k == NULL) {
  760. chan->channel.key = (char *) channel_malloc(1);
  761. chan->channel.key[0] = 0;
  762. return;
  763. }
  764. chan->channel.key = (char *) channel_malloc(strlen(k) + 1);
  765. strcpy(chan->channel.key, k);
  766. }
  767. /* Adds a ban, exempt or invite mask to the list
  768. * m should be chan->channel.(exempt|invite|ban)
  769. */
  770. static void newmask(masklist *m, char *s, char *who)
  771. {
  772. for (; m && m->mask[0] && rfc_casecmp(m->mask, s); m = m->next);
  773. if (m->mask[0])
  774. return; /* Already existent mask */
  775. m->next = (masklist *) channel_malloc(sizeof(masklist));
  776. m->next->next = NULL;
  777. m->next->mask = (char *) channel_malloc(1);
  778. m->next->mask[0] = 0;
  779. nfree(m->mask);
  780. m->mask = (char *) channel_malloc(strlen(s) + 1);
  781. strcpy(m->mask, s);
  782. m->who = (char *) channel_malloc(strlen(who) + 1);
  783. strcpy(m->who, who);
  784. m->timer = now;
  785. }
  786. /* Removes a nick from the channel member list (returns 1 if successful)
  787. */
  788. static int killmember(struct chanset_t *chan, char *nick)
  789. {
  790. memberlist *x, *old;
  791. old = NULL;
  792. for (x = chan->channel.member; x && x->nick[0]; old = x, x = x->next)
  793. if (!rfc_casecmp(x->nick, nick))
  794. break;
  795. if (!x || !x->nick[0]) {
  796. if (!channel_pending(chan))
  797. putlog(LOG_MISC, "*", "(!) killmember(%s) -> nonexistent", nick);
  798. return 0;
  799. }
  800. if (old)
  801. old->next = x->next;
  802. else
  803. chan->channel.member = x->next;
  804. nfree(x);
  805. chan->channel.members--;
  806. /* The following two errors should NEVER happen. We will try to correct
  807. * them though, to keep the bot from crashing.
  808. */
  809. if (chan->channel.members < 0) {
  810. chan->channel.members = 0;
  811. for (x = chan->channel.member; x && x->nick[0]; x = x->next)
  812. chan->channel.members++;
  813. putlog(LOG_MISC, "*", "(!) actually I know of %d members.",
  814. chan->channel.members);
  815. }
  816. if (!chan->channel.member) {
  817. chan->channel.member = (memberlist *) channel_malloc(sizeof(memberlist));
  818. chan->channel.member->nick[0] = 0;
  819. chan->channel.member->next = NULL;
  820. }
  821. return 1;
  822. }
  823. /* Check if I am a chanop. Returns boolean 1 or 0.
  824. */
  825. static int me_op(struct chanset_t *chan)
  826. {
  827. memberlist *mx = NULL;
  828. mx = ismember(chan, botname);
  829. if (!mx)
  830. return 0;
  831. if (chan_hasop(mx))
  832. return 1;
  833. else
  834. return 0;
  835. }
  836. /* Check whether I'm voice. Returns boolean 1 or 0.
  837. */
  838. static int me_voice(struct chanset_t *chan)
  839. {
  840. memberlist *mx;
  841. mx = ismember(chan, botname);
  842. if (!mx)
  843. return 0;
  844. if (chan_hasvoice(mx))
  845. return 1;
  846. else
  847. return 0;
  848. }
  849. /* Check if there are any ops on the channel. Returns boolean 1 or 0.
  850. */
  851. static int any_ops(struct chanset_t *chan)
  852. {
  853. memberlist *x;
  854. for (x = chan->channel.member; x && x->nick[0]; x = x->next)
  855. if (chan_hasop(x))
  856. break;
  857. if (!x || !x->nick[0])
  858. return 0;
  859. return 1;
  860. }
  861. /* Reset the channel information.
  862. */
  863. static void reset_chan_info(struct chanset_t *chan)
  864. {
  865. int opped = 0;
  866. /* Don't reset the channel if we're already resetting it */
  867. if (!shouldjoin(chan)) {
  868. dprintf(DP_MODE,"PART %s\n", chan->name);
  869. return;
  870. }
  871. if (!channel_pending(chan)) {
  872. if (me_op(chan))
  873. opped += 1;
  874. nfree(chan->channel.key);
  875. chan->channel.key = (char *) channel_malloc(1);
  876. chan->channel.key[0] = 0;
  877. clear_channel(chan, 1);
  878. chan->status |= CHAN_PEND;
  879. chan->status &= ~(CHAN_ACTIVE | CHAN_ASKEDMODES);
  880. if (!(chan->status & CHAN_ASKEDBANS)) {
  881. chan->status |= CHAN_ASKEDBANS;
  882. dprintf(DP_MODE, "MODE %s +b\n", chan->name);
  883. }
  884. if (opped) {
  885. if (!(chan->ircnet_status & CHAN_ASKED_EXEMPTS) &&
  886. use_exempts == 1) {
  887. chan->ircnet_status |= CHAN_ASKED_EXEMPTS;
  888. dprintf(DP_MODE, "MODE %s +e\n", chan->name);
  889. }
  890. if (!(chan->ircnet_status & CHAN_ASKED_INVITED) &&
  891. use_invites == 1) {
  892. chan->ircnet_status |= CHAN_ASKED_INVITED;
  893. dprintf(DP_MODE, "MODE %s +I\n", chan->name);
  894. }
  895. }
  896. /* These 2 need to get out asap, so into the mode queue */
  897. dprintf(DP_MODE, "MODE %s\n", chan->name);
  898. if (use_354)
  899. dprintf(DP_MODE, "WHO %s %%c%%h%%n%%u%%f\n", chan->name);
  900. else
  901. dprintf(DP_MODE, "WHO %s\n", chan->name);
  902. /* clear_channel nuked the data...so */
  903. }
  904. }
  905. /* Leave the specified channel and notify registered Tcl procs. This
  906. * should not be called by itsself.
  907. */
  908. static void do_channel_part(struct chanset_t *chan)
  909. {
  910. if (shouldjoin(chan) && chan->name[0]) {
  911. /* Using chan->name is important here, especially for !chans <cybah> */
  912. dprintf(DP_SERVER, "PART %s\n", chan->name);
  913. /* As we don't know of this channel anymore when we receive the server's
  914. ack for the above PART, we have to notify about it _now_. */
  915. }
  916. }
  917. /* If i'm the only person on the channel, and i'm not op'd,
  918. * might as well leave and rejoin. If i'm NOT the only person
  919. * on the channel, but i'm still not op'd, demand ops.
  920. */
  921. static void check_lonely_channel(struct chanset_t *chan)
  922. {
  923. memberlist *m;
  924. char s[UHOSTLEN];
  925. int i = 0;
  926. static int whined = 0;
  927. if (channel_pending(chan) || !channel_active(chan) || me_op(chan) ||
  928. !shouldjoin(chan) || (chan->channel.mode & CHANANON))
  929. return;
  930. /* Count non-split channel members */
  931. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  932. if (!chan_issplit(m))
  933. i++;
  934. if (i == 1 && channel_cycle(chan) && !channel_stop_cycle(chan)) {
  935. if (chan->name[0] != '+') { /* Its pointless to cycle + chans for ops */
  936. putlog(LOG_MISC, "*", "Trying to cycle %s to regain ops.", chan->dname);
  937. dprintf(DP_MODE, "PART %s\n", chan->name);
  938. /* If it's a !chan, we need to recreate the channel with !!chan <cybah> */
  939. dprintf(DP_MODE, "JOIN %s%s %s\n", (chan->dname[0] == '!') ? "!" : "",
  940. chan->dname, chan->key_prot);
  941. whined = 0;
  942. }
  943. } else if (any_ops(chan)) {
  944. whined = 0;
  945. request_op(chan);
  946. /* need: op */
  947. } else {
  948. /* Other people here, but none are ops. If there are other bots make
  949. * them LEAVE!
  950. */
  951. int ok = 1;
  952. struct userrec *u;
  953. if (!whined) {
  954. /* + is opless. Complaining about no ops when without special
  955. * help(services), we cant get them - Raist
  956. */
  957. if (chan->name[0] != '+')
  958. putlog(LOG_MISC, "*", "%s is active but has no ops :(", chan->dname);
  959. whined = 1;
  960. }
  961. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  962. sprintf(s, "%s!%s", m->nick, m->userhost);
  963. u = get_user_by_host(s);
  964. if (!match_my_nick(m->nick) && (!u || !(u->flags & USER_BOT))) {
  965. ok = 0;
  966. break;
  967. }
  968. }
  969. if (ok && channel_cycle(chan)) {
  970. /* ALL bots! make them LEAVE!!! */
  971. /*
  972. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  973. if (!match_my_nick(m->nick))
  974. dprintf(DP_SERVER, "PRIVMSG %s :go %s\n", m->nick, chan->dname);
  975. */
  976. } else {
  977. /* Some humans on channel, but still op-less */
  978. request_op(chan);
  979. /* need: op */
  980. }
  981. }
  982. }
  983. static void warn_pls_take()
  984. {
  985. struct chanset_t *chan;
  986. for (chan = chanset; chan; chan = chan->next)
  987. if (channel_take(chan) && me_op(chan))
  988. putlog(LOG_WARN, "*", "%s is set +take, and I'm already opped! +take is insecure, try +bitch instead", chan->dname);
  989. }
  990. void check_servers() {
  991. struct chanset_t *chan;
  992. for (chan = chanset; chan; chan = chan->next) {
  993. memberlist *m;
  994. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  995. if (chan_hasop(m) && ((!m->server || !m->server[0]) || !m->hops)) {
  996. dprintf(DP_HELP, STR("WHO %s\n"), chan->name);
  997. return;
  998. }
  999. }
  1000. }
  1001. }
  1002. #ifdef S_AUTOLOCK
  1003. void check_netfight()
  1004. {
  1005. int limit = atoi(CFG_FIGHTTHRESHOLD.gdata ? CFG_FIGHTTHRESHOLD.gdata : "0");
  1006. Context;
  1007. if (limit) {
  1008. struct chanset_t *chan;
  1009. for (chan = chanset; chan; chan = chan->next) {
  1010. Context;
  1011. if ((chan->channel.fighting) && (chan->channel.fighting > limit)) {
  1012. Context;
  1013. if (!channel_bitch(chan) || !channel_closed(chan)) {
  1014. Context;
  1015. putlog(LOG_WARN, "*", STR("Auto-closed %s - channel fight\n"), chan->dname);
  1016. Context;
  1017. do_chanset(chan, STR("+bitch +closed"), 1);
  1018. Context;
  1019. enforce_closed(chan);
  1020. Context;
  1021. dprintf(DP_MODE, STR("TOPIC %s :Auto-closed - channel fight\n"), chan->name);
  1022. Context;
  1023. }
  1024. Context;
  1025. }
  1026. chan->channel.fighting = 0; /* we put this here because we need to clear it once per min */
  1027. }
  1028. }
  1029. Context;
  1030. }
  1031. #endif /* S_AUTOLOCK */
  1032. void raise_limit(struct chanset_t * chan) {
  1033. int nl, cl, i, mem, ul, ll;
  1034. char s[50];
  1035. if (!chan || !me_op(chan)) {
  1036. return;
  1037. }
  1038. mem = chan->channel.members; //members
  1039. nl = mem + chan->limitraise; //new limit
  1040. cl = chan->channel.maxmembers; //current limit
  1041. i = chan->limitraise / 4;
  1042. /* if the newlimit will be in the range made by these vars, dont change. */
  1043. ul = nl + i; //upper limit range
  1044. ll = nl - i; //lower limit range
  1045. if (cl > ll && cl < ul) {
  1046. return; /* the current limit is in the range, so leave it. */
  1047. }
  1048. if (nl != chan->channel.maxmembers) {
  1049. sprintf(s, "%d", nl);
  1050. add_mode(chan, '+', 'l', s);
  1051. }
  1052. }
  1053. static void check_expired_chanstuff()
  1054. {
  1055. masklist *b, *e;
  1056. memberlist *m, *n;
  1057. char s[UHOSTLEN];
  1058. struct chanset_t *chan;
  1059. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1060. if (!server_online)
  1061. return;
  1062. for (chan = chanset; chan; chan = chan->next) {
  1063. if (channel_active(chan)) {
  1064. if (me_op(chan)) {
  1065. if (channel_dynamicbans(chan) && chan->ban_time)
  1066. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1067. if (now - b->timer > 60 * chan->ban_time &&
  1068. !u_sticky_mask(chan->bans, b->mask) &&
  1069. !u_sticky_mask(global_bans, b->mask) &&
  1070. expired_mask(chan, b->who)) {
  1071. putlog(LOG_MODES, chan->dname,
  1072. "(%s) Channel ban on %s expired.",
  1073. chan->dname, b->mask);
  1074. add_mode(chan, '-', 'b', b->mask);
  1075. b->timer = now;
  1076. }
  1077. if (use_exempts && channel_dynamicexempts(chan) && chan->exempt_time)
  1078. for (e = chan->channel.exempt; e->mask[0]; e = e->next)
  1079. if (now - e->timer > 60 * chan->exempt_time &&
  1080. !u_sticky_mask(chan->exempts, e->mask) &&
  1081. !u_sticky_mask(global_exempts, e->mask) &&
  1082. expired_mask(chan, e->who)) {
  1083. /* Check to see if it matches a ban */
  1084. int match = 0;
  1085. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1086. if (wild_match(b->mask, e->mask) ||
  1087. wild_match(e->mask, b->mask)) {
  1088. match = 1;
  1089. break;
  1090. }
  1091. /* Leave this extra logging in for now. Can be removed later
  1092. * Jason
  1093. */
  1094. if (match) {
  1095. putlog(LOG_MODES, chan->dname,
  1096. "(%s) Channel exemption %s NOT expired. Exempt still set!",
  1097. chan->dname, e->mask);
  1098. } else {
  1099. putlog(LOG_MODES, chan->dname,
  1100. "(%s) Channel exemption on %s expired.",
  1101. chan->dname, e->mask);
  1102. add_mode(chan, '-', 'e', e->mask);
  1103. }
  1104. e->timer = now;
  1105. }
  1106. if (use_invites && channel_dynamicinvites(chan) &&
  1107. chan->invite_time && !(chan->channel.mode & CHANINV))
  1108. for (b = chan->channel.invite; b->mask[0]; b = b->next)
  1109. if (now - b->timer > 60 * chan->invite_time &&
  1110. !u_sticky_mask(chan->invites, b->mask) &&
  1111. !u_sticky_mask(global_invites, b->mask) &&
  1112. expired_mask(chan, b->who)) {
  1113. putlog(LOG_MODES, chan->dname,
  1114. "(%s) Channel invitation on %s expired.",
  1115. chan->dname, b->mask);
  1116. add_mode(chan, '-', 'I', b->mask);
  1117. b->timer = now;
  1118. }
  1119. if (chan->idle_kick)
  1120. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  1121. if (now - m->last >= chan->idle_kick * 60 &&
  1122. !match_my_nick(m->nick) && !chan_issplit(m)) {
  1123. sprintf(s, "%s!%s", m->nick, m->userhost);
  1124. get_user_flagrec(m->user ? m->user : get_user_by_host(s),
  1125. &fr, chan->dname);
  1126. if (!(glob_bot(fr) || (glob_op(fr) && !glob_deop(fr)) || chan_op(fr))) {
  1127. dprintf(DP_SERVER, "KICK %s %s :%sidle %d min\n", chan->name,
  1128. m->nick, kickprefix, chan->idle_kick);
  1129. m->flags |= SENTKICK;
  1130. }
  1131. }
  1132. }
  1133. for (m = chan->channel.member; m && m->nick[0]; m = n) {
  1134. n = m->next;
  1135. if (m->split && now - m->split > wait_split) {
  1136. sprintf(s, "%s!%s", m->nick, m->userhost);
  1137. putlog(LOG_JOIN, chan->dname,
  1138. "%s (%s) got lost in the net-split.",
  1139. m->nick, m->userhost);
  1140. killmember(chan, m->nick);
  1141. }
  1142. m = n;
  1143. }
  1144. //autovoice of +v users if bot is +y
  1145. if (!loading && channel_active(chan) && me_op(chan) && dovoice(chan)) {
  1146. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1147. sprintf(s, "%s!%s", m->nick, m->userhost);
  1148. if (!m->user)
  1149. m->user = get_user_by_host(s);
  1150. if (m->user) {
  1151. struct flag_record fr2 = { FR_GLOBAL | FR_CHAN, 0, 0 };
  1152. get_user_flagrec(m->user, &fr2, chan->dname);
  1153. if (!private(fr2, chan, PRIV_VOICE) &&
  1154. ((channel_voice(chan) && !chk_devoice(fr2, chan)) ||
  1155. (!channel_voice(chan) && chk_voice(fr2, chan))) &&
  1156. !glob_bot(fr2) &&
  1157. !chan_hasop(m) && !chan_hasvoice(m) && !(m->flags & EVOICE)) {
  1158. putlog(LOG_DEBUG, "@", "VOICING %s in %s as '%s'", m->nick, chan->dname, m->user->handle);
  1159. add_mode(chan, '+', 'v', m->nick);
  1160. } else if (!glob_bot(fr2) &&
  1161. (chk_devoice(fr2, chan) || (m->flags & EVOICE))) {
  1162. if (!chan_hasop(m) && chan_hasvoice(m))
  1163. add_mode(chan, '-', 'v', m->nick);
  1164. }
  1165. } else if (m->user == NULL && !(m->flags & EVOICE)) {
  1166. if (channel_voice(chan) && !chan_hasop(m) && !chan_hasvoice(m)) {
  1167. add_mode(chan, '+', 'v', m->nick);
  1168. }
  1169. }
  1170. }
  1171. }
  1172. check_lonely_channel(chan);
  1173. }
  1174. else if (shouldjoin(chan) && !channel_pending(chan))
  1175. dprintf(DP_MODE, "JOIN %s %s\n",
  1176. (chan->name[0]) ? chan->name : chan->dname,
  1177. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  1178. }
  1179. }
  1180. static int channels_6char STDVAR
  1181. {
  1182. Function F = (Function) cd;
  1183. char x[20];
  1184. BADARGS(7, 7, " nick user@host handle desto/chan keyword/nick text");
  1185. CHECKVALIDITY(channels_6char);
  1186. sprintf(x, "%d", F(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]));
  1187. Tcl_AppendResult(irp, x, NULL);
  1188. return TCL_OK;
  1189. }
  1190. static int channels_5char STDVAR
  1191. {
  1192. Function F = (Function) cd;
  1193. BADARGS(6, 6, " nick user@host handle channel text");
  1194. CHECKVALIDITY(channels_5char);
  1195. F(argv[1], argv[2], argv[3], argv[4], argv[5]);
  1196. return TCL_OK;
  1197. }
  1198. static int channels_4char STDVAR
  1199. {
  1200. Function F = (Function) cd;
  1201. BADARGS(5, 5, " nick uhost hand chan/param");
  1202. CHECKVALIDITY(channels_4char);
  1203. F(argv[1], argv[2], argv[3], argv[4]);
  1204. return TCL_OK;
  1205. }
  1206. static int channels_2char STDVAR
  1207. {
  1208. Function F = (Function) cd;
  1209. BADARGS(3, 3, " channel type");
  1210. CHECKVALIDITY(channels_2char);
  1211. F(argv[1], argv[2]);
  1212. return TCL_OK;
  1213. }
  1214. #ifdef S_AUTH
  1215. static int check_tcl_pubc(char *cmd, char *nick, char *uhost,
  1216. struct userrec *u, char *args, char *chan)
  1217. {
  1218. struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
  1219. char *hand = u ? u->handle : "*";
  1220. int x;
  1221. get_user_flagrec(u, &fr, chan);
  1222. Tcl_SetVar(interp, "_msgc1", nick, 0);
  1223. Tcl_SetVar(interp, "_msgc2", uhost, 0);
  1224. Tcl_SetVar(interp, "_msgc3", hand, 0);
  1225. Tcl_SetVar(interp, "_msgc4", args, 0);
  1226. Tcl_SetVar(interp, "_msgc5", chan, 0);
  1227. x = check_tcl_bind(H_msgc, cmd, &fr, " $_msgc1 $_msgc2 $_msgc3 $_msgc4 $_msgc5",
  1228. MATCH_EXACT | BIND_HAS_BUILTINS | BIND_USE_ATTR);
  1229. if (x == BIND_EXEC_LOG)
  1230. putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %s%s %s", nick, uhost, hand, chan, cmdprefix,
  1231. cmd, args);
  1232. return ((x == BIND_MATCHED) || (x == BIND_EXECUTED) || (x == BIND_EXEC_LOG));
  1233. }
  1234. #endif /* S_AUTH */
  1235. static tcl_ints myints[] =
  1236. {
  1237. {"learn-users", &learn_users, 0}, /* arthur2 */
  1238. {"wait-split", &wait_split, 0},
  1239. {"wait-info", &wait_info, 0},
  1240. {"bounce-bans", &bounce_bans, 0},
  1241. {"bounce-exempts", &bounce_exempts, 0},
  1242. {"bounce-invites", &bounce_invites, 0},
  1243. {"bounce-modes", &bounce_modes, 0},
  1244. {"modes-per-line", &modesperline, 0},
  1245. {"mode-buf-length", &mode_buf_len, 0},
  1246. {"use-354", &use_354, 0},
  1247. {"kick-method", &kick_method, 0},
  1248. {"kick-fun", &kick_fun, 0},
  1249. {"ban-fun", &ban_fun, 0},
  1250. {"invite-key", &invite_key, 0},
  1251. {"no-chanrec-info", &no_chanrec_info, 0},
  1252. {"max-bans", &max_bans, 0},
  1253. {"max-exempts", &max_exempts, 0},
  1254. {"max-invites", &max_invites, 0},
  1255. {"max-modes", &max_modes, 0},
  1256. {"net-type", &net_type, 0},
  1257. {"strict-host", &strict_host, 0}, /* arthur2 */
  1258. {"ctcp-mode", &ctcp_mode, 0}, /* arthur2 */
  1259. {"keep-nick", &keepnick, 0}, /* guppy */
  1260. {"prevent-mixing", &prevent_mixing, 0},
  1261. {"rfc-compliant", &rfc_compliant, 0},
  1262. {"include-lk", &include_lk, 0},
  1263. {NULL, NULL, 0} /* arthur2 */
  1264. };
  1265. /* Flush the modes for EVERY channel.
  1266. */
  1267. static void flush_modes()
  1268. {
  1269. struct chanset_t *chan;
  1270. memberlist *m;
  1271. if (modesperline > MODES_PER_LINE_MAX)
  1272. modesperline = MODES_PER_LINE_MAX;
  1273. for (chan = chanset; chan; chan = chan->next) {
  1274. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1275. if (m->delay && m->delay <= now) {
  1276. m->delay = 0L;
  1277. m->flags &= ~FULL_DELAY;
  1278. if (chan_sentop(m)) {
  1279. m->flags &= ~SENTOP;
  1280. do_op(m->nick, chan, 0);
  1281. }
  1282. if (chan_sentvoice(m)) {
  1283. m->flags &= ~SENTVOICE;
  1284. add_mode(chan, '+', 'v', m->nick);
  1285. }
  1286. }
  1287. }
  1288. flush_mode(chan, NORMAL);
  1289. }
  1290. }
  1291. static void irc_report(int idx, int details)
  1292. {
  1293. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  1294. char ch[1024], q[160], *p;
  1295. int k, l;
  1296. struct chanset_t *chan;
  1297. strcpy(q, "Channels: ");
  1298. k = 10;
  1299. for (chan = chanset; chan; chan = chan->next) {
  1300. if (idx != DP_STDOUT)
  1301. get_user_flagrec(dcc[idx].user, &fr, chan->dname);
  1302. if (!private(fr, chan, PRIV_OP) &&
  1303. (idx == DP_STDOUT || glob_master(fr) || chan_master(fr))) {
  1304. p = NULL;
  1305. if (shouldjoin(chan)) {
  1306. if (chan->status & CHAN_JUPED)
  1307. p = MISC_JUPED;
  1308. else if (!(chan->status & CHAN_ACTIVE))
  1309. p = MISC_TRYING;
  1310. else if (chan->status & CHAN_PEND)
  1311. p = MISC_PENDING;
  1312. else if ((chan->dname[0] != '+') && !me_op(chan))
  1313. p = MISC_WANTOPS;
  1314. }
  1315. l = simple_sprintf(ch, "%s%s%s%s, ", chan->dname, p ? "(" : "",
  1316. p ? p : "", p ? ")" : "");
  1317. if ((k + l) > 70) {
  1318. dprintf(idx, " %s\n", q);
  1319. strcpy(q, " ");
  1320. k = 10;
  1321. }
  1322. k += my_strcpy(q + k, ch);
  1323. }
  1324. }
  1325. if (k > 10) {
  1326. q[k - 2] = 0;
  1327. dprintf(idx, " %s\n", q);
  1328. }
  1329. }
  1330. static void do_nettype()
  1331. {
  1332. switch (net_type) {
  1333. case 0: /* Efnet */
  1334. kick_method = 1;
  1335. modesperline = 4;
  1336. use_354 = 0;
  1337. use_exempts = 1;
  1338. use_invites = 1;
  1339. max_bans = 100;
  1340. max_modes = 100;
  1341. rfc_compliant = 1;
  1342. include_lk = 0;
  1343. break;
  1344. case 1: /* Ircnet */
  1345. kick_method = 4;
  1346. modesperline = 3;
  1347. use_354 = 0;
  1348. use_exempts = 1;
  1349. use_invites = 1;
  1350. max_bans = 30;
  1351. max_modes = 30;
  1352. rfc_compliant = 1;
  1353. include_lk = 1;
  1354. break;
  1355. case 2: /* Undernet */
  1356. kick_method = 1;
  1357. modesperline = 6;
  1358. use_354 = 1;
  1359. use_exempts = 0;
  1360. use_invites = 0;
  1361. max_bans = 30;
  1362. max_modes = 30;
  1363. rfc_compliant = 1;
  1364. include_lk = 1;
  1365. break;
  1366. case 3: /* Dalnet */
  1367. kick_method = 1;
  1368. modesperline = 6;
  1369. use_354 = 0;
  1370. use_exempts = 0;
  1371. use_invites = 0;
  1372. max_bans = 100;
  1373. max_modes = 100;
  1374. rfc_compliant = 0;
  1375. include_lk = 1;
  1376. break;
  1377. case 4: /* hybrid-6+ */
  1378. kick_method = 1;
  1379. modesperline = 4;
  1380. use_354 = 0;
  1381. use_exempts = 1;
  1382. use_invites = 0;
  1383. max_bans = 20;
  1384. max_modes = 20;
  1385. rfc_compliant = 1;
  1386. include_lk = 0;
  1387. break;
  1388. default:
  1389. break;
  1390. }
  1391. /* Update all rfc_ function pointers */
  1392. add_hook(HOOK_RFC_CASECMP, (Function) rfc_compliant);
  1393. }
  1394. #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
  1395. static char *traced_nettype(ClientData cdata, Tcl_Interp *irp,
  1396. CONST char *name1, CONST char *name2, int flags)
  1397. #else
  1398. static char *traced_nettype(ClientData cdata, Tcl_Interp *irp, char *name1,
  1399. char *name2, int flags)
  1400. #endif
  1401. {
  1402. do_nettype();
  1403. return NULL;
  1404. }
  1405. #if (((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION >= 4)) || (TCL_MAJOR_VERSION > 8))
  1406. static char *traced_rfccompliant(ClientData cdata, Tcl_Interp *irp,
  1407. CONST char *name1, CONST char *name2,
  1408. int flags)
  1409. #else
  1410. static char *traced_rfccompliant(ClientData cdata, Tcl_Interp *irp,
  1411. char *name1, char *name2, int flags)
  1412. #endif
  1413. {
  1414. /* This hook forces eggdrop core to change the rfc_ match function
  1415. * links to point to the rfc compliant versions if rfc_compliant
  1416. * is 1, or to the normal version if it's 0.
  1417. */
  1418. add_hook(HOOK_RFC_CASECMP, (Function) rfc_compliant);
  1419. return NULL;
  1420. }
  1421. static int irc_expmem()
  1422. {
  1423. return 0;
  1424. }
  1425. static cmd_t irc_bot[] = {
  1426. {"dp", "", (Function) mdop_request, NULL},
  1427. {"gi", "", (Function) getin_request, NULL},
  1428. {0, 0, 0, 0}
  1429. };
  1430. static void getin_3secondly()
  1431. {
  1432. if (!server_online)
  1433. return;
  1434. else {
  1435. struct chanset_t *ch;
  1436. for (ch = chanset; ch; ch = ch->next) {
  1437. if ((channel_pending(ch) || channel_active(ch)) && (!me_op(ch)))
  1438. request_op(ch);
  1439. }
  1440. }
  1441. }
  1442. static void irc_10secondly() {
  1443. struct chanset_t *ch = chanset;
  1444. for (ch=chanset;ch;ch=ch->next)
  1445. if (channel_closed(ch))
  1446. enforce_closed(ch);
  1447. }
  1448. EXPORT_SCOPE char *irc_start();
  1449. static Function irc_table[] =
  1450. {
  1451. /* 0 - 3 */
  1452. (Function) irc_start,
  1453. (Function) NULL,
  1454. (Function) irc_expmem,
  1455. (Function) irc_report,
  1456. /* 4 - 7 */
  1457. (Function) 0,
  1458. (Function) 0,
  1459. (Function) 0,
  1460. (Function) 0,
  1461. /* 8 - 11 */
  1462. (Function) 0,
  1463. (Function) 0,
  1464. (Function) 0,
  1465. (Function) 0,
  1466. /* 12 - 15 */
  1467. (Function) 0,
  1468. (Function) 0,
  1469. (Function) 0,
  1470. (Function) recheck_channel,
  1471. /* 16 - 19 */
  1472. (Function) me_op,
  1473. (Function) recheck_channel_modes,
  1474. (Function) 0,
  1475. (Function) do_channel_part,
  1476. /* 20 - 23 */
  1477. (Function) check_this_ban,
  1478. (Function) check_this_user,
  1479. (Function) me_voice,
  1480. (Function) raise_limit,
  1481. };
  1482. void irc_describe(struct cfg_entry *cfgent, int idx)
  1483. {
  1484. }
  1485. void irc_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
  1486. {
  1487. int i;
  1488. if (!cfgent->gdata)
  1489. return;
  1490. *valid = 0;
  1491. if (!strcmp(cfgent->name, STR("op-requests"))) {
  1492. int L,
  1493. R;
  1494. char *value = cfgent->gdata;
  1495. L = atoi(value);
  1496. value = strchr(value, ':');
  1497. if (!value)
  1498. return;
  1499. value++;
  1500. R = atoi(value);
  1501. if ((R >= 60) || (R <= 3) || (L < 1) || (L > R))
  1502. return;
  1503. *valid = 1;
  1504. return;
  1505. }
  1506. i = atoi(cfgent->gdata);
  1507. if (!strcmp(cfgent->name, STR("op-bots"))) {
  1508. if ((i < 1) || (i > 10))
  1509. return;
  1510. } else if (!strcmp(cfgent->name, STR("invite-bots"))) {
  1511. if ((i < 1) || (i > 10))
  1512. return;
  1513. } else if (!strcmp(cfgent->name, STR("key-bots"))) {
  1514. if ((i < 1) || (i > 10))
  1515. return;
  1516. } else if (!strcmp(cfgent->name, STR("limit-bots"))) {
  1517. if ((i < 1) || (i > 10))
  1518. return;
  1519. } else if (!strcmp(cfgent->name, STR("unban-bots"))) {
  1520. if ((i < 1) || (i > 10))
  1521. return;
  1522. } else if (!strcmp(cfgent->name, STR("lag-threshold"))) {
  1523. if ((i < 3) || (i > 60))
  1524. return;
  1525. } else if (!strcmp(cfgent->name, STR("fight-threshold"))) {
  1526. if (i && ((i < 50) || (i > 1000)))
  1527. return;
  1528. } else if (!strcmp(cfgent->name, STR("op-time-slack"))) {
  1529. if ((i < 30) || (i > 1200))
  1530. return;
  1531. }
  1532. *valid = 1;
  1533. return;
  1534. }
  1535. struct cfg_entry CFG_OPBOTS = {
  1536. "op-bots", CFGF_GLOBAL, NULL, NULL,
  1537. irc_changed, NULL, irc_describe
  1538. };
  1539. struct cfg_entry CFG_INBOTS = {
  1540. "in-bots", CFGF_GLOBAL, NULL, NULL,
  1541. irc_changed, NULL, irc_describe
  1542. };
  1543. struct cfg_entry CFG_LAGTHRESHOLD = {
  1544. "lag-threshold", CFGF_GLOBAL, NULL, NULL,
  1545. irc_changed, NULL, irc_describe
  1546. };
  1547. struct cfg_entry CFG_OPREQUESTS = {
  1548. "op-requests", CFGF_GLOBAL, NULL, NULL,
  1549. irc_changed, NULL, irc_describe
  1550. };
  1551. struct cfg_entry CFG_OPTIMESLACK = {
  1552. "op-time-slack", CFGF_GLOBAL, NULL, NULL,
  1553. irc_changed, NULL, irc_describe
  1554. };
  1555. #ifdef S_AUTOLOCK
  1556. struct cfg_entry CFG_FIGHTTHRESHOLD = {
  1557. "fight-threshold", CFGF_GLOBAL, NULL, NULL,
  1558. irc_changed, NULL, irc_describe
  1559. };
  1560. #endif /* S_AUTOLOCK */
  1561. char *irc_start(Function * global_funcs)
  1562. {
  1563. struct chanset_t *chan;
  1564. global = global_funcs;
  1565. module_register(MODULE_NAME, irc_table, 1, 3);
  1566. if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0))) {
  1567. module_undepend(MODULE_NAME);
  1568. return "This module requires server module 1.0 or later.";
  1569. }
  1570. if (!(channels_funcs = module_depend(MODULE_NAME, "channels", 1, 0))) {
  1571. module_undepend(MODULE_NAME);
  1572. return "This module requires channels module 1.0 or later.";
  1573. }
  1574. add_cfg(&CFG_OPBOTS);
  1575. add_cfg(&CFG_INBOTS);
  1576. add_cfg(&CFG_LAGTHRESHOLD);
  1577. add_cfg(&CFG_OPREQUESTS);
  1578. add_cfg(&CFG_OPTIMESLACK);
  1579. #ifdef S_AUTOLOCK
  1580. add_cfg(&CFG_FIGHTTHRESHOLD);
  1581. #endif /* S_AUTOLOCK */
  1582. for (chan = chanset; chan; chan = chan->next) {
  1583. if (shouldjoin(chan))
  1584. dprintf(DP_MODE, "JOIN %s %s\n",
  1585. (chan->name[0]) ? chan->name : chan->dname, chan->key_prot);
  1586. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND | CHAN_ASKEDBANS);
  1587. chan->ircnet_status &= ~(CHAN_ASKED_INVITED | CHAN_ASKED_EXEMPTS);
  1588. }
  1589. add_hook(HOOK_MINUTELY, (Function) check_expired_chanstuff);
  1590. add_hook(HOOK_MINUTELY, (Function) warn_pls_take);
  1591. add_hook(HOOK_MINUTELY, (Function) check_servers);
  1592. add_hook(HOOK_ADD_MODE, (Function) real_add_mode);
  1593. add_hook(HOOK_IDLE, (Function) flush_modes);
  1594. add_hook(HOOK_3SECONDLY, (Function) getin_3secondly);
  1595. add_hook(HOOK_10SECONDLY, (Function) irc_10secondly);
  1596. #ifdef S_AUTOLOCK
  1597. add_hook(HOOK_MINUTELY, (Function) check_netfight);
  1598. #endif /* S_AUTOLOCK */
  1599. Tcl_TraceVar(interp, "net-type",
  1600. TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
  1601. traced_nettype, NULL);
  1602. Tcl_TraceVar(interp, "rfc-compliant",
  1603. TCL_TRACE_READS | TCL_TRACE_WRITES | TCL_TRACE_UNSETS,
  1604. traced_rfccompliant, NULL);
  1605. add_tcl_ints(myints);
  1606. add_builtins(H_bot, irc_bot);
  1607. add_builtins(H_dcc, irc_dcc);
  1608. add_builtins(H_msg, C_msg);
  1609. #ifdef S_AUTH
  1610. add_builtins(H_msgc, C_msgc);
  1611. #endif /* S_AUTH */
  1612. add_builtins(H_raw, irc_raw);
  1613. add_tcl_commands(tclchan_cmds);
  1614. do_nettype();
  1615. return NULL;
  1616. }
  1617. #endif