]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
core_channel Implement invite (un)serialization
[user/henk/code/inspircd.git] / src / users.cpp
index cb1bc901ee89a4c038b6d4b8e08c5a0335658daa..d503844e794c76641187828a43ff395f30180a5d 100644 (file)
@@ -139,28 +139,6 @@ const std::string& User::GetFullRealHost()
        return this->cached_fullrealhost;
 }
 
-InviteList& LocalUser::GetInviteList()
-{
-       RemoveExpiredInvites();
-       return invites;
-}
-
-bool LocalUser::RemoveInvite(Channel* chan)
-{
-       Invitation* inv = Invitation::Find(chan, this);
-       if (inv)
-       {
-               delete inv;
-               return true;
-       }
-       return false;
-}
-
-void LocalUser::RemoveExpiredInvites()
-{
-       Invitation::Find(NULL, this);
-}
-
 bool User::HasModePermission(unsigned char, ModeType)
 {
        return true;
@@ -328,7 +306,6 @@ CullResult User::cull()
 
 CullResult LocalUser::cull()
 {
-       ClearInvites();
        eh.cull();
        return User::cull();
 }
@@ -764,7 +741,7 @@ void LocalUser::Write(const std::string& text)
        if (text.length() > ServerInstance->Config->Limits.MaxLine - 2)
        {
                // this should happen rarely or never. Crop the string at 512 and try again.
-               std::string try_again(0, ServerInstance->Config->Limits.MaxLine - 2);
+               std::string try_again(text, 0, ServerInstance->Config->Limits.MaxLine - 2);
                Write(try_again);
                return;
        }
@@ -845,95 +822,37 @@ void User::WriteFrom(User *user, const char* text, ...)
        this->WriteFrom(user, textbuffer);
 }
 
-void User::WriteCommon(const char* text, ...)
+namespace
 {
-       if (this->registered != REG_ALL || quitting)
-               return;
-
-       std::string textbuffer;
-       VAFORMAT(textbuffer, text, text);
-       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
-       this->WriteCommonRaw(textbuffer, true);
-}
-
-void User::WriteCommonRaw(const std::string &line, bool include_self)
-{
-       if (this->registered != REG_ALL || quitting)
-               return;
-
-       LocalUser::already_sent_id++;
-
-       IncludeChanList include_c(chans.begin(), chans.end());
-       std::map<User*,bool> exceptions;
-
-       exceptions[this] = include_self;
-
-       FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
-
-       for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
+       class WriteCommonRawHandler : public User::ForEachNeighborHandler
        {
-               LocalUser* u = IS_LOCAL(i->first);
-               if (u && !u->quitting)
+               const std::string& msg;
+
+               void Execute(LocalUser* user) CXX11_OVERRIDE
                {
-                       u->already_sent = LocalUser::already_sent_id;
-                       if (i->second)
-                               u->Write(line);
+                       user->Write(msg);
                }
-       }
-       for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v)
-       {
-               Channel* c = (*v)->chan;
-               const Channel::MemberMap& ulist = c->GetUsers();
-               for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
+
+        public:
+               WriteCommonRawHandler(const std::string& message)
+                       : msg(message)
                {
-                       LocalUser* u = IS_LOCAL(i->first);
-                       if (u && u->already_sent != LocalUser::already_sent_id)
-                       {
-                               u->already_sent = LocalUser::already_sent_id;
-                               u->Write(line);
-                       }
                }
-       }
+       };
 }
 
-void User::WriteCommonQuit(const std::string &normal_text, const std::string &oper_text)
+void User::WriteCommon(const char* text, ...)
 {
-       if (this->registered != REG_ALL)
-               return;
-
-       already_sent_t uniq_id = ++LocalUser::already_sent_id;
-
-       const std::string normalMessage = ":" + this->GetFullHost() + " QUIT :" + normal_text;
-       const std::string operMessage = ":" + this->GetFullHost() + " QUIT :" + oper_text;
-
-       IncludeChanList include_c(chans.begin(), chans.end());
-       std::map<User*,bool> exceptions;
-
-       FOREACH_MOD(OnBuildNeighborList, (this, include_c, exceptions));
+       std::string textbuffer;
+       VAFORMAT(textbuffer, text, text);
+       textbuffer = ":" + this->GetFullHost() + " " + textbuffer;
+       this->WriteCommonRaw(textbuffer, true);
+}
 
-       for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
-       {
-               LocalUser* u = IS_LOCAL(i->first);
-               if (u && !u->quitting)
-               {
-                       u->already_sent = uniq_id;
-                       if (i->second)
-                               u->Write(u->IsOper() ? operMessage : normalMessage);
-               }
-       }
-       for (IncludeChanList::const_iterator v = include_c.begin(); v != include_c.end(); ++v)
-       {
-               const Channel::MemberMap& ulist = (*v)->chan->GetUsers();
-               for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); i++)
-               {
-                       LocalUser* u = IS_LOCAL(i->first);
-                       if (u && (u->already_sent != uniq_id))
-                       {
-                               u->already_sent = uniq_id;
-                               u->Write(u->IsOper() ? operMessage : normalMessage);
-                       }
-               }
-       }
+void User::WriteCommonRaw(const std::string &line, bool include_self)
+{
+       WriteCommonRawHandler handler(line);
+       ForEachNeighbor(handler, include_self);
 }
 
 void User::ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self)