]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Add comments
[user/henk/code/inspircd.git] / src / channels.cpp
index e252100f169a53e27d0528283042c373723ec2d9..cab05caeb1b7a607c3faba8d2c74d6c1a58431d4 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
 #include "wildcard.h"
 #include "mode.h"
 
-Channel::Channel(InspIRCd* Instance) : ServerInstance(Instance)
+Channel::Channel(InspIRCd* Instance, const std::string &name, time_t ts) : ServerInstance(Instance)
 {
-       *name = *topic = *setby = *key = 0;
-       maxbans = created = topicset = limit = 0;
+       chan_hash::iterator findchan = ServerInstance->chanlist->find(name);
+       if (findchan != Instance->chanlist->end())
+               throw CoreException("Cannot create duplicate channel " + name);
+
+       (*(ServerInstance->chanlist))[name.c_str()] = this;
+       strlcpy(this->name, name.c_str(), CHANMAX);
+       this->created = ts ? ts : ServerInstance->Time(true);
+       this->age = this->created;
+
+
+
+
+       *topic = *setby = *key = 0;
+       maxbans = topicset = limit = 0;
        memset(&modes,0,64);
-       age = ServerInstance->Time(true);
 }
 
 void Channel::SetMode(char mode,bool mode_on)
@@ -271,7 +282,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
                                return NULL;
                }
 
-               Ptr = Channel::CreateChannel(Instance, cname, TS);
+               Ptr = new Channel(Instance, cname, TS);
        }
        else
        {
@@ -352,18 +363,6 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool
        return Channel::ForceChan(Instance, Ptr, user, privs, bursting);
 }
 
-Channel *Channel::CreateChannel(InspIRCd *ServerInstance, const std::string &name, time_t ts)
-{
-       /* create a new one */
-       Channel *c = new Channel(ServerInstance);
-       (*(ServerInstance->chanlist))[name.c_str()] = c;
-
-       strlcpy(c->name, name.c_str(), CHANMAX);
-       c->created = ts ? ts : ServerInstance->Time();
-       c->age = c->created;
-       return c;
-}
-
 Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting)
 {
        std::string nick = user->nick;
@@ -380,18 +379,15 @@ Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const
                ModeHandler* mh = Instance->Modes->FindPrefix(status);
                if (mh)
                {
+                       /* Set, and make sure that the mode handler knows this mode was now set */
                        Ptr->SetPrefix(user, status, mh->GetPrefixRank(), true);
-                       /* Make sure that the mode handler knows this mode was now set */
                        mh->OnModeChange(Instance->FakeClient, Instance->FakeClient, Ptr, nick, true);
 
                        switch (mh->GetPrefix())
                        {
-                               /* These logic ops are SAFE IN THIS CASE
-                                * because if the entry doesnt exist,
-                                * addressing operator[] creates it.
-                                * If they do exist, it points to it.
-                                * At all other times where we dont want
-                                * to create an item if it doesnt exist, we
+                               /* These logic ops are SAFE IN THIS CASE because if the entry doesnt exist,
+                                * addressing operator[] creates it. If they do exist, it points to it.
+                                * At all other times where we dont want to create an item if it doesnt exist, we
                                 * must stick to ::find().
                                 */
                                case '@':
@@ -483,7 +479,11 @@ long Channel::PartUser(User *user, const char* reason)
                /* kill the record */
                if (iter != ServerInstance->chanlist->end())
                {
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
+                       int MOD_RESULT = 0;
+                       FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
+                       if (MOD_RESULT == 1)
+                               return 1; // delete halted by module
+                       FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
                        ServerInstance->chanlist->erase(iter);
                }
                return 0;
@@ -529,7 +529,11 @@ long Channel::ServerKickUser(User* user, const char* reason, bool triggerevents)
                /* kill the record */
                if (iter != ServerInstance->chanlist->end())
                {
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
+                       int MOD_RESULT = 0;
+                       FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
+                       if (MOD_RESULT == 1)
+                               return 1; // delete halted by module
+                       FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
                        ServerInstance->chanlist->erase(iter);
                }
                return 0;
@@ -607,7 +611,11 @@ long Channel::KickUser(User *src, User *user, const char* reason)
                /* kill the record */
                if (iter != ServerInstance->chanlist->end())
                {
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
+                       int MOD_RESULT = 0;
+                       FOREACH_RESULT_I(ServerInstance,I_OnChannelPreDelete, OnChannelPreDelete(this));
+                       if (MOD_RESULT == 1)
+                               return 1; // delete halted by module
+                       FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this));
                        ServerInstance->chanlist->erase(iter);
                }
                return 0;