summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-01-09 17:29:28 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-01-09 17:29:28 +0000
commitdd2ace5916a8bb24801e74aa8b209d396e012d9b (patch)
tree0e98cc9d1c3add89ac347dc8ff35985420233ef8
parentae61237cdc5e4d94681fc801d3076d202825ff45 (diff)
Disallow adding prefix-mode when it is already set (fixes bug #935)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12245 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/channels.h3
-rw-r--r--src/channels.cpp9
-rw-r--r--src/mode.cpp17
-rw-r--r--src/modules/m_chanprotect.cpp9
4 files changed, 17 insertions, 21 deletions
diff --git a/include/channels.h b/include/channels.h
index 59f4d1cf3..591847407 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -362,8 +362,9 @@ class CoreExport Channel : public Extensible
* @param user The user to associate the privilage with
* @param prefix The prefix character to associate
* @param adding True if adding the prefix, false when removing
+ * @return True if a change was made
*/
- void SetPrefix(User* user, char prefix, bool adding);
+ bool SetPrefix(User* user, char prefix, bool adding);
/** Check if a user is banned on this channel
* @param user A user to check against the banlist
diff --git a/src/channels.cpp b/src/channels.cpp
index 31038484e..b0951c8cc 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -929,14 +929,14 @@ unsigned int Channel::GetPrefixValue(User* user)
return m->second->getRank();
}
-void Channel::SetPrefix(User* user, char prefix, bool adding)
+bool Channel::SetPrefix(User* user, char prefix, bool adding)
{
ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
if (!delta_mh)
- return;
+ return false;
UserMembIter m = userlist.find(user);
if (m == userlist.end())
- return;
+ return false;
for(unsigned int i=0; i < m->second->modes.length(); i++)
{
char mchar = m->second->modes[i];
@@ -947,11 +947,12 @@ void Channel::SetPrefix(User* user, char prefix, bool adding)
m->second->modes.substr(0,i) +
(adding ? std::string(1, prefix) : "") +
m->second->modes.substr(mchar == prefix ? i+1 : i);
- return;
+ return adding != (mchar == prefix);
}
}
if (adding)
m->second->modes += std::string(1, prefix);
+ return adding;
}
void Channel::RemoveAllPrefixes(User* user)
diff --git a/src/mode.cpp b/src/mode.cpp
index 7d99277df..28390d327 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -353,6 +353,15 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
return MODEACTION_DENY;
}
+ if (mh->GetPrefixRank() && chan)
+ {
+ User* user_to_prefix = ServerInstance->FindNick(parameter);
+ if (!user_to_prefix)
+ return MODEACTION_DENY;
+ if (!chan->SetPrefix(user_to_prefix, modechar, adding))
+ return MODEACTION_DENY;
+ }
+
/* Call the handler for the mode */
ModeAction ma = mh->OnModeChange(user, targetuser, chan, parameter, adding);
@@ -362,15 +371,9 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
if (ma != MODEACTION_ALLOW)
return ma;
+ // TODO this count may not be reliable
mh->ChangeCount(adding ? 1 : -1);
- if (mh->GetPrefixRank() && chan)
- {
- User* user_to_prefix = ServerInstance->FindNick(parameter);
- if (user_to_prefix)
- chan->SetPrefix(user_to_prefix, modechar, adding);
- }
-
for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
(*watchers)->AfterMode(user, targetuser, chan, parameter, adding, type);
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
index 369703d2c..8a842b626 100644
--- a/src/modules/m_chanprotect.cpp
+++ b/src/modules/m_chanprotect.cpp
@@ -147,10 +147,6 @@ class ChanFounder : public ModeHandler, public FounderProtectBase
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
{
- User* theuser = ServerInstance->FindNick(parameter);
-
- if (!theuser)
- return MODEACTION_DENY;
return MODEACTION_ALLOW;
}
@@ -218,11 +214,6 @@ class ChanProtect : public ModeHandler, public FounderProtectBase
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
{
- User* theuser = ServerInstance->FindNick(parameter);
-
- if (!theuser)
- return MODEACTION_DENY;
-
return MODEACTION_ALLOW;
}