]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treeserver.cpp
Read uline state in spanningtree; remove ConfigReader::ulines
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.cpp
index 8af3e777d9c68997b7b14752cbb040ad5fc19b3f..b51c21db65dacd3ef80d2e8bae6ad8833222bf25 100644 (file)
@@ -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, ServerInstance->Config->ServerDesc)
+       , Parent(NULL), Route(NULL)
        , 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, Desc)
+       , Parent(Above), 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,36 +136,49 @@ 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)
 {
-       const char* reason_s = reason.c_str();
-       std::vector<User*> time_to_die;
-       for (user_hash::iterator n = ServerInstance->Users->clientlist->begin(); n != ServerInstance->Users->clientlist->end(); n++)
+       std::string publicreason = ServerInstance->Config->HideSplits ? "*.net *.split" : reason;
+
+       const user_hash& users = *ServerInstance->Users->clientlist;
+       unsigned int original_size = users.size();
+       for (user_hash::const_iterator i = users.begin(); i != users.end(); )
        {
-               if (n->second->server == ServerName)
-               {
-                       time_to_die.push_back(n->second);
-               }
+               User* user = i->second;
+               // Increment the iterator now because QuitUser() removes the user from the container
+               ++i;
+               if (user->server == this)
+                       ServerInstance->Users->QuitUser(user, publicreason, &reason);
        }
-       for (std::vector<User*>::iterator n = time_to_die.begin(); n != time_to_die.end(); n++)
+       return original_size - users.size();
+}
+
+void TreeServer::CheckULine()
+{
+       uline = silentuline = false;
+
+       ConfigTagList tags = ServerInstance->Config->ConfTags("uline");
+       for (ConfigIter i = tags.first; i != tags.second; ++i)
        {
-               User* a = (User*)*n;
-               if (!IS_LOCAL(a))
+               ConfigTag* tag = i->second;
+               std::string server = tag->getString("server");
+               if (!strcasecmp(server.c_str(), GetName().c_str()))
                {
-                       if (Utils->quiet_bursts)
-                               a->quietquit = true;
-
-                       if (ServerInstance->Config->HideSplits)
-                               ServerInstance->Users->QuitUser(a, "*.net *.split", reason_s);
-                       else
-                               ServerInstance->Users->QuitUser(a, reason_s);
+                       if (this->IsRoot())
+                       {
+                               ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Servers should not uline themselves (at " + tag->getTagLocation() + ")");
+                               return;
+                       }
+
+                       uline = true;
+                       silentuline = tag->getBool("silent");
+                       break;
                }
        }
-       return time_to_die.size();
 }
 
 /** This method is used to add the structure to the
@@ -171,7 +187,7 @@ int TreeServer::QuitUsers(const std::string &reason)
  */
 void TreeServer::AddHashEntry()
 {
-       Utils->serverlist[ServerName] = this;
+       Utils->serverlist[GetName()] = this;
        Utils->sidlist[sid] = this;
 }
 
@@ -183,11 +199,6 @@ TreeServer* TreeServer::GetRoute()
        return Route;
 }
 
-const std::string& TreeServer::GetDesc()
-{
-       return ServerDesc;
-}
-
 const std::string& TreeServer::GetVersion()
 {
        return VersionString;
@@ -278,5 +289,5 @@ TreeServer::~TreeServer()
                delete ServerUser;
 
        Utils->sidlist.erase(sid);
-       Utils->serverlist.erase(ServerName);
+       Utils->serverlist.erase(GetName());
 }