]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Match USERINPUT/USEROUTPUT identifiers
[user/henk/code/inspircd.git] / src / users.cpp
index 170b0c7ece22054d656696274680625638007e54..14edf649f30710e8e483fa8625326be8bf02b286 100644 (file)
@@ -221,14 +221,13 @@ void User::DecrementModes()
        }
 }
 
-User::User(const std::string &uid)
+User::User(const std::string &uid, const std::string& sid, int type)
+       : uuid(uid), server(sid), usertype(type)
 {
-       server = ServerInstance->Config->ServerName;
        age = ServerInstance->Time();
-       signon = idle_lastmsg = registered = 0;
+       signon = idle_lastmsg = 0;
+       registered = 0;
        quietquit = quitting = exempt = dns_done = false;
-       fd = -1;
-       uuid = uid;
        client_sa.sa.sa_family = AF_UNSPEC;
 
        ServerInstance->Logs->Log("USERS", DEBUG, "New UUID for user: %s", uuid.c_str());
@@ -240,17 +239,21 @@ User::User(const std::string &uid)
                throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
 }
 
-LocalUser::LocalUser() : User(ServerInstance->GetUID())
+LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
+       : User(ServerInstance->GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL)
 {
        bytes_in = bytes_out = cmds_in = cmds_out = 0;
        server_sa.sa.sa_family = AF_UNSPEC;
        Penalty = 0;
        lastping = nping = 0;
+       SetFd(myfd);
+       memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
+       memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
 }
 
 User::~User()
 {
-       if (uuid.length())
+       if (ServerInstance->Users->uuidlist->find(uuid) != ServerInstance->Users->uuidlist->end())
                ServerInstance->Logs->Log("USERS", ERROR, "User destructor for %s called without cull", uuid.c_str());
 }
 
@@ -294,7 +297,7 @@ const std::string& User::MakeHostIP()
        return this->cached_hostip;
 }
 
-const std::string User::GetFullHost()
+const std::string& User::GetFullHost()
 {
        if (!this->cached_fullhost.empty())
                return this->cached_fullhost;
@@ -328,7 +331,7 @@ char* User::MakeWildHost()
        return nresult;
 }
 
-const std::string User::GetFullRealHost()
+const std::string& User::GetFullRealHost()
 {
        if (!this->cached_fullrealhost.empty())
                return this->cached_fullrealhost;
@@ -584,20 +587,15 @@ CullResult User::cull()
 {
        if (!quitting)
                ServerInstance->Users->QuitUser(this, "Culled without QuitUser");
-       if (uuid.empty())
-       {
-               ServerInstance->Logs->Log("USERS", DEBUG, "User culled twice? UUID empty");
-               return Extensible::cull();
-       }
        PurgeEmptyChannels();
-       if (IS_LOCAL(this) && fd != INT_MAX)
-               Close();
 
        this->InvalidateCache();
        this->DecrementModes();
 
+       if (client_sa.sa.sa_family != AF_UNSPEC)
+               ServerInstance->Users->RemoveCloneCounts(this);
+
        ServerInstance->Users->uuidlist->erase(uuid);
-       uuid.clear();
        return Extensible::cull();
 }
 
@@ -609,8 +607,14 @@ CullResult LocalUser::cull()
        else
                ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector");
 
-       if (client_sa.sa.sa_family != AF_UNSPEC)
-               ServerInstance->Users->RemoveCloneCounts(this);
+       Close();
+       return User::cull();
+}
+
+CullResult FakeUser::cull()
+{
+       // Fake users don't quit, they just get culled.
+       quitting = true;
        return User::cull();
 }
 
@@ -964,7 +968,7 @@ const char* User::GetIPString()
        return cachedip.c_str();
 }
 
-irc::string User::GetCIDRMask()
+irc::sockets::cidr_mask User::GetCIDRMask()
 {
        int range = 0;
        switch (client_sa.sa.sa_family)
@@ -976,7 +980,7 @@ irc::string User::GetCIDRMask()
                        range = ServerInstance->Config->c_ipv4_range;
                        break;
        }
-       return assign(irc::sockets::mask(client_sa, range));
+       return irc::sockets::cidr_mask(client_sa, range);
 }
 
 bool User::SetClientIP(const char* sip)
@@ -1008,7 +1012,7 @@ void LocalUser::Write(const std::string& text)
                return;
        }
 
-       ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
+       ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%s] O %s", uuid.c_str(), text.c_str());
 
        this->AddWriteBuf(text);
        this->AddWriteBuf(wide_newline);
@@ -1173,10 +1177,10 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
 
        for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
        {
-               User* u = i->first;
-               if (IS_LOCAL(u) && !u->quitting)
+               LocalUser* u = IS_LOCAL(i->first);
+               if (u && !u->quitting)
                {
-                       already_sent[u->fd] = uniq_id;
+                       already_sent[u->GetFd()] = uniq_id;
                        if (i->second)
                                u->Write(line);
                }
@@ -1187,10 +1191,10 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
                const UserMembList* ulist = c->GetUsers();
                for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
                {
-                       User* u = i->first;
-                       if (IS_LOCAL(u) && !u->quitting && already_sent[u->fd] != uniq_id)
+                       LocalUser* u = IS_LOCAL(i->first);
+                       if (u && !u->quitting && already_sent[u->GetFd()] != uniq_id)
                        {
-                               already_sent[u->fd] = uniq_id;
+                               already_sent[u->GetFd()] = uniq_id;
                                u->Write(line);
                        }
                }
@@ -1219,10 +1223,10 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
 
        for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
        {
-               User* u = i->first;
-               if (IS_LOCAL(u) && !u->quitting)
+               LocalUser* u = IS_LOCAL(i->first);
+               if (u && !u->quitting)
                {
-                       already_sent[u->fd] = uniq_id;
+                       already_sent[u->GetFd()] = uniq_id;
                        if (i->second)
                                u->Write(IS_OPER(u) ? out2 : out1);
                }
@@ -1232,10 +1236,10 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
                const UserMembList* ulist = (*v)->GetUsers();
                for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
                {
-                       User* u = i->first;
-                       if (IS_LOCAL(u) && !u->quitting && (already_sent[u->fd] != uniq_id))
+                       LocalUser* u = IS_LOCAL(i->first);
+                       if (u && !u->quitting && (already_sent[u->GetFd()] != uniq_id))
                        {
-                               already_sent[u->fd] = uniq_id;
+                               already_sent[u->GetFd()] = uniq_id;
                                u->Write(IS_OPER(u) ? out2 : out1);
                        }
                }
@@ -1356,17 +1360,17 @@ void User::DoHostCycle(const std::string &quitline)
 
        for (std::map<User*,bool>::iterator i = exceptions.begin(); i != exceptions.end(); ++i)
        {
-               User* u = i->first;
-               if (IS_LOCAL(u) && !u->quitting)
+               LocalUser* u = IS_LOCAL(i->first);
+               if (u && !u->quitting)
                {
                        if (i->second)
                        {
-                               already_sent[u->fd] = seen_id;
+                               already_sent[u->GetFd()] = seen_id;
                                u->Write(quitline);
                        }
                        else
                        {
-                               already_sent[u->fd] = silent_id;
+                               already_sent[u->GetFd()] = silent_id;
                        }
                }
        }
@@ -1375,9 +1379,12 @@ void User::DoHostCycle(const std::string &quitline)
                Channel* c = *v;
                snprintf(buffer, MAXBUF, ":%s JOIN %s", GetFullHost().c_str(), c->name.c_str());
                std::string joinline(buffer);
-               std::string modeline = ServerInstance->Modes->ModeString(this, c);
+               Membership* memb = c->GetUser(this);
+               std::string modeline = memb->modes;
                if (modeline.length() > 0)
                {
+                       for(unsigned int i=0; i < memb->modes.length(); i++)
+                               modeline.append(" ").append(nick);
                        snprintf(buffer, MAXBUF, ":%s MODE %s +%s", GetFullHost().c_str(), c->name.c_str(), modeline.c_str());
                        modeline = buffer;
                }
@@ -1385,16 +1392,16 @@ void User::DoHostCycle(const std::string &quitline)
                const UserMembList *ulist = c->GetUsers();
                for (UserMembList::const_iterator i = ulist->begin(); i != ulist->end(); i++)
                {
-                       User* u = i->first;
-                       if (u == this || !IS_LOCAL(u))
+                       LocalUser* u = IS_LOCAL(i->first);
+                       if (u == NULL || u == this)
                                continue;
-                       if (already_sent[u->fd] == silent_id)
+                       if (already_sent[u->GetFd()] == silent_id)
                                continue;
 
-                       if (already_sent[u->fd] != seen_id)
+                       if (already_sent[u->GetFd()] != seen_id)
                        {
                                u->Write(quitline);
-                               already_sent[i->first->fd] = seen_id;
+                               already_sent[u->GetFd()] = seen_id;
                        }
                        u->Write(joinline);
                        if (modeline.length() > 0)
@@ -1670,24 +1677,18 @@ void User::ShowRULES()
        this->WriteNumeric(RPL_RULESEND, "%s :End of RULES command.",this->nick.c_str());
 }
 
-void FakeUser::SetFakeServer(std::string name)
-{
-       this->nick = name;
-       this->server = name;
-}
-
-const std::string FakeUser::GetFullHost()
+const std::string& FakeUser::GetFullHost()
 {
        if (!ServerInstance->Config->HideWhoisServer.empty())
                return ServerInstance->Config->HideWhoisServer;
-       return nick;
+       return server;
 }
 
-const std::string FakeUser::GetFullRealHost()
+const std::string& FakeUser::GetFullRealHost()
 {
        if (!ServerInstance->Config->HideWhoisServer.empty())
                return ServerInstance->Config->HideWhoisServer;
-       return nick;
+       return server;
 }
 
 ConnectClass::ConnectClass(ConfigTag* tag, char t, const std::string& mask)