summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/channels.cpp20
-rw-r--r--src/coremods/core_channel/core_channel.cpp49
2 files changed, 52 insertions, 17 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index d99a57723..58388bef5 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -235,13 +235,10 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
if (MOD_RESULT == MOD_RES_PASSTHRU)
{
std::string ckey = chan->GetModeParameter(keymode);
- bool invited = user->IsInvited(chan);
- bool can_bypass = ServerInstance->Config->InvBypassModes && invited;
-
if (!ckey.empty())
{
FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key));
- if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key) || can_bypass))
+ if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key)))
{
// If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled)
user->WriteNumeric(ERR_BADCHANNELKEY, "%s :Cannot join channel (Incorrect channel key)", chan->name.c_str());
@@ -252,7 +249,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
if (chan->IsModeSet(inviteonlymode))
{
FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan));
- if (!MOD_RESULT.check(invited))
+ if (MOD_RESULT != MOD_RES_ALLOW)
{
user->WriteNumeric(ERR_INVITEONLYCHAN, "%s :Cannot join channel (Invite only)", chan->name.c_str());
return NULL;
@@ -263,27 +260,18 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co
if (!limit.empty())
{
FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan));
- if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass)))
+ if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()))))
{
user->WriteNumeric(ERR_CHANNELISFULL, "%s :Cannot join channel (Channel is full)", chan->name.c_str());
return NULL;
}
}
- if (chan->IsBanned(user) && !can_bypass)
+ if (chan->IsBanned(user))
{
user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s :Cannot join channel (You're banned)", chan->name.c_str());
return NULL;
}
-
- /*
- * If the user has invites for this channel, remove them now
- * after a successful join so they don't build up.
- */
- if (invited)
- {
- user->RemoveInvite(chan);
- }
}
}
}
diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp
index 99ad74d3d..ec617af13 100644
--- a/src/coremods/core_channel/core_channel.cpp
+++ b/src/coremods/core_channel/core_channel.cpp
@@ -1,7 +1,7 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
- * Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
+ * Copyright (C) 2014-2015 Attila Molnar <attilamolnar@hush.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
@@ -28,18 +28,41 @@ class CoreModChannel : public Module
CommandNames cmdnames;
CommandTopic cmdtopic;
+ ModResult IsInvited(User* user, Channel* chan)
+ {
+ LocalUser* localuser = IS_LOCAL(user);
+ if ((localuser) && (localuser->IsInvited(chan)))
+ return MOD_RES_ALLOW;
+ return MOD_RES_PASSTHRU;
+ }
+
public:
CoreModChannel()
: cmdinvite(this), cmdjoin(this), cmdkick(this), cmdnames(this), cmdtopic(this)
{
}
+ void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
+ {
+ Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan };
+ if (ServerInstance->Config->InvBypassModes)
+ ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation));
+ else
+ {
+ for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++)
+ ServerInstance->Modules.Detach(events[i], this);
+ }
+ }
+
void OnPostJoin(Membership* memb) CXX11_OVERRIDE
{
Channel* const chan = memb->chan;
LocalUser* const localuser = IS_LOCAL(memb->user);
if (localuser)
{
+ // Remove existing invite, if any
+ localuser->RemoveInvite(chan);
+
if (chan->topicset)
Topic::ShowTopic(localuser, chan);
@@ -48,6 +71,30 @@ class CoreModChannel : public Module
}
}
+ ModResult OnCheckKey(User* user, Channel* chan, const std::string& keygiven) CXX11_OVERRIDE
+ {
+ // Hook only runs when being invited bypasses +bkl
+ return IsInvited(user, chan);
+ }
+
+ ModResult OnCheckChannelBan(User* user, Channel* chan) CXX11_OVERRIDE
+ {
+ // Hook only runs when being invited bypasses +bkl
+ return IsInvited(user, chan);
+ }
+
+ ModResult OnCheckLimit(User* user, Channel* chan) CXX11_OVERRIDE
+ {
+ // Hook only runs when being invited bypasses +bkl
+ return IsInvited(user, chan);
+ }
+
+ ModResult OnCheckInvite(User* user, Channel* chan) CXX11_OVERRIDE
+ {
+ // Hook always runs
+ return IsInvited(user, chan);
+ }
+
void Prioritize() CXX11_OVERRIDE
{
ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST);