]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Get rid of irc::sockets::satoap().
[user/henk/code/inspircd.git] / src / channels.cpp
index f79b5b89f56c37e221e7aee01f24862d64f660cb..bc23c680a07b309a83de482bc29ef7c1ed18dd93 100644 (file)
@@ -46,12 +46,20 @@ void Channel::SetMode(ModeHandler* mh, bool on)
        modes[mh->GetId()] = on;
 }
 
-void Channel::SetTopic(User* u, const std::string& ntopic)
+void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const std::string* setter)
 {
-       this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic);
-       this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128);
-       this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
-       this->topicset = ServerInstance->Time();
+       // Send a TOPIC message to the channel only if the new topic text differs
+       if (this->topic != ntopic)
+       {
+               this->topic = ntopic;
+               this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str());
+       }
+
+       // Always update setter and set time
+       if (!setter)
+               setter = ServerInstance->Config->FullHostInTopic ? &u->GetFullHost() : &u->nick;
+       this->setby.assign(*setter, 0, ServerInstance->Config->Limits.GetMaxMask());
+       this->topicset = topicts;
 
        FOREACH_MOD(OnPostTopicChange, (u, this, this->topic));
 }
@@ -90,7 +98,6 @@ void Channel::CheckDestroy()
 
        FOREACH_MOD(OnChannelDelete, (this));
        ServerInstance->chanlist.erase(iter);
-       ClearInvites();
        ServerInstance->GlobalCulls.AddItem(this);
 }
 
@@ -131,7 +138,7 @@ void Channel::SetDefaultModes()
                        if (mode->IsPrefixMode())
                                continue;
 
-                       if (mode->GetNumParams(true))
+                       if (mode->NeedsParam(true))
                        {
                                list.GetToken(parameter);
                                // If the parameter begins with a ':' then it's invalid
@@ -141,7 +148,7 @@ void Channel::SetDefaultModes()
                        else
                                parameter.clear();
 
-                       if ((mode->GetNumParams(true)) && (parameter.empty()))
+                       if ((mode->NeedsParam(true)) && (parameter.empty()))
                                continue;
 
                        mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
@@ -174,14 +181,14 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                {
                        unsigned int opermaxchans = ConvToInt(user->oper->getConfig("maxchans"));
                        // If not set, use 2.0's <channels:opers>, if that's not set either, use limit from CC
-                       if (!opermaxchans)
+                       if (!opermaxchans && user->HasPrivPermission("channels/high-join-limit"))
                                opermaxchans = ServerInstance->Config->OperMaxChans;
                        if (opermaxchans)
                                maxchans = opermaxchans;
                }
                if (user->chans.size() >= maxchans)
                {
-                       user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s :You are on too many channels", cname.c_str());
+                       user->WriteNumeric(ERR_TOOMANYCHANNELS, cname, "You are on too many channels");
                        return NULL;
                }
        }
@@ -235,16 +242,13 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                        if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
                                std::string ckey = chan->GetModeParameter(keymode);
-                               bool invited = user->IsInvited(chan);
-                               bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
-
                                if (!ckey.empty())
                                {
                                        FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
-                                       if (!MOD_RESULT.check((ckey == key) || can_bypass))
+                                       if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key)))
                                        {
                                                // 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 :Cannot join channel (Incorrect channel key)", chan->name.c_str());
+                                               user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)");
                                                return NULL;
                                        }
                                }
@@ -252,9 +256,9 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                                if (chan->IsModeSet(inviteonlymode))
                                {
                                        FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
-                                       if (!MOD_RESULT.check(invited))
+                                       if (MOD_RESULT != MOD_RES_ALLOW)
                                        {
-                                               user->WriteNumeric(ERR_INVITEONLYCHAN, "%s :Cannot join channel (Invite only)", chan->name.c_str());
+                                               user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)");
                                                return NULL;
                                        }
                                }
@@ -263,27 +267,18 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
                                if (!limit.empty())
                                {
                                        FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
-                                       if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
+                                       if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()))))
                                        {
-                                               user->WriteNumeric(ERR_CHANNELISFULL, "%s :Cannot join channel (Channel is full)", chan->name.c_str());
+                                               user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)");
                                                return NULL;
                                        }
                                }
 
-                               if (chan->IsBanned(user) && !can_bypass)
+                               if (chan->IsBanned(user))
                                {
-                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s :Cannot join channel (You're banned)", chan->name.c_str());
+                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You're banned)");
                                        return NULL;
                                }
-
-                               /*
-                                * If the user has invites for this channel, remove them now
-                                * after a successful join so they don't build up.
-                                */
-                               if (invited)
-                               {
-                                       user->RemoveInvite(chan);
-                               }
                        }
                }
        }
@@ -418,23 +413,25 @@ ModResult Channel::GetExtBanStatus(User *user, char type)
  * Remove a channel from a users record, remove the reference to the Membership object
  * from the channel and destroy it.
  */
-void Channel::PartUser(User *user, std::string &reason)
+bool Channel::PartUser(User* user, std::string& reason)
 {
        MemberMap::iterator membiter = userlist.find(user);
 
-       if (membiter != userlist.end())
-       {
-               Membership* memb = membiter->second;
-               CUList except_list;
-               FOREACH_MOD(OnUserPart, (memb, reason, except_list));
+       if (membiter == userlist.end())
+               return false;
 
-               WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
+       Membership* memb = membiter->second;
+       CUList except_list;
+       FOREACH_MOD(OnUserPart, (memb, reason, except_list));
 
-               // Remove this channel from the user's chanlist
-               user->chans.erase(memb);
-               // Remove the Membership from this channel's userlist and destroy it
-               this->DelUser(membiter);
-       }
+       WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str());
+
+       // Remove this channel from the user's chanlist
+       user->chans.erase(memb);
+       // Remove the Membership from this channel's userlist and destroy it
+       this->DelUser(membiter);
+
+       return true;
 }
 
 void Channel::KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason)
@@ -573,6 +570,13 @@ const char* Channel::ChanModes(bool showkey)
        return scratch.c_str();
 }
 
+void Channel::WriteNotice(const std::string& text)
+{
+       std::string rawmsg = "NOTICE ";
+       rawmsg.append(this->name).append(" :").append(text);
+       WriteChannelWithServ(ServerInstance->Config->ServerName, rawmsg);
+}
+
 /* returns the status character for a given user on a channel, e.g. @ for op,
  * % for halfop etc. If the user has several modes set, the highest mode
  * the user has must be returned.
@@ -607,20 +611,17 @@ unsigned int Membership::getRank()
        return rv;
 }
 
-const char* Membership::GetAllPrefixChars() const
+std::string Membership::GetAllPrefixChars() const
 {
-       static char prefix[64];
-       int ctr = 0;
-
+       std::string ret;
        for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
                PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
                if (mh && mh->GetPrefix())
-                       prefix[ctr++] = mh->GetPrefix();
+                       ret.push_back(mh->GetPrefix());
        }
-       prefix[ctr] = 0;
 
-       return prefix;
+       return ret;
 }
 
 unsigned int Channel::GetPrefixValue(User* user)
@@ -650,68 +651,3 @@ bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding)
                modes.push_back(prefix);
        return adding;
 }
-
-void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
-{
-       if ((timeout != 0) && (ServerInstance->Time() >= timeout))
-               // Expired, don't bother
-               return;
-
-       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str());
-
-       Invitation* inv = Invitation::Find(c, u, false);
-       if (inv)
-       {
-                if ((inv->expiry == 0) || (inv->expiry > timeout))
-                       return;
-               inv->expiry = timeout;
-               ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv);
-       }
-       else
-       {
-               inv = new Invitation(c, u, timeout);
-               c->invites.push_front(inv);
-               u->invites.push_front(inv);
-               ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
-       }
-}
-
-Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
-{
-       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired);
-
-       Invitation* result = NULL;
-       for (InviteList::iterator i = u->invites.begin(); i != u->invites.end(); )
-       {
-               Invitation* inv = *i;
-               ++i;
-
-               if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time()))
-               {
-                       /* Expired invite, remove it. */
-                       std::string expiration = InspIRCd::TimeString(inv->expiry);
-                       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
-                       delete inv;
-               }
-               else
-               {
-                       /* Is it what we're searching for? */
-                       if (inv->chan == c)
-                       {
-                               result = inv;
-                               break;
-                       }
-               }
-       }
-
-       ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result);
-       return result;
-}
-
-Invitation::~Invitation()
-{
-       // Remove this entry from both lists
-       chan->invites.erase(this);
-       user->invites.erase(this);
-       ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "Invitation::~ %p", (void*) this);
-}