* ---------------------------------------------------
*/
+#include "inspircd.h"
#include "configreader.h"
#include "users.h"
#include "channels.h"
#include "commands/cmd_whois.h"
#include "commands/cmd_stats.h"
#include "socket.h"
-#include "inspircd.h"
#include "wildcard.h"
#include "xline.h"
#include "transport.h"
/* $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 */
+static std::map<std::string, std::string> warned; /* Server names that have had protocol violation warnings displayed for them */
+
int TreeSocket::WriteLine(std::string line)
{
- Instance->Log(DEBUG, "-> %s", line.c_str());
+ Instance->Log(DEBUG, "S[%d] -> %s", this->GetFd(), line.c_str());
line.append("\r\n");
return this->Write(line);
}
{
if (params.size() < 1)
return false;
- this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(InboundServerName != "" ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
+ this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
/* we will return false to cause the socket to close. */
return false;
}
if (u)
{
- Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
u->SetOperQuit(params[0]);
+ params[0] = ":" + params[0];
+ Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
}
return true;
}
-/*
- * Remote SQUIT (RSQUIT). Routing works similar to SVSNICK: Route it to the server that the target is connected to locally,
- * then let that server do the dirty work (squit it!). Example:
- * A -> B -> C -> D: oper on A squits D, A routes to B, B routes to C, C notices D connected locally, kills it. -- w00t
- */
-bool TreeSocket::RemoteSquit(const std::string &prefix, std::deque<std::string> ¶ms)
-{
- /* ok.. :w00t RSQUIT jupe.barafranca.com :reason here */
- if (params.size() < 2)
- return true;
-
- TreeServer* s = Utils->FindServerMask(params[0]);
-
- if (s)
- {
- if (s == Utils->TreeRoot)
- {
- this->Instance->SNO->WriteToSnoMask('l',"What the fuck, I recieved a remote SQUIT for myself? :< (from %s", prefix.c_str());
- return true;
- }
-
- TreeSocket* sock = s->GetSocket();
-
- if (sock)
- {
- /* it's locally connected, KILL IT! */
- Instance->SNO->WriteToSnoMask('l',"RSQUIT: Server \002%s\002 removed from network by %s: %s", params[0].c_str(), prefix.c_str(), params[1].c_str());
- sock->Squit(s,"Server quit by " + prefix + ": " + params[1]);
- Instance->SE->DelFd(sock);
- sock->Close();
- delete sock;
- }
- else
- {
- /* route the rsquit */
- params[1] = ":" + params[1];
- Utils->DoOneToOne(prefix, "RSQUIT", params, params[0]);
- }
- }
- else
- {
- /* mother fucker! it doesn't exist */
- }
-
- return true;
-}
-
bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> ¶ms)
{
if (params.size() < 2)
}
bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> ¶ms)
-{
+{
if (params.size() != 2)
return true;
- std::string nick = params[0];
- userrec* u = this->Instance->FindNick(prefix);
- userrec* who = this->Instance->FindNick(nick);
+ userrec* who = this->Instance->FindNick(params[0]);
if (who)
{
- /* Prepend kill source, if we don't have one */
- std::string sourceserv = prefix;
- if (u)
- {
- sourceserv = u->server;
- }
+ /* Prepend kill source, if we don't have one */
if (*(params[1].c_str()) != '[')
{
- params[1] = "[" + sourceserv + "] Killed (" + params[1] +")";
+ params[1] = "[" + prefix + "] Killed (" + params[1] +")";
}
std::string reason = params[1];
params[1] = ":" + params[1];
- Utils->DoOneToAllButSender(prefix,"KILL",params,sourceserv);
- who->Write(":%s KILL %s :%s (%s)", sourceserv.c_str(), who->nick, sourceserv.c_str(), reason.c_str());
+ Utils->DoOneToAllButSender(prefix,"KILL",params,prefix);
+ // NOTE: This is safe with kill hiding on, as RemoteKill is only reached if we have a server prefix.
+ // in short this is not executed for USERS.
+ who->Write(":%s KILL %s :%s (%s)", prefix.c_str(), who->nick, prefix.c_str(), reason.c_str());
userrec::QuitUser(this->Instance,who,reason);
}
return true;
TreeServer* ServerSource = Utils->FindServer(prefix);
if (ServerSource)
{
+ Utils->SetRemoteBursting(ServerSource, false);
+
if (params[0] == "*")
{
FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
TreeServer* Node = new TreeServer(this->Utils,this->Instance,servername,description,ParentOfThis,NULL, lnk ? lnk->Hidden : false);
ParentOfThis->AddChild(Node);
params[3] = ":" + params[3];
+ Utils->SetRemoteBursting(Node, true);
Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
return true;
this->InboundServerName = sname;
this->InboundDescription = description;
+ if (!sentcapab)
+ this->SendCapabilities();
+
if (hops)
{
this->SendError("Server too far away for authentication");
this->InboundServerName = sname;
this->InboundDescription = description;
+ if (!sentcapab)
+ this->SendCapabilities();
+
if (hops)
{
this->SendError("Server too far away for authentication");
CheckDupeSocket->SendError("Negotiation collision");
Instance->SE->DelFd(CheckDupeSocket);
CheckDupeSocket->Close();
- delete CheckDupeSocket;
return false;
}
/* Now check for fully initialized instances of the server */
irc::tokenstream tokens(line);
std::string param;
while (tokens.GetToken(param))
- n.push_back(param);
+ {
+ if (!param.empty())
+ n.push_back(param);
+ }
return;
}
if (line.empty())
return true;
- Instance->Log(DEBUG, "<- %s", line.c_str());
+ Instance->Log(DEBUG, "S[%d] <- %s", this->GetFd(), line.c_str());
this->Split(line.c_str(),params);
-
+
+ if (params.empty())
+ return true;
+
if ((params[0][0] == ':') && (params.size() > 1))
{
prefix = params[0].substr(1);
if ((delta < -300) || (delta > 300))
{
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));
- SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than ten minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
+ SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
return false;
}
else if ((delta < -30) || (delta > 30))
// have been exchanged and anything past this point is taken
// as gospel.
- if (prefix != "")
+ if (!prefix.empty())
{
std::string direction = prefix;
userrec* t = this->Instance->FindNick(prefix);
route_back_again->SetNextPingTime(time(NULL) + 60);
route_back_again->SetPingFlag();
}
+ else
+ {
+ prefix = this->GetName();
+ }
if ((command == "MODE") && (params.size() >= 2))
{
userrec* x = Instance->FindNick(prefix);
if (x)
{
- 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);
- Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending nonstandard modes: '%s MODE %s' and may cause desyncs.",
- x->server, x->nick, params[1].c_str());
+ if (warned.find(x->server) == warned.end())
+ {
+ 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);
+ 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());
+ warned[x->server] = x->nick;
+ }
}
}
}
*/
command = "MODE";
}
- std::string target = "";
+ std::string target;
/* Yes, know, this is a mess. Its reasonably fast though as we're
* working with std::string here.
*/
}
else if (command == "FJOIN")
{
+ TreeServer* ServerSource = Utils->FindServer(prefix);
+ if (ServerSource)
+ Utils->SetRemoteBursting(ServerSource, false);
return this->ForceJoin(prefix,params);
}
else if (command == "STATS")
{
return this->Motd(prefix, params);
}
+ else if (command == "KILL" && Utils->IsServer(prefix))
+ {
+ return this->RemoteKill(prefix,params);
+ }
else if (command == "MODULES")
{
return this->Modules(prefix, params);
}
else if (command == "FMODE")
{
+ TreeServer* ServerSource = Utils->FindServer(prefix);
+ if (ServerSource)
+ Utils->SetRemoteBursting(ServerSource, false);
return this->ForceMode(prefix,params);
}
- else if (command == "KILL")
- {
- return this->RemoteKill(prefix,params);
- }
else if (command == "FTOPIC")
{
return this->ForceTopic(prefix,params);
}
else if (command == "PING")
{
+ if (prefix.empty())
+ prefix = this->GetName();
/*
* We just got a ping from a server that's bursting.
* This can't be right, so set them to not bursting, and
* apply their lines.
*/
+ TreeServer* ServerSource = Utils->FindServer(prefix);
+ if (ServerSource)
+ Utils->SetRemoteBursting(ServerSource, false);
+
if (this->bursting)
{
this->bursting = false;
Instance->XLines->apply_lines(Utils->lines_to_apply);
Utils->lines_to_apply = 0;
}
- if (prefix == "")
- {
- prefix = this->GetName();
- }
+
return this->LocalPing(prefix,params);
}
else if (command == "PONG")
{
+ if (prefix.empty())
+ prefix = this->GetName();
/*
* We just got a pong from a server that's bursting.
* This can't be right, so set them to not bursting, and
* apply their lines.
*/
+ TreeServer* ServerSource = Utils->FindServer(prefix);
+ if (ServerSource)
+ Utils->SetRemoteBursting(ServerSource, false);
+
if (this->bursting)
{
this->bursting = false;
Instance->XLines->apply_lines(Utils->lines_to_apply);
Utils->lines_to_apply = 0;
}
- if (prefix == "")
- {
- prefix = this->GetName();
- }
+
return this->LocalPong(prefix,params);
}
else if (command == "VERSION")
}
else if (command == "ADDLINE")
{
+ TreeServer* ServerSource = Utils->FindServer(prefix);
+ if (ServerSource)
+ Utils->SetRemoteBursting(ServerSource, false);
return this->AddLine(prefix,params);
}
else if (command == "SVSNICK")
{
- if (prefix == "")
+ if (prefix.empty())
{
prefix = this->GetName();
}
{
return this->OperQuit(prefix,params);
}
- else if (command == "RSQUIT")
- {
- return this->RemoteSquit(prefix, params);
- }
else if (command == "IDLE")
{
return this->Whois(prefix,params);
delete chan;
}
}
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
{
sourceserv = this->InboundServerName;
}
}
else if (command == "SVSJOIN")
{
- if (prefix == "")
+ if (prefix.empty())
{
prefix = this->GetName();
}
else if (command == "OPERNOTICE")
{
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
sourceserv = this->InboundServerName;
if (params.size() >= 1)
Instance->WriteOpers("*** From " + sourceserv + ": " + params[0]);
else if (command == "MODENOTICE")
{
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
sourceserv = this->InboundServerName;
if (params.size() >= 2)
{
else if (command == "SNONOTICE")
{
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
sourceserv = this->InboundServerName;
if (params.size() >= 2)
{
Instance->XLines->apply_lines(Utils->lines_to_apply);
Utils->lines_to_apply = 0;
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
- {
+ if (!this->InboundServerName.empty())
sourceserv = this->InboundServerName;
- }
this->Instance->SNO->WriteToSnoMask('l',"Received end of netburst from \2%s\2",sourceserv.c_str());
Event rmode((char*)sourceserv.c_str(), (Module*)Utils->Creator, "new_server");
// this saves us having a huge ugly parser.
userrec* who = this->Instance->FindNick(prefix);
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
{
sourceserv = this->InboundServerName;
}
std::string TreeSocket::GetName()
{
std::string sourceserv = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
{
sourceserv = this->InboundServerName;
}
// If the connection is fully up (state CONNECTED)
// then propogate a netsplit to all peers.
std::string quitserver = this->myhost;
- if (this->InboundServerName != "")
+ if (!this->InboundServerName.empty())
{
quitserver = this->InboundServerName;
}
Squit(s,"Remote host closed the connection");
}
- if (quitserver != "")
+ if (!quitserver.empty())
+ {
this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
+ time_t server_uptime = Instance->Time() - this->age;
+ if (server_uptime)
+ Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+ }
}
int TreeSocket::OnIncomingConnection(int newsock, char* ip)