X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=5efc98250d7e1851b93d88cce54d6a900e1e6145;hb=663f0620bea4dc1e64ec640992f4d511ae1ef97b;hp=fd2517dce6da2d18ccb6b104bc201fb752d0585e;hpb=80df092fa38524a415a3bb258384dde819ec86e3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index fd2517dce..5efc98250 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -1,16 +1,27 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team - * See: http://wiki.inspircd.org/Credits + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2007, 2009 Dennis Friis + * Copyright (C) 2006-2008 Robin Burchell + * Copyright (C) 2008 Thomas Stagner + * Copyright (C) 2004-2008 Craig Edwards + * Copyright (C) 2006 Oliver Lupton * - * This program is free but copyrighted software; see - * the file COPYING for details. + * 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 + * License as published by the Free Software Foundation, version 2. * - * --------------------------------------------------- + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + #include "inspircd.h" #include "inspstring.h" @@ -34,8 +45,6 @@ #include "modes/cmode_l.h" /* +o (channel op) */ #include "modes/cmode_o.h" -/* +h (channel halfop) */ -#include "modes/cmode_h.h" /* +v (channel voice) */ #include "modes/cmode_v.h" /* +w (see wallops) */ @@ -48,8 +57,9 @@ #include "modes/umode_s.h" ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type) - : m_paramtype(TR_TEXT), parameters_taken(Params), mode(modeletter), prefix(0), oper(false), - list(false), m_type(type), count(0), levelrequired(HALFOP_VALUE), creator(Creator), name(Name) + : ServiceProvider(Creator, Name, SERVICE_MODE), m_paramtype(TR_TEXT), + parameters_taken(Params), mode(modeletter), prefix(0), oper(false), + list(false), m_type(type), levelrequired(HALFOP_VALUE) { } @@ -62,8 +72,6 @@ CullResult ModeHandler::cull() ModeHandler::~ModeHandler() { - if (ServerInstance && ServerInstance->Modes && ServerInstance->Modes->FindMode(mode, m_type) == this) - ServerInstance->Logs->Log("MODE", ERROR, "ERROR: Destructor for mode %c called while still registered", mode); } bool ModeHandler::IsListMode() @@ -76,17 +84,6 @@ unsigned int ModeHandler::GetPrefixRank() return 0; } -unsigned int ModeHandler::GetCount() -{ - return 0; -} - -void ModeHandler::ChangeCount(int modifier) -{ - count += modifier; - ServerInstance->Logs->Log("MODE", DEBUG,"Change count for mode %c is now %d", mode, count); -} - int ModeHandler::GetNumParams(bool adding) { switch (parameters_taken) @@ -101,11 +98,6 @@ int ModeHandler::GetNumParams(bool adding) return 0; } -char ModeHandler::GetModeChar() -{ - return mode; -} - std::string ModeHandler::GetUserParameter(User* user) { return ""; @@ -183,6 +175,25 @@ ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Chan return MODEACTION_DENY; } +ModeAction ParamChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) +{ + if (adding && !ParamValidate(parameter)) + return MODEACTION_DENY; + std::string now = channel->GetModeParameter(this); + if (parameter == now) + return MODEACTION_DENY; + if (adding) + channel->SetModeParam(this, parameter); + else + channel->SetModeParam(this, ""); + return MODEACTION_ALLOW; +} + +bool ParamChannelModeHandler::ParamValidate(std::string& parameter) +{ + return true; +} + ModeWatcher::ModeWatcher(Module* Creator, char modeletter, ModeType type) : mode(modeletter), m_type(type), creator(Creator) { @@ -263,6 +274,10 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool ModeHandler *mh = FindMode(modechar, type); int pcnt = mh->GetNumParams(adding); + // crop mode parameter size to 250 characters + if (parameter.length() > 250 && adding) + parameter = parameter.substr(0, 250); + ModResult MOD_RESULT; FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, modechar, parameter, adding, pcnt)); @@ -286,11 +301,23 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool unsigned int ourrank = chan->GetPrefixValue(user); if (ourrank < neededrank) { - /* Bog off */ - // TODO replace with a real search for the proper prefix - char needed = neededrank > HALFOP_VALUE ? '@' : '%'; - user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have channel privilege %c or above to %sset channel mode %c", - user->nick.c_str(), chan->name.c_str(), needed, adding ? "" : "un", modechar); + ModeHandler* neededmh = NULL; + for(char c='A'; c <= 'z'; c++) + { + ModeHandler *privmh = FindMode(c, MODETYPE_CHANNEL); + if (privmh && privmh->GetPrefixRank() >= neededrank) + { + // this mode is sufficient to allow this action + if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank()) + neededmh = privmh; + } + } + if (neededmh) + user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have channel %s access or above to %sset channel mode %c", + user->nick.c_str(), chan->name.c_str(), neededmh->name.c_str(), adding ? "" : "un", modechar); + else + user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You cannot %sset channel mode %c", + user->nick.c_str(), chan->name.c_str(), adding ? "" : "un", modechar); return MODEACTION_DENY; } } @@ -340,6 +367,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); @@ -349,15 +385,6 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool if (ma != MODEACTION_ALLOW) return ma; - 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); @@ -549,13 +576,11 @@ void ModeParser::DisplayListModes(User* user, Channel* chan, std::string &mode_s bool display = true; if (!user->HasPrivPermission("channels/auspex") && ServerInstance->Config->HideModeLists[mletter] && (chan->GetPrefixValue(user) < HALFOP_VALUE)) { - user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only half-operators and above may view the +%c list", + user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You do not have access to view the +%c list", user->nick.c_str(), chan->name.c_str(), mletter); display = false; } - /** See below for a description of what craq this is :D - */ unsigned char handler_id = (mletter - 'A') | MASK_CHANNEL; for(ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) @@ -632,6 +657,9 @@ bool ModeParser::AddMode(ModeHandler* mh) if ((mh->GetPrefix() == ',') || (mh->GetPrefix() == ':') || (mh->GetPrefix() == '#')) return false; + if (mh->GetPrefix() && FindPrefix(mh->GetPrefix())) + return false; + mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL; pos = (mh->GetModeChar()-65) | mask; @@ -935,7 +963,6 @@ struct builtin_modes ModeChannelBan b; ModeChannelOp o; - // halfop is added by configreader ModeChannelVoice v; ModeUserWallops uw; @@ -981,10 +1008,4 @@ ModeParser::ModeParser() ModeParser::~ModeParser() { - ModeHandler* mh = FindMode('h', MODETYPE_CHANNEL); - if (mh) - { - mh->cull(); - delete mh; - } }