X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=cab05caeb1b7a607c3faba8d2c74d6c1a58431d4;hb=59643d29385fd4fbfed7a5720e90e2c9ffd1fd21;hp=cc5a2d7d5cc1960a91b3c9dabf9b2475bc0cb0fe;hpb=ab6a7318e36bd8e0a259cd9eef3694a0f0e8684a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index cc5a2d7d5..cab05caeb 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -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 @@ -18,12 +18,23 @@ #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) @@ -198,7 +209,7 @@ void Channel::SetDefaultModes() * add a channel to a user, creating the record for it if needed and linking * it to the user record */ -Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, time_t TS) +Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS) { if (!user || !cn) return NULL; @@ -271,21 +282,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool return NULL; } - /* create a new one */ - Ptr = new Channel(Instance); - (*(Instance->chanlist))[cname] = Ptr; - - strlcpy(Ptr->name, cname,CHANMAX); - - /* As spotted by jilles, dont bother to set this on remote users */ - if (IS_LOCAL(user)) - Ptr->SetDefaultModes(); - - Ptr->created = TS ? TS : Instance->Time(); - Ptr->age = Ptr->created; - *Ptr->topic = 0; - *Ptr->setby = 0; - Ptr->topicset = 0; + Ptr = new Channel(Instance, cname, TS); } else { @@ -359,10 +356,14 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool } } - return Channel::ForceChan(Instance, Ptr, user, privs); + /* As spotted by jilles, dont bother to set this on remote users */ + if (IS_LOCAL(user) && Ptr->GetUserCounter() == 1) + Ptr->SetDefaultModes(); + + return Channel::ForceChan(Instance, Ptr, user, privs, bursting); } -Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs) +Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting) { std::string nick = user->nick; bool silent = false; @@ -378,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 '@': @@ -405,7 +403,7 @@ Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const } } - FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, silent)); + FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user, Ptr, bursting, silent)); if (!silent) Ptr->WriteChannel(user,"JOIN :%s",Ptr->name); @@ -481,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; @@ -527,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; @@ -605,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; @@ -835,6 +845,14 @@ void Channel::UserList(User *user, CUList *ulist) FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist)); if (MOD_RESULT == 1) return; + if (MOD_RESULT != -1) + { + if ((this->IsModeSet('s')) && (!this->HasUser(user))) + { + user->WriteServ("401 %s %s :No such nick/channel",user->nick, this->name); + return; + } + } dlen = curlen = snprintf(list,MAXBUF,"353 %s %c %s :", user->nick, this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name);