本文整理汇总了C++中ModeHandler类的典型用法代码示例。如果您正苦于以下问题:C++ ModeHandler类的具体用法?C++ ModeHandler怎么用?C++ ModeHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModeHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ModeParamsToChangeList
void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist, unsigned int beginindex, unsigned int endindex)
{
if (endindex > parameters.size())
endindex = parameters.size();
const std::string& mode_sequence = parameters[beginindex];
bool adding = true;
unsigned int param_at = beginindex+1;
for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
{
unsigned char modechar = *letter;
if (modechar == '+' || modechar == '-')
{
adding = (modechar == '+');
continue;
}
ModeHandler *mh = this->FindMode(modechar, type);
if (!mh)
{
/* No mode handler? Unknown mode character then. */
user->WriteNumeric(type == MODETYPE_CHANNEL ? ERR_UNKNOWNMODE : ERR_UNKNOWNSNOMASK, "%c :is unknown mode char to me", modechar);
continue;
}
std::string parameter;
if (mh->GetNumParams(adding) && param_at < endindex)
parameter = parameters[param_at++];
changelist.push(mh, adding, parameter);
}
}
示例2: list
void Channel::SetDefaultModes()
{
ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
ServerInstance->Config->DefaultModes.c_str());
irc::spacesepstream list(ServerInstance->Config->DefaultModes);
std::string modeseq;
std::string parameter;
list.GetToken(modeseq);
for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
{
ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
if (mode)
{
if (mode->IsPrefixMode())
continue;
if (mode->GetNumParams(true))
list.GetToken(parameter);
else
parameter.clear();
mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
}
}
}
示例3: moderemove
void User::UnOper()
{
if (!IS_OPER(this))
return;
/*
* unset their oper type (what IS_OPER checks).
* note, order is important - this must come before modes as -o attempts
* to call UnOper. -- w00t
*/
oper = NULL;
/* Remove all oper only modes from the user when the deoper - Bug #466*/
std::string moderemove("-");
for (unsigned char letter = 'A'; letter <= 'z'; letter++)
{
ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER);
if (mh && mh->NeedsOper())
moderemove += letter;
}
std::vector<std::string> parameters;
parameters.push_back(this->nick);
parameters.push_back(moderemove);
ServerInstance->Parser->CallHandler("MODE", parameters, this);
/* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */
ServerInstance->Users->all_opers.remove(this);
this->modes[UM_OPERATOR] = 0;
}
示例4: AccessCheck
ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
{
std::string::size_type pos = parameter.find(':');
if (pos == 0 || pos == std::string::npos)
return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
unsigned int mylevel = channel->GetPrefixValue(source);
std::string mid = parameter.substr(0, pos);
ModeHandler* mh = FindMode(mid);
if (adding && (!mh || !mh->GetPrefixRank()))
{
source->WriteNumeric(415, "%s %s :Cannot find prefix mode '%s' for autoop",
source->nick.c_str(), mid.c_str(), mid.c_str());
return MOD_RES_DENY;
}
else if (!mh)
return MOD_RES_PASSTHRU;
std::string dummy;
if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
return MOD_RES_DENY;
if (mh->GetLevelRequired() > mylevel)
{
source->WriteNumeric(482, "%s %s :You must be able to set mode '%s' to include it in an autoop",
source->nick.c_str(), channel->name.c_str(), mid.c_str());
return MOD_RES_DENY;
}
return MOD_RES_PASSTHRU;
}
示例5: FindMode
void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text)
{
if (targetchannel)
{
/* Display channel's current mode string */
user->WriteNumeric(RPL_CHANNELMODEIS, "%s +%s", targetchannel->name.c_str(), targetchannel->ChanModes(targetchannel->HasUser(user)));
user->WriteNumeric(RPL_CHANNELCREATED, "%s %lu", targetchannel->name.c_str(), (unsigned long)targetchannel->age);
return;
}
else
{
if (targetuser == user || user->HasPrivPermission("users/auspex"))
{
/* Display user's current mode string */
user->WriteNumeric(RPL_UMODEIS, ":+%s", targetuser->FormatModes());
if ((targetuser->IsOper()))
{
ModeHandler* snomask = FindMode('s', MODETYPE_USER);
user->WriteNumeric(RPL_SNOMASKIS, "%s :Server notice mask", snomask->GetUserParameter(user).c_str());
}
return;
}
else
{
user->WriteNumeric(ERR_USERSDONTMATCH, ":Can't view modes for other users");
return;
}
}
}
示例6: DisplayListModes
void ModeParser::DisplayListModes(User* user, Channel* chan, std::string &mode_sequence)
{
seq++;
for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
{
unsigned char mletter = *letter;
if (mletter == '+')
continue;
/* Ensure the user doesnt request the same mode twice,
* so they cant flood themselves off out of idiocy.
*/
if (sent[mletter] == seq)
continue;
sent[mletter] = seq;
ModeHandler *mh = this->FindMode(mletter, MODETYPE_CHANNEL);
if (!mh || !mh->IsListMode())
return;
ModResult MOD_RESULT;
FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, mletter, "", true, 0));
if (MOD_RESULT == MOD_RES_DENY)
continue;
bool display = true;
if (!user->HasPrivPermission("channels/auspex") && ServerInstance->Config->HideModeLists[mletter] && (chan->GetPrefixValue(user) < HALFOP_VALUE))
{
user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You do not have access to view the +%c list",
user->nick.c_str(), chan->name.c_str(), mletter);
display = false;
}
// Ask mode watchers whether it's OK to show the list
std::pair<ModeWatchIter, ModeWatchIter> itpair = modewatchermap.equal_range(mh->name);
for (ModeWatchIter i = itpair.first; i != itpair.second; ++i)
{
ModeWatcher* mw = i->second;
if (mw->GetModeType() == MODETYPE_CHANNEL)
{
std::string dummyparam;
if (!mw->BeforeMode(user, NULL, chan, dummyparam, true))
{
// A mode watcher doesn't want us to show the list
display = false;
break;
}
}
}
if (display)
mh->DisplayList(user, chan);
else
mh->DisplayEmptyList(user, chan);
}
}
示例7: OnCheckBan
ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
{
if ((mask.length() > 2) && (mask[0] == 'j') && (mask[1] == ':'))
{
std::string rm = mask.substr(2);
char status = 0;
ModeHandler* mh = ServerInstance->Modes->FindPrefix(rm[0]);
if (mh)
{
rm = mask.substr(3);
status = mh->GetModeChar();
}
for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
{
if (InspIRCd::Match((**i).name, rm))
{
if (status)
{
Membership* memb = (**i).GetUser(user);
if (memb && memb->hasMode(status))
return MOD_RES_DENY;
}
else
return MOD_RES_DENY;
}
}
}
return MOD_RES_PASSTHRU;
}
示例8: FindMode
PrefixMode* ModeParser::FindPrefixMode(unsigned char modeletter)
{
ModeHandler* mh = FindMode(modeletter, MODETYPE_CHANNEL);
if (!mh)
return NULL;
return mh->IsPrefixMode();
}
示例9: DisplayCurrentModes
void CommandMode::DisplayCurrentModes(User* user, User* targetuser, Channel* targetchannel)
{
if (targetchannel)
{
// Display channel's current mode string
user->WriteNumeric(RPL_CHANNELMODEIS, targetchannel->name, (std::string("+") + targetchannel->ChanModes(targetchannel->HasUser(user))));
user->WriteNumeric(RPL_CHANNELCREATED, targetchannel->name, (unsigned long)targetchannel->age);
}
else
{
if (targetuser == user || user->HasPrivPermission("users/auspex"))
{
// Display user's current mode string
// XXX: Use WriteServ() because WriteNumeric() assumes the target (i.e. next word after the number)
// is 'user' and puts his nick there which is not what we want
user->WriteServ("%03d %s :+%s", RPL_UMODEIS, targetuser->nick.c_str(), targetuser->FormatModes());
if (targetuser->IsOper())
{
ModeHandler* snomask = ServerInstance->Modes->FindMode('s', MODETYPE_USER);
std::string snomaskstr = snomask->GetUserParameter(user);
// snomaskstr is empty if the snomask mode isn't set, otherwise it begins with a '+'.
// In the former case output a "+", not an empty string.
user->WriteServ("%03d %s %s%s :Server notice mask", RPL_SNOMASKIS, targetuser->nick.c_str(), (snomaskstr.empty() ? "+" : ""), snomaskstr.c_str());
}
}
else
{
user->WriteNumeric(ERR_USERSDONTMATCH, "Can't view modes for other users");
}
}
}
示例10: DoSaveUsers
void DataKeeper::DoSaveUsers()
{
ModesExts currdata;
const user_hash& users = ServerInstance->Users->GetUsers();
for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i)
{
User* const user = i->second;
// Serialize user modes
for (size_t j = 0; j < handledmodes[MODETYPE_USER].size(); j++)
{
ModeHandler* mh = handledmodes[MODETYPE_USER][j].mh;
if (user->IsModeSet(mh))
currdata.modelist.push_back(InstanceData(j, mh->GetUserParameter(user)));
}
// Serialize all extensions attached to the User
SaveExtensions(user, currdata.extlist);
// Add to list if the user has any modes or extensions set that we are interested in, otherwise we don't
// have to do anything with this user when restoring
if (!currdata.empty())
{
userdatalist.push_back(UserData(user->uuid));
userdatalist.back().swap(currdata);
}
}
}
示例11: SaveMemberData
void DataKeeper::SaveMemberData(Channel* chan, std::vector<OwnedModesExts>& memberdatalist)
{
ModesExts currdata;
const Channel::MemberMap& users = chan->GetUsers();
for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
{
Membership* const memb = i->second;
for (size_t j = 0; j < handledmodes[MODETYPE_CHANNEL].size(); j++)
{
ModeHandler* mh = handledmodes[MODETYPE_CHANNEL][j].mh;
if ((mh->IsPrefixMode()) && (memb->hasMode(mh->GetModeChar())))
currdata.modelist.push_back(InstanceData(j, memb->user->uuid)); // Need to pass the user's uuid to the mode parser to set the mode later
}
SaveExtensions(memb, currdata.extlist);
// Same logic as in DoSaveUsers()
if (!currdata.empty())
{
memberdatalist.push_back(OwnedModesExts(memb->user->uuid));
memberdatalist.back().swap(currdata);
}
}
}
示例12: Call
ModResult Call(User* user, Channel* chan, const std::string& restriction)
{
unsigned int mypfx = chan->GetPrefixValue(user);
std::string minmode;
modelist* list = ec.extItem.get(chan);
if (list)
{
for (modelist::iterator i = list->begin(); i != list->end(); ++i)
{
std::string::size_type pos = (*i).mask.find(':');
if (pos == std::string::npos)
continue;
if ((*i).mask.substr(0,pos) == restriction)
minmode = (*i).mask.substr(pos + 1);
}
}
ModeHandler* mh = FindMode(minmode);
if (mh && mypfx >= mh->GetPrefixRank())
return MOD_RES_ALLOW;
if (mh || minmode == "*")
return MOD_RES_DENY;
return ServerInstance->HandleOnCheckExemption.Call(user, chan, restriction);
}
示例13: list
void Channel::SetDefaultModes()
{
ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
ServerInstance->Config->DefaultModes.c_str());
irc::spacesepstream list(ServerInstance->Config->DefaultModes);
std::string modeseq;
std::string parameter;
list.GetToken(modeseq);
for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
{
ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
if (mode)
{
if (mode->IsPrefixMode())
continue;
if (mode->NeedsParam(true))
{
list.GetToken(parameter);
// If the parameter begins with a ':' then it's invalid
if (parameter.c_str()[0] == ':')
continue;
}
else
parameter.clear();
if ((mode->NeedsParam(true)) && (parameter.empty()))
continue;
mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
}
}
}
示例14: UnOper
void User::UnOper()
{
if (!this->IsOper())
return;
/*
* unset their oper type (what IS_OPER checks).
* note, order is important - this must come before modes as -o attempts
* to call UnOper. -- w00t
*/
oper = NULL;
/* Remove all oper only modes from the user when the deoper - Bug #466*/
Modes::ChangeList changelist;
const ModeParser::ModeHandlerMap& usermodes = ServerInstance->Modes->GetModes(MODETYPE_USER);
for (ModeParser::ModeHandlerMap::const_iterator i = usermodes.begin(); i != usermodes.end(); ++i)
{
ModeHandler* mh = i->second;
if (mh->NeedsOper())
changelist.push_remove(mh);
}
ServerInstance->Modes->Process(this, NULL, this, changelist);
// Remove the user from the oper list
stdalgo::vector::swaperase(ServerInstance->Users->all_opers, this);
ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
this->SetMode(opermh, false);
}
示例15: GetListOfServersForChannel
/* returns a list of DIRECT servernames for a specific channel */
void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list)
{
unsigned int minrank = 0;
if (status)
{
ModeHandler* mh = ServerInstance->Modes->FindPrefix(status);
if (mh)
minrank = mh->GetPrefixRank();
}
const UserMembList *ulist = c->GetUsers();
for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
{
if (IS_LOCAL(i->first))
continue;
if (minrank && i->second->getRank() < minrank)
continue;
if (exempt_list.find(i->first) == exempt_list.end())
{
TreeServer* best = this->BestRouteTo(i->first->server);
if (best)
list.insert(best->GetSocket());
}
}
return;
}