chan.cc 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504
  1. /*
  2. * Copyright (C) 1997 Robey Pointer
  3. * Copyright (C) 1999 - 2002 Eggheads Development Team
  4. * Copyright (C) 2002 - 2014 Bryan Drewery
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. /*
  21. *
  22. * chan.c -- part of irc.mod
  23. * almost everything to do with channel manipulation
  24. * telling channel status
  25. * 'who' response
  26. * user kickban, kick, op, deop
  27. * idle kicking
  28. *
  29. */
  30. #include <bdlib/src/String.h>
  31. #include <bdlib/src/Array.h>
  32. static time_t last_ctcp = (time_t) 0L;
  33. static int count_ctcp = 0;
  34. static time_t last_invtime = (time_t) 0L;
  35. static char last_invchan[300] = "";
  36. typedef struct resolvstruct {
  37. char *chan;
  38. char *host;
  39. bd::String* servers;
  40. bd::String* server;
  41. } resolv_member;
  42. static void resolv_member_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
  43. {
  44. resolv_member *r = (resolv_member *) client_data;
  45. struct chanset_t* chan = NULL;
  46. if (!r || !r->chan || !r->host || !ips.size() || !(chan = findchan_by_dname(r->chan))) {
  47. if (r) {
  48. if (r->chan) free(r->chan);
  49. if (r->host) free(r->host);
  50. free(r);
  51. }
  52. return;
  53. }
  54. memberlist *m = NULL;
  55. char *pe = NULL, user[15] = "";
  56. bool matched_user = 0;
  57. /* Apply lookup results to all matching members by host */
  58. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  59. if (!m->userip[0] && m->userhost[0]) {
  60. pe = strchr(m->userhost, '@');
  61. if (pe && !strcmp(pe + 1, r->host)) {
  62. strlcpy(user, m->userhost, pe - m->userhost + 1);
  63. simple_snprintf(m->userip, sizeof(m->userip), "%s@%s", user, bd::String(ips[0]).c_str());
  64. simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
  65. if (!m->user) {
  66. m->user = get_user_by_host(m->fromip);
  67. /* Act on this lookup */
  68. if (m->user)
  69. check_this_user(m->user->handle, 0, NULL);
  70. }
  71. if (m->user)
  72. matched_user = 1;
  73. }
  74. }
  75. }
  76. if (!matched_user && channel_rbl(chan))
  77. resolve_to_rbl(chan, bd::String(ips[0]).c_str());
  78. free(r->host);
  79. free(r->chan);
  80. free(r);
  81. return;
  82. }
  83. void resolve_to_member(struct chanset_t *chan, char *nick, char *host)
  84. {
  85. resolv_member *r = (resolv_member *) calloc(1, sizeof(resolv_member));
  86. r->chan = strdup(chan->dname);
  87. r->host = strdup(host);
  88. if (egg_dns_lookup(host, 20, resolv_member_callback, (void *) r) == -2) { //Already querying?
  89. // Querying on clones will cause the callback to not be called and this nick will be ignored
  90. // cleanup memory as this chain is not even starting.
  91. free(r->host);
  92. free(r->chan);
  93. free(r);
  94. }
  95. }
  96. /* RBL */
  97. static void resolve_rbl_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
  98. {
  99. resolv_member *r = (resolv_member *) client_data;
  100. struct chanset_t* chan = NULL;
  101. if (!r || !r->chan || !r->host || !(chan = findchan_by_dname(r->chan)) || !ips.size()) {
  102. if (r && chan && r->host) {
  103. // Lookup from the next RBL
  104. resolve_to_rbl(chan, r->host, r);
  105. }
  106. return;
  107. }
  108. sdprintf("RBL match for %s:%s: %s", chan->dname, r->host, bd::String(ips[0]).c_str());
  109. char s1[UHOSTLEN] = "";
  110. simple_snprintf(s1, sizeof(s1), "*!*@%s", r->host);
  111. bd::String reason = "Listed in RBL: " + *(r->server);
  112. u_addmask('b', chan, s1, conf.bot->nick, reason.c_str(), now + (60 * (chan->ban_time ? chan->ban_time : 300)), 0);
  113. if (me_op(chan)) {
  114. do_mask(chan, chan->channel.ban, s1, 'b');
  115. memberlist *m = NULL;
  116. char *pe = NULL;
  117. /* Apply lookup results to all matching members by host */
  118. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  119. if (!m->user && !chan_sentkick(m) && m->userip[0]) {
  120. pe = strchr(m->userip, '@');
  121. if (pe && !strcmp(pe + 1, r->host)) {
  122. m->flags |= SENTKICK;
  123. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, reason.c_str());
  124. }
  125. }
  126. }
  127. }
  128. sdprintf("Done checking rbl (matched) for %s:%s", chan->dname, r->host);
  129. delete r->servers;
  130. delete r->server;
  131. free(r->host);
  132. free(r->chan);
  133. free(r);
  134. return;
  135. }
  136. void resolve_to_rbl(struct chanset_t *chan, const char *host, resolv_member *r)
  137. {
  138. // Skip past user@ if present
  139. char *p = strchr((char*)host, '@');
  140. if (p)
  141. host = p + 1;
  142. if (!r) {
  143. r = (resolv_member *) calloc(1, sizeof(resolv_member));
  144. r->chan = strdup(chan->dname);
  145. r->host = strdup(host);
  146. r->servers = new bd::String(rbl_servers);
  147. r->server = new bd::String;
  148. }
  149. bd::String rbl_server = newsplit(*(r->servers), ',');
  150. if (!rbl_server) {
  151. sdprintf("Done checking rbl (no match) for %s:%s", chan->dname, host);
  152. delete r->servers;
  153. delete r->server;
  154. free(r->host);
  155. free(r->chan);
  156. free(r);
  157. return; //No more servers
  158. }
  159. *(r->server) = rbl_server;
  160. size_t iplen = rbl_server.length() + 1;
  161. bool v6 = 0;
  162. if (strchr(host, ':')) {
  163. v6 = 1;
  164. iplen += 128 + 1;
  165. } else
  166. iplen += strlen(host) + 1;
  167. char *ip = (char *) calloc(1, iplen);
  168. if (v6)
  169. socket_ipv6_to_dots(host, ip);
  170. else {
  171. reverse_ip(host, ip);
  172. strlcat(ip, ".", iplen);
  173. }
  174. strlcat(ip, rbl_server.c_str(), iplen);
  175. if (egg_dns_lookup(ip, 20, resolve_rbl_callback, (void *) r, DNS_A) == -2) { //Already querying?
  176. // Querying on clones will cause the callback to not be called and this nick will be ignored
  177. // cleanup memory as this chain is not even starting.
  178. delete r->servers;
  179. delete r->server;
  180. free(r->host);
  181. free(r->chan);
  182. free(r);
  183. }
  184. free(ip);
  185. }
  186. // Just got a part event (KICK, PART) on me
  187. static void check_rejoin(struct chanset_t* chan) {
  188. if (shouldjoin(chan))
  189. force_join_chan(chan);
  190. else // Out of chan, not rejoining, just clear it
  191. clear_channel(chan, 1);
  192. }
  193. /* ID length for !channels.
  194. */
  195. #define CHANNEL_ID_LEN 5
  196. #ifdef NO
  197. static void print_memberlist(memberlist *toprint)
  198. {
  199. memberlist *m = NULL;
  200. for (m = toprint; m && m->nick[0]; m = m->next) {
  201. sdprintf("%s!%s user: %s tried: %d hops: %d", m->nick, m->userhost, m->user ? m->user->handle : "", m->tried_getuser, m->hops);
  202. }
  203. }
  204. #endif
  205. /* Returns a pointer to a new channel member structure.
  206. */
  207. static memberlist *newmember(struct chanset_t *chan, char *nick)
  208. {
  209. memberlist *x = chan->channel.member,
  210. *lx = NULL,
  211. *n = (memberlist *) calloc(1, sizeof(memberlist));
  212. /* This sorts the list */
  213. while (x && x->nick[0] && (rfc_casecmp(x->nick, nick) < 0)) {
  214. lx = x;
  215. x = x->next;
  216. }
  217. /*
  218. * redundant as calloc is used
  219. n->next = NULL;
  220. n->split = 0L;
  221. n->last = 0L;
  222. n->delay = 0L;
  223. */
  224. strlcpy(n->nick, nick, sizeof(n->nick));
  225. n->hops = -1;
  226. if (!lx) {
  227. // Free the pseudo-member created in init_channel()
  228. if (unlikely(!chan->channel.member->nick[0])) {
  229. free(chan->channel.member);
  230. chan->channel.member = NULL;
  231. }
  232. n->next = chan->channel.member;
  233. chan->channel.member = n;
  234. } else {
  235. n->next = lx->next;
  236. lx->next = n;
  237. }
  238. ++(chan->channel.members);
  239. n->floodtime = new bd::HashTable<flood_t, time_t>;
  240. n->floodnum = new bd::HashTable<flood_t, int>;
  241. return n;
  242. }
  243. void delete_member(memberlist* m) {
  244. delete m->floodtime;
  245. delete m->floodnum;
  246. free(m);
  247. }
  248. static bool member_getuser(memberlist* m, bool act_on_lookup) {
  249. if (!m) return 0;
  250. if (!m->user && !m->tried_getuser) {
  251. m->user = get_user_by_host(m->from);
  252. if (!m->user && m->userip[0]) {
  253. m->user = get_user_by_host(m->fromip);
  254. }
  255. m->tried_getuser = 1;
  256. /* Managed to get the user for a previously unknown user. Act on it! */
  257. if (act_on_lookup && m->user)
  258. check_this_user(m->user->handle, 0, NULL);
  259. }
  260. return !(m->user == NULL);
  261. }
  262. /* Always pass the channel dname (display name) to this function <cybah>
  263. */
  264. static void update_idle(char *chname, char *nick)
  265. {
  266. struct chanset_t *chan = findchan_by_dname(chname);
  267. if (chan) {
  268. memberlist *m = ismember(chan, nick);
  269. if (m)
  270. m->last = now;
  271. }
  272. }
  273. /* Returns the current channel mode.
  274. */
  275. static char *getchanmode(struct chanset_t *chan)
  276. {
  277. static char s[121] = "";
  278. int atr = chan->channel.mode;
  279. size_t i = 1;
  280. s[0] = '+';
  281. if (atr & CHANINV)
  282. s[i++] = 'i';
  283. if (atr & CHANPRIV)
  284. s[i++] = 'p';
  285. if (atr & CHANSEC)
  286. s[i++] = 's';
  287. if (atr & CHANMODER)
  288. s[i++] = 'm';
  289. if (atr & CHANNOCLR)
  290. s[i++] = 'c';
  291. if (atr & CHANNOCTCP)
  292. s[i++] = 'C';
  293. if (atr & CHANREGON)
  294. s[i++] = 'R';
  295. if (atr & CHANTOPIC)
  296. s[i++] = 't';
  297. if (atr & CHANMODR)
  298. s[i++] = 'M';
  299. if (atr & CHANLONLY)
  300. s[i++] = 'r';
  301. if (atr & CHANNOMSG)
  302. s[i++] = 'n';
  303. if (atr & CHANANON)
  304. s[i++] = 'a';
  305. if (atr & CHANKEY)
  306. s[i++] = 'k';
  307. if (chan->channel.maxmembers != 0)
  308. s[i++] = 'l';
  309. s[i] = 0;
  310. if (chan->channel.key[0])
  311. i += simple_snprintf(s + i, sizeof(s) - i, " %s", chan->channel.key);
  312. if (chan->channel.maxmembers != 0)
  313. simple_snprintf(s + i, sizeof(s) - i, " %d", chan->channel.maxmembers);
  314. return s;
  315. }
  316. static void check_exemptlist(struct chanset_t *chan, const char *from)
  317. {
  318. if (!use_exempts)
  319. return;
  320. bool ok = 0;
  321. for (masklist *e = chan->channel.exempt; e->mask[0]; e = e->next)
  322. if (wild_match(e->mask, from)) {
  323. add_mode(chan, '-', 'e', e->mask);
  324. ok = 1;
  325. }
  326. if (prevent_mixing && ok)
  327. flush_mode(chan, QUICK);
  328. }
  329. static void priority_do(struct chanset_t * chan, bool opsonly, int action, bool flush = 1)
  330. {
  331. if (!me_op(chan))
  332. return;
  333. if (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan))
  334. return;
  335. memberlist *m = NULL;
  336. int ops = 0, targets = 0, bpos = 0, tpos = 0, ft = 0, ct = 0, actions = 0, sent = 0;
  337. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  338. member_getuser(m);
  339. if (m->user && m->user->bot && (m->user->flags & USER_OP)) {
  340. ++ops;
  341. if (m->is_me)
  342. bpos = (ops - 1);
  343. } else if (!opsonly || chan_hasop(m)) {
  344. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  345. if (m->user)
  346. get_user_flagrec(m->user, &fr, chan->dname, chan);
  347. if (!chk_op(fr, chan))
  348. ++targets;
  349. }
  350. }
  351. if (!targets || !ops)
  352. return;
  353. for (int n = 0; n < 2; ++n) {
  354. // First pass - Handle my priority targets
  355. if (n == 0) {
  356. ft = (bpos * targets) / ops;
  357. ct = ((bpos + 2) * targets + (ops - 1)) / ops;
  358. ct = (ct - ft + 1);
  359. if (ct > 20)
  360. ct = 20;
  361. while (ft >= targets)
  362. ft -= targets;
  363. actions = 0;
  364. sent = 0;
  365. } else {
  366. // Second pass - Handle all remaining if I am able to
  367. ct = ct - actions;
  368. if (ct > ft)
  369. ct = ft;
  370. ft = 0;
  371. actions = 0;
  372. tpos = 0;
  373. }
  374. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  375. if (!opsonly || chan_hasop(m)) {
  376. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  377. if (m->user)
  378. get_user_flagrec(m->user, &fr, chan->dname, chan);
  379. if (!chk_op(fr, chan)) {
  380. if (tpos >= ft) {
  381. if ((action == PRIO_DEOP) && !chan_sentdeop(m)) {
  382. ++actions;
  383. ++sent;
  384. add_mode(chan, '-', 'o', m);
  385. if (!floodless && (actions >= ct || (n == 1 && sent > 20))) {
  386. if (flush)
  387. flush_mode(chan, QUICK);
  388. return;
  389. }
  390. } else if ((action == PRIO_KICK) && !chan_sentkick(m) &&
  391. // Check closed-exempt
  392. !((chan_hasop(m) && chan->closed_exempt_mode == CHAN_FLAG_OP) ||
  393. ((chan_hasvoice(m) || chan_hasop(m)) && chan->closed_exempt_mode == CHAN_FLAG_VOICE))) {
  394. ++actions;
  395. ++sent;
  396. if (chan->closed_ban)
  397. do_closed_kick(chan, m);
  398. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_CLOSED));
  399. m->flags |= SENTKICK;
  400. if (!floodless && (actions >= ct || (n == 1 && sent > 5)))
  401. return;
  402. }
  403. }
  404. ++tpos;
  405. }
  406. }
  407. }
  408. }
  409. }
  410. /* lame code
  411. static int target_priority(struct chanset_t * chan, memberlist *target, int opsonly)
  412. {
  413. memberlist *m;
  414. int ops = 0, targets = 0, bpos = 0, ft = 0, ct = 0, tp = (-1), pos = 0;
  415. return 1;
  416. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  417. if (m->user && ((m->user->flags & (USER_BOT | USER_OP)) == (USER_BOT | USER_OP))) {
  418. ops++;
  419. if (m->is_me)
  420. bpos = ops;
  421. } else if (!opsonly || chan_hasop(m)) {
  422. struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  423. if (m->user)
  424. get_user_flagrec(m->user, &fr, chan->dname);
  425. if (((glob_deop(fr) && !chan_op(fr)) || chan_deop(fr)) ||
  426. ((!channel_privchan(chan) && !chan_op(fr) && !glob_op(fr)) ||
  427. (channel_privchan(chan) && !glob_bot(fr) && !glob_owner(fr) && !chan_op(fr)))) {
  428. targets++;
  429. }
  430. }
  431. if (m == target)
  432. tp = pos;
  433. pos++;
  434. }
  435. if (!targets || !ops || (tp < 0)) {
  436. return 0;
  437. }
  438. ft = (bpos * targets) / ops;
  439. ct = ((bpos + 2) * targets + (ops - 1)) / ops;
  440. ct = (ct - ft + 1);
  441. if (ct > 20)
  442. ct = 20;
  443. while (ft >= targets) {
  444. ft -= targets;
  445. }
  446. if (ct >= targets) {
  447. putlog(LOG_MISC, "*", "%s 1 ct >= targets; ct %d targets %d", target, ct, targets);
  448. if ((tp >= ft) || (tp <= (ct % targets))) {
  449. putlog(LOG_MISC, "*", "%s (1) first if, tp %d ft %d ct/targets %d", target, tp, ft, (ct % targets));
  450. return 1;
  451. }
  452. } else {
  453. putlog(LOG_MISC, "*", "%s 2 else, ct %d targets %d", target, ct, targets);
  454. if ((tp >= ft) && (tp <= ct)) {
  455. putlog(LOG_MISC, "*", "%s (1) second if, tp %d ft %d", target, tp, ft);
  456. return 1;
  457. }
  458. }
  459. putlog(LOG_MISC, "*", "%s (0) returning 0", target);
  460. return 0;
  461. }
  462. */
  463. /* Check a channel and clean-out any more-specific matching masks.
  464. *
  465. * Moved all do_ban(), do_exempt() and do_invite() into this single function
  466. * as the code bloat is starting to get rediculous <cybah>
  467. */
  468. static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char Mode)
  469. {
  470. for (; m && m->mask[0]; m = m->next)
  471. if (wild_match(mask, m->mask) && rfc_casecmp(mask, m->mask))
  472. add_mode(chan, '-', Mode, m->mask);
  473. add_mode(chan, '+', Mode, mask);
  474. flush_mode(chan, QUICK);
  475. }
  476. /* This is a clone of detect_flood, but works for channel specificity now
  477. * and handles kick & deop as well.
  478. */
  479. static bool detect_chan_flood(memberlist* m, const char *from, struct chanset_t *chan, flood_t which, const char *msg)
  480. {
  481. /* Do not punish non-existant channel members and IRC services like
  482. * ChanServ
  483. */
  484. if (!chan || (which < 0) || (which >= FLOOD_CHAN_MAX) || !m)
  485. return 0;
  486. /* Okay, make sure i'm not flood-checking myself */
  487. if (m->is_me) {
  488. return 0;
  489. }
  490. if (!strcasecmp(m->userhost, botuserhost))
  491. return 0;
  492. /* My user@host (?) */
  493. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  494. struct userrec *u = NULL;
  495. member_getuser(m);
  496. u = m->user;
  497. get_user_flagrec(u, &fr, chan->dname, chan);
  498. if (glob_bot(fr) ||
  499. ((which == FLOOD_DEOP) &&
  500. (glob_master(fr) || chan_master(fr))) ||
  501. ((which == FLOOD_KICK) &&
  502. (glob_master(fr) || chan_master(fr))) ||
  503. ((which != FLOOD_DEOP) && (which != FLOOD_KICK) &&
  504. ( (chk_noflood(fr) ||
  505. (m && chan->flood_exempt_mode == CHAN_FLAG_OP && chan_hasop(m)) ||
  506. (m && chan->flood_exempt_mode == CHAN_FLAG_VOICE && (chan_hasvoice(m) || chan_hasop(m))) )
  507. )))
  508. return 0;
  509. char h[UHOSTLEN] = "", ftype[14] = "", *p = NULL;
  510. int thr = 0, mthr = 0;
  511. int increment = 1;
  512. time_t lapse = 0, mlapse = 0;
  513. /* Determine how many are necessary to make a flood. */
  514. switch (which) {
  515. case FLOOD_PRIVMSG:
  516. case FLOOD_NOTICE:
  517. thr = chan->flood_pub_thr;
  518. lapse = chan->flood_pub_time;
  519. mthr = chan->flood_mpub_thr;
  520. mlapse = chan->flood_mpub_time;
  521. strlcpy(ftype, "pub", sizeof(ftype));
  522. break;
  523. case FLOOD_BYTES:
  524. thr = chan->flood_bytes_thr;
  525. lapse = chan->flood_bytes_time;
  526. mthr = chan->flood_mbytes_thr;
  527. mlapse = chan->flood_mbytes_time;
  528. strlcpy(ftype, "bytes", sizeof(ftype));
  529. increment = static_cast<int>(strlen(msg));
  530. break;
  531. case FLOOD_CTCP:
  532. thr = chan->flood_ctcp_thr;
  533. lapse = chan->flood_ctcp_time;
  534. mthr = chan->flood_mctcp_thr;
  535. mlapse = chan->flood_mctcp_time;
  536. strlcpy(ftype, "ctcp", sizeof(ftype));
  537. break;
  538. case FLOOD_NICK:
  539. thr = chan->flood_nick_thr;
  540. lapse = chan->flood_nick_time;
  541. strlcpy(ftype, "nick", sizeof(ftype));
  542. break;
  543. case FLOOD_JOIN:
  544. case FLOOD_PART:
  545. thr = chan->flood_join_thr;
  546. lapse = chan->flood_join_time;
  547. strlcpy(ftype, "join", sizeof(ftype));
  548. break;
  549. case FLOOD_DEOP:
  550. thr = chan->flood_deop_thr;
  551. lapse = chan->flood_deop_time;
  552. strlcpy(ftype, "deop", sizeof(ftype));
  553. break;
  554. case FLOOD_KICK:
  555. thr = chan->flood_kick_thr;
  556. lapse = chan->flood_kick_time;
  557. strlcpy(ftype, "kick", sizeof(ftype));
  558. break;
  559. }
  560. if ((which == FLOOD_KICK) || (which == FLOOD_DEOP))
  561. p = m->nick;
  562. else {
  563. p = strchr(m->userhost, '@');
  564. if (p) {
  565. p++;
  566. }
  567. if (!p)
  568. return 0;
  569. }
  570. // Track across all clients in the channel
  571. if (mlapse && mthr) {
  572. if (!chan->channel.floodtime->contains("all")) {
  573. (*chan->channel.floodtime)["all"][which] = now;
  574. (*chan->channel.floodnum)["all"][which] = increment;
  575. return 0;
  576. }
  577. // No point locking down due to OPs flooding.
  578. if (!chan_hasop(m)) {
  579. bd::HashTable<flood_t, time_t> *global_floodtime = &(*chan->channel.floodtime)["all"];
  580. bd::HashTable<flood_t, int> *global_floodnum = &(*chan->channel.floodnum)["all"];
  581. if ((*global_floodtime)[which] < now - mlapse) {
  582. /* Flood timer expired, reset it */
  583. (*global_floodtime)[which] = now;
  584. (*global_floodnum)[which] = increment;
  585. } else {
  586. (*global_floodnum)[which] += increment;
  587. if ((*global_floodnum)[which] >= mthr) { /* FLOOD */
  588. /* Reset counters */
  589. (*global_floodnum).remove(which);
  590. (*global_floodtime).remove(which);
  591. if (!chan->channel.drone_set_mode) {
  592. lockdown_chan(chan, FLOOD_MASS_FLOOD, ftype);
  593. }
  594. }
  595. }
  596. }
  597. }
  598. if ((thr == 0) || (lapse == 0)) {
  599. return 0; /* no flood protection */
  600. }
  601. // Track individual hosts/clients
  602. bd::HashTable<flood_t, time_t> *floodtime; // floodtime[FLOOD_PRIVMSG] = now;
  603. bd::HashTable<flood_t, int> *floodnum; // floodnum[FLOOD_PRIVMSG] = 1;
  604. switch (which) {
  605. // These 2 don't have a persistent member, use chan list
  606. case FLOOD_JOIN:
  607. case FLOOD_PART:
  608. // If not found, add them and start the count for next iteration
  609. if (!chan->channel.floodtime->contains(m->userhost)) {
  610. (*chan->channel.floodtime)[m->userhost][which] = now;
  611. (*chan->channel.floodnum)[m->userhost][which] = increment;
  612. return 0;
  613. } else {
  614. floodtime = &(*chan->channel.floodtime)[m->userhost];
  615. floodnum = &(*chan->channel.floodnum)[m->userhost];
  616. }
  617. break;
  618. default:
  619. // Everything else, log to the member
  620. // If not found, add them and start the count for next iteration
  621. if (!m->floodtime->contains(which)) {
  622. (*m->floodtime)[which] = now;
  623. (*m->floodnum)[which] = increment;
  624. return 0;
  625. } else {
  626. floodtime = m->floodtime;
  627. floodnum = m->floodnum;
  628. }
  629. break;
  630. }
  631. if ((*floodtime)[which] < now - lapse) {
  632. /* Flood timer expired, reset it */
  633. (*floodtime)[which] = now;
  634. (*floodnum)[which] = increment;
  635. return 0;
  636. }
  637. (*floodnum)[which] += increment;
  638. if ((*floodnum)[which] >= thr) { /* FLOOD */
  639. /* Reset counters */
  640. (*floodnum).remove(which);
  641. (*floodtime).remove(which);
  642. switch (which) {
  643. case FLOOD_PRIVMSG:
  644. case FLOOD_NOTICE:
  645. case FLOOD_CTCP:
  646. case FLOOD_BYTES:
  647. /* Flooding chan! either by public or notice */
  648. if (!chan_sentkick(m) && me_op(chan)) {
  649. if (channel_floodban(chan)) {
  650. putlog(LOG_MODES, chan->dname, "Channel flood from %s -- banning", m->nick);
  651. char *s1 = quickban(chan, from);
  652. u_addmask('b', chan, s1, conf.bot->nick, "channel flood", now + (60 * chan->ban_time), 0);
  653. } else {
  654. const char *response = punish_flooder(chan, m);
  655. putlog(LOG_MODES, chan->dname, "Channel flood from %s -- %s", m->nick, response);
  656. }
  657. }
  658. return 1;
  659. case FLOOD_JOIN:
  660. case FLOOD_PART:
  661. case FLOOD_NICK:
  662. if (use_exempts &&
  663. (u_match_mask(global_exempts, from) ||
  664. u_match_mask(chan->exempts, from)))
  665. return 1;
  666. simple_snprintf(h, sizeof(h), "*!*@%s", p);
  667. if (!isbanned(chan, h) && me_op(chan)) {
  668. check_exemptlist(chan, from);
  669. do_mask(chan, chan->channel.ban, h, 'b');
  670. }
  671. if ((u_match_mask(global_bans, from))
  672. || (u_match_mask(chan->bans, from)))
  673. return 1; /* Already banned */
  674. if (which == FLOOD_JOIN || which == FLOOD_PART)
  675. putlog(LOG_MISC | LOG_JOIN, chan->dname, "JOIN flood from @%s! Banning.", p);
  676. else
  677. putlog(LOG_MISC | LOG_JOIN, chan->dname, "NICK flood from @%s! Banning.", p);
  678. strlcat(ftype, " flood", sizeof(ftype));
  679. u_addmask('b', chan, h, conf.bot->nick, ftype, now + (60 * chan->ban_time), 0);
  680. if (which == FLOOD_PART)
  681. add_mode(chan, '+', 'b', h);
  682. if (!channel_enforcebans(chan) && me_op(chan)) {
  683. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  684. if (!chan_sentkick(m) && wild_match(h, m->from) &&
  685. (m->joined >= (*floodtime)[which]) &&
  686. !m->is_me && me_op(chan)) {
  687. m->flags |= SENTKICK;
  688. if (which == FLOOD_JOIN)
  689. dprintf(DP_SERVER, "KICK %s %s :%sjoin flood\n", chan->name, m->nick, kickprefix);
  690. else
  691. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_NICKFLOOD));
  692. }
  693. }
  694. }
  695. return 1;
  696. case FLOOD_KICK:
  697. if (me_op(chan) && !chan_sentkick(m)) {
  698. putlog(LOG_MODES, chan->dname, "Kicking %s, for mass kick.", m->nick);
  699. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_KICKFLOOD));
  700. m->flags |= SENTKICK;
  701. }
  702. if (channel_protect(chan))
  703. do_protect(chan, "Mass Kick");
  704. return 1;
  705. case FLOOD_DEOP:
  706. if (me_op(chan) && !chan_sentkick(m)) {
  707. putlog(LOG_MODES, chan->dname,
  708. "Mass deop on %s by %s", chan->dname, from);
  709. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
  710. m->flags |= SENTKICK;
  711. }
  712. if (u) {
  713. char s[256] = "";
  714. simple_snprintf(s, sizeof(s), "Mass deop on %s by %s", chan->dname, from);
  715. deflag_user(u, DEFLAG_EVENT_MDOP, s, chan);
  716. }
  717. if (channel_protect(chan))
  718. do_protect(chan, "Mass Deop");
  719. return 1;
  720. }
  721. }
  722. return 0;
  723. }
  724. /* Given a chan/m do all necesary exempt checks and ban. */
  725. static void refresh_ban_kick(struct chanset_t*, memberlist *, const char *);
  726. static void do_closed_kick(struct chanset_t *chan, memberlist *m)
  727. {
  728. if (!chan || !m) return;
  729. char *s1 = NULL;
  730. if (!(use_exempts &&
  731. (u_match_mask(global_exempts, m->from) ||
  732. u_match_mask(chan->exempts, m->from)))) {
  733. if (u_match_mask(global_bans, m->from) || u_match_mask(chan->bans, m->from))
  734. refresh_ban_kick(chan, m, m->from);
  735. check_exemptlist(chan, m->from);
  736. s1 = quickban(chan, m->from);
  737. u_addmask('b', chan, s1, conf.bot->nick, "joined closed chan", now + (60 * chan->ban_time), 0);
  738. }
  739. return;
  740. }
  741. /* Given a nick!user@host, place a quick ban on them on a chan.
  742. */
  743. static char *quickban(struct chanset_t *chan, const char *from)
  744. {
  745. static char s1[512] = "";
  746. maskaddr(from, s1, chan->ban_type);
  747. do_mask(chan, chan->channel.ban, s1, 'b');
  748. return s1;
  749. }
  750. /* Kick any user (except friends/masters) with certain mask from channel
  751. * with a specified comment. Ernst 18/3/1998
  752. */
  753. static void kick_all(struct chanset_t *chan, char *hostmask, const char *comment, int bantype)
  754. {
  755. int flushed = 0;
  756. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  757. for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
  758. get_user_flagrec(m->user, &fr, chan->dname, chan);
  759. if ((wild_match(hostmask, m->from) || match_cidr(hostmask, m->from) ||
  760. (m->userip[0] && (wild_match(hostmask, m->fromip) || match_cidr(hostmask, m->fromip)))) &&
  761. !chan_sentkick(m) &&
  762. !m->is_me && !chan_issplit(m) &&
  763. !(use_exempts &&
  764. ((bantype && (isexempted(chan, m->from) || (chan->ircnet_status & CHAN_ASKED_EXEMPTS))) ||
  765. (u_match_mask(global_exempts, m->from) ||
  766. u_match_mask(chan->exempts, m->from) ||
  767. (m->userip[0] &&
  768. (u_match_mask(global_exempts, m->fromip) ||
  769. u_match_mask(chan->exempts, m->fromip))))))) {
  770. if (!flushed) {
  771. /* We need to kick someone, flush eventual bans first */
  772. flush_mode(chan, QUICK);
  773. flushed += 1;
  774. }
  775. if (!chan_sentkick(m)) {
  776. m->flags |= SENTKICK; /* Mark as pending kick */
  777. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, comment);
  778. }
  779. }
  780. }
  781. }
  782. /* If any bans match this wildcard expression, refresh them on the channel.
  783. */
  784. static void refresh_ban_kick(struct chanset_t* chan, memberlist *m, const char *user)
  785. {
  786. if (!m || chan_sentkick(m))
  787. return;
  788. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  789. get_user_flagrec(m->user, &fr, chan->dname, chan);
  790. /* Check global bans in first cycle and channel bans
  791. in second cycle. */
  792. for (int cycle = 0; cycle < 2; cycle++) {
  793. for (maskrec* b = cycle ? chan->bans : global_bans; b; b = b->next) {
  794. if (wild_match(b->mask, user) || match_cidr(b->mask, user)) {
  795. if (role == 1 && chan_hasop(m))
  796. add_mode(chan, '-', 'o', m); /* Guess it can't hurt. */
  797. check_exemptlist(chan, user);
  798. do_mask(chan, chan->channel.ban, b->mask, 'b');
  799. b->lastactive = now;
  800. if (role == 2) {
  801. char c[512] = ""; /* The ban comment. */
  802. if (b->desc && b->desc[0] != '@')
  803. simple_snprintf(c, sizeof(c), "banned: %s", b->desc);
  804. kick_all(chan, b->mask, c[0] ? (const char *) c : "You are banned", 0);
  805. }
  806. return; /* Drop out on 1st ban. */
  807. }
  808. }
  809. }
  810. }
  811. /* This is a bit cumbersome at the moment, but it works... Any improvements
  812. * then feel free to have a go.. Jason
  813. */
  814. static void refresh_exempt(struct chanset_t *chan, char *user)
  815. {
  816. maskrec *e = NULL;
  817. masklist *b = NULL;
  818. /* Check global exempts in first cycle and channel exempts
  819. in second cycle. */
  820. for (int cycle = 0; cycle < 2; cycle++) {
  821. for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
  822. if (wild_match(user, e->mask) || wild_match(e->mask, user) || match_cidr(e->mask, user)) {
  823. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  824. if (wild_match(b->mask, user) || wild_match(user, b->mask)) {
  825. if (e->lastactive < now - 60 && !isexempted(chan, e->mask)) {
  826. do_mask(chan, chan->channel.exempt, e->mask, 'e');
  827. e->lastactive = now;
  828. }
  829. }
  830. }
  831. }
  832. }
  833. }
  834. }
  835. static void refresh_invite(struct chanset_t *chan, const char *user)
  836. {
  837. maskrec *i = NULL;
  838. /* Check global invites in first cycle and channel invites
  839. in second cycle. */
  840. for (int cycle = 0; cycle < 2; cycle++) {
  841. for (i = cycle ? chan->invites : global_invites; i; i = i->next) {
  842. if (wild_match(i->mask, user) &&
  843. ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
  844. if (i->lastactive < now - 60 && !isinvited(chan, i->mask)) {
  845. do_mask(chan, chan->channel.invite, i->mask, 'I');
  846. i->lastactive = now;
  847. return;
  848. }
  849. }
  850. }
  851. }
  852. }
  853. /* Enforce all channel bans in a given channel. Ernst 18/3/1998
  854. */
  855. static void enforce_bans(struct chanset_t *chan)
  856. {
  857. if (!me_op(chan))
  858. return; /* Can't do it :( */
  859. if ((chan->ircnet_status & CHAN_ASKED_EXEMPTS))
  860. return;
  861. const memberlist *me = ismember(chan, botname);
  862. /* Go through all bans, kicking the users. */
  863. for (masklist *b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  864. if (!(wild_match(b->mask, me->from) || match_cidr(b->mask, me->fromip)) && !isexempted(chan, b->mask))
  865. kick_all(chan, b->mask, "You are banned", 1);
  866. }
  867. }
  868. /* Make sure that all who are 'banned' on the userlist are actually in fact
  869. * banned on the channel.
  870. *
  871. * Note: Since i was getting a ban list, i assume i'm chop.
  872. */
  873. static void recheck_bans(struct chanset_t *chan)
  874. {
  875. maskrec *u = NULL;
  876. /* Check global bans in first cycle and channel bans
  877. in second cycle. */
  878. for (int cycle = 0; cycle < 2; cycle++) {
  879. for (u = cycle ? chan->bans : global_bans; u; u = u->next)
  880. if (!isbanned(chan, u->mask) && (!channel_dynamicbans(chan) || (u->flags & MASKREC_STICKY)))
  881. add_mode(chan, '+', 'b', u->mask);
  882. }
  883. }
  884. /* Make sure that all who are exempted on the userlist are actually in fact
  885. * exempted on the channel.
  886. *
  887. * Note: Since i was getting an excempt list, i assume i'm chop.
  888. */
  889. static void recheck_exempts(struct chanset_t *chan)
  890. {
  891. maskrec *e = NULL;
  892. masklist *b = NULL;
  893. /* Check global exempts in first cycle and channel exempts
  894. in second cycle. */
  895. for (int cycle = 0; cycle < 2; cycle++) {
  896. for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
  897. if (!isexempted(chan, e->mask) &&
  898. (!channel_dynamicexempts(chan) || (e->flags & MASKREC_STICKY)))
  899. add_mode(chan, '+', 'e', e->mask);
  900. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  901. if ((wild_match(b->mask, e->mask) || wild_match(e->mask, b->mask)) &&
  902. !isexempted(chan, e->mask))
  903. add_mode(chan,'+','e',e->mask);
  904. /* do_mask(chan, chan->channel.exempt, e->mask, 'e');*/
  905. }
  906. }
  907. }
  908. }
  909. /* Make sure that all who are invited on the userlist are actually in fact
  910. * invited on the channel.
  911. *
  912. * Note: Since i was getting an invite list, i assume i'm chop.
  913. */
  914. static void recheck_invites(struct chanset_t *chan)
  915. {
  916. maskrec *ir = NULL;
  917. /* Check global invites in first cycle and channel invites
  918. in second cycle. */
  919. for (int cycle = 0; cycle < 2; cycle++) {
  920. for (ir = cycle ? chan->invites : global_invites; ir; ir = ir->next) {
  921. /* If invite isn't set and (channel is not dynamic invites and not invite
  922. * only) or invite is sticky.
  923. */
  924. if (!isinvited(chan, ir->mask) && ((!channel_dynamicinvites(chan) &&
  925. (chan->channel.mode & CHANINV)) || ir->flags & MASKREC_STICKY))
  926. add_mode(chan, '+', 'I', ir->mask);
  927. /* do_mask(chan, chan->channel.invite, ir->mask, 'I');*/
  928. }
  929. }
  930. }
  931. /* Resets the masks on the channel.
  932. */
  933. static void resetmasks(struct chanset_t *chan, masklist *m, maskrec *mrec, maskrec *global_masks, char mode)
  934. {
  935. if (!me_op(chan))
  936. return; /* Can't do it */
  937. /* Remove masks we didn't put there */
  938. for (; m && m->mask[0]; m = m->next) {
  939. if (!u_equals_mask(global_masks, m->mask) && !u_equals_mask(mrec, m->mask))
  940. add_mode(chan, '-', mode, m->mask);
  941. }
  942. /* Make sure the intended masks are still there */
  943. switch (mode) {
  944. case 'b':
  945. recheck_bans(chan);
  946. break;
  947. case 'e':
  948. recheck_exempts(chan);
  949. break;
  950. case 'I':
  951. recheck_invites(chan);
  952. break;
  953. default:
  954. putlog(LOG_MISC, "*", "(!) Invalid mode '%c' in resetmasks()", mode);
  955. break;
  956. }
  957. }
  958. void check_this_ban(struct chanset_t *chan, char *banmask, bool sticky)
  959. {
  960. if (!me_op(chan))
  961. return;
  962. const char *user = NULL;
  963. for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
  964. for (int i = 0; i < (m->userip[0] ? 2 : 1); ++i) {
  965. if (i == 0 && m->userip[0]) // Check userip first in case userhost is already an ip
  966. user = m->fromip;
  967. else
  968. user = m->from;
  969. if ((wild_match(banmask, user) || match_cidr(banmask, user)) &&
  970. !(use_exempts &&
  971. (u_match_mask(global_exempts, user) ||
  972. u_match_mask(chan->exempts, user)))) {
  973. refresh_ban_kick(chan, m, user);
  974. break;
  975. }
  976. }
  977. }
  978. if (!isbanned(chan, banmask) &&
  979. (!channel_dynamicbans(chan) || sticky))
  980. add_mode(chan, '+', 'b', banmask);
  981. }
  982. void check_this_exempt(struct chanset_t *chan, char *mask, bool sticky)
  983. {
  984. if (!isexempted(chan, mask) && (!channel_dynamicexempts(chan) || sticky))
  985. add_mode(chan, '+', 'e', mask);
  986. }
  987. void check_this_invite(struct chanset_t *chan, char *mask, bool sticky)
  988. {
  989. if (!isinvited(chan, mask) && (!channel_dynamicinvites(chan) || sticky))
  990. add_mode(chan, '+', 'I', mask);
  991. }
  992. void recheck_channel_modes(struct chanset_t *chan)
  993. {
  994. int cur = chan->channel.mode,
  995. mns = chan->mode_mns_prot,
  996. pls = chan->mode_pls_prot;
  997. if (channel_closed(chan)) {
  998. if (chan->closed_invite) {
  999. pls |= CHANINV;
  1000. mns &= ~CHANINV;
  1001. }
  1002. if (chan->closed_private) {
  1003. pls |= CHANPRIV;
  1004. mns &= ~CHANPRIV;
  1005. }
  1006. }
  1007. if (channel_voice(chan) && chan->voice_moderate) {
  1008. pls |= CHANMODER;
  1009. mns &= ~CHANMODER;
  1010. }
  1011. if (!(chan->ircnet_status & CHAN_ASKEDMODES)) {
  1012. if (pls & CHANINV && !(cur & CHANINV))
  1013. add_mode(chan, '+', 'i', "");
  1014. else if (mns & CHANINV && cur & CHANINV)
  1015. add_mode(chan, '-', 'i', "");
  1016. if (pls & CHANPRIV && !(cur & CHANPRIV))
  1017. add_mode(chan, '+', 'p', "");
  1018. else if (mns & CHANPRIV && cur & CHANPRIV)
  1019. add_mode(chan, '-', 'p', "");
  1020. if (pls & CHANSEC && !(cur & CHANSEC))
  1021. add_mode(chan, '+', 's', "");
  1022. else if (mns & CHANSEC && cur & CHANSEC)
  1023. add_mode(chan, '-', 's', "");
  1024. if (pls & CHANMODER && !(cur & CHANMODER))
  1025. add_mode(chan, '+', 'm', "");
  1026. else if (mns & CHANMODER && cur & CHANMODER)
  1027. add_mode(chan, '-', 'm', "");
  1028. if (pls & CHANNOCLR && !(cur & CHANNOCLR))
  1029. add_mode(chan, '+', 'c', "");
  1030. else if (mns & CHANNOCLR && cur & CHANNOCLR)
  1031. add_mode(chan, '-', 'c', "");
  1032. if (pls & CHANNOCTCP && !(cur & CHANNOCTCP))
  1033. add_mode(chan, '+', 'C', "");
  1034. else if (mns & CHANNOCTCP && cur & CHANNOCTCP)
  1035. add_mode(chan, '-', 'C', "");
  1036. if (pls & CHANREGON && !(cur & CHANREGON))
  1037. add_mode(chan, '+', 'R', "");
  1038. else if (mns & CHANREGON && cur & CHANREGON)
  1039. add_mode(chan, '-', 'R', "");
  1040. if (pls & CHANMODR && !(cur & CHANMODR))
  1041. add_mode(chan, '+', 'M', "");
  1042. else if (mns & CHANMODR && cur & CHANMODR)
  1043. add_mode(chan, '-', 'M', "");
  1044. if (pls & CHANLONLY && !(cur & CHANLONLY))
  1045. add_mode(chan, '+', 'r', "");
  1046. else if (mns & CHANLONLY && cur & CHANLONLY)
  1047. add_mode(chan, '-', 'r', "");
  1048. if (pls & CHANTOPIC && !(cur & CHANTOPIC))
  1049. add_mode(chan, '+', 't', "");
  1050. else if (mns & CHANTOPIC && cur & CHANTOPIC)
  1051. add_mode(chan, '-', 't', "");
  1052. if (pls & CHANNOMSG && !(cur & CHANNOMSG))
  1053. add_mode(chan, '+', 'n', "");
  1054. else if ((mns & CHANNOMSG) && (cur & CHANNOMSG))
  1055. add_mode(chan, '-', 'n', "");
  1056. if ((pls & CHANANON) && !(cur & CHANANON))
  1057. add_mode(chan, '+', 'a', "");
  1058. else if ((mns & CHANANON) && (cur & CHANANON))
  1059. add_mode(chan, '-', 'a', "");
  1060. if ((pls & CHANQUIET) && !(cur & CHANQUIET))
  1061. add_mode(chan, '+', 'q', "");
  1062. else if ((mns & CHANQUIET) && (cur & CHANQUIET))
  1063. add_mode(chan, '-', 'q', "");
  1064. if ((chan->limit_prot != 0) && (chan->channel.maxmembers == 0)) {
  1065. char s[11] = "";
  1066. simple_snprintf(s, sizeof(s), "%d", chan->limit_prot);
  1067. add_mode(chan, '+', 'l', s);
  1068. } else if ((mns & CHANLIMIT) && (chan->channel.maxmembers != 0))
  1069. add_mode(chan, '-', 'l', "");
  1070. if (chan->key_prot[0]) {
  1071. if (rfc_casecmp(chan->channel.key, chan->key_prot) != 0) {
  1072. if (chan->channel.key[0])
  1073. add_mode(chan, '-', 'k', chan->channel.key);
  1074. add_mode(chan, '+', 'k', chan->key_prot);
  1075. }
  1076. } else if ((mns & CHANKEY) && (chan->channel.key[0]))
  1077. add_mode(chan, '-', 'k', chan->channel.key);
  1078. }
  1079. }
  1080. static void check_this_member(struct chanset_t *chan, memberlist *m,
  1081. struct flag_record *fr)
  1082. {
  1083. if (!m || m->is_me || !me_op(chan))
  1084. return;
  1085. /* +d or bitch and not an op
  1086. * we dont check private because +private does not imply bitch. */
  1087. if (chan_hasop(m) &&
  1088. (chk_deop(*fr, chan) ||
  1089. (!loading && userlist && chan_bitch(chan) && !chk_op(*fr, chan)) ) ) {
  1090. /* if (target_priority(chan, m, 1)) */
  1091. add_mode(chan, '-', 'o', m);
  1092. } else if (!chan_hasop(m) && dovoice(chan) && chk_autoop(m, *fr, chan)) {
  1093. do_op(m, chan, 1, 0);
  1094. }
  1095. if (dovoice(chan)) {
  1096. if (chan_hasvoice(m) && !chan_hasop(m)) {
  1097. /* devoice +q users .. */
  1098. if (chk_devoice(*fr) || (channel_voicebitch(chan) && !chk_voice(*fr, chan)))
  1099. add_mode(chan, '-', 'v', m);
  1100. } else if (!chan_hasvoice(m) && !chan_hasop(m)) {
  1101. /* voice +v users */
  1102. if (chk_voice(*fr, chan)) {
  1103. add_mode(chan, '+', 'v', m);
  1104. if (m->flags & EVOICE)
  1105. m->flags &= ~EVOICE;
  1106. }
  1107. }
  1108. }
  1109. const char *s = NULL;
  1110. for (int i = 0; i < (m->userip[0] ? 2 : 1); ++i) {
  1111. if (i == 0 && m->userip[0]) // Check userip first in case userhost is already an ip
  1112. s = m->fromip;
  1113. else
  1114. s = m->from;
  1115. /* check vs invites */
  1116. if (use_invites &&
  1117. (u_match_mask(global_invites,s) ||
  1118. u_match_mask(chan->invites, s)))
  1119. refresh_invite(chan, s);
  1120. /* don't kickban if permanent exempted */
  1121. if (!(use_exempts &&
  1122. (u_match_mask(global_exempts, s) ||
  1123. u_match_mask(chan->exempts, s)))) {
  1124. /* Are they banned in the internal list? */
  1125. if (u_match_mask(global_bans, s) || u_match_mask(chan->bans, s))
  1126. refresh_ban_kick(chan, m, s);
  1127. /* are they +k ? */
  1128. if (!chan_sentkick(m) && (chan_kick(*fr) || glob_kick(*fr)) && me_op(chan)) {
  1129. char *p = (char *) get_user(&USERENTRY_COMMENT, m->user);
  1130. check_exemptlist(chan, s);
  1131. quickban(chan, s);
  1132. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, p ? p : response(RES_KICKBAN));
  1133. m->flags |= SENTKICK;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. //1 -user
  1139. //2 -host
  1140. void check_this_user(char *hand, int del, char *host)
  1141. {
  1142. memberlist *m = NULL;
  1143. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1144. for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
  1145. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1146. bool check_member = 0;
  1147. bool had_user = m->user ? 1 : 0;
  1148. m->tried_getuser = 0;
  1149. member_getuser(m);
  1150. struct userrec* u = m->user;
  1151. if (m->user && !had_user) // If a member is newly recognized, act on it
  1152. check_member = 1;
  1153. else if (del != 2 && m->user && !strcasecmp(m->user->handle, hand)) { //general check / -user, match specified user
  1154. check_member = 1;
  1155. if (del == 1)
  1156. u = NULL; // Pretend user doesn't exist when checking
  1157. } else if (0 && del == 2) { //-host, may now match on a diff user and need to act on them
  1158. /*
  1159. const char *s = NULL;
  1160. for (int i = 0; i < (m->userip[0] ? 2 : 1); ++i) {
  1161. if (i == 0 && m->userip[0]) // Check userip first in case userhost is already an ip
  1162. s = m->fromip;
  1163. else
  1164. s = m->from;
  1165. if (wild_match(host, s) ||
  1166. (i == 0 && m->userip[0] && match_cidr(host, s))) {
  1167. check_member = 1;
  1168. break;
  1169. }
  1170. }
  1171. */
  1172. if (m->user && !had_user)
  1173. check_member = 1;
  1174. }
  1175. if (check_member) {
  1176. get_user_flagrec(u, &fr, chan->dname, chan);
  1177. check_this_member(chan, m, &fr);
  1178. }
  1179. }
  1180. }
  1181. }
  1182. static void enforce_bitch(struct chanset_t *chan, bool flush = 1) {
  1183. if (!chan || !me_op(chan))
  1184. return;
  1185. priority_do(chan, 1, PRIO_DEOP, flush);
  1186. }
  1187. void enforce_closed(struct chanset_t *chan) {
  1188. if (!chan || !me_op(chan))
  1189. return;
  1190. char buf[3] = "", *p = buf;
  1191. if (chan->closed_invite && !(chan->channel.mode & CHANINV) && !(chan->mode_mns_prot & CHANINV))
  1192. *p++ = 'i';
  1193. if (chan->closed_private && !(chan->channel.mode & CHANPRIV) && !(chan->mode_mns_prot & CHANPRIV))
  1194. *p++ = 'p';
  1195. *p = 0;
  1196. if (buf[0])
  1197. dprintf(DP_MODE, "MODE %s +%s\n", chan->name, buf);
  1198. priority_do(chan, 0, PRIO_KICK);
  1199. }
  1200. inline static char *
  1201. take_massopline(char *op, char **to_op)
  1202. {
  1203. const size_t modes_len = 31, nicks_len = 151;
  1204. char *nicks = (char *) calloc(1, nicks_len),
  1205. *modes = (char *) calloc(1, modes_len),
  1206. *nick = NULL;
  1207. bool useop = 0;
  1208. static char ret[182] = "";
  1209. memset(ret, 0, sizeof(ret));
  1210. for (unsigned int i = 0; i < modesperline; i++) {
  1211. if (*to_op[0] || op) {
  1212. /* if 'op' then use it, then move on to to_op */
  1213. if (!useop && op) {
  1214. nick = op;
  1215. useop = 1;
  1216. } else if (*to_op[0])
  1217. nick = newsplit(to_op);
  1218. if (nick) {
  1219. strlcat(modes, "+o", modes_len);
  1220. strlcat(nicks, nick, nicks_len);
  1221. if (i != modesperline - 1)
  1222. strlcat(nicks, " ", nicks_len);
  1223. }
  1224. }
  1225. }
  1226. strlcat(ret, modes, sizeof(ret));
  1227. strlcat(ret, " ", sizeof(ret));
  1228. strlcat(ret, nicks, sizeof(ret));
  1229. free(modes);
  1230. free(nicks);
  1231. return ret;
  1232. }
  1233. inline static char *
  1234. take_makeline(char *op, char *deops, unsigned int deopn, size_t deops_len)
  1235. {
  1236. bool opn = op ? 1 : 0;
  1237. unsigned int n = opn + deopn; /* op + deops */
  1238. unsigned int pos = randint(deopn), i;
  1239. static char ret[151] = "";
  1240. memset(ret, 0, sizeof(ret));
  1241. for (i = 0; i < n; i++) {
  1242. if (opn && i == pos)
  1243. strlcat(ret, "+o", sizeof(ret));
  1244. else if (deopn)
  1245. strlcat(ret, "-o", sizeof(ret));
  1246. }
  1247. strlcat(ret, " ", sizeof(ret));
  1248. for (i = 0; i < n; i++) {
  1249. if (opn && i == pos)
  1250. strlcat(ret, op, sizeof(ret));
  1251. else if (deopn)
  1252. strlcat(ret, newsplit(&deops), sizeof(ret));
  1253. if (i != n - 1)
  1254. strlcat(ret, " ", sizeof(ret));
  1255. }
  1256. return ret;
  1257. }
  1258. static void
  1259. do_take(struct chanset_t *chan)
  1260. {
  1261. char to_deop[2048] = "", *to_deop_ptr = to_deop;
  1262. char to_op[2048] = "", *to_op_ptr = to_op;
  1263. size_t to_op_len = 0, to_deop_len = 0;
  1264. /* Make lists of who needs to be opped, and who needs to be deopped */
  1265. for (memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1266. if (!m->is_me) {
  1267. const bool isbot = m->user && m->user->bot ? 1 : 0;
  1268. /* Avoid countless unneeded operations from strcat/strlen */
  1269. if (isbot && !(m->flags & CHANOP)) {
  1270. to_op_len += strlcpy(to_op + to_op_len, m->nick, sizeof(to_op) - to_op_len);
  1271. *(to_op + to_op_len++) = ' ';
  1272. } else if (!isbot && (m->flags & CHANOP)) {
  1273. to_deop_len += strlcpy(to_deop + to_deop_len, m->nick, sizeof(to_deop) - to_deop_len);
  1274. *(to_deop + to_deop_len++) = ' ';
  1275. }
  1276. }
  1277. }
  1278. shuffle(to_op, " ", sizeof(to_op));
  1279. shuffle(to_deop, " ", sizeof(to_deop));
  1280. size_t deops_len = 0;
  1281. size_t work_len = 0;
  1282. short lines = 0;
  1283. const unsigned short max_lines = floodless ? 15 : default_alines;
  1284. char work[2048] = "", *op = NULL, *modeline = NULL, deops[2048] = "";
  1285. unsigned int deopn;
  1286. while (to_op_ptr[0] || to_deop_ptr[0]) {
  1287. deops_len = 0;
  1288. deopn = 0;
  1289. op = NULL;
  1290. modeline = NULL;
  1291. deops[0] = 0;
  1292. if (to_op_ptr[0])
  1293. op = newsplit(&to_op_ptr);
  1294. /* Prepare a list of modesperline-1 nicks for deop */
  1295. for (unsigned int i = 0; i < modesperline; i++) {
  1296. if (to_deop_ptr[0] && ((i < (modesperline - 1)) || (!op))) {
  1297. ++deopn;
  1298. const char *deop_nick = newsplit(&to_deop_ptr);
  1299. deops_len += strlcpy(deops + deops_len, deop_nick, sizeof(deops) - deops_len);
  1300. *(deops + deops_len++) = ' ';
  1301. }
  1302. }
  1303. deops[deops_len] = 0;
  1304. *(work + work_len++) = 'M';
  1305. *(work + work_len++) = 'O';
  1306. *(work + work_len++) = 'D';
  1307. *(work + work_len++) = 'E';
  1308. *(work + work_len++) = ' ';
  1309. work_len += strlcpy(work + work_len, chan->name, sizeof(work) - work_len);
  1310. *(work + work_len++) = ' ';
  1311. if (deops[0])
  1312. modeline = take_makeline(op, deops, deopn, deops_len);
  1313. else
  1314. modeline = take_massopline(op, &to_op_ptr);
  1315. work_len += strlcpy(work + work_len, modeline, sizeof(work) - work_len);
  1316. *(work + work_len++) = '\r';
  1317. *(work + work_len++) = '\n';
  1318. work[work_len] = 0;
  1319. // Prevent excess flood
  1320. if (++lines >= max_lines) {
  1321. tputs(serv, work, work_len);
  1322. work[0] = 0;
  1323. work_len = 0;
  1324. lines = 0;
  1325. }
  1326. }
  1327. if (work[0])
  1328. tputs(serv, work, work_len);
  1329. if (channel_closed(chan))
  1330. enforce_closed(chan);
  1331. enforce_bitch(chan); /* hell why not! */
  1332. return;
  1333. }
  1334. /* Things to do when i just became a chanop:
  1335. */
  1336. void recheck_channel(struct chanset_t *chan, int dobans)
  1337. {
  1338. static int stacking = 0;
  1339. if (stacking)
  1340. return; /* wewps */
  1341. if (!userlist || loading) /* Bot doesnt know anybody */
  1342. return; /* ... it's better not to deop everybody */
  1343. memberlist *m = NULL;
  1344. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1345. int stop_reset = 0, botops = 0, nonbotops = 0, botnonops = 0;
  1346. bool flush = 0;
  1347. ++stacking;
  1348. putlog(LOG_DEBUG, "*", "recheck_channel(%s, %d)", chan->dname, dobans);
  1349. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1350. bool hasop = chan_hasop(m);
  1351. if (m) {
  1352. if (m->user && m->user->bot && (m->user->flags & USER_OP)) {
  1353. if (hasop)
  1354. ++botops;
  1355. else
  1356. ++botnonops;
  1357. } else if (hasop)
  1358. ++nonbotops;
  1359. }
  1360. }
  1361. /* don't do much if i'm lonely bot. Maybe they won't notice me? :P */
  1362. if (unlikely(botops == 1 && !botnonops)) {
  1363. if (chan_bitch(chan) || channel_closed(chan))
  1364. putlog(LOG_MISC, "*", "Opped in %s, not checking +closed/+bitch until more bots arrive.", chan->dname);
  1365. } else {
  1366. /* if the chan is +closed, mass deop first, safer that way. */
  1367. if (chan_bitch(chan) || channel_closed(chan)) {
  1368. flush = 1;
  1369. enforce_bitch(chan, 0);
  1370. }
  1371. if (channel_closed(chan))
  1372. enforce_closed(chan);
  1373. }
  1374. /* this can all die, we want to enforce +bitch/+take first :) */
  1375. if (!channel_take(chan)) {
  1376. /* This is a bad hack for +e/+I */
  1377. if (dobans == 2 && chan->channel.members > 1) {
  1378. get_channel_masks(chan);
  1379. }
  1380. //Check +d/+O/+k
  1381. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1382. member_getuser(m);
  1383. get_user_flagrec(m->user, &fr, chan->dname, chan);
  1384. //Already a bot opped, dont bother resetting masks
  1385. if (glob_bot(fr) && chan_hasop(m) && !m->is_me)
  1386. stop_reset = 1;
  1387. check_this_member(chan, m, &fr);
  1388. }
  1389. //Only reset masks if the bot has already received the ban list before (meaning it has already been opped once)
  1390. //Ie, don't set bans without knowing what they are! (asked for above on first op)
  1391. if (dobans && (chan->ircnet_status & CHAN_HAVEBANS)) {
  1392. if (channel_nouserbans(chan) && !stop_reset)
  1393. resetbans(chan);
  1394. else
  1395. recheck_bans(chan);
  1396. if (use_invites && !(chan->ircnet_status & CHAN_ASKED_INVITES)) {
  1397. if (channel_nouserinvites(chan) && !stop_reset)
  1398. resetinvites(chan);
  1399. else
  1400. recheck_invites(chan);
  1401. }
  1402. if (use_exempts && !(chan->ircnet_status & CHAN_ASKED_EXEMPTS)) {
  1403. if (channel_nouserexempts(chan) && !stop_reset)
  1404. resetexempts(chan);
  1405. else
  1406. recheck_exempts(chan);
  1407. } else {
  1408. if (channel_enforcebans(chan))
  1409. enforce_bans(chan);
  1410. }
  1411. flush = 1;
  1412. }
  1413. // Do this here as the above only runs after already having been opped and having gotten bans.
  1414. if (dobans) {
  1415. if ((chan->ircnet_status & CHAN_ASKEDMODES) && !channel_inactive(chan))
  1416. dprintf(DP_MODE, "MODE %s\n", chan->name);
  1417. recheck_channel_modes(chan);
  1418. }
  1419. if (flush)
  1420. flush_mode(chan, QUICK);
  1421. }
  1422. --stacking;
  1423. }
  1424. static int got001(char *from, char *msg)
  1425. {
  1426. //Just connected, cleanup some vars
  1427. chained_who.clear();
  1428. return 0;
  1429. }
  1430. #ifdef CACHE
  1431. /* got 302: userhost
  1432. * <server> 302 <to> :<nick??user@host>
  1433. */
  1434. static int got302(char *from, char *msg)
  1435. {
  1436. char *p = NULL, *nick = NULL, *uhost = NULL;
  1437. cache_t *cache = NULL;
  1438. cache_chan_t *cchan = NULL;
  1439. newsplit(&msg);
  1440. fixcolon(msg);
  1441. p = strchr(msg, '=');
  1442. if (!p)
  1443. p = strchr(msg, '*');
  1444. if (!p)
  1445. return 0;
  1446. *p = 0;
  1447. nick = msg;
  1448. p += 2; /* skip =|* plus the next char */
  1449. uhost = p;
  1450. if ((p = strchr(uhost, ' ')))
  1451. *p = 0;
  1452. if ((cache = cache_find(nick))) {
  1453. if (!cache->uhost[0])
  1454. strlcpy(cache->uhost, uhost, sizeof(cache->uhost));
  1455. if (!cache->handle[0]) {
  1456. char s[UHOSTLEN] = "";
  1457. struct userrec *u = NULL;
  1458. simple_snprintf(s, sizeof(s), "%s!%s", nick, uhost);
  1459. if ((u = get_user_by_host(s)))
  1460. strlcpy(cache->handle, u->handle, sizeof(cache->handle));
  1461. }
  1462. cache->timeval = now;
  1463. /* check if we should invite this client to chans */
  1464. for (cchan = cache->cchan; cchan && cchan->dname[0]; cchan = cchan->next) {
  1465. if (cchan->invite) {
  1466. dprintf(DP_SERVER, "INVITE %s %s\n", nick, cchan->dname);
  1467. cchan->invite = 0;
  1468. cchan->invited = 1;
  1469. }
  1470. if (cchan->ban) {
  1471. cchan->ban = 0;
  1472. dprintf(DP_MODE_NEXT, "MODE %s +b *!%s\n", cchan->dname, uhost);
  1473. }
  1474. }
  1475. }
  1476. return 0;
  1477. }
  1478. #endif
  1479. #ifdef CACHE
  1480. /* got341 invited
  1481. * <server> 341 <to> <nick> <channel>
  1482. */
  1483. static int got341(char *from, char *msg)
  1484. {
  1485. char *nick = NULL, *chname = NULL;
  1486. cache_t *cache = NULL;
  1487. cache_chan_t *cchan = NULL;
  1488. newsplit(&msg);
  1489. nick = newsplit(&msg);
  1490. chname = newsplit(&msg);
  1491. struct chanset_t *chan = findchan(chname);
  1492. if (!chan) {
  1493. putlog(LOG_MISC, "*", "%s: %s", "Hmm, mode info from a channel I'm not on", chname);
  1494. dprintf(DP_SERVER, "PART %s\n", chname);
  1495. return 0;
  1496. }
  1497. cache = cache_find(nick);
  1498. if (cache) {
  1499. for (cchan = cache->cchan; cchan && cchan->dname; cchan = cchan->next) {
  1500. if (!rfc_casecmp(cchan->dname, chan->dname)) {
  1501. if (!cache->uhost[0] || !cchan->invited)
  1502. goto hijack;
  1503. cache->timeval = now;
  1504. notice_invite(chan, cache->handle[0] ? cache->handle : NULL, nick, cache->uhost, cchan->op);
  1505. // cache_del_chan_parm(cache, cache->cchan);
  1506. break;
  1507. }
  1508. }
  1509. }
  1510. if (!cache || !cchan)
  1511. goto hijack;
  1512. return 0;
  1513. hijack:
  1514. if (!cache)
  1515. cache = cache_new(nick);
  1516. if (!cchan)
  1517. cchan = cache_chan_add(cache, chan->dname);
  1518. if (!cache->uhost[0]) {
  1519. dprintf(DP_MODE_NEXT, "MODE %s +b %s!*@*\n", chan->name, nick);
  1520. cchan->ban = 1;
  1521. dprintf(DP_MODE_NEXT, "USERHOST %s\n", nick);
  1522. } else {
  1523. dprintf(DP_MODE_NEXT, "MODE %s +b *!*%s\n", chan->name, cache->uhost);
  1524. }
  1525. putlog(LOG_MISC, "*", "HIJACKED invite detected: %s to %s", nick, chan->dname);
  1526. bd::String msg;
  1527. msg = bd::String::printf("ALERT! \002%s was invited via a hijacked connection/process.\002", nick);
  1528. privmsg(chan->name, msg, DP_MODE_NEXT);
  1529. return 0;
  1530. }
  1531. #endif /* CACHE */
  1532. /* got 710: knock
  1533. * <server> 710 <to> <channel> <from> :<reason?>
  1534. * ratbox :irc.umich.edu 710 #wraith #wraith bryand!bryan@oper.blessed.net :has asked for an invite.
  1535. * csircd :irc.nac.net 710 * bryan_!bryan@pluto.xzibition.com has knocked on channel #wraith for an invite
  1536. *
  1537. */
  1538. static int got710(char *from, char *msg)
  1539. {
  1540. char *chname = NULL;
  1541. struct chanset_t *chan = NULL;
  1542. char buf[UHOSTLEN] = "", *uhost = buf, *nick;
  1543. chname = newsplit(&msg);
  1544. if (!strcmp(chname, "*")) {
  1545. //csircd
  1546. uhost = newsplit(&msg);
  1547. //has knocked on channel #CHAN for an invite
  1548. newsplit(&msg); //has
  1549. newsplit(&msg); //knocked
  1550. newsplit(&msg); //on
  1551. newsplit(&msg); //channel
  1552. chname = newsplit(&msg);
  1553. } else {
  1554. //Hybrid/ratbox
  1555. newsplit(&msg); //not used
  1556. uhost = newsplit(&msg);
  1557. }
  1558. if (!strchr(CHANMETA, chname[0]) || !strchr(uhost, '!'))
  1559. return 0;
  1560. chan = findchan(chname);
  1561. if (!chan->knock_flags || !dovoice(chan))
  1562. return 0;
  1563. struct userrec *u = get_user_by_host(uhost);
  1564. if (!u)
  1565. return 0;
  1566. nick = splitnick(&uhost);
  1567. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  1568. get_user_flagrec(u, &fr, chan->dname, chan);
  1569. // PASSING: +o and op || +v and op/voice || user
  1570. if (!((chan->knock_flags == CHAN_FLAG_OP && chk_op(fr, chan)) ||
  1571. (chan->knock_flags == CHAN_FLAG_VOICE && (chk_op(fr, chan) || chk_voice(fr, chan))) ||
  1572. (chan->knock_flags == CHAN_FLAG_USER)) ||
  1573. chan_kick(fr) || glob_kick(fr)) {
  1574. return 0;
  1575. }
  1576. // dprintf(DP_HELP, "PRIVMSG %s :%s knocked, inviting.. (%s)\n", chname, nick, u ? u->handle : "");
  1577. cache_invite(chan, nick, uhost, u ? u->handle : NULL, 0, 0);
  1578. return 0;
  1579. }
  1580. /* got 324: mode status
  1581. * <server> 324 <to> <channel> <mode>
  1582. */
  1583. static int got324(char *from, char *msg)
  1584. {
  1585. char *chname = NULL;
  1586. newsplit(&msg);
  1587. chname = newsplit(&msg);
  1588. if (match_my_nick(chname))
  1589. return 0;
  1590. struct chanset_t *chan = findchan(chname);
  1591. if (!chan) {
  1592. putlog(LOG_MISC, "*", "%s: %s", "Hmm, mode info from a channel I'm not on", chname);
  1593. dprintf(DP_SERVER, "PART %s\n", chname);
  1594. return 0;
  1595. }
  1596. // Sanity check, there may not be a mode returned if the server is sending bad data.
  1597. if (!msg[0]) return 0;
  1598. int i = 1;
  1599. bool ok = 0;
  1600. char *p = NULL, *q = NULL;
  1601. if (chan->ircnet_status & CHAN_ASKEDMODES)
  1602. ok = 1;
  1603. chan->ircnet_status &= ~CHAN_ASKEDMODES;
  1604. chan->channel.mode = 0;
  1605. while (msg[i] != 0) {
  1606. if (msg[i] == 'i')
  1607. chan->channel.mode |= CHANINV;
  1608. if (msg[i] == 'p')
  1609. chan->channel.mode |= CHANPRIV;
  1610. if (msg[i] == 's')
  1611. chan->channel.mode |= CHANSEC;
  1612. if (msg[i] == 'm')
  1613. chan->channel.mode |= CHANMODER;
  1614. if (msg[i] == 'c')
  1615. chan->channel.mode |= CHANNOCLR;
  1616. if (msg[i] == 'C')
  1617. chan->channel.mode |= CHANNOCTCP;
  1618. if (msg[i] == 'R')
  1619. chan->channel.mode |= CHANREGON;
  1620. if (msg[i] == 'M')
  1621. chan->channel.mode |= CHANMODR;
  1622. if (msg[i] == 'r')
  1623. chan->channel.mode |= CHANLONLY;
  1624. if (msg[i] == 't')
  1625. chan->channel.mode |= CHANTOPIC;
  1626. if (msg[i] == 'n')
  1627. chan->channel.mode |= CHANNOMSG;
  1628. if (msg[i] == 'a')
  1629. chan->channel.mode |= CHANANON;
  1630. if (msg[i] == 'q')
  1631. chan->channel.mode |= CHANQUIET;
  1632. if (msg[i] == 'k') {
  1633. chan->channel.mode |= CHANKEY;
  1634. p = strchr(msg, ' ');
  1635. if (p != NULL) { /* Test for null key assignment */
  1636. p++;
  1637. q = strchr(p, ' ');
  1638. if (q != NULL) {
  1639. *q = 0;
  1640. my_setkey(chan, p);
  1641. strcpy(p, q + 1);
  1642. } else {
  1643. my_setkey(chan, p);
  1644. *p = 0;
  1645. }
  1646. }
  1647. if ((chan->channel.mode & CHANKEY) && (!chan->channel.key[0] ||
  1648. !strcmp("*", chan->channel.key)))
  1649. /* Undernet use to show a blank channel key if one was set when
  1650. * you first joined a channel; however, this has been replaced by
  1651. * an asterisk and this has been agreed upon by other major IRC
  1652. * networks so we'll check for an asterisk here as well
  1653. * (guppy 22Dec2001) */
  1654. chan->ircnet_status |= CHAN_ASKEDMODES;
  1655. }
  1656. if (msg[i] == 'l') {
  1657. p = strchr(msg, ' ');
  1658. if (p != NULL) { /* test for null limit assignment */
  1659. p++;
  1660. q = strchr(p, ' ');
  1661. if (q != NULL) {
  1662. *q = 0;
  1663. chan->channel.maxmembers = atoi(p);
  1664. /* strcpy(p, q + 1); */
  1665. simple_sprintf(p, "%s", q + 1);
  1666. } else {
  1667. chan->channel.maxmembers = atoi(p);
  1668. *p = 0;
  1669. }
  1670. }
  1671. }
  1672. i++;
  1673. }
  1674. if (ok)
  1675. recheck_channel_modes(chan);
  1676. return 0;
  1677. }
  1678. static void memberlist_reposition(struct chanset_t *chan, memberlist *target) {
  1679. /* Move target from it's current position to it's correct sorted position */
  1680. memberlist *old = NULL, *m = NULL;
  1681. if (chan->channel.member == target) {
  1682. chan->channel.member = target->next;
  1683. } else {
  1684. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1685. if (m->next == target) {
  1686. m->next = target->next;
  1687. break;
  1688. }
  1689. }
  1690. }
  1691. target->next = NULL;
  1692. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  1693. if (rfc_casecmp(m->nick, target->nick)>0) {
  1694. if (old) {
  1695. target->next = m;
  1696. old->next = target;
  1697. } else {
  1698. target->next = chan->channel.member;
  1699. chan->channel.member = target;
  1700. }
  1701. return;
  1702. }
  1703. old = m;
  1704. }
  1705. if (old) {
  1706. target->next = old->next;
  1707. old->next = target;
  1708. } else {
  1709. target->next = NULL;
  1710. chan->channel.member = target;
  1711. }
  1712. }
  1713. static int got352or4(struct chanset_t *chan, char *user, char *host, char *nick, char *flags, int hops, char* realname, char* ip)
  1714. {
  1715. memberlist *m = ismember(chan, nick); /* in my channel list copy? */
  1716. // bool waschanop = 0;
  1717. // struct chanset_t *ch = NULL;
  1718. // memberlist *ml = NULL;
  1719. if (!m) { /* Nope, so update */
  1720. m = newmember(chan, nick); /* Get a new channel entry */
  1721. m->last = now; /* Last time I saw him */
  1722. /* Store the userhost */
  1723. simple_snprintf(m->userhost, sizeof(m->userhost), "%s@%s", user, host);
  1724. simple_snprintf(m->from, sizeof(m->from), "%s!%s", m->nick, m->userhost);
  1725. member_update_from_cache(chan, m);
  1726. if (!m->userip[0]) {
  1727. if (ip)
  1728. simple_snprintf(m->userip, sizeof(m->userip), "%s@%s", user, ip);
  1729. else if (is_dotted_ip(host))
  1730. simple_snprintf(m->userip, sizeof(m->userip), "%s@%s", user, host);
  1731. simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
  1732. }
  1733. }
  1734. m->hops = hops;
  1735. /* Propagate hops to other channel memlists... might save us a WHO #chan */
  1736. /* FIXME: great concept, HORRIBLE CPU USAGE
  1737. for (ch = chanset; ch; ch = ch->next) {
  1738. if (ch != chan) {
  1739. for (ml = ch->channel.member; ml && ml->nick[0]; ml = ml->next) {
  1740. if (!strcmp(ml->nick, m->nick)) {
  1741. ml->hops = m->hops;
  1742. break;
  1743. }
  1744. }
  1745. }
  1746. }
  1747. */
  1748. // waschanop = me_op(chan); /* Am I opped here? */
  1749. if (strchr(flags, '@') != NULL) /* Flags say he's opped? */
  1750. m->flags |= (CHANOP | WASOP); /* Yes, so flag in my table */
  1751. else
  1752. m->flags &= ~(CHANOP | WASOP);
  1753. if (strchr(flags, '*'))
  1754. m->flags |= OPER;
  1755. else
  1756. m->flags &= ~OPER;
  1757. if (strchr(flags, '+') != NULL) /* Flags say he's voiced? */
  1758. m->flags |= CHANVOICE; /* Yes */
  1759. else
  1760. m->flags &= ~CHANVOICE;
  1761. // if (!(m->flags & (CHANVOICE | CHANOP)))
  1762. // m->flags |= STOPWHO;
  1763. member_getuser(m);
  1764. //This bot is set +r, so resolve.
  1765. if (unlikely(doresolv(chan))) {
  1766. if (!m->userip[0])
  1767. resolve_to_member(chan, nick, host);
  1768. else if (!m->user && m->userip[0] && channel_rbl(chan))
  1769. resolve_to_rbl(chan, m->userip);
  1770. }
  1771. // If there's an opped bot, queue op to request_op
  1772. if (m->user && m->user->bot && chan_hasop(m)) {
  1773. chan->channel.do_opreq = 1;
  1774. }
  1775. return 0;
  1776. }
  1777. /* got a 352: who info!
  1778. */
  1779. static int got352(char *from, char *msg)
  1780. {
  1781. char *chname = NULL;
  1782. struct chanset_t *chan = NULL;
  1783. newsplit(&msg); /* Skip my nick - effeciently */
  1784. chname = newsplit(&msg); /* Grab the channel */
  1785. chan = findchan(chname); /* See if I'm on channel */
  1786. if (chan) { /* Am I? */
  1787. char *nick = NULL, *user = NULL, *host = NULL, *flags = NULL, *hops = NULL, *realname = NULL;
  1788. int real_hops = 1;
  1789. user = newsplit(&msg); /* Grab the user */
  1790. host = newsplit(&msg); /* Grab the host */
  1791. newsplit(&msg); /* skip the server */
  1792. nick = newsplit(&msg); /* Grab the nick */
  1793. flags = newsplit(&msg); /* Grab the flags */
  1794. hops = newsplit(&msg); /* grab server hops */
  1795. if (hops[0] == ':')
  1796. ++hops; /* Skip the : */
  1797. real_hops = atoi(hops);
  1798. realname = newsplit(&msg); /* realname/gecos */
  1799. got352or4(chan, user, host, nick, flags, real_hops, realname, NULL);
  1800. }
  1801. return 0;
  1802. }
  1803. /* got a 354: who info! - iru style
  1804. */
  1805. static int got354(char *from, char *msg)
  1806. {
  1807. if (use_354) {
  1808. newsplit(&msg); /* Skip my nick - effeciently */
  1809. if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
  1810. char *chname = newsplit(&msg); /* Grab the channel */
  1811. struct chanset_t *chan = findchan(chname); /* See if I'm on channel */
  1812. if (chan) { /* Am I? */
  1813. char *nick = NULL, *user = NULL, *host = NULL, *flags = NULL, *hops = NULL, *realname = NULL, *ip = NULL;
  1814. int real_hops = 1;
  1815. user = newsplit(&msg); /* Grab the user */
  1816. ip = newsplit(&msg); /** Get the numeric IP :) */
  1817. host = newsplit(&msg); /* Grab the host */
  1818. nick = newsplit(&msg); /* Grab the nick */
  1819. flags = newsplit(&msg); /* Grab the flags */
  1820. hops = newsplit(&msg); /* server hops */
  1821. if (hops[0] == ':')
  1822. ++hops; /* Skip the : */
  1823. real_hops = atoi(hops);
  1824. realname = newsplit(&msg); /* realname/gecos */
  1825. got352or4(chan, user, host, nick, flags, real_hops, realname, ip);
  1826. }
  1827. }
  1828. }
  1829. return 0;
  1830. }
  1831. /* got 315: end of who
  1832. * <server> 315 <to> <chan> :End of /who
  1833. */
  1834. static int got315(char *from, char *msg)
  1835. {
  1836. char *chname = NULL;
  1837. struct chanset_t *chan = NULL;
  1838. newsplit(&msg);
  1839. chname = newsplit(&msg);
  1840. putlog(LOG_DEBUG, "*", "END who %s", chname);
  1841. if (!chained_who.isEmpty()) {
  1842. // Send off next WHO request
  1843. while (1) {
  1844. if (chained_who.isEmpty()) break;
  1845. // Dequeue the next chan in the chain
  1846. chan = findchan(bd::String(chained_who.dequeue()).c_str());
  1847. if (chan) {
  1848. if (!strcmp(chan->name, chname)) continue; // First reply got queued too
  1849. if (!shouldjoin(chan)) continue; // No longer care about this channel
  1850. // Somehow got the WHO already
  1851. if (channel_active(chan) && !channel_pending(chan)) continue;
  1852. send_chan_who(chained_who_idx, chan);
  1853. break;
  1854. }
  1855. }
  1856. }
  1857. chan = findchan(chname);
  1858. /* May have left the channel before the who info came in */
  1859. if (!chan || !channel_pending(chan) || !shouldjoin(chan))
  1860. return 0;
  1861. /* Finished getting who list, can now be considered officially ON CHANNEL */
  1862. chan->ircnet_status |= CHAN_ACTIVE;
  1863. chan->ircnet_status &= ~(CHAN_PEND | CHAN_JOINING);
  1864. memberlist* me = ismember(chan, botname);
  1865. /* Am *I* on the channel now? if not, well d0h. */
  1866. if (!me) {
  1867. putlog(LOG_MISC | LOG_JOIN, chan->dname, "Oops, I'm not really on %s.", chan->dname);
  1868. force_join_chan(chan);
  1869. } else {
  1870. me->is_me = 1;
  1871. if (!me->joined)
  1872. me->joined = now; /* set this to keep the whining masses happy */
  1873. if (me_op(chan))
  1874. recheck_channel(chan, 2);
  1875. else if (chan->channel.members == 1)
  1876. chan->ircnet_status |= CHAN_STOP_CYCLE;
  1877. else if (chan->channel.do_opreq) {
  1878. request_op(chan);
  1879. }
  1880. }
  1881. /* do not check for i-lines here. */
  1882. return 0;
  1883. }
  1884. /* got 367: ban info
  1885. * <server> 367 <to> <chan> <ban> [placed-by] [timestamp]
  1886. */
  1887. static int got367(char *from, char *origmsg)
  1888. {
  1889. char *chname = NULL, buf[511] = "", *msg = NULL;
  1890. struct chanset_t *chan = NULL;
  1891. strlcpy(buf, origmsg, sizeof(buf));
  1892. msg = buf;
  1893. newsplit(&msg);
  1894. chname = newsplit(&msg);
  1895. chan = findchan(chname);
  1896. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  1897. return 0;
  1898. char *ban = newsplit(&msg), *who = newsplit(&msg);
  1899. /* Extended timestamp format? */
  1900. if (who[0])
  1901. newban(chan, ban, who);
  1902. else
  1903. newban(chan, ban, "existent");
  1904. return 0;
  1905. }
  1906. /* got 368: end of ban list
  1907. * <server> 368 <to> <chan> :etc
  1908. */
  1909. static int got368(char *from, char *msg)
  1910. {
  1911. struct chanset_t *chan = NULL;
  1912. char *chname = NULL;
  1913. /* Okay, now add bans that i want, which aren't set yet */
  1914. newsplit(&msg);
  1915. chname = newsplit(&msg);
  1916. chan = findchan(chname);
  1917. if (chan) {
  1918. chan->ircnet_status &= ~CHAN_ASKEDBANS;
  1919. chan->ircnet_status |= CHAN_HAVEBANS;
  1920. if (channel_nouserbans(chan))
  1921. resetbans(chan);
  1922. else
  1923. recheck_bans(chan);
  1924. }
  1925. /* If i sent a mode -b on myself (deban) in got367, either
  1926. * resetbans() or recheck_bans() will flush that.
  1927. */
  1928. return 0;
  1929. }
  1930. /* got 348: ban exemption info
  1931. * <server> 348 <to> <chan> <exemption>
  1932. */
  1933. static int got348(char *from, char *origmsg)
  1934. {
  1935. if (use_exempts == 0)
  1936. return 0;
  1937. char *chname = NULL, buf[511] = "", *msg = NULL;
  1938. struct chanset_t *chan = NULL;
  1939. strlcpy(buf, origmsg, sizeof(buf));
  1940. msg = buf;
  1941. newsplit(&msg);
  1942. chname = newsplit(&msg);
  1943. chan = findchan(chname);
  1944. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  1945. return 0;
  1946. char *exempt = newsplit(&msg), *who = newsplit(&msg);
  1947. /* Extended timestamp format? */
  1948. if (who[0])
  1949. newexempt(chan, exempt, who);
  1950. else
  1951. newexempt(chan, exempt, "existent");
  1952. return 0;
  1953. }
  1954. /* got 349: end of ban exemption list
  1955. * <server> 349 <to> <chan> :etc
  1956. */
  1957. static int got349(char *from, char *msg)
  1958. {
  1959. if (use_exempts == 1) {
  1960. struct chanset_t *chan = NULL;
  1961. char *chname = NULL;
  1962. newsplit(&msg);
  1963. chname = newsplit(&msg);
  1964. chan = findchan(chname);
  1965. if (chan) {
  1966. putlog(LOG_DEBUG, "*", "END +e %s", chan->dname);
  1967. chan->ircnet_status &= ~CHAN_ASKED_EXEMPTS;
  1968. if (channel_nouserexempts(chan))
  1969. resetexempts(chan);
  1970. else
  1971. recheck_exempts(chan);
  1972. if (channel_enforcebans(chan))
  1973. enforce_bans(chan);
  1974. }
  1975. }
  1976. return 0;
  1977. }
  1978. static void got353(char *from, char *msg)
  1979. {
  1980. char *chname = NULL;
  1981. struct chanset_t *chan = NULL;
  1982. newsplit(&msg); /* my nick */
  1983. newsplit(&msg); /* *|@|= */
  1984. chname = newsplit(&msg);
  1985. chan = findchan(chname);
  1986. fixcolon(msg);
  1987. irc_log(chan, "%s", msg);
  1988. }
  1989. /* got 346: invite exemption info
  1990. * <server> 346 <to> <chan> <exemption>
  1991. */
  1992. static int got346(char *from, char *origmsg)
  1993. {
  1994. if (use_invites == 0)
  1995. return 0;
  1996. char *chname = NULL, buf[511] = "", *msg = NULL;
  1997. struct chanset_t *chan = NULL;
  1998. strlcpy(buf, origmsg, sizeof(buf));
  1999. msg = buf;
  2000. newsplit(&msg);
  2001. chname = newsplit(&msg);
  2002. chan = findchan(chname);
  2003. if (!chan || !(channel_pending(chan) || channel_active(chan)))
  2004. return 0;
  2005. char *invite = newsplit(&msg), *who = newsplit(&msg);
  2006. /* Extended timestamp format? */
  2007. if (who[0])
  2008. newinvite(chan, invite, who);
  2009. else
  2010. newinvite(chan, invite, "existent");
  2011. return 0;
  2012. }
  2013. /* got 347: end of invite exemption list
  2014. * <server> 347 <to> <chan> :etc
  2015. */
  2016. static int got347(char *from, char *msg)
  2017. {
  2018. if (use_invites == 1) {
  2019. struct chanset_t *chan = NULL;
  2020. char *chname = NULL;
  2021. newsplit(&msg);
  2022. chname = newsplit(&msg);
  2023. chan = findchan(chname);
  2024. if (chan) {
  2025. chan->ircnet_status &= ~CHAN_ASKED_INVITES;
  2026. if (channel_nouserinvites(chan))
  2027. resetinvites(chan);
  2028. else
  2029. recheck_invites(chan);
  2030. }
  2031. }
  2032. return 0;
  2033. }
  2034. /* Too many channels.
  2035. */
  2036. static int got405(char *from, char *msg)
  2037. {
  2038. char *chname = NULL;
  2039. newsplit(&msg);
  2040. chname = newsplit(&msg);
  2041. putlog(LOG_MISC, "*", "I'm on too many channels--can't join: %s", chname);
  2042. return 0;
  2043. }
  2044. /* This is only of use to us with !channels. We get this message when
  2045. * attempting to join a non-existant !channel... The channel must be
  2046. * created by sending 'JOIN !!<channel>'. <cybah>
  2047. *
  2048. * 403 - ERR_NOSUCHCHANNEL
  2049. */
  2050. static int got403(char *from, char *msg)
  2051. {
  2052. char *chname = NULL;
  2053. struct chanset_t *chan = NULL;
  2054. newsplit(&msg);
  2055. chname = newsplit(&msg);
  2056. if (chname && chname[0]=='!') {
  2057. chan = findchan_by_dname(chname);
  2058. if (!chan) {
  2059. chan = findchan(chname);
  2060. if (!chan)
  2061. return 0; /* Ignore it */
  2062. /* We have the channel unique name, so we have attempted to join
  2063. * a specific !channel that doesnt exist. Now attempt to join the
  2064. * channel using it's short name.
  2065. */
  2066. putlog(LOG_MISC, "*",
  2067. "Unique channel %s does not exist... Attempting to join with "
  2068. "short name.", chname);
  2069. chan->name[0] = 0;
  2070. join_chan(chan);
  2071. } else {
  2072. /* We have found the channel, so the server has given us the short
  2073. * name. Prefix another '!' to it, and attempt the join again...
  2074. */
  2075. putlog(LOG_MISC, "*",
  2076. "Channel %s does not exist... Attempting to create it.", chname);
  2077. dprintf(DP_SERVER, "JOIN !%s\n", chan->dname);
  2078. }
  2079. }
  2080. return 0;
  2081. }
  2082. /* got 471: can't join channel, full
  2083. */
  2084. static int got471(char *from, char *msg)
  2085. {
  2086. char *chname = NULL;
  2087. struct chanset_t *chan = NULL;
  2088. newsplit(&msg);
  2089. chname = newsplit(&msg);
  2090. /* !channel short names (also referred to as 'description names'
  2091. * can be received by skipping over the unique ID.
  2092. */
  2093. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  2094. chname += CHANNEL_ID_LEN;
  2095. chname[0] = '!';
  2096. }
  2097. /* We use dname because name is first set on JOIN and we might not
  2098. * have joined the channel yet.
  2099. */
  2100. chan = findchan_by_dname(chname);
  2101. if (chan) {
  2102. chan->ircnet_status &= ~CHAN_JOINING;
  2103. putlog(LOG_JOIN, chan->dname, "Channel full--can't join: %s", chan->dname);
  2104. request_in(chan);
  2105. /* need: limit */
  2106. chan = findchan_by_dname(chname);
  2107. if (!chan)
  2108. return 0;
  2109. } else
  2110. putlog(LOG_JOIN, chname, "Channel full--can't join: %s", chname);
  2111. return 0;
  2112. }
  2113. /* got 473: can't join channel, invite only
  2114. */
  2115. static int got473(char *from, char *msg)
  2116. {
  2117. char *chname = NULL;
  2118. struct chanset_t *chan = NULL;
  2119. newsplit(&msg);
  2120. chname = newsplit(&msg);
  2121. /* !channel short names (also referred to as 'description names'
  2122. * can be received by skipping over the unique ID.
  2123. */
  2124. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  2125. chname += CHANNEL_ID_LEN;
  2126. chname[0] = '!';
  2127. }
  2128. /* We use dname because name is first set on JOIN and we might not
  2129. * have joined the channel yet.
  2130. */
  2131. chan = findchan_by_dname(chname);
  2132. if (chan) {
  2133. chan->ircnet_status &= ~CHAN_JOINING;
  2134. putlog(LOG_JOIN, chan->dname, "Channel invite only--can't join: %s", chan->dname);
  2135. request_in(chan);
  2136. /* need: invite */
  2137. chan = findchan_by_dname(chname);
  2138. if (!chan)
  2139. return 0;
  2140. } else
  2141. putlog(LOG_JOIN, chname, "Channel invite only--can't join: %s", chname);
  2142. return 0;
  2143. }
  2144. /* got 474: can't join channel, banned
  2145. */
  2146. static int got474(char *from, char *msg)
  2147. {
  2148. char *chname = NULL;
  2149. struct chanset_t *chan = NULL;
  2150. newsplit(&msg);
  2151. chname = newsplit(&msg);
  2152. /* !channel short names (also referred to as 'description names'
  2153. * can be received by skipping over the unique ID.
  2154. */
  2155. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  2156. chname += CHANNEL_ID_LEN;
  2157. chname[0] = '!';
  2158. }
  2159. /* We use dname because name is first set on JOIN and we might not
  2160. * have joined the channel yet.
  2161. */
  2162. chan = findchan_by_dname(chname);
  2163. if (chan) {
  2164. chan->ircnet_status &= ~CHAN_JOINING;
  2165. putlog(LOG_JOIN, chan->dname, "Banned from channel--can't join: %s", chan->dname);
  2166. request_in(chan);
  2167. /* need: unban */
  2168. chan = findchan_by_dname(chname);
  2169. if (!chan)
  2170. return 0;
  2171. } else
  2172. putlog(LOG_JOIN, chname, "Banned from channel--can't join: %s", chname);
  2173. return 0;
  2174. }
  2175. /* got 475: can't join channel, bad key
  2176. */
  2177. static int got475(char *from, char *msg)
  2178. {
  2179. char *chname = NULL;
  2180. struct chanset_t *chan = NULL;
  2181. newsplit(&msg);
  2182. chname = newsplit(&msg);
  2183. /* !channel short names (also referred to as 'description names'
  2184. * can be received by skipping over the unique ID.
  2185. */
  2186. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  2187. chname += CHANNEL_ID_LEN;
  2188. chname[0] = '!';
  2189. }
  2190. /* We use dname because name is first set on JOIN and we might not
  2191. * have joined the channel yet.
  2192. */
  2193. chan = findchan_by_dname(chname);
  2194. if (chan && shouldjoin(chan)) {
  2195. chan->ircnet_status &= ~CHAN_JOINING;
  2196. putlog(LOG_JOIN, chan->dname, "Bad key--can't join: %s", chan->dname);
  2197. if (chan->channel.key[0]) {
  2198. my_setkey(chan, NULL);
  2199. join_chan(chan);
  2200. } else {
  2201. request_in(chan);
  2202. /* need: key */
  2203. }
  2204. } else
  2205. putlog(LOG_JOIN, chname, "Bad key--can't join: %s", chname);
  2206. return 0;
  2207. }
  2208. /* got 478: Channel ban list is full
  2209. * [@] irc.blessed.net 478 wtest #wraith-devel *!*@host.com :Channel ban list is full
  2210. */
  2211. static int got478(char *from, char *msg)
  2212. {
  2213. char *chname = NULL;
  2214. struct chanset_t *chan = NULL;
  2215. newsplit(&msg);
  2216. chname = newsplit(&msg);
  2217. /* !channel short names (also referred to as 'description names'
  2218. * can be received by skipping over the unique ID.
  2219. */
  2220. if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
  2221. chname += CHANNEL_ID_LEN;
  2222. chname[0] = '!';
  2223. }
  2224. /* We use dname because name is first set on JOIN and we might not
  2225. * have joined the channel yet.
  2226. */
  2227. chan = findchan_by_dname(chname);
  2228. if (chan && shouldjoin(chan)) {
  2229. // Only lockdown if not already locked down
  2230. if (!chan->channel.drone_set_mode) {
  2231. lockdown_chan(chan, FLOOD_BANLIST);
  2232. }
  2233. }
  2234. return 0;
  2235. }
  2236. /* got invitation
  2237. */
  2238. static int gotinvite(char *from, char *msg)
  2239. {
  2240. char *nick = NULL;
  2241. struct chanset_t *chan = NULL;
  2242. bool flood = 0;
  2243. newsplit(&msg);
  2244. fixcolon(msg);
  2245. nick = splitnick(&from);
  2246. /* Two invites to the same channel in 10 seconds? */
  2247. if (!rfc_casecmp(last_invchan, msg))
  2248. if (now - last_invtime < 10)
  2249. flood = 1;
  2250. if (!flood)
  2251. putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg);
  2252. strlcpy(last_invchan, msg, sizeof(last_invchan));
  2253. last_invtime = now;
  2254. chan = findchan(msg);
  2255. if (!chan)
  2256. /* Might be a short-name */
  2257. chan = findchan_by_dname(msg);
  2258. if (chan) {
  2259. if (channel_pending(chan) || channel_active(chan))
  2260. notice(nick, "I'm already here.", DP_HELP);
  2261. else if (shouldjoin(chan))
  2262. join_chan(chan);
  2263. }
  2264. return 0;
  2265. }
  2266. /* Set the topic.
  2267. */
  2268. static void set_topic(struct chanset_t *chan, char *k)
  2269. {
  2270. if (chan->channel.topic)
  2271. free(chan->channel.topic);
  2272. if (k && k[0]) {
  2273. size_t tlen = strlen(k) + 1;
  2274. chan->channel.topic = (char *) calloc(1, tlen);
  2275. strlcpy(chan->channel.topic, k, tlen);
  2276. } else
  2277. chan->channel.topic = NULL;
  2278. }
  2279. /* Topic change.
  2280. */
  2281. static int gottopic(char *from, char *msg)
  2282. {
  2283. char *chname = newsplit(&msg), *nick = NULL;
  2284. struct chanset_t *chan = NULL;
  2285. fixcolon(msg);
  2286. nick = splitnick(&from);
  2287. chan = findchan(chname);
  2288. if (chan) {
  2289. memberlist *m = ismember(chan, nick);
  2290. irc_log(chan, "%s!%s changed topic to: %s", nick, from, msg);
  2291. if (m != NULL)
  2292. m->last = now;
  2293. set_topic(chan, msg);
  2294. }
  2295. return 0;
  2296. }
  2297. /* 331: no current topic for this channel
  2298. * <server> 331 <to> <chname> :etc
  2299. */
  2300. static int got331(char *from, char *msg)
  2301. {
  2302. char *chname = NULL;
  2303. struct chanset_t *chan = NULL;
  2304. newsplit(&msg);
  2305. chname = newsplit(&msg);
  2306. chan = findchan(chname);
  2307. if (chan) {
  2308. set_topic(chan, NULL);
  2309. }
  2310. return 0;
  2311. }
  2312. /* 332: topic on a channel i've just joined
  2313. * <server> 332 <to> <chname> :topic goes here
  2314. */
  2315. static int got332(char *from, char *msg)
  2316. {
  2317. struct chanset_t *chan = NULL;
  2318. char *chname = NULL;
  2319. newsplit(&msg);
  2320. chname = newsplit(&msg);
  2321. chan = findchan(chname);
  2322. if (chan) {
  2323. fixcolon(msg);
  2324. set_topic(chan, msg);
  2325. }
  2326. return 0;
  2327. }
  2328. /* Got a join
  2329. */
  2330. static int gotjoin(char *from, char *chname)
  2331. {
  2332. struct chanset_t *chan = NULL;
  2333. fixcolon(chname);
  2334. chan = findchan(chname);
  2335. if (!chan && chname[0] == '!') {
  2336. /* As this is a !channel, we need to search for it by display (short)
  2337. * name now. This will happen when we initially join the channel, as we
  2338. * dont know the unique channel name that the server has made up. <cybah>
  2339. */
  2340. size_t l_chname = strlen(chname);
  2341. if (l_chname > (CHANNEL_ID_LEN + 1)) {
  2342. char* ch_dname = (char *) calloc(1, l_chname + 1);
  2343. simple_snprintf(ch_dname, l_chname + 2, "!%s", chname + (CHANNEL_ID_LEN + 1));
  2344. chan = findchan_by_dname(ch_dname);
  2345. if (!chan) {
  2346. /* Hmm.. okay. Maybe the admin's a genius and doesn't know the
  2347. * difference between id and descriptive channel names. Search
  2348. * the channel name in the dname list using the id-name.
  2349. */
  2350. chan = findchan_by_dname(chname);
  2351. if (chan) {
  2352. /* Duh, I was right. Mark this channel as inactive and log
  2353. * the incident.
  2354. */
  2355. chan->status |= CHAN_INACTIVE;
  2356. putlog(LOG_MISC, "*", "Deactivated channel %s, because it uses "
  2357. "an ID channel-name. Use the descriptive name instead.", chname);
  2358. dprintf(DP_SERVER, "PART %s\n", chname);
  2359. free(ch_dname);
  2360. return 0;
  2361. }
  2362. }
  2363. free(ch_dname);
  2364. }
  2365. } else if (!chan) {
  2366. /* As this is not a !chan, we need to search for it by display name now.
  2367. * Unlike !chan's, we dont need to remove the unique part.
  2368. */
  2369. chan = findchan_by_dname(chname);
  2370. }
  2371. char *nick = NULL, buf[UHOSTLEN] = "", *uhost = buf;
  2372. strlcpy(uhost, from, sizeof(buf));
  2373. nick = splitnick(&uhost);
  2374. if (!chan || (chan && !shouldjoin(chan))) {
  2375. if (match_my_nick(nick)) {
  2376. putlog(LOG_WARN, "*", "joined %s but didn't want to!", chname);
  2377. dprintf(DP_MODE, "PART %s\n", chname);
  2378. }
  2379. } else if (!channel_pending(chan)) {
  2380. char *host = NULL;
  2381. chan->ircnet_status &= ~CHAN_STOP_CYCLE;
  2382. if ((host = strchr(uhost, '@')))
  2383. ++host;
  2384. if (!channel_active(chan) && !match_my_nick(nick)) {
  2385. /* uh, what?! i'm on the channel?! */
  2386. putlog(LOG_ERROR, "*", "confused bot: guess I'm on %s and didn't realize it", chan->dname);
  2387. chan->ircnet_status |= CHAN_ACTIVE;
  2388. chan->ircnet_status &= ~(CHAN_PEND | CHAN_JOINING);
  2389. reset_chan_info(chan);
  2390. } else {
  2391. memberlist *m = ismember(chan, nick);
  2392. bool splitjoin = 0;
  2393. /* Net-join */
  2394. if (m && m->split && !strcasecmp(m->userhost, uhost)) {
  2395. splitjoin = 1;
  2396. m->split = 0;
  2397. --(chan->channel.splitmembers);
  2398. m->last = now;
  2399. m->delay = 0L;
  2400. m->flags = (chan_hasop(m) ? WASOP : 0);
  2401. set_handle_laston(chan->dname, m->user, now);
  2402. // m->flags |= STOPWHO;
  2403. irc_log(chan, "%s returned from netsplit", m->nick);
  2404. if (!m->user) {
  2405. member_getuser(m);
  2406. if (!m->user && !m->userip[0] && doresolv(chan)) {
  2407. if (is_dotted_ip(host)) {
  2408. strlcpy(m->userip, uhost, sizeof(m->userip));
  2409. simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
  2410. if (channel_rbl(chan))
  2411. resolve_to_rbl(chan, m->userip);
  2412. } else
  2413. resolve_to_member(chan, nick, host);
  2414. }
  2415. }
  2416. } else {
  2417. if (m)
  2418. killmember(chan, nick);
  2419. m = newmember(chan, nick);
  2420. m->joined = m->last = now;
  2421. strlcpy(m->userhost, uhost, sizeof(m->userhost));
  2422. member_update_from_cache(chan, m);
  2423. simple_snprintf(m->from, sizeof(m->from), "%s!%s", m->nick, m->userhost);
  2424. if (is_dotted_ip(host)) {
  2425. strlcpy(m->userip, uhost, sizeof(m->userip));
  2426. simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
  2427. }
  2428. member_getuser(m);
  2429. if (!m->userip[0] && doresolv(chan))
  2430. resolve_to_member(chan, nick, host);
  2431. else if (!m->user && m->userip[0] && doresolv(chan) && channel_rbl(chan))
  2432. resolve_to_rbl(chan, m->userip);
  2433. // m->flags |= STOPWHO;
  2434. if (match_my_nick(nick)) {
  2435. m->is_me = 1;
  2436. /* It was me joining! Need to update the channel record with the
  2437. * unique name for the channel (as the server see's it). <cybah>
  2438. */
  2439. strlcpy(chan->name, chname, sizeof(chan->name));
  2440. chan->ircnet_status &= ~CHAN_JUPED;
  2441. /* ... and log us joining. Using chan->dname for the channel is
  2442. * important in this case. As the config file will never contain
  2443. * logs with the unique name.
  2444. */
  2445. if (chname[0] == '!')
  2446. irc_log(chan, "Joined. (%s)", chname);
  2447. else
  2448. irc_log(chan, "Joined.");
  2449. if (!match_my_nick(chname))
  2450. reset_chan_info(chan);
  2451. } else {
  2452. irc_log(chan, "Join: %s (%s)", nick, uhost);
  2453. detect_chan_flood(m, from, chan, FLOOD_JOIN);
  2454. set_handle_laston(chan->dname, m->user, now);
  2455. }
  2456. }
  2457. /* ok, the op-on-join,etc, tests...first only both if Im opped */
  2458. if (me_op(chan)) {
  2459. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  2460. get_user_flagrec(m->user, &fr, chan->dname, chan);
  2461. bool is_op = chk_op(fr, chan);
  2462. /* Check for a mass join */
  2463. if (!splitjoin && chan->flood_mjoin_time && chan->flood_mjoin_thr && !is_op) {
  2464. if (chan->channel.drone_jointime < now - chan->flood_mjoin_time) { //expired, reset counter
  2465. chan->channel.drone_joins = 0;
  2466. }
  2467. ++chan->channel.drone_joins;
  2468. chan->channel.drone_jointime = now;
  2469. if (!chan->channel.drone_set_mode && chan->channel.drone_joins >= chan->flood_mjoin_thr) { //flood from dronenet, let's attempt to set +im
  2470. lockdown_chan(chan, FLOOD_MASSJOIN);
  2471. }
  2472. }
  2473. /* Check for and reset exempts and invites.
  2474. *
  2475. * This will require further checking to account for when to use the
  2476. * various modes.
  2477. */
  2478. if (u_match_mask(global_invites,from) ||
  2479. u_match_mask(chan->invites, from))
  2480. refresh_invite(chan, from);
  2481. if (!(use_exempts && (u_match_mask(global_exempts,from) || u_match_mask(chan->exempts, from)))) {
  2482. if (channel_enforcebans(chan) && !chan_sentkick(m) && !is_op &&
  2483. !(use_exempts && (isexempted(chan, from) || (chan->ircnet_status & CHAN_ASKED_EXEMPTS)))) {
  2484. for (masklist* b = chan->channel.ban; b->mask[0]; b = b->next) {
  2485. if (wild_match(b->mask, from) || match_cidr(b->mask, from)) {
  2486. dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chname, m->nick, bankickprefix, r_banned(chan));
  2487. m->flags |= SENTKICK;
  2488. return 0;
  2489. }
  2490. }
  2491. }
  2492. /* If it matches a ban, dispose of them. */
  2493. if (u_match_mask(global_bans, from) || u_match_mask(chan->bans, from)) {
  2494. refresh_ban_kick(chan, m, from);
  2495. /* Likewise for kick'ees */
  2496. } else if (!chan_sentkick(m) && (glob_kick(fr) || chan_kick(fr))) {
  2497. check_exemptlist(chan, from);
  2498. quickban(chan, from);
  2499. dprintf(DP_MODE, "KICK %s %s :%s%s\n", chname, m->nick, bankickprefix, response(RES_KICKBAN));
  2500. m->flags |= SENTKICK;
  2501. }
  2502. }
  2503. bool op = 0;
  2504. #ifdef CACHE
  2505. cache_t *cache = cache_find(nick);
  2506. if (cache) {
  2507. cache_chan_t *cchan = NULL;
  2508. if (strcasecmp(cache->uhost, m->userhost)) {
  2509. }
  2510. for (cchan = cache->cchan; cchan && cchan->dname[0]; cchan = cchan->next) {
  2511. if (!rfc_casecmp(cchan->dname, chan->dname)) {
  2512. if (cchan->op) {
  2513. op = 1;
  2514. cchan->op = 0;
  2515. }
  2516. break;
  2517. }
  2518. }
  2519. }
  2520. #endif /* CACHE */
  2521. if (!splitjoin) {
  2522. /* Autoop */
  2523. if (!chan_hasop(m) &&
  2524. (op ||
  2525. (dovoice(chan) && chk_autoop(m, fr, chan)))) {
  2526. do_op(m, chan, 1, 0);
  2527. }
  2528. /* +v or +voice */
  2529. if (!chan_hasvoice(m) && !glob_bot(fr) && dovoice(chan)) {
  2530. if (m->user) {
  2531. if (!(m->flags & EVOICE) &&
  2532. (
  2533. /* +voice: Voice all clients who are not flag:+q. If the chan is +voicebitch, only op flag:+v clients */
  2534. (channel_voice(chan) && !chk_devoice(fr) && (!channel_voicebitch(chan) || (channel_voicebitch(chan) && chk_voice(fr, chan)))) ||
  2535. /* Or, if the channel is -voice but they still qualify to be voiced */
  2536. (!channel_voice(chan) && !privchan(fr, chan, PRIV_VOICE) && chk_voice(fr, chan))
  2537. )
  2538. ) {
  2539. m->delay = now + chan->auto_delay;
  2540. m->flags |= SENTVOICE;
  2541. }
  2542. } else if (!m->user && channel_voice(chan) && !channel_voicebitch(chan) && voice_ok(m, chan)) {
  2543. m->delay = now + chan->auto_delay;
  2544. m->flags |= SENTVOICE;
  2545. }
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. return 0;
  2552. }
  2553. /* Got a part
  2554. */
  2555. static int gotpart(char *from, char *msg)
  2556. {
  2557. char *nick = NULL, *chname = NULL;
  2558. struct chanset_t *chan = NULL;
  2559. char buf[UHOSTLEN] = "", *uhost = buf;
  2560. chname = newsplit(&msg);
  2561. fixcolon(chname);
  2562. fixcolon(msg);
  2563. chan = findchan(chname);
  2564. strlcpy(uhost, from, sizeof(buf));
  2565. nick = splitnick(&uhost);
  2566. if (chan && !shouldjoin(chan) && match_my_nick(nick)) {
  2567. irc_log(chan, "Parting");
  2568. clear_channel(chan, 1);
  2569. return 0;
  2570. }
  2571. if (chan && !channel_pending(chan)) {
  2572. memberlist* m = ismember(chan, nick);
  2573. struct userrec *u = (m && m->user) ? m->user : get_user_by_host(from);
  2574. if (!channel_active(chan)) {
  2575. /* whoa! */
  2576. putlog(LOG_ERRORS, "*", "confused bot: guess I'm on %s and didn't realize it", chan->dname);
  2577. chan->ircnet_status |= CHAN_ACTIVE;
  2578. chan->ircnet_status &= ~(CHAN_PEND | CHAN_JOINING);
  2579. reset_chan_info(chan);
  2580. }
  2581. set_handle_laston(chan->dname, u, now);
  2582. if (m) {
  2583. detect_chan_flood(m, from, chan, FLOOD_PART);
  2584. killmember(chan, nick);
  2585. }
  2586. if (msg[0])
  2587. irc_log(chan, "Part: %s (%s) [%s]", nick, uhost, msg);
  2588. else
  2589. irc_log(chan, "Part: %s (%s)", nick, uhost);
  2590. /* If it was me, all hell breaks loose... */
  2591. if (match_my_nick(nick)) {
  2592. check_rejoin(chan);
  2593. } else
  2594. check_lonely_channel(chan);
  2595. }
  2596. return 0;
  2597. }
  2598. /* Got a kick
  2599. */
  2600. static int gotkick(char *from, char *origmsg)
  2601. {
  2602. char buf2[511], *msg = buf2, *chname = NULL;
  2603. struct chanset_t *chan = NULL;
  2604. strlcpy(buf2, origmsg, sizeof(buf2));
  2605. msg = buf2;
  2606. chname = newsplit(&msg);
  2607. chan = findchan(chname);
  2608. if (!chan)
  2609. return 0;
  2610. char *nick = newsplit(&msg);
  2611. if (match_my_nick(nick) && channel_pending(chan)) {
  2612. check_rejoin(chan);
  2613. return 0; /* rejoin if kicked before getting needed info <Wcc[08/08/02]> */
  2614. }
  2615. if (channel_active(chan)) {
  2616. char *whodid = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
  2617. memberlist *m = NULL, *mv = NULL;
  2618. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  2619. fixcolon(msg);
  2620. strlcpy(uhost, from, sizeof(buf));
  2621. whodid = splitnick(&uhost);
  2622. chan = findchan(chname);
  2623. if (!chan)
  2624. return 0;
  2625. m = ismember(chan, whodid);
  2626. if (m) {
  2627. detect_chan_flood(m, from, chan, FLOOD_KICK);
  2628. m->last = now;
  2629. member_getuser(m);
  2630. if (m->user) {
  2631. /* This _needs_ to use chan->dname <cybah> */
  2632. get_user_flagrec(m->user, &fr, chan->dname, chan);
  2633. set_handle_laston(chan->dname, m->user, now);
  2634. }
  2635. }
  2636. if ((!m || !m->user) || (m && m->user && !m->user->bot)) {
  2637. chan->channel.fighting++;
  2638. }
  2639. mv = ismember(chan, nick);
  2640. member_getuser(mv);
  2641. if (mv->user) {
  2642. // Revenge kick clients that kick our bots
  2643. if (chan->revenge && !mv->is_me && m && m != mv && mv->user->bot && !(m->user && m->user->bot)) {
  2644. if (role < 5 && !chan_sentkick(m) && me_op(chan)) {
  2645. m->flags |= SENTKICK;
  2646. dprintf(DP_MODE_NEXT, "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_REVENGE));
  2647. } else {
  2648. if (m->user) {
  2649. char tmp[128] = "";
  2650. simple_snprintf(tmp, sizeof(tmp), "Kicked bot %s on %s", mv->nick, chan->dname);
  2651. deflag_user(m->user, DEFLAG_EVENT_REVENGE_KICK, tmp, chan);
  2652. }
  2653. }
  2654. }
  2655. set_handle_laston(chan->dname, mv->user, now);
  2656. }
  2657. irc_log(chan, "%s was kicked by %s (%s)", s1, from, msg);
  2658. /* Kicked ME?!? the sods! */
  2659. if (mv->is_me) {
  2660. check_rejoin(chan);
  2661. } else {
  2662. killmember(chan, nick);
  2663. check_lonely_channel(chan);
  2664. }
  2665. }
  2666. return 0;
  2667. }
  2668. /* Got a nick change
  2669. */
  2670. static int gotnick(char *from, char *msg)
  2671. {
  2672. char *nick = NULL, s1[UHOSTLEN] = "", buf[UHOSTLEN] = "", *uhost = buf;
  2673. memberlist *m = NULL, *mm = NULL;
  2674. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  2675. strlcpy(uhost, from, sizeof(buf));
  2676. nick = splitnick(&uhost);
  2677. fixcolon(msg);
  2678. irc_log(NULL, "[%s] Nick change: %s -> %s", samechans(nick, ","), nick, msg);
  2679. clear_chanlist_member(nick); /* Cache for nick 'nick' is meaningless now. */
  2680. Auth *auth = Auth::Find(uhost);
  2681. if (auth)
  2682. auth->NewNick(msg);
  2683. /* Compose a nick!user@host for the new nick */
  2684. simple_snprintf(s1, sizeof(s1), "%s!%s", msg, uhost);
  2685. /* Users can match by nick, so a recheck is needed */
  2686. struct userrec *u = get_user_by_host(s1);
  2687. for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
  2688. m = ismember(chan, nick);
  2689. if (m) {
  2690. m->user = u;
  2691. m->last = now;
  2692. /* Not just a capitalization change */
  2693. if (rfc_casecmp(nick, msg)) {
  2694. /* Someone on channel with old nick?! */
  2695. if ((mm = ismember(chan, msg)))
  2696. killmember(chan, mm->nick, false);
  2697. }
  2698. strlcpy(m->nick, msg, sizeof(m->nick));
  2699. strlcpy(m->from, s1, sizeof(m->from));
  2700. /*
  2701. * Banned?
  2702. */
  2703. memberlist_reposition(chan, m);
  2704. detect_chan_flood(m, from, chan, FLOOD_NICK);
  2705. /* Any pending kick or mode to the old nick is lost. */
  2706. m->flags &= ~(SENTKICK | SENTDEOP | SENTOP |
  2707. SENTVOICE | SENTDEVOICE);
  2708. /* nick-ban or nick is +k or something? */
  2709. get_user_flagrec(m->user, &fr, chan->dname, chan);
  2710. check_this_member(chan, m, &fr);
  2711. }
  2712. }
  2713. return 0;
  2714. }
  2715. void check_should_cycle(struct chanset_t *chan)
  2716. {
  2717. if (!me_op(chan))
  2718. return;
  2719. //If there are other ops split off and i'm the only op on this side of split, cycle
  2720. int localops = 0, localbotops = 0, splitops = 0, splitbotops = 0, localnonops = 0;
  2721. for (memberlist *ml = chan->channel.member; ml && ml->nick[0]; ml = ml->next) {
  2722. if (chan_hasop(ml)) {
  2723. if (chan_issplit(ml)) {
  2724. splitops++;
  2725. if ((ml->user) && ml->user->bot)
  2726. splitbotops++;
  2727. } else {
  2728. localops++;
  2729. if ((ml->user) && ml->user->bot)
  2730. localbotops++;
  2731. if (localbotops >= 2)
  2732. return;
  2733. if (localops > localbotops)
  2734. return;
  2735. }
  2736. } else {
  2737. if (!chan_issplit(ml))
  2738. localnonops++;
  2739. }
  2740. }
  2741. if (splitbotops > 5) {
  2742. sdprintf("Cycling %s", chan->dname);
  2743. /* I'm only one opped here... and other side has some ops... so i'm cycling */
  2744. if (localnonops) {
  2745. /* need to unset any +kil first */
  2746. dprintf(DP_MODE, "MODE %s -ilk %s\n", chan->name[0] ? chan->name : chan->dname, (chan->channel.key && chan->channel.key[0]) ? chan->channel.key : "");
  2747. dprintf(DP_MODE, "PART %s\n", chan->name[0] ? chan->name : chan->dname);
  2748. } else
  2749. dprintf(DP_MODE, "PART %s\n", chan->name[0] ? chan->name : chan->dname);
  2750. }
  2751. }
  2752. /* Signoff, similar to part.
  2753. */
  2754. static int gotquit(char *from, char *msg)
  2755. {
  2756. char *nick = NULL, *p = NULL;
  2757. bool split = 0;
  2758. memberlist *m = NULL;
  2759. char from2[NICKMAX + UHOSTMAX + 1] = "";
  2760. struct userrec *u = NULL;
  2761. strlcpy(from2, from, sizeof(from2));
  2762. #ifdef TCL
  2763. u = get_user_by_host(from2);
  2764. #endif
  2765. nick = splitnick(&from);
  2766. fixcolon(msg);
  2767. /* Fred1: Instead of expensive wild_match on signoff, quicker method.
  2768. * Determine if signoff string matches "%.% %.%", and only one
  2769. * space.
  2770. */
  2771. p = strchr(msg, ' ');
  2772. if (p && (p == strrchr(msg, ' '))) {
  2773. char *z1 = NULL, *z2 = NULL;
  2774. *p = 0;
  2775. z1 = strchr(p + 1, '.');
  2776. z2 = strchr(msg, '.');
  2777. if (z1 && z2 && (*(z1 + 1) != 0) && (z1 - 1 != p) &&
  2778. (z2 + 1 != p) && (z2 != msg)) {
  2779. /* Server split, or else it looked like it anyway (no harm in
  2780. * assuming)
  2781. */
  2782. split = 1;
  2783. } else
  2784. *p = ' ';
  2785. }
  2786. if (msg[0])
  2787. irc_log(NULL, "[%s] Quits %s (%s) (%s)", samechans(nick, ","), nick, from, msg);
  2788. else
  2789. irc_log(NULL, "[%s] Quits %s (%s)", samechans(nick, ","), nick, from);
  2790. for (struct chanset_t* chan = chanset; chan; chan = chan->next) {
  2791. if (!channel_active(chan))
  2792. continue;
  2793. m = ismember(chan, nick);
  2794. if (m) {
  2795. member_getuser(m);
  2796. u = m->user;
  2797. if (u) {
  2798. if (u->bot)
  2799. counter_clear(u->handle);
  2800. set_handle_laston(chan->dname, u, now); /* If you remove this, the bot will crash when the user record in question
  2801. is removed/modified during the tcl binds below, and the users was on more
  2802. than one monitored channel */
  2803. }
  2804. if (split) {
  2805. m->split = now;
  2806. ++(chan->channel.splitmembers);
  2807. irc_log(chan, "%s (%s) got netsplit.", nick, from);
  2808. } else {
  2809. killmember(chan, nick);
  2810. check_lonely_channel(chan);
  2811. }
  2812. if (channel_cycle(chan))
  2813. check_should_cycle(chan);
  2814. }
  2815. }
  2816. /* Our nick quit? if so, grab it.
  2817. */
  2818. if (keepnick && !match_my_nick(nick))
  2819. nicks_available(nick);
  2820. #ifdef CACHE
  2821. /* see if they were in our cache at all */
  2822. cache_t *cache = cache_find(nick);
  2823. if (cache)
  2824. cache_del(nick, cache);
  2825. #endif /* CACHE */
  2826. return 0;
  2827. }
  2828. /* Got a channel message.
  2829. */
  2830. static int gotmsg(char *from, char *msg)
  2831. {
  2832. if (!strchr("&#!+@$", msg[0]))
  2833. return 0;
  2834. bool ignoring = match_ignore(from);
  2835. char *to = newsplit(&msg), *realto = (to[0] == '@') ? to + 1 : to;
  2836. struct chanset_t *chan = findchan(realto);
  2837. if (!chan)
  2838. return 0; /* Private msg to an unknown channel?? */
  2839. char buf[UHOSTLEN] = "", *nick = NULL, buf2[512] = "", *uhost = buf, *p = NULL, *p1 = NULL, *code = NULL, *ctcp = NULL;
  2840. int ctcp_count = 0;
  2841. struct userrec *u = NULL;
  2842. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  2843. fixcolon(msg);
  2844. strlcpy(uhost, from, sizeof(buf));
  2845. nick = splitnick(&uhost);
  2846. memberlist *m = ismember(chan, nick);
  2847. /* Only check if flood-ctcp is active */
  2848. if (m && flood_ctcp.count && detect_avalanche(msg)) {
  2849. member_getuser(m);
  2850. u = m->user;
  2851. get_user_flagrec(u, &fr, chan->dname, chan);
  2852. /* Discard -- kick user if it was to the channel */
  2853. if (m && me_op(chan) &&
  2854. !chan_sentkick(m) &&
  2855. !(use_exempts && ban_fun &&
  2856. /* don't kickban if permanent exempted -- Eule */
  2857. (u_match_mask(global_exempts, from) ||
  2858. u_match_mask(chan->exempts, from)))) {
  2859. if (ban_fun) {
  2860. check_exemptlist(chan, from);
  2861. u_addmask('b', chan, quickban(chan, from), conf.bot->nick,
  2862. "that was fun, let's do it again!", now + (60 * chan->ban_time), 0);
  2863. }
  2864. if (kick_fun) {
  2865. /* This can induce kickflood - arthur2 */
  2866. dprintf(DP_SERVER, "KICK %s %s :%sthat was fun, let's do it again!\n", chan->name, nick, kickprefix);
  2867. m->flags |= SENTKICK;
  2868. }
  2869. }
  2870. if (!ignoring) {
  2871. putlog(LOG_MODES, "*", "Avalanche from %s!%s in %s - ignoring",
  2872. nick, uhost, chan->dname);
  2873. p = strchr(uhost, '@');
  2874. if (p)
  2875. p++;
  2876. else
  2877. p = uhost;
  2878. simple_snprintf(buf2, sizeof(buf2), "*!*@%s", p);
  2879. addignore(buf2, conf.bot->nick, "ctcp avalanche", now + (60 * ignore_time));
  2880. }
  2881. return 0;
  2882. }
  2883. /* Check for CTCP: */
  2884. ctcp_reply[0] = 0;
  2885. p = strchr(msg, 1);
  2886. while (p && *p) {
  2887. p++;
  2888. p1 = p;
  2889. while ((*p != 1) && *p)
  2890. p++;
  2891. if (*p == 1) {
  2892. *p = 0;
  2893. ctcp = buf2;
  2894. strlcpy(ctcp, p1, sizeof(buf2));
  2895. strcpy(p1 - 1, p + 1);
  2896. if (m) {
  2897. detect_chan_flood(m, from, chan, strncmp(ctcp, "ACTION ", 7) ? FLOOD_CTCP : FLOOD_PRIVMSG);
  2898. detect_chan_flood(m, from, chan, FLOOD_BYTES, msg);
  2899. }
  2900. /* Respond to the first answer_ctcp */
  2901. p = strchr(msg, 1);
  2902. if (ctcp_count < answer_ctcp) {
  2903. ctcp_count++;
  2904. if (ctcp[0] != ' ') {
  2905. code = newsplit(&ctcp);
  2906. u = get_user_by_host(from);
  2907. if (!ignoring || trigger_on_ignore) {
  2908. if (check_bind_ctcp(nick, uhost, u, to, code, ctcp) == BIND_RET_LOG) {
  2909. update_idle(chan->dname, nick);
  2910. }
  2911. /* Log DCC, it's to a channel damnit! */
  2912. if (!strcmp(code, "ACTION")) {
  2913. irc_log(chan, "* %s %s", nick, ctcp);
  2914. } else {
  2915. irc_log(chan, "CTCP %s: from %s (%s) to %s: %s", code, nick, from, to, ctcp);
  2916. }
  2917. }
  2918. }
  2919. }
  2920. }
  2921. }
  2922. /* Send out possible ctcp responses */
  2923. if (ctcp_reply[0]) {
  2924. if (ctcp_mode != 2) {
  2925. notice(nick, ctcp_reply, DP_HELP);
  2926. } else {
  2927. if (now - last_ctcp > flood_ctcp.time) {
  2928. notice(nick, ctcp_reply, DP_HELP);
  2929. count_ctcp = 1;
  2930. } else if (count_ctcp < flood_ctcp.count) {
  2931. notice(nick, ctcp_reply, DP_HELP);
  2932. count_ctcp++;
  2933. }
  2934. last_ctcp = now;
  2935. }
  2936. }
  2937. if (msg[0]) {
  2938. int botmatch = 0;
  2939. char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
  2940. if (me_op(chan) && doflood(chan))
  2941. detect_offense(m, chan, msg);
  2942. if (m) {
  2943. detect_chan_flood(m, from, chan, FLOOD_PRIVMSG);
  2944. detect_chan_flood(m, from, chan, FLOOD_BYTES, msg);
  2945. }
  2946. if (auth_chan) {
  2947. my_msg = my_ptr = strdup(msg);
  2948. fword = newsplit(&my_msg); /* take out first word */
  2949. /* the first word is a wildcard match to our nick. */
  2950. botmatch = wild_match(fword, botname);
  2951. if (botmatch && strcmp(fword, "*"))
  2952. fword = newsplit(&my_msg); /* now this will be the command */
  2953. /* is it a cmd? */
  2954. if (auth_prefix[0] && fword && fword[0] && fword[1] && ((botmatch && fword[0] != auth_prefix[0]) || (fword[0] == auth_prefix[0]))) {
  2955. Auth *auth = Auth::Find(uhost);
  2956. if (auth && auth->Authed()) {
  2957. if (fword[0] == auth_prefix[0])
  2958. fword++;
  2959. auth->atime = now;
  2960. check_bind_authc(fword, auth, chan->dname, my_msg);
  2961. }
  2962. }
  2963. free(my_ptr);
  2964. }
  2965. irc_log(chan, "%s<%s> %s", to[0] == '@' ? "@" : "", nick, msg);
  2966. update_idle(chan->dname, nick);
  2967. }
  2968. return 0;
  2969. }
  2970. /* Got a private notice.
  2971. */
  2972. static int gotnotice(char *from, char *msg)
  2973. {
  2974. if (!strchr(CHANMETA "@", *msg))
  2975. return 0;
  2976. bool ignoring = match_ignore(from);
  2977. char *to = newsplit(&msg), *realto = (*to == '@') ? to + 1 : to;
  2978. struct chanset_t *chan = NULL;
  2979. chan = findchan(realto);
  2980. if (!chan)
  2981. return 0; /* Notice to an unknown channel?? */
  2982. char *nick = NULL, buf2[512] = "", *p = NULL, *p1 = NULL, buf[512] = "", *uhost = buf;
  2983. char *ctcp = NULL, *code = NULL;
  2984. struct userrec *u = NULL;
  2985. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  2986. fixcolon(msg);
  2987. strlcpy(uhost, from, sizeof(buf));
  2988. nick = splitnick(&uhost);
  2989. memberlist *m = ismember(chan, nick);
  2990. if (m) {
  2991. member_getuser(m);
  2992. u = m->user;
  2993. }
  2994. if (flood_ctcp.count && detect_avalanche(msg)) {
  2995. get_user_flagrec(u, &fr, chan->dname, chan);
  2996. /* Discard -- kick user if it was to the channel */
  2997. if (me_op(chan) && m && !chan_sentkick(m) &&
  2998. !(use_exempts && ban_fun &&
  2999. /* don't kickban if permanent exempted -- Eule */
  3000. (u_match_mask(global_exempts,from) ||
  3001. u_match_mask(chan->exempts, from)))) {
  3002. if (ban_fun) {
  3003. check_exemptlist(chan, from);
  3004. u_addmask('b', chan, quickban(chan, from), conf.bot->nick,
  3005. "that was fun, let's do it again!", now + (60 * chan->ban_time), 0);
  3006. }
  3007. if (kick_fun) {
  3008. /* This can induce kickflood - arthur2 */
  3009. dprintf(DP_SERVER, "KICK %s %s :%sthat was fun, let's do it again!\n", chan->name, nick, kickprefix);
  3010. m->flags |= SENTKICK;
  3011. }
  3012. }
  3013. if (!ignoring)
  3014. putlog(LOG_MODES, "*", "Avalanche from %s", from);
  3015. return 0;
  3016. }
  3017. /* Check for CTCP: */
  3018. p = strchr(msg, 1);
  3019. while (p && *p) {
  3020. p++;
  3021. p1 = p;
  3022. while ((*p != 1) && *p)
  3023. p++;
  3024. if (*p == 1) {
  3025. *p = 0;
  3026. ctcp = buf2;
  3027. strlcpy(ctcp, p1, sizeof(buf2));
  3028. strcpy(p1 - 1, p + 1);
  3029. p = strchr(msg, 1);
  3030. if (m) {
  3031. detect_chan_flood(m, from, chan, strncmp(ctcp, "ACTION ", 7) ? FLOOD_CTCP : FLOOD_PRIVMSG);
  3032. detect_chan_flood(m, from, chan, FLOOD_BYTES, msg);
  3033. }
  3034. if (ctcp[0] != ' ') {
  3035. code = newsplit(&ctcp);
  3036. if (!ignoring || trigger_on_ignore) {
  3037. check_bind_ctcr(nick, uhost, u, chan->dname, code, msg);
  3038. chan = findchan(realto);
  3039. if (!chan)
  3040. return 0;
  3041. irc_log(chan, "CTCP reply %s: %s from %s (%s) to %s", code, msg, nick, from, chan->dname);
  3042. update_idle(chan->dname, nick);
  3043. }
  3044. }
  3045. }
  3046. }
  3047. if (msg[0]) {
  3048. if (m) {
  3049. detect_chan_flood(m, from, chan, FLOOD_NOTICE);
  3050. detect_chan_flood(m, from, chan, FLOOD_BYTES, msg);
  3051. }
  3052. update_idle(chan->dname, nick);
  3053. if (!ignoring)
  3054. irc_log(chan, "-%s:%s- %s", nick, to, msg);
  3055. }
  3056. return 0;
  3057. }
  3058. static cmd_t irc_raw[] =
  3059. {
  3060. {"001", "", (Function) got001, "irc:001", LEAF},
  3061. #ifdef CACHE
  3062. {"302", "", (Function) got302, "irc:302", LEAF},
  3063. {"341", "", (Function) got341, "irc:341", LEAF},
  3064. #endif /* CACHE */
  3065. {"324", "", (Function) got324, "irc:324", LEAF},
  3066. {"352", "", (Function) got352, "irc:352", LEAF},
  3067. {"354", "", (Function) got354, "irc:354", LEAF},
  3068. {"315", "", (Function) got315, "irc:315", LEAF},
  3069. {"367", "", (Function) got367, "irc:367", LEAF},
  3070. {"368", "", (Function) got368, "irc:368", LEAF},
  3071. {"403", "", (Function) got403, "irc:403", LEAF},
  3072. {"405", "", (Function) got405, "irc:405", LEAF},
  3073. {"471", "", (Function) got471, "irc:471", LEAF},
  3074. {"473", "", (Function) got473, "irc:473", LEAF},
  3075. {"474", "", (Function) got474, "irc:474", LEAF},
  3076. {"475", "", (Function) got475, "irc:475", LEAF},
  3077. {"478", "", (Function) got478, "irc:478", LEAF},
  3078. {"INVITE", "", (Function) gotinvite, "irc:invite", LEAF},
  3079. {"TOPIC", "", (Function) gottopic, "irc:topic", LEAF},
  3080. {"331", "", (Function) got331, "irc:331", LEAF},
  3081. {"332", "", (Function) got332, "irc:332", LEAF},
  3082. {"JOIN", "", (Function) gotjoin, "irc:join", LEAF},
  3083. {"PART", "", (Function) gotpart, "irc:part", LEAF},
  3084. {"KICK", "", (Function) gotkick, "irc:kick", LEAF},
  3085. {"NICK", "", (Function) gotnick, "irc:nick", LEAF},
  3086. {"QUIT", "", (Function) gotquit, "irc:quit", LEAF},
  3087. {"PRIVMSG", "", (Function) gotmsg, "irc:msg", LEAF},
  3088. {"NOTICE", "", (Function) gotnotice, "irc:notice", LEAF},
  3089. {"MODE", "", (Function) gotmode, "irc:mode", LEAF},
  3090. {"346", "", (Function) got346, "irc:346", LEAF},
  3091. {"347", "", (Function) got347, "irc:347", LEAF},
  3092. {"348", "", (Function) got348, "irc:348", LEAF},
  3093. {"349", "", (Function) got349, "irc:349", LEAF},
  3094. {"353", "", (Function) got353, "irc:353", LEAF},
  3095. {"710", "", (Function) got710, "irc:710", LEAF},
  3096. {NULL, NULL, NULL, NULL, 0}
  3097. };
  3098. /* vim: set sts=2 sw=2 ts=8 et: */