]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Get rid of Server::GetUsers(chanrec) - a throwback to before chanrec could do this...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 9 Aug 2006 10:37:42 +0000 (10:37 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 9 Aug 2006 10:37:42 +0000 (10:37 +0000)
Move:
bool ChangeDisplayedHost(const char* host);
bool ChangeName(const char* gecos);
int CountChannels();
Into userrec

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4807 e03df62e-2008-0410-955e-edbf42e46eb7

17 files changed:
include/message.h
include/modules.h
include/users.h
src/cmd_oper.cpp
src/message.cpp
src/modules.cpp
src/modules/extra/m_sqloper.cpp
src/modules/m_chanprotect.cpp
src/modules/m_chghost.cpp
src/modules/m_cloaking.cpp
src/modules/m_hostchange.cpp
src/modules/m_sethost.cpp
src/modules/m_setname.cpp
src/modules/m_spanningtree.cpp
src/modules/m_sslmodes.cpp
src/modules/m_vhost.cpp
src/users.cpp

index 7d7f4b0070e3a379fd262a3082e7cf668fa7ec92..f53f3d9d2670a3544487cccbfa78f5e41256bfb1 100644 (file)
@@ -28,9 +28,6 @@
 #include "users.h"
 #include "channels.h"
 
-int c_count(userrec* u);
-void ChangeName(userrec* user, const char* gecos);
-void ChangeDisplayedHost(userrec* user, const char* host);
 int isident(const char* n);
 int isnick(const char* n);
 const char* cmode(userrec *user, chanrec *chan);
index cb105c60e58d99bda22685cc1056dbfc369811db..f35aef0b0cd9ad78276c8ca3310fd76854114285 100644 (file)
@@ -84,11 +84,6 @@ class Module;
 typedef std::deque<std::string> file_cache;
 typedef file_cache string_list;
 
-/** Holds a list of users in a channel
- */
-typedef std::deque<userrec*> chanuserlist;
-
-
 /** Holds a list of 'published features' for modules.
  */
 typedef std::map<std::string,Module*> featurelist;
@@ -1472,20 +1467,6 @@ class Server : public Extensible
         */
        virtual bool IsValidModuleCommand(const std::string &commandname, int pcnt, userrec* user);
        
-       /** Change displayed hostname of a user.
-        * You should always call this method to change a user's host rather than writing directly to the
-        * dhost member of userrec, as any change applied via this method will be propogated to any
-        * linked servers.
-        */     
-       virtual void ChangeHost(userrec* user, const std::string &host);
-       
-       /** Change GECOS (fullname) of a user.
-        * You should always call this method to change a user's GECOS rather than writing directly to the
-        * fullname member of userrec, as any change applied via this method will be propogated to any
-        * linked servers.
-        */     
-       virtual void ChangeGECOS(userrec* user, const std::string &gecos);
-       
        /** Returns true if the servername you give is ulined.
         * ULined servers have extra privilages. They are allowed to change nicknames on remote servers,
         * change modes of clients which are on remote servers and set modes of channels where there are
@@ -1493,11 +1474,6 @@ class Server : public Extensible
         */
        virtual bool IsUlined(const std::string &server);
        
-       /** Fetches the userlist of a channel. This function must be here and not a member of userrec or
-        * chanrec due to include constraints.
-        */
-       virtual chanuserlist GetUsers(chanrec* chan);
-
        /** Remove a user's connection to the irc server, but leave their client in existence in the
         * user hash. When you call this function, the user's file descriptor will be replaced with the
         * value of FD_MAGIC_NUMBER and their old file descriptor will be closed. This idle client will
index cc70740048df711b1bef3cd33f84082017446e47..82da66c19f8665ba405bea063e45c0e4e25c9bfe 100644 (file)
@@ -633,6 +633,12 @@ class userrec : public connection
 
        bool SharesChannelWith(userrec *other);
 
+       bool ChangeDisplayedHost(const char* host);
+
+       bool ChangeName(const char* gecos);
+
+       int CountChannels();
+
        /** Default destructor
         */
        virtual ~userrec();
index eafeb227b1dc175cd17b056190757c183cdfe41f..abd34f65341cca94f281b608e69bfe7da67498a8 100644 (file)
@@ -93,7 +93,7 @@ void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
                                        /* found this oper's opertype */
                                        Config->ConfValue(Config->config_data, "type","host", j, HostName, MAXBUF);
                                        if (*HostName)
-                                               ChangeDisplayedHost(user,HostName);
+                                               user->ChangeDisplayedHost(HostName);
                                        if (!isnick(TypeName))
                                        {
                                                user->WriteServ("491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
index e69ce94ab0f4ff37bd1f0953acab10deef40b247..455c9754f86fbbc11d1daa361d0b2c20609a4854 100644 (file)
@@ -48,43 +48,6 @@ extern std::vector<ircd_module*> factory;
 extern time_t TIME;
 extern ServerConfig* Config;
 
-int c_count(userrec* u)
-{
-       int z = 0;
-       for (std::vector<ucrec*>::const_iterator i = u->chans.begin(); i != u->chans.end(); i++)
-               if ((*i)->channel)
-                       z++;
-       return z;
-
-}
-
-void ChangeName(userrec* user, const char* gecos)
-{
-       if (user->fd > -1)
-       {
-               int MOD_RESULT = 0;
-               FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(user,gecos));
-               if (MOD_RESULT)
-                       return;
-               FOREACH_MOD(I_OnChangeName,OnChangeName(user,gecos));
-       }
-       strlcpy(user->fullname,gecos,MAXGECOS+1);
-}
-
-void ChangeDisplayedHost(userrec* user, const char* host)
-{
-       if (user->fd > -1)
-       {
-               int MOD_RESULT = 0;
-               FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(user,host));
-               if (MOD_RESULT)
-                       return;
-               FOREACH_MOD(I_OnChangeHost,OnChangeHost(user,host));
-       }
-       strlcpy(user->dhost,host,63);
-       user->WriteServ("396 %s %s :is now your hidden host",user->nick,user->dhost);
-}
-
 /* verify that a user's ident and nickname is valid */
 
 int isident(const char* n)
index d9f13987fa9b7cab897e4eccf0a5851d1697ce09..3675319eca3d2166ea32788b7f9ecb95332b4a42 100644 (file)
@@ -400,16 +400,6 @@ void Server::SendToModeMask(const std::string &modes, int flags, const std::stri
        WriteMode(modes.c_str(),flags,"%s",text.c_str());
 }
 
-chanuserlist Server::GetUsers(chanrec* chan)
-{
-       chanuserlist userl;
-       userl.clear();
-       CUList *list = chan->GetUsers();
-       for (CUList::iterator i = list->begin(); i != list->end(); i++)
-               userl.push_back(i->second);
-       return userl;
-}
-
 bool Server::IsUlined(const std::string &server)
 {
        return is_uline(server.c_str());
@@ -460,16 +450,6 @@ void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream
        User->WriteServ(CompleteLine);
 }
 
-void Server::ChangeHost(userrec* user, const std::string &host)
-{
-       ChangeDisplayedHost(user,host.c_str());
-}
-
-void Server::ChangeGECOS(userrec* user, const std::string &gecos)
-{
-       ChangeName(user,gecos.c_str());
-}
-
 bool Server::IsNick(const std::string &nick)
 {
        return (isnick(nick.c_str()) != 0);
index 3e91959b8c0b6b9e0230f115a37b8c4e1aa10c0f..a67ec46e266b18531b7d10ef1383b2e572a03ca2 100644 (file)
@@ -231,7 +231,7 @@ public:
                                std::string operhost = Conf.ReadValue("type", "host", j);
                                                        
                                if (operhost.size())
-                                       Srv->ChangeHost(user, operhost);
+                                       user->ChangeDisplayedHost(operhost);
                                                                
                                strlcpy(user->oper, type.c_str(), NICKMAX-1);
                                
index 85e8d4a78b23cb83a80a39efd9b840091ee560d0..4ad3796b9868c9a9c69e02b218866d4077c1e22d 100644 (file)
@@ -3,13 +3,13 @@
  *       +------------------------------------+
  *
  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
+ *                    E-mail:
+ *             <brain@chatspike.net>
+ *               <Craig@chatspike.net>
  *     
  * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -33,9 +33,9 @@ class ChanFounder : public ModeHandler
 
        ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
        {
-               userrec* x = Find(parameter);
-               if (x)
-               {
+               userrec* x = Find(parameter);
+               if (x)
+               {
                        if (!channel->HasUser(x))
                        {
                                return std::make_pair(false, parameter);
@@ -44,15 +44,15 @@ class ChanFounder : public ModeHandler
                        {
                                std::string founder = "cm_founder_"+std::string(channel->name);
                                if (x->GetExt(founder,dummyptr))
-                               {
-                                       return std::make_pair(true, x->nick);
-                               }
-                               else
-                               {
-                                       return std::make_pair(false, parameter);
-                               }
+                               {
+                                       return std::make_pair(true, x->nick);
+                               }
+                               else
+                               {
+                                       return std::make_pair(false, parameter);
+                               }
                        }
-               }
+               }
                return std::make_pair(false, parameter);
        }
 
@@ -125,13 +125,13 @@ class ChanFounder : public ModeHandler
 
        void DisplayList(userrec* user, chanrec* channel)
        {
-               chanuserlist cl = Srv->GetUsers(channel);
+               CUList* cl = channel->GetUsers();
                std::string founder = "cm_founder_"+std::string(channel->name);
-               for (unsigned int i = 0; i < cl.size(); i++)
+               for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
                {
-                       if (cl[i]->GetExt(founder, dummyptr))
+                       if (i->second->GetExt(founder, dummyptr))
                        {
-                               user->WriteServ("386 %s %s %s",user->nick, channel->name,cl[i]->nick);
+                               user->WriteServ("386 %s %s %s",user->nick, channel->name,i->second->nick);
                        }
                }
                user->WriteServ("387 %s %s :End of channel founder list",user->nick, channel->name);
@@ -146,30 +146,30 @@ class ChanProtect : public ModeHandler
  public:
        ChanProtect(Server* s) : ModeHandler('a', 1, 1, true, MODETYPE_CHANNEL, false), Srv(s) { }
 
-        ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
-        {
-                userrec* x = Find(parameter);
-                if (x)
-                {
-                        if (!channel->HasUser(x))
-                        {
-                                return std::make_pair(false, parameter);
-                        }
-                        else
-                        {
-                                std::string founder = "cm_protect_"+std::string(channel->name);
-                                if (x->GetExt(founder,dummyptr))
-                                {
-                                        return std::make_pair(true, x->nick);
-                                }
-                                else
-                                {
-                                        return std::make_pair(false, parameter);
-                                }
-                        }
-                }
-                return std::make_pair(false, parameter);
-        }
+       ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
+       {
+               userrec* x = Find(parameter);
+               if (x)
+               {
+                       if (!channel->HasUser(x))
+                       {
+                               return std::make_pair(false, parameter);
+                       }
+                       else
+                       {
+                               std::string founder = "cm_protect_"+std::string(channel->name);
+                               if (x->GetExt(founder,dummyptr))
+                               {
+                                       return std::make_pair(true, x->nick);
+                               }
+                               else
+                               {
+                                       return std::make_pair(false, parameter);
+                               }
+                       }
+               }
+               return std::make_pair(false, parameter);
+       }
 
        ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
        {
@@ -227,13 +227,13 @@ class ChanProtect : public ModeHandler
 
        virtual void DisplayList(userrec* user, chanrec* channel)
        {
-               chanuserlist cl = Srv->GetUsers(channel);
+               CUList* cl = channel->GetUsers();
                std::string protect = "cm_protect_"+std::string(channel->name);
-               for (unsigned int i = 0; i < cl.size(); i++)
+               for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
                {
-                       if (cl[i]->GetExt(protect,dummyptr))
+                       if (i->second->GetExt(protect,dummyptr))
                        {
-                               user->WriteServ("388 %s %s %s",user->nick, channel->name,cl[i]->nick);
+                               user->WriteServ("388 %s %s %s",user->nick, channel->name,i->second->nick);
                        }
                }
                user->WriteServ("389 %s %s :End of channel protected user list",user->nick, channel->name);
@@ -436,19 +436,19 @@ class ModuleChanProtect : public Module
                // this is called when the server is linking into a net and wants to sync channel data.
                // we should send our mode changes for the channel here to ensure that other servers
                // know whos +q/+a on the channel.
-               chanuserlist cl = Srv->GetUsers(chan);
+               CUList* cl = chan->GetUsers();
                string_list commands;
                std::string founder = "cm_founder_"+std::string(chan->name);
                std::string protect = "cm_protect_"+std::string(chan->name);
-               for (unsigned int i = 0; i < cl.size(); i++)
+               for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
                {
-                       if (cl[i]->GetExt(founder,dummyptr))
+                       if (i->second->GetExt(founder,dummyptr))
                        {
-                               proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+q "+std::string(cl[i]->nick));
+                               proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+q "+std::string(i->second->nick));
                        }
-                       if (cl[i]->GetExt(protect,dummyptr))
+                       if (i->second->GetExt(protect,dummyptr))
                        {
-                               proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+a "+std::string(cl[i]->nick));
+                               proto->ProtoSendMode(opaque,TYPE_CHANNEL,chan,"+a "+std::string(i->second->nick));
                        }
                }
        }
index 82a94fadc82b581700952a4e90c37ae403bf1708..23a482a65343427b51b5ec07c9542b0dd83a0eb9 100644 (file)
@@ -59,8 +59,7 @@ class cmd_chghost : public command_t
                userrec* dest = Srv->FindNick(std::string(parameters[0]));
                if (dest)
                {
-                       Srv->ChangeHost(dest,parameters[1]);
-                       if (!Srv->IsUlined(user->server))
+                       if ((dest->ChangeDisplayedHost(parameters[1])) && (!Srv->IsUlined(user->server)))
                        {
                                // fix by brain - ulines set hosts silently
                                Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1]));
index 1e1826b4199c0e3a0eb5b7f9e4e4beb5f28575d2..b8164d9ba2771f31cef83ce25108a0190b13f43c 100644 (file)
@@ -347,7 +347,7 @@ class CloakUser : public ModeHandler
                                                b = std::string(ra) + "." + prefix + ".cloak";
                                        }
                                        Srv->Log(DEBUG,"cloak: allocated "+b);
-                                       Srv->ChangeHost(dest,b);
+                                       dest->ChangeDisplayedHost(b.c_str());
                                }
                                
                                dest->SetMode('x',true);
@@ -361,7 +361,7 @@ class CloakUser : public ModeHandler
                                /* User is removing the mode, so just restore their real host
                                 * and make it match the displayed one.
                                 */
-                               Srv->ChangeHost(dest,dest->host);
+                               dest->ChangeDisplayedHost(dest->host);
                                dest->SetMode('x',false);
                                return MODEACTION_ALLOW;
                        }
index 0a9ea8ccc045846899590a45eb7415b9520a38ff..354eea3ed3489659727c3224de596e1828885f71 100644 (file)
@@ -134,7 +134,8 @@ class ModuleHostChange : public Module
                                if (newhost != "")
                                {
                                        user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
-                                       Srv->ChangeHost(user,newhost);
+                                       if (!user->ChangeDisplayedHost(newhost.c_str()))
+                                               user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
                                        return;
                                }
                        }
index 94e811d798511cd718e54092ae9feac2a962aa63..631bd13a1fc1c64ac22987809d71134f73fa2c5e 100644 (file)
@@ -54,8 +54,8 @@ class cmd_sethost : public command_t
                                }
                        }
                }
-               Srv->ChangeHost(user,parameters[0]);
-               Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
+               if (user->ChangeDisplayedHost(parameters[0]))
+                       Srv->SendOpers(std::string(user->nick)+" used SETHOST to change their displayed host to "+std::string(parameters[0]));
        }
 };
 
index 72d255be7ea45654236cb28723d06afbf4563ba2..30eab34df30bf16058322d152a8547a983bb46e1 100644 (file)
@@ -44,7 +44,7 @@ class cmd_setname : public command_t
                        line = line + std::string(parameters[i]) + " ";
                }
                line = line + std::string(parameters[pcnt-1]);
-               Srv->ChangeGECOS(user,line);
+               user->ChangeName(line.c_str());
        }
 };
 
index 6ced44c9f7ce2ba0ee5c634981a838ee30a30f6b..aeeaa2c52f0386f33a2accacc62bb5839d5803b5 100644 (file)
@@ -2189,7 +2189,7 @@ class TreeSocket : public InspSocket
 
                if (u)
                {
-                       Srv->ChangeHost(u,params[0]);
+                       u->ChangeDisplayedHost(params[0].c_str());
                        DoOneToAllButSender(prefix,"FHOST",params,u->server);
                }
                return true;
@@ -2261,7 +2261,7 @@ class TreeSocket : public InspSocket
 
                if (u)
                {
-                       Srv->ChangeGECOS(u,params[0]);
+                       u->ChangeName(params[0].c_str());
                        params[0] = ":" + params[0];
                        DoOneToAllButSender(prefix,"FNAME",params,u->server);
                }
index 673c30536f208c17fee8a3abec9426a0f155efba..0d4b0e515bc37c629870d91d54cd32d93cc1267a 100644 (file)
@@ -19,13 +19,16 @@ class SSLMode : public ModeHandler
                {
                        if (!channel->IsModeSet('z'))
                        {
-                               chanuserlist userlist = Srv->GetUsers(channel);
-                               for(unsigned int i = 0; i < userlist.size(); i++)
+                               if (IS_LOCAL(source))
                                {
-                                       if(!userlist[i]->GetExt("ssl", dummy))
+                                       CUList* userlist = channel->GetUsers();
+                                       for(CUList::iterator i = userlist->begin(); i != userlist->end(); i++)
                                        {
-                                               source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
-                                               return MODEACTION_DENY;
+                                               if(!i->second->GetExt("ssl", dummy))
+                                               {
+                                                       source->WriteServ("490 %s %s :all members of the channel must be connected via SSL", source->nick, channel->name);
+                                                       return MODEACTION_DENY;
+                                               }
                                        }
                                }
                                channel->SetMode('z',true);
index 71fadf2f901d1072dd8fa7024a4f28edde3cd369..80d3f8f6b16fdada9655ed4c88f3863bae1e33cd 100644 (file)
@@ -48,7 +48,7 @@ class cmd_vhost : public command_t
                                if (mask != "")
                                {
                                        user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
-                                       Srv->ChangeHost(user,mask);
+                                       user->ChangeDisplayedHost(mask.c_str());
                                        return;
                                }
                        }
index 929caf19c253f1ba4488c2298120eb31cf9d3961..bb3ef18e90e88768dbea368188397332f1104ce9 100644 (file)
@@ -1578,23 +1578,65 @@ void userrec::WriteWallOps(const char* text, ...)
  */
 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;
+       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;
+}
+
+int userrec::CountChannels()
+{
+       int z = 0;
+       for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+               if ((*i)->channel)
+                       z++;
+       return z;
+}
+
+bool userrec::ChangeName(const char* gecos)
+{
+       if (IS_LOCAL(this))
+       {
+               int MOD_RESULT = 0;
+               FOREACH_RESULT(I_OnChangeLocalUserGECOS,OnChangeLocalUserGECOS(this,gecos));
+               if (MOD_RESULT)
+                       return false;
+               FOREACH_MOD(I_OnChangeName,OnChangeName(this,gecos));
+       }
+       strlcpy(this->fullname,gecos,MAXGECOS+1);
+       return true;
 }
+
+bool userrec::ChangeDisplayedHost(const char* host)
+{
+       if (IS_LOCAL(this))
+       {
+               int MOD_RESULT = 0;
+               FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host));
+               if (MOD_RESULT)
+                       return false;
+               FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
+       }
+       strlcpy(this->dhost,host,63);
+
+       if (IS_LOCAL(this))
+               this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
+
+       return true;
+}
+