chan.c 82 KB

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