1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
20 #include "transport.h"
21 #include "socketengine.h"
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
31 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
33 static std::map<std::string, std::string> warned; /* Server names that have had protocol violation warnings displayed for them */
35 int TreeSocket::WriteLine(std::string line)
37 Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
39 return this->Write(line);
43 /* Handle ERROR command */
44 bool TreeSocket::Error(std::deque<std::string> ¶ms)
46 if (params.size() < 1)
48 this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
49 /* we will return false to cause the socket to close. */
53 bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> ¶ms)
58 if (!this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
60 /* Pass it on, not for us */
61 Utils->DoOneToOne(prefix, "MODULES", params, params[0]);
66 std::deque<std::string> par;
67 par.push_back(prefix);
70 userrec* source = this->Instance->FindNick(prefix);
74 for (unsigned int i = 0; i < Instance->Config->module_names.size(); i++)
76 Version V = Instance->Modules->modules[i]->GetVersion();
77 char modulename[MAXBUF];
78 char flagstate[MAXBUF];
80 if (V.Flags & VF_STATIC)
81 strlcat(flagstate,", static",MAXBUF);
82 if (V.Flags & VF_VENDOR)
83 strlcat(flagstate,", vendor",MAXBUF);
84 if (V.Flags & VF_COMMON)
85 strlcat(flagstate,", common",MAXBUF);
86 if (V.Flags & VF_SERVICEPROVIDER)
87 strlcat(flagstate,", service provider",MAXBUF);
89 strcpy(flagstate," <no flags>");
90 strlcpy(modulename,Instance->Config->module_names[i].c_str(),256);
93 snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(long unsigned int)Instance->Modules->modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2);
97 snprintf(strbuf, MAXBUF, "::%s 900 %s :%s",Instance->Config->ServerName,source->nick,ServerConfig::CleanFilename(modulename));
100 Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
102 snprintf(strbuf, MAXBUF, "::%s 901 %s :End of MODULES list", Instance->Config->ServerName, source->nick);
104 Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
108 /** remote MOTD. leet, huh? */
109 bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> ¶ms)
111 if (params.size() > 0)
113 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
115 /* It's for our server */
117 userrec* source = this->Instance->FindNick(prefix);
121 std::deque<std::string> par;
122 par.push_back(prefix);
125 if (!Instance->Config->MOTD.size())
127 par[1] = std::string("::")+Instance->Config->ServerName+" 422 "+source->nick+" :Message of the day file is missing.";
128 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
132 par[1] = std::string("::")+Instance->Config->ServerName+" 375 "+source->nick+" :"+Instance->Config->ServerName+" message of the day";
133 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
135 for (unsigned int i = 0; i < Instance->Config->MOTD.size(); i++)
137 par[1] = std::string("::")+Instance->Config->ServerName+" 372 "+source->nick+" :- "+Instance->Config->MOTD[i];
138 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
141 par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" :End of message of the day.";
142 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
148 userrec* source = this->Instance->FindNick(prefix);
150 Utils->DoOneToOne(prefix, "MOTD", params, params[0]);
156 /** remote ADMIN. leet, huh? */
157 bool TreeSocket::Admin(const std::string &prefix, std::deque<std::string> ¶ms)
159 if (params.size() > 0)
161 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
163 /* It's for our server */
165 userrec* source = this->Instance->FindNick(prefix);
168 std::deque<std::string> par;
169 par.push_back(prefix);
171 par[1] = std::string("::")+Instance->Config->ServerName+" 256 "+source->nick+" :Administrative info for "+Instance->Config->ServerName;
172 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
173 par[1] = std::string("::")+Instance->Config->ServerName+" 257 "+source->nick+" :Name - "+Instance->Config->AdminName;
174 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
175 par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :Nickname - "+Instance->Config->AdminNick;
176 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
177 par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :E-Mail - "+Instance->Config->AdminEmail;
178 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
184 userrec* source = this->Instance->FindNick(prefix);
186 Utils->DoOneToOne(prefix, "ADMIN", params, params[0]);
192 bool TreeSocket::Stats(const std::string &prefix, std::deque<std::string> ¶ms)
194 /* Get the reply to a STATS query if it matches this servername,
195 * and send it back as a load of PUSH queries
197 if (params.size() > 1)
199 if (this->Instance->MatchText(this->Instance->Config->ServerName, params[1]))
201 /* It's for our server */
203 userrec* source = this->Instance->FindNick(prefix);
206 std::deque<std::string> par;
207 par.push_back(prefix);
209 DoStats(this->Instance, *(params[0].c_str()), source, results);
210 for (size_t i = 0; i < results.size(); i++)
212 par[1] = "::" + results[i];
213 Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
220 userrec* source = this->Instance->FindNick(prefix);
222 Utils->DoOneToOne(source->uuid, "STATS", params, params[1]);
229 /** Because the core won't let users or even SERVERS set +o,
230 * we use the OPERTYPE command to do this.
232 bool TreeSocket::OperType(const std::string &prefix, std::deque<std::string> ¶ms)
234 if (params.size() != 1)
236 std::string opertype = params[0];
237 userrec* u = this->Instance->FindNick(prefix);
240 u->modes[UM_OPERATOR] = 1;
241 this->Instance->all_opers.push_back(u);
242 strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
243 Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
245 TreeServer* remoteserver = Utils->FindServer(u->server);
248 if (this->Utils->quiet_bursts)
251 * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
252 * then do nothing. -- w00t
256 Utils->FindRemoteBurstServer(remoteserver) ||
257 this->Instance->SilentULine(this->Instance->FindServerNamePtr(u->server))
265 this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
270 /** Because Andy insists that services-compatible servers must
271 * implement SVSNICK and SVSJOIN, that's exactly what we do :p
273 bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> ¶ms)
275 if (params.size() < 3)
278 userrec* u = this->Instance->FindNick(params[0]);
282 Utils->DoOneToAllButSender(prefix,"SVSNICK",params,prefix);
286 std::deque<std::string> par;
287 par.push_back(params[1]);
289 if (!u->ForceNickChange(params[1].c_str()))
292 if (!u->ForceNickChange(u->uuid))
294 userrec::QuitUser(this->Instance, u, "Nickname collision");
299 u->age = atoi(params[2].c_str());
306 bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> ¶ms)
308 if (params.size() < 1)
311 userrec* u = this->Instance->FindNick(prefix);
315 u->SetOperQuit(params[0]);
316 params[0] = ":" + params[0];
317 Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
322 bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> ¶ms)
324 if (params.size() < 2)
327 if (!this->Instance->IsChannel(params[1].c_str()))
330 userrec* u = this->Instance->FindNick(params[0]);
334 /* only join if it's local, otherwise just pass it on! */
336 chanrec::JoinUser(this->Instance, u, params[1].c_str(), false, "", Instance->Time());
337 Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
342 bool TreeSocket::ServicePart(const std::string &prefix, std::deque<std::string> ¶ms)
344 if (params.size() < 2)
347 if (!this->Instance->IsChannel(params[1].c_str()))
350 userrec* u = this->Instance->FindNick(params[0]);
351 chanrec* c = this->Instance->FindChan(params[1]);
355 /* only part if it's local, otherwise just pass it on! */
357 if (!c->PartUser(u, "Services forced part"))
359 Utils->DoOneToAllButSender(prefix,"SVSPART",params,prefix);
365 bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque<std::string> ¶ms)
367 if (params.size() < 1)
370 std::string servermask = params[0];
372 if (this->Instance->MatchText(this->Instance->Config->ServerName,servermask))
374 this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated by \002"+prefix+"\002.");
375 this->Instance->RehashServer();
376 Utils->ReadConfiguration(false);
377 InitializeDisabledCommands(Instance->Config->DisabledCommands, Instance);
379 Utils->DoOneToAllButSender(prefix,"REHASH",params,prefix);
383 bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> ¶ms)
385 if (params.size() != 2)
388 userrec* who = this->Instance->FindNick(params[0]);
392 /* Prepend kill source, if we don't have one */
393 if (*(params[1].c_str()) != '[')
395 params[1] = "[" + prefix + "] Killed (" + params[1] +")";
397 std::string reason = params[1];
398 params[1] = ":" + params[1];
399 Utils->DoOneToAllButSender(prefix,"KILL",params,prefix);
400 // NOTE: This is safe with kill hiding on, as RemoteKill is only reached if we have a server prefix.
401 // in short this is not executed for USERS.
402 who->Write(":%s KILL %s :%s (%s)", prefix.c_str(), who->nick, prefix.c_str(), reason.c_str());
403 userrec::QuitUser(this->Instance,who,reason);
408 bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> ¶ms)
410 if (params.size() < 1)
413 if (params.size() == 1)
415 TreeServer* ServerSource = Utils->FindServer(prefix);
418 ServerSource->SetPingFlag();
420 gettimeofday(&t, NULL);
421 long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
422 ServerSource->rtt = ts - ServerSource->LastPingMsec;
427 std::string forwardto = params[1];
428 if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
431 * this is a PONG for us
432 * if the prefix is a user, check theyre local, and if they are,
433 * dump the PONG reply back to their fd. If its a server, do nowt.
434 * Services might want to send these s->s, but we dont need to yet.
436 userrec* u = this->Instance->FindNick(prefix);
439 u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
444 // not for us, pass it on :)
445 Utils->DoOneToOne(prefix,"PONG",params,forwardto);
452 bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> ¶ms)
454 if (params.size() < 2)
456 else if (params.size() < 3)
457 params.push_back("");
458 TreeServer* ServerSource = Utils->FindServer(prefix);
461 Utils->SetRemoteBursting(ServerSource, false);
463 if (params[0] == "*")
465 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
467 else if (*(params[0].c_str()) == '#')
469 chanrec* c = this->Instance->FindChan(params[0]);
472 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
475 else if (*(params[0].c_str()) != '#')
477 userrec* u = this->Instance->FindNick(params[0]);
480 FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
485 params[2] = ":" + params[2];
486 Utils->DoOneToAllButSender(prefix,"METADATA",params,prefix);
490 bool TreeSocket::ServerVersion(const std::string &prefix, std::deque<std::string> ¶ms)
492 if (params.size() < 1)
495 TreeServer* ServerSource = Utils->FindServer(prefix);
499 ServerSource->SetVersion(params[0]);
501 params[0] = ":" + params[0];
502 Utils->DoOneToAllButSender(prefix,"VERSION",params,prefix);
506 bool TreeSocket::ChangeHost(const std::string &prefix, std::deque<std::string> ¶ms)
508 if (params.size() < 1)
510 userrec* u = this->Instance->FindNick(prefix);
514 u->ChangeDisplayedHost(params[0].c_str());
515 Utils->DoOneToAllButSender(prefix,"FHOST",params,u->server);
520 bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> ¶ms)
522 if (params.size() < 6)
524 bool propogate = false;
526 Utils->lines_to_apply = 0;
527 switch (*(params[0].c_str()))
530 propogate = Instance->XLines->add_zline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
531 Instance->XLines->zline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
533 Utils->lines_to_apply |= APPLY_ZLINES;
536 propogate = Instance->XLines->add_qline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
537 Instance->XLines->qline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
539 Utils->lines_to_apply |= APPLY_QLINES;
542 propogate = Instance->XLines->add_eline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
543 Instance->XLines->eline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
546 propogate = Instance->XLines->add_gline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
547 Instance->XLines->gline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
549 Utils->lines_to_apply |= APPLY_GLINES;
552 propogate = Instance->XLines->add_kline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
554 Utils->lines_to_apply |= APPLY_KLINES;
557 /* Just in case... */
558 this->Instance->SNO->WriteToSnoMask('x',"\2WARNING\2: Invalid xline type '"+params[0]+"' sent by server "+prefix+", ignored!");
562 /* Send it on its way */
565 if (atoi(params[4].c_str()))
567 time_t c_requires_crap = ConvToInt(params[4]) + Instance->Time();
568 this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(c_requires_crap).c_str(),params[5].c_str());
572 this->Instance->SNO->WriteToSnoMask('x',"%s Added permenant %cLINE on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),params[5].c_str());
574 params[5] = ":" + params[5];
575 Utils->DoOneToAllButSender(prefix,"ADDLINE",params,prefix);
579 Instance->XLines->apply_lines(Utils->lines_to_apply);
580 Utils->lines_to_apply = 0;
585 bool TreeSocket::ChangeName(const std::string &prefix, std::deque<std::string> ¶ms)
587 if (params.size() < 1)
589 userrec* u = this->Instance->FindNick(prefix);
592 u->ChangeName(params[0].c_str());
593 params[0] = ":" + params[0];
594 Utils->DoOneToAllButSender(prefix,"FNAME",params,u->server);
599 bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> ¶ms)
601 if (params.size() < 1)
603 userrec* u = this->Instance->FindNick(prefix);
606 // an incoming request
607 if (params.size() == 1)
609 userrec* x = this->Instance->FindNick(params[0]);
610 if ((x) && (IS_LOCAL(x)))
612 userrec* x = this->Instance->FindNick(params[0]);
615 snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
616 snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time(true)));
617 std::deque<std::string> par;
618 par.push_back(prefix);
619 par.push_back(signon);
621 // ours, we're done, pass it BACK
622 Utils->DoOneToOne(params[0], "IDLE", par, u->server);
626 // not ours pass it on
628 Utils->DoOneToOne(prefix, "IDLE", params, x->server);
631 else if (params.size() == 3)
633 std::string who_did_the_whois = params[0];
634 userrec* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
635 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
637 // an incoming reply to a whois we sent out
638 std::string nick_whoised = prefix;
639 unsigned long signon = atoi(params[1].c_str());
640 unsigned long idle = atoi(params[2].c_str());
641 if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
643 do_whois(this->Instance, who_to_send_to, u, signon, idle, nick_whoised.c_str());
648 // not ours, pass it on
650 Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
657 bool TreeSocket::Push(const std::string &prefix, std::deque<std::string> ¶ms)
659 if (params.size() < 2)
661 userrec* u = this->Instance->FindNick(params[0]);
670 // continue the raw onwards
671 params[1] = ":" + params[1];
672 Utils->DoOneToOne(prefix,"PUSH",params,u->server);
677 bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> ¶ms)
679 if (!params.size() || !Utils->EnableTimeSync)
684 if ((params.size() == 2) && (params[1] == "FORCE"))
687 time_t them = atoi(params[0].c_str());
688 time_t us = Instance->Time(false);
690 time_t diff = them - us;
692 Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
694 if (force || (them != us))
696 time_t old = Instance->SetTimeDelta(diff);
697 Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old);
703 bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> ¶ms)
705 // :source.server TIME remote.server sendernick
706 // :remote.server TIME source.server sendernick TS
707 if (params.size() == 2)
709 // someone querying our time?
710 if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
712 userrec* u = this->Instance->FindNick(params[1]);
715 params.push_back(ConvToStr(Instance->Time(false)));
717 Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
722 // not us, pass it on
723 userrec* u = this->Instance->FindNick(params[1]);
725 Utils->DoOneToOne(prefix,"TIME",params,params[0]);
728 else if (params.size() == 3)
730 // a response to a previous TIME
731 userrec* u = this->Instance->FindNick(params[1]);
732 if ((u) && (IS_LOCAL(u)))
734 time_t rawtime = atol(params[2].c_str());
735 struct tm * timeinfo;
736 timeinfo = localtime(&rawtime);
738 snprintf(tms,26,"%s",asctime(timeinfo));
740 u->WriteServ("391 %s %s :%s",u->nick,prefix.c_str(),tms);
745 Utils->DoOneToOne(prefix,"TIME",params,u->server);
751 bool TreeSocket::LocalPing(const std::string &prefix, std::deque<std::string> ¶ms)
753 if (params.size() < 1)
755 if (params.size() == 1)
757 std::string stufftobounce = params[0];
758 this->WriteLine(std::string(":")+this->Instance->Config->GetSID()+" PONG "+stufftobounce);
763 std::string forwardto = params[1];
764 if (forwardto == this->Instance->Config->ServerName || forwardto == this->Instance->Config->GetSID())
766 // this is a ping for us, send back PONG to the requesting server
767 params[1] = params[0];
768 params[0] = forwardto;
769 Utils->DoOneToOne(forwardto,"PONG",params,params[1]);
773 // not for us, pass it on :)
774 Utils->DoOneToOne(prefix,"PING",params,forwardto);
780 /** TODO: This creates a total mess of output and needs to really use irc::modestacker.
782 bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string> ¶ms)
784 if (params.size() < 1)
786 chanrec* c = Instance->FindChan(params[0]);
789 for (char modeletter = 'A'; modeletter <= 'z'; modeletter++)
791 ModeHandler* mh = Instance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
799 bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> ¶ms)
801 if (params.size() < 5)
803 SendError("Protocol error - Missing SID");
807 std::string servername = params[0];
808 std::string password = params[1];
809 // hopcount is not used for a remote server, we calculate this ourselves
810 std::string sid = params[3];
811 std::string description = params[4];
812 TreeServer* ParentOfThis = Utils->FindServer(prefix);
815 this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
818 if (!Utils->IsSID(sid))
820 this->SendError("Invalid format server ID: "+sid+"!");
823 TreeServer* CheckDupe = Utils->FindServer(servername);
826 this->SendError("Server "+servername+" already exists!");
827 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix);
831 Link* lnk = Utils->FindLink(servername);
833 TreeServer *Node = new TreeServer(this->Utils, this->Instance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false);
835 if (Node->DuplicateID())
837 this->SendError("Server ID "+sid+" already exists on the network!");
838 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link with " + prefix);
842 ParentOfThis->AddChild(Node);
843 params[4] = ":" + params[4];
844 Utils->SetRemoteBursting(Node, true);
845 Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
846 this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
850 bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
852 if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12)))
854 /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
855 * We can't allow this password as valid.
857 if (!Instance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
860 /* Straight string compare of hashes */
861 return ours == theirs;
864 /* Straight string compare of plaintext */
865 return ours == theirs;
868 bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> ¶ms)
870 if (params.size() < 5)
872 SendError("Protocol error - Missing SID");
876 irc::string servername = params[0].c_str();
877 std::string sname = params[0];
878 std::string password = params[1];
879 std::string sid = params[3];
880 std::string description = params[4];
881 int hops = atoi(params[2].c_str());
883 this->InboundServerName = sname;
884 this->InboundDescription = description;
885 this->InboundSID = sid;
888 this->SendCapabilities();
892 this->SendError("Server too far away for authentication");
893 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
897 if (!Utils->IsSID(sid))
899 this->SendError("Invalid format server ID: "+sid+"!");
903 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
905 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)) || (x->RecvPass == password && (this->GetTheirChallenge().empty()))))
907 TreeServer* CheckDupe = Utils->FindServer(sname);
910 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
911 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
914 // Begin the sync here. this kickstarts the
915 // other side, waiting in WAIT_AUTH_2 state,
916 // into starting their burst, as it shows
918 this->LinkState = CONNECTED;
919 // we should add the details of this server now
920 // to the servers tree, as a child of the root
923 TreeServer *Node = new TreeServer(this->Utils, this->Instance, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
925 if (Node->DuplicateID())
927 this->SendError("Server ID "+sid+" already exists on the network!");
928 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link.");
932 Utils->TreeRoot->AddChild(Node);
933 params[4] = ":" + params[4];
934 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,sname);
935 this->bursting = true;
940 this->SendError("Invalid credentials");
941 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
945 bool TreeSocket::Inbound_Server(std::deque<std::string> ¶ms)
947 if (params.size() < 5)
949 SendError("Protocol error - Missing SID");
953 irc::string servername = params[0].c_str();
954 std::string sname = params[0];
955 std::string password = params[1];
956 std::string sid = params[3];
957 std::string description = params[4];
958 int hops = atoi(params[2].c_str());
960 this->InboundServerName = sname;
961 this->InboundDescription = description;
962 this->InboundSID = sid;
965 this->SendCapabilities();
969 this->SendError("Server too far away for authentication");
970 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
974 if (!Utils->IsSID(sid))
976 this->SendError("Invalid format server ID: "+sid+"!");
980 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
982 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password) || x->RecvPass == password && (this->GetTheirChallenge().empty()))))
984 /* First check for instances of the server that are waiting between the inbound and outbound SERVER command */
985 TreeSocket* CheckDupeSocket = Utils->FindBurstingServer(sname);
988 /* If we find one, we abort the link to prevent a race condition */
989 this->SendError("Negotiation collision");
990 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists in a negotiating state.");
991 CheckDupeSocket->SendError("Negotiation collision");
992 Instance->SE->DelFd(CheckDupeSocket);
993 CheckDupeSocket->Close();
996 /* Check for fully initialized instances of the server by id */
997 Instance->Log(DEBUG,"Looking for dupe SID %s", sid.c_str());
998 TreeServer* CheckDupeSID = Utils->FindServerID(sid);
1001 this->SendError("Server ID "+CheckDupeSID->GetID()+" already exists on server "+CheckDupeSID->GetName()+"!");
1002 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupeSID->GetID()+
1003 "' already exists on server "+CheckDupeSID->GetName());
1006 /* Now check for fully initialized instances of the server by name */
1007 TreeServer* CheckDupe = Utils->FindServer(sname);
1010 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
1011 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
1014 this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
1017 std::string name = InspSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
1018 this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
1021 Utils->AddBurstingServer(sname,this);
1023 // this is good. Send our details: Our server name and description and hopcount of 0,
1024 // along with the sendpass from this block.
1025 this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+Instance->Config->GetSID()+" :"+this->Instance->Config->ServerDesc);
1026 // move to the next state, we are now waiting for THEM.
1027 this->LinkState = WAIT_AUTH_2;
1031 this->SendError("Invalid credentials");
1032 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
1036 void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
1039 irc::tokenstream tokens(line);
1041 while (tokens.GetToken(param))
1048 bool TreeSocket::ProcessLine(std::string &line)
1050 std::deque<std::string> params;
1051 irc::string command;
1054 line = line.substr(0, line.find_first_of("\r\n"));
1059 Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
1061 this->Split(line.c_str(),params);
1066 if ((params[0][0] == ':') && (params.size() > 1))
1068 prefix = params[0].substr(1);
1071 command = params[0].c_str();
1073 switch (this->LinkState)
1078 // Waiting for SERVER command from remote server. Server initiating
1079 // the connection sends the first SERVER command, listening server
1080 // replies with theirs if its happy, then if the initiator is happy,
1081 // it starts to send its net sync, which starts the merge, otherwise
1082 // it sends an ERROR.
1083 if (command == "PASS")
1085 /* Silently ignored */
1087 else if (command == "SERVER")
1089 return this->Inbound_Server(params);
1091 else if (command == "ERROR")
1093 return this->Error(params);
1095 else if (command == "USER")
1097 this->SendError("Client connections to this port are prohibited.");
1100 else if (command == "CAPAB")
1102 return this->Capab(params);
1106 irc::string error = "Invalid command in negotiation phase: " + command;
1107 this->SendError(assign(error));
1112 // Waiting for start of other side's netmerge to say they liked our
1114 if (command == "SERVER")
1116 // cant do this, they sent it to us in the WAIT_AUTH_1 state!
1120 else if (command == "BURST")
1122 if (params.size() && Utils->EnableTimeSync)
1124 bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
1125 time_t them = atoi(params[0].c_str());
1126 time_t delta = them - Instance->Time(false);
1127 if ((delta < -600) || (delta > 600))
1129 Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
1130 SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
1133 else if ((delta < -30) || (delta > 30))
1135 Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
1138 if (!Utils->MasterTime && !we_have_delta)
1140 this->Instance->SetTimeDelta(delta);
1141 // Send this new timestamp to any other servers
1142 Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
1145 this->LinkState = CONNECTED;
1146 Link* lnk = Utils->FindLink(InboundServerName);
1148 Node = new TreeServer(this->Utils, this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
1150 if (Node->DuplicateID())
1152 this->SendError("Server ID "+InboundSID+" already exists on the network!");
1153 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+InboundServerName+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link.");
1156 Utils->DelBurstingServer(this);
1157 Utils->TreeRoot->AddChild(Node);
1159 params.push_back(InboundServerName);
1160 params.push_back("*");
1161 params.push_back("1");
1162 params.push_back(InboundSID);
1163 params.push_back(":"+InboundDescription);
1164 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,InboundServerName);
1165 this->bursting = true;
1166 this->DoBurst(Node);
1168 else if (command == "ERROR")
1170 return this->Error(params);
1172 else if (command == "CAPAB")
1174 return this->Capab(params);
1179 this->SendError("Internal error -- listening socket accepted its own descriptor!!!");
1183 if (command == "SERVER")
1185 // another server we connected to, which was in WAIT_AUTH_1 state,
1186 // has just sent us their credentials. If we get this far, theyre
1187 // happy with OUR credentials, and they are now in WAIT_AUTH_2 state.
1188 // if we're happy with this, we should send our netburst which
1189 // kickstarts the merge.
1190 return this->Outbound_Reply_Server(params);
1192 else if (command == "ERROR")
1194 return this->Error(params);
1196 else if (command == "CAPAB")
1198 return this->Capab(params);
1202 // This is the 'authenticated' state, when all passwords
1203 // have been exchanged and anything past this point is taken
1206 if (!prefix.empty())
1208 std::string direction = prefix;
1210 userrec *t = this->Instance->FindUUID(prefix);
1213 direction = t->server;
1216 TreeServer* route_back_again = Utils->BestRouteTo(direction);
1217 if ((!route_back_again) || (route_back_again->GetSocket() != this))
1219 if (route_back_again)
1220 Instance->Log(DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
1224 * When there is activity on the socket, reset the ping counter so
1225 * that we're not wasting bandwidth pinging an active server.
1227 route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
1228 route_back_again->SetPingFlag();
1232 TreeServer* n = Utils->FindServer(GetName());
1234 prefix = n->GetID();
1239 if ((command == "MODE") && (params.size() >= 2))
1241 chanrec* channel = Instance->FindChan(params[0]);
1244 userrec* x = Instance->FindNick(prefix);
1247 if (warned.find(x->server) == warned.end())
1249 Instance->Log(DEFAULT,"WARNING: I revceived modes '%s' from another server '%s'. This is not compliant with InspIRCd. Please check that server for bugs.", params[1].c_str(), x->server);
1250 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending nonstandard modes: '%s MODE %s' where FMODE should be used, and may cause desyncs.", x->server, x->nick, params[1].c_str());
1251 warned[x->server] = x->nick;
1257 if (command == "SVSMODE")
1259 /* Services expects us to implement
1260 * SVSMODE. In inspircd its the same as
1266 /* Yes, know, this is a mess. Its reasonably fast though as we're
1267 * working with std::string here.
1269 if (command == "UID")
1271 return this->ParseUID(prefix, params);
1273 else if (command == "FJOIN")
1275 TreeServer* ServerSource = Utils->FindServer(prefix);
1277 Utils->SetRemoteBursting(ServerSource, false);
1278 return this->ForceJoin(prefix,params);
1280 else if (command == "STATS")
1282 return this->Stats(prefix, params);
1284 else if (command == "MOTD")
1286 return this->Motd(prefix, params);
1288 else if (command == "KILL" && Utils->IsServer(prefix))
1290 return this->RemoteKill(prefix,params);
1292 else if (command == "MODULES")
1294 return this->Modules(prefix, params);
1296 else if (command == "ADMIN")
1298 return this->Admin(prefix, params);
1300 else if (command == "SERVER")
1302 return this->RemoteServer(prefix,params);
1304 else if (command == "ERROR")
1306 return this->Error(params);
1308 else if (command == "OPERTYPE")
1310 return this->OperType(prefix,params);
1312 else if (command == "FMODE")
1314 TreeServer* ServerSource = Utils->FindServer(prefix);
1316 Utils->SetRemoteBursting(ServerSource, false);
1317 return this->ForceMode(prefix,params);
1319 else if (command == "FTOPIC")
1321 return this->ForceTopic(prefix,params);
1323 else if (command == "REHASH")
1325 return this->RemoteRehash(prefix,params);
1327 else if (command == "METADATA")
1329 return this->MetaData(prefix,params);
1331 else if (command == "REMSTATUS")
1333 return this->RemoveStatus(prefix,params);
1335 else if (command == "PING")
1338 * We just got a ping from a server that's bursting.
1339 * This can't be right, so set them to not bursting, and
1340 * apply their lines.
1342 TreeServer* ServerSource = Utils->FindServer(prefix);
1344 Utils->SetRemoteBursting(ServerSource, false);
1348 this->bursting = false;
1349 Instance->XLines->apply_lines(Utils->lines_to_apply);
1350 Utils->lines_to_apply = 0;
1353 return this->LocalPing(prefix,params);
1355 else if (command == "PONG")
1358 * We just got a pong from a server that's bursting.
1359 * This can't be right, so set them to not bursting, and
1360 * apply their lines.
1362 TreeServer* ServerSource = Utils->FindServer(prefix);
1364 Utils->SetRemoteBursting(ServerSource, false);
1368 this->bursting = false;
1369 Instance->XLines->apply_lines(Utils->lines_to_apply);
1370 Utils->lines_to_apply = 0;
1373 return this->LocalPong(prefix,params);
1375 else if (command == "VERSION")
1377 return this->ServerVersion(prefix,params);
1379 else if (command == "FHOST")
1381 return this->ChangeHost(prefix,params);
1383 else if (command == "FNAME")
1385 return this->ChangeName(prefix,params);
1387 else if (command == "ADDLINE")
1389 TreeServer* ServerSource = Utils->FindServer(prefix);
1391 Utils->SetRemoteBursting(ServerSource, false);
1392 return this->AddLine(prefix,params);
1394 else if (command == "SVSNICK")
1396 return this->ForceNick(prefix,params);
1398 else if (command == "OPERQUIT")
1400 return this->OperQuit(prefix,params);
1402 else if (command == "IDLE")
1404 return this->Whois(prefix,params);
1406 else if (command == "PUSH")
1408 return this->Push(prefix,params);
1410 else if (command == "TIMESET")
1412 return this->HandleSetTime(prefix, params);
1414 else if (command == "TIME")
1416 return this->Time(prefix,params);
1418 else if ((command == "KICK") && (Utils->IsServer(prefix)))
1420 std::string sourceserv = this->myhost;
1421 if (params.size() == 3)
1423 userrec* user = this->Instance->FindNick(params[1]);
1424 chanrec* chan = this->Instance->FindChan(params[0]);
1427 if (!chan->ServerKickUser(user, params[2].c_str(), false))
1428 /* Yikes, the channels gone! */
1432 if (!this->InboundServerName.empty())
1434 sourceserv = this->InboundServerName;
1436 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1438 else if (command == "SVSJOIN")
1440 return this->ServiceJoin(prefix,params);
1442 else if (command == "SVSPART")
1444 return this->ServicePart(prefix,params);
1446 else if (command == "SQUIT")
1448 if (params.size() == 2)
1450 this->Squit(Utils->FindServer(params[0]),params[1]);
1454 else if (command == "OPERNOTICE")
1456 std::string sourceserv = this->myhost;
1457 if (!this->InboundServerName.empty())
1458 sourceserv = this->InboundServerName;
1459 if (params.size() >= 1)
1460 Instance->WriteOpers("*** From " + sourceserv + ": " + params[0]);
1461 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1463 else if (command == "MODENOTICE")
1465 std::string sourceserv = this->myhost;
1466 if (!this->InboundServerName.empty())
1467 sourceserv = this->InboundServerName;
1468 if (params.size() >= 2)
1470 Instance->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", sourceserv.c_str(), params[1].c_str());
1472 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1474 else if (command == "SNONOTICE")
1476 std::string sourceserv = this->myhost;
1477 if (!this->InboundServerName.empty())
1478 sourceserv = this->InboundServerName;
1479 if (params.size() >= 2)
1481 Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + sourceserv + ": "+ params[1]);
1483 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
1485 else if (command == "ENDBURST")
1487 this->bursting = false;
1488 Instance->XLines->apply_lines(Utils->lines_to_apply);
1489 Utils->lines_to_apply = 0;
1490 std::string sourceserv = this->myhost;
1491 if (!this->InboundServerName.empty())
1492 sourceserv = this->InboundServerName;
1493 this->Instance->SNO->WriteToSnoMask('l',"Received end of netburst from \2%s\2",sourceserv.c_str());
1495 Event rmode((char*)sourceserv.c_str(), (Module*)Utils->Creator, "new_server");
1496 rmode.Send(Instance);
1503 * Not a special s2s command. Emulate the user doing it.
1504 * This saves us having a huge ugly command parser again.
1506 userrec *who = this->Instance->FindUUID(prefix);
1508 std::string sourceserv = this->myhost;
1509 if (!this->InboundServerName.empty())
1511 sourceserv = this->InboundServerName;
1513 if ((!who) && (command == "MODE"))
1515 if (Utils->IsServer(prefix))
1517 const char* modelist[MAXPARAMETERS];
1518 for (size_t i = 0; i < params.size(); i++)
1519 modelist[i] = params[i].c_str();
1520 this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
1521 /* Hot potato! pass it on! */
1522 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1527 if (command == "NICK")
1529 if (params.size() != 2)
1531 SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
1534 /* Update timestamp on user when they change nicks */
1535 who->age = atoi(params[1].c_str());
1537 /* On nick messages, check that the nick doesnt
1538 * already exist here. If it does, kill their copy,
1541 userrec* x = this->Instance->FindNickOnly(params[0]);
1542 if ((x) && (x != who))
1545 /* x is local, who is remote */
1546 collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
1547 if (collideret != 1)
1550 * Remote client lost, or both lost,
1551 * parsing this nickchange would be
1552 * pointless, as the incoming client's
1553 * server will soon recieve SVSNICK to
1554 * change its nick to its UID. :)
1560 Old nickname collision logic..
1561 std::deque<std::string> p;
1562 p.push_back(params[0]);
1563 p.push_back(":Nickname collision ("+prefix+" -> "+params[0]+")");
1564 Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
1566 p.push_back(prefix);
1567 p.push_back(":Nickname collision");
1568 Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
1569 userrec::QuitUser(this->Instance,x,"Nickname collision ("+prefix+" -> "+params[0]+")");
1570 userrec* y = this->Instance->FindNick(prefix);
1573 userrec::QuitUser(this->Instance,y,"Nickname collision");
1575 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1580 target = who->server;
1581 const char* strparams[127];
1582 for (unsigned int q = 0; q < params.size(); q++)
1584 strparams[q] = params[q].c_str();
1586 switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
1589 this->SendError("Unrecognised command '"+std::string(command.c_str())+"' -- possibly loaded mismatched modules");
1596 /* CMD_SUCCESS and CMD_USER_DELETED fall through here */
1602 // its not a user. Its either a server, or somethings screwed up.
1603 if (Utils->IsServer(prefix))
1604 target = this->Instance->Config->GetSID();
1608 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
1617 std::string TreeSocket::GetName()
1619 std::string sourceserv = this->myhost;
1620 if (!this->InboundServerName.empty())
1622 sourceserv = this->InboundServerName;
1627 void TreeSocket::OnTimeout()
1629 if (this->LinkState == CONNECTING)
1631 Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
1632 Link* MyLink = Utils->FindLink(myhost);
1634 Utils->DoFailOver(MyLink);
1638 void TreeSocket::OnClose()
1640 if (this->LinkState == LISTENER)
1643 // Connection closed.
1644 // If the connection is fully up (state CONNECTED)
1645 // then propogate a netsplit to all peers.
1646 std::string quitserver = this->myhost;
1647 if (!this->InboundServerName.empty())
1649 quitserver = this->InboundServerName;
1651 TreeServer* s = Utils->FindServer(quitserver);
1654 Squit(s,"Remote host closed the connection");
1657 if (!quitserver.empty())
1659 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
1660 time_t server_uptime = Instance->Time() - this->age;
1662 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
1666 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
1668 /* To prevent anyone from attempting to flood opers/DDoS by connecting to the server port,
1669 * or discovering if this port is the server port, we don't allow connections from any
1670 * IPs for which we don't have a link block.
1674 found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
1677 for (vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
1678 if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
1683 Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
1684 Instance->SE->Close(newsock);
1689 TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
1690 s = s; /* Whinge whinge whinge, thats all GCC ever does. */