]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Remove this, we're not going to keep the .old, makes it twice as much work to documen...
[user/henk/code/inspircd.git] / src / users.cpp
index 01a973deae90a7b444736f0572cdc25b78377a8b..b53dcaca345342492ef7565749f7cddb59878cf6 100644 (file)
@@ -216,8 +216,6 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
        Visibility = NULL;
        ip = NULL;
        MyClass = NULL;
-       AllowedUserModes = NULL;
-       AllowedChanModes = NULL;
        AllowedOperCommands = NULL;
        chans.clear();
        invites.clear();
@@ -250,18 +248,6 @@ User::~User()
                AllowedOperCommands = NULL;
        }
 
-       if (this->AllowedUserModes)
-       {
-               delete[] AllowedUserModes;
-               AllowedUserModes = NULL;
-       }
-
-       if (this->AllowedChanModes)
-       {
-               delete[] AllowedChanModes;
-               AllowedChanModes = NULL;
-       }
-
        this->InvalidateCache();
        this->DecrementModes();
 
@@ -483,8 +469,7 @@ bool User::HasModePermission(unsigned char mode, ModeType type)
        if (!IS_OPER(this))
                return false;
 
-       if (!AllowedUserModes || !AllowedChanModes)
-               return false;
+       if (mode < 'A' || mode > ('A' + 64)) return false;
 
        return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')];
        
@@ -708,10 +693,6 @@ void User::FlushWriteBuf()
 
 void User::Oper(const std::string &opertype, const std::string &opername)
 {
-       char* mycmd;
-       char* savept;
-       char* savept2;
-
        if (this->IsModeSet('o'))
                this->UnOper();
 
@@ -735,36 +716,27 @@ void User::Oper(const std::string &opertype, const std::string &opername)
                else
                        AllowedOperCommands = new std::map<std::string, bool>;
 
-               if (!AllowedChanModes)
-                       AllowedChanModes = new bool[64];
-
-               if (!AllowedUserModes)
-                       AllowedUserModes = new bool[64];
+               AllowedUserModes.reset();
+               AllowedChanModes.reset();
+               this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
 
-               memset(AllowedUserModes, 0, 64);
-               memset(AllowedChanModes, 0, 64);
-
-               char* Classes = strdup(iter_opertype->second);
-               char* myclass = strtok_r(Classes," ",&savept);
-               while (myclass)
+               std::string myclass, mycmd;
+               irc::spacesepstream Classes(iter_opertype->second);
+               while (Classes.GetToken(myclass))
                {
-                       operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
+                       operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass.c_str());
                        if (iter_operclass != ServerInstance->Config->operclass.end())
                        {
-                               char* CommandList = strdup(iter_operclass->second.commandlist);
-                               mycmd = strtok_r(CommandList," ",&savept2);
-                               while (mycmd)
+                               irc::spacesepstream CommandList(iter_operclass->second.commandlist);
+                               while (CommandList.GetToken(mycmd))
                                {
                                        this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
-                                       mycmd = strtok_r(NULL," ",&savept2);
                                }
-                               free(CommandList);
-                               this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want.
                                for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c)
                                {
                                        if (*c == '*')
                                        {
-                                               memset(this->AllowedUserModes, (int)(true), 64);
+                                               this->AllowedUserModes.set();
                                        }
                                        else
                                        {
@@ -775,7 +747,7 @@ void User::Oper(const std::string &opertype, const std::string &opername)
                                {
                                        if (*c == '*')
                                        {
-                                               memset(this->AllowedChanModes, (int)(true), 64);
+                                               this->AllowedChanModes.set();
                                        }
                                        else
                                        {
@@ -783,9 +755,7 @@ void User::Oper(const std::string &opertype, const std::string &opername)
                                        }
                                }
                        }
-                       myclass = strtok_r(NULL," ",&savept);
                }
-               free(Classes);
        }
 
        FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype, opername));
@@ -826,17 +796,9 @@ void User::UnOper()
                        delete AllowedOperCommands;
                        AllowedOperCommands = NULL;
                }
-               if (AllowedUserModes)
-               {
-                       delete[] AllowedUserModes;
-                       AllowedUserModes = NULL;
-               }
-               if (AllowedChanModes)
-               {
-                       delete[] AllowedChanModes;
-                       AllowedChanModes = NULL;
-               }
 
+               AllowedUserModes.reset();
+               AllowedChanModes.reset();
        }
 }
 
@@ -880,10 +842,10 @@ void User::CheckClass()
        this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
 }
 
-bool User::CheckLines()
+bool User::CheckLines(bool doZline)
 {
-       const char* check[] = { "G" , "K", NULL };
-
+       const char* check[] = { "G" , "K", (doZline) ? "Z" : NULL, NULL };
+       
        if (!this->exempt)
        {
                for (int n = 0; check[n]; ++n)
@@ -983,8 +945,8 @@ User* User::UpdateNickHash(const char* New)
                return NULL; /* doesnt exist */
 
        User* olduser = oldnick->second;
-       (*(ServerInstance->Users->clientlist))[New] = olduser;
        ServerInstance->Users->clientlist->erase(oldnick);
+       (*(ServerInstance->Users->clientlist))[New] = olduser;
        return olduser;
 }
 
@@ -1644,7 +1606,10 @@ bool User::ChangeDisplayedHost(const char* shost)
                FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost));
        }
 
-       if (this->ServerInstance->Config->CycleHosts)
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
+
+       if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
                this->WriteCommonExcept("QUIT :Changing hosts");
 
        /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */
@@ -1652,7 +1617,7 @@ bool User::ChangeDisplayedHost(const char* shost)
 
        this->InvalidateCache();
 
-       if (this->ServerInstance->Config->CycleHosts)
+       if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
        {
                for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
                {
@@ -1671,17 +1636,20 @@ bool User::ChangeDisplayedHost(const char* shost)
 
 bool User::ChangeIdent(const char* newident)
 {
-       if (!this->ident.compare(newident))
+       if (this->ident == newident)
                return true;
 
-       if (this->ServerInstance->Config->CycleHosts)
+        int MOD_RESULT = 0;
+       FOREACH_RESULT(I_OnHostCycle, OnHostCycle(this));
+
+       if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
                this->WriteCommonExcept("%s","QUIT :Changing ident");
 
        this->ident.assign(newident, 0, ServerInstance->Config->Limits.IdentMax + 1);
 
        this->InvalidateCache();
 
-       if (this->ServerInstance->Config->CycleHosts)
+       if (this->ServerInstance->Config->CycleHosts && !MOD_RESULT)
        {
                for (UCListIter i = this->chans.begin(); i != this->chans.end(); i++)
                {