irc.c 56 KB

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