diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-01-05 15:04:01 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-01-05 15:04:01 +0100 |
commit | 11916574f67962dce1d7a2fdf7ef6a3d2d1fa49f (patch) | |
tree | 1c3c602de5512a62e2db96652ddd540e6e53e821 /src/modules | |
parent | 2f181fef775da4a686a892c06af843dddfb7950a (diff) |
Introduce Server class
- Replaces std::string server in User
- Replaces InspIRCd::ULine() and SilentULine()
Diffstat (limited to 'src/modules')
39 files changed, 123 insertions, 87 deletions
diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 78628cf06..5fea846da 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -274,7 +274,7 @@ class ModuleAlias : public Module } if ((u != NULL) && (!a->RequiredNick.empty()) && (a->ULineOnly)) { - if (!ServerInstance->ULine(u->server)) + if (!u->server->IsULine()) { ServerInstance->SNO->WriteToSnoMask('a', "NOTICE -- Service "+a->RequiredNick+" required by alias "+a->AliasedCommand+" is not on a u-lined server, possibly underhanded antics detected!"); user->WriteNumeric(ERR_NOSUCHNICK, a->RequiredNick + " :is an imposter! Please inform an IRC operator as soon as possible."); diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 84e147f7b..d12d2728d 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -126,7 +126,7 @@ class CommandCheck : public Command user->SendText(checkstr + " realname " + targuser->fullname); user->SendText(checkstr + " modes +" + targuser->FormatModes()); user->SendText(checkstr + " snomasks " + GetSnomasks(targuser)); - user->SendText(checkstr + " server " + targuser->server); + user->SendText(checkstr + " server " + targuser->server->GetName()); user->SendText(checkstr + " uid " + targuser->uuid); user->SendText(checkstr + " signon " + timestring(targuser->signon)); user->SendText(checkstr + " nickts " + timestring(targuser->age)); diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index f79ae4624..eefac00f1 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -64,7 +64,7 @@ class CommandChghost : public Command if (IS_LOCAL(dest)) { - if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server))) + if ((dest->ChangeDisplayedHost(parameters[1])) && (!user->server->IsULine())) { // fix by brain - ulines set hosts silently ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost); diff --git a/src/modules/m_chgident.cpp b/src/modules/m_chgident.cpp index 6d5df7be5..4607ae1a3 100644 --- a/src/modules/m_chgident.cpp +++ b/src/modules/m_chgident.cpp @@ -61,7 +61,7 @@ class CommandChgident : public Command { dest->ChangeIdent(parameters[1]); - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) ServerInstance->SNO->WriteGlobalSno('a', "%s used CHGIDENT to change %s's ident to '%s'", user->nick.c_str(), dest->nick.c_str(), dest->ident.c_str()); } diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index b955184e0..eab53b9bc 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -45,7 +45,7 @@ class ModulePrivacyMode : public Module if (target_type == TYPE_USER) { User* t = (User*)dest; - if (!user->IsOper() && (t->IsModeSet(pm)) && (!ServerInstance->ULine(user->server)) && !user->SharesChannelWith(t)) + if (!user->IsOper() && (t->IsModeSet(pm)) && (!user->server->IsULine()) && !user->SharesChannelWith(t)) { user->WriteNumeric(ERR_CANTSENDTOUSER, "%s :You are not permitted to send private messages to this user (+c set)", t->nick.c_str()); return MOD_RES_DENY; diff --git a/src/modules/m_deaf.cpp b/src/modules/m_deaf.cpp index 468f1046a..26d5029e8 100644 --- a/src/modules/m_deaf.cpp +++ b/src/modules/m_deaf.cpp @@ -109,7 +109,7 @@ class ModuleDeaf : public Module if (is_bypasschar && is_bypasschar_uline) continue; /* deliver message */ - is_a_uline = ServerInstance->ULine(i->first->server); + is_a_uline = i->first->server->IsULine(); /* matched a U-line only bypass */ if (is_bypasschar_uline && is_a_uline) continue; /* deliver message */ diff --git a/src/modules/m_lockserv.cpp b/src/modules/m_lockserv.cpp index 56c7b9c94..65b9aa036 100644 --- a/src/modules/m_lockserv.cpp +++ b/src/modules/m_lockserv.cpp @@ -44,7 +44,7 @@ class CommandLockserv : public Command } locked = true; - user->WriteNumeric(988, "%s :Closed for new connections", user->server.c_str()); + user->WriteNumeric(988, "%s :Closed for new connections", user->server->GetName().c_str()); ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str()); return CMD_SUCCESS; } @@ -69,7 +69,7 @@ class CommandUnlockserv : public Command } locked = false; - user->WriteNumeric(989, "%s :Open for new connections", user->server.c_str()); + user->WriteNumeric(989, "%s :Open for new connections", user->server->GetName().c_str()); ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str()); return CMD_SUCCESS; } diff --git a/src/modules/m_passforward.cpp b/src/modules/m_passforward.cpp index 589fc06a6..b5696c8f4 100644 --- a/src/modules/m_passforward.cpp +++ b/src/modules/m_passforward.cpp @@ -82,7 +82,7 @@ class ModulePassForward : public Module { /* Check if nick exists and its server is ulined */ User* u = ServerInstance->FindNick(nickrequired); - if (!u || !ServerInstance->ULine(u->server)) + if (!u || !u->server->IsULine()) return; } diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index d18f57916..4dcd5aaa1 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -81,7 +81,7 @@ class RemoveBase : public Command int ulevel = channel->GetPrefixValue(user); int tlevel = channel->GetPrefixValue(target); - if (ServerInstance->ULine(target->server)) + if (target->server->IsULine()) { user->WriteNumeric(482, "%s :Only a u-line may remove a u-line from a channel.", channame.c_str()); return CMD_FAILURE; diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp index 9d1e34ff3..eda58ef96 100644 --- a/src/modules/m_sajoin.cpp +++ b/src/modules/m_sajoin.cpp @@ -38,7 +38,7 @@ class CommandSajoin : public Command User* dest = ServerInstance->FindNick(parameters[0]); if ((dest) && (dest->registered == REG_ALL)) { - if (ServerInstance->ULine(dest->server)) + if (dest->server->IsULine()) { user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client"); return CMD_FAILURE; diff --git a/src/modules/m_sakick.cpp b/src/modules/m_sakick.cpp index 0e37acc3f..911b826dc 100644 --- a/src/modules/m_sakick.cpp +++ b/src/modules/m_sakick.cpp @@ -40,7 +40,7 @@ class CommandSakick : public Command { const std::string& reason = (parameters.size() > 2) ? parameters[2] : dest->nick; - if (ServerInstance->ULine(dest->server)) + if (dest->server->IsULine()) { user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client"); return CMD_FAILURE; diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp index 5f7860677..4ce6a5fb2 100644 --- a/src/modules/m_sanick.cpp +++ b/src/modules/m_sanick.cpp @@ -40,7 +40,7 @@ class CommandSanick : public Command /* Do local sanity checks and bails */ if (IS_LOCAL(user)) { - if (target && ServerInstance->ULine(target->server)) + if (target && target->server->IsULine()) { user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client"); return CMD_FAILURE; diff --git a/src/modules/m_sapart.cpp b/src/modules/m_sapart.cpp index 6de01c852..fa5ab176a 100644 --- a/src/modules/m_sapart.cpp +++ b/src/modules/m_sapart.cpp @@ -43,7 +43,7 @@ class CommandSapart : public Command if (parameters.size() > 2) reason = parameters[2]; - if (ServerInstance->ULine(dest->server)) + if (dest->server->IsULine()) { user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client"); return CMD_FAILURE; diff --git a/src/modules/m_saquit.cpp b/src/modules/m_saquit.cpp index 27ef86eb2..ee6de5e94 100644 --- a/src/modules/m_saquit.cpp +++ b/src/modules/m_saquit.cpp @@ -37,7 +37,7 @@ class CommandSaquit : public Command User* dest = ServerInstance->FindNick(parameters[0]); if ((dest) && (!IS_SERVER(dest))) { - if (ServerInstance->ULine(dest->server)) + if (dest->server->IsULine()) { user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client"); return CMD_FAILURE; diff --git a/src/modules/m_serverban.cpp b/src/modules/m_serverban.cpp index 87fe08670..f51d1d373 100644 --- a/src/modules/m_serverban.cpp +++ b/src/modules/m_serverban.cpp @@ -31,7 +31,7 @@ class ModuleServerBan : public Module { if ((mask.length() > 2) && (mask[0] == 's') && (mask[1] == ':')) { - if (InspIRCd::Match(user->server, mask.substr(2))) + if (InspIRCd::Match(user->server->GetName(), mask.substr(2))) return MOD_RES_DENY; } return MOD_RES_PASSTHRU; diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index 9ae0c8d7a..7a3b2d352 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -110,7 +110,7 @@ class ModuleShowwhois : public Module else { std::vector<std::string> params; - params.push_back(dest->server); + params.push_back(dest->server->GetName()); params.push_back("WHOISNOTICE"); params.push_back(dest->uuid); params.push_back(source->uuid); diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index 1c76b72f7..03d2b7953 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -76,7 +76,7 @@ class CommandSVSSilence : public Command * style command so services can modify lots of entries at once. * leaving it backwards compatible for now as it's late. -- w */ - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) return CMD_FAILURE; User *u = ServerInstance->FindNick(parameters[0]); diff --git a/src/modules/m_spanningtree/addline.cpp b/src/modules/m_spanningtree/addline.cpp index c6ca17db0..dbf0003bf 100644 --- a/src/modules/m_spanningtree/addline.cpp +++ b/src/modules/m_spanningtree/addline.cpp @@ -60,7 +60,7 @@ CmdResult CommandAddLine::Handle(User* usr, std::vector<std::string>& params) params[1].c_str(),params[5].c_str()); } - TreeServer* remoteserver = Utils->FindServer(usr->server); + TreeServer* remoteserver = TreeServer::Get(usr); if (!remoteserver->bursting) { diff --git a/src/modules/m_spanningtree/commandbuilder.h b/src/modules/m_spanningtree/commandbuilder.h index aa4778fa9..cd627227a 100644 --- a/src/modules/m_spanningtree/commandbuilder.h +++ b/src/modules/m_spanningtree/commandbuilder.h @@ -133,8 +133,8 @@ class CmdBuilder return Utils->DoOneToOne(*this, target); } - bool Unicast(User* target) const + void Unicast(User* target) const { - return Unicast(target->server); + Utils->DoOneToOne(*this, target->server); } }; diff --git a/src/modules/m_spanningtree/fjoin.cpp b/src/modules/m_spanningtree/fjoin.cpp index 0fb446877..47d8efb82 100644 --- a/src/modules/m_spanningtree/fjoin.cpp +++ b/src/modules/m_spanningtree/fjoin.cpp @@ -73,7 +73,7 @@ CmdResult CommandFJoin::Handle(User* srcuser, std::vector<std::string>& params) if (!TS) { ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "*** BUG? *** TS of 0 sent to FJOIN. Are some services authors smoking craq, or is it 1970 again?. Dropped."); - ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FJOIN with a TS of zero. Total craq. Command was dropped.", srcuser->server.c_str()); + ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FJOIN with a TS of zero. Total craq. Command was dropped.", srcuser->server->GetName().c_str()); return CMD_INVALID; } @@ -157,7 +157,7 @@ CmdResult CommandFJoin::Handle(User* srcuser, std::vector<std::string>& params) } irc::modestacker modestack(true); - TreeSocket* src_socket = Utils->FindServer(srcuser->server)->GetSocket(); + TreeSocket* src_socket = TreeServer::Get(srcuser)->GetSocket(); /* Now, process every 'modes,uuid' pair */ irc::tokenstream users(*params.rbegin()); @@ -190,8 +190,8 @@ bool CommandFJoin::ProcessModeUUIDPair(const std::string& item, TreeSocket* src_ } /* Check that the user's 'direction' is correct */ - TreeServer* route_back_again = Utils->BestRouteTo(who->server); - if ((!route_back_again) || (route_back_again->GetSocket() != src_socket)) + TreeServer* route_back_again = TreeServer::Get(who); + if (route_back_again->GetSocket() != src_socket) { return true; } diff --git a/src/modules/m_spanningtree/fmode.cpp b/src/modules/m_spanningtree/fmode.cpp index 16af5ccc0..bad68f053 100644 --- a/src/modules/m_spanningtree/fmode.cpp +++ b/src/modules/m_spanningtree/fmode.cpp @@ -28,7 +28,7 @@ CmdResult CommandFMode::Handle(User* who, std::vector<std::string>& params) if (!TS) { ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "*** BUG? *** TS of 0 sent to FMODE. Are some services authors smoking craq, or is it 1970 again?. Dropping link."); - ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq, dropping link.", who->server.c_str()); + ServerInstance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending FMODE with a TS of zero. Total craq, dropping link.", who->server->GetName().c_str()); return CMD_INVALID; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 8c04d6c90..3efd012ba 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -52,6 +52,17 @@ SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module) { } +namespace +{ + void SetLocalUsersServer(Server* newserver) + { + ServerInstance->FakeClient->server = newserver; + const LocalUserList& list = ServerInstance->Users->local_users; + for (LocalUserList::const_iterator i = list.begin(); i != list.end(); ++i) + (*i)->server = newserver; + } +} + void ModuleSpanningTree::init() { ServerInstance->SNO->EnableSnomask('l', "LINK"); @@ -62,6 +73,10 @@ void ModuleSpanningTree::init() delete ServerInstance->PI; ServerInstance->PI = new SpanningTreeProtocolInterface; + + delete ServerInstance->FakeClient->server; + SetLocalUsersServer(Utils->TreeRoot); + loopCall = false; SplitInProgress = false; @@ -81,7 +96,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops) for (TreeServer::ChildServers::const_iterator i = children.begin(); i != children.end(); ++i) { TreeServer* server = *i; - if ((server->Hidden) || ((Utils->HideULines) && (ServerInstance->ULine(server->GetName())))) + if ((server->Hidden) || ((Utils->HideULines) && (server->IsULine()))) { if (user->IsOper()) { @@ -94,7 +109,7 @@ void ModuleSpanningTree::ShowLinks(TreeServer* Current, User* user, int hops) } } /* Don't display the line if its a uline, hide ulines is on, and the user isnt an oper */ - if ((Utils->HideULines) && (ServerInstance->ULine(Current->GetName())) && (!user->IsOper())) + 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())) @@ -560,20 +575,16 @@ void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const // 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 - bool hide = (((this->SplitInProgress) && (Utils->quiet_bursts)) || (ServerInstance->SilentULine(user->server))); + bool hide = (((this->SplitInProgress) && (Utils->quiet_bursts)) || (user->server->IsSilentULine())); if (!hide) { ServerInstance->SNO->WriteToSnoMask('Q', "Client exiting on server %s: %s (%s) [%s]", - user->server.c_str(), user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_message.c_str()); + user->server->GetName().c_str(), user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_message.c_str()); } } // Regardless, We need to modify the user Counts.. - TreeServer* SourceServer = Utils->FindServer(user->server); - if (SourceServer) - { - SourceServer->UserCount--; - } + TreeServer::Get(user)->UserCount--; } void ModuleSpanningTree::OnUserPostNick(User* user, const std::string &oldnick) @@ -624,7 +635,7 @@ void ModuleSpanningTree::OnPreRehash(User* user, const std::string ¶meter) { CmdBuilder params((user ? user->uuid : ServerInstance->Config->GetSID()), "REHASH"); params.push_back(parameter); - params.Forward(user ? Utils->BestRouteTo(user->server) : NULL); + params.Forward(user ? TreeServer::Get(user)->GetRoute() : NULL); } } @@ -743,6 +754,9 @@ ModuleSpanningTree::~ModuleSpanningTree() delete ServerInstance->PI; ServerInstance->PI = new ProtocolInterface; + Server* newsrv = new Server(ServerInstance->Config->ServerName); + SetLocalUsersServer(newsrv); + /* This will also free the listeners */ delete Utils; diff --git a/src/modules/m_spanningtree/nick.cpp b/src/modules/m_spanningtree/nick.cpp index 7ace9cc73..eb6c9396f 100644 --- a/src/modules/m_spanningtree/nick.cpp +++ b/src/modules/m_spanningtree/nick.cpp @@ -28,6 +28,7 @@ #include "main.h" #include "utils.h" #include "commands.h" +#include "treeserver.h" CmdResult CommandNick::HandleRemote(RemoteUser* user, std::vector<std::string>& params) { @@ -45,7 +46,7 @@ CmdResult CommandNick::HandleRemote(RemoteUser* user, std::vector<std::string>& if ((x) && (x != user)) { /* x is local, who is remote */ - int collideret = Utils->DoCollision(x, Utils->FindServer(user->server), user->age, user->ident, user->GetIPString(), user->uuid); + int collideret = Utils->DoCollision(x, TreeServer::Get(user), user->age, user->ident, user->GetIPString(), user->uuid); if (collideret != 1) { /* diff --git a/src/modules/m_spanningtree/opertype.cpp b/src/modules/m_spanningtree/opertype.cpp index 6e5d473aa..1a9e36f72 100644 --- a/src/modules/m_spanningtree/opertype.cpp +++ b/src/modules/m_spanningtree/opertype.cpp @@ -50,12 +50,12 @@ CmdResult CommandOpertype::HandleRemote(RemoteUser* u, std::vector<std::string>& * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services), * then do nothing. -- w00t */ - TreeServer* remoteserver = Utils->FindServer(u->server); - if (remoteserver->bursting || ServerInstance->SilentULine(u->server)) + TreeServer* remoteserver = TreeServer::Get(u); + if (remoteserver->bursting || remoteserver->IsSilentULine()) return CMD_SUCCESS; } - ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server.c_str(), u->nick.c_str(),u->ident.c_str(), u->host.c_str(), opertype.c_str()); + ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%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; } diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index abefa823b..a9b68eb9b 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -85,7 +85,7 @@ void CommandMap::ShowMap(TreeServer* Current, User* user, int depth, int &line, if (!user->IsOper()) { if (child->Hidden) continue; - if ((Utils->HideULines) && (ServerInstance->ULine(child->GetName()))) + if ((Utils->HideULines) && (child->IsULine())) continue; } ShowMap(child, user, depth, line, names, maxnamew, stats); diff --git a/src/modules/m_spanningtree/postcommand.cpp b/src/modules/m_spanningtree/postcommand.cpp index 57fbca6bc..a059bcb5f 100644 --- a/src/modules/m_spanningtree/postcommand.cpp +++ b/src/modules/m_spanningtree/postcommand.cpp @@ -102,7 +102,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm User* d = ServerInstance->FindNick(dest); if (!d) return; - TreeServer* tsd = BestRouteTo(d->server); + TreeServer* tsd = TreeServer::Get(d)->GetRoute(); if (tsd == origin) // huh? no routing stuff around in a circle, please. return; diff --git a/src/modules/m_spanningtree/servercommand.h b/src/modules/m_spanningtree/servercommand.h index 2bd77fc84..156b405e4 100644 --- a/src/modules/m_spanningtree/servercommand.h +++ b/src/modules/m_spanningtree/servercommand.h @@ -20,8 +20,7 @@ #pragma once #include "utils.h" - -class TreeServer; +#include "treeserver.h" /** Base class for server-to-server commands that may have a (remote) user source or server source. */ @@ -67,7 +66,7 @@ class ServerOnlyServerCommand : public ServerCommand { if (!IS_SERVER(user)) return CMD_INVALID; - TreeServer* server = Utils->FindServer(user->server); + TreeServer* server = TreeServer::Get(user); return static_cast<T*>(this)->HandleServer(server, parameters); } }; diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 7d8abf4bf..34b71e07f 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -33,7 +33,8 @@ * no socket associated with it. Its version string is our own local version. */ TreeServer::TreeServer() - : Parent(NULL), Route(NULL), ServerName(ServerInstance->Config->ServerName), ServerDesc(ServerInstance->Config->ServerDesc) + : Server(ServerInstance->Config->ServerName) + , Parent(NULL), Route(NULL), ServerDesc(ServerInstance->Config->ServerDesc) , VersionString(ServerInstance->GetVersionString()), Socket(NULL), sid(ServerInstance->Config->GetSID()), ServerUser(ServerInstance->FakeClient) , age(ServerInstance->Time()), Warned(false), bursting(false), UserCount(0), OperCount(0), rtt(0), StartBurst(0), Hidden(false) { @@ -45,9 +46,11 @@ TreeServer::TreeServer() * its ping counters so that it will be pinged one minute from now. */ TreeServer::TreeServer(const std::string& Name, const std::string& Desc, const std::string& id, TreeServer* Above, TreeSocket* Sock, bool Hide) - : Parent(Above), ServerName(Name), ServerDesc(Desc), Socket(Sock), sid(id), ServerUser(new FakeUser(id, Name)) + : Server(Name) + , Parent(Above), ServerDesc(Desc), Socket(Sock), sid(id), ServerUser(new FakeUser(id, this)) , age(ServerInstance->Time()), Warned(false), bursting(true), UserCount(0), OperCount(0), rtt(0), Hidden(Hide) { + CheckULine(); SetNextPingTime(ServerInstance->Time() + Utils->PingFreq); SetPingFlag(); @@ -133,8 +136,8 @@ void TreeServer::FinishBurst() long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000); unsigned long bursttime = ts - this->StartBurst; ServerInstance->SNO->WriteToSnoMask(Parent == Utils->TreeRoot ? 'l' : 'L', "Received end of netburst from \2%s\2 (burst time: %lu %s)", - ServerName.c_str(), (bursttime > 10000 ? bursttime / 1000 : bursttime), (bursttime > 10000 ? "secs" : "msecs")); - AddServerEvent(Utils->Creator, ServerName); + GetName().c_str(), (bursttime > 10000 ? bursttime / 1000 : bursttime), (bursttime > 10000 ? "secs" : "msecs")); + AddServerEvent(Utils->Creator, GetName()); } int TreeServer::QuitUsers(const std::string &reason) @@ -148,19 +151,30 @@ int TreeServer::QuitUsers(const std::string &reason) User* user = i->second; // Increment the iterator now because QuitUser() removes the user from the container ++i; - if (user->server == ServerName) + if (user->server == this) ServerInstance->Users->QuitUser(user, publicreason, &reason); } return original_size - users.size(); } +void TreeServer::CheckULine() +{ + uline = silentuline = false; + std::map<irc::string, bool>::iterator it = ServerInstance->Config->ulines.find(GetName().c_str()); + if (it != ServerInstance->Config->ulines.end()) + { + uline = true; + silentuline = it->second; + } +} + /** This method is used to add the structure to the * hash_map for linear searches. It is only called * by the constructors. */ void TreeServer::AddHashEntry() { - Utils->serverlist[ServerName] = this; + Utils->serverlist[GetName()] = this; Utils->sidlist[sid] = this; } @@ -267,5 +281,5 @@ TreeServer::~TreeServer() delete ServerUser; Utils->sidlist.erase(sid); - Utils->serverlist.erase(ServerName); + Utils->serverlist.erase(GetName()); } diff --git a/src/modules/m_spanningtree/treeserver.h b/src/modules/m_spanningtree/treeserver.h index 8178c87fa..67ce96e63 100644 --- a/src/modules/m_spanningtree/treeserver.h +++ b/src/modules/m_spanningtree/treeserver.h @@ -37,12 +37,11 @@ * TreeServer items, deleting and inserting them as they * are created and destroyed. */ -class TreeServer : public classbase +class TreeServer : public Server { TreeServer* Parent; /* Parent entry */ TreeServer* Route; /* Route entry */ std::vector<TreeServer*> Children; /* List of child objects */ - std::string ServerName; /* Server's name */ std::string ServerDesc; /* Server's description */ std::string VersionString; /* Version string or empty string */ TreeSocket* Socket; /* Socket used to communicate with this server */ @@ -94,10 +93,6 @@ class TreeServer : public classbase */ bool IsLocal() const { return (this->Route == this); } - /** Get server name - */ - const std::string& GetName() const { return ServerName; } - /** Get server description (GECOS) */ const std::string& GetDesc(); @@ -180,6 +175,10 @@ class TreeServer : public classbase /** Recursive call for child servers */ void FinishBurstInternal(); + /** (Re)check the uline state of this server + */ + void CheckULine(); + CullResult cull(); /** Destructor @@ -187,4 +186,13 @@ class TreeServer : public classbase * hash maps. */ ~TreeServer(); + + /** Returns the TreeServer the given user is connected to + * @param user The user whose server to return + * @return The TreeServer this user is connected to. + */ + static TreeServer* Get(User* user) + { + return static_cast<TreeServer*>(user->server); + } }; diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index b66595bd1..f97ce5539 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -229,7 +229,6 @@ void TreeSocket::ProcessLine(std::string &line) void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params) { User* who = ServerInstance->FindUUID(prefix); - std::string direction; if (!who) { @@ -269,10 +268,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, } } - // Make sure prefix is still good - direction = who->server; - prefix = who->uuid; - /* * Check for fake direction here, and drop any instances that are found. * What is fake direction? Imagine the following server setup: @@ -289,12 +284,10 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, * a valid SID or a valid UUID, so that invalid UUID or SID never makes it * to the higher level functions. -- B */ - TreeServer* route_back_again = Utils->BestRouteTo(direction); - if ((!route_back_again) || (route_back_again->GetSocket() != this)) + TreeServer* route_back_again = TreeServer::Get(who)->GetRoute(); + if (route_back_again->GetSocket() != this) { - if (route_back_again) - ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'", - prefix.c_str(),linkID.c_str()); + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'", prefix.c_str(), linkID.c_str()); return; } diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 82d78124a..0d96167b9 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -71,7 +71,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st User* _new = NULL; try { - _new = new RemoteUser(params[0], remoteserver->GetName()); + _new = new RemoteUser(params[0], remoteserver); } catch (...) { @@ -132,11 +132,11 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st bool dosend = true; - if ((Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server)) + if ((Utils->quiet_bursts && remoteserver->bursting) || _new->server->IsSilentULine()) dosend = false; if (dosend) - ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", _new->server.c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString().c_str(), _new->fullname.c_str()); + ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", remoteserver->GetName().c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString().c_str(), _new->fullname.c_str()); FOREACH_MOD(OnPostConnect, (_new)); @@ -162,7 +162,7 @@ CmdResult CommandFName::HandleRemote(RemoteUser* src, std::vector<std::string>& } CommandUID::Builder::Builder(User* user) - : CmdBuilder(user->uuid.substr(0, 3), "UID") + : CmdBuilder(TreeServer::Get(user)->GetID(), "UID") { push(user->uuid); push_int(user->age); diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index dbd246ffe..fd51fb6b4 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -93,9 +93,7 @@ TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName) User *u = ServerInstance->FindNick(ServerName); if (u) { - Found = FindServer(u->server); - if (Found) - return Found->GetRoute(); + return TreeServer::Get(u)->GetRoute(); } return NULL; @@ -180,9 +178,8 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet if (exempt_list.find(i->first) == exempt_list.end()) { - TreeServer* best = this->BestRouteTo(i->first->server); - if (best) - list.insert(best->GetSocket()); + TreeServer* best = TreeServer::Get(i->first); + list.insert(best->GetSocket()); } } return; @@ -210,10 +207,16 @@ bool SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, const std::stri if (!Route) return false; - Route->GetSocket()->WriteLine(params); + DoOneToOne(params, Route); return true; } +void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, Server* server) +{ + TreeServer* ts = static_cast<TreeServer*>(server); + ts->GetSocket()->WriteLine(params); +} + void SpanningTreeUtilities::RefreshIPCache() { ValidIPs.clear(); @@ -349,6 +352,9 @@ void SpanningTreeUtilities::ReadConfiguration() AutoconnectBlocks.push_back(A); } + for (server_hash::const_iterator i = serverlist.begin(); i != serverlist.end(); ++i) + i->second->CheckULine(); + RefreshIPCache(); } diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 164bed1ca..4005f0db9 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -129,6 +129,7 @@ class SpanningTreeUtilities : public classbase /** Send a message from this server to one other local or remote */ bool DoOneToOne(const CmdBuilder& params, const std::string& target); + void DoOneToOne(const CmdBuilder& params, Server* target); /** Send a message from this server to all but one other, local or remote */ diff --git a/src/modules/m_sslmodes.cpp b/src/modules/m_sslmodes.cpp index af0fb26f6..6ac07434f 100644 --- a/src/modules/m_sslmodes.cpp +++ b/src/modules/m_sslmodes.cpp @@ -52,7 +52,7 @@ class SSLMode : public ModeHandler for(UserMembCIter i = userlist->begin(); i != userlist->end(); i++) { ssl_cert* cert = API->GetCertificate(i->first); - if (!cert && !ServerInstance->ULine(i->first->server)) + if (!cert && !i->first->server->IsULine()) { source->WriteNumeric(ERR_ALLMUSTSSL, "%s :all members of the channel must be connected via SSL", channel->name.c_str()); return MODEACTION_DENY; diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp index bb2fcdbc0..b1b454e63 100644 --- a/src/modules/m_svshold.cpp +++ b/src/modules/m_svshold.cpp @@ -89,7 +89,7 @@ class CommandSvshold : public Command /* syntax: svshold nickname time :reason goes here */ /* 'time' is a human-readable timestring, like 2d3h2s. */ - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) { /* don't allow SVSHOLD from non-ulined clients */ return CMD_FAILURE; diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp index 3e0ecbc8c..4eb2a9cda 100644 --- a/src/modules/m_swhois.cpp +++ b/src/modules/m_swhois.cpp @@ -51,11 +51,11 @@ class CommandSwhois : public Command if (text) { // We already had it set... - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) // Ulines set SWHOISes silently ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick.c_str(), dest->nick.c_str(), text->c_str(), parameters[1].c_str()); } - else if (!ServerInstance->ULine(user->server)) + else if (!user->server->IsULine()) { // Ulines set SWHOISes silently ServerInstance->SNO->WriteGlobalSno('a', "%s used SWHOIS to set %s's extra whois to '%s'", user->nick.c_str(), dest->nick.c_str(), parameters[1].c_str()); diff --git a/src/modules/m_topiclock.cpp b/src/modules/m_topiclock.cpp index 2d539dcab..c7431b4c6 100644 --- a/src/modules/m_topiclock.cpp +++ b/src/modules/m_topiclock.cpp @@ -29,7 +29,7 @@ class CommandSVSTOPIC : public Command CmdResult Handle(const std::vector<std::string> ¶meters, User *user) { - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) { // Ulines only return CMD_FAILURE; diff --git a/src/modules/m_uninvite.cpp b/src/modules/m_uninvite.cpp index 5e70b4dc7..6eaeb285f 100644 --- a/src/modules/m_uninvite.cpp +++ b/src/modules/m_uninvite.cpp @@ -70,11 +70,11 @@ class CommandUninvite : public Command { if (!lu->RemoveInvite(c)) { - user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server.c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str()); + user->SendText(":%s 505 %s %s %s :Is not invited to channel %s", user->server->GetName().c_str(), user->nick.c_str(), u->nick.c_str(), c->name.c_str(), c->name.c_str()); return CMD_FAILURE; } - user->SendText(":%s 494 %s %s %s :Uninvited", user->server.c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str()); + user->SendText(":%s 494 %s %s %s :Uninvited", user->server->GetName().c_str(), user->nick.c_str(), c->name.c_str(), u->nick.c_str()); lu->WriteNumeric(493, ":You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str()); std::string msg = "*** " + user->nick + " uninvited " + u->nick + "."; diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index bb0191250..6c7000a77 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -110,7 +110,7 @@ class CommandSVSWatch : public Command CmdResult Handle (const std::vector<std::string> ¶meters, User *user) { - if (!ServerInstance->ULine(user->server)) + if (!user->server->IsULine()) return CMD_FAILURE; User *u = ServerInstance->FindNick(parameters[0]); |