-/** Check a key against a keyring.
- * We are now treating the key part of /join channellist key as a key
- * ring; that is, we try one key against the actual channel key, and if that
- * doesn't work, we try the next one, and so on. -Kev -Texaco
- * Returns: 0 on match, 1 otherwise
- * This version contributed by SeKs \<intru@info.polymtl.ca\>
- *
- * @param key Key to check
- * @param keyring Comma separated list of keys
- *
- * @returns True if the key was found and matches, false otherwise.
- */
-static int compall(char *key, char *keyring)
-{
- char *p1;
-
-top:
- p1 = key; /* point to the key... */
- while (*p1 && *p1 == *keyring)
- { /* step through the key and ring until they
- don't match... */
- p1++;
- keyring++;
- }
-
- if (!*p1 && (!*keyring || *keyring == ','))
- /* ok, if we're at the end of the and also at the end of one of the keys
- in the keyring, we have a match */
- return 0;
-
- if (!*keyring) /* if we're at the end of the key ring, there
- weren't any matches, so we return 1 */
- return 1;
-
- /* Not at the end of the key ring, so step
- through to the next key in the ring: */
- while (*keyring && *(keyring++) != ',');
-
- goto top; /* and check it against the key */
-}
-
-/** Returns if a user can join a channel with a specific key.
- *
- * @param sptr The client trying to join
- * @param chptr The channel to join
- * @param key The key to use
- *
- * @returns any error that occurred bit-wise OR'd with MAGIC_OPER_OVERRIDE
- * if the oper used the magic key, 0 if no error occurred.
- */
-int can_join(struct Client *sptr, struct Channel *chptr, char *key)
-{
- int overrideJoin = 0;
-
- /*
- * Now a banned user CAN join if invited -- Nemesi
- * Now a user CAN escape channel limit if invited -- bfriendly
- * Now a user CAN escape anything if invited -- Isomer
- */
-
- if (IsInvited(sptr, chptr))
- return 0;
-
- /* An oper can force a join on a local channel using "OVERRIDE" as the key.
- a HACK(4) notice will be sent if he would not have been supposed
- to join normally. */
- if (IsLocalChannel(chptr->chname) && HasPriv(sptr, PRIV_WALK_LCHAN) &&
- !BadPtr(key) && compall("OVERRIDE",chptr->mode.key) != 0 &&
- compall("OVERRIDE",key) == 0)
- overrideJoin = MAGIC_OPER_OVERRIDE;
-
- if (chptr->mode.mode & MODE_INVITEONLY)
- return overrideJoin + ERR_INVITEONLYCHAN;
-
- if (chptr->mode.limit && chptr->users >= chptr->mode.limit)
- return overrideJoin + ERR_CHANNELISFULL;
-
- if ((chptr->mode.mode & MODE_REGONLY) && !IsAccount(sptr))
- return overrideJoin + ERR_NEEDREGGEDNICK;
-
- if (find_ban(sptr, chptr->banlist))
- return overrideJoin + ERR_BANNEDFROMCHAN;
-
- /*
- * now using compall (above) to test against a whole key ring -Kev
- */
- if (*chptr->mode.key && (EmptyString(key) || compall(chptr->mode.key, key)))
- return overrideJoin + ERR_BADCHANNELKEY;
-
- if (overrideJoin)
- return ERR_DONTCHEAT;
-
- return 0;
-}
-
-/** Remove bells and commas from channel name
- *
- * @param cn Channel name to clean, modified in place.
- */
-void clean_channelname(char *cn)
-{
- int i;
-
- for (i = 0; cn[i]; i++) {
- if (i >= CHANNELLEN || !IsChannelChar(cn[i])) {
- cn[i] = '\0';
- return;
- }
- if (IsChannelLower(cn[i])) {
- cn[i] = ToLower(cn[i]);
-#ifndef FIXME
- /*
- * Remove for .08+
- * toupper(0xd0)
- */
- if ((unsigned char)(cn[i]) == 0xd0)
- cn[i] = (char) 0xf0;
-#endif
- }
- }
-}
-