Use CheckTimeStamp to merge modes on netburst

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11596 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2009-09-02 00:44:06 +00:00
parent deb6822302
commit fbe8169b82
11 changed files with 15 additions and 41 deletions

View File

@ -266,14 +266,12 @@ class CoreExport ModeHandler : public Extensible
* override this function and use it to return true or false. The default implementation just returns true if
* theirs < ours. This will only be called for non-listmodes with parameters, when adding the mode and where
* theirs == ours (therefore the default implementation will always return false).
* @param theirs The timestamp of the remote side
* @param ours The timestamp of the local side
* @param their_param Their parameter if the mode has a parameter
* @param our_param Our parameter if the mode has a parameter
* @param channel The channel we are checking against
* @return True if the other side wins the merge, false if we win the merge for this mode.
*/
virtual bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel);
virtual bool CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel* channel);
/**
* When a remote server needs to bounce a set of modes, it will call this method for every mode
@ -536,7 +534,7 @@ class CoreExport ModeParser : public classbase
* and *user->server == NULL.
* @param servermode True if a server is setting the mode.
*/
void Process(const std::vector<std::string>& parameters, User *user, bool servermode);
void Process(const std::vector<std::string>& parameters, User *user, bool servermode, bool merge = false);
/** Find the mode handler for a given mode and type.
* @param modeletter mode letter to search for

View File

@ -23,7 +23,6 @@ class ModeChannelKey : public ModeHandler
ModeChannelKey(InspIRCd* Instance);
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool servermode);
ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter);
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel);
void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
void RemoveMode(User* user, irc::modestacker* stack = NULL);
};

View File

@ -23,5 +23,5 @@ class ModeChannelLimit : public ModeHandler
ModeChannelLimit(InspIRCd* Instance);
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool servermode);
ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string &parameter);
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel);
bool CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel* channel);
};

View File

@ -155,9 +155,9 @@ void ModeHandler::OnParameterMissing(User* user, User* dest, Channel* channel)
{
}
bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string&, const std::string&, Channel*)
bool ModeHandler::CheckTimeStamp(std::string& theirs, const std::string& ours, Channel*)
{
return (ours < theirs);
return (theirs < ours);
}
SimpleUserModeHandler::SimpleUserModeHandler(InspIRCd* Instance, char modeletter) : ModeHandler(Instance, modeletter, 0, 0, false, MODETYPE_USER, false)
@ -471,7 +471,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
return MODEACTION_ALLOW;
}
void ModeParser::Process(const std::vector<std::string>& parameters, User *user, bool servermode)
void ModeParser::Process(const std::vector<std::string>& parameters, User *user, bool servermode, bool merge)
{
std::string target = parameters[0];
Channel* targetchannel = ServerInstance->FindChan(target);
@ -562,6 +562,13 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
/* Make sure the user isn't trying to slip in an invalid parameter */
if ((parameter.find(':') == 0) || (parameter.rfind(' ') != std::string::npos))
continue;
if (merge && targetchannel && targetchannel->IsModeSet(modechar) && !mh->IsListMode())
{
std::string ours = targetchannel->GetModeParameter(modechar);
if (!mh->CheckTimeStamp(parameter, ours, targetchannel))
/* we won the mode merge, don't apply this mode */
continue;
}
}
ModeAction ma = TryMode(user, targetuser, targetchannel, adding, modechar, parameter, servermode, SkipAccessChecks);

View File

@ -61,12 +61,6 @@ void ModeChannelKey::RemoveMode(User*, irc::modestacker* stack)
{
}
bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
{
/* When TS is equal, the alphabetically later channel key wins */
return (their_param < our_param);
}
ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding, bool servermode)
{
bool exists = channel->IsModeSet('k');

View File

@ -34,7 +34,7 @@ ModePair ModeChannelLimit::ModeSet(User*, User*, Channel* channel, const std::st
}
}
bool ModeChannelLimit::CheckTimeStamp(time_t, time_t, const std::string &their_param, const std::string &our_param, Channel*)
bool ModeChannelLimit::CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel*)
{
/* When TS is equal, the higher channel limit wins */
return (atoi(their_param.c_str()) < atoi(our_param.c_str()));

View File

@ -97,12 +97,6 @@ class JoinFlood : public ModeHandler
return std::make_pair(false, parameter);
}
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
{
/* When TS is equal, the alphabetically later one wins */
return (their_param < our_param);
}
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
{
joinfloodsettings* dummy;

View File

@ -40,12 +40,6 @@ class KickRejoin : public ModeHandler
return std::make_pair(false, parameter);
}
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
{
/* When TS is equal, the alphabetically later one wins */
return (their_param < our_param);
}
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
{
if (!adding)

View File

@ -87,12 +87,6 @@ class MsgFlood : public ModeHandler
return std::make_pair(false, parameter);
}
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
{
/* When TS is equal, the alphabetically later one wins */
return (their_param < our_param);
}
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
{
floodsettings *f;

View File

@ -101,12 +101,6 @@ class NickFlood : public ModeHandler
return std::make_pair(false, parameter);
}
bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
{
/* When TS is equal, the alphabetically later one wins */
return (their_param < our_param);
}
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
{
nickfloodsettings* dummy;

View File

@ -97,7 +97,7 @@ bool TreeSocket::ForceMode(const std::string &source, parameterlist &params)
*/
if (TS <= ourTS)
{
ServerInstance->Modes->Process(modelist, who, (who == Utils->ServerUser));
ServerInstance->Modes->Process(modelist, who, (who == Utils->ServerUser), true);
/* HOT POTATO! PASS IT ON! */
Utils->DoOneToAllButSender(source,"FMODE",params,sourceserv);