Remove SetMode functions by letter, add IsModeSet query by name

This commit is contained in:
Daniel De Graaf 2010-02-16 13:38:54 -06:00
parent 9b67d1df2e
commit 62dba349a0
4 changed files with 15 additions and 23 deletions

View File

@ -97,7 +97,6 @@ class CoreExport Channel : public Extensible
* @param mode_on True if you want to set the mode or false if you want to remove it
*/
void SetMode(ModeHandler* mode, bool value);
void SetMode(char mode,bool mode_on);
/** Sets or unsets a custom mode in the channels info
* @param mode The mode character to set or unset
@ -105,7 +104,6 @@ class CoreExport Channel : public Extensible
* If it is empty, the mode is unset; if it is nonempty, the mode is set.
*/
void SetModeParam(ModeHandler* mode, const std::string& parameter);
void SetModeParam(char mode, const std::string& parameter);
/** Returns true if a mode is set on a channel
* @param mode The mode character you wish to query
@ -113,7 +111,7 @@ class CoreExport Channel : public Extensible
*/
inline bool IsModeSet(ModeHandler* mode) { return modebits[mode->id.GetID()]; }
bool IsModeSet(char mode);
bool IsModeSet(const std::string& mode);
/** Returns the parameter for a custom mode on a channel.
* @param mode The mode character you wish to query

View File

@ -29,13 +29,6 @@ Channel::Channel(const std::string &cname, time_t ts)
modebits.reset();
}
void Channel::SetMode(char mode, bool on)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(mode, MODETYPE_CHANNEL);
if (mh)
modebits[mh->id.GetID()] = on;
}
bool Channel::IsModeSet(char mode)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(mode, MODETYPE_CHANNEL);
@ -44,6 +37,14 @@ bool Channel::IsModeSet(char mode)
return modebits[mh->id.GetID()];
}
bool Channel::IsModeSet(const std::string& mode)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(mode);
if (!mh)
return false;
return modebits[mh->id.GetID()];
}
void Channel::SetMode(ModeHandler* mh, bool on)
{
modebits[mh->id.GetID()] = on;
@ -60,13 +61,6 @@ void Channel::SetModeParam(ModeHandler* mode, const std::string& parameter)
custom_mode_params[mode->id] = parameter;
}
void Channel::SetModeParam(char mode, const std::string& parameter)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(mode, MODETYPE_CHANNEL);
if (mh)
SetModeParam(mh, parameter);
}
std::string Channel::GetModeParameter(char mode)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(mode, MODETYPE_CHANNEL);

View File

@ -23,18 +23,18 @@ ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, M
ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
{
bool exists = channel->IsModeSet('k');
bool exists = channel->IsModeSet(this);
if (IS_LOCAL(source))
{
if (exists == adding)
return MODEACTION_DENY;
if (exists && (parameter != channel->GetModeParameter('k')))
if (exists && (parameter != channel->GetModeParameter(this)))
{
/* Key is currently set and the correct key wasnt given */
return MODEACTION_DENY;
}
} else {
if (exists && adding && parameter == channel->GetModeParameter('k'))
if (exists && adding && parameter == channel->GetModeParameter(this))
{
/* no-op, don't show */
return MODEACTION_DENY;
@ -53,11 +53,11 @@ ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, s
std::string ckey;
ckey.assign(parameter, 0, 32);
parameter = ckey;
channel->SetModeParam('k', parameter);
channel->SetModeParam(this, parameter);
}
else
{
channel->SetModeParam('k', "");
channel->SetModeParam(this, "");
}
return MODEACTION_ALLOW;
}

View File

@ -297,7 +297,7 @@ class ModuleBanRedirect : public Module
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())))
if(destchan && destchan->IsModeSet("redirect") && !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 MOD_RES_DENY;