* | 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.
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);
};
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);
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()
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::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);
}
}
{
for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
{
- std::vector<std::string> 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<std::string> parameters;
+ parameters.push_back(chan->name);
+ /* Send a fake PART from the channel, which will be silent */
+ parthandler->Handle(parameters, user);
+ }
}
+ user->Shrink("delayjoin");
}
}
/* 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?