mode.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. #ifdef LEAF
  2. /*
  3. * mode.c -- part of irc.mod
  4. * queuing and flushing mode changes made by the bot
  5. * channel mode changes and the bot's reaction to them
  6. * setting and getting the current wanted channel modes
  7. *
  8. */
  9. /* Reversing this mode? */
  10. static int reversing = 0;
  11. #define PLUS 0x01
  12. #define MINUS 0x02
  13. #define CHOP 0x04
  14. #define BAN 0x08
  15. #define VOICE 0x10
  16. #define EXEMPT 0x20
  17. #define INVITE 0x40
  18. #define CHHOP 0x80
  19. static struct flag_record user = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  20. static struct flag_record victim = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  21. static int do_op(char *nick, struct chanset_t *chan, int force)
  22. {
  23. memberlist *m = ismember(chan, nick);
  24. if (!me_op(chan) || !m || (m && !force && chan_hasop(m)))
  25. return 0;
  26. if (channel_fastop(chan) || channel_take(chan)) {
  27. add_mode(chan, '+', 'o', nick);
  28. } else {
  29. char *tmp = malloc(strlen(chan->name) + 200);
  30. makeopline(chan, nick, tmp);
  31. dprintf(DP_MODE, tmp);
  32. free(tmp);
  33. }
  34. return 1;
  35. }
  36. #define NEW_ADDMODE 1
  37. #ifdef NEW_ADDMODE
  38. void dequeue_op_deop(struct chanset_t * chan);
  39. static void flush_mode(struct chanset_t *chan, int pri)
  40. {
  41. char *p, out[512], post[512];
  42. size_t postsize = sizeof(post);
  43. int i, plus = 2; /* 0 = '-', 1 = '+', 2 = none */
  44. dequeue_op_deop(chan);
  45. p = out;
  46. post[0] = 0, postsize--;
  47. if (chan->pls[0]) {
  48. *p++ = '+', plus = 1;
  49. for (i = 0; i < strlen(chan->pls); i++)
  50. *p++ = chan->pls[i];
  51. chan->pls[0] = 0;
  52. }
  53. if (chan->mns[0]) {
  54. *p++ = '-', plus = 0;
  55. for (i = 0; i < strlen(chan->mns); i++)
  56. *p++ = chan->mns[i];
  57. chan->mns[0] = 0;
  58. }
  59. chan->bytes = 0;
  60. chan->compat = 0;
  61. /* +k or +l ? */
  62. if (chan->key && !chan->rmkey) {
  63. if (plus != 1) {
  64. *p++ = '+', plus = 1;
  65. }
  66. *p++ = 'k';
  67. postsize -= egg_strcatn(post, chan->key, sizeof(post));
  68. postsize -= egg_strcatn(post, " ", sizeof(post));
  69. free(chan->key), chan->key = NULL;
  70. }
  71. /* max +l is signed 2^32 on ircnet at least... so makesure we've got at least
  72. * a 13 char buffer for '-2147483647 \0'. We'll be overwriting the existing
  73. * terminating null in 'post', so makesure postsize >= 12.
  74. */
  75. if (chan->limit != 0 && postsize >= 12) {
  76. if (plus != 1) {
  77. *p++ = '+', plus = 1;
  78. }
  79. *p++ = 'l';
  80. /* 'sizeof(post) - 1' is used because we want to overwrite the old null */
  81. postsize -= sprintf(&post[(sizeof(post) - 1) - postsize], "%d ", chan->limit);
  82. chan->limit = 0;
  83. }
  84. /* -k ? */
  85. if (chan->rmkey) {
  86. if (plus) {
  87. *p++ = '-', plus = 0;
  88. }
  89. *p++ = 'k';
  90. postsize -= egg_strcatn(post, chan->rmkey, sizeof(post));
  91. postsize -= egg_strcatn(post, " ", sizeof(post));
  92. free(chan->rmkey), chan->rmkey = NULL;
  93. }
  94. /* Do -{b,e,I} before +{b,e,I} to avoid the server ignoring overlaps */
  95. for (i = 0; i < modesperline; i++) {
  96. if ((chan->cmode[i].type & MINUS) &&
  97. postsize > strlen(chan->cmode[i].op)) {
  98. if (plus) {
  99. *p++ = '-', plus = 0;
  100. }
  101. *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
  102. ((chan->cmode[i].type & CHOP) ? 'o' :
  103. ((chan->cmode[i].type & CHHOP) ? 'h' :
  104. ((chan->cmode[i].type & EXEMPT) ? 'e' :
  105. ((chan->cmode[i].type & INVITE) ? 'I' : 'v')))));
  106. postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
  107. postsize -= egg_strcatn(post, " ", sizeof(post));
  108. free(chan->cmode[i].op), chan->cmode[i].op = NULL;
  109. chan->cmode[i].type = 0;
  110. }
  111. }
  112. /* now do all the + modes... */
  113. for (i = 0; i < modesperline; i++) {
  114. if ((chan->cmode[i].type & PLUS) &&
  115. postsize > strlen(chan->cmode[i].op)) {
  116. if (plus != 1) {
  117. *p++ = '+', plus = 1;
  118. }
  119. *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
  120. ((chan->cmode[i].type & CHOP) ? 'o' :
  121. ((chan->cmode[i].type & CHHOP) ? 'h' :
  122. ((chan->cmode[i].type & EXEMPT) ? 'e' :
  123. ((chan->cmode[i].type & INVITE) ? 'I' : 'v')))));
  124. postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
  125. postsize -= egg_strcatn(post, " ", sizeof(post));
  126. free(chan->cmode[i].op), chan->cmode[i].op = NULL;
  127. chan->cmode[i].type = 0;
  128. }
  129. }
  130. /* remember to terminate the buffer ('out')... */
  131. *p = 0;
  132. if (post[0]) {
  133. /* remove the trailing space... */
  134. size_t index = (sizeof(post) - 1) - postsize;
  135. if (index > 0 && post[index - 1] == ' ')
  136. post[index - 1] = 0;
  137. egg_strcatn(out, " ", sizeof(out));
  138. egg_strcatn(out, post, sizeof(out));
  139. }
  140. if (out[0]) {
  141. if (pri == QUICK)
  142. dprintf(DP_MODE, "MODE %s %s\n", chan->name, out);
  143. else
  144. dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
  145. }
  146. }
  147. void dequeue_op_deop(struct chanset_t * chan) {
  148. char lines[4096];
  149. char modechars[10];
  150. char nicks[128];
  151. int i = 0, cnt = 0;
  152. lines[0] = 0;
  153. modechars[0] = 0;
  154. nicks[0] = 0;
  155. while ((i < 20) && (chan->opqueue[i].target)) {
  156. strcat(nicks, " ");
  157. strcat(nicks, chan->opqueue[i].target);
  158. if (!modechars[0])
  159. strcat(modechars, " +");
  160. strcat(modechars, "o");
  161. cnt++;
  162. if (!(cnt % 4)) {
  163. strcat(lines, "MODE ");
  164. strcat(lines, chan->name);
  165. strcat(lines, modechars);
  166. strcat(lines, nicks);
  167. strcat(lines, "\n");
  168. modechars[0] = 0;
  169. nicks[0] = 0;
  170. }
  171. free(chan->opqueue[i].target);
  172. chan->opqueue[i].target = NULL;
  173. i++;
  174. }
  175. if (modechars[0] && chan->deopqueue[0].target)
  176. strcat(modechars, "-");
  177. i = 0;
  178. while ((i < 20) && (chan->deopqueue[i].target)) {
  179. strcat(nicks, " ");
  180. strcat(nicks, chan->deopqueue[i].target);
  181. if (!modechars[0])
  182. strcat(modechars, " -");
  183. strcat(modechars, "o");
  184. cnt++;
  185. if (!(cnt % 4)) {
  186. strcat(lines, "MODE ");
  187. strcat(lines, chan->name);
  188. strcat(lines, modechars);
  189. strcat(lines, nicks);
  190. strcat(lines, "\n");
  191. modechars[0] = 0;
  192. nicks[0] = 0;
  193. if (cnt >= 24) {
  194. dprintf(DP_SERVER, lines);
  195. lines[0]=0;
  196. }
  197. }
  198. free(chan->deopqueue[i].target);
  199. chan->deopqueue[i].target = NULL;
  200. i++;
  201. }
  202. if (cnt % 4) {
  203. strcat(lines, "MODE ");
  204. strcat(lines, chan->name);
  205. strcat(lines, modechars);
  206. strcat(lines, nicks);
  207. strcat(lines, "\n");
  208. }
  209. if (lines[0])
  210. dprintf(DP_SERVER, lines);
  211. }
  212. void queue_op(struct chanset_t *chan, char *op) {
  213. int n;
  214. memberlist *m;
  215. for (n = 0; n < 20; n++) {
  216. if (!chan->opqueue[n].target) {
  217. chan->opqueue[n].target = malloc(strlen(op) + 1);
  218. strcpy(chan->opqueue[n].target, op);
  219. m = ismember(chan, op);
  220. if (m)
  221. m->flags |= SENTOP;
  222. if (n == 19)
  223. dequeue_op_deop(chan);
  224. return;
  225. }
  226. }
  227. }
  228. void queue_deop(struct chanset_t *chan, char *op) {
  229. int n;
  230. memberlist *m;
  231. for (n = 0; n<20; n++) {
  232. if (!chan->deopqueue[n].target) {
  233. chan->deopqueue[n].target = malloc(strlen(op)+1);
  234. strcpy(chan->deopqueue[n].target, op);
  235. m = ismember(chan, op);
  236. if (m)
  237. m->flags |= SENTDEOP;
  238. if (n == 19)
  239. dequeue_op_deop(chan);
  240. return;
  241. }
  242. }
  243. }
  244. /* Queue a channel mode change
  245. */
  246. static void real_add_mode(struct chanset_t *chan,
  247. char plus, char mode, char *op)
  248. {
  249. int i, type, modes, l;
  250. masklist *m;
  251. memberlist *mx;
  252. char s[21];
  253. if (!me_op(chan))
  254. return; /* No point in queueing the mode */
  255. if (mode == 'o') {
  256. if (plus=='+')
  257. queue_op(chan, op);
  258. else
  259. queue_deop(chan, op);
  260. return;
  261. }
  262. if (mode == 'v') {
  263. mx = ismember(chan, op);
  264. if (!mx)
  265. return;
  266. if (plus == '-' && mode == 'v') {
  267. if (chan_sentdevoice(mx) || !chan_hasvoice(mx))
  268. return;
  269. mx->flags |= SENTDEVOICE;
  270. }
  271. if (plus == '+' && mode == 'v') {
  272. if (chan_sentvoice(mx) || chan_hasvoice(mx))
  273. return;
  274. mx->flags |= SENTVOICE;
  275. }
  276. }
  277. if (chan->compat == 0) {
  278. if (mode == 'e' || mode == 'I')
  279. chan->compat = 2;
  280. else
  281. chan->compat = 1;
  282. } else if (mode == 'e' || mode == 'I') {
  283. if (prevent_mixing && chan->compat == 1)
  284. flush_mode(chan, NORMAL);
  285. } else if (prevent_mixing && chan->compat == 2)
  286. flush_mode(chan, NORMAL);
  287. if (mode == 'o' || mode == 'h' || mode == 'b' || mode == 'v' || mode == 'e' || mode == 'I') {
  288. type = (plus == '+' ? PLUS : MINUS) |
  289. (mode == 'o' ? CHOP :
  290. (mode == 'h' ? CHHOP :
  291. (mode == 'b' ? BAN :
  292. (mode == 'v' ? VOICE :
  293. (mode == 'e' ? EXEMPT : INVITE)))));
  294. /*
  295. * FIXME: Some networks remove overlapped bans, IrcNet does not
  296. * (poptix/drummer)
  297. *
  298. * Note: On ircnet ischanXXX() should be used, otherwise isXXXed().
  299. */
  300. /* If removing a non-existant mask... */
  301. if ((plus == '-' &&
  302. ((mode == 'b' && !ischanban(chan, op)) ||
  303. (mode == 'e' && !ischanexempt(chan, op)) ||
  304. (mode == 'I' && !ischaninvite(chan, op)))) ||
  305. /* or adding an existant mask... */
  306. (plus == '+' &&
  307. ((mode == 'b' && ischanban(chan, op)) ||
  308. (mode == 'e' && ischanexempt(chan, op)) ||
  309. (mode == 'I' && ischaninvite(chan, op)))))
  310. return; /* ...nuke it */
  311. /* If there are already max_bans bans, max_exempts exemptions,
  312. * max_invites invitations or max_modes +b/+e/+I modes on the
  313. * channel, don't try to add one more.
  314. */
  315. if (plus == '+' && (mode == 'b' || mode == 'e' || mode == 'I')) {
  316. int bans = 0, exempts = 0, invites = 0;
  317. for (m = chan->channel.ban; m && m->mask[0]; m = m->next)
  318. bans++;
  319. if (mode == 'b')
  320. if (bans >= max_bans)
  321. return;
  322. for (m = chan->channel.exempt; m && m->mask[0]; m = m->next)
  323. exempts++;
  324. if (mode == 'e')
  325. if (exempts >= max_exempts)
  326. return;
  327. for (m = chan->channel.invite; m && m->mask[0]; m = m->next)
  328. invites++;
  329. if (mode == 'I')
  330. if (invites >= max_invites)
  331. return;
  332. if (bans + exempts + invites >= max_modes)
  333. return;
  334. }
  335. /* op-type mode change */
  336. for (i = 0; i < modesperline; i++)
  337. if (chan->cmode[i].type == type && chan->cmode[i].op != NULL &&
  338. !rfc_casecmp(chan->cmode[i].op, op))
  339. return; /* Already in there :- duplicate */
  340. l = strlen(op) + 1;
  341. if (chan->bytes + l > mode_buf_len)
  342. flush_mode(chan, NORMAL);
  343. for (i = 0; i < modesperline; i++)
  344. if (chan->cmode[i].type == 0) {
  345. chan->cmode[i].type = type;
  346. chan->cmode[i].op = (char *) malloc(l);
  347. chan->bytes += l; /* Add 1 for safety */
  348. strcpy(chan->cmode[i].op, op);
  349. break;
  350. }
  351. }
  352. /* +k ? store key */
  353. else if (plus == '+' && mode == 'k') {
  354. if (chan->key)
  355. free(chan->key);
  356. chan->key = (char *) malloc(strlen(op) + 1);
  357. if (chan->key)
  358. strcpy(chan->key, op);
  359. }
  360. /* -k ? store removed key */
  361. else if (plus == '-' && mode == 'k') {
  362. if (chan->rmkey)
  363. free(chan->rmkey);
  364. chan->rmkey = (char *) malloc(strlen(op) + 1);
  365. if (chan->rmkey)
  366. strcpy(chan->rmkey, op);
  367. }
  368. /* +l ? store limit */
  369. else if (plus == '+' && mode == 'l')
  370. chan->limit = atoi(op);
  371. else {
  372. /* Typical mode changes */
  373. if (plus == '+')
  374. strcpy(s, chan->pls);
  375. else
  376. strcpy(s, chan->mns);
  377. if (!strchr(s, mode)) {
  378. if (plus == '+') {
  379. chan->pls[strlen(chan->pls) + 1] = 0;
  380. chan->pls[strlen(chan->pls)] = mode;
  381. } else {
  382. chan->mns[strlen(chan->mns) + 1] = 0;
  383. chan->mns[strlen(chan->mns)] = mode;
  384. }
  385. }
  386. }
  387. modes = modesperline; /* Check for full buffer. */
  388. for (i = 0; i < modesperline; i++)
  389. if (chan->cmode[i].type)
  390. modes--;
  391. if (include_lk && chan->limit)
  392. modes--;
  393. if (include_lk && chan->rmkey)
  394. modes--;
  395. if (include_lk && chan->key)
  396. modes--;
  397. if (modes < 1)
  398. flush_mode(chan, NORMAL); /* Full buffer! Flush modes. */
  399. }
  400. #else /* OLD SHIT */
  401. static void flush_mode(struct chanset_t *chan, int pri)
  402. {
  403. char *p, out[512], post[512];
  404. size_t postsize = sizeof(post);
  405. int i, plus = 2; /* 0 = '-', 1 = '+', 2 = none */
  406. p = out;
  407. post[0] = 0, postsize--;
  408. if (chan->mns[0]) {
  409. *p++ = '-', plus = 0;
  410. for (i = 0; i < strlen(chan->mns); i++)
  411. *p++ = chan->mns[i];
  412. chan->mns[0] = 0;
  413. }
  414. if (chan->pls[0]) {
  415. *p++ = '+', plus = 1;
  416. for (i = 0; i < strlen(chan->pls); i++)
  417. *p++ = chan->pls[i];
  418. chan->pls[0] = 0;
  419. }
  420. chan->bytes = 0;
  421. chan->compat = 0;
  422. /* +k or +l ? */
  423. if (chan->key && !chan->rmkey) {
  424. if (plus != 1) {
  425. *p++ = '+', plus = 1;
  426. }
  427. *p++ = 'k';
  428. postsize -= egg_strcatn(post, chan->key, sizeof(post));
  429. postsize -= egg_strcatn(post, " ", sizeof(post));
  430. free(chan->key), chan->key = NULL;
  431. }
  432. /* max +l is signed 2^32 on IRCnet at least... so makesure we've got at least
  433. * a 13 char buffer for '-2147483647 \0'. We'll be overwriting the existing
  434. * terminating null in 'post', so makesure postsize >= 12.
  435. */
  436. if (chan->limit != 0 && postsize >= 12) {
  437. if (plus != 1) {
  438. *p++ = '+', plus = 1;
  439. }
  440. *p++ = 'l';
  441. /* 'sizeof(post) - 1' is used because we want to overwrite the old null */
  442. postsize -=
  443. sprintf(&post[(sizeof(post) - 1) - postsize], "%d ", chan->limit);
  444. chan->limit = 0;
  445. }
  446. /* -k ? */
  447. if (chan->rmkey) {
  448. if (plus) {
  449. *p++ = '-', plus = 0;
  450. }
  451. *p++ = 'k';
  452. postsize -= egg_strcatn(post, chan->rmkey, sizeof(post));
  453. postsize -= egg_strcatn(post, " ", sizeof(post));
  454. free(chan->rmkey), chan->rmkey = NULL;
  455. }
  456. /* Do -{b,e,I} before +{b,e,I} to avoid the server ignoring overlaps */
  457. for (i = 0; i < modesperline; i++) {
  458. if ((chan->cmode[i].type & MINUS) && postsize > strlen(chan->cmode[i].op)) {
  459. if (plus) {
  460. *p++ = '-', plus = 0;
  461. }
  462. *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
  463. ((chan->cmode[i].type & CHOP) ? 'o' :
  464. ((chan->cmode[i].type & EXEMPT) ? 'e' :
  465. ((chan->cmode[i].type & INVITE) ? 'I' : 'v'))));
  466. postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
  467. postsize -= egg_strcatn(post, " ", sizeof(post));
  468. free(chan->cmode[i].op), chan->cmode[i].op = NULL;
  469. chan->cmode[i].type = 0;
  470. }
  471. }
  472. /* now do all the + modes... */
  473. for (i = 0; i < modesperline; i++) {
  474. if ((chan->cmode[i].type & PLUS) && postsize > strlen(chan->cmode[i].op)) {
  475. if (plus != 1) {
  476. *p++ = '+', plus = 1;
  477. }
  478. *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
  479. ((chan->cmode[i].type & CHOP) ? 'o' :
  480. ((chan->cmode[i].type & EXEMPT) ? 'e' :
  481. ((chan->cmode[i].type & INVITE) ? 'I' : 'v'))));
  482. postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
  483. postsize -= egg_strcatn(post, " ", sizeof(post));
  484. free(chan->cmode[i].op), chan->cmode[i].op = NULL;
  485. chan->cmode[i].type = 0;
  486. }
  487. }
  488. /* remember to terminate the buffer ('out')... */
  489. *p = 0;
  490. if (post[0]) {
  491. /* remove the trailing space... */
  492. size_t index = (sizeof(post) - 1) - postsize;
  493. if (index > 0 && post[index - 1] == ' ')
  494. post[index - 1] = 0;
  495. egg_strcatn(out, " ", sizeof(out));
  496. egg_strcatn(out, post, sizeof(out));
  497. }
  498. if (out[0]) {
  499. if (pri == QUICK)
  500. dprintf(DP_MODE, "MODE %s %s\n", chan->name, out);
  501. else
  502. dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
  503. }
  504. }
  505. /* Queue a channel mode change
  506. */
  507. static void real_add_mode(struct chanset_t *chan,
  508. char plus, char mode, char *op)
  509. {
  510. int i, type, modes, l;
  511. masklist *m;
  512. memberlist *mx;
  513. char s[21];
  514. /* Some IRCds do not allow halfops to set certian modes. The modes halfops
  515. * are not allowed to set can be changed in chan.h. */
  516. if (!me_op(chan))
  517. return;
  518. if (mode == 'o' || mode == 'h' || mode == 'v') {
  519. mx = ismember(chan, op);
  520. if (!mx)
  521. return;
  522. if (plus == '-' && mode == 'o') {
  523. if (chan_sentdeop(mx) || !chan_hasop(mx))
  524. return;
  525. mx->flags |= SENTDEOP;
  526. }
  527. if (plus == '+' && mode == 'o') {
  528. if (chan_sentop(mx) || chan_hasop(mx))
  529. return;
  530. mx->flags |= SENTOP;
  531. }
  532. if (plus == '-' && mode == 'v') {
  533. if (chan_sentdevoice(mx) || !chan_hasvoice(mx))
  534. return;
  535. mx->flags |= SENTDEVOICE;
  536. }
  537. if (plus == '+' && mode == 'v') {
  538. if (chan_sentvoice(mx) || chan_hasvoice(mx))
  539. return;
  540. mx->flags |= SENTVOICE;
  541. }
  542. }
  543. if (chan->compat == 0) {
  544. if (mode == 'e' || mode == 'I')
  545. chan->compat = 2;
  546. else
  547. chan->compat = 1;
  548. } else if (mode == 'e' || mode == 'I') {
  549. if (prevent_mixing && chan->compat == 1)
  550. flush_mode(chan, NORMAL);
  551. } else if (prevent_mixing && chan->compat == 2)
  552. flush_mode(chan, NORMAL);
  553. if (mode == 'o' || mode == 'b' || mode == 'v' || mode == 'e' || mode == 'I') {
  554. type = (plus == '+' ? PLUS : MINUS) | (mode == 'o' ? CHOP : (mode == 'b' ?
  555. BAN : (mode == 'v' ? VOICE : (mode == 'e' ? EXEMPT : INVITE))));
  556. /*
  557. * FIXME: Some networks remove overlapped bans,
  558. * IRCnet does not (poptix/drummer)
  559. *
  560. * Note: On IRCnet ischanXXX() should be used, otherwise isXXXed().
  561. */
  562. if ((plus == '-' && ((mode == 'b' && !ischanban(chan, op)) ||
  563. (mode == 'e' && !ischanexempt(chan, op)) ||
  564. (mode == 'I' && !ischaninvite(chan, op)))) || (plus == '+' &&
  565. ((mode == 'b' && ischanban(chan, op)) ||
  566. (mode == 'e' && ischanexempt(chan, op)) ||
  567. (mode == 'I' && ischaninvite(chan, op)))))
  568. return;
  569. /* If there are already max_bans bans, max_exempts exemptions,
  570. * max_invites invitations or max_modes +b/+e/+I modes on the
  571. * channel, don't try to add one more.
  572. */
  573. if (plus == '+' && (mode == 'b' || mode == 'e' || mode == 'I')) {
  574. int bans = 0, exempts = 0, invites = 0;
  575. for (m = chan->channel.ban; m && m->mask[0]; m = m->next)
  576. bans++;
  577. if ((mode == 'b') && (bans >= max_bans))
  578. return;
  579. for (m = chan->channel.exempt; m && m->mask[0]; m = m->next)
  580. exempts++;
  581. if ((mode == 'e') && (exempts >= max_exempts))
  582. return;
  583. for (m = chan->channel.invite; m && m->mask[0]; m = m->next)
  584. invites++;
  585. if ((mode == 'I') && (invites >= max_invites))
  586. return;
  587. if (bans + exempts + invites >= max_modes)
  588. return;
  589. }
  590. /* op-type mode change */
  591. for (i = 0; i < modesperline; i++)
  592. if (chan->cmode[i].type == type && chan->cmode[i].op != NULL &&
  593. !rfc_casecmp(chan->cmode[i].op, op))
  594. return; /* Already in there :- duplicate */
  595. l = strlen(op) + 1;
  596. if (chan->bytes + l > mode_buf_len)
  597. flush_mode(chan, NORMAL);
  598. for (i = 0; i < modesperline; i++)
  599. if (chan->cmode[i].type == 0) {
  600. chan->cmode[i].type = type;
  601. chan->cmode[i].op = (char *) malloc(l);
  602. chan->bytes += l; /* Add 1 for safety */
  603. strcpy(chan->cmode[i].op, op);
  604. break;
  605. }
  606. }
  607. /* +k ? store key */
  608. else if (plus == '+' && mode == 'k') {
  609. if (chan->key)
  610. free(chan->key);
  611. chan->key = (char *) malloc(strlen(op) + 1);
  612. if (chan->key)
  613. strcpy(chan->key, op);
  614. }
  615. /* -k ? store removed key */
  616. else if (plus == '-' && mode == 'k') {
  617. if (chan->rmkey)
  618. free(chan->rmkey);
  619. chan->rmkey = (char *) malloc(strlen(op) + 1);
  620. if (chan->rmkey)
  621. strcpy(chan->rmkey, op);
  622. }
  623. /* +l ? store limit */
  624. else if (plus == '+' && mode == 'l')
  625. chan->limit = atoi(op);
  626. else {
  627. /* Typical mode changes */
  628. if (plus == '+')
  629. strcpy(s, chan->pls);
  630. else
  631. strcpy(s, chan->mns);
  632. if (!strchr(s, mode)) {
  633. if (plus == '+') {
  634. chan->pls[strlen(chan->pls) + 1] = 0;
  635. chan->pls[strlen(chan->pls)] = mode;
  636. } else {
  637. chan->mns[strlen(chan->mns) + 1] = 0;
  638. chan->mns[strlen(chan->mns)] = mode;
  639. }
  640. }
  641. }
  642. modes = modesperline; /* Check for full buffer. */
  643. for (i = 0; i < modesperline; i++)
  644. if (chan->cmode[i].type)
  645. modes--;
  646. if (include_lk && chan->limit)
  647. modes--;
  648. if (include_lk && chan->rmkey)
  649. modes--;
  650. if (include_lk && chan->key)
  651. modes--;
  652. if (modes < 1)
  653. flush_mode(chan, NORMAL); /* Full buffer! Flush modes. */
  654. }
  655. #endif /* NEW_ADDMODE */
  656. /*
  657. * Mode parsing functions
  658. */
  659. static void got_key(struct chanset_t *chan, char *nick, char *from,
  660. char *key)
  661. {
  662. if ((!nick[0]) && (bounce_modes))
  663. reversing = 1;
  664. if (((reversing) && !(chan->key_prot[0])) ||
  665. ((chan->mode_mns_prot & CHANKEY) &&
  666. !(glob_master(user) || glob_bot(user) || chan_master(user)))) {
  667. if (strlen(key) != 0) {
  668. add_mode(chan, '-', 'k', key);
  669. } else {
  670. add_mode(chan, '-', 'k', "");
  671. }
  672. }
  673. }
  674. static void got_op(struct chanset_t *chan, char *nick, char *from,
  675. char *who, struct userrec *opu, struct flag_record *opper)
  676. {
  677. memberlist *m;
  678. char s[UHOSTLEN];
  679. struct userrec *u;
  680. int check_chan = 0;
  681. int snm = chan->stopnethack_mode;
  682. m = ismember(chan, who);
  683. if (!m) {
  684. if (channel_pending(chan))
  685. return;
  686. putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, who);
  687. dprintf(DP_MODE, "WHO %s\n", who);
  688. return;
  689. }
  690. /* Did *I* just get opped? */
  691. if (!me_op(chan) && match_my_nick(who))
  692. check_chan = 1;
  693. if (!m->user) {
  694. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  695. u = get_user_by_host(s);
  696. } else
  697. u = m->user;
  698. get_user_flagrec(u, &victim, chan->dname);
  699. /* Flags need to be set correctly right from the beginning now, so that
  700. * add_mode() doesn't get irritated.
  701. */
  702. m->flags |= CHANOP;
  703. /* Added new meaning of WASOP:
  704. * in mode binds it means: was he op before get (de)opped
  705. * (stupid IrcNet allows opped users to be opped again and
  706. * opless users to be deopped)
  707. * script now can use [wasop nick chan] proc to check
  708. * if user was op or wasnt (drummer)
  709. */
  710. m->flags &= ~SENTOP;
  711. if (channel_pending(chan))
  712. return;
  713. /* I'm opped, and the opper isn't me */
  714. if (me_op(chan) && !match_my_nick(who) &&
  715. /* and it isn't a server op */
  716. nick[0]) {
  717. /* Channis is +bitch, and the opper isn't a global master or a bot */
  718. /* deop if they are +d or it is +bitch */
  719. if ( chk_deop(victim, chan) ||
  720. (!loading && userlist && channel_bitch(chan) && !chk_op(victim, chan)) ) { /* chk_op covers +private */
  721. /* if (target_priority(chan, m, 1)) */
  722. // dprintf(DP_MODE, "MODE %s -o %s\n", chan->dname, who);
  723. add_mode(chan, '-', 'o', who);
  724. flush_mode(chan, QUICK);
  725. } else if (reversing) {
  726. add_mode(chan, '-', 'o', who);
  727. }
  728. } else if (reversing && !match_my_nick(who))
  729. add_mode(chan, '-', 'o', who);
  730. if (!nick[0] && me_op(chan) && !match_my_nick(who)) {
  731. if (chk_deop(victim, chan)) {
  732. m->flags |= FAKEOP;
  733. add_mode(chan, '-', 'o', who);
  734. } else if (snm > 0 && snm < 7 && !((0 || 0 ||
  735. 0) && (chan_op(victim) || (glob_op(victim) &&
  736. !chan_deop(victim)))) && !glob_exempt(victim) && !chan_exempt(victim)) {
  737. if (snm == 5) snm = channel_bitch(chan) ? 1 : 3;
  738. if (snm == 6) snm = channel_bitch(chan) ? 4 : 2;
  739. if (chan_wasoptest(victim) || glob_wasoptest(victim) ||
  740. snm == 2) {
  741. if (!chan_wasop(m)) {
  742. m->flags |= FAKEOP;
  743. add_mode(chan, '-', 'o', who);
  744. }
  745. } else if (!(chan_op(victim) ||
  746. (glob_op(victim) && !chan_deop(victim)))) {
  747. if (snm == 1 || snm == 4 || (snm == 3 && !chan_wasop(m))) {
  748. add_mode(chan, '-', 'o', who);
  749. m->flags |= FAKEOP;
  750. }
  751. } else if (snm == 4 && !chan_wasop(m)) {
  752. add_mode(chan, '-', 'o', who);
  753. m->flags |= FAKEOP;
  754. }
  755. }
  756. }
  757. m->flags |= WASOP;
  758. if (check_chan) {
  759. /* tell other bots to set jointime to 0 and join */
  760. char *buf = malloc(strlen(chan->dname) + 3 + 1);
  761. sprintf(buf, "jn %s", chan->dname);
  762. putallbots(buf);
  763. free(buf);
  764. recheck_channel(chan, 1);
  765. }
  766. }
  767. static void got_deop(struct chanset_t *chan, char *nick, char *from,
  768. char *who, struct userrec *opu)
  769. {
  770. memberlist *m;
  771. char s[UHOSTLEN], s1[UHOSTLEN];
  772. struct userrec *u;
  773. m = ismember(chan, who);
  774. if (!m) {
  775. if (channel_pending(chan))
  776. return;
  777. putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, who);
  778. dprintf(DP_MODE, "WHO %s\n", who);
  779. return;
  780. }
  781. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  782. simple_sprintf(s1, "%s!%s", nick, from);
  783. u = get_user_by_host(s);
  784. get_user_flagrec(u, &victim, chan->dname);
  785. /* Flags need to be set correctly right from the beginning now, so that
  786. * add_mode() doesn't get irritated.
  787. */
  788. m->flags &= ~(CHANOP | SENTDEOP | FAKEOP);
  789. /* Check comments in got_op() (drummer) */
  790. m->flags &= ~WASOP;
  791. if (channel_pending(chan))
  792. return;
  793. /* Deop'd someone on my oplist? */
  794. if (me_op(chan)) {
  795. int ok = 1;
  796. /* if they aren't d|d then check if they are something we should protect */
  797. if (!glob_deop(victim) && !chan_deop(victim)) {
  798. if (channel_protectops(chan) && (glob_master(victim) || chan_master(victim) ||
  799. glob_op(victim) || chan_op(victim)))
  800. ok = 0;
  801. }
  802. /* do we want to reop victim? */
  803. if ((reversing || !ok) && !match_my_nick(nick) &&
  804. rfc_casecmp(who, nick) && !match_my_nick(who) &&
  805. /* Is the deopper NOT a master or bot? */
  806. !glob_master(user) && !chan_master(user) && !glob_bot(user) &&
  807. ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) ||
  808. !channel_bitch(chan)))
  809. /* Then we'll bless the victim */
  810. do_op(who, chan, 0);
  811. }
  812. if (!nick[0])
  813. putlog(LOG_MODES, chan->dname, "TS resync (%s): %s deopped by %s",
  814. chan->dname, who, from);
  815. /* Check for mass deop */
  816. if (nick[0])
  817. detect_chan_flood(nick, from, s1, chan, FLOOD_DEOP, who);
  818. /* Having op hides your +v and +h status -- so now that someone's lost ops,
  819. * check to see if they have +v or +h
  820. */
  821. if (!(m->flags & (CHANVOICE | STOPWHO))) {
  822. dprintf(DP_HELP, "WHO %s\n", m->nick);
  823. m->flags |= STOPWHO;
  824. }
  825. /* Was the bot deopped? */
  826. if (match_my_nick(who)) {
  827. /* Cancel any pending kicks and modes */
  828. memberlist *m2;
  829. for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
  830. m2->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTVOICE | SENTDEVOICE);
  831. chan->channel.do_opreq=1;
  832. // request_op(chan);
  833. /* need: op */
  834. if (!nick[0])
  835. putlog(LOG_MODES, chan->dname, "TS resync deopped me on %s :(",
  836. chan->dname);
  837. }
  838. if (nick[0])
  839. maybe_revenge(chan, s1, s, REVENGE_DEOP);
  840. }
  841. static void got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
  842. {
  843. char me[UHOSTLEN], s[UHOSTLEN], s1[UHOSTLEN];
  844. memberlist *m;
  845. struct userrec *u;
  846. egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
  847. egg_snprintf(s, sizeof s, "%s!%s", nick, from);
  848. newban(chan, who, s);
  849. if (channel_pending(chan) || !me_op(chan))
  850. return;
  851. if (wild_match(who, me) && !isexempted(chan, me)) {
  852. add_mode(chan, '-', 'b', who);
  853. reversing = 1;
  854. return;
  855. }
  856. if (!match_my_nick(nick)) {
  857. if (channel_nouserbans(chan) && nick[0] && !glob_bot(user) &&
  858. !glob_master(user) && !chan_master(user)) {
  859. add_mode(chan, '-', 'b', who);
  860. return;
  861. }
  862. /* remove bans on ops unless a master/bot set it */
  863. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  864. egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
  865. if (wild_match(who, s1)) {
  866. u = get_user_by_host(s1);
  867. if (u) {
  868. get_user_flagrec(u, &victim, chan->dname);
  869. if (chk_op(victim, chan) && !chan_master(user) && !glob_master(user) &&
  870. !glob_bot(user) && !isexempted(chan, s1)) {
  871. /* if (target_priority(chan, m, 0)) */
  872. add_mode(chan, '-', 'b', who);
  873. return;
  874. }
  875. }
  876. }
  877. }
  878. }
  879. refresh_exempt(chan, who);
  880. /* This looks for bans added through bot and tacks on banned: if a description is found */
  881. if (nick[0] && channel_enforcebans(chan)) {
  882. register maskrec *b;
  883. int cycle;
  884. char resn[512]="";
  885. /* The point of this cycle crap is to first check chan->bans then global_bans */
  886. for (cycle = 0; cycle < 2; cycle++) {
  887. for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
  888. if (wild_match(b->mask, who)) {
  889. if (b->desc && b->desc[0] != '@')
  890. egg_snprintf(resn, sizeof resn, "%s %s", IRC_PREBANNED, b->desc);
  891. else
  892. resn[0] = 0;
  893. }
  894. }
  895. }
  896. kick_all(chan, who, resn[0] ? resn : kickreason(KICK_BANNED), match_my_nick(nick) ? 0 : 1);
  897. }
  898. if (!nick[0] && (bounce_bans || bounce_modes) &&
  899. (!u_equals_mask(global_bans, who) || !u_equals_mask(chan->bans, who)))
  900. add_mode(chan, '-', 'b', who);
  901. }
  902. static void got_unban(struct chanset_t *chan, char *nick, char *from,
  903. char *who, struct userrec *u)
  904. {
  905. masklist *b, *old;
  906. old = NULL;
  907. for (b = chan->channel.ban; b->mask[0] && rfc_casecmp(b->mask, who);
  908. old = b, b = b->next)
  909. ;
  910. if (b->mask[0]) {
  911. if (old)
  912. old->next = b->next;
  913. else
  914. chan->channel.ban = b->next;
  915. free(b->mask);
  916. free(b->who);
  917. free(b);
  918. }
  919. if (channel_pending(chan))
  920. return;
  921. if (u_sticky_mask(chan->bans, who) || u_sticky_mask(global_bans, who)) {
  922. /* That's a sticky ban! No point in being
  923. * sticky unless we enforce it!!
  924. */
  925. add_mode(chan, '+', 'b', who);
  926. }
  927. if ((u_equals_mask(global_bans, who) || u_equals_mask(chan->bans, who)) &&
  928. me_op(chan) && !channel_dynamicbans(chan)) {
  929. /* That's a permban! */
  930. if ((!glob_bot(user) || !(bot_flags(u) & BOT_SHARE)) && ((!glob_op(user) ||
  931. chan_deop(user)) && !chan_op(user)))
  932. add_mode(chan, '+', 'b', who);
  933. }
  934. }
  935. static void got_exempt(struct chanset_t *chan, char *nick, char *from,
  936. char *who)
  937. {
  938. char s[UHOSTLEN];
  939. simple_sprintf(s, "%s!%s", nick, from);
  940. newexempt(chan, who, s);
  941. if (channel_pending(chan))
  942. return;
  943. if (!match_my_nick(nick)) { /* It's not my exemption */
  944. if (channel_nouserexempts(chan) && nick[0] && !glob_bot(user) &&
  945. !glob_master(user) && !chan_master(user)) {
  946. /* No exempts made by users */
  947. add_mode(chan, '-', 'e', who);
  948. return;
  949. }
  950. if (!nick[0] && bounce_modes)
  951. reversing = 1;
  952. }
  953. if (reversing || (bounce_exempts && !nick[0] &&
  954. (!u_equals_mask(global_exempts, who) ||
  955. !u_equals_mask(chan->exempts, who))))
  956. add_mode(chan, '-', 'e', who);
  957. }
  958. static void got_unexempt(struct chanset_t *chan, char *nick, char *from,
  959. char *who, struct userrec *u)
  960. {
  961. masklist *e = chan->channel.exempt, *old = NULL;
  962. masklist *b ;
  963. int match = 0;
  964. while (e && e->mask[0] && rfc_casecmp(e->mask, who)) {
  965. old = e;
  966. e = e->next;
  967. }
  968. if (e && e->mask[0]) {
  969. if (old)
  970. old->next = e->next;
  971. else
  972. chan->channel.exempt = e->next;
  973. free(e->mask);
  974. free(e->who);
  975. free(e);
  976. }
  977. if (channel_pending(chan))
  978. return;
  979. if (u_sticky_mask(chan->exempts, who) || u_sticky_mask(global_exempts, who)) {
  980. /* That's a sticky exempt! No point in being sticky unless we enforce it!!
  981. */
  982. add_mode(chan, '+', 'e', who);
  983. }
  984. /* If exempt was removed by master then leave it else check for bans */
  985. if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)) {
  986. b = chan->channel.ban;
  987. while (b->mask[0] && !match) {
  988. if (wild_match(b->mask, who) ||
  989. wild_match(who, b->mask)) {
  990. add_mode(chan, '+', 'e', who);
  991. match = 1;
  992. } else
  993. b = b->next;
  994. }
  995. }
  996. if ((u_equals_mask(global_exempts, who) || u_equals_mask(chan->exempts, who)) &&
  997. me_op(chan) && !channel_dynamicexempts(chan)) {
  998. /* That's a permexempt! */
  999. if (glob_bot(user) && (bot_flags(u) & BOT_SHARE)) {
  1000. /* Sharebot -- do nothing */
  1001. } else
  1002. add_mode(chan, '+', 'e', who);
  1003. }
  1004. }
  1005. static void got_invite(struct chanset_t *chan, char *nick, char *from,
  1006. char *who)
  1007. {
  1008. char s[UHOSTLEN];
  1009. simple_sprintf(s, "%s!%s", nick, from);
  1010. newinvite(chan, who, s);
  1011. if (channel_pending(chan))
  1012. return;
  1013. if (!match_my_nick(nick)) { /* It's not my invitation */
  1014. if (channel_nouserinvites(chan) && nick[0] && !glob_bot(user) &&
  1015. !glob_master(user) && !chan_master(user)) {
  1016. /* No exempts made by users */
  1017. add_mode(chan, '-', 'I', who);
  1018. return;
  1019. }
  1020. if ((!nick[0]) && (bounce_modes))
  1021. reversing = 1;
  1022. }
  1023. if (reversing || (bounce_invites && (!nick[0]) &&
  1024. (!u_equals_mask(global_invites, who) ||
  1025. !u_equals_mask(chan->invites, who))))
  1026. add_mode(chan, '-', 'I', who);
  1027. }
  1028. static void got_uninvite(struct chanset_t *chan, char *nick, char *from,
  1029. char *who, struct userrec *u)
  1030. {
  1031. masklist *inv = chan->channel.invite, *old = NULL;
  1032. while (inv->mask[0] && rfc_casecmp(inv->mask, who)) {
  1033. old = inv;
  1034. inv = inv->next;
  1035. }
  1036. if (inv->mask[0]) {
  1037. if (old)
  1038. old->next = inv->next;
  1039. else
  1040. chan->channel.invite = inv->next;
  1041. free(inv->mask);
  1042. free(inv->who);
  1043. free(inv);
  1044. }
  1045. if (channel_pending(chan))
  1046. return;
  1047. if (u_sticky_mask(chan->invites, who) || u_sticky_mask(global_invites, who)) {
  1048. /* That's a sticky invite! No point in being sticky unless we enforce it!!
  1049. */
  1050. add_mode(chan, '+', 'I', who);
  1051. }
  1052. if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)
  1053. && (chan->channel.mode & CHANINV))
  1054. add_mode(chan, '+', 'I', who);
  1055. if ((u_equals_mask(global_invites, who) ||
  1056. u_equals_mask(chan->invites, who)) && me_op(chan) &&
  1057. !channel_dynamicinvites(chan)) {
  1058. /* That's a perminvite! */
  1059. if (glob_bot(user) && (bot_flags(u) & BOT_SHARE)) {
  1060. /* Sharebot -- do nothing */
  1061. } else
  1062. add_mode(chan, '+', 'I', who);
  1063. }
  1064. }
  1065. static int gotmode(char *from, char *msg)
  1066. {
  1067. char *nick, *ch, *op, *chg;
  1068. char s[UHOSTLEN];
  1069. char ms2[3];
  1070. int z;
  1071. struct userrec *u;
  1072. memberlist *m;
  1073. struct chanset_t *chan;
  1074. /* Usermode changes? */
  1075. if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
  1076. ch = newsplit(&msg);
  1077. if (match_my_nick(ch))
  1078. return 0;
  1079. chan = findchan(ch);
  1080. if (!chan) {
  1081. putlog(LOG_MISC, "*", CHAN_FORCEJOIN, ch);
  1082. dprintf(DP_SERVER, "PART %s\n", ch);
  1083. return 0;
  1084. }
  1085. /* let's pre-emptively check for mass op/deop, manual ops and cookieops */
  1086. if (strchr(from, '!')) {
  1087. char *modes[5] = { NULL, NULL, NULL, NULL, NULL };
  1088. char tmp[1024], sign = '+', *nfrom, *hfrom, *wptr, *p, work[1024];
  1089. struct userrec *ufrom = NULL;
  1090. memberlist *m;
  1091. int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0;
  1092. /* Split up the mode: #chan modes param param param param */
  1093. strncpyz(work, msg, sizeof(work));
  1094. wptr = work;
  1095. p = newsplit(&wptr);
  1096. while (*p) {
  1097. char *mp;
  1098. if (*p == '+')
  1099. sign = '+';
  1100. else if (*p == '-')
  1101. sign = '-';
  1102. else if (strchr(STR("oblkvIe"), p[0])) {
  1103. mp = newsplit(&wptr);
  1104. if (strchr("ob", p[0])) {
  1105. /* Just want o's and b's */
  1106. modes[modecnt] = malloc(strlen(mp) + 4);
  1107. sprintf(modes[modecnt], STR("%c%c %s"), sign, p[0], mp);
  1108. modecnt++;
  1109. if (p[0] == 'o') {
  1110. if (sign == '+')
  1111. ops++;
  1112. else
  1113. deops++;
  1114. }
  1115. if (p[0] == 'b') {
  1116. if (sign == '+')
  1117. bans++;
  1118. else
  1119. unbans++;
  1120. }
  1121. }
  1122. } else if (strchr(STR("pstnmi"), p[0])) {
  1123. } else {
  1124. /* hrmm... what modechar did i forget? */
  1125. putlog(LOG_ERRORS, "*", STR("Forgotten modechar in irc:gotmode: %c"), p[0]);
  1126. }
  1127. p++;
  1128. }
  1129. /* Split up from */
  1130. ufrom = get_user_by_host(from);
  1131. strncpyz(work, from, sizeof(work));
  1132. p = strchr(work, '!');
  1133. *p++ = 0;
  1134. nfrom = work; /* nick */
  1135. hfrom = p; /* host */
  1136. /* Now we got modes[], chan, ufrom, nfrom, hfrom, and count of each relevant mode */
  1137. /* check for mdop */
  1138. if ((chan) && (deops >= 3) && me_op(chan)) {
  1139. if ((!ufrom) || (!(ufrom->flags & USER_BOT))) {
  1140. if (ROLE_KICK_MDOP) {
  1141. m = ismember(chan, nfrom);
  1142. if (m && !chan_sentkick(m)) {
  1143. m->flags |= SENTKICK;
  1144. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MASSDEOP));
  1145. tputs(servi, tmp, strlen(tmp));
  1146. if (ufrom) {
  1147. sprintf(tmp, STR("Mass deop on %s by %s"), chan->dname, nfrom);
  1148. deflag_user(ufrom, DEFLAG_MDOP, tmp, chan);
  1149. }
  1150. }
  1151. }
  1152. }
  1153. }
  1154. /* check for mop */
  1155. if (chan && (ops >= 3) && me_op(chan)) {
  1156. if (channel_nomop(chan)) {
  1157. if ((!ufrom) || (!(ufrom->flags & USER_BOT))) {
  1158. if (ROLE_KICK_MDOP) {
  1159. m = ismember(chan, nfrom);
  1160. if (m && !chan_sentkick(m)) {
  1161. m->flags |= SENTKICK;
  1162. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MANUALOP));
  1163. tputs(servi, tmp, strlen(tmp));
  1164. if (ufrom) {
  1165. sprintf(tmp, STR("Mass op on %s by %s"), chan->dname, nfrom);
  1166. deflag_user(ufrom, DEFLAG_MOP, tmp, chan);
  1167. }
  1168. }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. if (chan && me_op(chan) && ops && (ufrom) && (ufrom->flags & USER_BOT) && !channel_fastop(chan) && !channel_take(chan)) {
  1174. int isbadop = 0;
  1175. if ((modecnt != 2) || (strncmp(modes[0], "+o", 2)) ||
  1176. (strncmp(modes[1], "-b", 2))) {
  1177. isbadop = 1;
  1178. } else {
  1179. char enccookie[25], plaincookie[25], key[NICKLEN + 20], goodcookie[25];
  1180. /* -b *!*@[...] */
  1181. strncpyz(enccookie, (char *) &(modes[1][8]), sizeof(enccookie));
  1182. p = enccookie + strlen(enccookie) - 1;
  1183. /* old shit
  1184. *p = 0;
  1185. while (p - enccookie < 24) {
  1186. *p++ = '.';
  1187. *p = 0;
  1188. }
  1189. */
  1190. strcpy(key, nfrom);
  1191. strcat(key, SALT2);
  1192. /* putlog(LOG_DEBUG, "*", "Decrypting cookie: %s with key %s", enccookie, key); */
  1193. p = decrypt_string(key, enccookie);
  1194. /* putlog(LOG_DEBUG, "*", "Decrypted cookie: %s", p); */
  1195. strncpyz(plaincookie, p, sizeof(plaincookie));
  1196. free(p);
  1197. /*
  1198. * last 6 digits of time
  1199. * last 5 chars of nick
  1200. * last 5 regular chars of chan
  1201. */
  1202. makeplaincookie(chan->dname, (char *) (modes[0] + 3), goodcookie);
  1203. /* putlog(LOG_DEBUG, "*", "cookie from %s: %s should be: %s", nfrom, plaincookie, goodcookie); */
  1204. if (strncmp((char *) &plaincookie[6], (char *) &goodcookie[6], 5))
  1205. isbadop = 2;
  1206. else if (strncmp((char *) &plaincookie[11], (char *) &goodcookie[11], 5))
  1207. isbadop = 3;
  1208. else {
  1209. char ltmp[20];
  1210. long optime;
  1211. int off;
  1212. sprintf(ltmp, STR("%010li"), (now + timesync));
  1213. strncpyz((char *) &ltmp[4], plaincookie, 7);
  1214. optime = atol(ltmp);
  1215. off = (now + timesync - optime);
  1216. if (abs(off) > OP_TIME_SLACK) {
  1217. /* isbadop = 4; */
  1218. putlog(LOG_DEBUG, "*", "%s opped with bad ts (not punishing.): %li was off by %li", nfrom, optime, off);
  1219. }
  1220. }
  1221. }
  1222. if (isbadop) {
  1223. char trg[NICKLEN] = "";
  1224. n = i = 0;
  1225. switch (role) {
  1226. case 0:
  1227. break;
  1228. case 1:
  1229. /* Kick opper */
  1230. m = ismember(chan, nfrom);
  1231. if (!m || !chan_sentkick(m)) {
  1232. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_BADOP));
  1233. tputs(servi, tmp, strlen(tmp));
  1234. if (m)
  1235. m->flags |= SENTKICK;
  1236. }
  1237. sprintf(tmp, STR("%s MODE %s"), from, msg);
  1238. deflag_user(ufrom, DEFLAG_BADCOOKIE, tmp, chan);
  1239. break;
  1240. default:
  1241. n = role - 1;
  1242. i = 0;
  1243. while ((i < 5) && (n > 0)) {
  1244. if (modes[i] && !strncmp(modes[i], "+o", 2))
  1245. n--;
  1246. if (n)
  1247. i++;
  1248. }
  1249. if (!n) {
  1250. strncpyz(trg, (char *) &modes[i][3], NICKLEN);
  1251. m = ismember(chan, trg);
  1252. if (m) {
  1253. if (!(m->flags & CHANOP)) {
  1254. if (!chan_sentkick(m)) {
  1255. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_BADOPPED));
  1256. tputs(servi, tmp, strlen(tmp));
  1257. m->flags |= SENTKICK;
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. if (isbadop == 1)
  1264. putlog(LOG_WARN, "*", STR("Missing cookie: %s MODE %s"), from, msg);
  1265. else if (isbadop == 2)
  1266. putlog(LOG_WARN, "*", STR("Invalid cookie (bad nick): %s MODE %s"), from, msg);
  1267. else if (isbadop == 3)
  1268. putlog(LOG_WARN, "*", STR("Invalid cookie (bad chan): %s MODE %s"), from, msg);
  1269. else if (isbadop == 4)
  1270. putlog(LOG_WARN, "*", STR("Invalid cookie (bad time): %s MODE %s"), from, msg);
  1271. } else
  1272. putlog(LOG_DEBUG, "@", STR("Good op: %s"), msg);
  1273. }
  1274. if ((ops) && chan && me_op(chan) && !channel_manop(chan) && (ufrom) &&
  1275. !(ufrom->flags & USER_BOT)) {
  1276. char trg[NICKLEN] = "";
  1277. n = i = 0;
  1278. switch (role) {
  1279. case 0:
  1280. break;
  1281. case 1:
  1282. /* Kick opper */
  1283. m = ismember(chan, nfrom);
  1284. if (!m || !chan_sentkick(m)) {
  1285. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MANUALOP));
  1286. tputs(servi, tmp, strlen(tmp));
  1287. if (m)
  1288. m->flags |= SENTKICK;
  1289. }
  1290. sprintf(tmp, STR("%s MODE %s"), from, msg);
  1291. deflag_user(ufrom, DEFLAG_MANUALOP, tmp, chan);
  1292. break;
  1293. default:
  1294. n = role - 1;
  1295. i = 0;
  1296. while ((i < 5) && (n > 0)) {
  1297. if (modes[i] && !strncmp(modes[i], "+o", 2))
  1298. n--;
  1299. if (n)
  1300. i++;
  1301. }
  1302. if (!n) {
  1303. strncpyz(trg, (char *) &modes[i][3], NICKLEN);
  1304. m = ismember(chan, trg);
  1305. if (m) {
  1306. if (!(m->flags & CHANOP) && (rfc_casecmp(botname, trg))) {
  1307. if (!chan_sentkick(m)) {
  1308. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_MANUALOPPED));
  1309. tputs(servi, tmp, strlen(tmp));
  1310. m->flags |= SENTKICK;
  1311. }
  1312. }
  1313. } else {
  1314. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_MANUALOPPED));
  1315. tputs(servi, tmp, strlen(tmp));
  1316. }
  1317. }
  1318. }
  1319. }
  1320. for (i = 0; i < 5; i++)
  1321. if (modes[i])
  1322. free(modes[i]);
  1323. }
  1324. /* Now do the modes again, this time throughly... */
  1325. chg = newsplit(&msg);
  1326. reversing = 0;
  1327. if (channel_active(chan) || channel_pending(chan)) {
  1328. z = strlen(msg);
  1329. if (msg[--z] == ' ') /* I hate cosmetic bugs :P -poptix */
  1330. msg[z] = 0;
  1331. putlog(LOG_MODES, chan->dname, "%s: mode change '%s %s' by %s",
  1332. ch, chg, msg, from);
  1333. u = get_user_by_host(from);
  1334. get_user_flagrec(u, &user, ch);
  1335. nick = splitnick(&from);
  1336. m = ismember(chan, nick);
  1337. if (m)
  1338. m->last = now;
  1339. if (channel_active(chan) && m && me_op(chan)) {
  1340. if (chan_fakeop(m)) {
  1341. putlog(LOG_MODES, ch, CHAN_FAKEMODE, ch);
  1342. dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix,
  1343. CHAN_FAKEMODE_KICK);
  1344. m->flags |= SENTKICK;
  1345. reversing = 1;
  1346. } else if (m->nick && !strchr(m->nick, '.') && /* HOW ABOUT IF THEY ARENT A FUCKING SERVER? */
  1347. !chan_hasop(m) &&
  1348. !channel_nodesynch(chan)) {
  1349. putlog(LOG_MODES, ch, CHAN_DESYNCMODE, ch);
  1350. dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix,
  1351. CHAN_DESYNCMODE_KICK);
  1352. m->flags |= SENTKICK;
  1353. reversing = 1;
  1354. }
  1355. }
  1356. ms2[0] = '+';
  1357. ms2[2] = 0;
  1358. while ((ms2[1] = *chg)) {
  1359. int todo = 0;
  1360. switch (*chg) {
  1361. case '+':
  1362. ms2[0] = '+';
  1363. break;
  1364. case '-':
  1365. ms2[0] = '-';
  1366. break;
  1367. case 'i':
  1368. todo = CHANINV;
  1369. if ((!nick[0]) && (bounce_modes))
  1370. reversing = 1;
  1371. break;
  1372. case 'p':
  1373. todo = CHANPRIV;
  1374. if ((!nick[0]) && (bounce_modes))
  1375. reversing = 1;
  1376. break;
  1377. case 's':
  1378. todo = CHANSEC;
  1379. if ((!nick[0]) && (bounce_modes))
  1380. reversing = 1;
  1381. break;
  1382. case 'm':
  1383. todo = CHANMODER;
  1384. if ((!nick[0]) && (bounce_modes))
  1385. reversing = 1;
  1386. break;
  1387. case 'c':
  1388. todo = CHANNOCLR;
  1389. if ((!nick[0]) && (bounce_modes))
  1390. reversing = 1;
  1391. break;
  1392. case 'C':
  1393. todo = CHANNOCTCP;
  1394. if ((!nick[0]) && (bounce_modes))
  1395. reversing = 1;
  1396. break;
  1397. case 'R':
  1398. todo = CHANREGON;
  1399. if ((!nick[0]) && (bounce_modes))
  1400. reversing = 1;
  1401. break;
  1402. case 'M':
  1403. todo = CHANMODR;
  1404. if ((!nick[0]) && (bounce_modes))
  1405. reversing = 1;
  1406. break;
  1407. case 'r':
  1408. todo = CHANLONLY;
  1409. if ((!nick[0]) && (bounce_modes))
  1410. reversing = 1;
  1411. break;
  1412. case 't':
  1413. todo = CHANTOPIC;
  1414. if ((!nick[0]) && (bounce_modes))
  1415. reversing = 1;
  1416. break;
  1417. case 'n':
  1418. todo = CHANNOMSG;
  1419. if ((!nick[0]) && (bounce_modes))
  1420. reversing = 1;
  1421. break;
  1422. case 'a':
  1423. todo = CHANANON;
  1424. if ((!nick[0]) && (bounce_modes))
  1425. reversing = 1;
  1426. break;
  1427. case 'q':
  1428. todo = CHANQUIET;
  1429. if ((!nick[0]) && (bounce_modes))
  1430. reversing = 1;
  1431. break;
  1432. case 'l':
  1433. if ((!nick[0]) && (bounce_modes))
  1434. reversing = 1;
  1435. if (ms2[0] == '-') {
  1436. if (channel_active(chan)) {
  1437. if ((reversing) && (chan->channel.maxmembers != 0)) {
  1438. simple_sprintf(s, "%d", chan->channel.maxmembers);
  1439. add_mode(chan, '+', 'l', s);
  1440. } else if ((chan->limit_prot != 0) && !glob_master(user) && !chan_master(user)) {
  1441. simple_sprintf(s, "%d", chan->limit_prot);
  1442. add_mode(chan, '+', 'l', s);
  1443. } else {
  1444. if (dolimit(chan) &&
  1445. (!chan_master(user) && !glob_master(user) && !glob_bot(user))) {
  1446. if (chan->limitraise) {
  1447. chan->channel.maxmembers = 0; /* set this to 0 so a new limit is generated */
  1448. raise_limit(chan);
  1449. }
  1450. }
  1451. }
  1452. }
  1453. chan->channel.maxmembers = 0;
  1454. } else {
  1455. op = newsplit(&msg);
  1456. fixcolon(op);
  1457. if (op == '\0')
  1458. break;
  1459. chan->channel.maxmembers = atoi(op);
  1460. if (channel_pending(chan))
  1461. break;
  1462. if (((reversing) &&
  1463. !(chan->mode_pls_prot & CHANLIMIT)) ||
  1464. ((chan->mode_mns_prot & CHANLIMIT) &&
  1465. !glob_master(user) && !chan_master(user)))
  1466. add_mode(chan, '-', 'l', "");
  1467. if ((chan->limit_prot != chan->channel.maxmembers) &&
  1468. (chan->mode_pls_prot & CHANLIMIT) &&
  1469. (chan->limit_prot != 0) && /* arthur2 */
  1470. !glob_master(user) && !chan_master(user)) {
  1471. simple_sprintf(s, "%d", chan->limit_prot);
  1472. add_mode(chan, '+', 'l', s);
  1473. }
  1474. if (!glob_bot(user))
  1475. if (dolimit(chan) && (!chan_master(user) && !glob_master(user)))
  1476. if (chan->limitraise)
  1477. raise_limit(chan);
  1478. }
  1479. break;
  1480. case 'k':
  1481. if (ms2[0] == '+')
  1482. chan->channel.mode |= CHANKEY;
  1483. else
  1484. chan->channel.mode &= ~CHANKEY;
  1485. op = newsplit(&msg);
  1486. fixcolon(op);
  1487. if (op == '\0') {
  1488. break;
  1489. }
  1490. if (ms2[0] == '+') {
  1491. my_setkey(chan, op);
  1492. if (channel_active(chan))
  1493. got_key(chan, nick, from, op);
  1494. } else {
  1495. if (channel_active(chan)) {
  1496. if ((reversing) && (chan->channel.key[0]))
  1497. add_mode(chan, '+', 'k', chan->channel.key);
  1498. else if ((chan->key_prot[0]) && !glob_master(user)
  1499. && !chan_master(user))
  1500. add_mode(chan, '+', 'k', chan->key_prot);
  1501. }
  1502. my_setkey(chan, NULL);
  1503. }
  1504. break;
  1505. case 'o':
  1506. #ifdef S_AUTOLOCK
  1507. chan->channel.fighting++;
  1508. #endif /* S_AUTOLOCK */
  1509. op = newsplit(&msg);
  1510. fixcolon(op);
  1511. if (ms2[0] == '+')
  1512. got_op(chan, nick, from, op, u, &user);
  1513. else
  1514. got_deop(chan, nick, from, op, u);
  1515. break;
  1516. case 'v':
  1517. op = newsplit(&msg);
  1518. fixcolon(op);
  1519. m = ismember(chan, op);
  1520. if (!m) {
  1521. if (channel_pending(chan))
  1522. break;
  1523. putlog(LOG_MISC, chan->dname,
  1524. CHAN_BADCHANMODE, chan->dname, op);
  1525. dprintf(DP_MODE, "WHO %s\n", op);
  1526. } else {
  1527. int dv = 0;
  1528. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  1529. get_user_flagrec(m->user ? m->user : get_user_by_host(s),
  1530. &victim, chan->dname);
  1531. if (ms2[0] == '+') {
  1532. if (m->flags & EVOICE) {
  1533. if (!chan_master(user) && !glob_master(user)) {
  1534. dv++;
  1535. } else {
  1536. putlog(LOG_DEBUG, "@", "Stripping EVOICE flag from: %s (%s)", m->nick, chan->dname);
  1537. m->flags &= ~EVOICE;
  1538. }
  1539. }
  1540. m->flags &= ~SENTVOICE;
  1541. m->flags |= CHANVOICE;
  1542. if (channel_active(chan) && dovoice(chan)) {
  1543. if (dv || chk_devoice(victim, chan)) {
  1544. add_mode(chan, '-', 'v', op);
  1545. } else if (reversing) {
  1546. add_mode(chan, '-', 'v', op);
  1547. }
  1548. }
  1549. } else if (ms2[0] == '-') {
  1550. m->flags &= ~SENTDEVOICE;
  1551. m->flags &= ~CHANVOICE;
  1552. if (channel_active(chan) && dovoice(chan)) {
  1553. /* revoice +v users */
  1554. if (chk_voice(victim, chan)) {
  1555. add_mode(chan, '+', 'v', op);
  1556. } else if (reversing) {
  1557. add_mode(chan, '+', 'v', op);
  1558. /* if they arent +v|v and VOICER is m+ then EVOICE them */
  1559. } else {
  1560. if (!match_my_nick(nick) && channel_voice(chan) &&
  1561. (glob_master(user) || chan_master(user) || glob_bot(user))) {
  1562. /* if the user is not +q set them norEVOICE. */
  1563. if (!chan_quiet(victim) && !(m->flags & EVOICE)) {
  1564. putlog(LOG_DEBUG, "@", "Giving EVOICE flag to: %s (%s)", m->nick, chan->dname);
  1565. m->flags |= EVOICE;
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. break;
  1573. case 'b':
  1574. #ifdef S_AUTOLOCK
  1575. chan->channel.fighting++;
  1576. #endif /* S_AUTOLOCK */
  1577. op = newsplit(&msg);
  1578. fixcolon(op);
  1579. if (ms2[0] == '+')
  1580. got_ban(chan, nick, from, op);
  1581. else
  1582. got_unban(chan, nick, from, op, u);
  1583. break;
  1584. case 'e':
  1585. #ifdef S_AUTOLOCK
  1586. chan->channel.fighting++;
  1587. #endif /* S_AUTOLOCK */
  1588. op = newsplit(&msg);
  1589. fixcolon(op);
  1590. if (ms2[0] == '+')
  1591. got_exempt(chan, nick, from, op);
  1592. else
  1593. got_unexempt(chan, nick, from, op, u);
  1594. break;
  1595. case 'I':
  1596. #ifdef S_AUTOLOCK
  1597. chan->channel.fighting++;
  1598. #endif /* S_AUTOLOCK */
  1599. op = newsplit(&msg);
  1600. fixcolon(op);
  1601. if (ms2[0] == '+')
  1602. got_invite(chan, nick, from, op);
  1603. else
  1604. got_uninvite(chan, nick, from, op, u);
  1605. break;
  1606. }
  1607. if (todo) {
  1608. if (ms2[0] == '+')
  1609. chan->channel.mode |= todo;
  1610. else
  1611. chan->channel.mode &= ~todo;
  1612. if (channel_active(chan)) {
  1613. if ((((ms2[0] == '+') && (chan->mode_mns_prot & todo)) ||
  1614. ((ms2[0] == '-') && (chan->mode_pls_prot & todo))) &&
  1615. !glob_master(user) && !chan_master(user))
  1616. add_mode(chan, ms2[0] == '+' ? '-' : '+', *chg, "");
  1617. else if (reversing &&
  1618. ((ms2[0] == '+') || (chan->mode_pls_prot & todo)) &&
  1619. ((ms2[0] == '-') || (chan->mode_mns_prot & todo)))
  1620. add_mode(chan, ms2[0] == '+' ? '-' : '+', *chg, "");
  1621. }
  1622. }
  1623. chg++;
  1624. }
  1625. if (chan->channel.do_opreq)
  1626. request_op(chan);
  1627. if (!me_op(chan) && !nick[0])
  1628. chan->status |= CHAN_ASKEDMODES;
  1629. }
  1630. }
  1631. return 0;
  1632. }
  1633. #endif /* LEAF */