]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move already sent id rollover handling and static LocalUser::already_sent_id into...
authorAttila Molnar <attilamolnar@hush.com>
Tue, 3 Nov 2015 12:13:00 +0000 (13:13 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Tue, 3 Nov 2015 12:13:00 +0000 (13:13 +0100)
include/usermanager.h
include/users.h
src/usermanager.cpp
src/users.cpp

index 605b841bb053022c65a9cc6355b395f9efd82970..670e51dd59782e079e7b8b85aef774eaba4deef2 100644 (file)
@@ -56,6 +56,11 @@ class CoreExport UserManager : public fakederef<UserManager>
         */
        LocalList local_users;
 
+       /** Last used already sent id, used when sending messages to neighbors to help determine whether the message has
+        * been sent to a particular user or not. See User::ForEachNeighbor() for more info.
+        */
+       already_sent_t already_sent_id;
+
  public:
        /** Constructor, initializes variables
         */
index 03540018b85d7816266ef304441427a34e7e2400..fa346a32968f2164a93aed14c447ef9ba25d7e42 100644 (file)
@@ -720,7 +720,6 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_node<Local
         */
        unsigned int CommandFloodPenalty;
 
-       static already_sent_t already_sent_id;
        already_sent_t already_sent;
 
        /** Check if the user matches a G or K line, and disconnect them if they do.
index c593e149f8ebef01da9a1c511b0a3e38b5153e7f..d81b83d20dbbc862b535bbac756e3586f64dcf91 100644 (file)
@@ -49,7 +49,8 @@ namespace
 }
 
 UserManager::UserManager()
-       : unregistered_count(0)
+       : already_sent_id(0)
+       , unregistered_count(0)
 {
 }
 
@@ -281,7 +282,6 @@ void UserManager::ServerNoticeAll(const char* text, ...)
 void UserManager::GarbageCollect()
 {
        // Reset the already_sent IDs so we don't wrap it around and drop a message
-       LocalUser::already_sent_id = 0;
        for (LocalList::const_iterator i = local_users.begin(); i != local_users.end(); ++i)
                (**i).already_sent = 0;
 }
@@ -371,5 +371,15 @@ void UserManager::DoBackgroundUserStuff()
 
 already_sent_t UserManager::NextAlreadySentId()
 {
-       return ++LocalUser::already_sent_id;
+       if (++already_sent_id == 0)
+       {
+               // Wrapped around, reset the already_sent ids of all users
+               already_sent_id = 1;
+               for (LocalList::iterator i = local_users.begin(); i != local_users.end(); ++i)
+               {
+                       LocalUser* user = *i;
+                       user->already_sent = 0;
+               }
+       }
+       return already_sent_id;
 }
index 2585443126c8f85a40cc5617d23679e2a3c72eb9..93fd8d06568b169f9e84138f09297a055bc92923 100644 (file)
@@ -26,8 +26,6 @@
 #include "inspircd.h"
 #include "xline.h"
 
-already_sent_t LocalUser::already_sent_id = 0;
-
 bool User::IsNoticeMaskSet(unsigned char sm)
 {
        if (!isalpha(sm))