X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=ebd317e1dfda4c0ed7b32d01d9d192c601336c58;hb=20680f9c4964a5e10e3649a1e479078ff85c5c85;hp=c69f09107d8a113bd1e3f9e51b6724b33400f6c7;hpb=488cea15e8de7f1afa779728aa4af2efd548d268;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index c69f09107..ebd317e1d 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,11 +18,15 @@ #include "wildcard.h" #include "mode.h" -Channel::Channel(InspIRCd* Instance, const std::string &name, time_t ts) : ServerInstance(Instance) +Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : ServerInstance(Instance) { - (*(ServerInstance->chanlist))[name.c_str()] = this; - strlcpy(this->name, name.c_str(), CHANMAX); - this->created = ts ? ts : ServerInstance->Time(true); + chan_hash::iterator findchan = ServerInstance->chanlist->find(name); + if (findchan != Instance->chanlist->end()) + throw CoreException("Cannot create duplicate channel " + cname); + + (*(ServerInstance->chanlist))[cname.c_str()] = this; + strlcpy(this->name, cname.c_str(), CHANMAX); + this->created = ts ? ts : ServerInstance->Time(); this->age = this->created; @@ -227,7 +231,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (user->chans.size() >= user->GetMaxChans()) { - user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick, cn); return NULL; } } @@ -237,7 +241,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (user->chans.size() >= Instance->Config->OperMaxChans) { - user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick, cn); return NULL; } } @@ -245,7 +249,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (user->chans.size() >= Instance->Config->MaxChans) { - user->WriteServ("405 %s %s :You are on too many channels",user->nick, cn); + user->WriteNumeric(405, "%s %s :You are on too many channels",user->nick, cn); return NULL; } } @@ -263,7 +267,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool if (!IS_LOCAL(user)) { if (!TS) - Instance->Log(DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn); + Instance->Logs->Log("CHANNEL",DEBUG,"*** BUG *** Channel::JoinUser called for REMOTE user '%s' on channel '%s' but no TS given!", user->nick, cn); } else { @@ -308,7 +312,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if ((!key) || strcmp(key,Ptr->key)) { - user->WriteServ("475 %s %s :Cannot join channel (Incorrect channel key)",user->nick, Ptr->name); + user->WriteNumeric(475, "%s %s :Cannot join channel (Incorrect channel key)",user->nick, Ptr->name); return NULL; } } @@ -321,7 +325,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (!user->IsInvited(Ptr->name)) { - user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name); + user->WriteNumeric(473, "%s %s :Cannot join channel (Invite only)",user->nick, Ptr->name); return NULL; } } @@ -335,7 +339,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (Ptr->GetUserCounter() >= Ptr->limit) { - user->WriteServ("471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name); + user->WriteNumeric(471, "%s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name); return NULL; } } @@ -344,7 +348,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool { if (Ptr->IsBanned(user)) { - user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name); + user->WriteNumeric(474, "%s %s :Cannot join channel (You're banned)",user->nick, Ptr->name); return NULL; } } @@ -375,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 '@': @@ -417,8 +418,8 @@ Channel* Channel::ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const { if (Ptr->topicset) { - user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic); - user->WriteServ("333 %s %s %s %lu", user->nick, Ptr->name, Ptr->setby, (unsigned long)Ptr->topicset); + user->WriteNumeric(332, "%s %s :%s", user->nick, Ptr->name, Ptr->topic); + user->WriteNumeric(333, "%s %s %s %lu", user->nick, Ptr->name, Ptr->setby, (unsigned long)Ptr->topicset); } Ptr->UserList(user); } @@ -478,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; @@ -524,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; @@ -544,12 +553,12 @@ long Channel::KickUser(User *src, User *user, const char* reason) { if (!this->HasUser(user)) { - src->WriteServ("441 %s %s %s :They are not on that channel",src->nick, user->nick, this->name); + src->WriteNumeric(441, "%s %s %s :They are not on that channel",src->nick, user->nick, this->name); return this->GetUserCounter(); } if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server))) { - src->WriteServ("482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, this->name); + src->WriteNumeric(482, "%s %s :Only a u-line may kick a u-line from a channel.",src->nick, this->name); return this->GetUserCounter(); } int MOD_RESULT = 0; @@ -574,7 +583,7 @@ long Channel::KickUser(User *src, User *user, const char* reason) int us = this->GetStatus(user); if ((them < STATUS_HOP) || (them < us)) { - src->WriteServ("482 %s %s :You must be a channel %soperator",src->nick, this->name, them == STATUS_HOP ? "" : "half-"); + src->WriteNumeric(482, "%s %s :You must be a channel %soperator",src->nick, this->name, them == STATUS_HOP ? "" : "half-"); return this->GetUserCounter(); } } @@ -602,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; @@ -611,7 +624,7 @@ long Channel::KickUser(User *src, User *user, const char* reason) return this->GetUserCounter(); } -void Channel::WriteChannel(User* user, char* text, ...) +void Channel::WriteChannel(User* user, const char* text, ...) { char textbuffer[MAXBUF]; va_list argsPtr; @@ -676,7 +689,7 @@ void Channel::WriteChannelWithServ(const char* ServName, const std::string &text /* write formatted text from a source user to all users on a channel except * for the sender (for privmsg etc) */ -void Channel::WriteAllExceptSender(User* user, bool serversource, char status, char* text, ...) +void Channel::WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...) { char textbuffer[MAXBUF]; va_list argsPtr; @@ -691,7 +704,7 @@ void Channel::WriteAllExceptSender(User* user, bool serversource, char status, c this->WriteAllExceptSender(user, serversource, status, std::string(textbuffer)); } -void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, char* text, ...) +void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...) { char textbuffer[MAXBUF]; va_list argsPtr; @@ -825,18 +838,20 @@ void Channel::UserList(User *user, CUList *ulist) char list[MAXBUF]; size_t dlen, curlen; int MOD_RESULT = 0; + bool call_modules = true; if (!IS_LOCAL(user)) return; FOREACH_RESULT(I_OnUserList,OnUserList(user, this, ulist)); if (MOD_RESULT == 1) - return; + call_modules = false; + if (MOD_RESULT != -1) { if ((this->IsModeSet('s')) && (!this->HasUser(user))) { - user->WriteServ("401 %s %s :No such nick/channel",user->nick, this->name); + user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, this->name); return; } } @@ -868,9 +883,19 @@ void Channel::UserList(User *user, CUList *ulist) if (i->first->Visibility && !i->first->Visibility->VisibleTo(user)) continue; - size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->first), i->second.c_str()); - /* OnUserList can change this - reset it back to normal */ - i->second = i->first->nick; + std::string prefixlist = this->GetPrefixChar(i->first); + std::string nick = i->first->nick; + + if (call_modules) + { + FOREACH_MOD(I_OnNamesListItem, OnNamesListItem(user, i->first, this, prefixlist, nick)); + + /* Nick was nuked, a module wants us to skip it */ + if (nick.empty()) + continue; + } + + size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", prefixlist.c_str(), nick.c_str()); curlen += ptrlen; ptr += ptrlen; @@ -897,7 +922,7 @@ void Channel::UserList(User *user, CUList *ulist) user->WriteServ(std::string(list)); } - user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, this->name); + user->WriteNumeric(366, "%s %s :End of /NAMES list.", user->nick, this->name); } long Channel::GetMaxBans()