summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/message.cpp35
-rw-r--r--src/modules.cpp5
-rw-r--r--src/users.cpp34
3 files changed, 34 insertions, 40 deletions
diff --git a/src/message.cpp b/src/message.cpp
index a786c60cb..9b56cc8ca 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -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);
diff --git a/src/modules.cpp b/src/modules.cpp
index d8557fc2e..d9f13987f 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -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;
diff --git a/src/users.cpp b/src/users.cpp
index 5086bd093..929caf19c 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -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;
+}