]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Channel::JoinUser() and Channel::ForceChan() changes
authorattilamolnar <attilamolnar@hush.com>
Fri, 12 Apr 2013 14:00:17 +0000 (16:00 +0200)
committerattilamolnar <attilamolnar@hush.com>
Sat, 13 Apr 2013 14:05:54 +0000 (16:05 +0200)
Convert static Channel::ForceChan() to non-static Channel::ForceJoin() that joins a user to a channel, no permission checks

The (static) Channel::JoinUser() now has a LocalUser parameter, and no longer have TS and bursting parameters. If the channel doesn't exist, it is created using current time as TS

13 files changed:
include/channels.h
src/channels.cpp
src/commands/cmd_join.cpp
src/modules/m_banredirect.cpp
src/modules/m_conn_join.cpp
src/modules/m_cycle.cpp
src/modules/m_denychans.cpp
src/modules/m_ojoin.cpp
src/modules/m_operjoin.cpp
src/modules/m_redirect.cpp
src/modules/m_sajoin.cpp
src/modules/m_spanningtree/fjoin.cpp
src/modules/m_spanningtree/svsjoin.cpp

index 3c60fcd6abe880208b6d68e2887d6154970e06c2..2b2681eace1fc43e0b39f6e570704fdb3d08ef83 100644 (file)
  */
 class CoreExport Channel : public Extensible, public InviteBase
 {
-       /** Connect a Channel to a User
-        */
-       static Channel* ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created);
-
        /** Set default modes for the channel on creation
         */
        void SetDefaultModes();
@@ -189,16 +185,24 @@ class CoreExport Channel : public Extensible, public InviteBase
         */
        void PartUser(User *user, std::string &reason);
 
-       /* Join a user to a channel. May be a channel that doesnt exist yet.
+       /** Join a local user to a channel, with or without permission checks. May be a channel that doesn't exist yet.
         * @param user The user to join to the channel.
         * @param channame The channel name to join to. Does not have to exist.
         * @param key The key of the channel, if given
         * @param override If true, override all join restrictions such as +bkil
         * @return A pointer to the Channel the user was joined to. A new Channel may have
         * been created if the channel did not exist before the user was joined to it.
-        * If the user could not be joined to a channel, the return value may be NULL.
+        * If the user could not be joined to a channel, the return value is NULL.
+        */
+       static Channel* JoinUser(LocalUser* user, std::string channame, bool override = false, const std::string& key = "");
+
+       /** Join a user to an existing channel, without doing any permission checks
+        * @param user The user to join to the channel
+        * @param privs Priviliges (prefix mode letters) to give to this user, may be NULL
+        * @param bursting True if this join is the result of a netburst (passed to modules in the OnUserJoin hook)
+        * @param created True if this channel was just created by a local user (passed to modules in the OnUserJoin hook)
         */
-       static Channel* JoinUser(User *user, std::string channame, bool override, const std::string& key, bool bursting, time_t TS = 0);
+       void ForceJoin(User* user, const std::string* privs = NULL, bool bursting = false, bool created_by_local = false);
 
        /** Write to a channel, from a user, using va_args for text
         * @param user User whos details to prefix the line with
index f2b0b457aa6d90391d00f4ae4faaa745b012ec6d..edb4d056a0cbc3d9aeb9a132f5020163af20a242 100644 (file)
@@ -146,8 +146,11 @@ long Channel::GetUserCounter()
 
 Membership* Channel::AddUser(User* user)
 {
-       Membership* memb = new Membership(user, this);
-       userlist[user] = memb;
+       Membership*& memb = userlist[user];
+       if (memb)
+               return NULL;
+
+       memb = new Membership(user, this);
        return memb;
 }
 
@@ -228,14 +231,13 @@ void Channel::SetDefaultModes()
  * add a channel to a user, creating the record for it if needed and linking
  * it to the user record
  */
-Channel* Channel::JoinUser(User* user, std::string cname, bool override, const std::string& key, bool bursting, time_t TS)
+Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, const std::string& key)
 {
-       // Fix: unregistered users could be joined using /SAJOIN
-       if (!user || user->registered != REG_ALL)
+       if (user->registered != REG_ALL)
+       {
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join unregistered user " + user->uuid + " to channel " + cname);
                return NULL;
-
-       std::string privs;
-       Channel *Ptr;
+       }
 
        /*
         * We don't restrict the number of channels that remote users or users that are override-joining may be in.
@@ -243,7 +245,7 @@ Channel* Channel::JoinUser(User* user, std::string cname, bool override, const s
         * We restrict local operators to OperMaxChans channels.
         * This is a lot more logical than how it was formerly. -- w00t
         */
-       if (IS_LOCAL(user) && !override)
+       if (!override)
        {
                if (user->HasPrivPermission("channels/high-join-limit"))
                {
@@ -266,97 +268,93 @@ Channel* Channel::JoinUser(User* user, std::string cname, bool override, const s
                }
        }
 
+       // Crop channel name if it's too long
        if (cname.length() > ServerInstance->Config->Limits.ChanMax)
                cname.resize(ServerInstance->Config->Limits.ChanMax);
 
-       Ptr = ServerInstance->FindChan(cname);
-       bool created_by_local = false;
+       Channel* chan = ServerInstance->FindChan(cname);
+       bool created_by_local = (chan == NULL); // Flag that will be passed to modules in the OnUserJoin() hook later
+       std::string privs; // Prefix mode(letter)s to give to the joining user
 
-       if (!Ptr)
+       if (!chan)
        {
-               /*
-                * Fix: desync bug was here, don't set @ on remote users - spanningtree handles their permissions. bug #358. -- w00t
-                */
-               if (!IS_LOCAL(user))
-               {
-                       if (!TS)
-                               ServerInstance->Logs->Log("CHANNELS",LOG_DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick.c_str(), cname.c_str());
-               }
-               else
-               {
-                       privs = "o";
-                       created_by_local = true;
-               }
+               privs = "o";
 
-               if (IS_LOCAL(user) && override == false)
+               if (override == false)
                {
+                       // Ask the modules whether they're ok with the join, pass NULL as Channel* as the channel is yet to be created
                        ModResult MOD_RESULT;
-                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (IS_LOCAL(user), NULL, cname, privs, key));
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key));
                        if (MOD_RESULT == MOD_RES_DENY)
-                               return NULL;
+                               return NULL; // A module wasn't happy with the join, abort
                }
 
-               Ptr = new Channel(cname, TS);
+               chan = new Channel(cname, ServerInstance->Time());
+               // Set the default modes on the channel (<options:defaultmodes>)
+               chan->SetDefaultModes();
        }
        else
        {
                /* Already on the channel */
-               if (Ptr->HasUser(user))
+               if (chan->HasUser(user))
                        return NULL;
 
-               /*
-                * remote users are allowed us to bypass channel modes
-                * and bans (used by servers)
-                */
-               if (IS_LOCAL(user) && override == false)
+               if (override == false)
                {
                        ModResult MOD_RESULT;
-                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (IS_LOCAL(user), Ptr, cname, privs, key));
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, chan, cname, privs, key));
+
+                       // A module explicitly denied the join and (hopefully) generated a message
+                       // describing the situation, so we may stop here without sending anything
                        if (MOD_RESULT == MOD_RES_DENY)
-                       {
                                return NULL;
-                       }
-                       else if (MOD_RESULT == MOD_RES_PASSTHRU)
+
+                       // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case
+                       // most of the time) then proceed to check channel modes +k, +i, +l and bans,
+                       // in this order.
+                       // If a module explicitly allowed the join (by returning MOD_RES_ALLOW),
+                       // then this entire section is skipped
+                       if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
-                               std::string ckey = Ptr->GetModeParameter('k');
-                               bool invited = IS_LOCAL(user)->IsInvited(Ptr);
+                               std::string ckey = chan->GetModeParameter('k');
+                               bool invited = user->IsInvited(chan);
                                bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
 
                                if (!ckey.empty())
                                {
-                                       FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, Ptr, key));
+                                       FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
                                        if (!MOD_RESULT.check((ckey == key) || can_bypass))
                                        {
                                                // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
-                                               user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               if (Ptr->IsModeSet('i'))
+                               if (chan->IsModeSet('i'))
                                {
-                                       FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, Ptr));
+                                       FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
                                        if (!MOD_RESULT.check(invited))
                                        {
-                                               user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               std::string limit = Ptr->GetModeParameter('l');
+                               std::string limit = chan->GetModeParameter('l');
                                if (!limit.empty())
                                {
-                                       FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, Ptr));
-                                       if (!MOD_RESULT.check((Ptr->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
+                                       FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
+                                       if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
                                        {
-                                               user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
+                                               user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), chan->name.c_str());
                                                return NULL;
                                        }
                                }
 
-                               if (Ptr->IsBanned(user) && !can_bypass)
+                               if (chan->IsBanned(user) && !can_bypass)
                                {
-                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str());
+                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), chan->name.c_str());
                                        return NULL;
                                }
 
@@ -366,67 +364,78 @@ Channel* Channel::JoinUser(User* user, std::string cname, bool override, const s
                                 */
                                if (invited)
                                {
-                                       IS_LOCAL(user)->RemoveInvite(Ptr);
+                                       user->RemoveInvite(chan);
                                }
                        }
                }
        }
 
-       if (created_by_local)
-       {
-               /* As spotted by jilles, dont bother to set this on remote users */
-               Ptr->SetDefaultModes();
-       }
-
-       return Channel::ForceChan(Ptr, user, privs, bursting, created_by_local);
+       // We figured that this join is allowed and also created the
+       // channel if it didn't exist before, now do the actual join
+       chan->ForceJoin(user, &privs, false, created_by_local);
+       return chan;
 }
 
-Channel* Channel::ForceChan(Channel* Ptr, User* user, const std::string &privs, bool bursting, bool created)
+void Channel::ForceJoin(User* user, const std::string* privs, bool bursting, bool created_by_local)
 {
-       std::string nick = user->nick;
+       Membership* memb = this->AddUser(user);
+       if (!memb)
+               return; // Already on the channel
 
-       Membership* memb = Ptr->AddUser(user);
-       user->chans.insert(Ptr);
+       if (IS_SERVER(user))
+       {
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join server user " + user->uuid + " to channel " + this->name);
+               return;
+       }
+
+       user->chans.insert(this);
 
-       for (std::string::const_iterator x = privs.begin(); x != privs.end(); x++)
+       if (privs)
        {
-               const char status = *x;
-               ModeHandler* mh = ServerInstance->Modes->FindMode(status, MODETYPE_CHANNEL);
-               if (mh)
+               // If the user was granted prefix modes (in the OnUserPreJoin hook, or he's a
+               // remote user and his own server set the modes), then set them internally now
+               memb->modes = *privs;
+               for (std::string::const_iterator i = privs->begin(); i != privs->end(); ++i)
                {
-                       /* Set, and make sure that the mode handler knows this mode was now set */
-                       Ptr->SetPrefix(user, mh->GetModeChar(), true);
-                       mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, Ptr, nick, true);
+                       ModeHandler* mh = ServerInstance->Modes->FindMode(*i, MODETYPE_CHANNEL);
+                       if (mh)
+                       {
+                               std::string nick = user->nick;
+                               /* Set, and make sure that the mode handler knows this mode was now set */
+                               this->SetPrefix(user, mh->GetModeChar(), true);
+                               mh->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, nick, true);
+                       }
                }
        }
 
+       // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
        CUList except_list;
-       FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created, except_list));
+       FOREACH_MOD(I_OnUserJoin,OnUserJoin(memb, bursting, created_by_local, except_list));
 
-       Ptr->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", Ptr->name.c_str());
+       this->WriteAllExcept(user, false, 0, except_list, "JOIN :%s", this->name.c_str());
 
        /* Theyre not the first ones in here, make sure everyone else sees the modes we gave the user */
-       if ((Ptr->GetUserCounter() > 1) && (!memb->modes.empty()))
+       if ((GetUserCounter() > 1) && (!memb->modes.empty()))
        {
                std::string ms = memb->modes;
                for(unsigned int i=0; i < memb->modes.length(); i++)
                        ms.append(" ").append(user->nick);
 
                except_list.insert(user);
-               Ptr->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", Ptr->name.c_str(), ms.c_str());
+               this->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", this->name.c_str(), ms.c_str());
        }
 
        if (IS_LOCAL(user))
        {
-               if (Ptr->topicset)
+               if (this->topicset)
                {
-                       user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), Ptr->name.c_str(), Ptr->topic.c_str());
-                       user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), Ptr->name.c_str(), Ptr->setby.c_str(), (unsigned long)Ptr->topicset);
+                       user->WriteNumeric(RPL_TOPIC, "%s %s :%s", user->nick.c_str(), this->name.c_str(), this->topic.c_str());
+                       user->WriteNumeric(RPL_TOPICTIME, "%s %s %s %lu", user->nick.c_str(), this->name.c_str(), this->setby.c_str(), (unsigned long)this->topicset);
                }
-               Ptr->UserList(user);
+               this->UserList(user);
        }
+
        FOREACH_MOD(I_OnPostJoin,OnPostJoin(memb));
-       return Ptr;
 }
 
 bool Channel::IsBanned(User* user)
index 9babdb6855f665aafd0273ca1f2e812ea5ad7856..da2ec1b4576fbf4654b474ab88256f7245fadfac 100644 (file)
  * the same way, however, they can be fully unloaded, where these
  * may not.
  */
-class CommandJoin : public Command
+class CommandJoin : public SplitCommand
 {
  public:
        /** Constructor for join.
         */
-       CommandJoin ( Module* parent) : Command(parent,"JOIN", 1, 2) { syntax = "<channel>{,<channel>} {<key>{,<key>}}"; Penalty = 2; }
+       CommandJoin(Module* parent)
+               : SplitCommand(parent, "JOIN", 1, 2)
+       {
+               syntax = "<channel>{,<channel>} {<key>{,<key>}}";
+               Penalty = 2;
+       }
+
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user);
 };
 
 /** Handle /JOIN
  */
-CmdResult CommandJoin::Handle (const std::vector<std::string>& parameters, User *user)
+CmdResult CommandJoin::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
 {
        if (parameters.size() > 1)
        {
                if (ServerInstance->Parser->LoopCall(user, this, parameters, 0, 1, false))
                        return CMD_SUCCESS;
 
-               if (ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (ServerInstance->IsChannel(parameters[0], ServerInstance->Config->Limits.ChanMax))
                {
-                       Channel::JoinUser(user, parameters[0], false, parameters[1].c_str(), false);
+                       Channel::JoinUser(user, parameters[0], false, parameters[1]);
                        return CMD_SUCCESS;
                }
        }
@@ -60,9 +66,9 @@ CmdResult CommandJoin::Handle (const std::vector<std::string>& parameters, User
                if (ServerInstance->Parser->LoopCall(user, this, parameters, 0, -1, false))
                        return CMD_SUCCESS;
 
-               if (ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (ServerInstance->IsChannel(parameters[0], ServerInstance->Config->Limits.ChanMax))
                {
-                       Channel::JoinUser(user, parameters[0], false, "", false);
+                       Channel::JoinUser(user, parameters[0]);
                        return CMD_SUCCESS;
                }
        }
index 2bb1357db4f64daa0b22917c703363244f9b36a7..95321bc03de41dae3207824f523baa516364e9fc 100644 (file)
@@ -327,7 +327,7 @@ class ModuleBanRedirect : public Module
                                                        user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str());
                                                        user->WriteNumeric(470, "%s %s %s :You are banned from this channel, so you are automatically transfered to the redirected channel.", user->nick.c_str(), chan->name.c_str(), redir->targetchan.c_str());
                                                        nofollow = true;
-                                                       Channel::JoinUser(user, redir->targetchan, false, "", false, ServerInstance->Time());
+                                                       Channel::JoinUser(user, redir->targetchan);
                                                        nofollow = false;
                                                        return MOD_RES_DENY;
                                                }
index 7ba2b0c7d992ce636092f87dd3fdbf9ef149db98..113e49dffa48b0172830dbab53a340ba8c9baf57 100644 (file)
@@ -45,19 +45,20 @@ class ModuleConnJoin : public Module
 
                void OnPostConnect(User* user)
                {
-                       if (!IS_LOCAL(user))
+                       LocalUser* localuser = IS_LOCAL(user);
+                       if (!localuser)
                                return;
 
                        std::string chanlist = ServerInstance->Config->ConfValue("autojoin")->getString("channel");
-                       chanlist = user->GetClass()->config->getString("autojoin", chanlist);
+                       chanlist = localuser->GetClass()->config->getString("autojoin", chanlist);
 
                        irc::commasepstream chans(chanlist);
                        std::string chan;
 
                        while (chans.GetToken(chan))
                        {
-                               if (ServerInstance->IsChannel(chan.c_str(), ServerInstance->Config->Limits.ChanMax))
-                                       Channel::JoinUser(user, chan, false, "", false, ServerInstance->Time());
+                               if (ServerInstance->IsChannel(chan, ServerInstance->Config->Limits.ChanMax))
+                                       Channel::JoinUser(localuser, chan);
                        }
                }
 };
index b23bf5b92764a0e0654c6142ce3c602564505384..bd09f5ae6214d34570e95d3069d03bc10353da8d 100644 (file)
 
 /** Handle /CYCLE
  */
-class CommandCycle : public Command
+class CommandCycle : public SplitCommand
 {
  public:
-       CommandCycle(Module* Creator) : Command(Creator,"CYCLE", 1)
+       CommandCycle(Module* Creator)
+               : SplitCommand(Creator, "CYCLE", 1)
        {
                Penalty = 3; syntax = "<channel> :[reason]";
                TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const std::vector<std::string> &parameters, User *user)
+       CmdResult HandleLocal(const std::vector<std::string> &parameters, LocalUser* user)
        {
                Channel* channel = ServerInstance->FindChan(parameters[0]);
                std::string reason = ConvToStr("Cycling");
@@ -65,8 +66,7 @@ class CommandCycle : public Command
                                }
 
                                channel->PartUser(user, reason);
-
-                               Channel::JoinUser(user, parameters[0], true, "", false, ServerInstance->Time());
+                               Channel::JoinUser(user, parameters[0], true);
                        }
 
                        return CMD_SUCCESS;
index 47db28978ae0c182d6da39184c1d2aaedfe4a945..b97c74f9b0bc4e7d49dcb3f6fc35c181524c51fc 100644 (file)
@@ -45,7 +45,7 @@ class ModuleDenyChannels : public Module
                        if (!redirect.empty())
                        {
 
-                               if (!ServerInstance->IsChannel(redirect.c_str(), ServerInstance->Config->Limits.ChanMax))
+                               if (!ServerInstance->IsChannel(redirect, ServerInstance->Config->Limits.ChanMax))
                                {
                                        if (user)
                                                user->WriteServ("NOTICE %s :Invalid badchan redirect '%s'", user->nick.c_str(), redirect.c_str());
@@ -115,7 +115,7 @@ class ModuleDenyChannels : public Module
                                                if ((!newchan) || (!(newchan->IsModeSet('L'))))
                                                {
                                                        user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str());
-                                                       Channel::JoinUser(user, redirect, false, "", false, ServerInstance->Time());
+                                                       Channel::JoinUser(user, redirect);
                                                        return MOD_RES_DENY;
                                                }
                                        }
index 5ac67a649d1bccb5c18a9bfca4b17ae215fa1f5d..3c9e84f3d38b96f1ed26ce9ce7bd0c1c9e2d7269 100644 (file)
@@ -45,28 +45,30 @@ bool op;
 
 /** Handle /OJOIN
  */
-class CommandOjoin : public Command
+class CommandOjoin : public SplitCommand
 {
  public:
        bool active;
-       CommandOjoin(Module* parent) : Command(parent,"OJOIN", 1)
+       CommandOjoin(Module* parent) :
+               SplitCommand(parent, "OJOIN", 1)
        {
                flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
                active = false;
                TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
+       CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
        {
                // Make sure the channel name is allowable.
-               if (!ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
+               if (!ServerInstance->IsChannel(parameters[0], ServerInstance->Config->Limits.ChanMax))
                {
                        user->WriteServ("NOTICE "+user->nick+" :*** Invalid characters in channel name or name too long");
                        return CMD_FAILURE;
                }
 
                active = true;
-               Channel* channel = Channel::JoinUser(user, parameters[0].c_str(), false, "", false);
+               // override is false because we want OnUserPreJoin to run
+               Channel* channel = Channel::JoinUser(user, parameters[0], false);
                active = false;
 
                if (channel)
index 2f5dda0ff4a55425d690c028ac979e5a26a3091a..864515e0c9aab36ac43af78390bb8b1e053be4f7 100644 (file)
@@ -78,23 +78,24 @@ class ModuleOperjoin : public Module
 
                virtual void OnPostOper(User* user, const std::string &opertype, const std::string &opername)
                {
-                       if (!IS_LOCAL(user))
+                       LocalUser* localuser = IS_LOCAL(user);
+                       if (!localuser)
                                return;
 
-                       for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
-                               if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
-                                       Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
+                       for (std::vector<std::string>::const_iterator i = operChans.begin(); i != operChans.end(); ++i)
+                               if (ServerInstance->IsChannel(*i, ServerInstance->Config->Limits.ChanMax))
+                                       Channel::JoinUser(localuser, *i, override);
 
-                       std::string chanList = user->oper->getConfig("autojoin");
+                       std::string chanList = localuser->oper->getConfig("autojoin");
                        if (!chanList.empty())
                        {
                                std::vector<std::string> typechans;
                                tokenize(chanList, typechans);
                                for (std::vector<std::string>::const_iterator it = typechans.begin(); it != typechans.end(); ++it)
                                {
-                                       if (ServerInstance->IsChannel(it->c_str(), ServerInstance->Config->Limits.ChanMax))
+                                       if (ServerInstance->IsChannel(*it, ServerInstance->Config->Limits.ChanMax))
                                        {
-                                               Channel::JoinUser(user, it->c_str(), override, "", false, ServerInstance->Time());
+                                               Channel::JoinUser(localuser, *it, override);
                                        }
                                }
                        }
index 72a3649d0b55ba7eeb720f88ac57106c9a9315ef..a045af8f83b1a5e723f5058e57c96026eb28c10b 100644 (file)
@@ -39,7 +39,7 @@ class Redirect : public ModeHandler
                {
                        if (IS_LOCAL(source))
                        {
-                               if (!ServerInstance->IsChannel(parameter.c_str(), ServerInstance->Config->Limits.ChanMax))
+                               if (!ServerInstance->IsChannel(parameter, ServerInstance->Config->Limits.ChanMax))
                                {
                                        source->WriteNumeric(403, "%s %s :Invalid channel name", source->nick.c_str(), parameter.c_str());
                                        parameter.clear();
@@ -142,8 +142,7 @@ class ModuleRedirect : public Module
                                        std::string channel = chan->GetModeParameter('L');
 
                                        /* sometimes broken ulines can make circular or chained +L, avoid this */
-                                       Channel* destchan = NULL;
-                                       destchan = ServerInstance->FindChan(channel);
+                                       Channel* destchan = ServerInstance->FindChan(channel);
                                        if (destchan && destchan->IsModeSet('L'))
                                        {
                                                user->WriteNumeric(470, "%s %s * :You may not join this channel. A redirect is set, but you may not be redirected as it is a circular loop.", user->nick.c_str(), cname.c_str());
@@ -159,7 +158,7 @@ class ModuleRedirect : public Module
                                        else
                                        {
                                                user->WriteNumeric(470, "%s %s %s :You may not join this channel, so you are automatically being transferred to the redirect channel.", user->nick.c_str(), cname.c_str(), channel.c_str());
-                                               Channel::JoinUser(user, channel, false, "", false, ServerInstance->Time());
+                                               Channel::JoinUser(user, channel);
                                                return MOD_RES_DENY;
                                        }
                                }
index 2d6bb0f97e5ad9b787b00949abaf32185a28cdd9..7c3d3512ad639eab79cbb56fdfd82952769ae428 100644 (file)
@@ -52,15 +52,14 @@ class CommandSajoin : public Command
                                return CMD_FAILURE;
                        }
 
-                       /* For local users, we send the JoinUser which may create a channel and set its TS.
+                       /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
                         * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
-                        * and then that server will generate the users JOIN or FJOIN instead.
+                        * and then that server will handle the command.
                         */
-                       if (IS_LOCAL(dest))
+                       LocalUser* localuser = IS_LOCAL(dest);
+                       if (localuser)
                        {
-                               Channel::JoinUser(dest, parameters[1], true, "", false, ServerInstance->Time());
-                               /* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propagate */
-                               Channel* n = ServerInstance->FindChan(parameters[1]);
+                               Channel* n = Channel::JoinUser(localuser, parameters[1], true);
                                if (n)
                                {
                                        if (n->HasUser(dest))
index be13f53181b2eb417d2a32c2f16a71b0f19bc8f6..5e58a164f2850a3678a8d5bf2bc94edbf156b82a 100644 (file)
@@ -192,7 +192,7 @@ bool CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeSocket* src_
                }
        }
 
-       Channel::JoinUser(who, chan->name, true, "", route_back_again->bursting, chan->age);
+       chan->ForceJoin(who, NULL, route_back_again->bursting);
        return true;
 }
 
index a1796740df5da821c193059011e371320e7dc41c..6b1d2835cbb1e88b6f69486415791e0d34217bd3 100644 (file)
@@ -34,8 +34,9 @@ CmdResult CommandSVSJoin::Handle(const std::vector<std::string>& parameters, Use
                return CMD_FAILURE;
 
        /* only join if it's local, otherwise just pass it on! */
-       if (IS_LOCAL(u))
-               Channel::JoinUser(u, parameters[1], false, "", false, ServerInstance->Time());
+       LocalUser* localuser = IS_LOCAL(u);
+       if (localuser)
+               Channel::JoinUser(localuser, parameters[1]);
        return CMD_SUCCESS;
 }