*/
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;
this->created = ts ? ts : ServerInstance->Time();
this->age = this->created;
-
- maxbans = topicset = limit = 0;
+ maxbans = topicset = 0;
modes.reset();
}
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()
}
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;
}
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))
}
Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
-{
+{
std::string nick = user->nick;
bool silent = false;
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:
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)
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);
}
}
{
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;
/* 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;
}
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
{
/* 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;
parameter = ConvToStr(limit);
/* Set new limit */
- channel->limit = limit;
+ channel->SetModeParam('l', parameter.c_str(), true);
channel->modes[CM_LIMIT] = 1;
return MODEACTION_ALLOW;
/* 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;
{
/* 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;
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")
{
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")
{
{
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');