]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Improve UserManager::QuitUser() and related code
authorAttila Molnar <attilamolnar@hush.com>
Sun, 5 Jan 2014 13:17:12 +0000 (14:17 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sun, 5 Jan 2014 13:17:12 +0000 (14:17 +0100)
- Make operreason optional; NULL means same as quitreason
- Remove User::quietquit, it is now handled internally in spanningtree
- Send snotice about quitting remote users from spanningtree

include/usermanager.h
include/users.h
src/commands/cmd_quit.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/treeserver.cpp
src/modules/m_spanningtree/treesocket1.cpp
src/usermanager.cpp
src/users.cpp
src/xline.cpp

index c6745ace626d12f2347c6caeccbe881e3b351884..a807cd447b57de70db5f0d5118042f526eb064bc 100644 (file)
@@ -102,10 +102,10 @@ class CoreExport UserManager
        /** Disconnect a user gracefully
         * @param user The user to remove
         * @param quitreason The quit reason to show to normal users
-        * @param operreason The quit reason to show to opers
+        * @param operreason The quit reason to show to opers, can be NULL if same as quitreason
         * @return Although this function has no return type, on exit the user provided will no longer exist.
         */
-       void QuitUser(User *user, const std::string &quitreason, const char* operreason = "");
+       void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
 
        /** Add a user to the local clone map
         * @param user The user to add
index aa11a2b82ac5b2adb52452cc17691002c5899f67..fa9d97c215f664403ec7e969f6242253c12557eb 100644 (file)
@@ -328,10 +328,6 @@ class CoreExport User : public Extensible
         */
        unsigned int registered:3;
 
-       /** Whether or not to send an snotice about this user's quitting
-        */
-       unsigned int quietquit:1;
-
        /** If this is set to true, then all socket operations for the user
         * are dropped into the bit-bucket.
         * This value is set by QuitUser, and is not needed seperately from that call.
index 61a88e2b55f53e73650f462025394d3445935665..144f4675b31a090f1f23bd79a5fb0d8743d99074 100644 (file)
@@ -56,21 +56,14 @@ CmdResult CommandQuit::Handle (const std::vector<std::string>& parameters, User
                        quitmsg = ServerInstance->Config->FixedQuit;
                else
                        quitmsg = parameters.size() ?
-                               ServerInstance->Config->PrefixQuit + std::string(parameters[0]) + ServerInstance->Config->SuffixQuit
+                               ServerInstance->Config->PrefixQuit + parameters[0] + ServerInstance->Config->SuffixQuit
                                : "Client exited";
        }
        else
                quitmsg = parameters.size() ? parameters[0] : "Client exited";
 
        std::string* operquit = ServerInstance->OperQuit.get(user);
-       if (operquit)
-       {
-               ServerInstance->Users->QuitUser(user, quitmsg, operquit->c_str());
-       }
-       else
-       {
-               ServerInstance->Users->QuitUser(user, quitmsg);
-       }
+       ServerInstance->Users->QuitUser(user, quitmsg, operquit);
 
        return CMD_SUCCESS;
 }
index 8d8a51ede496e1f43f40146884669499ad17ec47..8c04d6c909797cacebf09dbcbdb7c34d6ee7bd51 100644 (file)
@@ -63,6 +63,7 @@ void ModuleSpanningTree::init()
        delete ServerInstance->PI;
        ServerInstance->PI = new SpanningTreeProtocolInterface;
        loopCall = false;
+       SplitInProgress = false;
 
        // update our local user count
        Utils->TreeRoot->UserCount = ServerInstance->Users->local_users.size();
@@ -547,13 +548,25 @@ void ModuleSpanningTree::OnUserPart(Membership* memb, std::string &partmessage,
 
 void ModuleSpanningTree::OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
 {
-       if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
+       if (IS_LOCAL(user))
        {
                if (oper_message != reason)
                        ServerInstance->PI->SendMetaData(user, "operquit", oper_message);
 
                CmdBuilder(user, "QUIT").push_last(reason).Broadcast();
        }
+       else
+       {
+               // 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)));
+               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());
+               }
+       }
 
        // Regardless, We need to modify the user Counts..
        TreeServer* SourceServer = Utils->FindServer(user->server);
index c275207bfdf3ccc073d16e0d8d7a68d8da8535f0..bef94a53bbcdca28fa79bf907f0b1336853983cb 100644 (file)
@@ -73,6 +73,10 @@ class ModuleSpanningTree : public Module
         */
        bool loopCall;
 
+       /** True if users are quitting due to a netsplit
+        */
+       bool SplitInProgress;
+
        /** Constructor
         */
        ModuleSpanningTree();
index 8af3e777d9c68997b7b14752cbb040ad5fc19b3f..2fce9a504f20c360d14b6da146fd84291e8d9d7d 100644 (file)
@@ -139,7 +139,7 @@ void TreeServer::FinishBurst()
 
 int TreeServer::QuitUsers(const std::string &reason)
 {
-       const char* reason_s = reason.c_str();
+       std::string publicreason = ServerInstance->Config->HideSplits ? "*.net *.split" : reason;
        std::vector<User*> time_to_die;
        for (user_hash::iterator n = ServerInstance->Users->clientlist->begin(); n != ServerInstance->Users->clientlist->end(); n++)
        {
@@ -153,13 +153,7 @@ int TreeServer::QuitUsers(const std::string &reason)
                User* a = (User*)*n;
                if (!IS_LOCAL(a))
                {
-                       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);
+                       ServerInstance->Users->QuitUser(a, publicreason, &reason);
                }
        }
        return time_to_die.size();
index 3c838177d11ceb4c0ba68740c8337c3a4e482a9a..fa8a94f72bab89b080a8c98b91db50dba35967f1 100644 (file)
@@ -192,7 +192,12 @@ void TreeSocket::Squit(TreeServer* Current, const std::string &reason)
                int num_lost_servers = 0;
                int num_lost_users = 0;
                std::string from = Current->GetParent()->GetName()+" "+Current->GetName();
+
+               ModuleSpanningTree* st = Utils->Creator;
+               st->SplitInProgress = true;
                SquitServer(from, Current, num_lost_servers, num_lost_users);
+               st->SplitInProgress = false;
+
                ServerInstance->SNO->WriteToSnoMask(LocalSquit ? 'l' : 'L', "Netsplit complete, lost \002%d\002 user%s on \002%d\002 server%s.",
                        num_lost_users, num_lost_users != 1 ? "s" : "", num_lost_servers, num_lost_servers != 1 ? "s" : "");
                Current->Tidy();
index 1d1a05fa2e269febbaeb993e1a54d396422765ec..745934fd4467efc78db9c0b325d068aa7f98cc83 100644 (file)
@@ -169,7 +169,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
        FOREACH_MOD(OnUserInit, (New));
 }
 
-void UserManager::QuitUser(User *user, const std::string &quitreason, const char* operreason)
+void UserManager::QuitUser(User* user, const std::string& quitreason, const std::string* operreason)
 {
        if (user->quitting)
        {
@@ -186,57 +186,31 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
        user->quitting = true;
 
        ServerInstance->Logs->Log("USERS", LOG_DEBUG, "QuitUser: %s=%s '%s'", user->uuid.c_str(), user->nick.c_str(), quitreason.c_str());
-       user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), *operreason ? operreason : quitreason.c_str());
+       user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), operreason ? operreason->c_str() : quitreason.c_str());
 
        std::string reason;
-       std::string oper_reason;
        reason.assign(quitreason, 0, ServerInstance->Config->Limits.MaxQuit);
-       if (operreason && *operreason)
-               oper_reason.assign(operreason, 0, ServerInstance->Config->Limits.MaxQuit);
-       else
-               oper_reason = quitreason;
+       if (!operreason)
+               operreason = &reason;
 
        ServerInstance->GlobalCulls.AddItem(user);
 
        if (user->registered == REG_ALL)
        {
-               FOREACH_MOD(OnUserQuit, (user, reason, oper_reason));
-               user->WriteCommonQuit(reason, oper_reason);
+               FOREACH_MOD(OnUserQuit, (user, reason, *operreason));
+               user->WriteCommonQuit(reason, *operreason);
        }
-
-       if (user->registered != REG_ALL)
-               if (ServerInstance->Users->unregistered_count)
-                       ServerInstance->Users->unregistered_count--;
+       else
+               unregistered_count--;
 
        if (IS_LOCAL(user))
        {
                LocalUser* lu = IS_LOCAL(user);
                FOREACH_MOD(OnUserDisconnect, (lu));
                lu->eh.Close();
-       }
 
-       /*
-        * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
-        * if they were an oper with +s +qQ.
-        */
-       if (user->registered == REG_ALL)
-       {
-               if (IS_LOCAL(user))
-               {
-                       if (!user->quietquit)
-                       {
-                               ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s (%s) [%s]",
-                                       user->GetFullRealHost().c_str(), user->GetIPString().c_str(), oper_reason.c_str());
-                       }
-               }
-               else
-               {
-                       if ((!ServerInstance->SilentULine(user->server)) && (!user->quietquit))
-                       {
-                               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_reason.c_str());
-                       }
-               }
+               if (lu->registered == REG_ALL)
+                       ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s (%s) [%s]", user->GetFullRealHost().c_str(), user->GetIPString().c_str(), operreason->c_str());
        }
 
        user_hash::iterator iter = this->clientlist->find(user->nick);
@@ -246,7 +220,7 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
        else
                ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "ERROR: Nick not found in clientlist, cannot remove: " + user->nick);
 
-       ServerInstance->Users->uuidlist->erase(user->uuid);
+       uuidlist->erase(user->uuid);
 }
 
 void UserManager::AddLocalClone(User *user)
index 39a71719063dafbeca1d20e6456117cfeeef201b..fa4bb7a4226b4d8f4d52fcff7209f41f4a7cc6dc 100644 (file)
@@ -75,7 +75,7 @@ User::User(const std::string &uid, const std::string& sid, int type)
        age = ServerInstance->Time();
        signon = 0;
        registered = 0;
-       quietquit = quitting = false;
+       quitting = false;
        client_sa.sa.sa_family = AF_UNSPEC;
 
        ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New UUID for user: %s", uuid.c_str());
index bc8e596bd376a6cbf38ca647e82f378aafcf69ab..63a64d6b9d74d2b9ab73a4e38c8702f37b3c990b 100644 (file)
@@ -537,7 +537,7 @@ void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
                u->WriteNotice("*** " + ServerInstance->Config->XLineMessage);
 
        if (ServerInstance->Config->HideBans)
-               ServerInstance->Users->QuitUser(u, line + "-Lined", banReason.c_str());
+               ServerInstance->Users->QuitUser(u, line + "-Lined", &banReason);
        else
                ServerInstance->Users->QuitUser(u, banReason);
 
@@ -545,7 +545,7 @@ void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
        if (bancache)
        {
                ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Adding positive hit (" + line + ") for " + u->GetIPString());
-               ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason, this->duration);
+               ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, banReason, this->duration);
        }
 }