| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430 |
- #ifdef LEAF
- /*
- * mode.c -- part of irc.mod
- * queuing and flushing mode changes made by the bot
- * channel mode changes and the bot's reaction to them
- * setting and getting the current wanted channel modes
- *
- */
- /* Reversing this mode? */
- static int reversing = 0;
- # define PLUS BIT0
- # define MINUS BIT1
- # define CHOP BIT2
- # define BAN BIT3
- # define VOICE BIT4
- # define EXEMPT BIT5
- # define INVITE BIT6
- static struct flag_record user = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- static struct flag_record victim = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- static int
- do_op(char *nick, struct chanset_t *chan, int delay, int force)
- {
- memberlist *m = ismember(chan, nick);
- if (!me_op(chan) || !m || (m && !force && chan_hasop(m)))
- return 0;
- if (channel_fastop(chan) || channel_take(chan)) {
- // add_mode(chan, '+', 'o', nick);
- add_cookie(chan, nick);
- } else {
- add_cookie(chan, nick);
- }
- return 1;
- }
- static void
- flush_cookies(struct chanset_t *chan, int pri)
- {
- char *p = NULL, out[512] = "", post[512] = "";
- size_t postsize = sizeof(post);
- unsigned int i = 0;
- p = out;
- post[0] = 0, postsize--;
- chan->cbytes = 0;
- for (i = 0; i < (modesperline - 1); i++) {
- if (chan->ccmode[i].op && postsize > strlen(chan->ccmode[i].op)) {
- *p++ = '+';
- *p++ = 'o';
- postsize -= egg_strcatn(post, chan->ccmode[i].op, sizeof(post));
- postsize -= egg_strcatn(post, " ", sizeof(post));
- free(chan->ccmode[i].op), chan->ccmode[i].op = NULL;
- }
- }
- /* remember to terminate the buffer ('out')... */
- if (out[0]) {
- *p++ = '-';
- *p++ = 'b';
- }
- *p = 0;
- if (post[0]) {
- char *cookie = NULL;
- /* remove the trailing space... */
- size_t myindex = (sizeof(post) - 1) - postsize;
- if (myindex > 0 && post[myindex - 1] == ' ')
- post[myindex - 1] = 0;
- egg_strcatn(out, " ", sizeof(out));
- egg_strcatn(out, post, sizeof(out));
- egg_strcatn(out, " ", sizeof(out));
- cookie = makecookie(chan->dname, botname);
- egg_strcatn(out, cookie, sizeof(out));
- free(cookie);
- }
- if (out[0]) {
- if (pri == QUICK) {
- char outbuf[201] = "";
- sprintf(outbuf, "MODE %s %s\n", chan->name, out);
- tputs(serv, outbuf, strlen(outbuf));
- /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
- } else
- dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
- }
- }
- static void
- flush_mode(struct chanset_t *chan, int pri)
- {
- char *p = NULL, out[512] = "", post[512] = "";
- size_t postsize = sizeof(post);
- int plus = 2; /* 0 = '-', 1 = '+', 2 = none */
- unsigned int i = 0;
- if (!modesperline) /* Haven't received 005 yet :) */
- return;
- flush_cookies(chan, pri);
- /* dequeue_op_deop(chan); */
- p = out;
- post[0] = 0, postsize--;
- /* now does +o first.. */
- if (chan->mns[0]) {
- *p++ = '-', plus = 0;
- for (i = 0; i < strlen(chan->mns); i++)
- *p++ = chan->mns[i];
- chan->mns[0] = 0;
- }
- if (chan->pls[0]) {
- *p++ = '+', plus = 1;
- for (i = 0; i < strlen(chan->pls); i++)
- *p++ = chan->pls[i];
- chan->pls[0] = 0;
- }
- chan->bytes = 0;
- chan->compat = 0;
- /* +k or +l ? */
- if (chan->key && !chan->rmkey) {
- if (plus != 1) {
- *p++ = '+', plus = 1;
- }
- *p++ = 'k';
- postsize -= egg_strcatn(post, chan->key, sizeof(post));
- postsize -= egg_strcatn(post, " ", sizeof(post));
- free(chan->key), chan->key = NULL;
- }
- /* max +l is signed 2^32 on IRCnet at least... so makesure we've got at least
- * a 13 char buffer for '-2147483647 \0'. We'll be overwriting the existing
- * terminating null in 'post', so makesure postsize >= 12.
- */
- if (chan->limit != 0 && postsize >= 12) {
- if (plus != 1) {
- *p++ = '+', plus = 1;
- }
- *p++ = 'l';
- /* 'sizeof(post) - 1' is used because we want to overwrite the old null */
- postsize -= sprintf(&post[(sizeof(post) - 1) - postsize], "%d ", chan->limit);
- chan->limit = 0;
- }
- /* -k ? */
- if (chan->rmkey) {
- if (plus) {
- *p++ = '-', plus = 0;
- }
- *p++ = 'k';
- postsize -= egg_strcatn(post, chan->rmkey, sizeof(post));
- postsize -= egg_strcatn(post, " ", sizeof(post));
- free(chan->rmkey), chan->rmkey = NULL;
- }
- /* Do -{b,e,I} before +{b,e,I} to avoid the server ignoring overlaps */
- for (i = 0; i < modesperline; i++) {
- if ((chan->cmode[i].type & MINUS) && postsize > strlen(chan->cmode[i].op)) {
- if (plus) {
- *p++ = '-', plus = 0;
- }
- *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
- ((chan->cmode[i].type & CHOP) ? 'o' :
- ((chan->cmode[i].type & EXEMPT) ? 'e' : ((chan->cmode[i].type & INVITE) ? 'I' : 'v'))));
- postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
- postsize -= egg_strcatn(post, " ", sizeof(post));
- free(chan->cmode[i].op), chan->cmode[i].op = NULL;
- chan->cmode[i].type = 0;
- }
- }
- /* now do all the + modes... */
- for (i = 0; i < modesperline; i++) {
- if ((chan->cmode[i].type & PLUS) && postsize > strlen(chan->cmode[i].op)) {
- if (plus != 1) {
- *p++ = '+', plus = 1;
- }
- *p++ = ((chan->cmode[i].type & BAN) ? 'b' :
- ((chan->cmode[i].type & CHOP) ? 'o' :
- ((chan->cmode[i].type & EXEMPT) ? 'e' : ((chan->cmode[i].type & INVITE) ? 'I' : 'v'))));
- postsize -= egg_strcatn(post, chan->cmode[i].op, sizeof(post));
- postsize -= egg_strcatn(post, " ", sizeof(post));
- free(chan->cmode[i].op), chan->cmode[i].op = NULL;
- chan->cmode[i].type = 0;
- }
- }
- /* remember to terminate the buffer ('out')... */
- *p = 0;
- if (post[0]) {
- /* remove the trailing space... */
- size_t myindex = (sizeof(post) - 1) - postsize;
- if (myindex > 0 && post[myindex - 1] == ' ')
- post[myindex - 1] = 0;
- egg_strcatn(out, " ", sizeof(out));
- egg_strcatn(out, post, sizeof(out));
- }
- if (out[0]) {
- if (pri == QUICK) {
- char outbuf[201] = "";
- sprintf(outbuf, "MODE %s %s\n", chan->name, out);
- tputs(serv, outbuf, strlen(outbuf));
- /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
- } else
- dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
- }
- }
- /* Queue a channel mode change
- */
- void
- real_add_mode(struct chanset_t *chan, const char plus, const char mode, const char *op, int cookie)
- {
- int type, modes, l;
- unsigned int i;
- masklist *m = NULL;
- memberlist *mx = NULL;
- char s[21] = "";
- if (!me_op(chan))
- return;
- if (mode == 'o' || mode == 'v') {
- mx = ismember(chan, op);
- if (!mx)
- return;
- if (plus == '-' && mode == 'o') {
- if (chan_sentdeop(mx) || !chan_hasop(mx))
- return;
- mx->flags |= SENTDEOP;
- }
- if (plus == '+' && mode == 'o') {
- if (chan_sentop(mx) || chan_hasop(mx))
- return;
- mx->flags |= SENTOP;
- }
- if (plus == '-' && mode == 'v') {
- if (chan_sentdevoice(mx) || !chan_hasvoice(mx))
- return;
- mx->flags |= SENTDEVOICE;
- }
- if (plus == '+' && mode == 'v') {
- if (chan_sentvoice(mx) || chan_hasvoice(mx))
- return;
- mx->flags |= SENTVOICE;
- }
- }
- if (chan->compat == 0) {
- if (mode == 'e' || mode == 'I')
- chan->compat = 2;
- else
- chan->compat = 1;
- } else if (mode == 'e' || mode == 'I') {
- if (prevent_mixing && chan->compat == 1)
- flush_mode(chan, NORMAL);
- } else if (prevent_mixing && chan->compat == 2)
- flush_mode(chan, NORMAL);
- if (mode == 'o' || mode == 'b' || mode == 'v' || mode == 'e' || mode == 'I') {
- type = (plus == '+' ? PLUS : MINUS) |
- (mode == 'o' ? CHOP : (mode == 'b' ? BAN : (mode == 'v' ? VOICE : (mode == 'e' ? EXEMPT : INVITE))));
- /*
- * FIXME: Some networks remove overlapped bans,
- * IRCnet does not (poptix/drummer)
- *
- * Note: On IRCnet ischanXXX() should be used, otherwise isXXXed().
- */
- if ((plus == '-' && ((mode == 'b' && !ischanban(chan, op)) ||
- (mode == 'e' && !ischanexempt(chan, op)) ||
- (mode == 'I' && !ischaninvite(chan, op)))) || (plus == '+' &&
- ((mode == 'b' && ischanban(chan, op))
- || (mode == 'e' &&
- ischanexempt(chan, op)) ||
- (mode == 'I' &&
- ischaninvite(chan, op)))))
- return;
- /* If there are already max_bans bans, max_exempts exemptions,
- * max_invites invitations or max_modes +b/+e/+I modes on the
- * channel, don't try to add one more.
- */
- if (plus == '+' && (mode == 'b' || mode == 'e' || mode == 'I')) {
- int bans = 0, exempts = 0, invites = 0;
- for (m = chan->channel.ban; m && m->mask[0]; m = m->next)
- bans++;
- if ((mode == 'b') && (bans >= max_bans))
- return;
- for (m = chan->channel.exempt; m && m->mask[0]; m = m->next)
- exempts++;
- if ((mode == 'e') && (exempts >= max_exempts))
- return;
- for (m = chan->channel.invite; m && m->mask[0]; m = m->next)
- invites++;
- if ((mode == 'I') && (invites >= max_invites))
- return;
- if (bans + exempts + invites >= max_modes)
- return;
- }
- /* op-type mode change */
- /* for cookie ops, use ccmode instead of cmode */
- if (cookie) {
- for (i = 0; i < (modesperline - 1); i++)
- if (chan->ccmode[i].op != NULL && !rfc_casecmp(chan->ccmode[i].op, op))
- return; /* Already in there :- duplicate */
- l = strlen(op) + 1;
- if (chan->cbytes + l > mode_buf_len)
- flush_mode(chan, NORMAL);
- for (i = 0; i < (modesperline - 1); i++)
- if (!chan->ccmode[i].op) {
- chan->ccmode[i].op = (char *) calloc(1, l);
- chan->cbytes += l; /* Add 1 for safety */
- strcpy(chan->ccmode[i].op, op);
- break;
- }
- } else {
- for (i = 0; i < modesperline; i++)
- if (chan->cmode[i].type == type && chan->cmode[i].op != NULL && !rfc_casecmp(chan->cmode[i].op, op))
- return; /* Already in there :- duplicate */
- l = strlen(op) + 1;
- if (chan->bytes + l > mode_buf_len)
- flush_mode(chan, NORMAL);
- for (i = 0; i < modesperline; i++)
- if (chan->cmode[i].type == 0) {
- chan->cmode[i].type = type;
- chan->cmode[i].op = (char *) calloc(1, l);
- chan->bytes += l; /* Add 1 for safety */
- strcpy(chan->cmode[i].op, op);
- break;
- }
- }
- }
- /* +k ? store key */
- else if (plus == '+' && mode == 'k') {
- if (chan->key)
- free(chan->key);
- chan->key = (char *) calloc(1, strlen(op) + 1);
- strcpy(chan->key, op);
- }
- /* -k ? store removed key */
- else if (plus == '-' && mode == 'k') {
- if (chan->rmkey)
- free(chan->rmkey);
- chan->rmkey = (char *) calloc(1, strlen(op) + 1);
- strcpy(chan->rmkey, op);
- }
- /* +l ? store limit */
- else if (plus == '+' && mode == 'l')
- chan->limit = atoi(op);
- else {
- /* Typical mode changes */
- if (plus == '+')
- strcpy(s, chan->pls);
- else
- strcpy(s, chan->mns);
- if (!strchr(s, mode)) {
- if (plus == '+') {
- chan->pls[strlen(chan->pls) + 1] = 0;
- chan->pls[strlen(chan->pls)] = mode;
- } else {
- chan->mns[strlen(chan->mns) + 1] = 0;
- chan->mns[strlen(chan->mns)] = mode;
- }
- }
- }
- modes = modesperline; /* Check for full buffer. */
- for (i = 0; i < modesperline; i++)
- if (chan->cmode[i].type)
- modes--;
- if (include_lk && chan->limit)
- modes--;
- if (include_lk && chan->rmkey)
- modes--;
- if (include_lk && chan->key)
- modes--;
- if (modes < 1)
- flush_mode(chan, NORMAL); /* Full buffer! Flush modes. */
-
- /* flush full cookie queue */
- modes = modesperline - 1;
- for (i = 0; i < (modesperline - 1); i++)
- if (chan->ccmode[i].op)
- modes--;
- if (modes < 1)
- flush_cookies(chan, NORMAL);
- }
- /*
- * Mode parsing functions
- */
- static void
- got_key(struct chanset_t *chan, char *nick, char *from, char *key)
- {
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- if (((reversing) && !(chan->key_prot[0])) ||
- ((chan->mode_mns_prot & CHANKEY) && !(glob_master(user) || glob_bot(user) || chan_master(user)))) {
- if (strlen(key) != 0) {
- add_mode(chan, '-', 'k', key);
- } else {
- add_mode(chan, '-', 'k', "");
- }
- }
- }
- static void
- got_op(struct chanset_t *chan, char *nick, char *from,
- char *who, struct userrec *opu, struct flag_record *opper)
- {
- memberlist *m = NULL;
- char s[UHOSTLEN] = "";
- struct userrec *u;
- int check_chan = 0;
- int snm = chan->stopnethack_mode;
- m = ismember(chan, who);
- if (!m) {
- if (channel_pending(chan))
- return;
- putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, who);
- dprintf(DP_MODE, "WHO %s\n", who);
- return;
- }
- /* Did *I* just get opped? */
- if (!me_op(chan) && match_my_nick(who))
- check_chan = 1;
- if (!m->user) {
- simple_sprintf(s, "%s!%s", m->nick, m->userhost);
- u = get_user_by_host(s);
- } else
- u = m->user;
- get_user_flagrec(u, &victim, chan->dname);
- /* Flags need to be set correctly right from the beginning now, so that
- * add_mode() doesn't get irritated.
- */
- m->flags |= CHANOP;
- /* Added new meaning of WASOP:
- * in mode binds it means: was he op before get (de)opped
- * (stupid IrcNet allows opped users to be opped again and
- * opless users to be deopped)
- * script now can use [wasop nick chan] proc to check
- * if user was op or wasnt (drummer)
- */
- m->flags &= ~SENTOP;
- if (channel_pending(chan))
- return;
- /* I'm opped, and the opper isn't me */
- if (me_op(chan) && !match_my_nick(who) &&
- /* and it isn't a server op */
- nick[0]) {
- /* Channis is +bitch, and the opper isn't a global master or a bot */
- /* deop if they are +d or it is +bitch */
- if (chk_deop(victim) || (!loading && userlist && channel_bitch(chan) && !chk_op(victim, chan))) { /* chk_op covers +private */
- /* char outbuf[101] = ""; */
- /* if (target_priority(chan, m, 1)) */
- /* dprintf(DP_MODE, "MODE %s -o %s\n", chan->name, who); */
- add_mode(chan, '-', 'o', who);
- flush_mode(chan, QUICK);
- /* sprintf(outbuf, "MODE %s -o %s\n", chan->name, who);
- tputs(serv, outbuf, strlen(outbuf));
- */
- } else if (reversing) {
- add_mode(chan, '-', 'o', who);
- }
- } else if (reversing && !match_my_nick(who))
- add_mode(chan, '-', 'o', who);
- if (!nick[0] && me_op(chan) && !match_my_nick(who)) {
- if (chk_deop(victim)) {
- m->flags |= FAKEOP;
- add_mode(chan, '-', 'o', who);
- } else if (snm > 0 && snm < 7 && !((0 || 0 ||
- 0) && (chan_op(victim) || (glob_op(victim) &&
- !chan_deop(victim)))) &&
- !glob_exempt(victim) && !chan_exempt(victim)) {
- if (snm == 5)
- snm = channel_bitch(chan) ? 1 : 3;
- if (snm == 6)
- snm = channel_bitch(chan) ? 4 : 2;
- if (chan_wasoptest(victim) || glob_wasoptest(victim) || snm == 2) {
- if (!chan_wasop(m)) {
- m->flags |= FAKEOP;
- add_mode(chan, '-', 'o', who);
- }
- } else if (!(chan_op(victim) || (glob_op(victim) && !chan_deop(victim)))) {
- if (snm == 1 || snm == 4 || (snm == 3 && !chan_wasop(m))) {
- add_mode(chan, '-', 'o', who);
- m->flags |= FAKEOP;
- }
- } else if (snm == 4 && !chan_wasop(m)) {
- add_mode(chan, '-', 'o', who);
- m->flags |= FAKEOP;
- }
- }
- }
- m->flags |= WASOP;
- if (check_chan) {
- /* tell other bots to set jointime to 0 and join */
- char *buf = NULL;
- buf = calloc(1, strlen(chan->dname) + 3 + 1);
- sprintf(buf, "jn %s", chan->dname);
- putallbots(buf);
- free(buf);
- recheck_channel(chan, 1);
- }
- }
- static void
- got_deop(struct chanset_t *chan, char *nick, char *from, char *who, struct userrec *opu)
- {
- memberlist *m = NULL;
- char s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
- struct userrec *u = NULL;
- m = ismember(chan, who);
- if (!m) {
- if (channel_pending(chan))
- return;
- putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, who);
- dprintf(DP_MODE, "WHO %s\n", who);
- return;
- }
- simple_sprintf(s, "%s!%s", m->nick, m->userhost);
- simple_sprintf(s1, "%s!%s", nick, from);
- u = get_user_by_host(s);
- get_user_flagrec(u, &victim, chan->dname);
- /* Flags need to be set correctly right from the beginning now, so that
- * add_mode() doesn't get irritated.
- */
- m->flags &= ~(CHANOP | SENTDEOP | FAKEOP);
- /* Check comments in got_op() (drummer) */
- m->flags &= ~WASOP;
- if (channel_pending(chan))
- return;
- /* Deop'd someone on my oplist? */
- if (me_op(chan)) {
- int ok = 1;
- /* if they aren't d|d then check if they are something we should protect */
- if (!glob_deop(victim) && !chan_deop(victim)) {
- if (channel_protectops(chan) && (glob_master(victim) || chan_master(victim) ||
- glob_op(victim) || chan_op(victim)))
- ok = 0;
- }
- /* do we want to reop victim? */
- if ((reversing || !ok) && !match_my_nick(nick) && rfc_casecmp(who, nick) && !match_my_nick(who) &&
- /* Is the deopper NOT a master or bot? */
- !glob_master(user) && !chan_master(user) && !glob_bot(user) &&
- ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) || !channel_bitch(chan)))
- /* Then we'll bless the victim */
- do_op(who, chan, 0, 0);
- }
- if (!nick[0])
- putlog(LOG_MODES, chan->dname, "TS resync (%s): %s deopped by %s", chan->dname, who, from);
- /* Check for mass deop */
- if (nick[0])
- detect_chan_flood(nick, from, s1, chan, FLOOD_DEOP, who);
- /* Having op hides your +v and +h status -- so now that someone's lost ops,
- * check to see if they have +v or +h
- */
- if (!channel_take(chan) && !channel_bitch(chan) && !(m->flags & (CHANVOICE | STOPWHO))) {
- dprintf(DP_HELP, "WHO %s\n", m->nick);
- m->flags |= STOPWHO;
- }
- /* Was the bot deopped? */
- if (match_my_nick(who)) {
- /* Cancel any pending kicks and modes */
- memberlist *m2;
- for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
- m2->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTVOICE | SENTDEVOICE);
- chan->channel.do_opreq = 1;
- /* request_op(chan); */
- /* need: op */
- if (!nick[0])
- putlog(LOG_MODES, chan->dname, "TS resync deopped me on %s :(", chan->dname);
- }
- if (nick[0])
- maybe_revenge(chan, s1, s, REVENGE_DEOP);
- }
- static void
- got_ban(struct chanset_t *chan, char *nick, char *from, char *who)
- {
- char me[UHOSTLEN] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "";
- memberlist *m = NULL;
- struct userrec *u = NULL;
- egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
- egg_snprintf(s, sizeof s, "%s!%s", nick, from);
- newban(chan, who, s);
- if (channel_pending(chan) || !me_op(chan))
- return;
- if (wild_match(who, me) && !isexempted(chan, me)) {
- add_mode(chan, '-', 'b', who);
- reversing = 1;
- return;
- }
- if (!match_my_nick(nick)) {
- if (channel_nouserbans(chan) && nick[0] && !glob_bot(user)) {
- add_mode(chan, '-', 'b', who);
- return;
- }
- /* remove bans on ops unless a master/bot set it */
- for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
- egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
- if (wild_match(who, s1)) {
- u = get_user_by_host(s1);
- if (u) {
- get_user_flagrec(u, &victim, chan->dname);
- if (chk_op(victim, chan) && !chan_master(user) && !glob_master(user) &&
- !glob_bot(user) && !isexempted(chan, s1)) {
- /* if (target_priority(chan, m, 0)) */
- add_mode(chan, '-', 'b', who);
- return;
- }
- }
- }
- }
- }
- refresh_exempt(chan, who);
- /* This looks for bans added through bot and tacks on banned: if a description is found */
- if (nick[0] && channel_enforcebans(chan)) {
- register maskrec *b;
- int cycle;
- char resn[512] = "";
- /* The point of this cycle crap is to first check chan->bans then global_bans */
- for (cycle = 0; cycle < 2; cycle++) {
- for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
- if (wild_match(b->mask, who)) {
- if (b->desc && b->desc[0] != '@')
- egg_snprintf(resn, sizeof resn, "%s %s", IRC_PREBANNED, b->desc);
- else
- resn[0] = 0;
- }
- }
- }
- kick_all(chan, who, resn[0] ? resn : response(RES_BANNED), match_my_nick(nick) ? 0 : 1);
- }
- if (!nick[0] && (bounce_bans || bounce_modes) &&
- (!u_equals_mask(global_bans, who) || !u_equals_mask(chan->bans, who)))
- add_mode(chan, '-', 'b', who);
- }
- static void
- got_unban(struct chanset_t *chan, char *nick, char *from, char *who, struct userrec *u)
- {
- masklist *b = NULL, *old = NULL;
- for (b = chan->channel.ban; b->mask[0] && rfc_casecmp(b->mask, who); old = b, b = b->next) ;
- if (b->mask[0]) {
- if (old)
- old->next = b->next;
- else
- chan->channel.ban = b->next;
- free(b->mask);
- free(b->who);
- free(b);
- }
- if (channel_pending(chan))
- return;
- if (u_sticky_mask(chan->bans, who) || u_sticky_mask(global_bans, who)) {
- /* That's a sticky ban! No point in being
- * sticky unless we enforce it!!
- */
- add_mode(chan, '+', 'b', who);
- }
- if ((u_equals_mask(global_bans, who) || u_equals_mask(chan->bans, who)) &&
- me_op(chan) && !channel_dynamicbans(chan)) {
- /* That's a permban! */
- if (!glob_bot(user) && !chk_op(user, chan))
- add_mode(chan, '+', 'b', who);
- }
- }
- static void
- got_exempt(struct chanset_t *chan, char *nick, char *from, char *who)
- {
- char s[UHOSTLEN] = "";
- simple_sprintf(s, "%s!%s", nick, from);
- newexempt(chan, who, s);
- if (channel_pending(chan))
- return;
- if (!match_my_nick(nick)) { /* It's not my exemption */
- if (channel_nouserexempts(chan) && nick[0] && !glob_bot(user) && !glob_master(user) && !chan_master(user)) {
- /* No exempts made by users */
- add_mode(chan, '-', 'e', who);
- return;
- }
- if (!nick[0] && bounce_modes)
- reversing = 1;
- }
- if (reversing || (bounce_exempts && !nick[0] &&
- (!u_equals_mask(global_exempts, who) || !u_equals_mask(chan->exempts, who))))
- add_mode(chan, '-', 'e', who);
- }
- static void
- got_unexempt(struct chanset_t *chan, char *nick, char *from, char *who, struct userrec *u)
- {
- masklist *e = chan->channel.exempt, *old = NULL;
- masklist *b = NULL;
- int match = 0;
- while (e && e->mask[0] && rfc_casecmp(e->mask, who)) {
- old = e;
- e = e->next;
- }
- if (e && e->mask[0]) {
- if (old)
- old->next = e->next;
- else
- chan->channel.exempt = e->next;
- free(e->mask);
- free(e->who);
- free(e);
- }
- if (channel_pending(chan))
- return;
- if (u_sticky_mask(chan->exempts, who) || u_sticky_mask(global_exempts, who)) {
- /* That's a sticky exempt! No point in being sticky unless we enforce it!!
- */
- add_mode(chan, '+', 'e', who);
- }
- /* If exempt was removed by master then leave it else check for bans */
- if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)) {
- b = chan->channel.ban;
- while (b->mask[0] && !match) {
- if (wild_match(b->mask, who) || wild_match(who, b->mask)) {
- add_mode(chan, '+', 'e', who);
- match = 1;
- } else
- b = b->next;
- }
- }
- if ((u_equals_mask(global_exempts, who) || u_equals_mask(chan->exempts, who)) &&
- me_op(chan) && !channel_dynamicexempts(chan) && !glob_bot(user))
- add_mode(chan, '+', 'e', who);
- }
- static void
- got_invite(struct chanset_t *chan, char *nick, char *from, char *who)
- {
- char s[UHOSTLEN] = "";
- simple_sprintf(s, "%s!%s", nick, from);
- newinvite(chan, who, s);
- if (channel_pending(chan))
- return;
- if (!match_my_nick(nick)) { /* It's not my invitation */
- if (channel_nouserinvites(chan) && nick[0] && !glob_bot(user) && !glob_master(user) && !chan_master(user)) {
- /* No exempts made by users */
- add_mode(chan, '-', 'I', who);
- return;
- }
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- }
- if (reversing || (bounce_invites && (!nick[0]) &&
- (!u_equals_mask(global_invites, who) || !u_equals_mask(chan->invites, who))))
- add_mode(chan, '-', 'I', who);
- }
- static void
- got_uninvite(struct chanset_t *chan, char *nick, char *from, char *who, struct userrec *u)
- {
- masklist *inv = chan->channel.invite, *old = NULL;
- while (inv->mask[0] && rfc_casecmp(inv->mask, who)) {
- old = inv;
- inv = inv->next;
- }
- if (inv->mask[0]) {
- if (old)
- old->next = inv->next;
- else
- chan->channel.invite = inv->next;
- free(inv->mask);
- free(inv->who);
- free(inv);
- }
- if (channel_pending(chan))
- return;
- if (u_sticky_mask(chan->invites, who) || u_sticky_mask(global_invites, who)) {
- /* That's a sticky invite! No point in being sticky unless we enforce it!!
- */
- add_mode(chan, '+', 'I', who);
- }
- if (!nick[0] && glob_bot(user) && !glob_master(user) && !chan_master(user)
- && (chan->channel.mode & CHANINV))
- add_mode(chan, '+', 'I', who);
- if ((u_equals_mask(global_invites, who) ||
- u_equals_mask(chan->invites, who)) && me_op(chan) && !channel_dynamicinvites(chan) && !glob_bot(user))
- add_mode(chan, '+', 'I', who);
- }
- static int
- gotmode(char *from, char *msg)
- {
- char *nick = NULL, *ch = NULL, *op = NULL, *chg = NULL, s[UHOSTLEN] = "", ms2[3] = "";
- int z, isserver = 0;
- struct userrec *u = NULL;
- memberlist *m = NULL;
- struct chanset_t *chan = NULL;
- /* Usermode changes? */
- if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
- ch = newsplit(&msg);
- if (match_my_nick(ch))
- return 0;
- chan = findchan(ch);
- if (!chan) {
- putlog(LOG_MISC, "*", CHAN_FORCEJOIN, ch);
- dprintf(DP_SERVER, "PART %s\n", ch);
- return 0;
- }
- /* let's pre-emptively check for mass op/deop, manual ops and cookieops */
- if (!strchr(from, '!'))
- isserver++;
- if ((channel_active(chan) || channel_pending(chan))) {
- z = strlen(msg);
- if (msg[--z] == ' ') /* I hate cosmetic bugs :P -poptix */
- msg[z] = 0;
- /* Split up from */
- u = get_user_by_host(from);
- nick = splitnick(&from);
- if ((m = ismember(chan, nick))) {
- m->last = now;
- if (!m->user && u)
- m->user = u;
- }
- if (!isserver) {
- char **modes = NULL;
- char tmp[1024] = "", *wptr = NULL, *p = NULL, work[1024] = "", sign = '+';
- int modecnt = 0, i = 0, n = 0, ops = 0, deops = 0, bans = 0, unbans = 0, me_opped = 0;
- /* Split up the mode: #chan modes param param param param */
- strncpyz(work, msg, sizeof(work));
- wptr = work;
- p = newsplit(&wptr);
- modes = calloc(modesperline + 1, sizeof(char *));
- while (*p) { /* +MODES PARAM PARAM PARAM ... */
- char *mp = NULL;
- if (*p == '+')
- sign = '+';
- else if (*p == '-')
- sign = '-';
- else if (strchr("oblkvIe", p[0])) {
- mp = newsplit(&wptr); /* PARAM as noted above */
- if (strchr("ob", p[0])) {
- /* Just want o's and b's */
- modes[modecnt] = calloc(1, strlen(mp) + 4);
- sprintf(modes[modecnt], "%c%c %s", sign, p[0], mp);
- modecnt++;
- if (p[0] == 'o') {
- if (sign == '+') {
- ops++;
- if (match_my_nick(mp))
- me_opped++;
- } else
- deops++;
- }
- if (p[0] == 'b') {
- if (sign == '+')
- bans++;
- else
- unbans++;
- }
- }
- } else if (strchr("pstnmi", p[0])) {
- } else {
- /* hrmm... what modechar did i forget? */
- putlog(LOG_ERRORS, "*", "Forgotten modechar in irc:gotmode: %c", p[0]);
- }
- p++;
- }
- /* take ASAP */
- if (me_opped && !me_op(chan) && channel_take(chan))
- do_take(chan);
- /* Now we got modes[], chan, u, nick, and count of each relevant mode */
- /* check for mdop */
- if (me_op(chan)) {
- if (role && (!u || (u && !u->bot)) && m && !chan_sentkick(m)) {
- if (deops >= 3) {
- m->flags |= SENTKICK;
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, nick, kickprefix, response(RES_MASSDEOP));
- tputs(serv, tmp, strlen(tmp));
- if (u) {
- sprintf(tmp, "Mass deop on %s by %s", chan->dname, nick);
- deflag_user(u, DEFLAG_MDOP, tmp, chan);
- }
- }
- /* check for mop */
- if (ops >= 3) {
- if (channel_nomop(chan)) {
- m->flags |= SENTKICK;
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, nick, kickprefix, response(RES_MANUALOP));
- tputs(serv, tmp, strlen(tmp));
- if (u) {
- sprintf(tmp, "Mass op on %s by %s", chan->dname, nick);
- deflag_user(u, DEFLAG_MOP, tmp, chan);
- }
- enforce_bitch(chan); /* deop quick! */
- }
- }
- }
- if (ops && u) {
- if (u->bot && !channel_fastop(chan) && !channel_take(chan)) {
- int isbadop = 0;
- /* If no unbans or the -b is not the LAST mode, it's bad. */
- if (unbans != 1 || (strncmp(modes[modecnt - 1], "-b", 2))) {
- isbadop = 1;
- } else {
- char cookie[20] = "", *goodcookie = NULL;
- /* -b hash!rand@time */
- strncpyz(cookie, (char *) &(modes[modecnt - 1][3]), sizeof(cookie));
- checkcookie(chan->dname, nick, cookie);
- /*
- * last 6 digits of time
- * last 5 chars of nick
- * last 5 regular chars of chan
- */
- /*
- makeplaincookie(chan->dname, (char *) (modes[0] + 3), goodcookie);
- if (strncmp((char *) &plaincookie[6], (char *) &goodcookie[6], 5))
- isbadop = 2;
- else if (strncmp((char *) &plaincookie[11], (char *) &goodcookie[11], 5))
- isbadop = 3;
- else {
- char ltmp[20] = "";
- time_t optime, off;
- sprintf(ltmp, "%010li", now + timesync);
- strncpyz((char *) <mp[4], plaincookie, 7);
- optime = atol(ltmp);
- off = (now + timesync - optime);
- if (chan->cookie_time_slack && (abs(off) > chan->cookie_time_slack)) {
- // isbadop = 4;
- putlog(LOG_DEBUG, "*", "%s opped with bad ts (not punishing.): %li was off by %li", nick,
- optime, off);
- }
- }
- */
- }
- if (isbadop) {
- char trg[NICKLEN] = "";
- putlog(LOG_DEBUG, "*", "%s opped in %s with bad cookie(%d): %s", nick, chan->dname, isbadop,
- msg);
- n = i = 0;
- switch (role) {
- case 0:
- break;
- case 1:
- /* Kick opper */
- if (!m || !chan_sentkick(m)) {
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, nick, kickprefix, response(RES_BADOP));
- tputs(serv, tmp, strlen(tmp));
- if (m)
- m->flags |= SENTKICK;
- }
- sprintf(tmp, "%s!%s MODE %s", nick, from, msg);
- deflag_user(u, DEFLAG_BADCOOKIE, tmp, chan);
- break;
- default:
- n = role - 1;
- i = 0;
- while ((i < modecnt) && (n > 0)) {
- if (modes[i] && !strncmp(modes[i], "+o", 2))
- n--;
- if (n)
- i++;
- }
- if (!n) {
- memberlist *mo = NULL;
- strncpyz(trg, (char *) &modes[i][3], NICKLEN);
- mo = ismember(chan, trg);
- if (mo) {
- if (!(mo->flags & CHANOP)) {
- if (!chan_sentkick(mo)) {
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix,
- response(RES_BADOPPED));
- tputs(serv, tmp, strlen(tmp));
- mo->flags |= SENTKICK;
- }
- }
- }
- }
- }
- if (isbadop == 1)
- putlog(LOG_WARN, "*", "Missing cookie: %s!%s MODE %s", nick, from, msg);
- else if (isbadop == 2)
- putlog(LOG_WARN, "*", "Invalid cookie (bad nick): %s!%s MODE %s", nick, from, msg);
- else if (isbadop == 3)
- putlog(LOG_WARN, "*", "Invalid cookie (bad chan): %s!%s MODE %s", nick, from, msg);
- else if (isbadop == 4)
- putlog(LOG_WARN, "*", "Invalid cookie (bad time): %s!%s MODE %s", nick, from, msg);
- } else
- putlog(LOG_DEBUG, "@", "Good op: %s", msg);
- }
- if (!channel_manop(chan) && !u->bot) {
- char trg[NICKLEN] = "";
- n = i = 0;
- switch (role) {
- case 0:
- break;
- case 1:
- /* Kick opper */
- if (!m || !chan_sentkick(m)) {
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, nick, kickprefix, response(RES_MANUALOP));
- tputs(serv, tmp, strlen(tmp));
- if (m)
- m->flags |= SENTKICK;
- }
- sprintf(tmp, "%s!%s MODE %s", nick, from, msg);
- deflag_user(u, DEFLAG_MANUALOP, tmp, chan);
- break;
- default:
- n = role - 1;
- i = 0;
- while ((i < modecnt) && (n > 0)) {
- if (modes[i] && !strncmp(modes[i], "+o", 2))
- n--;
- if (n)
- i++;
- }
- if (!n) {
- memberlist *mo = NULL;
- strncpyz(trg, (char *) &modes[i][3], NICKLEN);
- mo = ismember(chan, trg);
- if (mo) {
- if (!(mo->flags & CHANOP) && !match_my_nick(trg)) {
- if (!chan_sentkick(mo)) {
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix,
- response(RES_MANUALOPPED));
- tputs(serv, tmp, strlen(tmp));
- m->flags |= SENTKICK;
- }
- }
- } else {
- sprintf(tmp, "KICK %s %s :%s%s\n", chan->name, trg, kickprefix,
- response(RES_MANUALOPPED));
- tputs(serv, tmp, strlen(tmp));
- }
- }
- }
- }
- }
- }
- for (i = 0; i < modecnt; i++)
- if (modes[i])
- free(modes[i]);
- free(modes);
- }
- /* Now do the modes again, this time throughly... */
- chg = newsplit(&msg);
- reversing = 0;
- irc_log(chan, "%s!%s sets mode: %s %s", nick, from, chg, msg);
- get_user_flagrec(u, &user, ch);
- if (channel_active(chan) && m && me_op(chan)) {
- if (chan_fakeop(m)) {
- putlog(LOG_MODES, ch, CHAN_FAKEMODE, ch);
- dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix, CHAN_FAKEMODE_KICK);
- m->flags |= SENTKICK;
- reversing = 1;
- } else if (m->nick && !isserver && /* HOW ABOUT IF THEY ARENT A FUCKING SERVER? */
- !chan_hasop(m) && !channel_nodesynch(chan)) {
- putlog(LOG_MODES, ch, CHAN_DESYNCMODE, ch);
- dprintf(DP_MODE, "KICK %s %s :%s%s\n", ch, nick, kickprefix, CHAN_DESYNCMODE_KICK);
- m->flags |= SENTKICK;
- reversing = 1;
- }
- }
- ms2[0] = '+';
- ms2[2] = 0;
- while ((ms2[1] = *chg)) {
- int todo = 0;
- switch (*chg) {
- case '+':
- ms2[0] = '+';
- break;
- case '-':
- ms2[0] = '-';
- break;
- case 'i':
- todo = CHANINV;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'p':
- todo = CHANPRIV;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 's':
- todo = CHANSEC;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'm':
- todo = CHANMODER;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'c':
- todo = CHANNOCLR;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'C':
- todo = CHANNOCTCP;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'R':
- todo = CHANREGON;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'M':
- todo = CHANMODR;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'r':
- todo = CHANLONLY;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 't':
- todo = CHANTOPIC;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'n':
- todo = CHANNOMSG;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'a':
- todo = CHANANON;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'q':
- todo = CHANQUIET;
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- break;
- case 'l':
- if ((!nick[0]) && (bounce_modes))
- reversing = 1;
- if (ms2[0] == '-') {
- if (channel_active(chan)) {
- if ((reversing) && (chan->channel.maxmembers != 0)) {
- simple_sprintf(s, "%d", chan->channel.maxmembers);
- add_mode(chan, '+', 'l', s);
- } else if ((chan->limit_prot != 0) && !glob_master(user) && !chan_master(user)) {
- simple_sprintf(s, "%d", chan->limit_prot);
- add_mode(chan, '+', 'l', s);
- } else {
- if (dolimit(chan) && (!chan_master(user) && !glob_master(user) && !glob_bot(user))) {
- if (chan->limitraise) {
- chan->channel.maxmembers = 0; /* set this to 0 so a new limit is generated */
- raise_limit(chan);
- }
- }
- }
- }
- chan->channel.maxmembers = 0;
- } else {
- op = newsplit(&msg);
- fixcolon(op);
- if (op == '\0')
- break;
- chan->channel.maxmembers = atoi(op);
- if (channel_pending(chan))
- break;
- if (((reversing) &&
- !(chan->mode_pls_prot & CHANLIMIT)) ||
- ((chan->mode_mns_prot & CHANLIMIT) && !glob_master(user) && !chan_master(user)))
- add_mode(chan, '-', 'l', "");
- if ((chan->limit_prot != chan->channel.maxmembers) && (chan->mode_pls_prot & CHANLIMIT) && (chan->limit_prot != 0) && /* arthur2 */
- !glob_master(user) && !chan_master(user)) {
- simple_sprintf(s, "%d", chan->limit_prot);
- add_mode(chan, '+', 'l', s);
- }
- if (!glob_bot(user))
- if (dolimit(chan) && (!chan_master(user) && !glob_master(user)))
- if (chan->limitraise)
- raise_limit(chan);
- }
- break;
- case 'k':
- if (ms2[0] == '+')
- chan->channel.mode |= CHANKEY;
- else
- chan->channel.mode &= ~CHANKEY;
- op = newsplit(&msg);
- fixcolon(op);
- if (op == '\0') {
- break;
- }
- if (ms2[0] == '+') {
- my_setkey(chan, op);
- if (channel_active(chan))
- got_key(chan, nick, from, op);
- } else {
- if (channel_active(chan)) {
- if ((reversing) && (chan->channel.key[0]))
- add_mode(chan, '+', 'k', chan->channel.key);
- else if ((chan->key_prot[0]) && !glob_master(user)
- && !chan_master(user))
- add_mode(chan, '+', 'k', chan->key_prot);
- }
- my_setkey(chan, NULL);
- }
- break;
- case 'o':
- chan->channel.fighting++;
- op = newsplit(&msg);
- fixcolon(op);
- if (ms2[0] == '+')
- got_op(chan, nick, from, op, u, &user);
- else
- got_deop(chan, nick, from, op, u);
- break;
- case 'v':
- op = newsplit(&msg);
- fixcolon(op);
- m = ismember(chan, op);
- if (!m) {
- if (channel_pending(chan))
- break;
- putlog(LOG_MISC, chan->dname, CHAN_BADCHANMODE, chan->dname, op);
- dprintf(DP_MODE, "WHO %s\n", op);
- } else {
- int dv = 0;
- simple_sprintf(s, "%s!%s", m->nick, m->userhost);
- get_user_flagrec(m->user ? m->user : get_user_by_host(s), &victim, chan->dname);
- if (ms2[0] == '+') {
- if (m->flags & EVOICE) {
- /* FIXME: This is a lame check, we need to expand on this more */
- if (!chan_master(user) && !glob_master(user)) {
- dv++;
- } else {
- m->flags &= ~EVOICE;
- }
- }
- m->flags &= ~SENTVOICE;
- m->flags |= CHANVOICE;
- if (channel_active(chan) && dovoice(chan)) {
- if (dv || chk_devoice(victim)) {
- add_mode(chan, '-', 'v', op);
- } else if (reversing) {
- add_mode(chan, '-', 'v', op);
- }
- }
- } else if (ms2[0] == '-') {
- m->flags &= ~SENTDEVOICE;
- m->flags &= ~CHANVOICE;
- if (channel_active(chan) && dovoice(chan)) {
- /* revoice +v users */
- if (chk_voice(victim, chan)) {
- add_mode(chan, '+', 'v', op);
- } else if (reversing) {
- add_mode(chan, '+', 'v', op);
- /* if they arent +v|v and VOICER is m+ then EVOICE them */
- } else {
- /* FIXME: same thing here */
- if (!match_my_nick(nick) && channel_voice(chan) &&
- (glob_master(user) || chan_master(user) || glob_bot(user))) {
- /* if the user is not +q set them norEVOICE. */
- if (!chan_quiet(victim) && !(m->flags & EVOICE)) {
- putlog(LOG_DEBUG, "@", "Giving EVOICE flag to: %s (%s)", m->nick, chan->dname);
- m->flags |= EVOICE;
- }
- }
- }
- }
- }
- }
- break;
- case 'b':
- chan->channel.fighting++;
- op = newsplit(&msg);
- fixcolon(op);
- if (ms2[0] == '+')
- got_ban(chan, nick, from, op);
- else
- got_unban(chan, nick, from, op, u);
- break;
- case 'e':
- chan->channel.fighting++;
- op = newsplit(&msg);
- fixcolon(op);
- if (ms2[0] == '+')
- got_exempt(chan, nick, from, op);
- else
- got_unexempt(chan, nick, from, op, u);
- break;
- case 'I':
- chan->channel.fighting++;
- op = newsplit(&msg);
- fixcolon(op);
- if (ms2[0] == '+')
- got_invite(chan, nick, from, op);
- else
- got_uninvite(chan, nick, from, op, u);
- break;
- }
- if (todo) {
- if (ms2[0] == '+')
- chan->channel.mode |= todo;
- else
- chan->channel.mode &= ~todo;
- if (channel_active(chan)) {
- if ((((ms2[0] == '+') && (chan->mode_mns_prot & todo)) ||
- ((ms2[0] == '-') && (chan->mode_pls_prot & todo))) &&
- !glob_master(user) && !chan_master(user))
- add_mode(chan, ms2[0] == '+' ? '-' : '+', *chg, "");
- else if (reversing &&
- ((ms2[0] == '+') || (chan->mode_pls_prot & todo)) &&
- ((ms2[0] == '-') || (chan->mode_mns_prot & todo)))
- add_mode(chan, ms2[0] == '+' ? '-' : '+', *chg, "");
- }
- }
- chg++;
- }
- if (chan->channel.do_opreq)
- request_op(chan);
- if (!me_op(chan) && !nick[0])
- chan->status |= CHAN_ASKEDMODES;
- }
- }
- return 0;
- }
- #endif /* LEAF */
|