+ joinbuf_join(&create, chptr, CHFL_CHANOP | CHFL_CHANNEL_MANAGER);
+ } else if (find_member_link(chptr, sptr)) {
+ continue; /* already on channel */
+ } else if (check_target_limit(sptr, chptr, chptr->chname, 0)) {
+ continue;
+ } else {
+ int flags = CHFL_DEOPPED;
+ int err = 0;
+
+ /* Check Apass/Upass -- since we only ever look at a single
+ * "key" per channel now, this hampers brute force attacks. */
+ if (key && !strcmp(key, chptr->mode.apass))
+ flags = CHFL_CHANOP | CHFL_CHANNEL_MANAGER;
+ else if (key && !strcmp(key, chptr->mode.upass))
+ flags = CHFL_CHANOP;
+ else if (chptr->users == 0 && !chptr->mode.apass[0]) {
+ /* Joining a zombie channel (zannel): give ops and increment TS. */
+ flags = CHFL_CHANOP;
+ chptr->creationtime++;
+ } else if (IsInvited(sptr, chptr)) {
+ /* Invites bypass these other checks. */
+ } else if (chptr->mode.mode & MODE_INVITEONLY)
+ err = ERR_INVITEONLYCHAN;
+ else if (chptr->mode.limit && (chptr->users >= chptr->mode.limit))
+ err = ERR_CHANNELISFULL;
+ else if ((chptr->mode.mode & MODE_REGONLY) && !IsAccount(sptr))
+ err = ERR_NEEDREGGEDNICK;
+ else if (find_ban(sptr, chptr->banlist))
+ err = ERR_BANNEDFROMCHAN;
+ else if (*chptr->mode.key && (!key || strcmp(key, chptr->mode.key)))
+ err = ERR_BADCHANNELKEY;
+
+ /* An oper with WALK_LCHAN privilege can join a local channel
+ * he otherwise could not join by using "OVERRIDE" as the key.
+ * This will generate a HACK(4) notice, but fails if the oper
+ * could normally join the channel. */
+ if (IsLocalChannel(chptr->chname)
+ && HasPriv(sptr, PRIV_WALK_LCHAN)
+ && !(flags & CHFL_CHANOP)
+ && key && !strcmp(key, "OVERRIDE"))
+ {
+ switch (err) {
+ case 0:
+ if (strcmp(chptr->mode.key, "OVERRIDE")
+ && strcmp(chptr->mode.apass, "OVERRIDE")
+ && strcmp(chptr->mode.upass, "OVERRIDE")) {
+ send_reply(sptr, ERR_DONTCHEAT, chptr->chname);
+ continue;
+ }
+ break;
+ case ERR_INVITEONLYCHAN: err = 'i'; break;
+ case ERR_CHANNELISFULL: err = 'l'; break;
+ case ERR_BANNEDFROMCHAN: err = 'b'; break;
+ case ERR_BADCHANNELKEY: err = 'k'; break;
+ case ERR_NEEDREGGEDNICK: err = 'r'; break;
+ default: err = '?'; break;
+ }
+ /* send accountability notice */
+ if (err)
+ sendto_opmask_butone(0, SNO_HACK4, "OPER JOIN: %C JOIN %H "
+ "(overriding +%c)", sptr, chptr, err);
+ err = 0;
+ }