本文整理汇总了C++中TreeServer类的典型用法代码示例。如果您正苦于以下问题:C++ TreeServer类的具体用法?C++ TreeServer怎么用?C++ TreeServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleServer
CmdResult CommandSQuit::HandleServer(TreeServer* server, std::vector<std::string>& params)
{
TreeServer* quitting = Utils->FindServer(params[0]);
if (!quitting)
{
ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Squit from unknown server");
return CMD_FAILURE;
}
CmdResult ret = CMD_SUCCESS;
if (quitting == server)
{
ret = CMD_FAILURE;
server = server->GetParent();
}
else if (quitting->GetParent() != server)
throw ProtocolException("Attempted to SQUIT a non-directly connected server or the parent");
server->SQuitChild(quitting, params[1]);
// XXX: Return CMD_FAILURE when servers SQUIT themselves (i.e. :00S SQUIT 00S :Shutting down)
// to stop this message from being forwarded.
// The squit logic generates a SQUIT message with our sid as the source and sends it to the
// remaining servers.
return ret;
}
示例2: HandleRemote
/** Because the core won't let users or even SERVERS set +o,
* we use the OPERTYPE command to do this.
*/
CmdResult CommandOpertype::HandleRemote(RemoteUser* u, std::vector<std::string>& params)
{
const std::string& opertype = params[0];
if (!u->IsOper())
ServerInstance->Users->all_opers.push_back(u);
ModeHandler* opermh = ServerInstance->Modes->FindMode('o', MODETYPE_USER);
u->SetMode(opermh, true);
OperIndex::iterator iter = ServerInstance->Config->OperTypes.find(opertype);
if (iter != ServerInstance->Config->OperTypes.end())
u->oper = iter->second;
else
{
u->oper = new OperInfo;
u->oper->name = opertype;
}
if (Utils->quiet_bursts)
{
/*
* If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
* then do nothing. -- w00t
*/
TreeServer* remoteserver = TreeServer::Get(u);
if (remoteserver->bursting || remoteserver->IsSilentULine())
return CMD_SUCCESS;
}
ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%[email protected]%s) is now an IRC operator of type %s",u->server->GetName().c_str(), u->nick.c_str(),u->ident.c_str(), u->host.c_str(), opertype.c_str());
return CMD_SUCCESS;
}
示例3: HandleStats
int ModuleSpanningTree::HandleStats(const char** parameters, int pcnt, userrec* user)
{
if (pcnt > 1)
{
if (match(ServerInstance->Config->ServerName, parameters[1]))
return 0;
/* Remote STATS, the server is within the 2nd parameter */
std::deque<std::string> params;
params.push_back(parameters[0]);
params.push_back(parameters[1]);
/* Send it out remotely, generate no reply yet */
TreeServer* s = Utils->FindServerMask(parameters[1]);
if (s)
{
params[1] = s->GetName();
Utils->DoOneToOne(user->nick, "STATS", params, s->GetName());
}
else
{
user->WriteServ( "402 %s %s :No such server", user->nick, parameters[1]);
}
return 1;
}
return 0;
}
示例4: 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)
{
PrefixMode* 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 = TreeServer::Get(i->first);
list.insert(best->GetSocket());
}
}
return;
}
示例5: DelLine
bool TreeSocket::DelLine(const std::string &prefix, parameterlist ¶ms)
{
if (params.size() < 2)
return true;
std::string setter = "<unknown>";
User* user = ServerInstance->FindNick(prefix);
if (user)
setter = user->nick;
else
{
TreeServer* t = Utils->FindServer(prefix);
if (t)
setter = t->GetName();
}
/* NOTE: No check needed on 'user', this function safely handles NULL */
if (ServerInstance->XLines->DelLine(params[1].c_str(), params[0], user))
{
ServerInstance->SNO->WriteToSnoMask('X',"%s removed %s%s on %s", setter.c_str(),
params[0].c_str(), params[0].length() == 1 ? "-line" : "", params[1].c_str());
Utils->DoOneToAllButSender(prefix,"DELLINE", params, prefix);
}
return true;
}
示例6: HandleSquit
int ModuleSpanningTree::HandleSquit(const char** parameters, int pcnt, userrec* user)
{
TreeServer* s = Utils->FindServerMask(parameters[0]);
if (s)
{
if (s == Utils->TreeRoot)
{
user->WriteServ("NOTICE %s :*** SQUIT: Foolish mortal, you cannot make a server SQUIT itself! (%s matches local server name)",user->nick,parameters[0]);
return 1;
}
TreeSocket* sock = s->GetSocket();
if (sock)
{
ServerInstance->SNO->WriteToSnoMask('l',"SQUIT: Server \002%s\002 removed from network by %s",parameters[0],user->nick);
sock->Squit(s,std::string("Server quit by ") + user->GetFullRealHost());
ServerInstance->SE->DelFd(sock);
sock->Close();
}
else
{
if (IS_LOCAL(user))
user->WriteServ("NOTICE %s :*** WARNING: Using SQUIT to split remote servers is deprecated. Please use RSQUIT instead.",user->nick);
}
}
else
{
user->WriteServ("NOTICE %s :*** SQUIT: The server \002%s\002 does not exist on the network.",user->nick,parameters[0]);
}
return 1;
}
示例7: ShowLinks
void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops)
{
std::string Parent = Utils->TreeRoot->GetName();
if (Current->GetParent())
{
Parent = Current->GetParent()->GetName();
}
const TreeServer::ChildServers& children = Current->GetChildren();
for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i)
{
TreeServer* server = *i;
if ((server->Hidden) || ((Utils->HideULines) && (server->IsULine())))
{
if (user->IsOper())
{
ShowLinks(server, user, hops+1);
}
}
else
{
ShowLinks(server, user, hops+1);
}
}
/* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */
if ((Utils->HideULines) && (Current->IsULine()) && (!user->IsOper()))
return;
/* Or if the server is hidden and they're not an oper */
else if ((Current->Hidden) && (!user->IsOper()))
return;
user->WriteNumeric(RPL_LINKS, Current->GetName(),
(((Utils->FlatLinks) && (!user->IsOper())) ? ServerInstance->Config->ServerName : Parent),
InspIRCd::Format("%d %s", (((Utils->FlatLinks) && (!user->IsOper())) ? 0 : hops), Current->GetDesc().c_str()));
}
示例8: HandleSquit
ModResult ModuleSpanningTree::HandleSquit(const std::vector<std::string>& parameters, User* user)
{
TreeServer* s = Utils->FindServerMask(parameters[0]);
if (s)
{
if (s == Utils->TreeRoot)
{
user->WriteNotice("*** SQUIT: Foolish mortal, you cannot make a server SQUIT itself! (" + parameters[0] + " matches local server name)");
return MOD_RES_DENY;
}
TreeSocket* sock = s->GetSocket();
if (sock)
{
ServerInstance->SNO->WriteToSnoMask('l',"SQUIT: Server \002%s\002 removed from network by %s",parameters[0].c_str(),user->nick.c_str());
sock->Squit(s,"Server quit by " + user->GetFullRealHost());
ServerInstance->SE->DelFd(sock);
sock->Close();
}
else
{
user->WriteNotice("*** SQUIT may not be used to remove remote servers. Please use RSQUIT instead.");
}
}
else
{
user->WriteNotice("*** SQUIT: The server \002" + parameters[0] + "\002 does not exist on the network.");
}
return MOD_RES_DENY;
}
示例9: DoOneToOne
void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, Server* server)
{
TreeServer* ts = static_cast<TreeServer*>(server);
TreeSocket* sock = ts->GetSocket();
if (sock)
sock->WriteLine(params);
}
示例10: HandleVersion
ModResult ModuleSpanningTree::HandleVersion(const CommandBase::Params& parameters, User* user)
{
// We've already confirmed that !parameters.empty(), so this is safe
TreeServer* found = Utils->FindServerMask(parameters[0]);
if (found)
{
if (found == Utils->TreeRoot)
{
// Pass to default VERSION handler.
return MOD_RES_PASSTHRU;
}
// If an oper wants to see the version then show the full version string instead of the normal,
// but only if it is non-empty.
// If it's empty it might be that the server is still syncing (full version hasn't arrived yet)
// or the server is a 2.0 server and does not send a full version.
bool showfull = ((user->IsOper()) && (!found->GetFullVersion().empty()));
Numeric::Numeric numeric(RPL_VERSION);
irc::tokenstream tokens(showfull ? found->GetFullVersion() : found->GetVersion());
for (std::string token; tokens.GetTrailing(token); )
numeric.push(token);
user->WriteNumeric(numeric);
}
else
{
user->WriteNumeric(ERR_NOSUCHSERVER, parameters[0], "No such server");
}
return MOD_RES_DENY;
}
示例11: CmdBuilder
void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
{
if (IS_LOCAL(user))
{
if (oper_message != reason)
ServerInstance->PI->SendMetaData(user, "operquit", oper_message);
CmdBuilder(user, "QUIT").push_last(reason).Broadcast();
}
else
{
// Hide the message if one of the following is true:
// - User is being quit due to a netsplit and quietbursts is on
// - Server is a silent uline
TreeServer* server = TreeServer::Get(user);
bool hide = (((server->IsDead()) && (Utils->quiet_bursts)) || (server->IsSilentULine()));
if (!hide)
{
ServerInstance->SNO.WriteToSnoMask('Q', "Client exiting on server %s: %s (%s) [%s]",
user->server->GetName().c_str(), user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_message.c_str());
}
}
// Regardless, update the UserCount
TreeServer::Get(user)->UserCount--;
}
示例12: HandleVersion
ModResult ModuleSpanningTree::HandleVersion(const std::vector<std::string>& parameters, User* user)
{
// we've already checked if pcnt > 0, so this is safe
TreeServer* found = Utils->FindServerMask(parameters[0]);
if (found)
{
if (found == Utils->TreeRoot)
{
// Pass to default VERSION handler.
return MOD_RES_PASSTHRU;
}
// If an oper wants to see the version then show the full version string instead of the normal,
// but only if it is non-empty.
// If it's empty it might be that the server is still syncing (full version hasn't arrived yet)
// or the server is a 2.0 server and does not send a full version.
bool showfull = ((user->IsOper()) && (!found->GetFullVersion().empty()));
const std::string& Version = (showfull ? found->GetFullVersion() : found->GetVersion());
user->WriteNumeric(RPL_VERSION, ":%s", Version.c_str());
}
else
{
user->WriteNumeric(ERR_NOSUCHSERVER, "%s :No such server", parameters[0].c_str());
}
return MOD_RES_DENY;
}
示例13: encap
bool SpanningTreeProtocolInterface::SendEncapsulatedData(const std::string& targetmask, const std::string& cmd, const parameterlist& params, User* source)
{
if (!source)
source = ServerInstance->FakeClient;
CmdBuilder encap(source, "ENCAP");
// Are there any wildcards in the target string?
if (targetmask.find_first_of("*?") != std::string::npos)
{
// Yes, send the target string as-is; servers will decide whether or not it matches them
encap.push(targetmask).push(cmd).insert(params).Broadcast();
}
else
{
// No wildcards which means the target string has to be the name of a known server
TreeServer* server = Utils->FindServer(targetmask);
if (!server)
return false;
// Use the SID of the target in the message instead of the server name
encap.push(server->GetID()).push(cmd).insert(params).Unicast(server->ServerUser);
}
return true;
}
示例14: OnGetServerDescription
void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description)
{
TreeServer* s = Utils->FindServer(servername);
if (s)
{
description = s->GetDesc();
}
}
示例15: DoOneToOne
bool SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, const std::string& target)
{
TreeServer* Route = this->BestRouteTo(target);
if (!Route)
return false;
Route->GetSocket()->WriteLine(params);
return true;
}