X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_delayjoin.cpp;h=8b5e83e88b5b6d3e82ced1e3929aec1ec0165857;hb=f25c4b7a2263f5f3ce9bb41ba56b43c0d3a6d124;hp=d47976c090264be39bcba722bdf61b15c2a807eb;hpb=43847ec9c7e1a195163eb4c529f1c92fd1ace0a4;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index d47976c09..8b5e83e88 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -3,7 +3,7 @@ * +------------------------------------+ * * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * 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); }; @@ -28,13 +28,12 @@ class DelayJoinMode : public ModeHandler class ModuleDelayJoin : public Module { private: - DelayJoinMode* djm; + DelayJoinMode djm; CUList nl; public: - ModuleDelayJoin(InspIRCd* Me) : Module(Me) + ModuleDelayJoin(InspIRCd* Me) : Module(Me), djm(Me, this) { - djm = new DelayJoinMode(ServerInstance, this); - if (!ServerInstance->Modes->AddMode(djm)) + if (!ServerInstance->Modes->AddMode(&djm)) throw ModuleException("Could not add new modes!"); Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnNamesListItem, I_OnText, I_OnHostCycle }; ServerInstance->Modules->Attach(eventlist, this, 7); @@ -42,7 +41,8 @@ class ModuleDelayJoin : public Module virtual ~ModuleDelayJoin(); 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); + virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created); + 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,39 +55,27 @@ 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() { - ServerInstance->Modes->DelMode(djm); - delete djm; + ServerInstance->Modes->DelMode(&djm); } Version ModuleDelayJoin::GetVersion() @@ -103,15 +91,16 @@ 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(); } -void ModuleDelayJoin::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent) +void ModuleDelayJoin::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created) { if (channel->IsModeSet('D')) { @@ -130,29 +119,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 +171,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 +207,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?