本文整理汇总了C++中TreeSocket类的典型用法代码示例。如果您正苦于以下问题:C++ TreeSocket类的具体用法?C++ TreeSocket怎么用?C++ TreeSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: DoOneToOne
void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, Server* server)
{
TreeServer* ts = static_cast<TreeServer*>(server);
TreeSocket* sock = ts->GetSocket();
if (sock)
sock->WriteLine(params);
}
示例3: 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;
}
示例4: TreeSocket
void ServernameResolver::OnLookupComplete(const DNS::Query *r)
{
const DNS::ResourceRecord &ans_record = r->answers[0];
/* Initiate the connection, now that we have an IP to use.
* Passing a hostname directly to BufferedSocket causes it to
* just bail and set its FD to -1.
*/
TreeServer* CheckDupe = Utils->FindServer(MyLink->Name.c_str());
if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
{
TreeSocket* newsocket = new TreeSocket(Utils, MyLink, myautoconnect, ans_record.rdata);
if (newsocket->GetFd() > -1)
{
/* We're all OK */
}
else
{
/* Something barfed, show the opers */
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
MyLink->Name.c_str(), newsocket->getError().c_str());
ServerInstance->GlobalCulls.AddItem(newsocket);
}
}
}
示例5: TreeSocket
void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
{
bool ipvalid = true;
if (InspIRCd::Match(ServerInstance->Config->ServerName, assign(x->Name)))
{
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Not connecting to myself.");
return;
}
DNS::QueryType start_type = DNS::QUERY_AAAA;
if (strchr(x->IPAddr.c_str(),':'))
{
in6_addr n;
if (inet_pton(AF_INET6, x->IPAddr.c_str(), &n) < 1)
ipvalid = false;
}
else
{
in_addr n;
if (inet_aton(x->IPAddr.c_str(),&n) < 1)
ipvalid = false;
}
/* Do we already have an IP? If so, no need to resolve it. */
if (ipvalid)
{
/* Gave a hook, but it wasnt one we know */
TreeSocket* newsocket = new TreeSocket(x, y, x->IPAddr);
if (newsocket->GetFd() > -1)
{
/* Handled automatically on success */
}
else
{
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
x->Name.c_str(), newsocket->getError().c_str());
ServerInstance->GlobalCulls.AddItem(newsocket);
}
}
else if (!DNS)
{
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Hostname given and m_dns.so is not loaded, unable to resolve.", x->Name.c_str());
}
else
{
ServernameResolver* snr = new ServernameResolver(*DNS, x->IPAddr, x, start_type, y);
try
{
DNS->Process(snr);
}
catch (DNS::Exception& e)
{
delete snr;
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
ConnectServer(y, false);
}
}
}
示例6: DoPingChecks
void ModuleSpanningTree::DoPingChecks(time_t curtime)
{
/*
* Cancel remote burst mode on any servers which still have it enabled due to latency/lack of data.
* This prevents lost REMOTECONNECT notices
*/
long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000);
restart:
for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
{
TreeServer *s = i->second;
// Skip myself
if (s->IsRoot())
continue;
// Do not ping servers that are not fully connected yet!
// Servers which are connected to us have IsLocal() == true and if they're fully connected
// then Socket->LinkState == CONNECTED. Servers that are linked to another server are always fully connected.
if (s->IsLocal() && s->GetSocket()->GetLinkState() != CONNECTED)
continue;
// Now do PING checks on all servers
// Only ping if this server needs one
if (curtime >= s->NextPingTime())
{
// And if they answered the last
if (s->AnsweredLastPing())
{
// They did, send a ping to them
s->SetNextPingTime(curtime + Utils->PingFreq);
s->GetSocket()->WriteLine(CmdBuilder("PING").push(s->GetID()));
s->LastPingMsec = ts;
}
else
{
// They didn't answer the last ping, if they are locally connected, get rid of them.
if (s->IsLocal())
{
TreeSocket* sock = s->GetSocket();
sock->SendError("Ping timeout");
sock->Close();
goto restart;
}
}
}
// If warn on ping enabled and not warned and the difference is sufficient and they didn't answer the last ping...
if ((Utils->PingWarnTime) && (!s->Warned) && (curtime >= s->NextPingTime() - (Utils->PingFreq - Utils->PingWarnTime)) && (!s->AnsweredLastPing()))
{
/* The server hasnt responded, send a warning to opers */
ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not responded to PING for %d seconds, high latency.", s->GetName().c_str(), Utils->PingWarnTime);
s->Warned = true;
}
}
}
示例7: OnUnloadModule
void ModuleSpanningTree::OnUnloadModule(Module* mod)
{
if (!Utils)
return;
ServerInstance->PI->SendMetaData(NULL, "modules", "-" + mod->ModuleSourceFile);
// Close all connections which use an IO hook provided by this module
const TreeServer::ChildServers& list = Utils->TreeRoot->GetChildren();
for (TreeServer::ChildServers::const_iterator i = list.begin(); i != list.end(); ++i)
{
TreeSocket* sock = (*i)->GetSocket();
if (sock && sock->GetIOHook() && sock->GetIOHook()->creator == mod)
{
sock->SendError("SSL module unloaded");
sock->Close();
}
}
for (SpanningTreeUtilities::TimeoutList::const_iterator i = Utils->timeoutlist.begin(); i != Utils->timeoutlist.end(); ++i)
{
TreeSocket* sock = i->first;
if (sock->GetIOHook() && sock->GetIOHook()->creator == mod)
sock->Close();
}
}
示例8: ProtoSendMetaData
void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
{
TreeSocket* s = static_cast<TreeSocket*>(opaque);
User* u = dynamic_cast<User*>(target);
Channel* c = dynamic_cast<Channel*>(target);
if (u)
s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
else if (c)
s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+ConvToStr(c->age)+" "+extname+" :"+extdata);
else if (!target)
s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
}
示例9: TreeSocket
void ModuleSpanningTree::ConnectServer(Link* x)
{
bool ipvalid = true;
QueryType start_type = DNS_QUERY_A;
#ifdef IPV6
start_type = DNS_QUERY_AAAA;
if (strchr(x->IPAddr.c_str(),':'))
{
in6_addr n;
if (inet_pton(AF_INET6, x->IPAddr.c_str(), &n) < 1)
ipvalid = false;
}
else
#endif
{
in_addr n;
if (inet_aton(x->IPAddr.c_str(),&n) < 1)
ipvalid = false;
}
/* Do we already have an IP? If so, no need to resolve it. */
if (ipvalid)
{
/* Gave a hook, but it wasnt one we know */
if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end()))
return;
TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
if (newsocket->GetFd() > -1)
{
/* Handled automatically on success */
}
else
{
ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
delete newsocket;
Utils->DoFailOver(x);
}
}
else
{
try
{
bool cached;
ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached, start_type);
ServerInstance->AddResolver(snr, cached);
}
catch (ModuleException& e)
{
ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
Utils->DoFailOver(x);
}
}
}
示例10: 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;
}
TreeSocket* sock = server->GetSocket();
sock->Squit(quitting, params[1]);
return CMD_SUCCESS;
}
示例11: msg
void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit)
{
CmdBuilder msg(prefix, message_type);
if (status == 0)
status = ' ';
msg.push(status).push_raw(target->name).push_last(text);
TreeSocketSet list;
this->GetListOfServersForChannel(target, list, status, exempt_list);
for (TreeSocketSet::iterator i = list.begin(); i != list.end(); ++i)
{
TreeSocket* Sock = *i;
if (Sock != omit)
Sock->WriteLine(msg);
}
}
示例12: if
void ModuleSpanningTree::OnUserNotice(userrec* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
{
if (target_type == TYPE_USER)
{
userrec* d = (userrec*)dest;
if ((d->GetFd() < 0) && (IS_LOCAL(user)))
{
std::deque<std::string> params;
params.clear();
params.push_back(d->nick);
params.push_back(":"+text);
Utils->DoOneToOne(user->nick,"NOTICE",params,d->server);
}
}
else if (target_type == TYPE_CHANNEL)
{
if (IS_LOCAL(user))
{
chanrec *c = (chanrec*)dest;
if (c)
{
std::string cname = c->name;
if (status)
cname = status + cname;
TreeServerList list;
Utils->GetListOfServersForChannel(c,list,status,exempt_list);
for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
{
TreeSocket* Sock = i->second->GetSocket();
if (Sock)
Sock->WriteLine(":"+std::string(user->nick)+" NOTICE "+cname+" :"+text);
}
}
}
}
else if (target_type == TYPE_SERVER)
{
if (IS_LOCAL(user))
{
char* target = (char*)dest;
std::deque<std::string> par;
par.push_back(target);
par.push_back(":"+text);
Utils->DoOneToMany(user->nick,"NOTICE",par);
}
}
}
示例13: ConstructLine
bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist ¶ms)
{
std::string FullLine = ConstructLine(prefix, command, params);
unsigned int items = this->TreeRoot->ChildCount();
for (unsigned int x = 0; x < items; x++)
{
TreeServer* Route = this->TreeRoot->GetChild(x);
if (Route && Route->GetSocket())
{
TreeSocket* Sock = Route->GetSocket();
if (Sock)
Sock->WriteLine(FullLine);
}
}
return true;
}
示例14: ProtoSendMode
void ModuleSpanningTree::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline)
{
TreeSocket* s = (TreeSocket*)opaque;
if (target)
{
if (target_type == TYPE_USER)
{
userrec* u = (userrec*)target;
s->WriteLine(std::string(":")+ServerInstance->Config->ServerName+" FMODE "+u->nick+" "+ConvToStr(u->age)+" "+modeline);
}
else
{
chanrec* c = (chanrec*)target;
s->WriteLine(std::string(":")+ServerInstance->Config->ServerName+" FMODE "+c->name+" "+ConvToStr(c->age)+" "+modeline);
}
}
}
示例15: raw
void SpanningTreeUtilities::SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit)
{
std::string raw(":");
raw.append(prefix).append(1, ' ').append(message_type).push_back(' ');
if (status)
raw.push_back(status);
raw.append(target->name).append(" :").append(text);
TreeSocketSet list;
this->GetListOfServersForChannel(target, list, status, exempt_list);
for (TreeSocketSet::iterator i = list.begin(); i != list.end(); ++i)
{
TreeSocket* Sock = *i;
if (Sock != omit)
Sock->WriteLine(raw);
}
}