]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
common_channels -> userrec::SharesChannelWith()
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 9 Aug 2006 10:04:58 +0000 (10:04 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 9 Aug 2006 10:04:58 +0000 (10:04 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4805 e03df62e-2008-0410-955e-edbf42e46eb7

include/globals.h
include/message.h
include/modules.h
include/users.h
src/message.cpp
src/modules.cpp
src/users.cpp

index d3aac6571ad6d52e8738c82e92514d1c6a3e375a..a6e39066eba30806e0b8d8389e9040487a116597 100644 (file)
@@ -33,7 +33,6 @@ typedef std::multimap< std::string, KeyValList > ConfigDataHash;
 
 void WriteOpers(char* text, ...);
 void do_log(int level, char *text, ...);
-int common_channels(userrec *u, userrec *u2);
 int isnick(const char *n);
 chanrec* FindChan(const char* chan);
 void readfile(file_cache &F, const char* fname);
index f7fcba278fa8faabd02dff9404490663c66438c6..edcda3da91f4ce0fc14b1e7548de86171ddd78b1 100644 (file)
@@ -28,7 +28,6 @@
 #include "users.h"
 #include "channels.h"
 
-int common_channels(userrec *u, userrec *u2);
 void Blocking(int s);
 void NonBlocking(int s);
 int c_count(userrec* u);
index 392047a35037b0c56c6a481ba9fa9f6326b451fd..cb105c60e58d99bda22685cc1056dbfc369811db 100644 (file)
@@ -1327,12 +1327,6 @@ class Server : public Extensible
         */
        virtual void Log(int level, const std::string &s);
 
-       /** Returns true if two users share a common channel.
-        * This method is used internally by the NICK and QUIT commands, and the Server::SendCommon
-        * method.
-        */
-       virtual bool CommonChannels(userrec* u1, userrec* u2);
-
        /** Returns true if a nick is valid.
         * Nicks for unregistered connections will return false.
         */
index 5e6225dfb8f3f2e8fda48c41a8918f5c07245dee..cc70740048df711b1bef3cd33f84082017446e47 100644 (file)
@@ -627,9 +627,11 @@ class userrec : public connection
         */
        void WriteCommonExcept(const std::string &text);
 
-       void userrec::WriteWallOps(const char* text, ...);
+       void WriteWallOps(const char* text, ...);
 
-       void userrec::WriteWallOps(const std::string &text);
+       void WriteWallOps(const std::string &text);
+
+       bool SharesChannelWith(userrec *other);
 
        /** Default destructor
         */
index a786c60cbfb61a71601043de942ae244f1cb7053..9b56cc8ca4e65c4012396a3fe181fe7de5e21fab 100644 (file)
@@ -48,41 +48,6 @@ extern std::vector<ircd_module*> factory;
 extern time_t TIME;
 extern ServerConfig* Config;
 
-/* return 0 or 1 depending if users u and u2 share one or more common channels
- * (used by QUIT, NICK etc which arent channel specific notices)
- *
- * The old algorithm in 1.0 for this was relatively inefficient, iterating over
- * the first users channels then the second users channels within the outer loop,
- * therefore it was a maximum of x*y iterations (upon returning 0 and checking
- * all possible iterations). However this new function instead checks against the
- * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
- * and saves us time as we already know what pointer value we are after.
- * Don't quote me on the maths as i am not a mathematician or computer scientist,
- * but i believe this algorithm is now x+(log y) maximum iterations instead.
- */
-int common_channels(userrec *u, userrec *u2)
-{
-       if ((!u) || (!u2) || (u->registered != REG_ALL) || (u2->registered != REG_ALL))
-               return 0;
-
-       /* Outer loop */
-       for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
-       {
-               /* Fetch the channel from the user */
-               ucrec* user_channel = *i;
-
-               if (user_channel->channel)
-               {
-                       /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
-                        * by replacing it with a map::find which *should* be more efficient
-                        */
-                       if (user_channel->channel->HasUser(u2))
-                               return 1;
-               }
-       }
-       return 0;
-}
-
 void Blocking(int s)
 {
        int flags = fcntl(s, F_GETFL, 0);
index d8557fc2ecf860ed8eff9756b8f8dfc13d9a5b6f..d9f13987fa9b7cab897e4eccf0a5851d1697ce09 100644 (file)
@@ -444,11 +444,6 @@ void Server::SendMode(const char** parameters, int pcnt, userrec *user)
        ServerInstance->ModeGrok->Process(parameters,pcnt,user,true);
 }
 
-bool Server::CommonChannels(userrec* u1, userrec* u2)
-{
-       return (common_channels(u1,u2) != 0);
-}
-
 void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
 {
        std::string CompleteLine = LinePrefix;
index 5086bd093d11ca81e272466a522b219d48cf2f19..929caf19c253f1ba4488c2298120eb31cf9d3961 100644 (file)
@@ -1564,3 +1564,37 @@ void userrec::WriteWallOps(const char* text, ...)
        this->WriteWallOps(std::string(textbuffer));
 }                                     
 
+/* return 0 or 1 depending if users u and u2 share one or more common channels
+ * (used by QUIT, NICK etc which arent channel specific notices)
+ *
+ * The old algorithm in 1.0 for this was relatively inefficient, iterating over
+ * the first users channels then the second users channels within the outer loop,
+ * therefore it was a maximum of x*y iterations (upon returning 0 and checking
+ * all possible iterations). However this new function instead checks against the
+ * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
+ * and saves us time as we already know what pointer value we are after.
+ * Don't quote me on the maths as i am not a mathematician or computer scientist,
+ * but i believe this algorithm is now x+(log y) maximum iterations instead.
+ */
+bool userrec::SharesChannelWith(userrec *other)
+{
+        if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
+                return false;
+
+        /* Outer loop */
+        for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+        {
+                /* Fetch the channel from the user */
+                ucrec* user_channel = *i;
+
+                if (user_channel->channel)
+                {
+                        /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
+                         * by replacing it with a map::find which *should* be more efficient
+                         */
+                        if (user_channel->channel->HasUser(other))
+                                return true;
+                }
+        }
+        return false;
+}