From: w00t Date: Sun, 20 Jul 2008 14:30:00 +0000 (+0000) Subject: Remove custom members for +lk storage X-Git-Tag: v2.0.23~2890 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=4c286655e1b930908fd02681ac00e172156e737c;p=user%2Fhenk%2Fcode%2Finspircd.git Remove custom members for +lk storage git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10053 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/include/channels.h b/include/channels.h index 2042df220..c27329310 100644 --- a/include/channels.h +++ b/include/channels.h @@ -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; diff --git a/src/channels.cpp b/src/channels.cpp index 8628148cf..7f843eeeb 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -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 : ""); - 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 = ""; + } + break; case CM_NOEXTERNAL: case CM_TOPICLOCK: case CM_INVITEONLY: diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp index 4d4453d44..8e7692efc 100644 --- a/src/modes/cmode_k.cpp +++ b/src/modes/cmode_k.cpp @@ -23,14 +23,15 @@ ModeChannelKey::ModeChannelKey(InspIRCd* Instance) : ModeHandler(Instance, 'k', ModePair ModeChannelKey::ModeSet(User*, User*, Channel* channel, const std::string ¶meter) { - 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 parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->key); + std::vector 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; } diff --git a/src/modes/cmode_l.cpp b/src/modes/cmode_l.cpp index 4ed95bc2c..8d6a962fb 100644 --- a/src/modes/cmode_l.cpp +++ b/src/modes/cmode_l.cpp @@ -23,9 +23,10 @@ ModeChannelLimit::ModeChannelLimit(InspIRCd* Instance) : ModeHandler(Instance, ' ModePair ModeChannelLimit::ModeSet(User*, User*, Channel* channel, const std::string ¶meter) { - 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; diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 5965811c4..ffb263ff7 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -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; diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index 15cf2ae55..dc9e9ab37 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -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") { diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index 8b088af8e..c81ab2a70 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -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');