X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=dcfb2b4aad05bb60e94167d17792f0fad436ec76;hb=599941771e7d174c3e15f65ab2a1d7d9fefbd5f3;hp=dcf4652c7bb77fe6d23c75023030bfadcf1cf54c;hpb=6427e2077e3881845650e0dc9bb37839c17dfca3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index dcf4652c7..dcfb2b4aa 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -49,7 +49,7 @@ bool TreeSocket::Error(std::deque ¶ms) { 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; } @@ -294,53 +294,6 @@ bool TreeSocket::OperQuit(const std::string &prefix, std::deque &pa 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 ¶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 ¶ms) { if (params.size() < 2) @@ -377,30 +330,25 @@ bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque } bool TreeSocket::RemoteKill(const std::string &prefix, std::deque ¶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; @@ -857,6 +805,9 @@ bool TreeSocket::Outbound_Reply_Server(std::deque ¶ms) this->InboundServerName = sname; this->InboundDescription = description; + if (!sentcapab) + this->SendCapabilities(); + if (hops) { this->SendError("Server too far away for authentication"); @@ -910,6 +861,9 @@ bool TreeSocket::Inbound_Server(std::deque ¶ms) this->InboundServerName = sname; this->InboundDescription = description; + if (!sentcapab) + this->SendCapabilities(); + if (hops) { this->SendError("Server too far away for authentication"); @@ -931,7 +885,6 @@ bool TreeSocket::Inbound_Server(std::deque ¶ms) CheckDupeSocket->SendError("Negotiation collision"); Instance->SE->DelFd(CheckDupeSocket); CheckDupeSocket->Close(); - delete CheckDupeSocket; return false; } /* Now check for fully initialized instances of the server */ @@ -1189,7 +1142,7 @@ bool TreeSocket::ProcessLine(std::string &line) */ 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. */ @@ -1212,6 +1165,10 @@ bool TreeSocket::ProcessLine(std::string &line) { 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); @@ -1239,10 +1196,6 @@ bool TreeSocket::ProcessLine(std::string &line) 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); @@ -1261,7 +1214,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else if (command == "PING") { - if (prefix == "") + if (prefix.empty()) prefix = this->GetName(); /* * We just got a ping from a server that's bursting. @@ -1283,7 +1236,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else if (command == "PONG") { - if (prefix == "") + if (prefix.empty()) prefix = this->GetName(); /* * We just got a pong from a server that's bursting. @@ -1324,7 +1277,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else if (command == "SVSNICK") { - if (prefix == "") + if (prefix.empty()) { prefix = this->GetName(); } @@ -1334,10 +1287,6 @@ bool TreeSocket::ProcessLine(std::string &line) { return this->OperQuit(prefix,params); } - else if (command == "RSQUIT") - { - return this->RemoteSquit(prefix, params); - } else if (command == "IDLE") { return this->Whois(prefix,params); @@ -1368,7 +1317,7 @@ bool TreeSocket::ProcessLine(std::string &line) delete chan; } } - if (this->InboundServerName != "") + if (!this->InboundServerName.empty()) { sourceserv = this->InboundServerName; } @@ -1376,7 +1325,7 @@ bool TreeSocket::ProcessLine(std::string &line) } else if (command == "SVSJOIN") { - if (prefix == "") + if (prefix.empty()) { prefix = this->GetName(); } @@ -1393,7 +1342,7 @@ bool TreeSocket::ProcessLine(std::string &line) 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]); @@ -1402,7 +1351,7 @@ bool TreeSocket::ProcessLine(std::string &line) else if (command == "MODENOTICE") { std::string sourceserv = this->myhost; - if (this->InboundServerName != "") + if (!this->InboundServerName.empty()) sourceserv = this->InboundServerName; if (params.size() >= 2) { @@ -1413,7 +1362,7 @@ bool TreeSocket::ProcessLine(std::string &line) else if (command == "SNONOTICE") { std::string sourceserv = this->myhost; - if (this->InboundServerName != "") + if (!this->InboundServerName.empty()) sourceserv = this->InboundServerName; if (params.size() >= 2) { @@ -1427,10 +1376,8 @@ bool TreeSocket::ProcessLine(std::string &line) 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"); @@ -1445,7 +1392,7 @@ bool TreeSocket::ProcessLine(std::string &line) // 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; } @@ -1534,7 +1481,7 @@ bool TreeSocket::ProcessLine(std::string &line) std::string TreeSocket::GetName() { std::string sourceserv = this->myhost; - if (this->InboundServerName != "") + if (!this->InboundServerName.empty()) { sourceserv = this->InboundServerName; } @@ -1558,7 +1505,7 @@ void TreeSocket::OnClose() // 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; } @@ -1568,7 +1515,7 @@ void TreeSocket::OnClose() 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;