mode.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  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 void do_op(char *nick, struct chanset_t *chan, int force)
  22. {
  23. memberlist *m = ismember(chan, nick);
  24. if (!m) return;
  25. if (!force && chan_hasop(m))
  26. return;
  27. if (channel_fastop(chan) || channel_take(chan)) {
  28. add_mode(chan, '+', 'o', nick);
  29. } else {
  30. char *tmp = nmalloc(strlen(chan->name) + 200);
  31. makeopline(chan, nick, tmp);
  32. dprintf(DP_MODE, tmp);
  33. nfree(tmp);
  34. }
  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. nfree(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. nfree(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. nfree(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. nfree(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. nfree(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. nfree(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 = nmalloc(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 = nmalloc(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 *) channel_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. nfree(chan->key);
  356. chan->key = (char *) channel_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. nfree(chan->rmkey);
  364. chan->rmkey = (char *) channel_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. nfree(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. nfree(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. nfree(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. nfree(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 *) channel_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. nfree(chan->key);
  611. chan->key = (char *) channel_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. nfree(chan->rmkey);
  619. chan->rmkey = (char *) channel_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. (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. recheck_channel(chan, 1);
  760. }
  761. static void got_deop(struct chanset_t *chan, char *nick, char *from,
  762. char *who, struct userrec *opu)
  763. {
  764. memberlist *m;
  765. char s[UHOSTLEN], s1[UHOSTLEN];
  766. struct userrec *u;
  767. m = ismember(chan, who);
  768. if (!m) {
  769. if (channel_pending(chan))
  770. return;
  771. putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, who);
  772. dprintf(DP_MODE, "WHO %s\n", who);
  773. return;
  774. }
  775. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  776. simple_sprintf(s1, "%s!%s", nick, from);
  777. u = get_user_by_host(s);
  778. get_user_flagrec(u, &victim, chan->dname);
  779. /* Flags need to be set correctly right from the beginning now, so that
  780. * add_mode() doesn't get irritated.
  781. */
  782. m->flags &= ~(CHANOP | SENTDEOP | FAKEOP);
  783. /* Check comments in got_op() (drummer) */
  784. m->flags &= ~WASOP;
  785. if (channel_pending(chan))
  786. return;
  787. /* Deop'd someone on my oplist? */
  788. if (me_op(chan)) {
  789. int ok = 1;
  790. /* if they aren't d|d then check if they are something we should protect */
  791. if (!glob_deop(victim) && !chan_deop(victim)) {
  792. if (channel_protectops(chan) && (glob_master(victim) || chan_master(victim) ||
  793. glob_op(victim) || chan_op(victim)))
  794. ok = 0;
  795. }
  796. /* do we want to reop victim? */
  797. if ((reversing || !ok) && !match_my_nick(nick) &&
  798. rfc_casecmp(who, nick) && !match_my_nick(who) &&
  799. /* Is the deopper NOT a master or bot? */
  800. !glob_master(user) && !chan_master(user) && !glob_bot(user) &&
  801. ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) ||
  802. !channel_bitch(chan)))
  803. /* Then we'll bless the victim */
  804. do_op(who, chan, 0);
  805. }
  806. if (!nick[0])
  807. putlog(LOG_MODES, chan->dname, "TS resync (%s): %s deopped by %s",
  808. chan->dname, who, from);
  809. /* Check for mass deop */
  810. if (nick[0])
  811. detect_chan_flood(nick, from, s1, chan, FLOOD_DEOP, who);
  812. /* Having op hides your +v and +h status -- so now that someone's lost ops,
  813. * check to see if they have +v or +h
  814. */
  815. if (!(m->flags & (CHANVOICE | STOPWHO))) {
  816. dprintf(DP_HELP, "WHO %s\n", m->nick);
  817. m->flags |= STOPWHO;
  818. }
  819. /* Was the bot deopped? */
  820. if (match_my_nick(who)) {
  821. /* Cancel any pending kicks and modes */
  822. memberlist *m2;
  823. for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
  824. m2->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTVOICE | SENTDEVOICE);
  825. chan->channel.do_opreq=1;
  826. // request_op(chan);
  827. /* need: op */
  828. if (!nick[0])
  829. putlog(LOG_MODES, chan->dname, "TS resync deopped me on %s :(",
  830. chan->dname);
  831. }
  832. if (nick[0])
  833. maybe_revenge(chan, s1, s, REVENGE_DEOP);
  834. }
  835. static void got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
  836. {
  837. char me[UHOSTLEN], s[UHOSTLEN], s1[UHOSTLEN];
  838. memberlist *m;
  839. struct userrec *u;
  840. egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
  841. egg_snprintf(s, sizeof s, "%s!%s", nick, from);
  842. newban(chan, who, s);
  843. if (channel_pending(chan) || !me_op(chan))
  844. return;
  845. if (wild_match(who, me) && !isexempted(chan, me)) {
  846. add_mode(chan, '-', 'b', who);
  847. reversing = 1;
  848. return;
  849. }
  850. if (!match_my_nick(nick)) {
  851. if (channel_nouserbans(chan) && nick[0] && !glob_bot(user) &&
  852. !glob_master(user) && !chan_master(user)) {
  853. add_mode(chan, '-', 'b', who);
  854. return;
  855. }
  856. /* remove bans on ops unless a master/bot set it */
  857. for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
  858. egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
  859. if (wild_match(who, s1)) {
  860. u = get_user_by_host(s1);
  861. if (u) {
  862. get_user_flagrec(u, &victim, chan->dname);
  863. if (chk_op(victim, chan) && !chan_master(user) && !glob_master(user) &&
  864. !glob_bot(user) && !isexempted(chan, s1)) {
  865. /* if (target_priority(chan, m, 0)) */
  866. add_mode(chan, '-', 'b', who);
  867. return;
  868. }
  869. }
  870. }
  871. }
  872. }
  873. refresh_exempt(chan, who);
  874. /* This looks for bans added through bot and tacks on banned: if a description is found */
  875. if (nick[0] && channel_enforcebans(chan)) {
  876. register maskrec *b;
  877. int cycle;
  878. char resn[512]="";
  879. /* The point of this cycle crap is to first check chan->bans then global_bans */
  880. for (cycle = 0; cycle < 2; cycle++) {
  881. for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
  882. if (wild_match(b->mask, who)) {
  883. if (b->desc && b->desc[0] != '@')
  884. egg_snprintf(resn, sizeof resn, "%s %s", IRC_PREBANNED, b->desc);
  885. else
  886. resn[0] = 0;
  887. }
  888. }
  889. }
  890. kick_all(chan, who, resn[0] ? resn : kickreason(KICK_BANNED), match_my_nick(nick) ? 0 : 1);
  891. }
  892. if (!nick[0] && (bounce_bans || bounce_modes) &&
  893. (!u_equals_mask(global_bans, who) || !u_equals_mask(chan->bans, who)))
  894. add_mode(chan, '-', 'b', who);
  895. }
  896. static void got_unban(struct chanset_t *chan, char *nick, char *from,
  897. char *who, struct userrec *u)
  898. {
  899. masklist *b, *old;
  900. old = NULL;
  901. for (b = chan->channel.ban; b->mask[0] && rfc_casecmp(b->mask, who);
  902. old = b, b = b->next)
  903. ;
  904. if (b->mask[0]) {
  905. if (old)
  906. old->next = b->next;
  907. else
  908. chan->channel.ban = b->next;
  909. nfree(b->mask);
  910. nfree(b->who);
  911. nfree(b);
  912. }
  913. if (channel_pending(chan))
  914. return;
  915. if (u_sticky_mask(chan->bans, who) || u_sticky_mask(global_bans, who)) {
  916. /* That's a sticky ban! No point in being
  917. * sticky unless we enforce it!!
  918. */
  919. add_mode(chan, '+', 'b', who);
  920. }
  921. if ((u_equals_mask(global_bans, who) || u_equals_mask(chan->bans, who)) &&
  922. me_op(chan) && !channel_dynamicbans(chan)) {
  923. /* That's a permban! */
  924. if ((!glob_bot(user) || !(bot_flags(u) & BOT_SHARE)) && ((!glob_op(user) ||
  925. chan_deop(user)) && !chan_op(user)))
  926. add_mode(chan, '+', 'b', who);
  927. }
  928. }
  929. #ifdef S_IRCNET
  930. static void got_exempt(struct chanset_t *chan, char *nick, char *from,
  931. char *who)
  932. {
  933. char s[UHOSTLEN];
  934. simple_sprintf(s, "%s!%s", nick, from);
  935. newexempt(chan, who, s);
  936. if (channel_pending(chan))
  937. return;
  938. if (!match_my_nick(nick)) { /* It's not my exemption */
  939. if (channel_nouserexempts(chan) && nick[0] && !glob_bot(user) &&
  940. !glob_master(user) && !chan_master(user)) {
  941. /* No exempts made by users */
  942. add_mode(chan, '-', 'e', who);
  943. return;
  944. }
  945. if (!nick[0] && bounce_modes)
  946. reversing = 1;
  947. }
  948. if (reversing || (bounce_exempts && !nick[0] &&
  949. (!u_equals_mask(global_exempts, who) ||
  950. !u_equals_mask(chan->exempts, who))))
  951. add_mode(chan, '-', 'e', who);
  952. }
  953. static void got_unexempt(struct chanset_t *chan, char *nick, char *from,
  954. char *who, struct userrec *u)
  955. {
  956. masklist *e = chan->channel.exempt, *old = NULL;
  957. masklist *b ;
  958. int match = 0;
  959. while (e && e->mask[0] && rfc_casecmp(e->mask, who)) {
  960. old = e;
  961. e = e->next;
  962. }
  963. if (e && e->mask[0]) {
  964. if (old)
  965. old->next = e->next;
  966. else
  967. chan->channel.exempt = e->next;
  968. nfree(e->mask);
  969. nfree(e->who);
  970. nfree(e);
  971. }
  972. if (channel_pending(chan))
  973. return;
  974. if (u_sticky_mask(chan->exempts, who) || u_sticky_mask(global_exempts, who)) {
  975. /* That's a sticky exempt! No point in being sticky unless we enforce it!!
  976. */
  977. add_mode(chan, '+', 'e', who);
  978. }
  979. /* If exempt was removed by master then leave it else check for bans */
  980. if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)) {
  981. b = chan->channel.ban;
  982. while (b->mask[0] && !match) {
  983. if (wild_match(b->mask, who) ||
  984. wild_match(who, b->mask)) {
  985. add_mode(chan, '+', 'e', who);
  986. match = 1;
  987. } else
  988. b = b->next;
  989. }
  990. }
  991. if ((u_equals_mask(global_exempts, who) || u_equals_mask(chan->exempts, who)) &&
  992. me_op(chan) && !channel_dynamicexempts(chan)) {
  993. /* That's a permexempt! */
  994. if (glob_bot(user) && (bot_flags(u) & BOT_SHARE)) {
  995. /* Sharebot -- do nothing */
  996. } else
  997. add_mode(chan, '+', 'e', who);
  998. }
  999. }
  1000. static void got_invite(struct chanset_t *chan, char *nick, char *from,
  1001. char *who)
  1002. {
  1003. char s[UHOSTLEN];
  1004. simple_sprintf(s, "%s!%s", nick, from);
  1005. newinvite(chan, who, s);
  1006. if (channel_pending(chan))
  1007. return;
  1008. if (!match_my_nick(nick)) { /* It's not my invitation */
  1009. if (channel_nouserinvites(chan) && nick[0] && !glob_bot(user) &&
  1010. !glob_master(user) && !chan_master(user)) {
  1011. /* No exempts made by users */
  1012. add_mode(chan, '-', 'I', who);
  1013. return;
  1014. }
  1015. if ((!nick[0]) && (bounce_modes))
  1016. reversing = 1;
  1017. }
  1018. if (reversing || (bounce_invites && (!nick[0]) &&
  1019. (!u_equals_mask(global_invites, who) ||
  1020. !u_equals_mask(chan->invites, who))))
  1021. add_mode(chan, '-', 'I', who);
  1022. }
  1023. static void got_uninvite(struct chanset_t *chan, char *nick, char *from,
  1024. char *who, struct userrec *u)
  1025. {
  1026. masklist *inv = chan->channel.invite, *old = NULL;
  1027. while (inv->mask[0] && rfc_casecmp(inv->mask, who)) {
  1028. old = inv;
  1029. inv = inv->next;
  1030. }
  1031. if (inv->mask[0]) {
  1032. if (old)
  1033. old->next = inv->next;
  1034. else
  1035. chan->channel.invite = inv->next;
  1036. nfree(inv->mask);
  1037. nfree(inv->who);
  1038. nfree(inv);
  1039. }
  1040. if (channel_pending(chan))
  1041. return;
  1042. if (u_sticky_mask(chan->invites, who) || u_sticky_mask(global_invites, who)) {
  1043. /* That's a sticky invite! No point in being sticky unless we enforce it!!
  1044. */
  1045. add_mode(chan, '+', 'I', who);
  1046. }
  1047. if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)
  1048. && (chan->channel.mode & CHANINV))
  1049. add_mode(chan, '+', 'I', who);
  1050. if ((u_equals_mask(global_invites, who) ||
  1051. u_equals_mask(chan->invites, who)) && me_op(chan) &&
  1052. !channel_dynamicinvites(chan)) {
  1053. /* That's a perminvite! */
  1054. if (glob_bot(user) && (bot_flags(u) & BOT_SHARE)) {
  1055. /* Sharebot -- do nothing */
  1056. } else
  1057. add_mode(chan, '+', 'I', who);
  1058. }
  1059. }
  1060. #endif
  1061. static int gotmode(char *from, char *msg)
  1062. {
  1063. char *nick, *ch, *op, *chg;
  1064. char s[UHOSTLEN];
  1065. char ms2[3];
  1066. int z;
  1067. struct userrec *u;
  1068. memberlist *m;
  1069. struct chanset_t *chan;
  1070. /* Usermode changes? */
  1071. if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
  1072. ch = newsplit(&msg);
  1073. if (match_my_nick(ch))
  1074. return 0;
  1075. chan = findchan(ch);
  1076. if (!chan) {
  1077. putlog(LOG_MISC, "*", CHAN_FORCEJOIN, ch);
  1078. dprintf(DP_SERVER, "PART %s\n", ch);
  1079. return 0;
  1080. }
  1081. /* let's pre-emptively check for mass op/deop, manual ops and cookieops */
  1082. if (strchr(from, '!')) {
  1083. char *modes[5] = { NULL, NULL, NULL, NULL, NULL };
  1084. char tmp[1024], sign = '+', *nfrom, *hfrom, *wptr, *p, work[1024];
  1085. struct userrec *ufrom = NULL;
  1086. memberlist *m;
  1087. int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0;
  1088. /* Split up the mode: #chan modes param param param param */
  1089. strncpyz(work, msg, sizeof(work));
  1090. wptr = work;
  1091. p = newsplit(&wptr);
  1092. while (*p) {
  1093. char *mp;
  1094. if (*p == '+')
  1095. sign = '+';
  1096. else if (*p == '-')
  1097. sign = '-';
  1098. else if (strchr(STR("oblkvIe"), p[0])) {
  1099. mp = newsplit(&wptr);
  1100. if (strchr("ob", p[0])) {
  1101. /* Just want o's and b's */
  1102. modes[modecnt] = nmalloc(strlen(mp) + 4);
  1103. sprintf(modes[modecnt], STR("%c%c %s"), sign, p[0], mp);
  1104. modecnt++;
  1105. if (p[0] == 'o') {
  1106. if (sign == '+')
  1107. ops++;
  1108. else
  1109. deops++;
  1110. }
  1111. if (p[0] == 'b') {
  1112. if (sign == '+')
  1113. bans++;
  1114. else
  1115. unbans++;
  1116. }
  1117. }
  1118. } else if (strchr(STR("pstnmi"), p[0])) {
  1119. } else {
  1120. /* hrmm... what modechar did i forget? */
  1121. putlog(LOG_ERRORS, "*", STR("Forgotten modechar in irc:gotmode: %c"), p[0]);
  1122. }
  1123. p++;
  1124. }
  1125. /* Split up from */
  1126. ufrom = get_user_by_host(from);
  1127. strncpyz(work, from, sizeof(work));
  1128. p = strchr(work, '!');
  1129. *p++ = 0;
  1130. nfrom = work; /* nick */
  1131. hfrom = p; /* host */
  1132. /* Now we got modes[], chan, ufrom, nfrom, hfrom, and count of each relevant mode */
  1133. /* check for mdop */
  1134. if ((chan) && (deops >= 3)) {
  1135. if ((!ufrom) || (!(ufrom->flags & USER_BOT))) {
  1136. if (ROLE_KICK_MDOP) {
  1137. m = ismember(chan, nfrom);
  1138. if (m && !chan_sentkick(m)) {
  1139. m->flags |= SENTKICK;
  1140. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MASSDEOP));
  1141. tputs(servi, tmp, strlen(tmp));
  1142. if (ufrom) {
  1143. sprintf(tmp, STR("Mass deop on %s by %s"), chan->dname, nfrom);
  1144. deflag_user(ufrom, DEFLAG_MDOP, tmp, chan);
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. /* check for mop */
  1151. if (chan && (ops >= 3)) {
  1152. if (channel_nomop(chan)) {
  1153. if ((!ufrom) || (!(ufrom->flags & USER_BOT))) {
  1154. if (ROLE_KICK_MDOP) {
  1155. m = ismember(chan, nfrom);
  1156. if (m && !chan_sentkick(m)) {
  1157. m->flags |= SENTKICK;
  1158. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MANUALOP));
  1159. tputs(servi, tmp, strlen(tmp));
  1160. if (ufrom) {
  1161. sprintf(tmp, STR("Mass op on %s by %s"), chan->dname, nfrom);
  1162. deflag_user(ufrom, DEFLAG_MOP, tmp, chan);
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. if (chan && ops && (ufrom) && (ufrom->flags & USER_BOT) && !channel_fastop(chan) && !channel_take(chan)) {
  1170. int isbadop = 0;
  1171. if ((modecnt != 2) || (strncmp(modes[0], "+o", 2)) ||
  1172. (strncmp(modes[1], "-b", 2))) {
  1173. isbadop = 1;
  1174. } else {
  1175. char enccookie[25], plaincookie[25], key[NICKLEN + 20], goodcookie[25];
  1176. /* -b *!*@[...] */
  1177. strncpyz(enccookie, (char *) &(modes[1][8]), sizeof(enccookie));
  1178. p = enccookie + strlen(enccookie) - 1;
  1179. /* old shit
  1180. *p = 0;
  1181. while (p - enccookie < 24) {
  1182. *p++ = '.';
  1183. *p = 0;
  1184. }
  1185. */
  1186. strcpy(key, nfrom);
  1187. strcat(key, SALT2);
  1188. /* putlog(LOG_DEBUG, "*", "Decrypting cookie: %s with key %s", enccookie, key); */
  1189. p = decrypt_string(key, enccookie);
  1190. /* putlog(LOG_DEBUG, "*", "Decrypted cookie: %s", p); */
  1191. strncpyz(plaincookie, p, sizeof(plaincookie));
  1192. nfree(p);
  1193. /*
  1194. * last 6 digits of time
  1195. * last 5 chars of nick
  1196. * last 5 regular chars of chan
  1197. */
  1198. makeplaincookie(chan->dname, (char *) (modes[0] + 3), goodcookie);
  1199. /* putlog(LOG_DEBUG, "*", "cookie from %s: %s should be: %s", nfrom, plaincookie, goodcookie); */
  1200. if (strncmp((char *) &plaincookie[6], (char *) &goodcookie[6], 5))
  1201. isbadop = 2;
  1202. else if (strncmp((char *) &plaincookie[11], (char *) &goodcookie[11], 5))
  1203. isbadop = 3;
  1204. else {
  1205. char ltmp[20];
  1206. long optime;
  1207. int off;
  1208. sprintf(ltmp, STR("%010li"), (now + timesync));
  1209. strncpyz((char *) &ltmp[4], plaincookie, 7);
  1210. optime = atol(ltmp);
  1211. off = (now + timesync - optime);
  1212. if (abs(off) > OP_TIME_SLACK) {
  1213. /* isbadop = 4; */
  1214. putlog(LOG_ERRORS, "*", "%s opped with bad ts (not punishing.): %li was off by %li", nfrom, optime, off);
  1215. }
  1216. }
  1217. }
  1218. if (isbadop) {
  1219. char trg[NICKLEN + 1] = "";
  1220. n = i = 0;
  1221. switch (role) {
  1222. case 0:
  1223. break;
  1224. case 1:
  1225. /* Kick opper */
  1226. m = ismember(chan, nfrom);
  1227. if (!m || !chan_sentkick(m)) {
  1228. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_BADOP));
  1229. tputs(servi, tmp, strlen(tmp));
  1230. if (m)
  1231. m->flags |= SENTKICK;
  1232. }
  1233. sprintf(tmp, STR("%s MODE %s"), from, msg);
  1234. deflag_user(ufrom, DEFLAG_BADCOOKIE, tmp, chan);
  1235. break;
  1236. default:
  1237. n = role - 1;
  1238. i = 0;
  1239. while ((i < 5) && (n > 0)) {
  1240. if (modes[i] && !strncmp(modes[i], "+o", 2))
  1241. n--;
  1242. if (n)
  1243. i++;
  1244. }
  1245. if (!n) {
  1246. strcpy(trg, (char *) &modes[i][3]);
  1247. m = ismember(chan, trg);
  1248. if (m) {
  1249. if (!(m->flags & CHANOP)) {
  1250. if (!chan_sentkick(m)) {
  1251. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_BADOPPED));
  1252. tputs(servi, tmp, strlen(tmp));
  1253. m->flags |= SENTKICK;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. if (isbadop == 1)
  1260. putlog(LOG_WARN, "*", STR("Missing cookie: %s MODE %s"), from, msg);
  1261. else if (isbadop == 2)
  1262. putlog(LOG_WARN, "*", STR("Invalid cookie (bad nick): %s MODE %s"), from, msg);
  1263. else if (isbadop == 3)
  1264. putlog(LOG_WARN, "*", STR("Invalid cookie (bad chan): %s MODE %s"), from, msg);
  1265. else if (isbadop == 4)
  1266. putlog(LOG_WARN, "*", STR("Invalid cookie (bad time): %s MODE %s"), from, msg);
  1267. } else
  1268. putlog(LOG_DEBUG, "@", STR("Good op: %s"), msg);
  1269. }
  1270. if ((ops) && chan && !channel_manop(chan) && (ufrom) &&
  1271. !(ufrom->flags & USER_BOT)) {
  1272. char trg[NICKLEN + 1] = "";
  1273. n = i = 0;
  1274. switch (role) {
  1275. case 0:
  1276. break;
  1277. case 1:
  1278. /* Kick opper */
  1279. m = ismember(chan, nfrom);
  1280. if (!m || !chan_sentkick(m)) {
  1281. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, nfrom, kickprefix, kickreason(KICK_MANUALOP));
  1282. tputs(servi, tmp, strlen(tmp));
  1283. if (m)
  1284. m->flags |= SENTKICK;
  1285. }
  1286. sprintf(tmp, STR("%s MODE %s"), from, msg);
  1287. deflag_user(ufrom, DEFLAG_MANUALOP, tmp, chan);
  1288. break;
  1289. default:
  1290. n = role - 1;
  1291. i = 0;
  1292. while ((i < 5) && (n > 0)) {
  1293. if (modes[i] && !strncmp(modes[i], "+o", 2))
  1294. n--;
  1295. if (n)
  1296. i++;
  1297. }
  1298. if (!n) {
  1299. strcpy(trg, (char *) &modes[i][3]);
  1300. m = ismember(chan, trg);
  1301. if (m) {
  1302. if (!(m->flags & CHANOP) && (rfc_casecmp(botname, trg))) {
  1303. if (!chan_sentkick(m)) {
  1304. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_MANUALOPPED));
  1305. tputs(servi, tmp, strlen(tmp));
  1306. m->flags |= SENTKICK;
  1307. }
  1308. }
  1309. } else {
  1310. sprintf(tmp, STR("KICK %s %s :%s%s\n"), chan->name, trg, kickprefix, kickreason(KICK_MANUALOPPED));
  1311. tputs(servi, tmp, strlen(tmp));
  1312. }
  1313. }
  1314. }
  1315. }
  1316. for (i = 0; i < 5; i++)
  1317. if (modes[i])
  1318. nfree(modes[i]);
  1319. }
  1320. /* Now do the modes again, this time throughly... */
  1321. chg = newsplit(&msg);
  1322. reversing = 0;
  1323. if (channel_active(chan) || channel_pending(chan)) {
  1324. z = strlen(msg);
  1325. if (msg[--z] == ' ') /* I hate cosmetic bugs :P -poptix */
  1326. msg[z] = 0;
  1327. putlog(LOG_MODES, chan->dname, "%s: mode change '%s %s' by %s",
  1328. ch, chg, msg, from);
  1329. u = get_user_by_host(from);
  1330. get_user_flagrec(u, &user, ch);
  1331. nick = splitnick(&from);
  1332. m = ismember(chan, nick);
  1333. if (m)
  1334. m->last = now;
  1335. if (channel_active(chan) && m && me_op(chan) &&
  1336. !((channel_dontkickops(chan) && (chan_op(user) || (glob_op(user) &&
  1337. !chan_deop(user)))))) {
  1338. if (chan_fakeop(m)) {
  1339. putlog(LOG_MODES, ch, CHAN_FAKEMODE, ch);
  1340. dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix,
  1341. CHAN_FAKEMODE_KICK);
  1342. m->flags |= SENTKICK;
  1343. reversing = 1;
  1344. } else if (m->nick && !strchr(m->nick, '.') && /* HOW ABOUT IF THEY ARENT A FUCKING SERVER? */
  1345. !chan_hasop(m) &&
  1346. !channel_nodesynch(chan)) {
  1347. putlog(LOG_MODES, ch, CHAN_DESYNCMODE, ch);
  1348. dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix,
  1349. CHAN_DESYNCMODE_KICK);
  1350. m->flags |= SENTKICK;
  1351. reversing = 1;
  1352. }
  1353. }
  1354. ms2[0] = '+';
  1355. ms2[2] = 0;
  1356. while ((ms2[1] = *chg)) {
  1357. int todo = 0;
  1358. switch (*chg) {
  1359. case '+':
  1360. ms2[0] = '+';
  1361. break;
  1362. case '-':
  1363. ms2[0] = '-';
  1364. break;
  1365. case 'i':
  1366. todo = CHANINV;
  1367. if ((!nick[0]) && (bounce_modes))
  1368. reversing = 1;
  1369. break;
  1370. case 'p':
  1371. todo = CHANPRIV;
  1372. if ((!nick[0]) && (bounce_modes))
  1373. reversing = 1;
  1374. break;
  1375. case 's':
  1376. todo = CHANSEC;
  1377. if ((!nick[0]) && (bounce_modes))
  1378. reversing = 1;
  1379. break;
  1380. case 'm':
  1381. todo = CHANMODER;
  1382. if ((!nick[0]) && (bounce_modes))
  1383. reversing = 1;
  1384. break;
  1385. case 'c':
  1386. todo = CHANNOCLR;
  1387. if ((!nick[0]) && (bounce_modes))
  1388. reversing = 1;
  1389. break;
  1390. case 'C':
  1391. todo = CHANNOCTCP;
  1392. if ((!nick[0]) && (bounce_modes))
  1393. reversing = 1;
  1394. break;
  1395. case 'R':
  1396. todo = CHANREGON;
  1397. if ((!nick[0]) && (bounce_modes))
  1398. reversing = 1;
  1399. break;
  1400. case 'M':
  1401. todo = CHANMODR;
  1402. if ((!nick[0]) && (bounce_modes))
  1403. reversing = 1;
  1404. break;
  1405. case 'r':
  1406. todo = CHANLONLY;
  1407. if ((!nick[0]) && (bounce_modes))
  1408. reversing = 1;
  1409. break;
  1410. case 't':
  1411. todo = CHANTOPIC;
  1412. if ((!nick[0]) && (bounce_modes))
  1413. reversing = 1;
  1414. break;
  1415. case 'n':
  1416. todo = CHANNOMSG;
  1417. if ((!nick[0]) && (bounce_modes))
  1418. reversing = 1;
  1419. break;
  1420. case 'a':
  1421. todo = CHANANON;
  1422. if ((!nick[0]) && (bounce_modes))
  1423. reversing = 1;
  1424. break;
  1425. case 'q':
  1426. todo = CHANQUIET;
  1427. if ((!nick[0]) && (bounce_modes))
  1428. reversing = 1;
  1429. break;
  1430. case 'l':
  1431. if ((!nick[0]) && (bounce_modes))
  1432. reversing = 1;
  1433. if (ms2[0] == '-') {
  1434. if (channel_active(chan)) {
  1435. if ((reversing) && (chan->channel.maxmembers != 0)) {
  1436. simple_sprintf(s, "%d", chan->channel.maxmembers);
  1437. add_mode(chan, '+', 'l', s);
  1438. } else if ((chan->limit_prot != 0) && !glob_master(user) && !chan_master(user)) {
  1439. simple_sprintf(s, "%d", chan->limit_prot);
  1440. add_mode(chan, '+', 'l', s);
  1441. } else {
  1442. if (dolimit(chan) &&
  1443. (!chan_master(user) && !glob_master(user) && !glob_bot(user))) {
  1444. if (chan->limitraise) {
  1445. chan->channel.maxmembers = 0; /* set this to 0 so a new limit is generated */
  1446. raise_limit(chan);
  1447. }
  1448. }
  1449. }
  1450. }
  1451. chan->channel.maxmembers = 0;
  1452. } else {
  1453. op = newsplit(&msg);
  1454. fixcolon(op);
  1455. if (op == '\0')
  1456. break;
  1457. chan->channel.maxmembers = atoi(op);
  1458. if (channel_pending(chan))
  1459. break;
  1460. if (((reversing) &&
  1461. !(chan->mode_pls_prot & CHANLIMIT)) ||
  1462. ((chan->mode_mns_prot & CHANLIMIT) &&
  1463. !glob_master(user) && !chan_master(user)))
  1464. add_mode(chan, '-', 'l', "");
  1465. if ((chan->limit_prot != chan->channel.maxmembers) &&
  1466. (chan->mode_pls_prot & CHANLIMIT) &&
  1467. (chan->limit_prot != 0) && /* arthur2 */
  1468. !glob_master(user) && !chan_master(user)) {
  1469. simple_sprintf(s, "%d", chan->limit_prot);
  1470. add_mode(chan, '+', 'l', s);
  1471. }
  1472. if (!glob_bot(user))
  1473. if (dolimit(chan) && (!chan_master(user) && !glob_master(user)))
  1474. if (chan->limitraise)
  1475. raise_limit(chan);
  1476. }
  1477. break;
  1478. case 'k':
  1479. if (ms2[0] == '+')
  1480. chan->channel.mode |= CHANKEY;
  1481. else
  1482. chan->channel.mode &= ~CHANKEY;
  1483. op = newsplit(&msg);
  1484. fixcolon(op);
  1485. if (op == '\0') {
  1486. break;
  1487. }
  1488. if (ms2[0] == '+') {
  1489. my_setkey(chan, op);
  1490. if (channel_active(chan))
  1491. got_key(chan, nick, from, op);
  1492. } else {
  1493. if (channel_active(chan)) {
  1494. if ((reversing) && (chan->channel.key[0]))
  1495. add_mode(chan, '+', 'k', chan->channel.key);
  1496. else if ((chan->key_prot[0]) && !glob_master(user)
  1497. && !chan_master(user))
  1498. add_mode(chan, '+', 'k', chan->key_prot);
  1499. }
  1500. my_setkey(chan, NULL);
  1501. }
  1502. break;
  1503. case 'o':
  1504. #ifdef S_AUTOLOCK
  1505. chan->channel.fighting++;
  1506. #endif /* S_AUTOLOCK */
  1507. op = newsplit(&msg);
  1508. fixcolon(op);
  1509. if (ms2[0] == '+')
  1510. got_op(chan, nick, from, op, u, &user);
  1511. else
  1512. got_deop(chan, nick, from, op, u);
  1513. break;
  1514. case 'v':
  1515. op = newsplit(&msg);
  1516. fixcolon(op);
  1517. m = ismember(chan, op);
  1518. if (!m) {
  1519. if (channel_pending(chan))
  1520. break;
  1521. putlog(LOG_MISC, chan->dname,
  1522. CHAN_BADCHANMODE, chan->dname, op);
  1523. dprintf(DP_MODE, "WHO %s\n", op);
  1524. } else {
  1525. int dv = 0;
  1526. simple_sprintf(s, "%s!%s", m->nick, m->userhost);
  1527. get_user_flagrec(m->user ? m->user : get_user_by_host(s),
  1528. &victim, chan->dname);
  1529. if (ms2[0] == '+') {
  1530. if (m->flags & EVOICE) {
  1531. if (!chan_master(user) && !glob_master(user)) {
  1532. dv++;
  1533. } else {
  1534. putlog(LOG_DEBUG, "@", "Stripping EVOICE flag from: %s (%s)", m->nick, chan->dname);
  1535. m->flags &= ~EVOICE;
  1536. }
  1537. }
  1538. m->flags &= ~SENTVOICE;
  1539. m->flags |= CHANVOICE;
  1540. if (channel_active(chan) && dovoice(chan)) {
  1541. if (dv || chk_devoice(victim, chan)) {
  1542. add_mode(chan, '-', 'v', op);
  1543. } else if (reversing) {
  1544. add_mode(chan, '-', 'v', op);
  1545. }
  1546. }
  1547. } else if (ms2[0] == '-') {
  1548. m->flags &= ~SENTDEVOICE;
  1549. m->flags &= ~CHANVOICE;
  1550. if (channel_active(chan) && dovoice(chan)) {
  1551. /* revoice +v users */
  1552. if (chk_voice(victim, chan)) {
  1553. add_mode(chan, '+', 'v', op);
  1554. } else if (reversing) {
  1555. add_mode(chan, '+', 'v', op);
  1556. /* if they arent +v|v and VOICER is m+ then EVOICE them */
  1557. } else {
  1558. if (!match_my_nick(nick) && channel_voice(chan) &&
  1559. (glob_master(user) || chan_master(user) || glob_bot(user))) {
  1560. /* if the user is not +q set them norEVOICE. */
  1561. if (!chan_quiet(victim) && !(m->flags & EVOICE)) {
  1562. putlog(LOG_DEBUG, "@", "Giving EVOICE flag to: %s (%s)", m->nick, chan->dname);
  1563. m->flags |= EVOICE;
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. break;
  1571. case 'b':
  1572. #ifdef S_AUTOLOCK
  1573. chan->channel.fighting++;
  1574. #endif /* S_AUTOLOCK */
  1575. op = newsplit(&msg);
  1576. fixcolon(op);
  1577. if (ms2[0] == '+')
  1578. got_ban(chan, nick, from, op);
  1579. else
  1580. got_unban(chan, nick, from, op, u);
  1581. break;
  1582. #ifdef S_IRCNET
  1583. case 'e':
  1584. #ifdef S_AUTOLOCK
  1585. chan->channel.fighting++;
  1586. #endif /* S_AUTOLOCK */
  1587. op = newsplit(&msg);
  1588. fixcolon(op);
  1589. if (ms2[0] == '+')
  1590. got_exempt(chan, nick, from, op);
  1591. else
  1592. got_unexempt(chan, nick, from, op, u);
  1593. break;
  1594. case 'I':
  1595. #ifdef S_AUTOLOCK
  1596. chan->channel.fighting++;
  1597. #endif /* S_AUTOLOCK */
  1598. op = newsplit(&msg);
  1599. fixcolon(op);
  1600. if (ms2[0] == '+')
  1601. got_invite(chan, nick, from, op);
  1602. else
  1603. got_uninvite(chan, nick, from, op, u);
  1604. break;
  1605. }
  1606. #endif
  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 */