* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
*/
+/** @file
+ * @brief Channel management and maintenance
+ * @version $Id$
+ */
+#include "config.h"
+
#include "channel.h"
#include "client.h"
+#include "destruct_event.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_chattr.h"
+#include "ircd_defs.h"
+#include "ircd_features.h"
+#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "match.h"
#include "msg.h"
+#include "msgq.h"
#include "numeric.h"
#include "numnicks.h"
#include "querycmds.h"
#include "s_misc.h"
#include "s_user.h"
#include "send.h"
-#include "sprintf_irc.h"
#include "struct.h"
-#include "support.h"
#include "sys.h"
#include "whowas.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/** Linked list containing the full list of all channels */
struct Channel* GlobalChannelList = 0;
+/** Number of struct Membership*'s allocated */
static unsigned int membershipAllocCount;
+/** Freelist for struct Membership*'s */
static struct Membership* membershipFreeList;
-
-static struct SLink *next_overlapped_ban(void);
-static int del_banid(struct Channel *, char *, int);
-void del_invite(struct Client *, struct Channel *);
-
-const char* const PartFmt1 = ":%s " MSG_PART " %s";
-const char* const PartFmt2 = ":%s " MSG_PART " %s :%s";
-const char* const PartFmt1serv = "%s%s " TOK_PART " %s";
-const char* const PartFmt2serv = "%s%s " TOK_PART " %s :%s";
-
-
-static struct SLink* next_ban;
-static struct SLink* prev_ban;
-static struct SLink* removed_bans_list;
-
-/*
- * Use a global variable to remember if an oper set a mode on a local channel. Ugly,
- * but the only way to do it without changing set_mode intensively.
- */
-int LocalChanOperMode = 0;
+/** Freelist for struct Ban*'s */
+static struct Ban* free_bans;
+/** Number of ban structures allocated. */
+static size_t bans_alloc;
+/** Number of ban structures in use. */
+static size_t bans_inuse;
#if !defined(NDEBUG)
-/*
- * return the length (>=0) of a chain of links.
+/** return the length (>=0) of a chain of links.
+ * @param lp pointer to the start of the linked list
+ * @return the number of items in the list
*/
static int list_length(struct SLink *lp)
{
}
#endif
+/** Set the mask for a ban, checking for IP masks.
+ * @param[in,out] ban Ban structure to modify.
+ * @param[in] banstr Mask to ban.
+ */
+static void
+set_ban_mask(struct Ban *ban, const char *banstr)
+{
+ char *sep;
+ assert(banstr != NULL);
+ ircd_strncpy(ban->banstr, banstr, sizeof(ban->banstr) - 1);
+ sep = strrchr(banstr, '@');
+ if (sep) {
+ ban->nu_len = sep - banstr;
+ if (ipmask_parse(sep + 1, &ban->address, &ban->addrbits))
+ ban->flags |= BAN_IPMASK;
+ }
+}
+
+/** Allocate a new Ban structure.
+ * @param[in] banstr Ban mask to use.
+ * @return Newly allocated ban.
+ */
+struct Ban *
+make_ban(const char *banstr)
+{
+ struct Ban *ban;
+ if (free_bans) {
+ ban = free_bans;
+ free_bans = free_bans->next;
+ }
+ else if (!(ban = MyMalloc(sizeof(*ban))))
+ return NULL;
+ else
+ bans_alloc++;
+ bans_inuse++;
+ memset(ban, 0, sizeof(*ban));
+ set_ban_mask(ban, banstr);
+ return ban;
+}
+
+/** Deallocate a ban structure.
+ * @param[in] ban Ban to deallocate.
+ */
+void
+free_ban(struct Ban *ban)
+{
+ ban->next = free_bans;
+ free_bans = ban;
+ bans_inuse--;
+}
+
+/** Report ban usage to \a cptr.
+ * @param[in] cptr Client requesting information.
+ */
+void bans_send_meminfo(struct Client *cptr)
+{
+ struct Ban *ban;
+ size_t num_free;
+ for (num_free = 0, ban = free_bans; ban; ban = ban->next)
+ num_free++;
+ send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Bans: inuse %zu(%zu) free %zu alloc %zu",
+ bans_inuse, bans_inuse * sizeof(*ban), num_free, bans_alloc);
+}
+
+/** return the struct Membership* that represents a client on a channel
+ * This function finds a struct Membership* which holds the state about
+ * a client on a specific channel. The code is smart enough to iterate
+ * over the channels a user is in, or the users in a channel to find the
+ * user depending on which is likely to be more efficient.
+ *
+ * @param chptr pointer to the channel struct
+ * @param cptr pointer to the client struct
+ *
+ * @returns pointer to the struct Membership representing this client on
+ * this channel. Returns NULL if the client is not on the channel.
+ * Returns NULL if the client is actually a server.
+ * @see find_channel_member()
+ */
struct Membership* find_member_link(struct Channel* chptr, const struct Client* cptr)
{
struct Membership *m;
* and 99% are on 10 or less.
*/
else {
- m = cptr->user->channel;
+ m = (cli_user(cptr))->channel;
while (m) {
assert(m->user == cptr);
if (m->channel == chptr)
return 0;
}
-/*
- * find_chasing - Find the client structure for a nick name (user)
+/** Find the client structure for a nick name (user)
+ * Find the client structure for a nick name (user)
* using history mechanism if necessary. If the client is not found, an error
* message (NO SUCH NICK) is generated. If the client was found
* through the history, chasing will be 1 and otherwise 0.
+ *
+ * This function was used extensively in the P09 days, and since we now have
+ * numeric nicks is no longer quite as important.
+ *
+ * @param sptr Pointer to the client that has requested the search
+ * @param user a string representing the client to be found
+ * @param chasing a variable set to 0 if the user was found directly,
+ * 1 otherwise
+ * @returns a pointer the client, or NULL if the client wasn't found.
*/
struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing)
{
if (who)
return who;
- if (!(who = get_history(user, KILLCHASETIMELIMIT))) {
+ if (!(who = get_history(user, feature_int(FEAT_KILLCHASETIMELIMIT)))) {
send_reply(sptr, ERR_NOSUCHNICK, user);
return 0;
}
return who;
}
-/*
- * Create a string of form "foo!bar@fubar" given foo, bar and fubar
- * as the parameters. If NULL, they become "*".
- */
-static char *make_nick_user_host(const char *nick, const char *name,
- const char *host)
-{
- static char namebuf[NICKLEN + USERLEN + HOSTLEN + 3];
- sprintf_irc(namebuf, "%s!%s@%s", nick, name, host);
- return namebuf;
-}
-
-/*
- * Create a string of form "foo!bar@123.456.789.123" given foo, bar and the
- * IP-number as the parameters. If NULL, they become "*".
- */
-static char *make_nick_user_ip(char *nick, char *name, struct in_addr ip)
-{
- static char ipbuf[NICKLEN + USERLEN + 16 + 3];
- sprintf_irc(ipbuf, "%s!%s@%s", nick, name, ircd_ntoa((const char*) &ip));
- return ipbuf;
-}
-
-#if 0
-static int DoesOp(const char* modebuf)
-{
- assert(0 != modebuf);
- while (*modebuf) {
- if (*modebuf == 'o' || *modebuf == 'v')
- return 1;
- ++modebuf;
- }
- return 0;
-}
-
-/*
- * This function should be removed when all servers are 2.10
- */
-static void sendmodeto_one(struct Client* cptr, const char* from,
- const char* name, const char* mode,
- const char* param, time_t creationtime)
-{
- if (IsServer(cptr) && DoesOp(mode) && creationtime)
- sendto_one(cptr, ":%s MODE %s %s %s " TIME_T_FMT, /* XXX DEAD */
- from, name, mode, param, creationtime);
- else
- sendto_one(cptr, ":%s MODE %s %s %s", from, name, mode, param); /* XXX DEAD */
-}
-#endif /* 0 */
-
-/*
- * Subtract one user from channel i (and free channel
- * block, if channel became empty).
- * Returns: true (1) if channel still exists
- * false (0) if the channel was destroyed
+/** Decrement the count of users, and free if empty.
+ * Subtract one user from channel i (and free channel * block, if channel
+ * became empty).
+ *
+ * @param chptr The channel to subtract one from.
+ *
+ * @returns true (1) if channel still has members.
+ * false (0) if the channel is now empty.
*/
int sub1_from_channel(struct Channel* chptr)
{
- struct SLink *tmp;
- struct SLink *obtmp;
-
if (chptr->users > 1) /* Can be 0, called for an empty channel too */
{
assert(0 != chptr->members);
return 1;
}
+ chptr->users = 0;
+
+ /* There is a semantics problem here: Assuming no fragments across a
+ * split, a channel without Apass could be maliciously destroyed and
+ * recreated, and someone could set apass on the new instance.
+ *
+ * This could be fixed by preserving the empty non-Apass channel for
+ * the same time as if it had an Apass (but removing +i and +l), and
+ * reopping the first user to rejoin. However, preventing net rides
+ * requires a backwards-incompatible protocol change..
+ */
+ if (!chptr->mode.apass[0]) /* If no Apass, destroy now. */
+ destruct_channel(chptr);
+ else if (TStime() - chptr->creationtime < 172800) /* Channel younger than 48 hours? */
+ schedule_destruct_event_1m(chptr); /* Get rid of it in approximately 4-5 minutes */
+ else
+ schedule_destruct_event_48h(chptr); /* Get rid of it in approximately 48 hours */
+
+ return 0;
+}
+
+/** Destroy an empty channel
+ * This function destroys an empty channel, removing it from hashtables,
+ * and removing any resources it may have consumed.
+ *
+ * @param chptr The channel to destroy
+ *
+ * @returns 0 (success)
+ *
+ * FIXME: Change to return void, this function never fails.
+ */
+int destruct_channel(struct Channel* chptr)
+{
+ struct Ban *ban, *next;
+
assert(0 == chptr->members);
- /* Channel became (or was) empty: Remove channel */
- if (is_listed(chptr))
- {
- int i;
- for (i = 0; i <= HighestFd; i++)
- {
- struct Client *acptr = 0;
- if ((acptr = LocalClientArray[i]) && acptr->listing &&
- acptr->listing->chptr == chptr)
- {
- list_next_channels(acptr, 1);
- break; /* Only one client can list a channel */
- }
- }
- }
/*
* Now, find all invite links from channel structure
*/
- while ((tmp = chptr->invites))
- del_invite(tmp->value.cptr, chptr);
+ while (chptr->invites)
+ del_invite(chptr->invites->value.cptr, chptr);
- tmp = chptr->banlist;
- while (tmp)
+ for (ban = chptr->banlist; ban; ban = next)
{
- obtmp = tmp;
- tmp = tmp->next;
- MyFree(obtmp->value.ban.banstr);
- MyFree(obtmp->value.ban.who);
- free_link(obtmp);
+ next = ban->next;
+ free_ban(ban);
}
if (chptr->prev)
chptr->prev->next = chptr->next;
return 0;
}
-/*
- * add_banid
- *
- * `cptr' must be the client adding the ban.
- *
- * If `change' is true then add `banid' to channel `chptr'.
- * Returns 0 if the ban was added.
- * Returns -2 if the ban already existed and was marked CHFL_BURST_BAN_WIPEOUT.
- * Return -1 otherwise.
- *
- * Those bans that overlapped with `banid' are flagged with CHFL_BAN_OVERLAPPED
- * when `change' is false, otherwise they will be removed from the banlist.
- * Subsequently calls to next_overlapped_ban() or next_removed_overlapped_ban()
- * respectively will return these bans until NULL is returned.
+/** returns Membership * if a person is joined and not a zombie
+ * @param cptr Client
+ * @param chptr Channel
+ * @returns pointer to the client's struct Membership * on the channel if that
+ * user is a full member of the channel, or NULL otherwise.
*
- * If `firsttime' is true, the ban list as returned by next_overlapped_ban()
- * is reset (unless a non-zero value is returned, in which case the
- * CHFL_BAN_OVERLAPPED flag might not have been reset!).
- *
- * --Run
+ * @see find_member_link()
*/
-int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
- int change, int firsttime)
+struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr)
{
- struct SLink* ban;
- struct SLink** banp;
- int cnt = 0;
- int removed_bans = 0;
- int len = strlen(banid);
-
- if (firsttime)
- {
- next_ban = NULL;
- assert(0 == prev_ban);
- assert(0 == removed_bans_list);
- }
- if (MyUser(cptr))
- collapse(banid);
- for (banp = &chptr->banlist; *banp;)
- {
- len += strlen((*banp)->value.ban.banstr);
- ++cnt;
- if (((*banp)->flags & CHFL_BURST_BAN_WIPEOUT))
- {
- if (!strcmp((*banp)->value.ban.banstr, banid))
- {
- (*banp)->flags &= ~CHFL_BURST_BAN_WIPEOUT;
- return -2;
- }
- }
- else if (!mmatch((*banp)->value.ban.banstr, banid))
- return -1;
- if (!mmatch(banid, (*banp)->value.ban.banstr))
- {
- struct SLink *tmp = *banp;
- if (change)
- {
- if (MyUser(cptr))
- {
- cnt--;
- len -= strlen(tmp->value.ban.banstr);
- }
- *banp = tmp->next;
-#if 0
- /* Silently remove overlapping bans */
- MyFree(tmp->value.ban.banstr);
- MyFree(tmp->value.ban.who);
- free_link(tmp);
- tmp = 0;
-#else
- /* These will be sent to the user later as -b */
- tmp->next = removed_bans_list;
- removed_bans_list = tmp;
- removed_bans = 1;
-#endif
- }
- else if (!(tmp->flags & CHFL_BURST_BAN_WIPEOUT))
- {
- tmp->flags |= CHFL_BAN_OVERLAPPED;
- if (!next_ban)
- next_ban = tmp;
- banp = &tmp->next;
- }
- else
- banp = &tmp->next;
- }
- else
- {
- if (firsttime)
- (*banp)->flags &= ~CHFL_BAN_OVERLAPPED;
- banp = &(*banp)->next;
- }
- }
- if (MyUser(cptr) && !removed_bans && (len > MAXBANLENGTH || (cnt >= MAXBANS)))
- {
- send_reply(cptr, ERR_BANLISTFULL, chptr->chname, banid);
- return -1;
- }
- if (change)
- {
- char* ip_start;
- struct Membership* member;
- ban = make_link();
- ban->next = chptr->banlist;
-
- ban->value.ban.banstr = (char*) MyMalloc(strlen(banid) + 1);
- assert(0 != ban->value.ban.banstr);
- strcpy(ban->value.ban.banstr, banid);
-
- ban->value.ban.who = (char*) MyMalloc(strlen(cptr->name) + 1);
- assert(0 != ban->value.ban.who);
- strcpy(ban->value.ban.who, cptr->name);
-
- ban->value.ban.when = TStime();
- ban->flags = CHFL_BAN; /* This bit is never used I think... */
- if ((ip_start = strrchr(banid, '@')) && check_if_ipmask(ip_start + 1))
- ban->flags |= CHFL_BAN_IPMASK;
- chptr->banlist = ban;
+ struct Membership* member;
+ assert(0 != chptr);
- /*
- * Erase ban-valid-bit
- */
- for (member = chptr->members; member; member = member->next_member)
- ClearBanValid(member); /* `ban' == channel member ! */
- }
- return 0;
+ member = find_member_link(chptr, cptr);
+ return (member && !IsZombie(member)) ? member : 0;
}
-static struct SLink *next_overlapped_ban(void)
-{
- struct SLink *tmp = next_ban;
- if (tmp)
+/** Searches for a ban from a ban list that matches a user.
+ * @param[in] cptr The client to test.
+ * @param[in] banlist The list of bans to test.
+ * @return Pointer to a matching ban, or NULL if none exit.
+ */
+struct Ban *find_ban(struct Client *cptr, struct Ban *banlist)
+{
+ char nu[NICKLEN + USERLEN + 2];
+ char tmphost[HOSTLEN + 1];
+ char *sr;
+ struct Ban *found;
+
+ /* Build nick!user and alternate host names. */
+ ircd_snprintf(0, nu, sizeof(nu), "%s!%s",
+ cli_name(cptr), cli_user(cptr)->username);
+ if (!IsAccount(cptr))
+ sr = NULL;
+ else if (HasHiddenHost(cptr))
+ sr = cli_user(cptr)->realhost;
+ else
{
- struct SLink *ban;
- for (ban = tmp->next; ban; ban = ban->next)
- if ((ban->flags & CHFL_BAN_OVERLAPPED))
- break;
- next_ban = ban;
+ ircd_snprintf(0, tmphost, HOSTLEN, "%s.%s",
+ cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
+ sr = tmphost;
}
- return tmp;
-}
-struct SLink *next_removed_overlapped_ban(void)
-{
- struct SLink *tmp = removed_bans_list;
- if (prev_ban)
- {
- if (prev_ban->value.ban.banstr) /* Can be set to NULL in set_mode() */
- MyFree(prev_ban->value.ban.banstr);
- MyFree(prev_ban->value.ban.who);
- free_link(prev_ban);
- prev_ban = 0;
+ /* Walk through ban list. */
+ for (found = NULL; banlist; banlist = banlist->next) {
+ int res;
+ /* If we have found a positive ban already, only consider exceptions. */
+ if (found && !(banlist->flags & BAN_EXCEPTION))
+ continue;
+ /* Compare nick!user portion of ban. */
+ banlist->banstr[banlist->nu_len] = '\0';
+ res = match(banlist->banstr, nu);
+ banlist->banstr[banlist->nu_len] = '@';
+ if (res)
+ continue;
+ /* Compare host portion of ban. */
+ if (!((banlist->flags & BAN_IPMASK)
+ && ipmask_check(&cli_ip(cptr), &banlist->address, banlist->addrbits))
+ && match(banlist->banstr + banlist->nu_len + 1, cli_user(cptr)->host)
+ && !(sr && match(banlist->banstr + banlist->nu_len + 1, sr) == 0))
+ continue;
+ /* If an exception matches, no ban can match. */
+ if (banlist->flags & BAN_EXCEPTION)
+ return NULL;
+ /* Otherwise, remember this ban but keep searching for an exception. */
+ found = banlist;
}
- if (tmp)
- removed_bans_list = removed_bans_list->next;
- prev_ban = tmp;
- return tmp;
+ return found;
}
-/*
- * del_banid
+/**
+ * This function returns true if the user is banned on the said channel.
+ * This function will check the ban cache if applicable, otherwise will
+ * do the comparisons and cache the result.
*
- * If `change' is true, delete `banid' from channel `chptr'.
- * Returns `false' if removal was (or would have been) successful.
- */
-static int del_banid(struct Channel *chptr, char *banid, int change)
-{
- struct SLink **ban;
- struct SLink *tmp;
-
- if (!banid)
- return -1;
- for (ban = &(chptr->banlist); *ban; ban = &((*ban)->next)) {
- if (0 == ircd_strcmp(banid, (*ban)->value.ban.banstr))
- {
- tmp = *ban;
- if (change)
- {
- struct Membership* member;
- *ban = tmp->next;
- MyFree(tmp->value.ban.banstr);
- MyFree(tmp->value.ban.who);
- free_link(tmp);
- /*
- * Erase ban-valid-bit, for channel members that are banned
- */
- for (member = chptr->members; member; member = member->next_member)
- if (CHFL_BANVALIDMASK == (member->status & CHFL_BANVALIDMASK))
- ClearBanValid(member); /* `tmp' == channel member */
- }
- return 0;
- }
- }
- return -1;
-}
-
-/*
- * find_channel_member - returns Membership * if a person is joined and not a zombie
- */
-struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr)
-{
- struct Membership* member;
- assert(0 != chptr);
-
- member = find_member_link(chptr, cptr);
- return (member && !IsZombie(member)) ? member : 0;
-}
-
-/*
- * is_banned - a non-zero value if banned else 0.
+ * @param[in] member The Membership to test for banned-ness.
+ * @return Non-zero if the member is banned, zero if not.
*/
-static int is_banned(struct Client *cptr, struct Channel *chptr,
- struct Membership* member)
+static int is_banned(struct Membership* member)
{
- struct SLink* tmp;
- char* s;
- char* ip_s = NULL;
-
- if (!IsUser(cptr))
- return 0;
-
- if (member && IsBanValid(member))
+ if (IsBanValid(member))
return IsBanned(member);
- s = make_nick_user_host(cptr->name, cptr->user->username, cptr->user->host);
-
- for (tmp = chptr->banlist; tmp; tmp = tmp->next) {
- if ((tmp->flags & CHFL_BAN_IPMASK)) {
- if (!ip_s)
- ip_s = make_nick_user_ip(cptr->name, cptr->user->username, cptr->ip);
- if (match(tmp->value.ban.banstr, ip_s) == 0)
- break;
- }
- else if (match(tmp->value.ban.banstr, s) == 0)
- break;
- }
-
- if (member) {
- SetBanValid(member);
- if (tmp) {
- SetBanned(member);
- return 1;
- }
- else {
- ClearBanned(member);
- return 0;
- }
+ SetBanValid(member);
+ if (find_ban(member->user, member->channel->banlist)) {
+ SetBanned(member);
+ return 1;
+ } else {
+ ClearBanned(member);
+ return 0;
}
-
- return (tmp != NULL);
}
-/*
+/** add a user to a channel.
* adds a user to a channel by adding another link to the channels member
* chain.
+ *
+ * @param chptr The channel to add to.
+ * @param who The user to add.
+ * @param flags The flags the user gets initially.
+ * @param oplevel The oplevel the user starts with.
*/
void add_user_to_channel(struct Channel* chptr, struct Client* who,
- unsigned int flags)
+ unsigned int flags, int oplevel)
{
assert(0 != chptr);
assert(0 != who);
- if (who->user) {
+ if (cli_user(who)) {
struct Membership* member = membershipFreeList;
if (member)
member->user = who;
member->channel = chptr;
member->status = flags;
+ member->oplevel = oplevel;
member->next_member = chptr->members;
if (member->next_member)
member->prev_member = 0;
chptr->members = member;
- member->next_channel = who->user->channel;
+ member->next_channel = (cli_user(who))->channel;
if (member->next_channel)
member->next_channel->prev_channel = member;
member->prev_channel = 0;
- who->user->channel = member;
+ (cli_user(who))->channel = member;
+ if (chptr->destruct_event)
+ remove_destruct_event(chptr);
++chptr->users;
- ++who->user->joined;
+ ++((cli_user(who))->joined);
}
}
+/** Remove a person from a channel, given their Membership*
+ *
+ * @param member A member of a channel.
+ *
+ * @returns true if there are more people in the channel.
+ */
static int remove_member_from_channel(struct Membership* member)
{
struct Channel* chptr;
member->prev_member->next_member = member->next_member;
else
member->channel->members = member->next_member;
-
+
+ /*
+ * If this is the last delayed-join user, may have to clear WASDELJOINS.
+ */
+ if (IsDelayedJoin(member))
+ CheckDelayedJoins(chptr);
+
/*
* unlink client channel list
*/
if (member->prev_channel)
member->prev_channel->next_channel = member->next_channel;
else
- member->user->user->channel = member->next_channel;
+ (cli_user(member->user))->channel = member->next_channel;
- --member->user->user->joined;
+ --(cli_user(member->user))->joined;
member->next_member = membershipFreeList;
membershipFreeList = member;
return sub1_from_channel(chptr);
}
+/** Check if all the remaining members on the channel are zombies
+ *
+ * @returns False if the channel has any non zombie members, True otherwise.
+ * @see \ref zombie
+ */
static int channel_all_zombies(struct Channel* chptr)
{
struct Membership* member;
}
+/** Remove a user from a channel
+ * This is the generic entry point for removing a user from a channel, this
+ * function will remove the client from the channel, and destroy the channel
+ * if there are no more normal users left.
+ *
+ * @param cptr The client
+ * @param chptr The channel
+ */
void remove_user_from_channel(struct Client* cptr, struct Channel* chptr)
{
}
}
+/** Remove a user from all channels they are on.
+ *
+ * This function removes a user from all channels they are on.
+ *
+ * @param cptr The client to remove.
+ */
void remove_user_from_all_channels(struct Client* cptr)
{
struct Membership* chan;
assert(0 != cptr);
- assert(0 != cptr->user);
+ assert(0 != cli_user(cptr));
- while ((chan = cptr->user->channel))
+ while ((chan = (cli_user(cptr))->channel))
remove_user_from_channel(cptr, chan->channel);
}
+/** Check if this user is a legitimate chanop
+ *
+ * @param cptr Client to check
+ * @param chptr Channel to check
+ *
+ * @returns True if the user is a chanop (And not a zombie), False otherwise.
+ * @see \ref zombie
+ */
int is_chan_op(struct Client *cptr, struct Channel *chptr)
{
struct Membership* member;
return 0;
}
-static int is_deopped(struct Client *cptr, struct Channel *chptr)
-{
- struct Membership* member;
-
- assert(0 != chptr);
- if ((member = find_member_link(chptr, cptr)))
- return IsDeopped(member);
-
- return (IsUser(cptr) ? 1 : 0);
-}
-
+/** Check if a user is a Zombie on a specific channel.
+ *
+ * @param cptr The client to check.
+ * @param chptr The channel to check.
+ *
+ * @returns True if the client (cptr) is a zombie on the channel (chptr),
+ * False otherwise.
+ *
+ * @see \ref zombie
+ */
int is_zombie(struct Client *cptr, struct Channel *chptr)
{
struct Membership* member;
return 0;
}
+/** Returns if a user has voice on a channel.
+ *
+ * @param cptr The client
+ * @param chptr The channel
+ *
+ * @returns True if the client (cptr) is voiced on (chptr) and is not a zombie.
+ * @see \ref zombie
+ */
int has_voice(struct Client* cptr, struct Channel* chptr)
{
struct Membership* member;
return 0;
}
-int member_can_send_to_channel(struct Membership* member)
+/** Can this member send to a channel
+ *
+ * A user can speak on a channel iff:
+ * <ol>
+ * <li> They didn't use the Apass to gain ops.
+ * <li> They are op'd or voice'd.
+ * <li> You aren't banned.
+ * <li> The channel isn't +m
+ * <li> The channel isn't +n or you are on the channel.
+ * </ol>
+ *
+ * This function will optionally reveal a user on a delayed join channel if
+ * they are allowed to send to the channel.
+ *
+ * @param member The membership of the user
+ * @param reveal If true, the user will be "revealed" on a delayed
+ * joined channel.
+ *
+ * @returns True if the client can speak on the channel.
+ */
+int member_can_send_to_channel(struct Membership* member, int reveal)
{
assert(0 != member);
+ /* Discourage using the Apass to get op. They should use the upass. */
+ if (IsChannelManager(member) && *member->channel->mode.upass)
+ return 0;
+
if (IsVoicedOrOpped(member))
return 1;
/*
- * If it's moderated, and you aren't a priviledged user, you can't
+ * If it's moderated, and you aren't a privileged user, you can't
* speak.
*/
if (member->channel->mode.mode & MODE_MODERATED)
return 0;
+ /* If only logged in users may join and you're not one, you can't speak. */
+ if (member->channel->mode.mode & MODE_REGONLY && !IsAccount(member->user))
+ return 0;
/*
* If you're banned then you can't speak either.
* but because of the amount of CPU time that is_banned chews
* we only check it for our clients.
*/
- if (MyUser(member->user) && is_banned(member->user, member->channel, member))
+ if (MyUser(member->user) && is_banned(member))
return 0;
+
+ if (IsDelayedJoin(member) && reveal)
+ RevealDelayedJoin(member);
+
return 1;
}
-int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr)
+/** Check if a client can send to a channel.
+ *
+ * Has the added check over member_can_send_to_channel() of servers can
+ * always speak.
+ *
+ * @param cptr The client to check
+ * @param chptr The channel to check
+ * @param reveal If the user should be revealed (see
+ * member_can_send_to_channel())
+ *
+ * @returns true if the client is allowed to speak on the channel, false
+ * otherwise
+ *
+ * @see member_can_send_to_channel()
+ */
+int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal)
{
struct Membership *member;
assert(0 != cptr);
member = find_channel_member(cptr, chptr);
/*
- * You can't speak if your off channel, if the channel is modeless, or
- * +n.(no external messages)
+ * You can't speak if you're off channel, and it is +n (no external messages)
+ * or +m (moderated).
*/
if (!member) {
- if ((chptr->mode.mode & MODE_NOPRIVMSGS) || IsModelessChannel(chptr->chname))
+ if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED)) ||
+ ((chptr->mode.mode & MODE_REGONLY) && !IsAccount(cptr)))
return 0;
else
- return 1;
+ return !find_ban(cptr, chptr->banlist);
}
- return member_can_send_to_channel(member);
+ return member_can_send_to_channel(member, reveal);
}
-/*
- * find_no_nickchange_channel
- * if a member and not opped or voiced and banned
- * return the name of the first channel banned on
+/** Returns the name of a channel that prevents the user from changing nick.
+ * if a member and not (opped or voiced) and (banned or moderated), return
+ * the name of the first channel banned on.
+ *
+ * @param cptr The client
+ *
+ * @returns the name of the first channel banned on, or NULL if the user
+ * can change nicks.
*/
const char* find_no_nickchange_channel(struct Client* cptr)
{
if (MyUser(cptr)) {
struct Membership* member;
- for (member = cptr->user->channel; member; member = member->next_channel) {
- if (!IsVoicedOrOpped(member) && is_banned(cptr, member->channel, member))
+ for (member = (cli_user(cptr))->channel; member;
+ member = member->next_channel) {
+ if (!IsVoicedOrOpped(member) &&
+ (is_banned(member) ||
+ (member->channel->mode.mode & MODE_MODERATED)))
return member->channel->chname;
}
}
}
-/*
+/** Fill mbuf/pbuf with modes from chptr
* write the "simple" list of channel modes for channel chptr onto buffer mbuf
- * with the parameters in pbuf.
+ * with the parameters in pbuf as visible by cptr.
+ *
+ * This function will hide keys from non-op'd, non-server clients.
+ *
+ * @param cptr The client to generate the mode for.
+ * @param mbuf The buffer to write the modes into.
+ * @param pbuf The buffer to write the mode parameters into.
+ * @param buflen The length of the buffers.
+ * @param chptr The channel to get the modes from.
+ * @param member The membership of this client on this channel (or NULL
+ * if this client isn't on this channel)
+ *
*/
-void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
- struct Channel *chptr)
+void channel_modes(struct Client *cptr, char *mbuf, char *pbuf, int buflen,
+ struct Channel *chptr, struct Membership *member)
{
+ int previous_parameter = 0;
+
assert(0 != mbuf);
assert(0 != pbuf);
assert(0 != chptr);
*mbuf++ = 'i';
if (chptr->mode.mode & MODE_NOPRIVMSGS)
*mbuf++ = 'n';
+ if (chptr->mode.mode & MODE_REGONLY)
+ *mbuf++ = 'r';
+ if (chptr->mode.mode & MODE_DELJOINS)
+ *mbuf++ = 'D';
+ else if (MyUser(cptr) && (chptr->mode.mode & MODE_WASDELJOINS))
+ *mbuf++ = 'd';
if (chptr->mode.limit) {
*mbuf++ = 'l';
- sprintf_irc(pbuf, "%d", chptr->mode.limit);
+ ircd_snprintf(0, pbuf, buflen, "%u", chptr->mode.limit);
+ previous_parameter = 1;
}
if (*chptr->mode.key) {
*mbuf++ = 'k';
+ if (previous_parameter)
+ strcat(pbuf, " ");
if (is_chan_op(cptr, chptr) || IsServer(cptr)) {
- if (chptr->mode.limit)
- strcat(pbuf, " ");
strcat(pbuf, chptr->mode.key);
- }
+ } else
+ strcat(pbuf, "*");
+ previous_parameter = 1;
+ }
+ if (*chptr->mode.apass) {
+ *mbuf++ = 'A';
+ if (previous_parameter)
+ strcat(pbuf, " ");
+ if (IsServer(cptr)) {
+ strcat(pbuf, chptr->mode.apass);
+ } else
+ strcat(pbuf, "*");
+ previous_parameter = 1;
+ }
+ if (*chptr->mode.upass) {
+ *mbuf++ = 'U';
+ if (previous_parameter)
+ strcat(pbuf, " ");
+ if (IsServer(cptr) || (member && IsChanOp(member) && OpLevel(member) == 0)) {
+ strcat(pbuf, chptr->mode.upass);
+ } else
+ strcat(pbuf, "*");
}
*mbuf = '\0';
}
-#if 0
-static int send_mode_list(struct Client *cptr, char *chname,
- time_t creationtime, struct SLink *top,
- int mask, char flag)
+/** Compare two members oplevel
+ *
+ * @param mp1 Pointer to a pointer to a membership
+ * @param mp2 Pointer to a pointer to a membership
+ *
+ * @returns 0 if equal, -1 if mp1 is lower, +1 otherwise.
+ *
+ * Used for qsort(3).
+ */
+int compare_member_oplevel(const void *mp1, const void *mp2)
{
- struct SLink* lp;
- char* cp;
- char* name;
- int count = 0;
- int send = 0;
- int sent = 0;
+ struct Membership const* member1 = *(struct Membership const**)mp1;
+ struct Membership const* member2 = *(struct Membership const**)mp2;
+ if (member1->oplevel == member2->oplevel)
+ return 0;
+ return (member1->oplevel < member2->oplevel) ? -1 : 1;
+}
- cp = modebuf + strlen(modebuf);
- if (*parabuf) /* mode +l or +k xx */
- count = 1;
- for (lp = top; lp; lp = lp->next)
- {
- if (!(lp->flags & mask))
- continue;
- if (mask == CHFL_BAN)
- name = lp->value.ban.banstr;
- else
- name = lp->value.cptr->name;
- if (strlen(parabuf) + strlen(name) + 11 < MODEBUFLEN)
- {
- strcat(parabuf, " ");
- strcat(parabuf, name);
- count++;
- *cp++ = flag;
- *cp = '\0';
- }
- else if (*parabuf)
- send = 1;
- if (count == 6)
- send = 1;
- if (send)
- {
- /* cptr is always a server! So we send creationtimes */
- sendmodeto_one(cptr, me.name, chname, modebuf, parabuf, creationtime);
- sent = 1;
- send = 0;
- *parabuf = '\0';
- cp = modebuf;
- *cp++ = '+';
- if (count != 6)
- {
- strcpy(parabuf, name);
- *cp++ = flag;
- }
- count = 0;
- *cp = '\0';
- }
- }
- return sent;
-}
-
-#endif /* 0 */
-
-/*
- * send "cptr" a full list of the modes for channel chptr.
+/* send "cptr" a full list of the modes for channel chptr.
+ *
+ * Sends a BURST line to cptr, bursting all the modes for the channel.
+ *
+ * @param cptr Client pointer
+ * @param chptr Channel pointer
*/
void send_channel_modes(struct Client *cptr, struct Channel *chptr)
{
+ /* The order in which modes are generated is now mandatory */
static unsigned int current_flags[4] =
- { 0, CHFL_CHANOP | CHFL_VOICE, CHFL_VOICE, CHFL_CHANOP };
+ { 0, CHFL_VOICE, CHFL_CHANOP, CHFL_CHANOP | CHFL_VOICE };
int first = 1;
int full = 1;
int flag_cnt = 0;
int new_mode = 0;
size_t len;
- size_t sblen;
struct Membership* member;
- struct SLink* lp2;
+ struct Ban* lp2;
char modebuf[MODEBUFLEN];
char parabuf[MODEBUFLEN];
- char sndbuf[IRC_BUFSIZE];
+ struct MsgBuf *mb;
+ int number_of_ops = 0;
+ int opped_members_index = 0;
+ struct Membership** opped_members = NULL;
+ int last_oplevel = 0;
+ int feat_oplevels = (chptr->mode.apass[0]) != '\0';
assert(0 != cptr);
assert(0 != chptr);
lp2 = chptr->banlist;
*modebuf = *parabuf = '\0';
- channel_modes(cptr, modebuf, parabuf, chptr);
+ channel_modes(cptr, modebuf, parabuf, sizeof(parabuf), chptr, 0);
for (first = 1; full; first = 0) /* Loop for multiple messages */
{
/* (Continued) prefix: "<Y> B <channel> <TS>" */
/* is there any better way we can do this? */
- sblen = ircd_snprintf(&me, sndbuf, sizeof(sndbuf), "%C " TOK_BURST
- " %H %Tu", &me, chptr, chptr->creationtime);
+ mb = msgq_make(&me, "%C " TOK_BURST " %H %Tu", &me, chptr,
+ chptr->creationtime);
- if (first && modebuf[1]) /* Add simple modes (iklmnpst)
+ if (first && modebuf[1]) /* Add simple modes (Aiklmnpstu)
if first message */
{
/* prefix: "<Y> B <channel> <TS>[ <modes>[ <params>]]" */
- sndbuf[sblen++] = ' ';
- strcpy(sndbuf + sblen, modebuf);
- sblen += strlen(modebuf);
+ msgq_append(&me, mb, " %s", modebuf);
+
if (*parabuf)
- {
- sndbuf[sblen++] = ' ';
- strcpy(sndbuf + sblen, parabuf);
- sblen += strlen(parabuf);
- }
+ msgq_append(&me, mb, " %s", parabuf);
}
/*
- * Attach nicks, comma seperated " nick[:modes],nick[:modes],..."
+ * Attach nicks, comma separated " nick[:modes],nick[:modes],..."
*
- * Run 4 times over all members, to group the members with the
- * same mode together
+ * First find all opless members.
+ * Run 2 times over all members, to group the members with
+ * and without voice together.
+ * Then run 2 times over all opped members (which are ordered
+ * by op-level) to also group voice and non-voice together.
*/
- for (first = 1; flag_cnt < 4;
- member = chptr->members, new_mode = 1, flag_cnt++)
+ for (first = 1; flag_cnt < 4; new_mode = 1, ++flag_cnt)
{
- for (; member; member = member->next_member)
+ while (member)
{
- if ((member->status & CHFL_VOICED_OR_OPPED) !=
- current_flags[flag_cnt])
- continue; /* Skip members with different flags */
- if (sblen + NUMNICKLEN + 4 > BUFSIZE - 3)
- /* The 4 is a possible ",:ov"
- The -3 is for the "\r\n\0" that is added in send.c */
- {
- full = 1; /* Make sure we continue after
- sending it so far */
- new_mode = 1; /* Ensure the new BURST line contains the current
- mode. --Gte */
- break; /* Do not add this member to this message */
- }
- sndbuf[sblen++] = first ? ' ' : ',';
- first = 0; /* From now on, us comma's to add new nicks */
-
- sblen += ircd_snprintf(&me, sndbuf + sblen, sizeof(sndbuf) - sblen,
- "%C", member->user);
- /*
- * Do we have a nick with a new mode ?
- * Or are we starting a new BURST line?
- */
- if (new_mode)
- {
- new_mode = 0;
- if (IsVoicedOrOpped(member)) {
- sndbuf[sblen++] = ':';
- if (IsChanOp(member))
- sndbuf[sblen++] = 'o';
- if (HasVoice(member))
- sndbuf[sblen++] = 'v';
- }
- }
+ if (flag_cnt < 2 && IsChanOp(member))
+ {
+ /*
+ * The first loop (to find all non-voice/op), we count the ops.
+ * The second loop (to find all voiced non-ops), store the ops
+ * in a dynamic array.
+ */
+ if (flag_cnt == 0)
+ ++number_of_ops;
+ else
+ opped_members[opped_members_index++] = member;
+ }
+ /* Only handle the members with the flags that we are interested in. */
+ if ((member->status & CHFL_VOICED_OR_OPPED) == current_flags[flag_cnt])
+ {
+ if (msgq_bufleft(mb) < NUMNICKLEN + 3 + MAXOPLEVELDIGITS)
+ /* The 3 + MAXOPLEVELDIGITS is a possible ",:v999". */
+ {
+ full = 1; /* Make sure we continue after
+ sending it so far */
+ /* Ensure the new BURST line contains the current
+ * ":mode", except when there is no mode yet. */
+ new_mode = (flag_cnt > 0) ? 1 : 0;
+ break; /* Do not add this member to this message */
+ }
+ msgq_append(&me, mb, "%c%C", first ? ' ' : ',', member->user);
+ first = 0; /* From now on, use commas to add new nicks */
+
+ /*
+ * Do we have a nick with a new mode ?
+ * Or are we starting a new BURST line?
+ */
+ if (new_mode)
+ {
+ /*
+ * This means we are at the _first_ member that has only
+ * voice, or the first member that has only ops, or the
+ * first member that has voice and ops (so we get here
+ * at most three times, plus once for every start of
+ * a continued BURST line where only these modes is current.
+ * In the two cases where the current mode includes ops,
+ * we need to add the _absolute_ value of the oplevel to the mode.
+ */
+ char tbuf[3 + MAXOPLEVELDIGITS] = ":";
+ int loc = 1;
+
+ if (HasVoice(member)) /* flag_cnt == 1 or 3 */
+ tbuf[loc++] = 'v';
+ if (IsChanOp(member)) /* flag_cnt == 2 or 3 */
+ {
+ /* append the absolute value of the oplevel */
+ if (feat_oplevels)
+ loc += ircd_snprintf(0, tbuf + loc, sizeof(tbuf) - loc, "%u", last_oplevel = member->oplevel);
+ else
+ tbuf[loc++] = 'o';
+ }
+ tbuf[loc] = '\0';
+ msgq_append(&me, mb, tbuf);
+ new_mode = 0;
+ }
+ else if (feat_oplevels && flag_cnt > 1 && last_oplevel != member->oplevel)
+ {
+ /*
+ * This can't be the first member of a (continued) BURST
+ * message because then either flag_cnt == 0 or new_mode == 1
+ * Now we need to append the incremental value of the oplevel.
+ */
+ char tbuf[2 + MAXOPLEVELDIGITS];
+ ircd_snprintf(0, tbuf, sizeof(tbuf), ":%u", member->oplevel - last_oplevel);
+ last_oplevel = member->oplevel;
+ msgq_append(&me, mb, tbuf);
+ }
+ }
+ /* Go to the next `member'. */
+ if (flag_cnt < 2)
+ member = member->next_member;
+ else
+ member = opped_members[++opped_members_index];
}
if (full)
- break;
- }
+ break;
+
+ /* Point `member' at the start of the list again. */
+ if (flag_cnt == 0)
+ {
+ member = chptr->members;
+ /* Now, after one loop, we know the number of ops and can
+ * allocate the dynamic array with pointer to the ops. */
+ opped_members = (struct Membership**)
+ MyMalloc((number_of_ops + 1) * sizeof(struct Membership*));
+ opped_members[number_of_ops] = NULL; /* Needed for loop termination */
+ }
+ else
+ {
+ /* At the end of the second loop, sort the opped members with
+ * increasing op-level, so that we will output them in the
+ * correct order (and all op-level increments stay positive) */
+ if (flag_cnt == 1)
+ qsort(opped_members, number_of_ops,
+ sizeof(struct Membership*), compare_member_oplevel);
+ /* The third and fourth loop run only over the opped members. */
+ member = opped_members[(opped_members_index = 0)];
+ }
+
+ } /* loop over 0,+v,+o,+ov */
if (!full)
{
- /* Attach all bans, space seperated " :%ban ban ..." */
+ /* Attach all bans, space separated " :%ban ban ..." */
for (first = 2; lp2; lp2 = lp2->next)
{
- len = strlen(lp2->value.ban.banstr);
- if (sblen + len + 1 + first > BUFSIZE - 3)
+ len = strlen(lp2->banstr);
+ if (msgq_bufleft(mb) < len + 1 + first)
/* The +1 stands for the added ' '.
* The +first stands for the added ":%".
- * The -3 is for the "\r\n\0" that is added in send.c
*/
{
full = 1;
break;
}
- if (first)
- {
- first = 0;
- sndbuf[sblen++] = ' ';
- sndbuf[sblen++] = ':'; /* Will be last parameter */
- sndbuf[sblen++] = '%'; /* To tell bans apart */
- }
- else
- sndbuf[sblen++] = ' ';
- strcpy(sndbuf + sblen, lp2->value.ban.banstr);
- sblen += len;
+ msgq_append(&me, mb, " %s%s", first ? ":%" : "",
+ lp2->banstr);
+ first = 0;
}
}
- sndbuf[sblen] = '\0';
- send_buffer(cptr, sndbuf); /* Send this message */
+ send_buffer(cptr, mb, 0); /* Send this message */
+ msgq_clean(mb);
} /* Continue when there was something
that didn't fit (full==1) */
+ if (opped_members)
+ MyFree(opped_members);
+ if (feature_bool(FEAT_TOPIC_BURST) && (chptr->topic[0] != '\0'))
+ sendcmdto_one(&me, CMD_TOPIC, cptr, "%H %Tu %Tu :%s", chptr,
+ chptr->creationtime, chptr->topic_time, chptr->topic);
}
-/*
+/** Canonify a mask.
* pretty_mask
*
- * by Carlo Wood (Run), 05 Oct 1998.
- *
- * Canonify a mask.
+ * @author Carlo Wood (Run),
+ * 05 Oct 1998.
*
* When the nick is longer then NICKLEN, it is cut off (its an error of course).
* When the user name or host name are too long (USERLEN and HOSTLEN
* The following transformations are made:
*
* 1) xxx -> nick!*@*
- * 2) xxx.xxx -> *!*@host
- * 3) xxx!yyy -> nick!user@*
- * 4) xxx@yyy -> *!user@host
- * 5) xxx!yyy@zzz -> nick!user@host
+ * 2) xxx.xxx -> *!*\@host
+ * 3) xxx\!yyy -> nick!user\@*
+ * 4) xxx\@yyy -> *!user\@host
+ * 5) xxx!yyy\@zzz -> nick!user\@host
+ *
+ * @param mask The uncanonified mask.
+ * @returns The updated mask in a static buffer.
*/
char *pretty_mask(char *mask)
-{
- static char star[2] = { '*', 0 };
- char *last_dot = NULL;
- char *ptr;
-
- /* Case 1: default */
- char *nick = mask;
- char *user = star;
- char *host = star;
-
- /* Do a _single_ pass through the characters of the mask: */
- for (ptr = mask; *ptr; ++ptr)
- {
- if (*ptr == '!')
- {
- /* Case 3 or 5: Found first '!' (without finding a '@' yet) */
- user = ++ptr;
- host = star;
- }
- else if (*ptr == '@')
- {
- /* Case 4: Found last '@' (without finding a '!' yet) */
- nick = star;
- user = mask;
- host = ++ptr;
- }
- else if (*ptr == '.')
- {
- /* Case 2: Found last '.' (without finding a '!' or '@' yet) */
- last_dot = ptr;
- continue;
- }
- else
- continue;
- for (; *ptr; ++ptr)
- {
- if (*ptr == '@')
- {
- /* Case 4 or 5: Found last '@' */
- host = ptr + 1;
- }
- }
- break;
- }
- if (user == star && last_dot)
- {
- /* Case 2: */
- nick = star;
- user = star;
- host = mask;
- }
- /* Check lengths */
- if (nick != star)
- {
- char *nick_end = (user != star) ? user - 1 : ptr;
- if (nick_end - nick > NICKLEN)
- nick[NICKLEN] = 0;
- *nick_end = 0;
- }
- if (user != star)
- {
- char *user_end = (host != star) ? host - 1 : ptr;
- if (user_end - user > USERLEN)
- {
- user = user_end - USERLEN;
- *user = '*';
- }
- *user_end = 0;
- }
- if (host != star && ptr - host > HOSTLEN)
- {
- host = ptr - HOSTLEN;
- *host = '*';
- }
- return make_nick_user_host(nick, user, host);
-}
-
-static void send_ban_list(struct Client* cptr, struct Channel* chptr)
-{
- struct SLink* lp;
-
- assert(0 != cptr);
- assert(0 != chptr);
-
- for (lp = chptr->banlist; lp; lp = lp->next)
- send_reply(cptr, RPL_BANLIST, chptr->chname, lp->value.ban.banstr,
- lp->value.ban.who, lp->value.ban.when);
-
- send_reply(cptr, RPL_ENDOFBANLIST, chptr->chname);
-}
-
-/*
- * Check and try to apply the channel modes passed in the parv array for
- * the client ccptr to channel chptr. The resultant changes are printed
- * into mbuf and pbuf (if any) and applied to the channel.
- */
-int set_mode(struct Client* cptr, struct Client* sptr,
- struct Channel* chptr, int parc, char* parv[],
- char* mbuf, char* pbuf, char* npbuf, int* badop)
-{
- /*
- * This size is only needed when a broken
- * server sends more then MAXMODEPARAMS
- * parameters
- */
- static struct SLink chops[MAXPARA - 2];
- static int flags[] = {
- MODE_PRIVATE, 'p',
- MODE_SECRET, 's',
- MODE_MODERATED, 'm',
- MODE_NOPRIVMSGS, 'n',
- MODE_TOPICLIMIT, 't',
- MODE_INVITEONLY, 'i',
- MODE_VOICE, 'v',
- MODE_KEY, 'k',
- 0x0, 0x0
- };
-
- char bmodebuf[MODEBUFLEN];
- char bparambuf[MODEBUFLEN];
- char nbparambuf[MODEBUFLEN]; /* "Numeric" Bounce Parameter Buffer */
- struct SLink* lp;
- char* curr = parv[0];
- char* cp = NULL;
- int* ip;
- struct Membership* member_x;
- struct Membership* member_y;
- unsigned int whatt = MODE_ADD;
- unsigned int bwhatt = 0;
- int limitset = 0;
- int bounce;
- int add_banid_called = 0;
- size_t len;
- size_t nlen;
- size_t blen;
- size_t nblen;
- int keychange = 0;
- unsigned int nusers = 0;
- unsigned int newmode;
- int opcnt = 0;
- int banlsent = 0;
- int doesdeop = 0;
- int doesop = 0;
- int hacknotice = 0;
- int change;
- int gotts = 0;
- struct Client* who;
- struct Mode* mode;
- struct Mode oldm;
- static char numeric[16];
- char* bmbuf = bmodebuf;
- char* bpbuf = bparambuf;
- char* nbpbuf = nbparambuf;
- time_t newtime = 0;
- struct ConfItem* aconf;
-
- *mbuf = *pbuf = *npbuf = *bmbuf = *bpbuf = *nbpbuf = '\0';
- *badop = 0;
- if (parc < 1)
- return 0;
- /*
- * Mode is accepted when sptr is a channel operator
- * but also when the mode is received from a server.
- * At this point, let any member pass, so they are allowed
- * to see the bans.
- */
- member_y = find_channel_member(sptr, chptr);
- if (!(IsServer(cptr) || member_y))
- return 0;
-
-#ifdef OPER_MODE_LCHAN
- if (IsOperOnLocalChannel(sptr, chptr->chname) && !IsChanOp(member_y))
- LocalChanOperMode = 1;
-#endif
-
- mode = &(chptr->mode);
- memcpy(&oldm, mode, sizeof(struct Mode));
-
- newmode = mode->mode;
-
- while (curr && *curr) {
- switch (*curr) {
- case '+':
- whatt = MODE_ADD;
- break;
- case '-':
- whatt = MODE_DEL;
- break;
- case 'o':
- case 'v':
- if (--parc <= 0)
- break;
- parv++;
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- /*
- * Check for nickname changes and try to follow these
- * to make sure the right client is affected by the
- * mode change.
- * Even if we find a nick with find_chasing() there
- * is still a reason to ignore in a special case.
- * We need to ignore the mode when:
- * - It is part of a net.burst (from a server and
- * a MODE_ADD). Ofcourse we don't ignore mode
- * changes from Uworld.
- * - The found nick is not on the right side off
- * the net.junction.
- * This fixes the bug that when someone (tries to)
- * ride a net.break and does so with the nick of
- * someone on the otherside, that he is nick collided
- * (killed) but his +o still ops the other person.
- */
- if (MyUser(sptr))
- {
- if (!(who = find_chasing(sptr, parv[0], NULL)))
- break;
- }
- else
- {
- if (!(who = findNUser(parv[0])))
- break;
- }
- if (whatt == MODE_ADD && IsServer(sptr) && who->from != sptr->from &&
- !find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD))
- break;
-
- if (!(member_x = find_member_link(chptr, who)) ||
- (MyUser(sptr) && IsZombie(member_x)))
- {
- send_reply(cptr, ERR_USERNOTINCHANNEL, who->name, chptr->chname);
- break;
- }
- /*
- * if the user is +k, prevent a deop from local user
- */
- if (whatt == MODE_DEL && IsChannelService(who) && *curr == 'o') {
- /*
- * XXX - CHECKME
- */
- if (MyUser(cptr)) {
- send_reply(cptr, ERR_ISCHANSERVICE, parv[0], chptr->chname);
- break;
- }
- else {
- sprintf_irc(sendbuf,":%s NOTICE * :*** Notice -- Deop of +k user on %s by %s", /* XXX set_mode only called by old m_mode */
- me.name,chptr->chname,cptr->name);
- }
- }
-#ifdef NO_OPER_DEOP_LCHAN
- /*
- * if the user is an oper on a local channel, prevent him
- * from being deoped. that oper can deop himself though.
- */
- if (whatt == MODE_DEL && IsOperOnLocalChannel(who, chptr->chname) &&
- (who != sptr) && MyUser(cptr) && *curr == 'o')
- {
- send_reply(cptr, ERR_ISOPERLCHAN, parv[0], chptr->chname);
- break;
- }
-#endif
- if (whatt == MODE_ADD)
- {
- lp = &chops[opcnt++];
- lp->value.cptr = who;
- if (IsServer(sptr) && (!(who->flags & FLAGS_TS8) || ((*curr == 'o') &&
- !(member_x->status & (CHFL_SERVOPOK | CHFL_CHANOP)))))
- *badop = ((member_x->status & CHFL_DEOPPED) && (*curr == 'o')) ? 2 : 3;
- lp->flags = (*curr == 'o') ? MODE_CHANOP : MODE_VOICE;
- lp->flags |= MODE_ADD;
- }
- else if (whatt == MODE_DEL)
- {
- lp = &chops[opcnt++];
- lp->value.cptr = who;
- doesdeop = 1; /* Also when -v */
- lp->flags = (*curr == 'o') ? MODE_CHANOP : MODE_VOICE;
- lp->flags |= MODE_DEL;
- }
- if (*curr == 'o')
- doesop = 1;
- break;
- case 'k':
- if (--parc <= 0)
- break;
- parv++;
- /* check now so we eat the parameter if present */
- if (keychange)
- break;
- else
- {
- char *s = &(*parv)[-1];
- unsigned short count = KEYLEN + 1;
-
- while (*++s > ' ' && *s != ':' && --count);
- *s = '\0';
- if (!**parv) /* nothing left in key */
- break;
- }
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- if (whatt == MODE_ADD)
- {
- if (*mode->key && !IsServer(cptr))
- send_reply(cptr, ERR_KEYSET, chptr->chname);
- else if (!*mode->key || IsServer(cptr))
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- if (strlen(lp->value.cp) > KEYLEN)
- lp->value.cp[KEYLEN] = '\0';
- lp->flags = MODE_KEY | MODE_ADD;
- keychange = 1;
- }
- }
- else if (whatt == MODE_DEL)
- {
- /* Debug((DEBUG_INFO, "removing key: mode->key: >%s< *parv: >%s<", mode->key, *parv)); */
- if (0 == ircd_strcmp(mode->key, *parv) || IsServer(cptr))
- {
- /* Debug((DEBUG_INFO, "key matched")); */
- lp = &chops[opcnt++];
- lp->value.cp = mode->key;
- lp->flags = MODE_KEY | MODE_DEL;
- keychange = 1;
- }
- }
- break;
- case 'b':
- if (--parc <= 0) {
- if (0 == banlsent) {
- /*
- * Only send it once
- */
- send_ban_list(cptr, chptr);
- banlsent = 1;
- }
- break;
- }
- parv++;
- if (EmptyString(*parv))
- break;
- if (MyUser(sptr))
- {
- if ((cp = strchr(*parv, ' ')))
- *cp = 0;
- if (opcnt >= MAXMODEPARAMS || **parv == ':' || **parv == '\0')
- break;
- }
- if (whatt == MODE_ADD)
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- lp->flags = MODE_ADD | MODE_BAN;
- }
- else if (whatt == MODE_DEL)
- {
- lp = &chops[opcnt++];
- lp->value.cp = *parv;
- lp->flags = MODE_DEL | MODE_BAN;
- }
- break;
- case 'l':
- /*
- * limit 'l' to only *1* change per mode command but
- * eat up others.
- */
- if (limitset)
- {
- if (whatt == MODE_ADD && --parc > 0)
- parv++;
- break;
- }
- if (whatt == MODE_DEL)
- {
- limitset = 1;
- nusers = 0;
- break;
- }
- if (--parc > 0)
- {
- if (EmptyString(*parv))
- break;
- if (MyUser(sptr) && opcnt >= MAXMODEPARAMS)
- break;
- if (!(nusers = atoi(*++parv)))
- continue;
- lp = &chops[opcnt++];
- lp->flags = MODE_ADD | MODE_LIMIT;
- limitset = 1;
- break;
- }
- need_more_params(cptr, "MODE +l");
- break;
- case 'i': /* falls through for default case */
- if (whatt == MODE_DEL)
- while ((lp = chptr->invites))
- del_invite(lp->value.cptr, chptr);
- default:
- for (ip = flags; *ip; ip += 2)
- if (*(ip + 1) == *curr)
- break;
-
- if (*ip)
- {
- if (whatt == MODE_ADD)
- {
- if (*ip == MODE_PRIVATE)
- newmode &= ~MODE_SECRET;
- else if (*ip == MODE_SECRET)
- newmode &= ~MODE_PRIVATE;
- newmode |= *ip;
- }
- else
- newmode &= ~*ip;
- }
- else if (!IsServer(cptr))
- send_reply(cptr, ERR_UNKNOWNMODE, *curr);
- break;
- }
- curr++;
- /*
- * Make sure mode strings such as "+m +t +p +i" are parsed
- * fully.
- */
- if (!*curr && parc > 0)
- {
- curr = *++parv;
- parc--;
- /* If this was from a server, and it is the last
- * parameter and it starts with a digit, it must
- * be the creationtime. --Run
- */
- if (IsServer(sptr))
- {
- if (parc == 1 && IsDigit(*curr))
- {
- newtime = atoi(curr);
- if (newtime && chptr->creationtime == MAGIC_REMOTE_JOIN_TS)
- {
- chptr->creationtime = newtime;
- *badop = 0;
- }
- gotts = 1;
- if (newtime == 0)
- {
- *badop = 2;
- hacknotice = 1;
- }
- else if (newtime > chptr->creationtime)
- { /* It is a net-break ride if we have ops.
- bounce modes if we have ops. --Run */
- if (doesdeop)
- *badop = 2;
- else if (chptr->creationtime == 0)
- {
- if (chptr->creationtime == 0 || doesop)
- chptr->creationtime = newtime;
- *badop = 0;
- }
- /* Bounce: */
- else
- *badop = 1;
- }
- /*
- * A legal *badop can occur when two
- * people join simultaneously a channel,
- * Allow for 10 min of lag (and thus hacking
- * on channels younger then 10 min) --Run
- */
- else if (*badop == 0 ||
- chptr->creationtime > (TStime() - TS_LAG_TIME))
- {
- if (newtime < chptr->creationtime)
- chptr->creationtime = newtime;
- *badop = 0;
- }
- break;
- }
- }
- else
- *badop = 0;
- }
- } /* end of while loop for MODE processing */
-
-#ifdef OPER_MODE_LCHAN
- /*
- * Now reject non chan ops. Accept modes from opers on local channels
- * even if they are deopped
- */
- if (!IsServer(cptr) &&
- (!member_y || !(IsChanOp(member_y) ||
- IsOperOnLocalChannel(sptr, chptr->chname))))
-#else
- if (!IsServer(cptr) && (!member_y || !IsChanOp(member_y)))
-#endif
- {
- *badop = 0;
- return (opcnt || newmode != mode->mode || limitset || keychange) ? 0 : -1;
- }
-
- if (doesop && newtime == 0 && IsServer(sptr))
- *badop = 2;
-
- if (*badop >= 2 &&
- (aconf = find_conf_byhost(cptr->confs, sptr->name, CONF_UWORLD)))
- *badop = 4;
-
-#ifdef OPER_MODE_LCHAN
- bounce = (*badop == 1 || *badop == 2 ||
- (is_deopped(sptr, chptr) &&
- !IsOperOnLocalChannel(sptr, chptr->chname))) ? 1 : 0;
-#else
- bounce = (*badop == 1 || *badop == 2 || is_deopped(sptr, chptr)) ? 1 : 0;
-#endif
-
- whatt = 0;
- for (ip = flags; *ip; ip += 2) {
- if ((*ip & newmode) && !(*ip & oldm.mode))
- {
- if (bounce)
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- *bmbuf++ = *(ip + 1);
- }
- else
- {
- if (whatt != MODE_ADD)
- {
- *mbuf++ = '+';
- whatt = MODE_ADD;
- }
- mode->mode |= *ip;
- *mbuf++ = *(ip + 1);
- }
- }
- }
- for (ip = flags; *ip; ip += 2) {
- if ((*ip & oldm.mode) && !(*ip & newmode))
- {
- if (bounce)
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = *(ip + 1);
- }
- else
- {
- if (whatt != MODE_DEL)
- {
- *mbuf++ = '-';
- whatt = MODE_DEL;
- }
- mode->mode &= ~*ip;
- *mbuf++ = *(ip + 1);
- }
- }
- }
- blen = nblen = 0;
- if (limitset && !nusers && mode->limit)
- {
- if (bounce)
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = 'l';
- sprintf(numeric, "%-15d", mode->limit);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- strcat(bpbuf, numeric);
- blen += strlen(numeric);
- strcat(bpbuf, " ");
- strcat(nbpbuf, numeric);
- nblen += strlen(numeric);
- strcat(nbpbuf, " ");
- }
- else
- {
- if (whatt != MODE_DEL)
- {
- *mbuf++ = '-';
- whatt = MODE_DEL;
- }
- mode->mode &= ~MODE_LIMIT;
- mode->limit = 0;
- *mbuf++ = 'l';
- }
- }
- /*
- * Reconstruct "+bkov" chain.
- */
- if (opcnt)
- {
- int i = 0;
- char c = 0;
- unsigned int prev_whatt = 0;
-
- for (; i < opcnt; i++)
- {
- lp = &chops[i];
- /*
- * make sure we have correct mode change sign
- */
- if (whatt != (lp->flags & (MODE_ADD | MODE_DEL)))
- {
- if (lp->flags & MODE_ADD)
- {
- *mbuf++ = '+';
- prev_whatt = whatt;
- whatt = MODE_ADD;
- }
- else
- {
- *mbuf++ = '-';
- prev_whatt = whatt;
- whatt = MODE_DEL;
- }
- }
- len = strlen(pbuf);
- nlen = strlen(npbuf);
- /*
- * get c as the mode char and tmp as a pointer to
- * the parameter for this mode change.
- */
- switch (lp->flags & MODE_WPARAS)
- {
- case MODE_CHANOP:
- c = 'o';
- cp = lp->value.cptr->name;
- break;
- case MODE_VOICE:
- c = 'v';
- cp = lp->value.cptr->name;
- break;
- case MODE_BAN:
- /*
- * I made this a bit more user-friendly (tm):
- * nick = nick!*@*
- * nick!user = nick!user@*
- * user@host = *!user@host
- * host.name = *!*@host.name --Run
- */
- c = 'b';
- cp = pretty_mask(lp->value.cp);
- break;
- case MODE_KEY:
- c = 'k';
- cp = lp->value.cp;
- break;
- case MODE_LIMIT:
- c = 'l';
- sprintf(numeric, "%-15d", nusers);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- cp = numeric;
- break;
- }
-
- /* What could be added: cp+' '+' '+<TS>+'\0' */
- if (len + strlen(cp) + 13 > MODEBUFLEN ||
- nlen + strlen(cp) + NUMNICKLEN + 12 > MODEBUFLEN)
- break;
-
- switch (lp->flags & MODE_WPARAS)
- {
- case MODE_KEY:
- if (strlen(cp) > KEYLEN)
- *(cp + KEYLEN) = '\0';
- if ((whatt == MODE_ADD && (*mode->key == '\0' ||
- 0 != ircd_strcmp(mode->key, cp))) ||
- (whatt == MODE_DEL && (*mode->key != '\0')))
- {
- if (bounce)
- {
- if (*mode->key == '\0')
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- strcat(bpbuf, cp);
- blen += strlen(cp);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, cp);
- nblen += strlen(cp);
- strcat(nbpbuf, " ");
- nblen++;
- }
- else
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- strcat(bpbuf, mode->key);
- blen += strlen(mode->key);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, mode->key);
- nblen += strlen(mode->key);
- strcat(nbpbuf, " ");
- nblen++;
- }
- *bmbuf++ = c;
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- else
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- if (whatt == MODE_ADD)
- ircd_strncpy(mode->key, cp, KEYLEN);
- else
- *mode->key = '\0';
- }
- }
- break;
- case MODE_LIMIT:
- if (nusers && nusers != mode->limit)
- {
- if (bounce)
- {
- if (mode->limit == 0)
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- }
- else
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- sprintf(numeric, "%-15d", mode->limit);
- if ((cp = strchr(numeric, ' ')))
- *cp = '\0';
- strcat(bpbuf, numeric);
- blen += strlen(numeric);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, numeric);
- nblen += strlen(numeric);
- strcat(nbpbuf, " ");
- nblen++;
- }
- *bmbuf++ = c;
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- else
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- mode->limit = nusers;
- }
- }
- break;
- case MODE_CHANOP:
- case MODE_VOICE:
- member_y = find_member_link(chptr, lp->value.cptr);
- if (lp->flags & MODE_ADD)
- {
- change = (~member_y->status) & CHFL_VOICED_OR_OPPED & lp->flags;
- if (change && bounce)
- {
- if (lp->flags & MODE_CHANOP)
- SetDeopped(member_y);
-
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- *bmbuf++ = c;
- strcat(bpbuf, lp->value.cptr->name);
- blen += strlen(lp->value.cptr->name);
- strcat(bpbuf, " ");
- blen++;
- sprintf_irc(nbpbuf + nblen, "%s%s ", NumNick(lp->value.cptr));
- nblen += strlen(nbpbuf + nblen);
- change = 0;
- }
- else if (change)
- {
- member_y->status |= lp->flags & CHFL_VOICED_OR_OPPED;
- if (IsChanOp(member_y))
- {
- ClearDeopped(member_y);
- if (IsServer(sptr))
- ClearServOpOk(member_y);
- }
- }
- }
- else
- {
- change = member_y->status & CHFL_VOICED_OR_OPPED & lp->flags;
- if (change && bounce)
- {
- if (lp->flags & MODE_CHANOP)
- ClearDeopped(member_y);
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- *bmbuf++ = c;
- strcat(bpbuf, lp->value.cptr->name);
- blen += strlen(lp->value.cptr->name);
- strcat(bpbuf, " ");
- blen++;
- sprintf_irc(nbpbuf + nblen, "%s%s ", NumNick(lp->value.cptr));
- blen += strlen(bpbuf + blen);
- change = 0;
- }
- else
- {
- member_y->status &= ~change;
- if ((change & MODE_CHANOP) && IsServer(sptr))
- SetDeopped(member_y);
- }
- }
- if (change || *badop == 2 || *badop == 4)
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- sprintf_irc(npbuf + nlen, "%s%s ", NumNick(lp->value.cptr));
- nlen += strlen(npbuf + nlen);
- npbuf[nlen++] = ' ';
- npbuf[nlen] = 0;
- }
- else
- {
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- break;
- case MODE_BAN:
-/*
- * Only bans aren't bounced, it makes no sense to bounce last second
- * bans while propagating bans done before the net.rejoin. The reason
- * why I don't bounce net.rejoin bans is because it is too much
- * work to take care of too long strings adding the necessary TS to
- * net.burst bans -- RunLazy
- * We do have to check for *badop==2 now, we don't want HACKs to take
- * effect.
- *
- * Since BURST - I *did* implement net.rejoin ban bouncing. So now it
- * certainly makes sense to also bounce 'last second' bans (bans done
- * after the net.junction). -- RunHardWorker
- */
- if ((change = (whatt & MODE_ADD) &&
- !add_banid(sptr, chptr, cp, !bounce, !add_banid_called)))
- add_banid_called = 1;
- else
- change = (whatt & MODE_DEL) && !del_banid(chptr, cp, !bounce);
-
- if (bounce && change)
- {
- change = 0;
- if ((whatt & MODE_ADD))
- {
- if (bwhatt != MODE_DEL)
- {
- *bmbuf++ = '-';
- bwhatt = MODE_DEL;
- }
- }
- else if ((whatt & MODE_DEL))
- {
- if (bwhatt != MODE_ADD)
- {
- *bmbuf++ = '+';
- bwhatt = MODE_ADD;
- }
- }
- *bmbuf++ = c;
- strcat(bpbuf, cp);
- blen += strlen(cp);
- strcat(bpbuf, " ");
- blen++;
- strcat(nbpbuf, cp);
- nblen += strlen(cp);
- strcat(nbpbuf, " ");
- nblen++;
- }
- if (change)
- {
- *mbuf++ = c;
- strcat(pbuf, cp);
- len += strlen(cp);
- strcat(pbuf, " ");
- len++;
- strcat(npbuf, cp);
- nlen += strlen(cp);
- strcat(npbuf, " ");
- nlen++;
- }
- else
- {
- mbuf--;
- if (*mbuf != '+' && *mbuf != '-')
- mbuf++;
- else
- whatt = prev_whatt;
- }
- break;
- }
- } /* for (; i < opcnt; i++) */
- } /* if (opcnt) */
+{
+ static char star[2] = { '*', 0 };
+ static char retmask[NICKLEN + USERLEN + HOSTLEN + 3];
+ char *last_dot = NULL;
+ char *ptr;
- *mbuf++ = '\0';
- *bmbuf++ = '\0';
+ /* Case 1: default */
+ char *nick = mask;
+ char *user = star;
+ char *host = star;
- /* Bounce here */
- if (!hacknotice && *bmodebuf && chptr->creationtime)
- {
- sendcmdto_one(&me, CMD_MODE, cptr, "%H %s %s %Tu", chptr, bmodebuf,
- nbparambuf, *badop == 2 ? (time_t) 0 : chptr->creationtime);
- }
- /* If there are possibly bans to re-add, bounce them now */
- if (add_banid_called && bounce)
+ /* Do a _single_ pass through the characters of the mask: */
+ for (ptr = mask; *ptr; ++ptr)
{
- struct SLink *ban[6]; /* Max 6 bans at a time */
- size_t len[6], sblen, total_len;
- int cnt, delayed = 0;
- while (delayed || (ban[0] = next_overlapped_ban()))
+ if (*ptr == '!')
{
- len[0] = strlen(ban[0]->value.ban.banstr);
- cnt = 1; /* We already got one ban :) */
- /* XXX sendbuf used to send ban bounces! */
- sblen = sprintf_irc(sendbuf, ":%s MODE %s +b", /* XXX set_mode only called by old m_mode */
- me.name, chptr->chname) - sendbuf; /* XXX set_mode only called by old m_mode */
- total_len = sblen + 1 + len[0]; /* 1 = ' ' */
- /* Find more bans: */
- delayed = 0;
- while (cnt < 6 && (ban[cnt] = next_overlapped_ban()))
- {
- len[cnt] = strlen(ban[cnt]->value.ban.banstr);
- if (total_len + 5 + len[cnt] > BUFSIZE) /* 5 = "b \r\n\0" */
- {
- delayed = cnt + 1; /* != 0 */
- break; /* Flush */
- }
- sendbuf[sblen++] = 'b'; /* XXX set_mode only called by old m_mode */
- total_len += 2 + len[cnt++]; /* 2 = "b " */
- }
- while (cnt--)
+ /* Case 3 or 5: Found first '!' (without finding a '@' yet) */
+ user = ++ptr;
+ host = star;
+ }
+ else if (*ptr == '@')
+ {
+ /* Case 4: Found last '@' (without finding a '!' yet) */
+ nick = star;
+ user = mask;
+ host = ++ptr;
+ }
+ else if (*ptr == '.')
+ {
+ /* Case 2: Found last '.' (without finding a '!' or '@' yet) */
+ last_dot = ptr;
+ continue;
+ }
+ else
+ continue;
+ for (; *ptr; ++ptr)
+ {
+ if (*ptr == '@')
{
- sendbuf[sblen++] = ' '; /* XXX set_mode only called by old m_mode */
- strcpy(sendbuf + sblen, ban[cnt]->value.ban.banstr); /* XXX set_mode only called by old m_mode */
- sblen += len[cnt];
+ /* Case 4 or 5: Found last '@' */
+ host = ptr + 1;
}
- sendbufto_one(cptr); /* Send bounce to uplink */ /* XXX set_mode only called by old m_mode */
- if (delayed)
- ban[0] = ban[delayed - 1];
}
+ break;
+ }
+ if (user == star && last_dot)
+ {
+ /* Case 2: */
+ nick = star;
+ user = star;
+ host = mask;
+ }
+ /* Check lengths */
+ if (nick != star)
+ {
+ char *nick_end = (user != star) ? user - 1 : ptr;
+ if (nick_end - nick > NICKLEN)
+ nick[NICKLEN] = 0;
+ *nick_end = 0;
}
- /* Send -b's of overlapped bans to clients to keep them synchronized */
- if (add_banid_called && !bounce)
+ if (user != star)
{
- struct SLink *ban;
- char *banstr[6]; /* Max 6 bans at a time */
- size_t len[6], sblen, psblen, total_len;
- int cnt, delayed = 0;
- struct Membership* member_z;
- struct Client *acptr;
- if (IsServer(sptr))
- /* XXX sendbuf used to send ban bounces! */
- psblen = sprintf_irc(sendbuf, ":%s MODE %s -b", /* XXX set_mode only called by old m_mode */
- sptr->name, chptr->chname) - sendbuf; /* XXX set_mode only called by old m_mode */
- else /* We rely on IsRegistered(sptr) being true for MODE */
- psblen = sprintf_irc(sendbuf, ":%s!%s@%s MODE %s -b", sptr->name, /* XXX set_mode only called by old m_mode */
- sptr->user->username, sptr->user->host, chptr->chname) - sendbuf; /* XXX set_mode only called by old m_mode */
- while (delayed || (ban = next_removed_overlapped_ban()))
+ char *user_end = (host != star) ? host - 1 : ptr;
+ if (user_end - user > USERLEN)
{
- if (!delayed)
- {
- len[0] = strlen((banstr[0] = ban->value.ban.banstr));
- ban->value.ban.banstr = NULL;
- }
- cnt = 1; /* We already got one ban :) */
- sblen = psblen;
- total_len = sblen + 1 + len[0]; /* 1 = ' ' */
- /* Find more bans: */
- delayed = 0;
- while (cnt < 6 && (ban = next_removed_overlapped_ban()))
- {
- len[cnt] = strlen((banstr[cnt] = ban->value.ban.banstr));
- ban->value.ban.banstr = NULL;
- if (total_len + 5 + len[cnt] > BUFSIZE) /* 5 = "b \r\n\0" */
- {
- delayed = cnt + 1; /* != 0 */
- break; /* Flush */
- }
- sendbuf[sblen++] = 'b'; /* XXX set_mode only called by old m_mode */
- total_len += 2 + len[cnt++]; /* 2 = "b " */
- }
- while (cnt--)
- {
- sendbuf[sblen++] = ' '; /* XXX set_mode only called by old m_mode */
- strcpy(sendbuf + sblen, banstr[cnt]); /* XXX set_mode only called by old m_mode */
- MyFree(banstr[cnt]);
- sblen += len[cnt];
- }
- for (member_z = chptr->members; member_z; member_z = member_z->next_member) {
- acptr = member_z->user;
- if (MyConnect(acptr) && !IsZombie(member_z))
- sendbufto_one(acptr); /* XXX set_mode only called by old m_mode */
- }
- if (delayed)
- {
- banstr[0] = banstr[delayed - 1];
- len[0] = len[delayed - 1];
- }
+ user = user_end - USERLEN;
+ *user = '*';
}
+ *user_end = 0;
+ }
+ if (host != star && ptr - host > HOSTLEN)
+ {
+ host = ptr - HOSTLEN;
+ *host = '*';
}
+ ircd_snprintf(0, retmask, sizeof(retmask), "%s!%s@%s", nick, user, host);
+ return retmask;
+}
- return gotts ? 1 : -1;
+/** send a banlist to a client for a channel
+ *
+ * @param cptr Client to send the banlist to.
+ * @param chptr Channel whose banlist to send.
+ */
+static void send_ban_list(struct Client* cptr, struct Channel* chptr)
+{
+ struct Ban* lp;
+
+ assert(0 != cptr);
+ assert(0 != chptr);
+
+ for (lp = chptr->banlist; lp; lp = lp->next)
+ send_reply(cptr, RPL_BANLIST, chptr->chname, lp->banstr,
+ lp->who, lp->when);
+
+ send_reply(cptr, RPL_ENDOFBANLIST, chptr->chname);
}
-/* We are now treating the <key> part of /join <channel list> <key> as a key
+/** 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>
+ * 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)
{
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)
{
- struct SLink *lp;
int overrideJoin = 0;
/*
* Now a user CAN escape anything if invited -- Isomer
*/
- for (lp = sptr->user->invited; lp; lp = lp->next)
- if (lp->value.chptr == chptr)
- return 0;
+ if (IsInvited(sptr, chptr))
+ return 0;
-#ifdef OPER_WALK_THROUGH_LMODES
/* 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 (IsOperOnLocalChannel(sptr,chptr->chname) && !BadPtr(key) && compall("OVERRIDE",key) == 0)
- {
+ 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;
- }
-#endif
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 (is_banned(sptr, chptr, NULL))
+ if (find_ban(sptr, chptr->banlist))
return overrideJoin + ERR_BANNEDFROMCHAN;
/*
return 0;
}
-/*
- * Remove bells and commas from channel name
+/** 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])) {
+ if (i >= IRCD_MIN(CHANNELLEN, feature_int(FEAT_CHANNELLEN))
+ || !IsChannelChar(cn[i])) {
cn[i] = '\0';
return;
}
}
}
-/*
- * Get Channel block for i (and allocate a new channel
+/** Get a channel block, creating if necessary.
+ * Get Channel block for chname (and allocate a new channel
* block, if it didn't exists before).
+ *
+ * @param cptr Client joining the channel.
+ * @param chname The name of the channel to join.
+ * @param flag set to CGT_CREATE to create the channel if it doesn't
+ * exist
+ *
+ * @returns NULL if the channel is invalid, doesn't exist and CGT_CREATE
+ * wasn't specified or a pointer to the channel structure
*/
struct Channel *get_channel(struct Client *cptr, char *chname, ChannelGetType flag)
{
return chptr;
}
+/** invite a user to a channel.
+ *
+ * Adds an invite for a user to a channel. Limits the number of invites
+ * to FEAT_MAXCHANNELSPERUSER. Does not sent notification to the user.
+ *
+ * @param cptr The client to be invited.
+ * @param chptr The channel to be invited to.
+ */
void add_invite(struct Client *cptr, struct Channel *chptr)
{
struct SLink *inv, **tmp;
/*
* Delete last link in chain if the list is max length
*/
- assert(list_length(cptr->user->invited) == cptr->user->invites);
- if (cptr->user->invites>=MAXCHANNELSPERUSER)
- del_invite(cptr, cptr->user->invited->value.chptr);
+ assert(list_length((cli_user(cptr))->invited) == (cli_user(cptr))->invites);
+ if ((cli_user(cptr))->invites >= feature_int(FEAT_MAXCHANNELSPERUSER))
+ del_invite(cptr, (cli_user(cptr))->invited->value.chptr);
/*
* Add client to channel invite list
*/
/*
* Add channel to the end of the client invite list
*/
- for (tmp = &(cptr->user->invited); *tmp; tmp = &((*tmp)->next));
+ for (tmp = &((cli_user(cptr))->invited); *tmp; tmp = &((*tmp)->next));
inv = make_link();
inv->value.chptr = chptr;
inv->next = NULL;
(*tmp) = inv;
- cptr->user->invites++;
+ (cli_user(cptr))->invites++;
}
-/*
+/** Delete an invite
* Delete Invite block from channel invite list and client invite list
+ *
+ * @param cptr Client pointer
+ * @param chptr Channel pointer
*/
void del_invite(struct Client *cptr, struct Channel *chptr)
{
*inv = tmp->next;
free_link(tmp);
tmp = 0;
- cptr->user->invites--;
+ (cli_user(cptr))->invites--;
break;
}
- for (inv = &(cptr->user->invited); (tmp = *inv); inv = &tmp->next)
+ for (inv = &((cli_user(cptr))->invited); (tmp = *inv); inv = &tmp->next)
if (tmp->value.chptr == chptr)
{
*inv = tmp->next;
}
}
-/* List and skip all channels that are listen */
-void list_next_channels(struct Client *cptr, int nr)
-{
- struct ListingArgs *args = cptr->listing;
- struct Channel *chptr = args->chptr;
- chptr->mode.mode &= ~MODE_LISTED;
- while (is_listed(chptr) || --nr >= 0)
- {
- for (; chptr; chptr = chptr->next)
- {
- if (!cptr->user || (SecretChannel(chptr) && !find_channel_member(cptr, chptr)))
- continue;
- if (chptr->users > args->min_users && chptr->users < args->max_users &&
- chptr->creationtime > args->min_time &&
- chptr->creationtime < args->max_time &&
- (!args->topic_limits || (*chptr->topic &&
- chptr->topic_time > args->min_topic_time &&
- chptr->topic_time < args->max_topic_time)))
- {
- if (ShowChannel(cptr,chptr))
- send_reply(cptr, RPL_LIST, chptr->chname, chptr->users,
- chptr->topic);
- chptr = chptr->next;
- break;
- }
- }
- if (!chptr)
- {
- MyFree(cptr->listing);
- cptr->listing = NULL;
- send_reply(cptr, RPL_LISTEND);
- break;
- }
- }
- if (chptr)
- {
- cptr->listing->chptr = chptr;
- chptr->mode.mode |= MODE_LISTED;
- }
-}
-
-/* XXX AIEEEE! sendbuf is an institution here :( */
-void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
- int *send_itp, char is_a_ban, int mode)
-{
- int first = *firstp;
-
- /*
- * Heh - we do not need to test if it still fits in the buffer, because
- * this BURST message is reconstructed from another BURST message, and
- * it only can become smaller. --Run
- */
-
- if (*firstp) /* First token in this parameter ? */
- {
- *firstp = 0;
- if (*send_itp == 0)
- *send_itp = 1; /* Buffer contains data to be sent */
- sendbuf[(*sblenp)++] = ' '; /* XXX add_token_to_sendbuf only called by old m_burst */
- if (is_a_ban)
- {
- sendbuf[(*sblenp)++] = ':'; /* Bans are always the last "parv" */ /* XXX add_token_to_sendbuf only called by old m_burst */
- sendbuf[(*sblenp)++] = is_a_ban; /* XXX add_token_to_sendbuf only called by old m_burst */
- }
- }
- else /* Of course, 'send_it' is already set here */
- /* Seperate banmasks with a space because
- they can contain commas themselfs: */
- sendbuf[(*sblenp)++] = is_a_ban ? ' ' : ','; /* XXX add_token_to_sendbuf only called by old m_burst */
- strcpy(sendbuf + *sblenp, token); /* XXX add_token_to_sendbuf only called by old m_burst */
- *sblenp += strlen(token);
- if (!is_a_ban) /* nick list ? Need to take care
- of modes for nicks: */
- {
- static int last_mode = 0;
- mode &= CHFL_CHANOP | CHFL_VOICE;
- if (first)
- last_mode = 0;
- if (last_mode != mode) /* Append mode like ':ov' if changed */
- {
- last_mode = mode;
- sendbuf[(*sblenp)++] = ':'; /* XXX add_token_to_sendbuf only called by old m_burst */
- if (mode & CHFL_CHANOP)
- sendbuf[(*sblenp)++] = 'o'; /* XXX add_token_to_sendbuf only called by old m_burst */
- if (mode & CHFL_VOICE)
- sendbuf[(*sblenp)++] = 'v'; /* XXX add_token_to_sendbuf only called by old m_burst */
- }
- sendbuf[*sblenp] = '\0'; /* XXX add_token_to_sendbuf only called by old m_burst */
- }
-}
-
-void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
- const char *param, int *count)
-{
- static char* pb;
- static char* sbp;
- static char* sbpi;
- int paramdoesntfit = 0;
- char parabuf[MODEBUFLEN];
-
- assert(0 != sptr);
- assert(0 != chptr);
- assert(0 != count);
-
- if (*count == -1) /* initialize ? */
- {
- /* XXX sendbuf used! */
- sbp = sbpi =
- sprintf_irc(sendbuf, ":%s MODE %s -", sptr->name, chptr->chname); /* XXX cancel_mode only called from old ms_burst */
- pb = parabuf;
- *count = 0;
- }
- /* m == 0 means flush */
- if (m)
- {
- if (param)
- {
- size_t nplen = strlen(param);
- if (pb - parabuf + nplen + 23 > MODEBUFLEN)
- paramdoesntfit = 1;
- else
- {
- *sbp++ = m;
- *pb++ = ' ';
- strcpy(pb, param);
- pb += nplen;
- ++*count;
- }
- }
- else
- *sbp++ = m;
- }
- else if (*count == 0)
- return;
- if (*count == 6 || !m || paramdoesntfit)
- {
- struct Membership* member;
- strcpy(sbp, parabuf);
- for (member = chptr->members; member; member = member->next_member)
- if (MyUser(member->user))
- sendbufto_one(member->user); /* XXX cancel_mode only called from old ms_burst */
- sbp = sbpi;
- pb = parabuf;
- *count = 0;
- }
- if (paramdoesntfit)
- {
- *sbp++ = m;
- *pb++ = ' ';
- strcpy(pb, param);
- pb += strlen(param);
- ++*count;
- }
-}
-
-
-/*
- * Consider:
+/** @page zombie Explanation of Zombies
+ *
+ * Synopsis:
*
+ * A channel member is turned into a zombie when he is kicked from a
+ * channel but his server has not acknowledged the kick. Servers that
+ * see the member as a zombie can accept actions he performed before
+ * being kicked, without allowing chanop operations from outsiders or
+ * desyncing the network.
+ *
+ * Consider:
+ * <pre>
* client
* |
* c
* X --a--> A --b--> B --d--> D
* |
* who
+ * </pre>
*
* Where `who' is being KICK-ed by a "KICK" message received by server 'A'
* via 'a', or on server 'B' via either 'b' or 'c', or on server D via 'd'.
*
* a) On server A : set CHFL_ZOMBIE for `who' (lp) and pass on the KICK.
- * Remove the user immedeately when no users are left on the channel.
+ * Remove the user immediately when no users are left on the channel.
* b) On server B : remove the user (who/lp) from the channel, send a
* PART upstream (to A) and pass on the KICK.
* c) KICKed by `client'; On server B : remove the user (who/lp) from the
* - A PART is only sent upstream in case b).
*
* 2 aug 97:
- *
+ * <pre>
* 6
* |
* 1 --- 2 --- 3 --- 4 --- 5
* | |
* kicker who
+ * </pre>
*
* We also need to turn 'who' into a zombie on servers 1 and 6,
* because a KICK from 'who' (kicking someone else in that direction)
- * can arrive there afterwards - which should not be bounced itself.
+ * can arrive there afterward - which should not be bounced itself.
* Therefore case a) also applies for servers 1 and 6.
*
* --Run
*/
-void make_zombie(struct Membership* member, struct Client* who, struct Client* cptr,
- struct Client* sptr, struct Channel* chptr)
+
+/** Turn a user on a channel into a zombie
+ * This function turns a user into a zombie (see \ref zombie)
+ *
+ * @param member The structure representing this user on this channel.
+ * @param who The client that is being kicked.
+ * @param cptr The connection the kick came from.
+ * @param sptr The client that is doing the kicking.
+ * @param chptr The channel the user is being kicked from.
+ */
+void make_zombie(struct Membership* member, struct Client* who,
+ struct Client* cptr, struct Client* sptr, struct Channel* chptr)
{
assert(0 != member);
assert(0 != who);
remove_user_from_channel(who, chptr);
return;
}
- if (who->from == cptr) /* True on servers 1, 5 and 6 */
+ if (cli_from(who) == cptr) /* True on servers 1, 5 and 6 */
{
- struct Client *acptr = IsServer(sptr) ? sptr : sptr->user->server;
- for (; acptr != &me; acptr = acptr->serv->up)
- if (acptr == who->user->server) /* Case d) (server 5) */
+ struct Client *acptr = IsServer(sptr) ? sptr : (cli_user(sptr))->server;
+ for (; acptr != &me; acptr = (cli_serv(acptr))->up)
+ if (acptr == (cli_user(who))->server) /* Case d) (server 5) */
{
remove_user_from_channel(who, chptr);
return;
*/
}
+/** returns the number of zombies on a channel
+ * @param chptr Channel to count zombies in.
+ *
+ * @returns The number of zombies on the channel.
+ */
int number_of_zombies(struct Channel *chptr)
{
struct Membership* member;
return count;
}
-/*
- * send_hack_notice()
- *
- * parc & parv[] are the same as that of the calling function:
- * mtype == 1 is from m_mode, 2 is from m_create, 3 is from m_kick.
- *
- * This function prepares sendbuf with the server notices and wallops
- * to be sent for all hacks. -Ghostwolf 18-May-97
- */
-/* XXX let's get rid of this if we can */
-void send_hack_notice(struct Client *cptr, struct Client *sptr, int parc,
- char *parv[], int badop, int mtype)
-{
- struct Channel *chptr;
- static char params[MODEBUFLEN];
- int i = 3;
- chptr = FindChannel(parv[1]);
- *params = '\0';
-
- /* P10 servers require numeric nick conversion before sending. */
- switch (mtype)
- {
- case 1: /* Convert nicks for MODE HACKs here */
- {
- char *mode = parv[2];
- while (i < parc)
- {
- while (*mode && *mode != 'o' && *mode != 'v')
- ++mode;
- strcat(params, " ");
- if (*mode == 'o' || *mode == 'v')
- {
- /*
- * blindly stumble through parameter list hoping one of them
- * might turn out to be a numeric nick
- * NOTE: this should not cause a problem but _may_ end up finding
- * something we aren't looking for. findNUser should be able to
- * handle any garbage that is thrown at it, but may return a client
- * if we happen to get lucky with a mode string or a timestamp
- */
- struct Client *acptr;
- if ((acptr = findNUser(parv[i])) != NULL) /* Convert nicks here */
- strcat(params, acptr->name);
- else
- {
- strcat(params, "<");
- strcat(params, parv[i]);
- strcat(params, ">");
- }
- }
- else /* If it isn't a numnick, send it 'as is' */
- strcat(params, parv[i]);
- i++;
- }
- sprintf_irc(sendbuf, /* XXX send_hack_notice only called from old m_mode */
- ":%s NOTICE * :*** Notice -- %sHACK(%d): %s MODE %s %s%s ["
- TIME_T_FMT "]", me.name, (badop == 3) ? "BOUNCE or " : "", badop,
- parv[0], parv[1], parv[2], params, chptr->creationtime);
- sendbufto_op_mask((badop == 3) ? SNO_HACK3 : (badop == /* XXX DYING */ /* XXX send_hack_notice only called from old m_mode */
- 4) ? SNO_HACK4 : SNO_HACK2);
-
- if ((IsServer(sptr)) && (badop == 2))
- {
- sprintf_irc(sendbuf, ":%s DESYNCH :HACK: %s MODE %s %s%s", /* XXX send_hack_notice only called from old m_mode */
- me.name, parv[0], parv[1], parv[2], params);
- sendbufto_serv_butone(cptr); /* XXX DYING */ /* XXX send_hack_notice only called from old m_mode */
- }
- break;
- }
- case 2: /* No conversion is needed for CREATE; the only numnick is sptr */
- {
- sendto_serv_butone(cptr, ":%s DESYNCH :HACK: %s CREATE %s %s", /* XXX DYING */
- me.name, sptr->name, chptr->chname, parv[2]);
- sendto_op_mask(SNO_HACK2, "HACK(2): %s CREATE %s %s", /* XXX DYING */
- sptr->name, chptr->chname, parv[2]);
- break;
- }
- case 3: /* Convert nick in KICK message */
- {
- struct Client *acptr;
- if ((acptr = findNUser(parv[2])) != NULL) /* attempt to convert nick */
- sprintf_irc(sendbuf, /* XXX send_hack_notice only called from old m_mode */
- ":%s NOTICE * :*** Notice -- HACK: %s KICK %s %s :%s",
- me.name, sptr->name, parv[1], acptr->name, parv[3]);
- else /* if conversion fails, send it 'as is' in <>'s */
- sprintf_irc(sendbuf, /* XXX send_hack_notice only called from old m_mode */
- ":%s NOTICE * :*** Notice -- HACK: %s KICK %s <%s> :%s",
- me.name, sptr->name, parv[1], parv[2], parv[3]);
- sendbufto_op_mask(SNO_HACK4); /* XXX DYING */ /* XXX send_hack_notice only called from old m_mode */
- break;
- }
- }
-}
-
-/*
+/** Concatenate some strings together.
* This helper function builds an argument string in strptr, consisting
* of the original string, a space, and str1 and str2 concatenated (if,
* of course, str2 is not NULL)
+ *
+ * @param strptr The buffer to concatenate into
+ * @param strptr_i modified offset to the position to modify
+ * @param str1 The string to concatenate from.
+ * @param str2 The second string to contatenate from.
+ * @param c Charactor to separate the string from str1 and str2.
*/
static void
-build_string(char *strptr, int *strptr_i, char *str1, char *str2, char c)
+build_string(char *strptr, int *strptr_i, const char *str1,
+ const char *str2, char c)
{
if (c)
strptr[(*strptr_i)++] = c;
strptr[(*strptr_i)] = '\0';
}
-/*
+/** Flush out the modes
* This is the workhorse of our ModeBuf suite; this actually generates the
* output MODE commands, HACK notices, or whatever. It's pretty complicated.
+ *
+ * @param mbuf The mode buffer to flush
+ * @param all If true, flush all modes, otherwise leave partial modes in the
+ * buffer.
+ *
+ * @returns 0
*/
static int
modebuf_flush_int(struct ModeBuf *mbuf, int all)
MODE_TOPICLIMIT, 't',
MODE_INVITEONLY, 'i',
MODE_NOPRIVMSGS, 'n',
+ MODE_REGONLY, 'r',
+ MODE_DELJOINS, 'D',
+ MODE_WASDELJOINS, 'd',
/* MODE_KEY, 'k', */
/* MODE_BAN, 'b', */
-/* MODE_LIMIT, 'l', */
+ MODE_LIMIT, 'l',
+/* MODE_APASS, 'A', */
+/* MODE_UPASS, 'U', */
0x0, 0x0
};
int i;
if (mbuf->mb_add == 0 && mbuf->mb_rem == 0 && mbuf->mb_count == 0)
return 0;
- /* Ok, if we were given the OPMODE flag, hide the source if its a user */
- if (mbuf->mb_dest & MODEBUF_DEST_OPMODE && !IsServer(mbuf->mb_source))
- app_source = mbuf->mb_source->user->server;
+ /* Ok, if we were given the OPMODE flag, or its a server, hide the source.
+ */
+ if (mbuf->mb_dest & MODEBUF_DEST_OPMODE || IsServer(mbuf->mb_source))
+ app_source = &me;
else
app_source = mbuf->mb_source;
}
if (MB_TYPE(mbuf, i) & (MODE_CHANOP | MODE_VOICE)) {
- tmp = strlen(MB_CLIENT(mbuf, i)->name);
+ tmp = strlen(cli_name(MB_CLIENT(mbuf, i)));
if ((totalbuflen - IRCD_MAX(5, tmp)) <= 0) /* don't overflow buffer */
MB_TYPE(mbuf, i) |= MODE_SAVE; /* save for later */
bufptr[(*bufptr_i)++] = MB_TYPE(mbuf, i) & MODE_CHANOP ? 'o' : 'v';
totalbuflen -= IRCD_MAX(5, tmp) + 1;
}
- } else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN)) {
+ } else if (MB_TYPE(mbuf, i) & (MODE_BAN | MODE_APASS | MODE_UPASS)) {
tmp = strlen(MB_STRING(mbuf, i));
if ((totalbuflen - tmp) <= 0) /* don't overflow buffer */
MB_TYPE(mbuf, i) |= MODE_SAVE; /* save for later */
else {
- bufptr[(*bufptr_i)++] = MB_TYPE(mbuf, i) & MODE_KEY ? 'k' : 'b';
+ char mode_char;
+ switch(MB_TYPE(mbuf, i) & (MODE_BAN | MODE_APASS | MODE_UPASS))
+ {
+ case MODE_APASS:
+ mode_char = 'A';
+ break;
+ case MODE_UPASS:
+ mode_char = 'U';
+ break;
+ default:
+ mode_char = 'b';
+ break;
+ }
+ bufptr[(*bufptr_i)++] = mode_char;
+ totalbuflen -= tmp + 1;
+ }
+ } else if (MB_TYPE(mbuf, i) & MODE_KEY) {
+ tmp = (mbuf->mb_dest & MODEBUF_DEST_NOKEY ? 1 :
+ strlen(MB_STRING(mbuf, i)));
+
+ if ((totalbuflen - tmp) <= 0) /* don't overflow buffer */
+ MB_TYPE(mbuf, i) |= MODE_SAVE; /* save for later */
+ else {
+ bufptr[(*bufptr_i)++] = 'k';
totalbuflen -= tmp + 1;
}
} else if (MB_TYPE(mbuf, i) & MODE_LIMIT) {
/* if it's a limit, we also format the number */
- sprintf_irc(limitbuf, "%d", MB_UINT(mbuf, i));
+ ircd_snprintf(0, limitbuf, sizeof(limitbuf), "%u", MB_UINT(mbuf, i));
tmp = strlen(limitbuf);
/* deal with clients... */
if (MB_TYPE(mbuf, i) & (MODE_CHANOP | MODE_VOICE))
- build_string(strptr, strptr_i, MB_CLIENT(mbuf, i)->name, 0, ' ');
+ build_string(strptr, strptr_i, cli_name(MB_CLIENT(mbuf, i)), 0, ' ');
- /* deal with strings... */
- else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN))
+ /* deal with bans... */
+ else if (MB_TYPE(mbuf, i) & MODE_BAN)
build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0, ' ');
+ /* deal with keys... */
+ else if (MB_TYPE(mbuf, i) & MODE_KEY)
+ build_string(strptr, strptr_i, mbuf->mb_dest & MODEBUF_DEST_NOKEY ?
+ "*" : MB_STRING(mbuf, i), 0, ' ');
+
+ /* deal with invisible passwords */
+ else if (MB_TYPE(mbuf, i) & (MODE_APASS | MODE_UPASS))
+ build_string(strptr, strptr_i, "*", 0, ' ');
+
/*
* deal with limit; note we cannot include the limit parameter if we're
* removing it
}
/* send the messages off to their destination */
- if (mbuf->mb_dest & MODEBUF_DEST_HACK2) {
+ if (mbuf->mb_dest & MODEBUF_DEST_HACK2)
sendto_opmask_butone(0, SNO_HACK2, "HACK(2): %s MODE %s %s%s%s%s%s%s "
- "[%Tu]", app_source->name, mbuf->mb_channel->chname,
+ "[%Tu]",
+ cli_name(feature_bool(FEAT_HIS_SNOTICES) ?
+ mbuf->mb_source : app_source),
+ mbuf->mb_channel->chname,
rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
addbuf, remstr, addstr,
mbuf->mb_channel->creationtime);
- sendcmdto_serv_butone(&me, CMD_DESYNCH, mbuf->mb_connect,
- ":HACK: %s MODE %s %s%s%s%s%s%s [%Tu]",
- app_source->name, mbuf->mb_channel->chname,
- rembuf_i ? "-" : "", rembuf,
- addbuf_i ? "+" : "", addbuf, remstr, addstr,
- mbuf->mb_channel->creationtime);
- }
if (mbuf->mb_dest & MODEBUF_DEST_HACK3)
sendto_opmask_butone(0, SNO_HACK3, "BOUNCE or HACK(3): %s MODE %s "
- "%s%s%s%s%s%s [%Tu]", app_source->name,
+ "%s%s%s%s%s%s [%Tu]",
+ cli_name(feature_bool(FEAT_HIS_SNOTICES) ?
+ mbuf->mb_source : app_source),
mbuf->mb_channel->chname, rembuf_i ? "-" : "",
rembuf, addbuf_i ? "+" : "", addbuf, remstr, addstr,
mbuf->mb_channel->creationtime);
if (mbuf->mb_dest & MODEBUF_DEST_HACK4)
sendto_opmask_butone(0, SNO_HACK4, "HACK(4): %s MODE %s %s%s%s%s%s%s "
- "[%Tu]", app_source->name, mbuf->mb_channel->chname,
+ "[%Tu]",
+ cli_name(feature_bool(FEAT_HIS_SNOTICES) ?
+ mbuf->mb_source : app_source),
+ mbuf->mb_channel->chname,
rembuf_i ? "-" : "", rembuf, addbuf_i ? "+" : "",
addbuf, remstr, addstr,
mbuf->mb_channel->creationtime);
-#ifdef OPATH
- if (mbuf->mb_dest & MODEBUF_DEST_LOG) {
- write_log(OPATH, "%Tu %#C OPMODE %H %s%s%s%s%s%s\n", TStime(),
- mbuf->mb_source, mbuf->mb_channel, rembuf_i ? "-" : "", rembuf,
+ if (mbuf->mb_dest & MODEBUF_DEST_LOG)
+ log_write(LS_OPERMODE, L_INFO, LOG_NOSNOTICE,
+ "%#C OPMODE %H %s%s%s%s%s%s", mbuf->mb_source,
+ mbuf->mb_channel, rembuf_i ? "-" : "", rembuf,
addbuf_i ? "+" : "", addbuf, remstr, addstr);
- }
-#endif
if (mbuf->mb_dest & MODEBUF_DEST_CHANNEL)
- sendcmdto_channel_butserv(app_source, CMD_MODE, mbuf->mb_channel,
+ sendcmdto_channel_butserv_butone(app_source, CMD_MODE, mbuf->mb_channel, NULL, 0,
"%H %s%s%s%s%s%s", mbuf->mb_channel,
rembuf_i ? "-" : "", rembuf,
addbuf_i ? "+" : "", addbuf, remstr, addstr);
build_string(strptr, strptr_i, NumNick(MB_CLIENT(mbuf, i)), ' ');
/* deal with modes that take strings */
- else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN))
+ else if (MB_TYPE(mbuf, i) & (MODE_KEY | MODE_BAN | MODE_APASS | MODE_UPASS))
build_string(strptr, strptr_i, MB_STRING(mbuf, i), 0, ' ');
/*
return 0;
}
-/*
+/** Initialise a modebuf
* This routine just initializes a ModeBuf structure with the information
* needed and the options given.
+ *
+ * @param mbuf The mode buffer to initialise.
+ * @param source The client that is performing the mode.
+ * @param connect ?
+ * @param chan The channel that the mode is being performed upon.
+ * @param dest ?
*/
void
modebuf_init(struct ModeBuf *mbuf, struct Client *source,
assert(0 != chan);
assert(0 != dest);
+ if (IsLocalChannel(chan->chname)) dest &= ~MODEBUF_DEST_SERVER;
+
mbuf->mb_add = 0;
mbuf->mb_rem = 0;
mbuf->mb_source = source;
}
}
-/*
+/** Append a new mode to a modebuf
* This routine simply adds modes to be added or deleted; do a binary OR
* with either MODE_ADD or MODE_DEL
+ *
+ * @param mbuf Mode buffer
+ * @param mode MODE_ADD or MODE_DEL OR'd with MODE_PRIVATE etc.
*/
void
modebuf_mode(struct ModeBuf *mbuf, unsigned int mode)
assert(0 != (mode & (MODE_ADD | MODE_DEL)));
mode &= (MODE_ADD | MODE_DEL | MODE_PRIVATE | MODE_SECRET | MODE_MODERATED |
- MODE_TOPICLIMIT | MODE_INVITEONLY | MODE_NOPRIVMSGS);
+ MODE_TOPICLIMIT | MODE_INVITEONLY | MODE_NOPRIVMSGS | MODE_REGONLY |
+ MODE_DELJOINS | MODE_WASDELJOINS);
+
+ if (!(mode & ~(MODE_ADD | MODE_DEL))) /* don't add empty modes... */
+ return;
if (mode & MODE_ADD) {
mbuf->mb_rem &= ~mode;
}
}
-/*
+/** Append a mode that takes an int argument to the modebuf
+ *
* This routine adds a mode to be added or deleted that takes a unsigned
* int parameter; mode may *only* be the relevant mode flag ORed with one
* of MODE_ADD or MODE_DEL
+ *
+ * @param mbuf The mode buffer to append to.
+ * @param mode The mode to append.
+ * @param uint The argument to the mode.
*/
void
modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode, unsigned int uint)
assert(0 != mbuf);
assert(0 != (mode & (MODE_ADD | MODE_DEL)));
+ if (mode == (MODE_LIMIT | MODE_DEL)) {
+ mbuf->mb_rem |= mode;
+ return;
+ }
MB_TYPE(mbuf, mbuf->mb_count) = mode;
MB_UINT(mbuf, mbuf->mb_count) = uint;
modebuf_flush_int(mbuf, 0);
}
-/*
+/** append a string mode
* This routine adds a mode to be added or deleted that takes a string
* parameter; mode may *only* be the relevant mode flag ORed with one of
* MODE_ADD or MODE_DEL
+ *
+ * @param mbuf The mode buffer to append to.
+ * @param mode The mode to append.
+ * @param string The string parameter to append.
+ * @param free If the string should be free'd later.
*/
void
modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode, char *string,
modebuf_flush_int(mbuf, 0);
}
-/*
+/** Append a mode on a client to a modebuf.
* This routine adds a mode to be added or deleted that takes a client
* parameter; mode may *only* be the relevant mode flag ORed with one of
* MODE_ADD or MODE_DEL
+ *
+ * @param mbuf The modebuf to append the mode to.
+ * @param mode The mode to append.
+ * @param client The client argument to append.
*/
void
modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
modebuf_flush_int(mbuf, 0);
}
-/*
- * This is the exported binding for modebuf_flush()
+/** The exported binding for modebuf_flush()
+ *
+ * @param mbuf The mode buffer to flush.
+ *
+ * @see modebuf_flush_int()
*/
int
modebuf_flush(struct ModeBuf *mbuf)
{
+ struct Membership *memb;
+
+ /* Check if MODE_WASDELJOINS should be set */
+ if (!(mbuf->mb_channel->mode.mode & (MODE_DELJOINS | MODE_WASDELJOINS))
+ && (mbuf->mb_rem & MODE_DELJOINS)) {
+ for (memb = mbuf->mb_channel->members; memb; memb = memb->next_member) {
+ if (IsDelayedJoin(memb)) {
+ mbuf->mb_channel->mode.mode |= MODE_WASDELJOINS;
+ mbuf->mb_add |= MODE_WASDELJOINS;
+ mbuf->mb_rem &= ~MODE_WASDELJOINS;
+ break;
+ }
+ }
+ }
+
return modebuf_flush_int(mbuf, 1);
}
-/*
- * This extracts the simple modes contained in mbuf
+/* This extracts the simple modes contained in mbuf
+ *
+ * @param mbuf The mode buffer to extract the modes from.
+ * @param buf The string buffer to write the modes into.
*/
void
modebuf_extract(struct ModeBuf *mbuf, char *buf)
MODE_INVITEONLY, 'i',
MODE_NOPRIVMSGS, 'n',
MODE_KEY, 'k',
+ MODE_APASS, 'A',
+ MODE_UPASS, 'U',
/* MODE_BAN, 'b', */
MODE_LIMIT, 'l',
+ MODE_REGONLY, 'r',
+ MODE_DELJOINS, 'D',
0x0, 0x0
};
unsigned int add;
int i, bufpos = 0, len;
int *flag_p;
char *key = 0, limitbuf[20];
+ char *apass = 0, *upass = 0;
assert(0 != mbuf);
assert(0 != buf);
for (i = 0; i < mbuf->mb_count; i++) { /* find keys and limits */
if (MB_TYPE(mbuf, i) & MODE_ADD) {
- add |= MB_TYPE(mbuf, i) & (MODE_KEY | MODE_LIMIT);
+ add |= MB_TYPE(mbuf, i) & (MODE_KEY | MODE_LIMIT | MODE_APASS | MODE_UPASS);
if (MB_TYPE(mbuf, i) & MODE_KEY) /* keep strings */
key = MB_STRING(mbuf, i);
else if (MB_TYPE(mbuf, i) & MODE_LIMIT)
- ircd_snprintf(0, limitbuf, sizeof(limitbuf), "%d", MB_UINT(mbuf, i));
+ ircd_snprintf(0, limitbuf, sizeof(limitbuf), "%u", MB_UINT(mbuf, i));
+ else if (MB_TYPE(mbuf, i) & MODE_UPASS)
+ upass = MB_STRING(mbuf, i);
+ else if (MB_TYPE(mbuf, i) & MODE_APASS)
+ apass = MB_STRING(mbuf, i);
}
}
build_string(buf, &bufpos, key, 0, ' ');
else if (buf[i] == 'l')
build_string(buf, &bufpos, limitbuf, 0, ' ');
+ else if (buf[i] == 'U')
+ build_string(buf, &bufpos, upass, 0, ' ');
+ else if (buf[i] == 'A')
+ build_string(buf, &bufpos, apass, 0, ' ');
}
buf[bufpos] = '\0';
return;
}
-/*
- * Simple function to invalidate bans
+/** Simple function to invalidate bans
+ *
+ * This function sets all bans as being valid.
+ *
+ * @param chan The channel to operate on.
*/
void
mode_ban_invalidate(struct Channel *chan)
ClearBanValid(member);
}
-/*
- * Simple function to drop invite structures
+/** Simple function to drop invite structures
+ *
+ * Remove all the invites on the channel.
+ *
+ * @param chan Channel to remove invites from.
+ *
*/
void
mode_invite_clear(struct Channel *chan)
}
/* What we've done for mode_parse so far... */
-#define DONE_LIMIT 0x01 /* We've set the limit */
-#define DONE_KEY 0x02 /* We've set the key */
-#define DONE_BANLIST 0x04 /* We've sent the ban list */
-#define DONE_NOTOPER 0x08 /* We've sent a "Not oper" error */
-#define DONE_BANCLEAN 0x10 /* We've cleaned bans... */
+#define DONE_LIMIT 0x01 /**< We've set the limit */
+#define DONE_KEY 0x02 /**< We've set the key */
+#define DONE_BANLIST 0x04 /**< We've sent the ban list */
+#define DONE_NOTOPER 0x08 /**< We've sent a "Not oper" error */
+#define DONE_BANCLEAN 0x10 /**< We've cleaned bans... */
+#define DONE_UPASS 0x20 /**< We've set user pass */
+#define DONE_APASS 0x40 /**< We've set admin pass */
struct ParseState {
struct ModeBuf *mbuf;
struct Client *cptr;
struct Client *sptr;
struct Channel *chptr;
+ struct Membership *member;
int parc;
char **parv;
unsigned int flags;
int args_used;
int max_args;
int numbans;
- struct SLink banlist[MAXPARA];
+ struct Ban banlist[MAXPARA];
struct {
unsigned int flag;
struct Client *client;
} cli_change[MAXPARA];
};
-/*
+/** Helper function to send "Not oper" or "Not member" messages
* Here's a helper function to deal with sending along "Not oper" or
* "Not member" messages
+ *
+ * @param state Parsing State object
*/
static void
send_notoper(struct ParseState *state)
state->done |= DONE_NOTOPER;
}
-/*
+/** Parse a limit
* Helper function to convert limits
+ *
+ * @param state Parsing state object.
+ * @param flag_p ?
*/
static void
mode_parse_limit(struct ParseState *state, int *flag_p)
return;
}
- t_limit = atoi(state->parv[state->args_used++]); /* grab arg */
+ t_limit = strtoul(state->parv[state->args_used++], 0, 10); /* grab arg */
state->parc--;
state->max_args--;
+ if ((int)t_limit<0) /* don't permit a negative limit */
+ return;
+
if (!(state->flags & MODE_PARSE_WIPEOUT) &&
(!t_limit || t_limit == state->chptr->mode.limit))
return;
return;
}
+ /* Can't remove a limit that's not there */
+ if (state->dir == MODE_DEL && !state->chptr->mode.limit)
+ return;
+
+ /* Skip if this is a burst and a lower limit than this is set already */
+ if ((state->flags & MODE_PARSE_BURST) &&
+ (state->chptr->mode.mode & flag_p[0]) &&
+ (state->chptr->mode.limit < t_limit))
+ return;
+
if (state->done & DONE_LIMIT) /* allow limit to be set only once */
return;
state->done |= DONE_LIMIT;
return;
state->done |= DONE_KEY;
- t_len = KEYLEN + 1;
+ t_len = KEYLEN;
/* clean up the key string */
s = t_str;
- while (*++s > ' ' && *s != ':' && --t_len)
- ;
+ while (*s > ' ' && *s != ':' && *s != ',' && t_len--)
+ s++;
*s = '\0';
if (!*t_str) { /* warn if empty */
if (!state->mbuf)
return;
+ /* Skip if this is a burst, we have a key already and the new key is
+ * after the old one alphabetically */
+ if ((state->flags & MODE_PARSE_BURST) &&
+ *(state->chptr->mode.key) &&
+ ircd_strcmp(state->chptr->mode.key, t_str) <= 0)
+ return;
+
/* can't add a key if one is set, nor can one remove the wrong key */
if (!(state->flags & MODE_PARSE_FORCE))
if ((state->dir == MODE_ADD && *state->chptr->mode.key) ||
}
/*
- * Helper function to convert bans
+ * Helper function to convert user passes
*/
static void
-mode_parse_ban(struct ParseState *state, int *flag_p)
+mode_parse_upass(struct ParseState *state, int *flag_p)
{
char *t_str, *s;
- struct SLink *ban, *newban = 0;
+ int t_len;
- if (state->parc <= 0) { /* Not enough args, send ban list */
- if (MyUser(state->sptr) && !(state->done & DONE_BANLIST)) {
- send_ban_list(state->sptr, state->chptr);
- state->done |= DONE_BANLIST;
+ if (MyUser(state->sptr) && state->max_args <= 0) /* drop if too many args */
+ return;
+
+ if (state->parc <= 0) { /* warn if not enough args */
+ if (MyUser(state->sptr))
+ need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +U" :
+ "MODE -U");
+ return;
+ }
+
+ t_str = state->parv[state->args_used++]; /* grab arg */
+ state->parc--;
+ state->max_args--;
+
+ /* If they're not an oper, they can't change modes */
+ if (state->flags & (MODE_PARSE_NOTOPER | MODE_PARSE_NOTMEMBER)) {
+ send_notoper(state);
+ return;
+ }
+
+ /* If a non-service user is trying to force it, refuse. */
+ if (state->flags & MODE_PARSE_FORCE && MyUser(state->sptr)
+ && !HasPriv(state->sptr, PRIV_APASS_OPMODE)) {
+ send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+ state->chptr->chname);
+ return;
+ }
+
+ /* If they are not the channel manager, they are not allowed to change it */
+ if (MyUser(state->sptr) && !(state->flags & MODE_PARSE_FORCE || IsChannelManager(state->member))) {
+ if (*state->chptr->mode.apass) {
+ send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+ state->chptr->chname);
+ } else if (TStime() - state->chptr->creationtime >= 171000) {
+ send_reply(state->sptr, ERR_NOMANAGER_LONG, state->chptr->chname);
+ } else {
+ send_reply(state->sptr, ERR_NOMANAGER_SHORT, state->chptr->chname);
}
+ return;
+ }
+
+ if (state->done & DONE_UPASS) /* allow upass to be set only once */
+ return;
+ state->done |= DONE_UPASS;
+ t_len = PASSLEN + 1;
+
+ /* clean up the upass string */
+ s = t_str;
+ while (*++s > ' ' && *s != ':' && --t_len)
+ ;
+ *s = '\0';
+
+ if (!*t_str) { /* warn if empty */
+ if (MyUser(state->sptr))
+ need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +U" :
+ "MODE -U");
return;
}
+ if (!state->mbuf)
+ return;
+
+ if (!(state->flags & MODE_PARSE_FORCE)) {
+ /* can't add the upass while apass is not set */
+ if (state->dir == MODE_ADD && !*state->chptr->mode.apass) {
+ send_reply(state->sptr, ERR_UPASSNOTSET, state->chptr->chname, state->chptr->chname);
+ return;
+ }
+ /* cannot set a +U password that is the same as +A */
+ if (state->dir == MODE_ADD && !ircd_strcmp(state->chptr->mode.apass, t_str)) {
+ send_reply(state->sptr, ERR_UPASS_SAME_APASS, state->chptr->chname);
+ return;
+ }
+ /* can't add a upass if one is set, nor can one remove the wrong upass */
+ if ((state->dir == MODE_ADD && *state->chptr->mode.upass) ||
+ (state->dir == MODE_DEL &&
+ ircd_strcmp(state->chptr->mode.upass, t_str))) {
+ send_reply(state->sptr, ERR_KEYSET, state->chptr->chname);
+ return;
+ }
+ }
+
+ if (!(state->flags & MODE_PARSE_WIPEOUT) && state->dir == MODE_ADD &&
+ !ircd_strcmp(state->chptr->mode.upass, t_str))
+ return; /* no upass change */
+
+ if (state->flags & MODE_PARSE_BOUNCE) {
+ if (*state->chptr->mode.upass) /* reset old upass */
+ modebuf_mode_string(state->mbuf, MODE_DEL | flag_p[0],
+ state->chptr->mode.upass, 0);
+ else /* remove new bogus upass */
+ modebuf_mode_string(state->mbuf, MODE_ADD | flag_p[0], t_str, 0);
+ } else /* send new upass */
+ modebuf_mode_string(state->mbuf, state->dir | flag_p[0], t_str, 0);
+
+ if (state->flags & MODE_PARSE_SET) {
+ if (state->dir == MODE_ADD) /* set the new upass */
+ ircd_strncpy(state->chptr->mode.upass, t_str, PASSLEN);
+ else /* remove the old upass */
+ *state->chptr->mode.upass = '\0';
+ }
+}
+
+/*
+ * Helper function to convert admin passes
+ */
+static void
+mode_parse_apass(struct ParseState *state, int *flag_p)
+{
+ char *t_str, *s;
+ int t_len;
+
if (MyUser(state->sptr) && state->max_args <= 0) /* drop if too many args */
return;
+ if (state->parc <= 0) { /* warn if not enough args */
+ if (MyUser(state->sptr))
+ need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +A" :
+ "MODE -A");
+ return;
+ }
+
t_str = state->parv[state->args_used++]; /* grab arg */
state->parc--;
state->max_args--;
return;
}
- if ((s = strchr(t_str, ' ')))
- *s = '\0';
+ /* If a non-service user is trying to force it, refuse. */
+ if (state->flags & MODE_PARSE_FORCE && MyUser(state->sptr)
+ && !HasPriv(state->sptr, PRIV_APASS_OPMODE)) {
+ send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+ state->chptr->chname);
+ return;
+ }
- if (!*t_str || *t_str == ':') { /* warn if empty */
- if (MyUser(state->sptr))
- need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +b" :
- "MODE -b");
+ /* Don't allow to change the Apass if the channel is older than 48 hours. */
+ if (TStime() - state->chptr->creationtime >= 172800 && !IsAnOper(state->sptr)) {
+ send_reply(state->sptr, ERR_CHANSECURED, state->chptr->chname);
return;
}
- t_str = collapse(pretty_mask(t_str));
+ /* If they are not the channel manager, they are not allowed to change it */
+ if (MyUser(state->sptr) && !(state->flags & MODE_PARSE_FORCE || IsChannelManager(state->member))) {
+ if (*state->chptr->mode.apass) {
+ send_reply(state->sptr, ERR_NOTMANAGER, state->chptr->chname,
+ state->chptr->chname);
+ } else if (TStime() - state->chptr->creationtime >= 171000) {
+ send_reply(state->sptr, ERR_NOMANAGER_LONG, state->chptr->chname);
+ } else {
+ send_reply(state->sptr, ERR_NOMANAGER_SHORT, state->chptr->chname);
+ }
+ return;
+ }
- /* remember the ban for the moment... */
- if (state->dir == MODE_ADD) {
- newban = state->banlist + (state->numbans++);
- newban->next = 0;
+ if (state->done & DONE_APASS) /* allow apass to be set only once */
+ return;
+ state->done |= DONE_APASS;
- DupString(newban->value.ban.banstr, t_str);
- newban->value.ban.who = state->sptr->name;
- newban->value.ban.when = TStime();
+ t_len = PASSLEN + 1;
- newban->flags = CHFL_BAN | MODE_ADD;
+ /* clean up the apass string */
+ s = t_str;
+ while (*++s > ' ' && *s != ':' && --t_len)
+ ;
+ *s = '\0';
- if ((s = strrchr(t_str, '@')) && check_if_ipmask(s + 1))
- newban->flags |= CHFL_BAN_IPMASK;
+ if (!*t_str) { /* warn if empty */
+ if (MyUser(state->sptr))
+ need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +A" :
+ "MODE -A");
+ return;
}
- if (!state->chptr->banlist) {
- state->chptr->banlist = newban; /* add our ban with its flags */
- state->done |= DONE_BANCLEAN;
+ if (!state->mbuf)
return;
+
+ if (!(state->flags & MODE_PARSE_FORCE)) {
+ /* can't remove the apass while upass is still set */
+ if (state->dir == MODE_DEL && *state->chptr->mode.upass) {
+ send_reply(state->sptr, ERR_UPASSSET, state->chptr->chname, state->chptr->chname);
+ return;
+ }
+ /* can't add an apass if one is set, nor can one remove the wrong apass */
+ if ((state->dir == MODE_ADD && *state->chptr->mode.apass) ||
+ (state->dir == MODE_DEL && ircd_strcmp(state->chptr->mode.apass, t_str))) {
+ send_reply(state->sptr, ERR_KEYSET, state->chptr->chname);
+ return;
+ }
}
- /* Go through all bans */
- for (ban = state->chptr->banlist; ban; ban = ban->next) {
- /* first, clean the ban flags up a bit */
- if (!(state->done & DONE_BANCLEAN))
- /* Note: We're overloading *lots* of bits here; be careful! */
- ban->flags &= ~(MODE_ADD | MODE_DEL | CHFL_BAN_OVERLAPPED);
+ if (!(state->flags & MODE_PARSE_WIPEOUT) && state->dir == MODE_ADD &&
+ !ircd_strcmp(state->chptr->mode.apass, t_str))
+ return; /* no apass change */
- /* Bit meanings:
- *
- * MODE_ADD - Ban was added; if we're bouncing modes,
- * then we'll remove it below; otherwise,
- * we'll have to allocate a real ban
- *
- * MODE_DEL - Ban was marked for deletion; if we're
- * bouncing modes, we'll have to re-add it,
- * otherwise, we'll have to remove it
- *
- * CHFL_BAN_OVERLAPPED - The ban we added turns out to overlap
- * with a ban already set; if we're
- * bouncing modes, we'll have to bounce
- * this one; otherwise, we'll just ignore
- * it when we process added bans
- */
+ if (state->flags & MODE_PARSE_BOUNCE) {
+ if (*state->chptr->mode.apass) /* reset old apass */
+ modebuf_mode_string(state->mbuf, MODE_DEL | flag_p[0],
+ state->chptr->mode.apass, 0);
+ else /* remove new bogus apass */
+ modebuf_mode_string(state->mbuf, MODE_ADD | flag_p[0], t_str, 0);
+ } else /* send new apass */
+ modebuf_mode_string(state->mbuf, state->dir | flag_p[0], t_str, 0);
- if (state->dir == MODE_DEL && !ircd_strcmp(ban->value.ban.banstr, t_str)) {
- ban->flags |= MODE_DEL; /* delete one ban */
+ if (state->flags & MODE_PARSE_SET) {
+ if (state->dir == MODE_ADD) { /* set the new apass */
+ /* Make it VERY clear to the user that this is a one-time password */
+ ircd_strncpy(state->chptr->mode.apass, t_str, PASSLEN);
+ if (MyUser(state->sptr)) {
+ send_reply(state->sptr, RPL_APASSWARN_SET, state->chptr->mode.apass);
+ send_reply(state->sptr, RPL_APASSWARN_SECRET, state->chptr->chname,
+ state->chptr->mode.apass);
+ }
+ } else { /* remove the old apass */
+ *state->chptr->mode.apass = '\0';
+ if (MyUser(state->sptr))
+ send_reply(state->sptr, RPL_APASSWARN_CLEAR);
+ }
+ }
+}
- if (state->done & DONE_BANCLEAN) /* If we're cleaning, finish */
- break;
- } else if (state->dir == MODE_ADD) {
- /* if the ban already exists, don't worry about it */
- if (!ircd_strcmp(ban->value.ban.banstr, t_str)) {
- if (state->done & DONE_BANCLEAN) /* If we're cleaning, finish */
- break;
- continue;
- } else if (!mmatch(ban->value.ban.banstr, t_str)) {
- if (!(ban->flags & MODE_DEL))
- newban->flags |= CHFL_BAN_OVERLAPPED; /* our ban overlaps */
- } else if (!mmatch(t_str, ban->value.ban.banstr))
- ban->flags |= MODE_DEL; /* mark ban for deletion: overlapping */
-
- if (!ban->next) {
- ban->next = newban; /* add our ban with its flags */
- break; /* get out of loop */
+/** Compare one ban's extent to another.
+ * This works very similarly to mmatch() but it knows about CIDR masks
+ * and ban exceptions. If both bans are CIDR-based, compare their
+ * address bits; otherwise, use mmatch().
+ * @param[in] old_ban One ban.
+ * @param[in] new_ban Another ban.
+ * @return Zero if \a old_ban is a superset of \a new_ban, non-zero otherwise.
+ */
+static int
+bmatch(struct Ban *old_ban, struct Ban *new_ban)
+{
+ int res;
+ assert(old_ban != NULL);
+ assert(new_ban != NULL);
+ /* A ban is never treated as a superset of an exception. */
+ if (!(old_ban->flags & BAN_EXCEPTION)
+ && (new_ban->flags & BAN_EXCEPTION))
+ return 1;
+ /* If either is not an address mask, match the text masks. */
+ if ((old_ban->flags & new_ban->flags & BAN_IPMASK) == 0)
+ return mmatch(old_ban->banstr, new_ban->banstr);
+ /* If the old ban has a longer prefix than new, it cannot be a superset. */
+ if (old_ban->addrbits > new_ban->addrbits)
+ return 1;
+ /* Compare the masks before the hostname part. */
+ old_ban->banstr[old_ban->nu_len] = new_ban->banstr[new_ban->nu_len] = '\0';
+ res = mmatch(old_ban->banstr, new_ban->banstr);
+ old_ban->banstr[old_ban->nu_len] = new_ban->banstr[new_ban->nu_len] = '@';
+ if (res)
+ return res;
+ /* Compare the addresses. */
+ return !ipmask_check(&new_ban->address, &old_ban->address, old_ban->addrbits);
+}
+
+/** Add a ban from a ban list and mark bans that should be removed
+ * because they overlap.
+ *
+ * There are three invariants for a ban list. First, no ban may be
+ * more specific than another ban. Second, no exception may be more
+ * specific than another exception. Finally, no ban may be more
+ * specific than any exception.
+ *
+ * @param[in,out] banlist Pointer to head of list.
+ * @param[in] newban Ban (or exception) to add (or remove).
+ * @param[in] do_free If non-zero, free \a newban on failure.
+ * @return Zero if \a newban could be applied, non-zero if not.
+ */
+int apply_ban(struct Ban **banlist, struct Ban *newban, int do_free)
+{
+ struct Ban *ban;
+ size_t count = 0;
+
+ assert(newban->flags & (BAN_ADD|BAN_DEL));
+ if (newban->flags & BAN_ADD) {
+ size_t totlen = 0;
+ /* If a less specific entry is found, fail. */
+ for (ban = *banlist; ban; ban = ban->next) {
+ if (!bmatch(ban, newban)) {
+ if (do_free)
+ free_ban(newban);
+ return 1;
+ }
+ if (!(ban->flags & (BAN_OVERLAPPED|BAN_DEL))) {
+ count++;
+ totlen += strlen(ban->banstr);
+ }
+ }
+ /* Mark more specific entries and add this one to the end of the list. */
+ while ((ban = *banlist) != NULL) {
+ if (!bmatch(newban, ban)) {
+ ban->flags |= BAN_OVERLAPPED | BAN_DEL;
+ }
+ banlist = &ban->next;
+ }
+ *banlist = newban;
+ return 0;
+ } else if (newban->flags & BAN_DEL) {
+ size_t remove_count = 0;
+ /* Mark more specific entries. */
+ for (ban = *banlist; ban; ban = ban->next) {
+ if (!bmatch(newban, ban)) {
+ ban->flags |= BAN_OVERLAPPED | BAN_DEL;
+ remove_count++;
}
}
+ if (remove_count)
+ return 0;
+ /* If no matches were found, fail. */
+ if (do_free)
+ free_ban(newban);
+ return 3;
+ }
+ if (do_free)
+ free_ban(newban);
+ return 4;
+}
+
+/*
+ * Helper function to convert bans
+ */
+static void
+mode_parse_ban(struct ParseState *state, int *flag_p)
+{
+ char *t_str, *s;
+ struct Ban *ban, *newban;
+
+ if (state->parc <= 0) { /* Not enough args, send ban list */
+ if (MyUser(state->sptr) && !(state->done & DONE_BANLIST)) {
+ send_ban_list(state->sptr, state->chptr);
+ state->done |= DONE_BANLIST;
+ }
+
+ return;
+ }
+
+ if (MyUser(state->sptr) && state->max_args <= 0) /* drop if too many args */
+ return;
+
+ t_str = state->parv[state->args_used++]; /* grab arg */
+ state->parc--;
+ state->max_args--;
+
+ /* If they're not an oper, they can't change modes */
+ if (state->flags & (MODE_PARSE_NOTOPER | MODE_PARSE_NOTMEMBER)) {
+ send_notoper(state);
+ return;
+ }
+
+ if ((s = strchr(t_str, ' ')))
+ *s = '\0';
+
+ if (!*t_str || *t_str == ':') { /* warn if empty */
+ if (MyUser(state->sptr))
+ need_more_params(state->sptr, state->dir == MODE_ADD ? "MODE +b" :
+ "MODE -b");
+ return;
+ }
+
+ /* Clear all ADD/DEL/OVERLAPPED flags from ban list. */
+ if (!(state->done & DONE_BANCLEAN)) {
+ for (ban = state->chptr->banlist; ban; ban = ban->next)
+ ban->flags &= ~(BAN_ADD | BAN_DEL | BAN_OVERLAPPED);
+ state->done |= DONE_BANCLEAN;
}
- state->done |= DONE_BANCLEAN;
+
+ /* remember the ban for the moment... */
+ newban = state->banlist + (state->numbans++);
+ newban->next = 0;
+ newban->flags = ((state->dir == MODE_ADD) ? BAN_ADD : BAN_DEL)
+ | (*flag_p == MODE_BAN ? 0 : BAN_EXCEPTION);
+ set_ban_mask(newban, collapse(pretty_mask(t_str)));
+ ircd_strncpy(newban->who, cli_name(state->sptr), HOSTLEN);
+ newban->when = TStime();
+ apply_ban(&state->chptr->banlist, newban, 0);
}
/*
static void
mode_process_bans(struct ParseState *state)
{
- struct SLink *ban, *newban, *prevban, *nextban;
+ struct Ban *ban, *newban, *prevban, *nextban;
int count = 0;
int len = 0;
int banlen;
for (prevban = 0, ban = state->chptr->banlist; ban; ban = nextban) {
count++;
- banlen = strlen(ban->value.ban.banstr);
+ banlen = strlen(ban->banstr);
len += banlen;
nextban = ban->next;
- if ((ban->flags & (MODE_DEL | MODE_ADD)) == (MODE_DEL | MODE_ADD)) {
+ if ((ban->flags & (BAN_DEL | BAN_ADD)) == (BAN_DEL | BAN_ADD)) {
if (prevban)
prevban->next = 0; /* Break the list; ban isn't a real ban */
else
count--;
len -= banlen;
- MyFree(ban->value.ban.banstr);
-
continue;
- } else if (ban->flags & MODE_DEL) { /* Deleted a ban? */
+ } else if (ban->flags & BAN_DEL) { /* Deleted a ban? */
+ char *bandup;
+ DupString(bandup, ban->banstr);
modebuf_mode_string(state->mbuf, MODE_DEL | MODE_BAN,
- ban->value.ban.banstr,
- state->flags & MODE_PARSE_SET);
+ bandup, 1);
if (state->flags & MODE_PARSE_SET) { /* Ok, make it take effect */
if (prevban) /* clip it out of the list... */
count--;
len -= banlen;
-
- MyFree(ban->value.ban.who);
- free_link(ban);
+ free_ban(ban);
changed++;
continue; /* next ban; keep prevban like it is */
} else
- ban->flags &= (CHFL_BAN | CHFL_BAN_IPMASK); /* unset other flags */
- } else if (ban->flags & MODE_ADD) { /* adding a ban? */
+ ban->flags &= BAN_IPMASK; /* unset other flags */
+ } else if (ban->flags & BAN_ADD) { /* adding a ban? */
if (prevban)
prevban->next = 0; /* Break the list; ban isn't a real ban */
else
state->chptr->banlist = 0;
/* If we're supposed to ignore it, do so. */
- if (ban->flags & CHFL_BAN_OVERLAPPED &&
+ if (ban->flags & BAN_OVERLAPPED &&
!(state->flags & MODE_PARSE_BOUNCE)) {
count--;
len -= banlen;
-
- MyFree(ban->value.ban.banstr);
} else {
if (state->flags & MODE_PARSE_SET && MyUser(state->sptr) &&
- (len > MAXBANLENGTH || count >= MAXBANS)) {
+ (len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXBANS)) ||
+ count > feature_int(FEAT_MAXBANS))) {
send_reply(state->sptr, ERR_BANLISTFULL, state->chptr->chname,
- ban->value.ban.banstr);
+ ban->banstr);
count--;
len -= banlen;
-
- MyFree(ban->value.ban.banstr);
} else {
+ char *bandup;
/* add the ban to the buffer */
+ DupString(bandup, ban->banstr);
modebuf_mode_string(state->mbuf, MODE_ADD | MODE_BAN,
- ban->value.ban.banstr,
- !(state->flags & MODE_PARSE_SET));
+ bandup, 1);
if (state->flags & MODE_PARSE_SET) { /* create a new ban */
- newban = make_link();
- newban->value.ban.banstr = ban->value.ban.banstr;
- DupString(newban->value.ban.who, ban->value.ban.who);
- newban->value.ban.when = ban->value.ban.when;
- newban->flags = ban->flags & (CHFL_BAN | CHFL_BAN_IPMASK);
+ newban = make_ban(ban->banstr);
+ strcpy(newban->who, ban->who);
+ newban->when = ban->when;
+ newban->flags = ban->flags & BAN_IPMASK;
newban->next = state->chptr->banlist; /* and link it in */
state->chptr->banlist = newban;
(MyUser(state->sptr) && IsZombie(member))) {
if (MyUser(state->sptr))
send_reply(state->sptr, ERR_USERNOTINCHANNEL,
- state->cli_change[i].client->name, state->chptr->chname);
+ cli_name(state->cli_change[i].client),
+ state->chptr->chname);
continue;
}
if (state->flags & MODE_PARSE_FORCE) /* it was forced */
sendto_opmask_butone(0, SNO_HACK4, "Deop of +k user on %H by %s",
state->chptr,
- (IsServer(state->sptr) ? state->sptr->name :
- state->sptr->user->server->name));
+ (IsServer(state->sptr) ? cli_name(state->sptr) :
+ cli_name((cli_user(state->sptr))->server)));
else if (MyUser(state->sptr) && state->flags & MODE_PARSE_SET) {
send_reply(state->sptr, ERR_ISCHANSERVICE,
- state->cli_change[i].client->name, state->chptr->chname);
+ cli_name(state->cli_change[i].client),
+ state->chptr->chname);
continue;
}
}
-#ifdef NO_OPER_DEOP_LCHAN
- /* don't allow local opers to be deopped on local channels */
- if (MyUser(state->sptr) && state->cli_change[i].client != state->sptr &&
- IsOperOnLocalChannel(state->cli_change[i].client,
- state->chptr->chname)) {
- send_reply(state->sptr, ERR_ISOPERLCHAN,
- state->cli_change[i].client->name, state->chptr->chname);
- continue;
- }
-#endif
+ /* check deop for local user */
+ if (MyUser(state->sptr)) {
+
+ /* don't allow local opers to be deopped on local channels */
+ if (state->cli_change[i].client != state->sptr &&
+ IsLocalChannel(state->chptr->chname) &&
+ HasPriv(state->cli_change[i].client, PRIV_DEOP_LCHAN)) {
+ send_reply(state->sptr, ERR_ISOPERLCHAN,
+ cli_name(state->cli_change[i].client),
+ state->chptr->chname);
+ continue;
+ }
+
+ /* don't allow to deop members with an op level that is <= our own level */
+ if (state->sptr != state->cli_change[i].client /* but allow to deop oneself */
+ && state->chptr->mode.apass[0]
+ && state->member
+ && OpLevel(member) <= OpLevel(state->member)) {
+ int equal = (OpLevel(member) == OpLevel(state->member));
+ send_reply(state->sptr, ERR_NOTLOWEROPLEVEL,
+ cli_name(state->cli_change[i].client),
+ state->chptr->chname,
+ OpLevel(state->member), OpLevel(member),
+ "deop", equal ? "the same" : "a higher");
+ continue;
+ }
+ }
}
- /* accumulate the change */
- modebuf_mode_client(state->mbuf, state->cli_change[i].flag,
- state->cli_change[i].client);
+ /* set op-level of member being opped */
+ if ((state->cli_change[i].flag & (MODE_ADD | MODE_CHANOP)) ==
+ (MODE_ADD | MODE_CHANOP)) {
+ /* If being opped by an outsider, get oplevel 0 for an apass
+ * channel, else MAXOPLEVEL.
+ * Otherwise, if not an apass channel, or state->member has
+ * MAXOPLEVEL, get oplevel MAXOPLEVEL.
+ * Otherwise, get state->member's oplevel+1.
+ */
+ if (!state->member)
+ SetOpLevel(member, state->chptr->mode.apass[0] ? 0 : MAXOPLEVEL);
+ else if (!state->chptr->mode.apass[0] || OpLevel(state->member) == MAXOPLEVEL)
+ SetOpLevel(member, MAXOPLEVEL);
+ else
+ SetOpLevel(member, OpLevel(state->member) + 1);
+ }
/* actually effect the change */
if (state->flags & MODE_PARSE_SET) {
if (state->cli_change[i].flag & MODE_ADD) {
+ if (IsDelayedJoin(member))
+ RevealDelayedJoin(member);
member->status |= (state->cli_change[i].flag &
(MODE_CHANOP | MODE_VOICE));
if (state->cli_change[i].flag & MODE_CHANOP)
member->status &= ~(state->cli_change[i].flag &
(MODE_CHANOP | MODE_VOICE));
}
- } /* for (i = 0; state->cli_change[i].flags; i++) { */
+
+ /* accumulate the change */
+ modebuf_mode_client(state->mbuf, state->cli_change[i].flag,
+ state->cli_change[i].client);
+ } /* for (i = 0; state->cli_change[i].flags; i++) */
}
/*
state->add &= ~MODE_SECRET;
state->del |= MODE_SECRET;
}
+ if (flag_p[0] & MODE_DELJOINS) {
+ state->add &= ~MODE_WASDELJOINS;
+ state->del |= MODE_WASDELJOINS;
+ }
} else {
state->add &= ~flag_p[0];
state->del |= flag_p[0];
*/
int
mode_parse(struct ModeBuf *mbuf, struct Client *cptr, struct Client *sptr,
- struct Channel *chptr, int parc, char *parv[], unsigned int flags)
+ struct Channel *chptr, int parc, char *parv[], unsigned int flags,
+ struct Membership* member)
{
static int chan_flags[] = {
MODE_CHANOP, 'o',
MODE_INVITEONLY, 'i',
MODE_NOPRIVMSGS, 'n',
MODE_KEY, 'k',
+ MODE_APASS, 'A',
+ MODE_UPASS, 'U',
MODE_BAN, 'b',
MODE_LIMIT, 'l',
+ MODE_REGONLY, 'r',
+ MODE_DELJOINS, 'D',
MODE_ADD, '+',
MODE_DEL, '-',
0x0, 0x0
state.cptr = cptr;
state.sptr = sptr;
state.chptr = chptr;
+ state.member = member;
state.parc = parc;
state.parv = parv;
state.flags = flags;
for (i = 0; i < MAXPARA; i++) { /* initialize ops/voices arrays */
state.banlist[i].next = 0;
- state.banlist[i].value.ban.banstr = 0;
- state.banlist[i].value.ban.who = 0;
- state.banlist[i].value.ban.when = 0;
+ state.banlist[i].who[0] = '\0';
+ state.banlist[i].when = 0;
state.banlist[i].flags = 0;
state.cli_change[i].flag = 0;
state.cli_change[i].client = 0;
mode_parse_key(&state, flag_p);
break;
+ case 'A': /* deal with Admin passes */
+ if (feature_bool(FEAT_OPLEVELS))
+ mode_parse_apass(&state, flag_p);
+ break;
+
+ case 'U': /* deal with user passes */
+ if (feature_bool(FEAT_OPLEVELS))
+ mode_parse_upass(&state, flag_p);
+ break;
+
case 'b': /* deal with bans */
mode_parse_ban(&state, flag_p);
break;
default: /* deal with other modes */
mode_parse_mode(&state, flag_p);
break;
- } /* switch (*modestr) { */
- } /* for (; *modestr; modestr++) { */
+ } /* switch (*modestr) */
+ } /* for (; *modestr; modestr++) */
if (state.flags & MODE_PARSE_BURST)
break; /* don't interpret any more arguments */
break; /* break out of while loop */
}
}
- } /* while (*modestr) { */
+ } /* while (*modestr) */
/*
* the rest of the function finishes building resultant MODEs; if the
if (*state.chptr->mode.key && !(state.done & DONE_KEY))
modebuf_mode_string(state.mbuf, MODE_DEL | MODE_KEY,
state.chptr->mode.key, 0);
+ if (*state.chptr->mode.upass && !(state.done & DONE_UPASS))
+ modebuf_mode_string(state.mbuf, MODE_DEL | MODE_UPASS,
+ state.chptr->mode.upass, 0);
+ if (*state.chptr->mode.apass && !(state.done & DONE_APASS))
+ modebuf_mode_string(state.mbuf, MODE_DEL | MODE_APASS,
+ state.chptr->mode.apass, 0);
}
if (state.done & DONE_BANCLEAN) /* process bans */
joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan, unsigned int flags)
{
unsigned int len;
+ int is_local;
assert(0 != jbuf);
return;
}
+ is_local = IsLocalChannel(chan->chname);
+
if (jbuf->jb_type == JOINBUF_TYPE_PART ||
jbuf->jb_type == JOINBUF_TYPE_PARTALL) {
+ struct Membership *member = find_member_link(chan, jbuf->jb_source);
+ if (IsUserParting(member))
+ return;
+ SetUserParting(member);
+
/* Send notification to channel */
- if (!(flags & CHFL_ZOMBIE))
- sendcmdto_channel_butserv(jbuf->jb_source, CMD_PART, chan,
+ if (!(flags & (CHFL_ZOMBIE | CHFL_DELAYED)))
+ sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_PART, chan, NULL, 0,
(flags & CHFL_BANNED || !jbuf->jb_comment) ?
":%H" : "%H :%s", chan, jbuf->jb_comment);
else if (MyUser(jbuf->jb_source))
* the original m_part.c */
if (jbuf->jb_type == JOINBUF_TYPE_PARTALL ||
- IsLocalChannel(chan->chname)) /* got to remove user here */
+ is_local) /* got to remove user here */
remove_user_from_channel(jbuf->jb_source, chan);
} else {
+ int oplevel = !chan->mode.apass[0] ? MAXOPLEVEL
+ : (flags & CHFL_CHANNEL_MANAGER) ? 0
+ : 1;
/* Add user to channel */
- add_user_to_channel(chan, jbuf->jb_source, flags);
+ if ((chan->mode.mode & MODE_DELJOINS) && !(flags & CHFL_VOICED_OR_OPPED))
+ add_user_to_channel(chan, jbuf->jb_source, flags | CHFL_DELAYED, oplevel);
+ else
+ add_user_to_channel(chan, jbuf->jb_source, flags, oplevel);
/* send notification to all servers */
- if (jbuf->jb_type != JOINBUF_TYPE_CREATE && !IsLocalChannel(chan->chname))
- sendcmdto_serv_butone(jbuf->jb_source, CMD_JOIN, jbuf->jb_connect,
- "%H %Tu", chan, chan->creationtime);
+ if (jbuf->jb_type != JOINBUF_TYPE_CREATE && !is_local)
+ {
+ if (flags & CHFL_CHANOP)
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_JOIN, jbuf->jb_connect,
+ "%u:%H %Tu", oplevel, chan, chan->creationtime);
+ else
+ sendcmdto_serv_butone(jbuf->jb_source, CMD_JOIN, jbuf->jb_connect,
+ "%H %Tu", chan, chan->creationtime);
+ }
- /* Send the notification to the channel */
- sendcmdto_channel_butserv(jbuf->jb_source, CMD_JOIN, chan, ":%H", chan);
+ if (!((chan->mode.mode & MODE_DELJOINS) && !(flags & CHFL_VOICED_OR_OPPED))) {
+ /* Send the notification to the channel */
+ sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_JOIN, chan, NULL, 0, "%H", chan);
- /* send an op, too, if needed */
- if (!MyUser(jbuf->jb_source) && jbuf->jb_type == JOINBUF_TYPE_CREATE &&
- !IsModelessChannel(chan->chname))
- sendcmdto_channel_butserv(jbuf->jb_source, CMD_MODE, chan, "%H +o %C",
- chan, jbuf->jb_source);
+ /* send an op, too, if needed */
+ if (flags & CHFL_CHANOP && (oplevel < MAXOPLEVEL || !MyUser(jbuf->jb_source)))
+ sendcmdto_channel_butserv_butone((chan->mode.apass[0] ? &me : jbuf->jb_source),
+ CMD_MODE, chan, NULL, 0, "%H +o %C",
+ chan, jbuf->jb_source);
+ } else if (MyUser(jbuf->jb_source))
+ sendcmdto_one(jbuf->jb_source, CMD_JOIN, jbuf->jb_source, ":%H", chan);
}
- if (jbuf->jb_type == JOINBUF_TYPE_PARTALL || IsLocalChannel(chan->chname))
+ if (jbuf->jb_type == JOINBUF_TYPE_PARTALL ||
+ jbuf->jb_type == JOINBUF_TYPE_JOIN || is_local)
return; /* don't send to remote */
/* figure out if channel name will cause buffer to be overflowed */
len = chan ? strlen(chan->chname) + 1 : 2;
- if (jbuf->jb_strlen + len > IRC_BUFSIZE)
+ if (jbuf->jb_strlen + len > BUFSIZE)
joinbuf_flush(jbuf);
/* add channel to list of channels to send and update counts */
int
joinbuf_flush(struct JoinBuf *jbuf)
{
- char chanlist[IRC_BUFSIZE];
+ char chanlist[BUFSIZE];
int chanlist_i = 0;
int i;
return 0;
}
+
+/* Returns TRUE (1) if client is invited, FALSE (0) if not */
+int IsInvited(struct Client* cptr, const void* chptr)
+{
+ struct SLink *lp;
+
+ for (lp = (cli_user(cptr))->invited; lp; lp = lp->next)
+ if (lp->value.chptr == chptr)
+ return 1;
+ return 0;
+}
+
+/* RevealDelayedJoin: sends a join for a hidden user */
+
+void RevealDelayedJoin(struct Membership *member)
+{
+ ClearDelayedJoin(member);
+ sendcmdto_channel_butserv_butone(member->user, CMD_JOIN, member->channel, member->user, 0, ":%H",
+ member->channel);
+ CheckDelayedJoins(member->channel);
+}
+
+/* CheckDelayedJoins: checks and clear +d if necessary */
+
+void CheckDelayedJoins(struct Channel *chan)
+{
+ struct Membership *memb2;
+
+ if (chan->mode.mode & MODE_WASDELJOINS) {
+ for (memb2=chan->members;memb2;memb2=memb2->next_member)
+ if (IsDelayedJoin(memb2))
+ break;
+
+ if (!memb2) {
+ /* clear +d */
+ chan->mode.mode &= ~MODE_WASDELJOINS;
+ sendcmdto_channel_butserv_butone(&me, CMD_MODE, chan, NULL, 0,
+ "%H -d", chan);
+ }
+ }
+}