irc.c 57 KB

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