]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Remove custom members for +lk storage
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 20 Jul 2008 14:30:00 +0000 (14:30 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Sun, 20 Jul 2008 14:30:00 +0000 (14:30 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10053 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
src/channels.cpp
src/modes/cmode_k.cpp
src/modes/cmode_l.cpp
src/modules/m_banredirect.cpp
src/modules/m_override.cpp
src/modules/m_redirect.cpp

index 2042df2209d31f51f72b9b839c02b5d5b6c84639..c273293102a1667006371f52afa6239295c4e3d8 100644 (file)
@@ -197,16 +197,6 @@ class CoreExport Channel : public Extensible
         */
        std::string setby; /* 128 */
 
-       /** Contains the channel user limit.
-        * If this value is zero, there is no limit in place.
-        */
-       short int limit;
-       
-       /** Contains the channel key.
-        * If this value is an empty string, there is no channel key in place.
-        */
-       std::string key; /* 32 */
-
        /** The list of all bans set on the channel.
         */
        BanList bans;
index 8628148cf7d3d89ebf0ded664c1194b13e519f3a..7f843eeebf2845b343b8dc4245bb96cb34d6cdf9 100644 (file)
@@ -29,8 +29,7 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : Serv
        this->created = ts ? ts : ServerInstance->Time();
        this->age = this->created;
 
-
-       maxbans = topicset = limit = 0;
+       maxbans = topicset = 0;
        modes.reset();
 }
 
@@ -68,19 +67,10 @@ bool Channel::IsModeSet(char mode)
 
 std::string Channel::GetModeParameter(char mode)
 {
-       switch (mode)
-       {
-               case 'k':
-                       return this->key;
-               case 'l':
-                       return ConvToStr(this->limit);
-               default:
-                       CustomModeList::iterator n = custom_mode_params.find(mode);
-                       if (n != custom_mode_params.end())
-                               return n->second;
-                       return "";
-               break;
-       }
+       CustomModeList::iterator n = custom_mode_params.find(mode);
+       if (n != custom_mode_params.end())
+               return n->second;
+       return "";
 }
 
 long Channel::GetUserCounter()
@@ -302,13 +292,14 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                        }
                        else if (MOD_RESULT == 0)
                        {
-                               if (!Ptr->key.empty())
+                               std::string ckey = Ptr->GetModeParameter('k');
+                               if (!ckey.empty())
                                {
                                        MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : ""));
+                                       FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : ""));
                                        if (!MOD_RESULT)
                                        {
-                                               if ((!key) || Ptr->key == key)
+                                               if ((!key) || ckey != key)
                                                {
                                                        user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str());
                                                        return NULL;
@@ -329,19 +320,23 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                        }
                                        user->RemoveInvite(Ptr->name.c_str());
                                }
-                               if (Ptr->limit)
+
+                               std::string limit = Ptr->GetModeParameter('l');
+                               if (!limit.empty())
                                {
                                        MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckLimit,OnCheckLimit(user, Ptr));
+                                       FOREACH_RESULT_I(Instance, I_OnCheckLimit, OnCheckLimit(user, Ptr));
                                        if (!MOD_RESULT)
                                        {
-                                               if (Ptr->GetUserCounter() >= Ptr->limit)
+                                               long llimit = atol(limit.c_str());
+                                               if (Ptr->GetUserCounter() >= llimit)
                                                {
                                                        user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str());
                                                        return NULL;
                                                }
                                        }
                                }
+
                                if (Ptr->bans.size())
                                {
                                        if (Ptr->IsBanned(user))
@@ -362,7 +357,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
 }
 
 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
-{
+{      
        std::string nick = user->nick;
        bool silent = false;
 
@@ -845,11 +840,16 @@ char* Channel::ChanModes(bool showkey)
                        switch (n)
                        {
                                case CM_KEY:
-                                       extparam = (showkey ? this->key : "<key>");
-                               break;
-                               case CM_LIMIT:
-                                       extparam = ConvToStr(this->limit);
-                               break;
+                                       // Unfortunately this must be special-cased, as we definitely don't want to always display key.
+                                       if (showkey)
+                                       {
+                                               extparam = this->GetModeParameter('k');
+                                       }
+                                       else
+                                       {
+                                               extparam = "<key>";
+                                       }
+                                       break;
                                case CM_NOEXTERNAL:
                                case CM_TOPICLOCK:
                                case CM_INVITEONLY:
index 4d4453d4497b79161dec6aeaa04dce9269eb9c62..8e7692efccfccc203a77cfe3433aa64a8ade4b10 100644 (file)
@@ -23,14 +23,15 @@ ModeChannelKey::ModeChannelKey(InspIRCd* Instance) : ModeHandler(Instance, 'k',
 
 ModePair ModeChannelKey::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
 {       
-        if (channel->modes[CM_KEY])
-        {
-                return std::make_pair(true, channel->key);
-        }
-        else
-        {
-                return std::make_pair(false, parameter);
-        }
+    if (channel->modes[CM_KEY])
+    {
+               std::string ckey = channel->GetModeParameter('k');
+               return std::make_pair(true, ckey);
+    }
+    else
+    {
+               return std::make_pair(false, parameter);
+    }
 }
 
 void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
@@ -42,10 +43,12 @@ void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
        if (channel->IsModeSet(this->GetModeChar()))
        {
                if (stack)
-                       stack->Push(this->GetModeChar(), channel->key);
+               {
+                       stack->Push(this->GetModeChar(), channel->GetModeParameter('k'));
+               }
                else
                {
-                       std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->key);
+                       std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->GetModeParameter('k'));
                        ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
                }
        }
@@ -65,7 +68,7 @@ ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, s
 {
        if ((channel->IsModeSet('k') != adding) || (!IS_LOCAL(source)))
        {
-               if (((channel->IsModeSet('k')) && (parameter != channel->key)) && (IS_LOCAL(source)))
+               if (((channel->IsModeSet('k')) && (parameter != channel->GetModeParameter('k'))) && (IS_LOCAL(source)))
                {
                        /* Key is currently set and the correct key wasnt given */
                        return MODEACTION_DENY;
@@ -75,18 +78,18 @@ ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, s
                        /* Key isnt currently set */
                        if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos))
                        {
-                               channel->key.assign(parameter, 0, 32);
-                               channel->SetMode('k', adding);
-                               parameter = channel->key;
+                               std::string ckey;
+                               ckey.assign(parameter, 0, 32);
+                               channel->SetMode('k', ckey.c_str());
+                               parameter = ckey;
                                return MODEACTION_ALLOW;
                        }
                        else
                                return MODEACTION_DENY;
                }
-               else if (((channel->IsModeSet('k')) && (parameter == channel->key)) || ((!adding) && (!IS_LOCAL(source))))
+               else if (((channel->IsModeSet('k')) && (parameter == channel->GetModeParameter('k'))) || ((!adding) && (!IS_LOCAL(source))))
                {
                        /* Key is currently set, and correct key was given */
-                       channel->key.clear();
                        channel->SetMode('k', adding);
                        return MODEACTION_ALLOW;
                }
index 4ed95bc2cdb934e6f3333861d5a9a8bda153af3a..8d6a962fb1788160ce42093f8de98efb75b1ab87 100644 (file)
@@ -23,9 +23,10 @@ ModeChannelLimit::ModeChannelLimit(InspIRCd* Instance) : ModeHandler(Instance, '
 
 ModePair ModeChannelLimit::ModeSet(User*, User*, Channel* channel, const std::string &parameter)
 {
-       if (channel->limit)
+       std::string climit = channel->GetModeParameter('l');
+       if (!climit.empty())
        {
-               return std::make_pair(true, ConvToStr(channel->limit));
+               return std::make_pair(true, climit);
        }
        else
        {
@@ -52,7 +53,8 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s
 
                /* If the new limit is the same as the old limit,
                 * and the old limit isnt 0, disallow */
-               if ((limit == channel->limit) && (channel->limit > 0))
+               std::string oldlimit = channel->GetModeParameter('l');
+               if (limit == atoi(oldlimit.c_str()) && oldlimit != "0")
                {
                        parameter = "";
                        return MODEACTION_DENY;
@@ -70,7 +72,7 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s
                parameter = ConvToStr(limit);
 
                /* Set new limit */
-               channel->limit = limit;
+               channel->SetModeParam('l', parameter.c_str(), true);
                channel->modes[CM_LIMIT] = 1;
 
                return MODEACTION_ALLOW;
@@ -80,14 +82,14 @@ ModeAction ModeChannelLimit::OnModeChange(User*, User*, Channel* channel, std::s
                /* Check if theres a limit here to remove.
                 * If there isnt, dont allow the -l
                 */
-               if (!channel->limit)
+               if (channel->GetModeParameter('l').empty())
                {
                        parameter = "";
                        return MODEACTION_DENY;
                }
 
                /* Removing old limit, no checks here */
-               channel->limit = 0;
+               channel->SetModeParam('l', "", false);
                channel->modes[CM_LIMIT] = 0;
 
                return MODEACTION_ALLOW;
index 5965811c446669e6fdeaf666c201561f4a0f390a..ffb263ff7743c14218ddb44e646964686370643e 100644 (file)
@@ -295,8 +295,12 @@ class ModuleBanRedirect : public Module
                                        {
                                                /* tell them they're banned and are being transferred */
                                                Channel* destchan = ServerInstance->FindChan(redir->targetchan);
+                                               std::string destlimit;
 
-                                               if(destchan && ServerInstance->Modules->Find("m_redirect.so") && destchan->IsModeSet('L') && destchan->limit && (destchan->GetUserCounter() >= destchan->limit))
+                                               if (destchan)
+                                                       destlimit = destchan->GetModeParameter('l');
+
+                                               if(destchan && ServerInstance->Modules->Find("m_redirect.so") && destchan->IsModeSet('L') && !destlimit.empty() && (destchan->GetUserCounter() >= atoi(destlimit.c_str())))
                                                {
                                                        user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str());
                                                        return 1;
index 15cf2ae55ed2266a349275a933c5cfbaeceef65f..dc9e9ab374533eb77d812cf38c909068b52163d6 100644 (file)
@@ -253,7 +253,7 @@ class ModuleOverride : public Module
                                        return -1;
                                }
 
-                               if ((!chan->key.empty()) && (CanOverride(user,"KEY")) && keygiven != chan->key)
+                               if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
                                {
                                        if (RequireKey && keygiven != "override")
                                        {
@@ -268,7 +268,7 @@ class ModuleOverride : public Module
                                        return -1;
                                }
 
-                               if ((chan->limit > 0) && (chan->GetUserCounter() >=  chan->limit) && (CanOverride(user,"LIMIT")))
+                               if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >=  atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
                                {
                                        if (RequireKey && keygiven != "override")
                                        {
index 8b088af8ea1631f8e735fadfcb0bf24308e3f92f..c81ab2a706e953c29c2b4539c2cb011f82e2704d 100644 (file)
@@ -116,9 +116,9 @@ class ModuleRedirect : public Module
        {
                if (chan)
                {
-                       if (chan->IsModeSet('L') && chan->limit)
+                       if (chan->IsModeSet('L') && chan->modes[CM_LIMIT])
                        {
-                               if (chan->GetUserCounter() >= chan->limit)
+                               if (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str()))
                                {
                                        std::string channel = chan->GetModeParameter('L');