chan.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873
  1. #ifdef LEAF
  2. /*
  3. *
  4. * chan.c -- part of irc.mod
  5. * almost everything to do with channel manipulation
  6. * telling channel status
  7. * 'who' response
  8. * user kickban, kick, op, deop
  9. * idle kicking
  10. *
  11. */
  12. static time_t last_ctcp = (time_t) 0L;
  13. static int count_ctcp = 0;
  14. static time_t last_invtime = (time_t) 0L;
  15. static char last_invchan[300] = "";
  16. /* ID length for !channels.
  17. */
  18. #define CHANNEL_ID_LEN 5
  19. /* Returns a pointer to a new channel member structure.
  20. */
  21. static memberlist *newmember(struct chanset_t *chan, char * nick)
  22. {
  23. memberlist *x = NULL, *lx = NULL, *n = NULL;
  24. x = chan->channel.member;
  25. lx = NULL;
  26. while (x && x->nick[0] && (rfc_casecmp(x->nick, nick)<0)) {
  27. lx = x;
  28. x = x->next;
  29. }
  30. n = (memberlist *) calloc(1, sizeof(memberlist));
  31. n->next = NULL;
  32. strncpyz(n->nick, nick, sizeof(n->nick));
  33. n->split = 0L;
  34. n->last = 0L;
  35. n->delay = 0L;
  36. n->hops = -1;
  37. if (!lx) {
  38. n->next = chan->channel.member;
  39. chan->channel.member=n;
  40. } else {
  41. n->next = lx->next;
  42. lx->next = n;
  43. }
  44. chan->channel.members++;
  45. return n;
  46. }
  47. /* Always pass the channel dname (display name) to this function <cybah>
  48. */
  49. static void update_idle(char *chname, char *nick)
  50. {
  51. memberlist *m = NULL;
  52. struct chanset_t *chan = NULL;
  53. chan = findchan_by_dname(chname);
  54. if (chan) {
  55. m = ismember(chan, nick);
  56. if (m)
  57. m->last = now;
  58. }
  59. }
  60. /* Returns the current channel mode.
  61. */
  62. static char *getchanmode(struct chanset_t *chan)
  63. {
  64. static char s[121] = "";
  65. int atr, i;
  66. s[0] = '+';
  67. i = 1;
  68. atr = chan->channel.mode;
  69. if (atr & CHANINV)
  70. s[i++] = 'i';
  71. if (atr & CHANPRIV)
  72. s[i++] = 'p';
  73. if (atr & CHANSEC)
  74. s[i++] = 's';
  75. if (atr & CHANMODER)
  76. s[i++] = 'm';
  77. if (atr & CHANNOCLR)
  78. s[i++] = 'c';
  79. if (atr & CHANNOCTCP)
  80. s[i++] = 'C';
  81. if (atr & CHANREGON)
  82. s[i++] = 'R';
  83. if (atr & CHANTOPIC)
  84. s[i++] = 't';
  85. if (atr & CHANMODR)
  86. s[i++] = 'M';
  87. if (atr & CHANLONLY)
  88. s[i++] = 'r';
  89. if (atr & CHANNOMSG)
  90. s[i++] = 'n';
  91. if (atr & CHANANON)
  92. s[i++] = 'a';
  93. if (atr & CHANKEY)
  94. s[i++] = 'k';
  95. if (chan->channel.maxmembers != 0)
  96. s[i++] = 'l';
  97. s[i] = 0;
  98. if (chan->channel.key[0])
  99. i += sprintf(s + i, " %s", chan->channel.key);
  100. if (chan->channel.maxmembers != 0)
  101. sprintf(s + i, " %d", chan->channel.maxmembers);
  102. return s;
  103. }
  104. static void check_exemptlist(struct chanset_t *chan, char *from)
  105. {
  106. masklist *e = NULL;
  107. int ok = 0;
  108. if (!use_exempts)
  109. return;
  110. for (e = chan->channel.exempt; e->mask[0]; e = e->next)
  111. if (wild_match(e->mask, from)) {
  112. add_mode(chan, '-', 'e', e->mask);
  113. ok = 1;
  114. }
  115. if (prevent_mixing && ok)
  116. flush_mode(chan, QUICK);
  117. }
  118. void priority_do(struct chanset_t * chan, int opsonly, int action)
  119. {
  120. memberlist *m = NULL;
  121. int ops = 0, targets = 0, bpos = 0, tpos = 0, ft = 0, ct = 0, actions = 0, sent = 0;
  122. if (!me_op(chan))
  123. return;
  124. if (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan))
  125. return;
  126. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  127. if (!m->user) {
  128. char s[256] = "";
  129. sprintf(s, "%s!%s", m->nick, m->userhost);
  130. m->user = get_user_by_host(s);
  131. }
  132. if (m->user && ((m->user->flags & (USER_BOT | USER_OP)) == (USER_BOT | USER_OP))) {
  133. ops++;
  134. if (!strcmp(m->nick, botname))
  135. bpos = (ops - 1);
  136. } else if (!opsonly || chan_hasop(m)) {
  137. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0};
  138. if (m->user)
  139. get_user_flagrec(m->user, &fr, chan->dname);
  140. if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) || //+d ?
  141. ((!channel_private(chan) && !chan_op(fr) && !glob_op(fr)) || //simply no +o flag.
  142. (channel_private(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) { //private?
  143. targets++;
  144. }
  145. }
  146. }
  147. if (!targets || !ops)
  148. return;
  149. ft = (bpos * targets) / ops;
  150. ct = ((bpos + 2) * targets + (ops - 1)) / ops;
  151. ct = (ct - ft + 1);
  152. if (ct > 20)
  153. ct = 20;
  154. while (ft >= targets)
  155. ft -= targets;
  156. actions = 0;
  157. sent = 0;
  158. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  159. if (!opsonly || chan_hasop(m)) {
  160. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0};
  161. if (m->user)
  162. get_user_flagrec(m->user, &fr, chan->dname);
  163. if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
  164. ((!channel_private(chan) && !chan_op(fr) && !glob_op(fr)) ||
  165. (channel_private(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
  166. if (tpos >= ft) {
  167. if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
  168. actions++;
  169. sent++;
  170. add_mode(chan, '-', 'o', m->nick);
  171. if (actions >= ct) {
  172. flush_mode(chan, QUICK);
  173. return;
  174. }
  175. } else if ((action == PRIO_KICK) && !chan_sentkick(m)) {
  176. actions++;
  177. sent++;
  178. if (chan->closed_ban)
  179. doban(chan, m);
  180. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, kickreason(KICK_CLOSED));
  181. m->flags |= SENTKICK;
  182. if (actions >= ct)
  183. return;
  184. }
  185. }
  186. tpos++;
  187. }
  188. }
  189. }
  190. ct = ct - actions;
  191. if (ct > ft)
  192. ct = ft;
  193. ft = 0;
  194. actions = 0;
  195. tpos = 0;
  196. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  197. if (!opsonly || chan_hasop(m)) {
  198. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0};
  199. if (m->user)
  200. get_user_flagrec(m->user, &fr, chan->dname);
  201. if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
  202. ((!channel_private(chan) && !chan_op(fr) && !glob_op(fr)) ||
  203. (channel_private(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
  204. if (tpos >= ft) {
  205. if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
  206. actions++;
  207. sent++;
  208. add_mode(chan, '-', 'o', m->nick);
  209. if ((actions >= ct) || (sent > 20)) {
  210. flush_mode(chan, QUICK);
  211. return;
  212. }
  213. } else if ((action == PRIO_KICK) && !chan_sentkick(m)) {
  214. actions++;
  215. if (chan->closed_ban)
  216. doban(chan, m);
  217. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, kickreason(KICK_CLOSED));
  218. m->flags |= SENTKICK;
  219. if ((actions >= ct) || (sent > 5))
  220. return;
  221. }
  222. }
  223. tpos++;
  224. }
  225. }
  226. }
  227. }
  228. /* lame code
  229. static int target_priority(struct chanset_t * chan, memberlist *target, int opsonly)
  230. {
  231. memberlist *m;
  232. int ops = 0, targets = 0, bpos = 0, ft = 0, ct = 0, tp = (-1), pos = 0;
  233. return 1;
  234. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  235. if (m->user && ((m->user->flags & (USER_BOT | USER_OP)) == (USER_BOT | USER_OP))) {
  236. ops++;
  237. if (match_my_nick(m->nick))
  238. bpos = ops;
  239. } else if (!opsonly || chan_hasop(m)) {
  240. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0};
  241. if (m->user)
  242. get_user_flagrec(m->user, &fr, chan->dname);
  243. if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
  244. ((!channel_private(chan) && !chan_op(fr) && !glob_op(fr)) ||
  245. (channel_private(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
  246. targets++;
  247. }
  248. }
  249. if (m == target)
  250. tp = pos;
  251. pos++;
  252. }
  253. if (!targets || !ops || (tp < 0)) {
  254. return 0;
  255. }
  256. ft = (bpos * targets) / ops;
  257. ct = ((bpos + 2) * targets + (ops - 1)) / ops;
  258. ct = (ct - ft + 1);
  259. if (ct > 20)
  260. ct = 20;
  261. while (ft >= targets) {
  262. ft -= targets;
  263. }
  264. if (ct >= targets) {
  265. putlog(LOG_MISC, "*", "%s 1 ct >= targets; ct %d targets %d", target, ct, targets);
  266. if ((tp >= ft) || (tp <= (ct % targets))) {
  267. putlog(LOG_MISC, "*", "%s (1) first if, tp %d ft %d ct/targets %d", target, tp, ft, (ct % targets));
  268. return 1;
  269. }
  270. } else {
  271. putlog(LOG_MISC, "*", "%s 2 else, ct %d targets %d", target, ct, targets);
  272. if ((tp >= ft) && (tp <= ct)) {
  273. putlog(LOG_MISC, "*", "%s (1) second if, tp %d ft %d", target, tp, ft);
  274. return 1;
  275. }
  276. }
  277. putlog(LOG_MISC, "*", "%s (0) returning 0", target);
  278. return 0;
  279. }
  280. */
  281. /* Check a channel and clean-out any more-specific matching masks.
  282. *
  283. * Moved all do_ban(), do_exempt() and do_invite() into this single function
  284. * as the code bloat is starting to get rediculous <cybah>
  285. */
  286. static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char Mode)
  287. {
  288. for (; m && m->mask[0]; m = m->next)
  289. if (wild_match(mask, m->mask) && rfc_casecmp(mask, m->mask))
  290. add_mode(chan, '-', Mode, m->mask);
  291. add_mode(chan, '+', Mode, mask);
  292. flush_mode(chan, QUICK);
  293. }
  294. /* This is a clone of detect_flood, but works for channel specificity now
  295. * and handles kick & deop as well.
  296. */
  297. static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
  298. struct chanset_t *chan, int which, char *victim)
  299. {
  300. char h[UHOSTLEN] = "", ftype[12] = "", *p = NULL;
  301. struct userrec *u = NULL;
  302. memberlist *m = NULL;
  303. int thr = 0, lapse = 0;
  304. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  305. if (!chan || (which < 0) || (which >= FLOOD_CHAN_MAX))
  306. return 0;
  307. m = ismember(chan, floodnick);
  308. /* Do not punish non-existant channel members and IRC services like
  309. * ChanServ
  310. */
  311. if (!m && (which != FLOOD_JOIN))
  312. return 0;
  313. get_user_flagrec(get_user_by_host(from), &fr, chan->dname);
  314. if (glob_bot(fr) ||
  315. ((which == FLOOD_DEOP) &&
  316. (glob_master(fr) || chan_master(fr))) ||
  317. ((which == FLOOD_KICK) &&
  318. (glob_master(fr) || chan_master(fr))) ||
  319. ((which != FLOOD_DEOP) && (which != FLOOD_KICK) &&
  320. (glob_noflood(fr) || chan_noflood(fr))))
  321. return 0;
  322. /* Determine how many are necessary to make a flood. */
  323. switch (which) {
  324. case FLOOD_PRIVMSG:
  325. case FLOOD_NOTICE:
  326. thr = chan->flood_pub_thr;
  327. lapse = chan->flood_pub_time;
  328. strcpy(ftype, "pub");
  329. break;
  330. case FLOOD_CTCP:
  331. thr = chan->flood_ctcp_thr;
  332. lapse = chan->flood_ctcp_time;
  333. strcpy(ftype, "pub");
  334. break;
  335. case FLOOD_NICK:
  336. thr = chan->flood_nick_thr;
  337. lapse = chan->flood_nick_time;
  338. strcpy(ftype, "nick");
  339. break;
  340. case FLOOD_JOIN:
  341. thr = chan->flood_join_thr;
  342. lapse = chan->flood_join_time;
  343. strcpy(ftype, "join");
  344. break;
  345. case FLOOD_DEOP:
  346. thr = chan->flood_deop_thr;
  347. lapse = chan->flood_deop_time;
  348. strcpy(ftype, "deop");
  349. break;
  350. case FLOOD_KICK:
  351. thr = chan->flood_kick_thr;
  352. lapse = chan->flood_kick_time;
  353. strcpy(ftype, "kick");
  354. break;
  355. }
  356. if ((thr == 0) || (lapse == 0))
  357. return 0; /* no flood protection */
  358. /* Okay, make sure i'm not flood-checking myself */
  359. if (match_my_nick(floodnick))
  360. return 0;
  361. if (!egg_strcasecmp(floodhost, botuserhost))
  362. return 0;
  363. /* My user@host (?) */
  364. if ((which == FLOOD_KICK) || (which == FLOOD_DEOP))
  365. p = floodnick;
  366. else {
  367. p = strchr(floodhost, '@');
  368. if (p) {
  369. p++;
  370. }
  371. if (!p)
  372. return 0;
  373. }
  374. if (rfc_casecmp(chan->floodwho[which], p)) { /* new */
  375. strncpy(chan->floodwho[which], p, 81);
  376. chan->floodwho[which][81] = 0;
  377. chan->floodtime[which] = now;
  378. chan->floodnum[which] = 1;
  379. return 0;
  380. }
  381. if (chan->floodtime[which] < now - lapse) {
  382. /* Flood timer expired, reset it */
  383. chan->floodtime[which] = now;
  384. chan->floodnum[which] = 1;
  385. return 0;
  386. }
  387. /* Deop'n the same person, sillyness ;) - so just ignore it */
  388. if (which == FLOOD_DEOP) {
  389. if (!rfc_casecmp(chan->deopd, victim))
  390. return 0;
  391. else
  392. strcpy(chan->deopd, victim);
  393. }
  394. chan->floodnum[which]++;
  395. if (chan->floodnum[which] >= thr) { /* FLOOD */
  396. /* Reset counters */
  397. chan->floodnum[which] = 0;
  398. chan->floodtime[which] = 0;
  399. chan->floodwho[which][0] = 0;
  400. if (which == FLOOD_DEOP)
  401. chan->deopd[0] = 0;
  402. u = get_user_by_host(from);
  403. switch (which) {
  404. case FLOOD_PRIVMSG:
  405. case FLOOD_NOTICE:
  406. case FLOOD_CTCP:
  407. /* Flooding chan! either by public or notice */
  408. if (!chan_sentkick(m) && me_op(chan)) {
  409. putlog(LOG_MODES, chan->dname, IRC_FLOODKICK, floodnick);
  410. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, floodnick, kickprefix, kickreason(KICK_FLOOD));
  411. m->flags |= SENTKICK;
  412. }
  413. return 1;
  414. case FLOOD_JOIN:
  415. case FLOOD_NICK:
  416. if (use_exempts &&
  417. (u_match_mask(global_exempts, from) ||
  418. u_match_mask(chan->exempts, from)))
  419. return 1;
  420. simple_sprintf(h, "*!*@%s", p);
  421. if (!isbanned(chan, h) && me_op(chan)) {
  422. check_exemptlist(chan, from);
  423. do_mask(chan, chan->channel.ban, h, 'b');
  424. }
  425. if ((u_match_mask(global_bans, from))
  426. || (u_match_mask(chan->bans, from)))
  427. return 1; /* Already banned */
  428. if (which == FLOOD_JOIN)
  429. putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE3, p);
  430. else
  431. putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE4, p);
  432. strcpy(ftype + 4, " flood");
  433. u_addmask('b', chan, h, conf.bot->nick, ftype, now + (60 * chan->ban_time), 0);
  434. if (!channel_enforcebans(chan) && me_op(chan)) {
  435. char s[UHOSTLEN];
  436. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  437. sprintf(s, "%s!%s", m->nick, m->userhost);
  438. if (wild_match(h, s) &&
  439. (m->joined >= chan->floodtime[which]) &&
  440. !chan_sentkick(m) && !match_my_nick(m->nick) && me_op(chan)) {
  441. m->flags |= SENTKICK;
  442. if (which == FLOOD_JOIN)
  443. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick,
  444. kickprefix, IRC_JOIN_FLOOD);
  445. else
  446. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, kickreason(KICK_NICKFLOOD));
  447. }
  448. }
  449. }
  450. return 1;
  451. case FLOOD_KICK:
  452. if (me_op(chan) && !chan_sentkick(m)) {
  453. putlog(LOG_MODES, chan->dname, "Kicking %s, for mass kick.", floodnick);
  454. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, floodnick, kickprefix, kickreason(KICK_KICKFLOOD));
  455. m->flags |= SENTKICK;
  456. }
  457. return 1;
  458. case FLOOD_DEOP:
  459. if (me_op(chan) && !chan_sentkick(m)) {
  460. putlog(LOG_MODES, chan->dname,
  461. CHAN_MASSDEOP, chan->dname, from);
  462. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, floodnick, kickprefix, kickreason(KICK_MASSDEOP));
  463. m->flags |= SENTKICK;
  464. }
  465. if (u) {
  466. char s[256] = "";
  467. sprintf(s, "Mass deop on %s by %s", chan->dname, from);
  468. deflag_user(u, DEFLAG_MDOP, s, chan);
  469. }
  470. return 1;
  471. }
  472. }
  473. return 0;
  474. }
  475. /* Given a chan/m do all necesary exempt checks and ban. */
  476. static void refresh_ban_kick(struct chanset_t *, char *, char *);
  477. static void doban(struct chanset_t *chan, memberlist *m)
  478. {
  479. char s[UHOSTLEN] = "", *s1 = NULL;
  480. if (!chan || !m) return;
  481. sprintf(s, "%s!%s", m->nick, m->userhost);
  482. if (!(use_exempts &&
  483. (u_match_mask(global_exempts,s) ||
  484. u_match_mask(chan->exempts, s)))) {
  485. if (u_match_mask(global_bans, s) || u_match_mask(chan->bans, s))
  486. refresh_ban_kick(chan, s, m->nick);
  487. check_exemptlist(chan, s);
  488. s1 = quickban(chan, m->userhost);
  489. u_addmask('b', chan, s1, conf.bot->nick, "joined closed chan", now + (60 * chan->ban_time), 0);
  490. }
  491. return;
  492. }
  493. /* Given a [nick!]user@host, place a quick ban on them on a chan.
  494. */
  495. static char *quickban(struct chanset_t *chan, char *uhost)
  496. {
  497. static char s1[512] = "";
  498. maskhost(uhost, s1);
  499. if ((strlen(s1) != 1) && (strict_host == 0))
  500. s1[2] = '*'; /* arthur2 */
  501. do_mask(chan, chan->channel.ban, s1, 'b');
  502. return s1;
  503. }
  504. /* Kick any user (except friends/masters) with certain mask from channel
  505. * with a specified comment. Ernst 18/3/1998
  506. */
  507. static void kick_all(struct chanset_t *chan, char *hostmask, char *comment, int bantype)
  508. {
  509. memberlist *m = NULL;
  510. char kicknick[512] = "", s[UHOSTLEN] = "";
  511. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  512. int k, l, flushed;
  513. if (!me_op(chan))
  514. return;
  515. k = 0;
  516. flushed = 0;
  517. kicknick[0] = 0;
  518. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  519. sprintf(s, "%s!%s", m->nick, m->userhost);
  520. get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
  521. if (me_op(chan) &&
  522. wild_match(hostmask, s) && !chan_sentkick(m) &&
  523. !match_my_nick(m->nick) && !chan_issplit(m) &&
  524. !(use_exempts &&
  525. ((bantype && (isexempted(chan, s) || (chan->ircnet_status & CHAN_ASKED_EXEMPTS))) ||
  526. (u_match_mask(global_exempts, s) ||
  527. u_match_mask(chan->exempts, s))))) {
  528. if (!flushed) {
  529. /* We need to kick someone, flush eventual bans first */
  530. flush_mode(chan, QUICK);
  531. flushed += 1;
  532. }
  533. m->flags |= SENTKICK; /* Mark as pending kick */
  534. if (kicknick[0])
  535. strcat(kicknick, ",");
  536. strcat(kicknick, m->nick);
  537. k += 1;
  538. l = strlen(chan->name) + strlen(kicknick) + strlen(comment) + 5;
  539. if ((kick_method != 0 && k == kick_method) || (l > 480)) {
  540. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, kicknick, kickprefix, comment);
  541. k = 0;
  542. kicknick[0] = 0;
  543. }
  544. }
  545. }
  546. if (k > 0) {
  547. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, kicknick, kickprefix, comment);
  548. }
  549. }
  550. /* If any bans match this wildcard expression, refresh them on the channel.
  551. */
  552. static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
  553. {
  554. register maskrec *b = NULL;
  555. memberlist *m = NULL;
  556. int cycle;
  557. m = ismember(chan, nick);
  558. if (!m || chan_sentkick(m))
  559. return;
  560. /* Check global bans in first cycle and channel bans
  561. in second cycle. */
  562. for (cycle = 0; cycle < 2; cycle++) {
  563. for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
  564. if (wild_match(b->mask, user)) {
  565. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  566. char c[512] = ""; /* The ban comment. */
  567. char s[UHOSTLEN] = "";
  568. sprintf(s, "%s!%s", m->nick, m->userhost);
  569. get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr,
  570. chan->dname);
  571. if (role == 1)
  572. add_mode(chan, '-', 'o', nick); /* Guess it can't hurt. */
  573. check_exemptlist(chan, user);
  574. do_mask(chan, chan->channel.ban, b->mask, 'b');
  575. b->lastactive = now;
  576. if (b->desc && b->desc[0] != '@')
  577. egg_snprintf(c, sizeof c, "%s %s", IRC_PREBANNED, b->desc);
  578. else
  579. c[0] = 0;
  580. if (role == 2)
  581. kick_all(chan, b->mask, c[0] ? c : IRC_YOUREBANNED, 0);
  582. return; /* Drop out on 1st ban. */
  583. }
  584. }
  585. }
  586. }
  587. /* This is a bit cumbersome at the moment, but it works... Any improvements
  588. * then feel free to have a go.. Jason
  589. */
  590. static void refresh_exempt(struct chanset_t *chan, char *user)
  591. {
  592. maskrec *e = NULL;
  593. masklist *b = NULL;
  594. int cycle;
  595. /* Check global exempts in first cycle and channel exempts
  596. in second cycle. */
  597. for (cycle = 0; cycle < 2; cycle++) {
  598. for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
  599. if (wild_match(user, e->mask) || wild_match(e->mask,user)) {
  600. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  601. if (wild_match(b->mask, user) || wild_match(user, b->mask)) {
  602. if (e->lastactive < now - 60 && !isexempted(chan, e->mask)) {
  603. do_mask(chan, chan->channel.exempt, e->mask, 'e');
  604. e->lastactive = now;
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. static void refresh_invite(struct chanset_t *chan, char *user)
  613. {
  614. maskrec *i = NULL;
  615. int cycle;
  616. /* Check global invites in first cycle and channel invites
  617. in second cycle. */
  618. for (cycle = 0; cycle < 2; cycle++) {
  619. for (i = cycle ? chan->invites : global_invites; i; i = i->next) {
  620. if (wild_match(i->mask, user) &&
  621. ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
  622. if (i->lastactive < now - 60 && !isinvited(chan, i->mask)) {
  623. do_mask(chan, chan->channel.invite, i->mask, 'I');
  624. i->lastactive = now;
  625. return;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. /* Enforce all channel bans in a given channel. Ernst 18/3/1998
  632. */
  633. static void enforce_bans(struct chanset_t *chan)
  634. {
  635. char me[UHOSTLEN] = "";
  636. masklist *b = NULL;
  637. if (!me_op(chan))
  638. return; /* Can't do it :( */
  639. simple_sprintf(me, "%s!%s", botname, botuserhost);
  640. /* Go through all bans, kicking the users. */
  641. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  642. if (!wild_match(b->mask, me))
  643. if (!isexempted(chan, b->mask) && !(chan->ircnet_status & CHAN_ASKED_EXEMPTS))
  644. kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
  645. }
  646. }
  647. /* Make sure that all who are 'banned' on the userlist are actually in fact
  648. * banned on the channel.
  649. *
  650. * Note: Since i was getting a ban list, i assume i'm chop.
  651. */
  652. static void recheck_bans(struct chanset_t *chan)
  653. {
  654. maskrec *u = NULL;
  655. int cycle;
  656. /* Check global bans in first cycle and channel bans
  657. in second cycle. */
  658. for (cycle = 0; cycle < 2; cycle++) {
  659. for (u = cycle ? chan->bans : global_bans; u; u = u->next)
  660. if (!isbanned(chan, u->mask) && (!channel_dynamicbans(chan) ||
  661. (u->flags & MASKREC_STICKY)))
  662. add_mode(chan, '+', 'b', u->mask);
  663. }
  664. }
  665. /* Make sure that all who are exempted on the userlist are actually in fact
  666. * exempted on the channel.
  667. *
  668. * Note: Since i was getting an excempt list, i assume i'm chop.
  669. */
  670. static void recheck_exempts(struct chanset_t *chan)
  671. {
  672. maskrec *e = NULL;
  673. masklist *b = NULL;
  674. int cycle;
  675. /* Check global exempts in first cycle and channel exempts
  676. in second cycle. */
  677. for (cycle = 0; cycle < 2; cycle++) {
  678. for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
  679. if (!isexempted(chan, e->mask) &&
  680. (!channel_dynamicexempts(chan) || (e->flags & MASKREC_STICKY)))
  681. add_mode(chan, '+', 'e', e->mask);
  682. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  683. if ((wild_match(b->mask, e->mask) || wild_match(e->mask, b->mask)) &&
  684. !isexempted(chan, e->mask))
  685. add_mode(chan,'+','e',e->mask);
  686. /* do_mask(chan, chan->channel.exempt, e->mask, 'e');*/
  687. }
  688. }
  689. }
  690. }
  691. /* Make sure that all who are invited on the userlist are actually in fact
  692. * invited on the channel.
  693. *
  694. * Note: Since i was getting an invite list, i assume i'm chop.
  695. */
  696. static void recheck_invites(struct chanset_t *chan)
  697. {
  698. maskrec *ir = NULL;
  699. int cycle;
  700. /* Check global invites in first cycle and channel invites
  701. in second cycle. */
  702. for (cycle = 0; cycle < 2; cycle++) {
  703. for (ir = cycle ? chan->invites : global_invites; ir; ir = ir->next) {
  704. /* If invite isn't set and (channel is not dynamic invites and not invite
  705. * only) or invite is sticky.
  706. */
  707. if (!isinvited(chan, ir->mask) && ((!channel_dynamicinvites(chan) &&
  708. !(chan->channel.mode & CHANINV)) || ir->flags & MASKREC_STICKY))
  709. add_mode(chan, '+', 'I', ir->mask);
  710. /* do_mask(chan, chan->channel.invite, ir->mask, 'I');*/
  711. }
  712. }
  713. }
  714. /* Resets the masks on the channel.
  715. */
  716. static void resetmasks(struct chanset_t *chan, masklist *m, maskrec *mrec, maskrec *global_masks, char mode)
  717. {
  718. if (!me_op(chan))
  719. return; /* Can't do it */
  720. /* Remove masks we didn't put there */
  721. for (; m && m->mask[0]; m = m->next) {
  722. if (!u_equals_mask(global_masks, m->mask) && !u_equals_mask(mrec, m->mask))
  723. add_mode(chan, '-', mode, m->mask);
  724. }
  725. /* Make sure the intended masks are still there */
  726. switch (mode) {
  727. case 'b':
  728. recheck_bans(chan);
  729. break;
  730. case 'e':
  731. recheck_exempts(chan);
  732. break;
  733. case 'I':
  734. recheck_invites(chan);
  735. break;
  736. default:
  737. putlog(LOG_MISC, "*", "(!) Invalid mode '%c' in resetmasks()", mode);
  738. break;
  739. }
  740. }
  741. void check_this_ban(struct chanset_t *chan, char *banmask, int sticky)
  742. {
  743. memberlist *m = NULL;
  744. char user[UHOSTLEN] = "";
  745. if (!me_op(chan))
  746. return;
  747. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  748. sprintf(user, "%s!%s", m->nick, m->userhost);
  749. if (wild_match(banmask, user) &&
  750. !(use_exempts &&
  751. (u_match_mask(global_exempts, user) ||
  752. u_match_mask(chan->exempts, user))))
  753. refresh_ban_kick(chan, user, m->nick);
  754. }
  755. if (!isbanned(chan, banmask) &&
  756. (!channel_dynamicbans(chan) || sticky))
  757. add_mode(chan, '+', 'b', banmask);
  758. }
  759. void recheck_channel_modes(struct chanset_t *chan)
  760. {
  761. int cur = chan->channel.mode,
  762. mns = chan->mode_mns_prot,
  763. pls = chan->mode_pls_prot;
  764. if (channel_closed(chan)) {
  765. pls |= CHANINV;
  766. mns &= ~CHANINV;
  767. }
  768. if (!(chan->status & CHAN_ASKEDMODES)) {
  769. if (pls & CHANINV && !(cur & CHANINV))
  770. add_mode(chan, '+', 'i', "");
  771. else if (mns & CHANINV && cur & CHANINV)
  772. add_mode(chan, '-', 'i', "");
  773. if (pls & CHANPRIV && !(cur & CHANPRIV))
  774. add_mode(chan, '+', 'p', "");
  775. else if (mns & CHANPRIV && cur & CHANPRIV)
  776. add_mode(chan, '-', 'p', "");
  777. if (pls & CHANSEC && !(cur & CHANSEC))
  778. add_mode(chan, '+', 's', "");
  779. else if (mns & CHANSEC && cur & CHANSEC)
  780. add_mode(chan, '-', 's', "");
  781. if (pls & CHANMODER && !(cur & CHANMODER))
  782. add_mode(chan, '+', 'm', "");
  783. else if (mns & CHANMODER && cur & CHANMODER)
  784. add_mode(chan, '-', 'm', "");
  785. if (pls & CHANNOCLR && !(cur & CHANNOCLR))
  786. add_mode(chan, '+', 'c', "");
  787. else if (mns & CHANNOCLR && cur & CHANNOCLR)
  788. add_mode(chan, '-', 'c', "");
  789. if (pls & CHANNOCTCP && !(cur & CHANNOCTCP))
  790. add_mode(chan, '+', 'C', "");
  791. else if (mns & CHANNOCTCP && cur & CHANNOCTCP)
  792. add_mode(chan, '-', 'C', "");
  793. if (pls & CHANREGON && !(cur & CHANREGON))
  794. add_mode(chan, '+', 'R', "");
  795. else if (mns & CHANREGON && cur & CHANREGON)
  796. add_mode(chan, '-', 'R', "");
  797. if (pls & CHANMODR && !(cur & CHANMODR))
  798. add_mode(chan, '+', 'M', "");
  799. else if (mns & CHANMODR && cur & CHANMODR)
  800. add_mode(chan, '-', 'M', "");
  801. if (pls & CHANLONLY && !(cur & CHANLONLY))
  802. add_mode(chan, '+', 'r', "");
  803. else if (mns & CHANLONLY && cur & CHANLONLY)
  804. add_mode(chan, '-', 'r', "");
  805. if (pls & CHANTOPIC && !(cur & CHANTOPIC))
  806. add_mode(chan, '+', 't', "");
  807. else if (mns & CHANTOPIC && cur & CHANTOPIC)
  808. add_mode(chan, '-', 't', "");
  809. if (pls & CHANNOMSG && !(cur & CHANNOMSG))
  810. add_mode(chan, '+', 'n', "");
  811. else if ((mns & CHANNOMSG) && (cur & CHANNOMSG))
  812. add_mode(chan, '-', 'n', "");
  813. if ((pls & CHANANON) && !(cur & CHANANON))
  814. add_mode(chan, '+', 'a', "");
  815. else if ((mns & CHANANON) && (cur & CHANANON))
  816. add_mode(chan, '-', 'a', "");
  817. if ((pls & CHANQUIET) && !(cur & CHANQUIET))
  818. add_mode(chan, '+', 'q', "");
  819. else if ((mns & CHANQUIET) && (cur & CHANQUIET))
  820. add_mode(chan, '-', 'q', "");
  821. if ((chan->limit_prot != 0) && (chan->channel.maxmembers == 0)) {
  822. char s[50] = "";
  823. sprintf(s, "%d", chan->limit_prot);
  824. add_mode(chan, '+', 'l', s);
  825. } else if ((mns & CHANLIMIT) && (chan->channel.maxmembers != 0))
  826. add_mode(chan, '-', 'l', "");
  827. if (chan->key_prot[0]) {
  828. if (rfc_casecmp(chan->channel.key, chan->key_prot) != 0) {
  829. if (chan->channel.key[0])
  830. add_mode(chan, '-', 'k', chan->channel.key);
  831. add_mode(chan, '+', 'k', chan->key_prot);
  832. }
  833. } else if ((mns & CHANKEY) && (chan->channel.key[0]))
  834. add_mode(chan, '-', 'k', chan->channel.key);
  835. }
  836. }
  837. static void check_this_member(struct chanset_t *chan, char *nick, struct flag_record *fr)
  838. {
  839. memberlist *m = NULL;
  840. char s[UHOSTLEN] = "", *p = NULL;
  841. m = ismember(chan, nick);
  842. if (!m || match_my_nick(nick) || !me_op(chan))
  843. return;
  844. if (me_op(chan)) {
  845. /* +d or bitch and not an op
  846. * we dont check private because +private does not imply bitch. */
  847. if (chan_hasop(m) &&
  848. (chk_deop(*fr, chan) ||
  849. (!loading && userlist && channel_bitch(chan) && !chk_op(*fr, chan)) ) ) {
  850. /* if (target_priority(chan, m, 1)) */
  851. add_mode(chan, '-', 'o', m->nick);
  852. } else if (!chan_hasop(m) && chk_autoop(*fr, chan)) {
  853. do_op(m->nick, chan, 1, 0);
  854. }
  855. if (dovoice(chan)) {
  856. if (chan_hasvoice(m) && !chan_hasop(m)) {
  857. /* devoice +q users .. */
  858. if (chk_devoice(*fr, chan))
  859. add_mode(chan, '-', 'v', m->nick);
  860. } else if (!chan_hasvoice(m) && !chan_hasop(m)) {
  861. /* voice +v users */
  862. if (chk_voice(*fr, chan))
  863. add_mode(chan, '+', 'v', m->nick);
  864. }
  865. }
  866. }
  867. sprintf(s, "%s!%s", m->nick, m->userhost);
  868. /* check vs invites */
  869. if (use_invites &&
  870. (u_match_mask(global_invites,s) ||
  871. u_match_mask(chan->invites, s)))
  872. refresh_invite(chan, s);
  873. /* don't kickban if permanent exempted */
  874. if (!(use_exempts &&
  875. (u_match_mask(global_exempts,s) ||
  876. u_match_mask(chan->exempts, s)))) {
  877. if (u_match_mask(global_bans, s) || u_match_mask(chan->bans, s))
  878. refresh_ban_kick(chan, s, m->nick);
  879. /* are they +k ? */
  880. if (!chan_sentkick(m) && (chan_kick(*fr) || glob_kick(*fr)) && me_op(chan)) {
  881. check_exemptlist(chan, s);
  882. quickban(chan, m->userhost);
  883. p = get_user(&USERENTRY_COMMENT, m->user);
  884. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, p ? p : kickreason(KICK_KUSER));
  885. m->flags |= SENTKICK;
  886. }
  887. }
  888. }
  889. void check_this_user(char *hand, int delete, char *host)
  890. {
  891. char s[UHOSTLEN] = "";
  892. memberlist *m = NULL;
  893. struct userrec *u = NULL;
  894. struct chanset_t *chan = NULL;
  895. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  896. for (chan = chanset; chan; chan = chan->next)
  897. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  898. sprintf(s, "%s!%s", m->nick, m->userhost);
  899. u = m->user ? m->user : get_user_by_host(s);
  900. if ((u && !egg_strcasecmp(u->handle, hand) && delete < 2) ||
  901. (!u && delete == 2 && wild_match(host, fixfrom(s)))) {
  902. u = delete ? NULL : u;
  903. get_user_flagrec(u, &fr, chan->dname);
  904. check_this_member(chan, m->nick, &fr);
  905. }
  906. }
  907. }
  908. static void enforce_bitch(struct chanset_t *chan) {
  909. if (!chan || !me_op(chan)) return;
  910. priority_do(chan, 1, PRIO_DEOP);
  911. }
  912. void enforce_closed(struct chanset_t *chan) {
  913. char buf[1024] = "";
  914. if (!chan || !me_op(chan)) return;
  915. if (!(chan->channel.mode & CHANINV))
  916. strcat(buf, "i");
  917. if (chan->closed_private && !(chan->channel.mode & CHANPRIV))
  918. strcat(buf, "p");
  919. if (buf && buf[0])
  920. dprintf(DP_MODE, "MODE %s +%s\n", chan->name, buf);
  921. priority_do(chan, 0, PRIO_KICK);
  922. }
  923. static char *
  924. take_makeline(char *op, char *deops, int deopn)
  925. {
  926. int pos = 0, i = 0, n = 0, opn = op ? 1 : 0;
  927. char *ret = NULL;
  928. n = opn + deopn; /* op + deops */
  929. ret = calloc(1, 101);
  930. pos = randint(deopn);
  931. for (i = 0; i < n; i++) {
  932. if (opn && i == pos) strcat(ret, "+o");
  933. else if (deopn) strcat(ret, "-o");
  934. }
  935. strcat(ret, " ");
  936. for (i = 0; i < n; i++) {
  937. if (opn && i == pos)
  938. strcat(ret, op);
  939. else if (deopn)
  940. strcat(ret, newsplit(&deops));
  941. strcat(ret, " ");
  942. }
  943. /* putlog(LOG_MISC, "*", "modeline: %s", ret); */
  944. return ret;
  945. }
  946. static void
  947. do_take(struct chanset_t *chan)
  948. {
  949. memberlist *m = NULL;
  950. char work[512] = "", *to_op = NULL, *to_deop = NULL, *to_op_ptr = NULL, *to_deop_ptr = NULL;
  951. int lines = 0;
  952. to_op = to_op_ptr = calloc(1, 2048);
  953. to_deop = to_deop_ptr = calloc(1, 2048);
  954. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  955. int hasop = (m->flags & CHANOP);
  956. if (m && rfc_casecmp(m->nick, botname)) {
  957. if (m->user && (m->user->flags & USER_BOT) && !hasop) {
  958. strcat(to_op, m->nick);
  959. strcat(to_op, " ");
  960. /* } else if (hasop && !(m->user && m->user->flags & USER_OP)) { */
  961. } else if (hasop && !(m->user && (m->user->flags & USER_BOT))) {
  962. strcat(to_deop, m->nick);
  963. strcat(to_deop, " ");
  964. }
  965. }
  966. }
  967. shuffle(to_op, " ");
  968. shuffle(to_deop, " ");
  969. /*
  970. putlog(LOG_MISC, "*", "op: %s", to_op);
  971. putlog(LOG_MISC, "*", "deop: %s", to_deop);
  972. */
  973. while (to_op[0] || to_deop[0]) {
  974. int deopn = 0, i = 0;
  975. char *op = NULL, *deopline = NULL, deops[201] = "";
  976. if (to_op[0])
  977. op = newsplit(&to_op);
  978. for (i = 0; i < 4; i ++) {
  979. if (to_deop[0] && ((i < 3) || (!op))) {
  980. deopn++;
  981. strcat(deops, newsplit(&to_deop));
  982. strcat(deops, " ");
  983. }
  984. }
  985. strcat(work, "MODE ");
  986. strcat(work, chan->name);
  987. strcat(work, " ");
  988. deopline = take_makeline(op, deops, deopn);
  989. strcat(work, deopline);
  990. strcat(work, "\n");
  991. lines++;
  992. free(deopline);
  993. /* just dump when we have 5 lines because the server is going to throttle after that anyway */
  994. if (lines == 5) {
  995. tputs(serv, work, strlen(work));
  996. work[0] = 0;
  997. lines = 0;
  998. }
  999. }
  1000. if (work[0])
  1001. tputs(serv, work, strlen(work));
  1002. free(to_op_ptr);
  1003. free(to_deop_ptr);
  1004. if (channel_closed(chan))
  1005. enforce_closed(chan);
  1006. enforce_bitch(chan); /* hell why not! */
  1007. return;
  1008. }
  1009. time_t last_eI; /* this will stop +e and +I from being checked over and over if the bot is stuck in a
  1010. * -o+o loop for some reason, hence possibly causing a SENDQ kill
  1011. */
  1012. /* Things to do when i just became a chanop:
  1013. */
  1014. void recheck_channel(struct chanset_t *chan, int dobans)
  1015. {
  1016. memberlist *m = NULL;
  1017. char s[UHOSTLEN] = "";
  1018. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  1019. static int stacking = 0;
  1020. int stop_reset = 0, botops = 0, nonbotops = 0, botnonops = 0;
  1021. if (stacking)
  1022. return; /* wewps */
  1023. if (!userlist || loading) /* Bot doesnt know anybody */
  1024. return; /* ... it's better not to deop everybody */
  1025. stacking++;
  1026. putlog(LOG_DEBUG, "*", "recheck_channel %s", chan->dname);
  1027. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1028. int hasop = chan_hasop(m);
  1029. if (m) {
  1030. if (m->user && m->user->flags & (USER_BOT | USER_OP)) {
  1031. if (hasop)
  1032. botops++;
  1033. else
  1034. botnonops++;
  1035. } else if (hasop)
  1036. nonbotops++;
  1037. }
  1038. }
  1039. /* don't do much if i'm lonely bot. Maybe they won't notice me? :P */
  1040. if (botops == 1 && !botnonops) {
  1041. if (channel_bitch(chan) || channel_closed(chan))
  1042. putlog(LOG_MISC, "*", "Opped in %s, not checking +closed/+bitch until more bots arrive.", chan->dname);
  1043. } else {
  1044. /* if the chan is +closed, mass deop first, safer that way. */
  1045. if (channel_bitch(chan) || channel_closed(chan))
  1046. enforce_bitch(chan);
  1047. if (channel_closed(chan))
  1048. enforce_closed(chan);
  1049. }
  1050. /* this can all die, we want to enforce +bitch/+take first :) */
  1051. /* This is a bad hack for +e/+I */
  1052. if (!channel_take(chan) && me_op(chan) && ((now - last_eI) > 30)) {
  1053. last_eI = now;
  1054. if (!(chan->ircnet_status & CHAN_ASKED_EXEMPTS) &&
  1055. use_exempts == 1) {
  1056. chan->ircnet_status |= CHAN_ASKED_EXEMPTS;
  1057. dprintf(DP_MODE, "MODE %s +e\n", chan->name);
  1058. }
  1059. if (!(chan->ircnet_status & CHAN_ASKED_INVITED) &&
  1060. use_invites == 1) {
  1061. chan->ircnet_status |= CHAN_ASKED_INVITED;
  1062. dprintf(DP_MODE, "MODE %s +I\n", chan->name);
  1063. }
  1064. }
  1065. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1066. sprintf(s, "%s!%s", m->nick, m->userhost);
  1067. if (!m->user && !m->tried_getuser) {
  1068. m->tried_getuser = 1;
  1069. m->user = get_user_by_host(s);
  1070. }
  1071. get_user_flagrec(m->user, &fr, chan->dname);
  1072. if (glob_bot(fr) && chan_hasop(m) && !match_my_nick(m->nick))
  1073. stop_reset = 1;
  1074. check_this_member(chan, m->nick, &fr);
  1075. }
  1076. if (dobans) {
  1077. if (channel_nouserbans(chan) && !stop_reset)
  1078. resetbans(chan);
  1079. else
  1080. recheck_bans(chan);
  1081. if (use_invites) {
  1082. if (channel_nouserinvites(chan) && !stop_reset)
  1083. resetinvites(chan);
  1084. else
  1085. recheck_invites(chan);
  1086. }
  1087. if (use_exempts) {
  1088. if (channel_nouserexempts(chan) && !stop_reset)
  1089. resetexempts(chan);
  1090. else
  1091. recheck_exempts(chan);
  1092. } else {
  1093. if (channel_enforcebans(chan))
  1094. enforce_bans(chan);
  1095. }
  1096. flush_mode(chan, QUICK);
  1097. if ((chan->status & CHAN_ASKEDMODES) && !channel_inactive(chan))
  1098. dprintf(DP_MODE, "MODE %s\n", chan->name);
  1099. recheck_channel_modes(chan);
  1100. }
  1101. stacking--;
  1102. }
  1103. /* got 324: mode status
  1104. * <server> 324 <to> <channel> <mode>
  1105. */
  1106. static int got324(char *from, char *msg)
  1107. {
  1108. int i = 1, ok =0;
  1109. char *p = NULL, *q = NULL, *chname = NULL;
  1110. struct chanset_t *chan = NULL;
  1111. newsplit(&msg);
  1112. chname = newsplit(&msg);
  1113. if (match_my_nick(chname))
  1114. return 0;
  1115. chan = findchan(chname);
  1116. if (!chan) {
  1117. putlog(LOG_MISC, "*", "%s: %s", IRC_UNEXPECTEDMODE, chname);
  1118. dprintf(DP_SERVER, "PART %s\n", chname);
  1119. return 0;
  1120. }
  1121. if (chan->status & CHAN_ASKEDMODES)
  1122. ok = 1;
  1123. chan->status &= ~CHAN_ASKEDMODES;
  1124. chan->channel.mode = 0;
  1125. while (msg[i] != 0) {
  1126. if (msg[i] == 'i')
  1127. chan->channel.mode |= CHANINV;
  1128. if (msg[i] == 'p')
  1129. chan->channel.mode |= CHANPRIV;
  1130. if (msg[i] == 's')
  1131. chan->channel.mode |= CHANSEC;
  1132. if (msg[i] == 'm')
  1133. chan->channel.mode |= CHANMODER;
  1134. if (msg[i] == 'c')
  1135. chan->channel.mode |= CHANNOCLR;
  1136. if (msg[i] == 'C')
  1137. chan->channel.mode |= CHANNOCTCP;
  1138. if (msg[i] == 'R')
  1139. chan->channel.mode |= CHANREGON;
  1140. if (msg[i] == 'M')
  1141. chan->channel.mode |= CHANMODR;
  1142. if (msg[i] == 'r')
  1143. chan->channel.mode |= CHANLONLY;
  1144. if (msg[i] == 't')
  1145. chan->channel.mode |= CHANTOPIC;
  1146. if (msg[i] == 'n')
  1147. chan->channel.mode |= CHANNOMSG;
  1148. if (msg[i] == 'a')
  1149. chan->channel.mode |= CHANANON;
  1150. if (msg[i] == 'q')
  1151. chan->channel.mode |= CHANQUIET;
  1152. if (msg[i] == 'k') {
  1153. chan->channel.mode |= CHANKEY;
  1154. p = strchr(msg, ' ');
  1155. if (p != NULL) { /* Test for null key assignment */
  1156. p++;
  1157. q = strchr(p, ' ');
  1158. if (q != NULL) {
  1159. *q = 0;
  1160. my_setkey(chan, p);
  1161. strcpy(p, q + 1);
  1162. } else {
  1163. my_setkey(chan, p);
  1164. *p = 0;
  1165. }
  1166. }
  1167. if ((chan->channel.mode & CHANKEY) && (!chan->channel.key[0] ||
  1168. !strcmp("*", chan->channel.key)))
  1169. /* Undernet use to show a blank channel key if one was set when
  1170. * you first joined a channel; however, this has been replaced by
  1171. * an asterisk and this has been agreed upon by other major IRC
  1172. * networks so we'll check for an asterisk here as well
  1173. * (guppy 22Dec2001) */
  1174. chan->status |= CHAN_ASKEDMODES;
  1175. }
  1176. if (msg[i] == 'l') {
  1177. p = strchr(msg, ' ');
  1178. if (p != NULL) { /* test for null limit assignment */
  1179. p++;
  1180. q = strchr(p, ' ');
  1181. if (q != NULL) {
  1182. *q = 0;
  1183. chan->channel.maxmembers = atoi(p);
  1184. /* strcpy(p, q + 1); */
  1185. sprintf(p, "%s", q + 1);
  1186. } else {
  1187. chan->channel.maxmembers = atoi(p);
  1188. *p = 0;
  1189. }
  1190. }
  1191. }
  1192. i++;
  1193. }
  1194. if (ok)
  1195. recheck_channel_modes(chan);
  1196. return 0;
  1197. }
  1198. static void memberlist_reposition(struct chanset_t * chan, memberlist * target) {
  1199. /* Move target from it's current position to it's correct sorted position */
  1200. memberlist *old = NULL, *m = NULL;
  1201. if (chan->channel.member == target) {
  1202. chan->channel.member = target->next;
  1203. } else {
  1204. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1205. if (m->next == target) {
  1206. m->next = target->next;
  1207. break;
  1208. }
  1209. }
  1210. }
  1211. target->next = NULL;
  1212. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1213. if (rfc_casecmp(m->nick, target->nick)>0) {
  1214. if (old) {
  1215. target->next = m;
  1216. old->next = target;
  1217. } else {
  1218. target->next = chan->channel.member;
  1219. chan->channel.member = target;
  1220. }
  1221. return;
  1222. }
  1223. old = m;
  1224. }
  1225. if (old) {
  1226. target->next = old->next;
  1227. old->next = target;
  1228. } else {
  1229. target->next = NULL;
  1230. chan->channel.member = target;
  1231. }
  1232. }
  1233. static int got352or4(struct chanset_t *chan, char *user, char *host, char *serv, char *nick, char *flags, int hops)
  1234. {
  1235. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0};
  1236. char userhost[UHOSTLEN] = "";
  1237. memberlist *m = NULL;
  1238. int waschanop;
  1239. m = ismember(chan, nick); /* In my channel list copy? */
  1240. if (!m) { /* Nope, so update */
  1241. m = newmember(chan, nick); /* Get a new channel entry */
  1242. m->joined = m->split = m->delay = 0L; /* Don't know when he joined */
  1243. m->flags = 0; /* No flags for now */
  1244. m->last = now; /* Last time I saw him */
  1245. }
  1246. strcpy(m->nick, nick); /* Store the nick in list */
  1247. if (serv) {
  1248. struct chanset_t *ch = NULL;
  1249. memberlist *ml = NULL;
  1250. strncpyz(m->server, serv, SERVLEN);
  1251. /* Propagate server to other channel memlists... might save us a WHO #chan */
  1252. for (ch = chanset; ch; ch = ch->next) {
  1253. if (ch != chan) {
  1254. for (ml = ch->channel.member; ml && ml->nick[0]; ml = ml->next) {
  1255. if (!strcmp(ml->nick, m->nick)) {
  1256. strcpy(ml->server, m->server);
  1257. break;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. } else
  1263. m->server[0] = 0;
  1264. {
  1265. struct chanset_t *ch = NULL;
  1266. memberlist *ml = NULL;
  1267. m->hops = hops;
  1268. /* Propagate hops to other channel memlists... might save us a WHO #chan */
  1269. for (ch = chanset; ch; ch = ch->next) {
  1270. if (ch != chan) {
  1271. for (ml = ch->channel.member; ml && ml->nick[0]; ml = ml->next) {
  1272. if (!strcmp(ml->nick, m->nick)) {
  1273. ml->hops = m->hops;
  1274. break;
  1275. }
  1276. }
  1277. }
  1278. }
  1279. }
  1280. /* Store the userhost */
  1281. simple_sprintf(m->userhost, "%s@%s", user, host);
  1282. simple_sprintf(userhost, "%s!%s", nick, m->userhost);
  1283. /* Combine n!u@h */
  1284. m->user = NULL; /* No handle match (yet) */
  1285. m->tried_getuser = 0;
  1286. if (match_my_nick(nick)) { /* Is it me? */
  1287. strcpy(botuserhost, m->userhost); /* Yes, save my own userhost */
  1288. m->joined = now; /* set this to keep the whining masses happy */
  1289. }
  1290. waschanop = me_op(chan); /* Am I opped here? */
  1291. if (strchr(flags, '@') != NULL) /* Flags say he's opped? */
  1292. m->flags |= (CHANOP | WASOP); /* Yes, so flag in my table */
  1293. else
  1294. m->flags &= ~(CHANOP | WASOP);
  1295. if (strchr(flags, '*'))
  1296. m->flags |= OPER;
  1297. else
  1298. m->flags &= ~OPER;
  1299. if (strchr(flags, '+') != NULL) /* Flags say he's voiced? */
  1300. m->flags |= CHANVOICE; /* Yes */
  1301. else
  1302. m->flags &= ~CHANVOICE;
  1303. if (!(m->flags & (CHANVOICE | CHANOP)))
  1304. m->flags |= STOPWHO;
  1305. if (match_my_nick(nick) && !waschanop && me_op(chan))
  1306. recheck_channel(chan, 1);
  1307. if (match_my_nick(nick) && any_ops(chan) && !me_op(chan))
  1308. chan->channel.do_opreq = 1;
  1309. m->user = get_user_by_host(userhost);
  1310. m->tried_getuser = 1;
  1311. get_user_flagrec(m->user, &fr, chan->dname);
  1312. /* are they a chanop, and me too */
  1313. /* are they a channel or global de-op */
  1314. if (chan_hasop(m) && me_op(chan) && chk_deop(fr, chan) && !match_my_nick(nick))
  1315. /* && target_priority(chan, m, 1) */
  1316. add_mode(chan, '-', 'o', nick);
  1317. /* if channel is enforce bans */
  1318. if (channel_enforcebans(chan) &&
  1319. /* and user matches a ban */
  1320. (u_match_mask(global_bans, userhost) || u_match_mask(chan->bans, userhost)) &&
  1321. /* and it's not me, and i'm an op */
  1322. !match_my_nick(nick) && me_op(chan)) {
  1323. /* && target_priority(chan, m, 0) */
  1324. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, nick, bankickprefix, kickreason(KICK_BANNED));
  1325. m->flags |= SENTKICK;
  1326. }
  1327. /* if the user is a +k */
  1328. else if ((chan_kick(fr) || glob_kick(fr)) &&
  1329. /* and it's not me :) who'd set me +k anyway, a sicko? */
  1330. /* and if im an op */
  1331. !match_my_nick(nick) && me_op(chan)) {
  1332. /* && target_priority(chan, m, 0) */
  1333. /* cya later! */
  1334. quickban(chan, userhost);
  1335. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, nick, bankickprefix, kickreason(KICK_KUSER));
  1336. m->flags |= SENTKICK;
  1337. }
  1338. return 0;
  1339. }
  1340. /* got a 352: who info!
  1341. */
  1342. static int got352(char *from, char *msg)
  1343. {
  1344. char *nick = NULL, *user = NULL, *host = NULL, *chname = NULL, *flags = NULL, *serv = NULL, *hops = NULL;
  1345. struct chanset_t *chan = NULL;
  1346. newsplit(&msg); /* Skip my nick - effeciently */
  1347. chname = newsplit(&msg); /* Grab the channel */
  1348. chan = findchan(chname); /* See if I'm on channel */
  1349. if (chan) { /* Am I? */
  1350. user = newsplit(&msg); /* Grab the user */
  1351. host = newsplit(&msg); /* Grab the host */
  1352. serv = newsplit(&msg); /* And the server */
  1353. nick = newsplit(&msg); /* Grab the nick */
  1354. flags = newsplit(&msg); /* Grab the flags */
  1355. hops = newsplit(&msg); /* grab server hops */
  1356. hops++;
  1357. got352or4(chan, user, host, serv, nick, flags, atoi(hops));
  1358. }
  1359. return 0;
  1360. }
  1361. /* got a 354: who info! - iru style
  1362. */
  1363. static int got354(char *from, char *msg)
  1364. {
  1365. char *nick = NULL, *user = NULL, *host = NULL, *chname = NULL, *flags = NULL, *hops = NULL;
  1366. struct chanset_t *chan = NULL;
  1367. if (use_354) {
  1368. newsplit(&msg); /* Skip my nick - effeciently */
  1369. if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
  1370. chname = newsplit(&msg); /* Grab the channel */
  1371. chan = findchan(chname); /* See if I'm on channel */
  1372. if (chan) { /* Am I? */
  1373. user = newsplit(&msg); /* Grab the user */
  1374. host = newsplit(&msg); /* Grab the host */
  1375. nick = newsplit(&msg); /* Grab the nick */
  1376. flags = newsplit(&msg); /* Grab the flags */
  1377. hops = newsplit(&msg); /* yay for hops, does iru even have hops?? */
  1378. hops++;
  1379. got352or4(chan, user, host, NULL, nick, flags, atoi(hops));
  1380. }
  1381. }
  1382. }
  1383. return 0;
  1384. }
  1385. /* got 315: end of who
  1386. * <server> 315 <to> <chan> :End of /who
  1387. */
  1388. static int got315(char *from, char *msg)
  1389. {
  1390. char *chname = NULL;
  1391. struct chanset_t *chan = NULL;
  1392. newsplit(&msg);
  1393. chname = newsplit(&msg);
  1394. chan = findchan(chname);
  1395. /* May have left the channel before the who info came in */
  1396. if (!chan || !channel_pending(chan))
  1397. return 0;
  1398. /* Finished getting who list, can now be considered officially ON CHANNEL */
  1399. chan->status |= CHAN_ACTIVE;
  1400. chan->status &= ~CHAN_PEND;
  1401. /* Am *I* on the channel now? if not, well d0h. */
  1402. if (!ismember(chan, botname)) {
  1403. putlog(LOG_MISC | LOG_JOIN, chan->dname, "Oops, I'm not really on %s.",
  1404. chan->dname);
  1405. clear_channel(chan, 1);
  1406. chan->status &= ~CHAN_ACTIVE;
  1407. dprintf(DP_MODE, "JOIN %s %s\n",
  1408. (chan->name[0]) ? chan->name : chan->dname,
  1409. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  1410. } else {
  1411. if (me_op(chan))
  1412. recheck_channel(chan, 1);
  1413. else if (chan->channel.members == 1)
  1414. chan->status |= CHAN_STOP_CYCLE;
  1415. else
  1416. request_op(chan);
  1417. }
  1418. /* do not check for i-lines here. */
  1419. return 0;
  1420. }
  1421. /* got 367: ban info
  1422. * <server> 367 <to> <chan> <ban> [placed-by] [timestamp]
  1423. */
  1424. static int got367(char *from, char *origmsg)
  1425. {
  1426. char *ban = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
  1427. struct chanset_t *chan = NULL;
  1428. strncpy(buf, origmsg, 510);
  1429. buf[510] = 0;
  1430. msg = buf;
  1431. newsplit(&msg);
  1432. chname = newsplit(&msg);
  1433. chan = findchan(chname);
  1434. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  1435. return 0;
  1436. ban = newsplit(&msg);
  1437. who = newsplit(&msg);
  1438. /* Extended timestamp format? */
  1439. if (who[0])
  1440. newban(chan, ban, who);
  1441. else
  1442. newban(chan, ban, "existent");
  1443. return 0;
  1444. }
  1445. /* got 368: end of ban list
  1446. * <server> 368 <to> <chan> :etc
  1447. */
  1448. static int got368(char *from, char *msg)
  1449. {
  1450. struct chanset_t *chan = NULL;
  1451. char *chname = NULL;
  1452. /* Okay, now add bans that i want, which aren't set yet */
  1453. newsplit(&msg);
  1454. chname = newsplit(&msg);
  1455. chan = findchan(chname);
  1456. if (chan)
  1457. chan->status &= ~CHAN_ASKEDBANS;
  1458. /* If i sent a mode -b on myself (deban) in got367, either
  1459. * resetbans() or recheck_bans() will flush that.
  1460. */
  1461. return 0;
  1462. }
  1463. /* got 348: ban exemption info
  1464. * <server> 348 <to> <chan> <exemption>
  1465. */
  1466. static int got348(char *from, char *origmsg)
  1467. {
  1468. char *exempt = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
  1469. struct chanset_t *chan = NULL;
  1470. if (use_exempts == 0)
  1471. return 0;
  1472. strncpy(buf, origmsg, 510);
  1473. buf[510] = 0;
  1474. msg = buf;
  1475. newsplit(&msg);
  1476. chname = newsplit(&msg);
  1477. chan = findchan(chname);
  1478. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  1479. return 0;
  1480. exempt = newsplit(&msg);
  1481. who = newsplit(&msg);
  1482. /* Extended timestamp format? */
  1483. if (who[0])
  1484. newexempt(chan, exempt, who);
  1485. else
  1486. newexempt(chan, exempt, "existent");
  1487. return 0;
  1488. }
  1489. /* got 349: end of ban exemption list
  1490. * <server> 349 <to> <chan> :etc
  1491. */
  1492. static int got349(char *from, char *msg)
  1493. {
  1494. struct chanset_t *chan = NULL;
  1495. char *chname = NULL;
  1496. if (use_exempts == 1) {
  1497. newsplit(&msg);
  1498. chname = newsplit(&msg);
  1499. chan = findchan(chname);
  1500. if (chan) {
  1501. putlog(LOG_DEBUG, "*", "END +e %s", chan->dname);
  1502. chan->ircnet_status &= ~CHAN_ASKED_EXEMPTS;
  1503. if (channel_enforcebans(chan))
  1504. enforce_bans(chan);
  1505. }
  1506. }
  1507. return 0;
  1508. }
  1509. /* got 346: invite exemption info
  1510. * <server> 346 <to> <chan> <exemption>
  1511. */
  1512. static int got346(char *from, char *origmsg)
  1513. {
  1514. char *invite = NULL, *who = NULL, *chname = NULL, buf[511] = "", *msg = NULL;
  1515. struct chanset_t *chan = NULL;
  1516. strncpy(buf, origmsg, 510);
  1517. buf[510] = 0;
  1518. msg = buf;
  1519. if (use_invites == 0)
  1520. return 0;
  1521. newsplit(&msg);
  1522. chname = newsplit(&msg);
  1523. chan = findchan(chname);
  1524. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  1525. return 0;
  1526. invite = newsplit(&msg);
  1527. who = newsplit(&msg);
  1528. /* Extended timestamp format? */
  1529. if (who[0])
  1530. newinvite(chan, invite, who);
  1531. else
  1532. newinvite(chan, invite, "existent");
  1533. return 0;
  1534. }
  1535. /* got 347: end of invite exemption list
  1536. * <server> 347 <to> <chan> :etc
  1537. */
  1538. static int got347(char *from, char *msg)
  1539. {
  1540. struct chanset_t *chan = NULL;
  1541. char *chname = NULL;
  1542. if (use_invites == 1) {
  1543. newsplit(&msg);
  1544. chname = newsplit(&msg);
  1545. chan = findchan(chname);
  1546. if (chan)
  1547. chan->ircnet_status &= ~CHAN_ASKED_INVITED;
  1548. }
  1549. return 0;
  1550. }
  1551. /* Too many channels.
  1552. */
  1553. static int got405(char *from, char *msg)
  1554. {
  1555. char *chname = NULL;
  1556. newsplit(&msg);
  1557. chname = newsplit(&msg);
  1558. putlog(LOG_MISC, "*", IRC_TOOMANYCHANS, chname);
  1559. return 0;
  1560. }
  1561. /* This is only of use to us with !channels. We get this message when
  1562. * attempting to join a non-existant !channel... The channel must be
  1563. * created by sending 'JOIN !!<channel>'. <cybah>
  1564. *
  1565. * 403 - ERR_NOSUCHCHANNEL
  1566. */
  1567. static int got403(char *from, char *msg)
  1568. {
  1569. char *chname = NULL;
  1570. struct chanset_t *chan = NULL;
  1571. newsplit(&msg);
  1572. chname = newsplit(&msg);
  1573. if (chname && chname[0]=='!') {
  1574. chan = findchan_by_dname(chname);
  1575. if (!chan) {
  1576. chan = findchan(chname);
  1577. if (!chan)
  1578. return 0; /* Ignore it */
  1579. /* We have the channel unique name, so we have attempted to join
  1580. * a specific !channel that doesnt exist. Now attempt to join the
  1581. * channel using it's short name.
  1582. */
  1583. putlog(LOG_MISC, "*",
  1584. "Unique channel %s does not exist... Attempting to join with "
  1585. "short name.", chname);
  1586. dprintf(DP_SERVER, "JOIN %s\n", chan->dname);
  1587. } else {
  1588. /* We have found the channel, so the server has given us the short
  1589. * name. Prefix another '!' to it, and attempt the join again...
  1590. */
  1591. putlog(LOG_MISC, "*",
  1592. "Channel %s does not exist... Attempting to create it.", chname);
  1593. dprintf(DP_SERVER, "JOIN !%s\n", chan->dname);
  1594. }
  1595. }
  1596. return 0;
  1597. }
  1598. /* got 471: can't join channel, full
  1599. */
  1600. static int got471(char *from, char *msg)
  1601. {
  1602. char *chname = NULL;
  1603. struct chanset_t *chan = NULL;
  1604. newsplit(&msg);
  1605. chname = newsplit(&msg);
  1606. /* !channel short names (also referred to as 'description names'
  1607. * can be received by skipping over the unique ID.
  1608. */
  1609. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  1610. chname += CHANNEL_ID_LEN;
  1611. chname[0] = '!';
  1612. }
  1613. /* We use dname because name is first set on JOIN and we might not
  1614. * have joined the channel yet.
  1615. */
  1616. chan = findchan_by_dname(chname);
  1617. if (chan) {
  1618. putlog(LOG_JOIN, chan->dname, IRC_CHANFULL, chan->dname);
  1619. request_in(chan);
  1620. /* need: limit */
  1621. chan = findchan_by_dname(chname);
  1622. if (!chan)
  1623. return 0;
  1624. } else
  1625. putlog(LOG_JOIN, chname, IRC_CHANFULL, chname);
  1626. return 0;
  1627. }
  1628. /* got 473: can't join channel, invite only
  1629. */
  1630. static int got473(char *from, char *msg)
  1631. {
  1632. char *chname = NULL;
  1633. struct chanset_t *chan = NULL;
  1634. newsplit(&msg);
  1635. chname = newsplit(&msg);
  1636. /* !channel short names (also referred to as 'description names'
  1637. * can be received by skipping over the unique ID.
  1638. */
  1639. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  1640. chname += CHANNEL_ID_LEN;
  1641. chname[0] = '!';
  1642. }
  1643. /* We use dname because name is first set on JOIN and we might not
  1644. * have joined the channel yet.
  1645. */
  1646. chan = findchan_by_dname(chname);
  1647. if (chan) {
  1648. putlog(LOG_JOIN, chan->dname, IRC_CHANINVITEONLY, chan->dname);
  1649. request_in(chan);
  1650. /* need: invite */
  1651. chan = findchan_by_dname(chname);
  1652. if (!chan)
  1653. return 0;
  1654. } else
  1655. putlog(LOG_JOIN, chname, IRC_CHANINVITEONLY, chname);
  1656. return 0;
  1657. }
  1658. /* got 474: can't join channel, banned
  1659. */
  1660. static int got474(char *from, char *msg)
  1661. {
  1662. char *chname = NULL;
  1663. struct chanset_t *chan = NULL;
  1664. newsplit(&msg);
  1665. chname = newsplit(&msg);
  1666. /* !channel short names (also referred to as 'description names'
  1667. * can be received by skipping over the unique ID.
  1668. */
  1669. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  1670. chname += CHANNEL_ID_LEN;
  1671. chname[0] = '!';
  1672. }
  1673. /* We use dname because name is first set on JOIN and we might not
  1674. * have joined the channel yet.
  1675. */
  1676. chan = findchan_by_dname(chname);
  1677. if (chan) {
  1678. putlog(LOG_JOIN, chan->dname, IRC_BANNEDFROMCHAN, chan->dname);
  1679. request_in(chan);
  1680. /* need: unban */
  1681. chan = findchan_by_dname(chname);
  1682. if (!chan)
  1683. return 0;
  1684. } else
  1685. putlog(LOG_JOIN, chname, IRC_BANNEDFROMCHAN, chname);
  1686. return 0;
  1687. }
  1688. /* got 475: can't goin channel, bad key
  1689. */
  1690. static int got475(char *from, char *msg)
  1691. {
  1692. char *chname = NULL;
  1693. struct chanset_t *chan = NULL;
  1694. newsplit(&msg);
  1695. chname = newsplit(&msg);
  1696. /* !channel short names (also referred to as 'description names'
  1697. * can be received by skipping over the unique ID.
  1698. */
  1699. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  1700. chname += CHANNEL_ID_LEN;
  1701. chname[0] = '!';
  1702. }
  1703. /* We use dname because name is first set on JOIN and we might not
  1704. * have joined the channel yet.
  1705. */
  1706. chan = findchan_by_dname(chname);
  1707. if (chan) {
  1708. putlog(LOG_JOIN, chan->dname, IRC_BADCHANKEY, chan->dname);
  1709. if (chan->channel.key[0]) {
  1710. free(chan->channel.key);
  1711. chan->channel.key = (char *) calloc(1, 1);
  1712. dprintf(DP_MODE, "JOIN %s %s\n", chan->dname, chan->key_prot);
  1713. } else {
  1714. request_in(chan);
  1715. /* need: key */
  1716. chan = findchan_by_dname(chname);
  1717. if (!chan)
  1718. return 0;
  1719. }
  1720. } else
  1721. putlog(LOG_JOIN, chname, IRC_BADCHANKEY, chname);
  1722. return 0;
  1723. }
  1724. /* got invitation
  1725. */
  1726. static int gotinvite(char *from, char *msg)
  1727. {
  1728. char *nick = NULL;
  1729. struct chanset_t *chan = NULL;
  1730. newsplit(&msg);
  1731. fixcolon(msg);
  1732. nick = splitnick(&from);
  1733. if (!rfc_casecmp(last_invchan, msg))
  1734. if (now - last_invtime < 30)
  1735. return 0; /* Two invites to the same channel in 30 seconds? */
  1736. putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg);
  1737. strncpy(last_invchan, msg, 299);
  1738. last_invchan[299] = 0;
  1739. last_invtime = now;
  1740. chan = findchan(msg);
  1741. if (!chan)
  1742. /* Might be a short-name */
  1743. chan = findchan_by_dname(msg);
  1744. if (chan && (channel_pending(chan) || channel_active(chan)))
  1745. dprintf(DP_HELP, "NOTICE %s :I'm already here.\n", nick);
  1746. else if (chan && shouldjoin(chan))
  1747. dprintf(DP_MODE, "JOIN %s %s\n", (chan->name[0]) ? chan->name : chan->dname,
  1748. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  1749. return 0;
  1750. }
  1751. /* Set the topic.
  1752. */
  1753. static void set_topic(struct chanset_t *chan, char *k)
  1754. {
  1755. if (chan->channel.topic)
  1756. free(chan->channel.topic);
  1757. if (k && k[0]) {
  1758. chan->channel.topic = (char *) calloc(1, strlen(k) + 1);
  1759. strcpy(chan->channel.topic, k);
  1760. } else
  1761. chan->channel.topic = NULL;
  1762. }
  1763. /* Topic change.
  1764. */
  1765. static int gottopic(char *from, char *msg)
  1766. {
  1767. char *nick = NULL, *chname = NULL;
  1768. memberlist *m = NULL;
  1769. struct chanset_t *chan = NULL;
  1770. struct userrec *u = NULL;
  1771. chname = newsplit(&msg);
  1772. fixcolon(msg);
  1773. u = get_user_by_host(from);
  1774. nick = splitnick(&from);
  1775. chan = findchan(chname);
  1776. if (chan) {
  1777. putlog(LOG_JOIN, chan->dname, "Topic changed on %s by %s!%s: %s",
  1778. chan->dname, nick, from, msg);
  1779. m = ismember(chan, nick);
  1780. if (m != NULL)
  1781. m->last = now;
  1782. set_topic(chan, msg);
  1783. }
  1784. return 0;
  1785. }
  1786. /* 331: no current topic for this channel
  1787. * <server> 331 <to> <chname> :etc
  1788. */
  1789. static int got331(char *from, char *msg)
  1790. {
  1791. char *chname = NULL;
  1792. struct chanset_t *chan = NULL;
  1793. newsplit(&msg);
  1794. chname = newsplit(&msg);
  1795. chan = findchan(chname);
  1796. if (chan) {
  1797. set_topic(chan, NULL);
  1798. }
  1799. return 0;
  1800. }
  1801. /* 332: topic on a channel i've just joined
  1802. * <server> 332 <to> <chname> :topic goes here
  1803. */
  1804. static int got332(char *from, char *msg)
  1805. {
  1806. struct chanset_t *chan = NULL;
  1807. char *chname = NULL;
  1808. newsplit(&msg);
  1809. chname = newsplit(&msg);
  1810. chan = findchan(chname);
  1811. if (chan) {
  1812. fixcolon(msg);
  1813. set_topic(chan, msg);
  1814. }
  1815. return 0;
  1816. }
  1817. /* Got a join
  1818. */
  1819. static int gotjoin(char *from, char *chname)
  1820. {
  1821. char *nick = NULL, *p = NULL, buf[UHOSTLEN] = "", *uhost = buf;
  1822. char *ch_dname = NULL;
  1823. struct chanset_t *chan = NULL;
  1824. memberlist *m = NULL;
  1825. masklist *b = NULL;
  1826. struct userrec *u = NULL;
  1827. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  1828. fixcolon(chname);
  1829. chan = findchan(chname);
  1830. if (!chan && chname[0] == '!') {
  1831. /* As this is a !channel, we need to search for it by display (short)
  1832. * name now. This will happen when we initially join the channel, as we
  1833. * dont know the unique channel name that the server has made up. <cybah>
  1834. */
  1835. int l_chname = strlen(chname);
  1836. if (l_chname > (CHANNEL_ID_LEN + 1)) {
  1837. ch_dname = malloc(l_chname + 1);
  1838. if (ch_dname) {
  1839. egg_snprintf(ch_dname, l_chname + 2, "!%s",
  1840. chname + (CHANNEL_ID_LEN + 1));
  1841. chan = findchan_by_dname(ch_dname);
  1842. if (!chan) {
  1843. /* Hmm.. okay. Maybe the admin's a genius and doesn't know the
  1844. * difference between id and descriptive channel names. Search
  1845. * the channel name in the dname list using the id-name.
  1846. */
  1847. chan = findchan_by_dname(chname);
  1848. if (chan) {
  1849. /* Duh, I was right. Mark this channel as inactive and log
  1850. * the incident.
  1851. */
  1852. chan->status |= CHAN_INACTIVE;
  1853. putlog(LOG_MISC, "*", "Deactivated channel %s, because it uses "
  1854. "an ID channel-name. Use the descriptive name instead.",
  1855. chname);
  1856. dprintf(DP_SERVER, "PART %s\n", chname);
  1857. goto exit;
  1858. }
  1859. }
  1860. }
  1861. }
  1862. } else if (!chan) {
  1863. /* As this is not a !chan, we need to search for it by display name now.
  1864. * Unlike !chan's, we dont need to remove the unique part.
  1865. */
  1866. chan = findchan_by_dname(chname);
  1867. }
  1868. if (!chan || (chan && !shouldjoin(chan))) {
  1869. strcpy(uhost, from);
  1870. nick = splitnick(&uhost);
  1871. if (match_my_nick(nick)) {
  1872. putlog(LOG_MISC, "*", "joined %s but didn't want to!", chname);
  1873. dprintf(DP_MODE, "PART %s\n", chname);
  1874. }
  1875. } else if (!channel_pending(chan)) {
  1876. chan->status &= ~CHAN_STOP_CYCLE;
  1877. strcpy(uhost, from);
  1878. nick = splitnick(&uhost);
  1879. detect_chan_flood(nick, uhost, from, chan, FLOOD_JOIN, NULL);
  1880. chan = findchan(chname);
  1881. if (!chan) {
  1882. if (ch_dname)
  1883. chan = findchan_by_dname(ch_dname);
  1884. else
  1885. chan = findchan_by_dname(chname);
  1886. }
  1887. if (!chan)
  1888. /* The channel doesn't exist anymore, so get out of here. */
  1889. goto exit;
  1890. /* Grab last time joined before we update it */
  1891. u = get_user_by_host(from);
  1892. get_user_flagrec(u, &fr, chan->dname); /* Lam: fix to work with !channels */
  1893. if (!channel_active(chan) && !match_my_nick(nick)) {
  1894. /* uh, what?! i'm on the channel?! */
  1895. putlog(LOG_MISC, chan->dname,
  1896. "confused bot: guess I'm on %s and didn't realize it",
  1897. chan->dname);
  1898. chan->status |= CHAN_ACTIVE;
  1899. chan->status &= ~CHAN_PEND;
  1900. reset_chan_info(chan);
  1901. } else {
  1902. m = ismember(chan, nick);
  1903. if (m && m->split && !egg_strcasecmp(m->userhost, uhost)) {
  1904. chan = findchan(chname);
  1905. if (!chan) {
  1906. if (ch_dname)
  1907. chan = findchan_by_dname(ch_dname);
  1908. else
  1909. chan = findchan_by_dname(chname);
  1910. }
  1911. if (!chan)
  1912. /* The channel doesn't exist anymore, so get out of here. */
  1913. goto exit;
  1914. /* The tcl binding might have deleted the current user. Recheck. */
  1915. u = get_user_by_host(from);
  1916. m->split = 0;
  1917. m->last = now;
  1918. m->delay = 0L;
  1919. m->flags = (chan_hasop(m) ? WASOP : 0);
  1920. m->user = u;
  1921. set_handle_laston(chan->dname, u, now);
  1922. m->flags |= STOPWHO;
  1923. putlog(LOG_JOIN, chan->dname, "%s (%s) returned to %s.", nick, uhost,
  1924. chan->dname);
  1925. } else {
  1926. if (m)
  1927. killmember(chan, nick);
  1928. m = newmember(chan, nick);
  1929. m->joined = now;
  1930. m->split = 0L;
  1931. m->flags = 0;
  1932. m->last = now;
  1933. m->delay = 0L;
  1934. strcpy(m->nick, nick);
  1935. strcpy(m->userhost, uhost);
  1936. m->user = u;
  1937. m->flags |= STOPWHO;
  1938. /* The tcl binding might have deleted the current user and the
  1939. * current channel, so we'll now have to re-check whether they
  1940. * both still exist.
  1941. */
  1942. chan = findchan(chname);
  1943. if (!chan) {
  1944. if (ch_dname)
  1945. chan = findchan_by_dname(ch_dname);
  1946. else
  1947. chan = findchan_by_dname(chname);
  1948. }
  1949. if (!chan)
  1950. /* The channel doesn't exist anymore, so get out of here. */
  1951. goto exit;
  1952. /* The record saved in the channel record always gets updated,
  1953. so we can use that. */
  1954. u = m->user;
  1955. if (match_my_nick(nick)) {
  1956. /* It was me joining! Need to update the channel record with the
  1957. * unique name for the channel (as the server see's it). <cybah>
  1958. */
  1959. strncpy(chan->name, chname, 81);
  1960. chan->name[80] = 0;
  1961. chan->status &= ~CHAN_JUPED;
  1962. /* ... and log us joining. Using chan->dname for the channel is
  1963. * important in this case. As the config file will never contain
  1964. * logs with the unique name.
  1965. */
  1966. if (chname[0] == '!')
  1967. putlog(LOG_JOIN, chan->dname, "%s joined %s (%s)", nick, chan->dname, chname);
  1968. else
  1969. putlog(LOG_JOIN, chan->dname, "%s joined %s.", nick,
  1970. chname);
  1971. if (!match_my_nick(chname))
  1972. reset_chan_info(chan);
  1973. } else {
  1974. putlog(LOG_JOIN, chan->dname,
  1975. "%s (%s) joined %s.", nick, uhost, chan->dname);
  1976. /* Don't re-display greeting if they've been on the channel
  1977. * recently.
  1978. */
  1979. set_handle_laston(chan->dname, u, now);
  1980. }
  1981. }
  1982. /* ok, the op-on-join,etc, tests...first only both if Im opped */
  1983. if (me_op(chan)) {
  1984. /* Check for and reset exempts and invites.
  1985. *
  1986. * This will require further checking to account for when to use the
  1987. * various modes.
  1988. */
  1989. if (u_match_mask(global_invites,from) ||
  1990. u_match_mask(chan->invites, from))
  1991. refresh_invite(chan, from);
  1992. if (!(use_exempts &&
  1993. (u_match_mask(global_exempts,from) ||
  1994. u_match_mask(chan->exempts, from)))) {
  1995. if (channel_enforcebans(chan) && !chan_op(fr) && !glob_op(fr) && !chan_sentkick(m) &&
  1996. !(use_exempts && (isexempted(chan, from) || (chan->ircnet_status & CHAN_ASKED_EXEMPTS))) &&
  1997. me_op(chan)) {
  1998. for (b = chan->channel.ban; b->mask[0]; b = b->next) {
  1999. if (wild_match(b->mask, from)) {
  2000. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chname, m->nick, bankickprefix, kickreason(KICK_BANNED));
  2001. m->flags |= SENTKICK;
  2002. goto exit;
  2003. }
  2004. }
  2005. }
  2006. /* If it matches a ban, dispose of them. */
  2007. if (u_match_mask(global_bans, from) ||
  2008. u_match_mask(chan->bans, from)) {
  2009. refresh_ban_kick(chan, from, nick);
  2010. /* Likewise for kick'ees */
  2011. } else if (!chan_sentkick(m) && (glob_kick(fr) || chan_kick(fr)) &&
  2012. me_op(chan)) {
  2013. check_exemptlist(chan, from);
  2014. quickban(chan, from);
  2015. p = get_user(&USERENTRY_COMMENT, m->user);
  2016. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chname, nick, bankickprefix, kickreason(KICK_KUSER));
  2017. m->flags |= SENTKICK;
  2018. }
  2019. }
  2020. if (!chan_hasop(m) && chk_autoop(fr, chan)) {
  2021. do_op(m->nick, chan, 1, 0);
  2022. }
  2023. }
  2024. }
  2025. }
  2026. exit:
  2027. if (ch_dname)
  2028. free(ch_dname);
  2029. return 0;
  2030. }
  2031. /* Got a part
  2032. */
  2033. static int gotpart(char *from, char *msg)
  2034. {
  2035. char *nick = NULL, *chname = NULL;
  2036. struct chanset_t *chan = NULL;
  2037. struct userrec *u = NULL;
  2038. chname = newsplit(&msg);
  2039. fixcolon(chname);
  2040. fixcolon(msg);
  2041. chan = findchan(chname);
  2042. if (chan && !shouldjoin(chan)) {
  2043. /* shouldnt this check for match_my_nick? */
  2044. clear_channel(chan, 1);
  2045. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
  2046. return 0;
  2047. }
  2048. if (chan && !channel_pending(chan)) {
  2049. u = get_user_by_host(from);
  2050. nick = splitnick(&from);
  2051. if (!channel_active(chan)) {
  2052. /* whoa! */
  2053. putlog(LOG_MISC, chan->dname,
  2054. "confused bot: guess I'm on %s and didn't realize it", chan->dname);
  2055. chan->status |= CHAN_ACTIVE;
  2056. chan->status &= ~CHAN_PEND;
  2057. reset_chan_info(chan);
  2058. }
  2059. set_handle_laston(chan->dname, u, now);
  2060. chan = findchan(chname);
  2061. if (!chan)
  2062. return 0;
  2063. killmember(chan, nick);
  2064. if (msg[0])
  2065. putlog(LOG_JOIN, chan->dname, "%s (%s) left %s (%s).", nick, from, chan->dname, msg);
  2066. else
  2067. putlog(LOG_JOIN, chan->dname, "%s (%s) left %s.", nick, from, chan->dname);
  2068. /* If it was me, all hell breaks loose... */
  2069. if (match_my_nick(nick)) {
  2070. clear_channel(chan, 1);
  2071. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
  2072. if (shouldjoin(chan))
  2073. dprintf(DP_MODE, "JOIN %s %s\n",
  2074. (chan->name[0]) ? chan->name : chan->dname,
  2075. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  2076. } else
  2077. check_lonely_channel(chan);
  2078. }
  2079. return 0;
  2080. }
  2081. /* Got a kick
  2082. */
  2083. static int gotkick(char *from, char *origmsg)
  2084. {
  2085. char *nick = NULL, *whodid = NULL, *chname = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
  2086. char buf2[511] = "", *msg = NULL;
  2087. memberlist *m = NULL;
  2088. struct chanset_t *chan = NULL;
  2089. struct userrec *u = NULL;
  2090. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  2091. strncpy(buf2, origmsg, 510);
  2092. buf2[510] = 0;
  2093. msg = buf2;
  2094. chname = newsplit(&msg);
  2095. chan = findchan(chname);
  2096. if (!chan)
  2097. return 0;
  2098. nick = newsplit(&msg);
  2099. if (match_my_nick(nick) && channel_pending(chan) && shouldjoin(chan)) {
  2100. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
  2101. dprintf(DP_MODE, "JOIN %s %s\n",
  2102. (chan->name[0]) ? chan->name : chan->dname,
  2103. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  2104. clear_channel(chan, 1);
  2105. return 0; /* rejoin if kicked before getting needed info <Wcc[08/08/02]> */
  2106. }
  2107. if (channel_active(chan)) {
  2108. #ifdef S_AUTOLOCK
  2109. chan->channel.fighting++;
  2110. #endif /* S_AUTOLOCK */
  2111. fixcolon(msg);
  2112. u = get_user_by_host(from);
  2113. strcpy(uhost, from);
  2114. whodid = splitnick(&uhost);
  2115. detect_chan_flood(whodid, uhost, from, chan, FLOOD_KICK, nick);
  2116. chan = findchan(chname);
  2117. if (!chan)
  2118. return 0;
  2119. m = ismember(chan, whodid);
  2120. if (m)
  2121. m->last = now;
  2122. /* This _needs_ to use chan->dname <cybah> */
  2123. get_user_flagrec(u, &fr, chan->dname);
  2124. set_handle_laston(chan->dname, u, now);
  2125. chan = findchan(chname);
  2126. if (!chan)
  2127. return 0;
  2128. if ((m = ismember(chan, nick))) {
  2129. struct userrec *u2;
  2130. simple_sprintf(s1, "%s!%s", m->nick, m->userhost);
  2131. u2 = get_user_by_host(s1);
  2132. set_handle_laston(chan->dname, u2, now);
  2133. maybe_revenge(chan, from, s1, REVENGE_KICK);
  2134. } else {
  2135. simple_sprintf(s1, "%s!*@could.not.loookup.hostname", nick);
  2136. }
  2137. putlog(LOG_MODES, chan->dname, "%s kicked from %s by %s: %s", s1,
  2138. chan->dname, from, msg);
  2139. /* Kicked ME?!? the sods! */
  2140. if (match_my_nick(nick) && shouldjoin(chan)) {
  2141. chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
  2142. dprintf(DP_MODE, "JOIN %s %s\n",
  2143. (chan->name[0]) ? chan->name : chan->dname,
  2144. chan->channel.key[0] ? chan->channel.key : chan->key_prot);
  2145. clear_channel(chan, 1);
  2146. } else {
  2147. killmember(chan, nick);
  2148. check_lonely_channel(chan);
  2149. }
  2150. }
  2151. return 0;
  2152. }
  2153. /* Got a nick change
  2154. */
  2155. static int gotnick(char *from, char *msg)
  2156. {
  2157. char *nick = NULL, *chname = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
  2158. memberlist *m = NULL, *mm = NULL;
  2159. struct chanset_t *chan = NULL, *oldchan = NULL;
  2160. struct userrec *u = NULL;
  2161. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  2162. strcpy(uhost, from);
  2163. nick = splitnick(&uhost);
  2164. fixcolon(msg);
  2165. clear_chanlist_member(nick); /* Cache for nick 'nick' is meaningless now. */
  2166. for (chan = chanset; chan; chan = chan->next) {
  2167. oldchan = chan;
  2168. chname = chan->dname;
  2169. m = ismember(chan, nick);
  2170. if (m) {
  2171. putlog(LOG_JOIN, chan->dname, "Nick change: %s -> %s", nick, msg);
  2172. m->last = now;
  2173. if (rfc_casecmp(nick, msg)) {
  2174. /* Not just a capitalization change */
  2175. mm = ismember(chan, msg);
  2176. if (mm) {
  2177. /* Someone on channel with old nick?! */
  2178. if (mm->split)
  2179. putlog(LOG_JOIN, chan->dname,
  2180. "Possible future nick collision: %s", mm->nick);
  2181. else
  2182. putlog(LOG_MISC, chan->dname,
  2183. "* Bug: nick change to existing nick");
  2184. killmember(chan, mm->nick);
  2185. }
  2186. }
  2187. /*
  2188. * Banned?
  2189. */
  2190. /* Compose a nick!user@host for the new nick */
  2191. sprintf(s1, "%s!%s", msg, uhost);
  2192. strcpy(m->nick, msg);
  2193. memberlist_reposition(chan, m);
  2194. detect_chan_flood(msg, uhost, from, chan, FLOOD_NICK, NULL);
  2195. if (!findchan_by_dname(chname)) {
  2196. chan = oldchan;
  2197. continue;
  2198. }
  2199. /* don't fill the serverqueue with modes or kicks in a nickflood */
  2200. if (chan_sentkick(m) || chan_sentdeop(m) || chan_sentop(m) ||
  2201. chan_sentdevoice(m) || chan_sentvoice(m))
  2202. m->flags |= STOPCHECK;
  2203. /* Any pending kick or mode to the old nick is lost. */
  2204. m->flags &= ~(SENTKICK | SENTDEOP | SENTOP |
  2205. SENTVOICE | SENTDEVOICE);
  2206. /* make sure they stay devoiced if EVOICE! */
  2207. /* nick-ban or nick is +k or something? */
  2208. if (!chan_stopcheck(m)) {
  2209. get_user_flagrec(m->user ? m->user : get_user_by_host(s1), &fr, chan->dname);
  2210. check_this_member(chan, m->nick, &fr);
  2211. }
  2212. u = get_user_by_host(from); /* make sure this is in the loop, someone could have changed the record
  2213. in an earlier iteration of the loop */
  2214. if (!findchan_by_dname(chname)) {
  2215. chan = oldchan;
  2216. continue;
  2217. }
  2218. }
  2219. }
  2220. return 0;
  2221. }
  2222. #ifdef S_SPLITHIJACK
  2223. void check_should_cycle(struct chanset_t *chan)
  2224. {
  2225. /*
  2226. If there are other ops split off and i'm the only op on this side of split, cycle
  2227. */
  2228. memberlist *ml = NULL;
  2229. int localops = 0, localbotops = 0, splitops = 0, splitbotops = 0, localnonops = 0;
  2230. if (!me_op(chan))
  2231. return;
  2232. for (ml = chan->channel.member; ml && ml->nick[0]; ml = ml->next) {
  2233. if (chan_hasop(ml)) {
  2234. if (chan_issplit(ml)) {
  2235. splitops++;
  2236. if ((ml->user) && (ml->user->flags & USER_BOT))
  2237. splitbotops++;
  2238. } else {
  2239. localops++;
  2240. if ((ml->user) && (ml->user->flags & USER_BOT))
  2241. localbotops++;
  2242. if (localbotops >= 2)
  2243. return;
  2244. if (localops > localbotops)
  2245. return;
  2246. }
  2247. } else {
  2248. if (!chan_issplit(ml))
  2249. localnonops++;
  2250. }
  2251. }
  2252. if (splitbotops > 5) {
  2253. /* I'm only one opped here... and other side has some ops... so i'm cycling */
  2254. if (localnonops) {
  2255. /* need to unset any +kil first */
  2256. dprintf(DP_MODE, "MODE %s -ilk %s\nPART %s\nJOIN %s\n", chan->name,
  2257. (chan->channel.key && chan->channel.key[0]) ? chan->channel.key : "",
  2258. chan->name, chan->name);
  2259. } else
  2260. dprintf(DP_MODE, "PART %s\nJOIN %s\n", chan->name, chan->name);
  2261. }
  2262. }
  2263. #endif /* S_SPLITHIJACK */
  2264. /* Signoff, similar to part.
  2265. */
  2266. static int gotquit(char *from, char *msg)
  2267. {
  2268. char *nick = NULL, *chname = NULL, *p = NULL;
  2269. int split = 0;
  2270. char from2[NICKMAX + UHOSTMAX + 1] = "";
  2271. memberlist *m = NULL;
  2272. struct chanset_t *chan = NULL, *oldchan = NULL;
  2273. struct userrec *u = NULL;
  2274. strcpy(from2,from);
  2275. u = get_user_by_host(from2);
  2276. nick = splitnick(&from);
  2277. fixcolon(msg);
  2278. /* Fred1: Instead of expensive wild_match on signoff, quicker method.
  2279. * Determine if signoff string matches "%.% %.%", and only one
  2280. * space.
  2281. */
  2282. p = strchr(msg, ' ');
  2283. if (p && (p == strrchr(msg, ' '))) {
  2284. char *z1, *z2;
  2285. *p = 0;
  2286. z1 = strchr(p + 1, '.');
  2287. z2 = strchr(msg, '.');
  2288. if (z1 && z2 && (*(z1 + 1) != 0) && (z1 - 1 != p) &&
  2289. (z2 + 1 != p) && (z2 != msg)) {
  2290. /* Server split, or else it looked like it anyway (no harm in
  2291. * assuming)
  2292. */
  2293. split = 1;
  2294. } else
  2295. *p = ' ';
  2296. }
  2297. for (chan = chanset; chan; chan = chan->next) {
  2298. oldchan = chan;
  2299. chname = chan->dname;
  2300. m = ismember(chan, nick);
  2301. if (m) {
  2302. u = get_user_by_host(from2);
  2303. if (u) {
  2304. set_handle_laston(chan->dname, u, now); /* If you remove this, the bot will crash when the user record in question
  2305. is removed/modified during the tcl binds below, and the users was on more
  2306. than one monitored channel */
  2307. }
  2308. if (split) {
  2309. m->split = now;
  2310. if (!findchan_by_dname(chname)) {
  2311. chan = oldchan;
  2312. continue;
  2313. }
  2314. putlog(LOG_JOIN, chan->dname, "%s (%s) got netsplit.", nick,
  2315. from);
  2316. } else {
  2317. if (!findchan_by_dname(chname)) {
  2318. chan = oldchan;
  2319. continue;
  2320. }
  2321. putlog(LOG_JOIN, chan->dname, "%s (%s) left irc: %s", nick,
  2322. from, msg);
  2323. killmember(chan, nick);
  2324. check_lonely_channel(chan);
  2325. }
  2326. #ifdef S_SPLITHIJACK
  2327. if (channel_cycle(chan))
  2328. check_should_cycle(chan);
  2329. #endif /* S_SPLITHIJACK */
  2330. }
  2331. }
  2332. /* Our nick quit? if so, grab it.
  2333. */
  2334. if (keepnick) {
  2335. if (!rfc_casecmp(nick, origbotname)) {
  2336. putlog(LOG_MISC, "*", IRC_GETORIGNICK, origbotname);
  2337. dprintf(DP_SERVER, "NICK %s\n", origbotname);
  2338. }
  2339. }
  2340. return 0;
  2341. }
  2342. /* Got a private message.
  2343. */
  2344. static int gotmsg(char *from, char *msg)
  2345. {
  2346. char *to = NULL, *realto = NULL, buf[UHOSTLEN] = "", *nick = NULL, buf2[512] = "", *uhost = buf;
  2347. char *p = NULL, *p1 = NULL, *code = NULL, *ctcp = NULL;
  2348. int ctcp_count = 0;
  2349. struct chanset_t *chan = NULL;
  2350. int ignoring;
  2351. struct userrec *u = NULL;
  2352. memberlist *m = NULL;
  2353. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  2354. if (!strchr("&#!+@$", msg[0]))
  2355. return 0;
  2356. ignoring = match_ignore(from);
  2357. to = newsplit(&msg);
  2358. realto = (to[0] == '@') ? to + 1 : to;
  2359. chan = findchan(realto);
  2360. if (!chan)
  2361. return 0; /* Private msg to an unknown channel?? */
  2362. fixcolon(msg);
  2363. strcpy(uhost, from);
  2364. nick = splitnick(&uhost);
  2365. /* Only check if flood-ctcp is active */
  2366. detect_autokick(nick, uhost, chan, msg);
  2367. if (flud_ctcp_thr && detect_avalanche(msg)) {
  2368. u = get_user_by_host(from);
  2369. get_user_flagrec(u, &fr, chan->dname);
  2370. m = ismember(chan, nick);
  2371. /* Discard -- kick user if it was to the channel */
  2372. if (m && me_op(chan) &&
  2373. !chan_sentkick(m) &&
  2374. !(use_exempts && ban_fun &&
  2375. /* don't kickban if permanent exempted -- Eule */
  2376. (u_match_mask(global_exempts, from) ||
  2377. u_match_mask(chan->exempts, from)))) {
  2378. if (ban_fun) {
  2379. check_exemptlist(chan, from);
  2380. u_addmask('b', chan, quickban(chan, uhost), conf.bot->nick,
  2381. IRC_FUNKICK, now + (60 * chan->ban_time), 0);
  2382. }
  2383. if (kick_fun) {
  2384. /* This can induce kickflood - arthur2 */
  2385. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, nick,
  2386. kickprefix, IRC_FUNKICK);
  2387. m->flags |= SENTKICK;
  2388. }
  2389. }
  2390. if (!ignoring) {
  2391. putlog(LOG_MODES, "*", "Avalanche from %s!%s in %s - ignoring",
  2392. nick, uhost, chan->dname);
  2393. p = strchr(uhost, '@');
  2394. if (p)
  2395. p++;
  2396. else
  2397. p = uhost;
  2398. simple_sprintf(buf2, "*!*@%s", p);
  2399. addignore(buf2, conf.bot->nick, "ctcp avalanche", now + (60 * ignore_time));
  2400. }
  2401. return 0;
  2402. }
  2403. /* Check for CTCP: */
  2404. ctcp_reply[0] = 0;
  2405. p = strchr(msg, 1);
  2406. while (p && *p) {
  2407. p++;
  2408. p1 = p;
  2409. while ((*p != 1) && *p)
  2410. p++;
  2411. if (*p == 1) {
  2412. *p = 0;
  2413. ctcp = buf2;
  2414. strcpy(ctcp, p1);
  2415. strcpy(p1 - 1, p + 1);
  2416. detect_chan_flood(nick, uhost, from, chan,
  2417. strncmp(ctcp, "ACTION ", 7) ?
  2418. FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
  2419. chan = findchan(realto);
  2420. if (!chan)
  2421. return 0;
  2422. /* Respond to the first answer_ctcp */
  2423. p = strchr(msg, 1);
  2424. if (ctcp_count < answer_ctcp) {
  2425. ctcp_count++;
  2426. if (ctcp[0] != ' ') {
  2427. code = newsplit(&ctcp);
  2428. u = get_user_by_host(from);
  2429. if (!ignoring || trigger_on_ignore) {
  2430. if (check_bind_ctcp(nick, uhost, u, to, code, ctcp) == BIND_RET_LOG) {
  2431. chan = findchan(realto);
  2432. if (!chan)
  2433. return 0;
  2434. update_idle(chan->dname, nick);
  2435. }
  2436. if (!ignoring) {
  2437. /* Log DCC, it's to a channel damnit! */
  2438. if (!strcmp(code, "ACTION")) {
  2439. putlog(LOG_PUBLIC, chan->dname, "Action: %s %s", nick, ctcp);
  2440. } else {
  2441. putlog(LOG_PUBLIC, chan->dname,
  2442. "CTCP %s: %s from %s (%s) to %s", code, ctcp, nick,
  2443. from, to);
  2444. }
  2445. }
  2446. }
  2447. }
  2448. }
  2449. }
  2450. }
  2451. /* Send out possible ctcp responses */
  2452. if (ctcp_reply[0]) {
  2453. if (ctcp_mode != 2) {
  2454. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  2455. } else {
  2456. if (now - last_ctcp > flud_ctcp_time) {
  2457. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  2458. count_ctcp = 1;
  2459. } else if (count_ctcp < flud_ctcp_thr) {
  2460. dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
  2461. count_ctcp++;
  2462. }
  2463. last_ctcp = now;
  2464. }
  2465. }
  2466. if (msg[0]) {
  2467. int dolog = 1, botmatch = 0;
  2468. #ifdef S_AUTHCMDS
  2469. int i = 0;
  2470. struct userrec *my_u = NULL;
  2471. char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
  2472. #endif /* S_AUTHCMDS */
  2473. /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
  2474. detect_chan_flood(nick, uhost, from, chan, FLOOD_PRIVMSG, NULL);
  2475. chan = findchan(realto);
  2476. if (!chan)
  2477. return 0;
  2478. #ifdef S_AUTHCMDS
  2479. my_msg = my_ptr = strdup(msg);
  2480. fword = newsplit(&my_msg); /* take out first word */
  2481. /* the first word is a wildcard match to our nick. */
  2482. botmatch = wild_match(fword, botname);
  2483. if (botmatch && strcmp(fword, "*"))
  2484. fword = newsplit(&my_msg); /* now this will be the command */
  2485. /* is it a cmd? */
  2486. if (fword[1] && ((botmatch && fword[0] != cmdprefix[0]) || (fword[0] == cmdprefix[0]))) {
  2487. i = findauth(uhost);
  2488. if (i > -1 && auth[i].authed) {
  2489. if (fword[0] == cmdprefix[0])
  2490. fword++;
  2491. my_u = auth[i].user;
  2492. if (check_bind_pubc(fword, nick, uhost, my_u, my_msg, chan->dname)) {
  2493. auth[i].atime = now;
  2494. dolog--; /* don't log */
  2495. }
  2496. }
  2497. }
  2498. free(my_ptr);
  2499. #endif /* S_AUTHCMDS */
  2500. if (dolog) {
  2501. if (!ignoring) {
  2502. if (to[0] == '@')
  2503. putlog(LOG_PUBLIC, chan->dname, "@<%s> %s", nick, msg);
  2504. else
  2505. putlog(LOG_PUBLIC, chan->dname, "<%s> %s", nick, msg);
  2506. }
  2507. }
  2508. update_idle(chan->dname, nick);
  2509. }
  2510. return 0;
  2511. }
  2512. /* Got a private notice.
  2513. */
  2514. static int gotnotice(char *from, char *msg)
  2515. {
  2516. char *to = NULL, *realto = NULL, *nick = NULL, buf2[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", *uhost = buf;
  2517. char *ctcp = NULL, *code = NULL;
  2518. struct userrec *u = NULL;
  2519. memberlist *m = NULL;
  2520. struct chanset_t *chan = NULL;
  2521. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0};
  2522. int ignoring;
  2523. if (!strchr(CHANMETA "@", *msg))
  2524. return 0;
  2525. ignoring = match_ignore(from);
  2526. to = newsplit(&msg);
  2527. realto = (*to == '@') ? to + 1 : to;
  2528. chan = findchan(realto);
  2529. if (!chan)
  2530. return 0; /* Notice to an unknown channel?? */
  2531. fixcolon(msg);
  2532. strcpy(uhost, from);
  2533. nick = splitnick(&uhost);
  2534. u = get_user_by_host(from);
  2535. if (flud_ctcp_thr && detect_avalanche(msg)) {
  2536. get_user_flagrec(u, &fr, chan->dname);
  2537. m = ismember(chan, nick);
  2538. /* Discard -- kick user if it was to the channel */
  2539. if (me_op(chan) && m && !chan_sentkick(m) &&
  2540. !(use_exempts && ban_fun &&
  2541. /* don't kickban if permanent exempted -- Eule */
  2542. (u_match_mask(global_exempts,from) ||
  2543. u_match_mask(chan->exempts, from)))) {
  2544. if (ban_fun) {
  2545. check_exemptlist(chan, from);
  2546. u_addmask('b', chan, quickban(chan, uhost), conf.bot->nick,
  2547. IRC_FUNKICK, now + (60 * chan->ban_time), 0);
  2548. }
  2549. if (kick_fun) {
  2550. /* This can induce kickflood - arthur2 */
  2551. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, nick,
  2552. kickprefix, IRC_FUNKICK);
  2553. m->flags |= SENTKICK;
  2554. }
  2555. }
  2556. if (!ignoring)
  2557. putlog(LOG_MODES, "*", "Avalanche from %s", from);
  2558. return 0;
  2559. }
  2560. /* Check for CTCP: */
  2561. p = strchr(msg, 1);
  2562. while (p && *p) {
  2563. p++;
  2564. p1 = p;
  2565. while ((*p != 1) && *p)
  2566. p++;
  2567. if (*p == 1) {
  2568. *p = 0;
  2569. ctcp = buf2;
  2570. strcpy(ctcp, p1);
  2571. strcpy(p1 - 1, p + 1);
  2572. p = strchr(msg, 1);
  2573. detect_chan_flood(nick, uhost, from, chan,
  2574. strncmp(ctcp, "ACTION ", 7) ?
  2575. FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
  2576. chan = findchan(realto);
  2577. if (!chan)
  2578. return 0;
  2579. if (ctcp[0] != ' ') {
  2580. code = newsplit(&ctcp);
  2581. if (!ignoring || trigger_on_ignore) {
  2582. check_bind_ctcr(nick, uhost, u, chan->dname, code, msg);
  2583. chan = findchan(realto);
  2584. if (!chan)
  2585. return 0;
  2586. if (!ignoring) {
  2587. putlog(LOG_PUBLIC, chan->dname, "CTCP reply %s: %s from %s (%s) to %s",
  2588. code, msg, nick, from, chan->dname);
  2589. update_idle(chan->dname, nick);
  2590. }
  2591. }
  2592. }
  2593. }
  2594. }
  2595. if (msg[0]) {
  2596. /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
  2597. detect_chan_flood(nick, uhost, from, chan, FLOOD_NOTICE, NULL);
  2598. chan = findchan(realto);
  2599. if (!chan)
  2600. return 0;
  2601. if (!ignoring || trigger_on_ignore) {
  2602. chan = findchan(realto);
  2603. if (!chan)
  2604. return 0;
  2605. }
  2606. if (!ignoring)
  2607. putlog(LOG_PUBLIC, chan->dname, "-%s:%s- %s", nick, to, msg);
  2608. update_idle(chan->dname, nick);
  2609. }
  2610. return 0;
  2611. }
  2612. static cmd_t irc_raw[] =
  2613. {
  2614. {"324", "", (Function) got324, "irc:324"},
  2615. {"352", "", (Function) got352, "irc:352"},
  2616. {"354", "", (Function) got354, "irc:354"},
  2617. {"315", "", (Function) got315, "irc:315"},
  2618. {"367", "", (Function) got367, "irc:367"},
  2619. {"368", "", (Function) got368, "irc:368"},
  2620. {"403", "", (Function) got403, "irc:403"},
  2621. {"405", "", (Function) got405, "irc:405"},
  2622. {"471", "", (Function) got471, "irc:471"},
  2623. {"473", "", (Function) got473, "irc:473"},
  2624. {"474", "", (Function) got474, "irc:474"},
  2625. {"475", "", (Function) got475, "irc:475"},
  2626. {"INVITE", "", (Function) gotinvite, "irc:invite"},
  2627. {"TOPIC", "", (Function) gottopic, "irc:topic"},
  2628. {"331", "", (Function) got331, "irc:331"},
  2629. {"332", "", (Function) got332, "irc:332"},
  2630. {"JOIN", "", (Function) gotjoin, "irc:join"},
  2631. {"PART", "", (Function) gotpart, "irc:part"},
  2632. {"KICK", "", (Function) gotkick, "irc:kick"},
  2633. {"NICK", "", (Function) gotnick, "irc:nick"},
  2634. {"QUIT", "", (Function) gotquit, "irc:quit"},
  2635. {"PRIVMSG", "", (Function) gotmsg, "irc:msg"},
  2636. {"NOTICE", "", (Function) gotnotice, "irc:notice"},
  2637. {"MODE", "", (Function) gotmode, "irc:mode"},
  2638. {"346", "", (Function) got346, "irc:346"},
  2639. {"347", "", (Function) got347, "irc:347"},
  2640. {"348", "", (Function) got348, "irc:348"},
  2641. {"349", "", (Function) got349, "irc:349"},
  2642. {NULL, NULL, NULL, NULL}
  2643. };
  2644. #endif /* LEAF */