/* Check whether I'm voice. Returns boolean 1 or 0. */ static int me_voice(struct chanset_t *chan) { memberlist *mx; mx = ismember(chan, botname); if (!mx) return 0; if (chan_hasvoice(mx)) return 1; else return 0; }
/* Report the channel status of every active channel to dcc chat every * 5 minutes. */ static void status_log() { masklist *b; memberlist *m; struct chanset_t *chan; char s[20], s2[20]; int chops, halfops, voice, nonops, bans, invites, exempts; if (!server_online) return; for (chan = chanset; chan != NULL; chan = chan->next) { if (channel_active(chan) && channel_logstatus(chan) && !channel_inactive(chan)) { chops = 0; voice = 0; halfops = 0; for (m = chan->channel.member; m && m->nick[0]; m = m->next) { if (chan_hasop(m)) chops++; else if (chan_hashalfop(m)) halfops++; else if (chan_hasvoice(m)) voice++; } nonops = (chan->channel.members - (chops + voice + halfops)); for (bans = 0, b = chan->channel.ban; b->mask[0]; b = b->next) bans++; for (exempts = 0, b = chan->channel.exempt; b->mask[0]; b = b->next) exempts++; for (invites = 0, b = chan->channel.invite; b->mask[0]; b = b->next) invites++; sprintf(s, "%d", exempts); sprintf(s2, "%d", invites); putlog(LOG_MISC, chan->dname, "%s%s (%s) : [m/%d o/%d h/%d v/%d n/%d b/%d e/%s I/%s]", me_op(chan) ? "@" : me_voice(chan) ? "+" : me_halfop(chan) ? "%" : "", chan->dname, getchanmode(chan), chan->channel.members, chops, halfops, voice, nonops, bans, use_exempts ? s : "-", use_invites ? s2 : "-"); } } }
/* Queue a channel mode change */ static void real_add_mode(struct chanset_t *chan, char plus, char mode, char *op) { int i, type, modes, l; masklist *m; memberlist *mx; char s[21]; /* Some IRCds do not allow halfops to set certain modes. The modes halfops * are not allowed to set can be changed in chan.h. */ #ifdef NO_HALFOP_CHANMODES if (!me_op(chan)) #else if (HALFOP_CANTDOMODE(mode)) #endif return; if (mode == 'o' || mode == 'h' || 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 == 'h') { if (chan_sentdehalfop(mx) || !chan_hashalfop(mx)) return; mx->flags |= SENTDEHALFOP; } if (plus == '+' && mode == 'h') { if (chan_senthalfop(mx) || chan_hashalfop(mx)) return; mx->flags |= SENTHALFOP; } 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 == 'h' || mode == 'b' || mode == 'v' || mode == 'e' || mode == 'I') { type = (plus == '+' ? PLUS : MINUS) | (mode == 'o' ? CHOP : (mode == 'h' ? CHHOP : (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 (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 *) channel_malloc(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) nfree(chan->key); chan->key = (char *) channel_malloc(strlen(op) + 1); if (chan->key) strcpy(chan->key, op); } /* -k ? store removed key */ else if (plus == '-' && mode == 'k') { if (chan->rmkey) nfree(chan->rmkey); chan->rmkey = (char *) channel_malloc(strlen(op) + 1); if (chan->rmkey) 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. */ }