X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_delayjoin.cpp;h=707557f08d857759c71cd66ceda4f62113a17d6f;hb=8be88f3e732e7a40f2e501c5e5b78c7f1b999f2d;hp=7ecc81a0e5482f5c680b626955e9541cfd2bd822;hpb=697098bb47651b40ed9c768361d1a3b1ca452856;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index 7ecc81a0e..707557f08 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -20,7 +20,7 @@ class DelayJoinMode : public ModeHandler CUList empty; Module* Creator; public: - DelayJoinMode(InspIRCd* Instance, Module* Parent) : ModeHandler(Instance, 'D', 0, 0, false, MODETYPE_CHANNEL, false), Creator(Parent) {}; + DelayJoinMode(InspIRCd* Instance, Module* Parent) : ModeHandler(Instance, 'D', 0, 0, false, MODETYPE_CHANNEL, false, 0, '@'), Creator(Parent) {}; ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool); }; @@ -43,6 +43,7 @@ class ModuleDelayJoin : public Module virtual Version GetVersion(); virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick); virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent); + void CleanUser(User* user); bool OnHostCycle(User* user); void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent); void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent); @@ -55,33 +56,22 @@ class ModuleDelayJoin : public Module ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) { - if (channel->IsModeSet('D') != adding) - { - if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP)) - { - source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only channel operators may %sset channel mode +D", source->nick.c_str(), channel->name.c_str(), adding ? "" : "un"); - return MODEACTION_DENY; - } - else - { - if (channel->IsModeSet('D')) - { - /* - * Make all users visible, as +D is being removed. If we don't do this, - * they remain permanently invisible on this channel! - */ - CUList* names = channel->GetUsers(); - for (CUListIter n = names->begin(); n != names->end(); ++n) - Creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty); - } - channel->SetMode('D', adding); - return MODEACTION_ALLOW; - } - } - else - { + /* no change */ + if (channel->IsModeSet('D') == adding) return MODEACTION_DENY; + + if (!adding) + { + /* + * Make all users visible, as +D is being removed. If we don't do this, + * they remain permanently invisible on this channel! + */ + CUList* names = channel->GetUsers(); + for (CUListIter n = names->begin(); n != names->end(); ++n) + Creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty); } + channel->SetMode('D', adding); + return MODEACTION_ALLOW; } ModuleDelayJoin::~ModuleDelayJoin() @@ -103,11 +93,12 @@ void ModuleDelayJoin::OnNamesListItem(User* issuer, User* user, Channel* channel if (nick.empty()) return; - /* If the user is hidden by delayed join, hide them from the NAMES list */ - std::string key("delayjoin_"); - key.append(channel->name); + /* don't prevent the user from seeing themself */ + if (issuer == user) + return; - if (user->GetExt(key)) + /* If the user is hidden by delayed join, hide them from the NAMES list */ + if (user->GetExt("delayjoin_"+channel->name)) nick.clear(); } @@ -130,29 +121,43 @@ void ModuleDelayJoin::OnUserJoin(User* user, Channel* channel, bool sync, bool & } } +void ModuleDelayJoin::CleanUser(User* user) +{ + /* Check if the user is hidden on any other +D channels, if so don't take away the + * metadata that says they're hidden on one or more channels + */ + for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++) + if (user->GetExt("delayjoin_" + f->first->name)) + return; + + user->Shrink("delayjoin"); +} + void ModuleDelayJoin::OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent) { - if (channel->IsModeSet('D')) + if (!channel->IsModeSet('D')) + return; + if (user->GetExt("delayjoin_"+channel->name)) { - if (user->GetExt("delayjoin_"+channel->name)) - { - silent = true; - /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */ - user->WriteFrom(user, "PART %s%s%s", channel->name.c_str(), partmessage.empty() ? "" : " :", partmessage.empty() ? "" : partmessage.c_str()); - } + user->Shrink("delayjoin_"+channel->name); + silent = true; + /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */ + user->WriteFrom(user, "PART %s%s%s", channel->name.c_str(), partmessage.empty() ? "" : " :", partmessage.empty() ? "" : partmessage.c_str()); + CleanUser(user); } } void ModuleDelayJoin::OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent) { - if (chan->IsModeSet('D')) + if (!chan->IsModeSet('D')) + return; + /* Send silenced event only to the user being kicked and the user doing the kick */ + if (user->GetExt("delayjoin_"+chan->name)) { - /* Send silenced event only to the user being kicked and the user doing the kick */ - if (user->GetExt("delayjoin_"+chan->name)) - { - silent = true; - user->WriteFrom(source, "KICK %s %s %s", chan->name.c_str(), user->nick.c_str(), reason.c_str()); - } + user->Shrink("delayjoin_"+chan->name); + silent = true; + user->WriteFrom(source, "KICK %s %s %s", chan->name.c_str(), user->nick.c_str(), reason.c_str()); + CleanUser(user); } } @@ -168,11 +173,16 @@ void ModuleDelayJoin::OnUserQuit(User* user, const std::string &reason, const st { for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++) { - std::vector parameters; - parameters.push_back(f->first->name); - /* This triggers our OnUserPart, above, making the PART silent */ - parthandler->Handle(parameters, user); + Channel* chan = f->first; + if (user->GetExt("delayjoin_"+chan->name)) + { + std::vector parameters; + parameters.push_back(chan->name); + /* Send a fake PART from the channel, which will be silent */ + parthandler->Handle(parameters, user); + } } + user->Shrink("delayjoin"); } } @@ -199,15 +209,7 @@ void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std: /* Shrink off the neccessary metadata for a specific channel */ user->Shrink("delayjoin_"+channel->name); - - /* Check if the user is left on any other +D channels, if so don't take away the - * metadata that says theyre on one or more channels - */ - for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++) - if (f->first->IsModeSet('D')) - return; - - user->Shrink("delayjoin"); + CleanUser(user); } // .. is there a real need to duplicate WriteCommonExcept?