From 17cc3b8490692ee3a225f052425deb43a45b98db Mon Sep 17 00:00:00 2001 From: danieldg Date: Tue, 3 Nov 2009 17:12:36 +0000 Subject: Create m_halfop git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11997 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/modes/cmode_h.h | 31 ----------------- src/configreader.cpp | 19 ++-------- src/mode.cpp | 8 ----- src/modes/cmode_h.cpp | 64 ---------------------------------- src/modules/m_halfop.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+), 119 deletions(-) delete mode 100644 include/modes/cmode_h.h delete mode 100644 src/modes/cmode_h.cpp create mode 100644 src/modules/m_halfop.cpp diff --git a/include/modes/cmode_h.h b/include/modes/cmode_h.h deleted file mode 100644 index a93e8bf6a..000000000 --- a/include/modes/cmode_h.h +++ /dev/null @@ -1,31 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * 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. - * - * --------------------------------------------------- - */ - -#include "mode.h" -#include "channels.h" - -class InspIRCd; - -/** Channel mode +h - */ -class ModeChannelHalfOp : public ModeHandler -{ - private: - public: - ModeChannelHalfOp(); - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding); - unsigned int GetPrefixRank(); - void RemoveMode(Channel* channel, irc::modestacker* stack = NULL); - void RemoveMode(User* user, irc::modestacker* stack = NULL); -}; - diff --git a/src/configreader.cpp b/src/configreader.cpp index 9e0aa2031..348554584 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -30,7 +30,6 @@ #include "xline.h" #include "exitcodes.h" #include "commands/cmd_whowas.h" -#include "modes/cmode_h.h" #include "configparser.h" ServerConfig::ServerConfig() @@ -749,9 +748,6 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) ServerInstance->Exit(EXIT_STATUS_CONFIG); } - if (ConfValue("options")->getBool("allowhalfop")) - ServerInstance->Modes->AddMode(new ModeChannelHalfOp); - return; } @@ -768,18 +764,6 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) void ServerConfig::ApplyModules(User* user) { - bool AllowHalfOp = ConfValue("options")->getBool("allowhalfop"); - ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL); - if (AllowHalfOp && !mh) { - ServerInstance->Logs->Log("CONFIG", DEFAULT, "Enabling halfop mode."); - mh = new ModeChannelHalfOp; - ServerInstance->Modes->AddMode(mh); - } else if (!AllowHalfOp && mh) { - ServerInstance->Logs->Log("CONFIG", DEFAULT, "Disabling halfop mode."); - ServerInstance->Modes->DelMode(mh); - delete mh; - } - Module* whowas = ServerInstance->Modules->Find("cmd_whowas.so"); if (whowas) WhowasRequest(NULL, whowas, WhowasRequest::WHOWAS_PRUNE).Send(); @@ -802,6 +786,9 @@ void ServerConfig::ApplyModules(User* user) } } + if (ConfValue("options")->getBool("allowhalfop") && removed_modules.erase("m_halfop.so") == 0) + added_modules.push_back("m_halfop.so"); + for (std::set::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++) { // Don't remove cmd_*.so, just remove m_*.so diff --git a/src/mode.cpp b/src/mode.cpp index fd2517dce..9c3b75101 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -34,8 +34,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) */ @@ -981,10 +979,4 @@ ModeParser::ModeParser() ModeParser::~ModeParser() { - ModeHandler* mh = FindMode('h', MODETYPE_CHANNEL); - if (mh) - { - mh->cull(); - delete mh; - } } diff --git a/src/modes/cmode_h.cpp b/src/modes/cmode_h.cpp deleted file mode 100644 index 0b0f0b700..000000000 --- a/src/modes/cmode_h.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * 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. - * - * --------------------------------------------------- - */ - -#include "inspircd.h" -#include "configreader.h" -#include "mode.h" -#include "channels.h" -#include "users.h" -#include "modules.h" -#include "modes/cmode_h.h" - -ModeChannelHalfOp::ModeChannelHalfOp() : ModeHandler(NULL, "halfop", 'h', PARAM_ALWAYS, MODETYPE_CHANNEL) -{ - list = true; - prefix = '%'; - levelrequired = OP_VALUE; - m_paramtype = TR_NICK; -} - -unsigned int ModeChannelHalfOp::GetPrefixRank() -{ - return HALFOP_VALUE; -} - -void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack) -{ - const UserMembList* clist = channel->GetUsers(); - - for (UserMembCIter i = clist->begin(); i != clist->end(); i++) - { - if (stack) - { - stack->Push(this->GetModeChar(), i->first->nick); - } - else - { - std::vector parameters; - parameters.push_back(channel->name); - parameters.push_back("-h"); - parameters.push_back(i->first->nick); - ServerInstance->SendMode(parameters, ServerInstance->FakeClient); - } - } - -} - -void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack) -{ -} - -ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) -{ - return MODEACTION_ALLOW; -} diff --git a/src/modules/m_halfop.cpp b/src/modules/m_halfop.cpp new file mode 100644 index 000000000..4ddf083d9 --- /dev/null +++ b/src/modules/m_halfop.cpp @@ -0,0 +1,91 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * 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. + * + * --------------------------------------------------- + */ + +#include "inspircd.h" + +class ModeChannelHalfOp : public ModeHandler +{ + public: + ModeChannelHalfOp(Module* parent); + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding); + unsigned int GetPrefixRank(); + void RemoveMode(Channel* channel, irc::modestacker* stack = NULL); + void RemoveMode(User* user, irc::modestacker* stack = NULL); +}; + +ModeChannelHalfOp::ModeChannelHalfOp(Module* parent) : ModeHandler(parent, "halfop", 'h', PARAM_ALWAYS, MODETYPE_CHANNEL) +{ + list = true; + prefix = '%'; + levelrequired = OP_VALUE; + m_paramtype = TR_NICK; +} + +unsigned int ModeChannelHalfOp::GetPrefixRank() +{ + return HALFOP_VALUE; +} + +void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack) +{ + const UserMembList* clist = channel->GetUsers(); + + for (UserMembCIter i = clist->begin(); i != clist->end(); i++) + { + if (stack) + { + stack->Push(this->GetModeChar(), i->first->nick); + } + else + { + std::vector parameters; + parameters.push_back(channel->name); + parameters.push_back("-h"); + parameters.push_back(i->first->nick); + ServerInstance->SendMode(parameters, ServerInstance->FakeClient); + } + } + +} + +void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack) +{ +} + +ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) +{ + return MODEACTION_ALLOW; +} + +class ModuleHalfop : public Module +{ + ModeChannelHalfOp mh; + public: + ModuleHalfop() : mh(this) + { + if (!ServerInstance->Modes->AddMode(&mh)) + throw ModuleException("Could not add new modes!"); + } + + ~ModuleHalfop() + { + ServerInstance->Modes->DelMode(&mh); + } + + Version GetVersion() + { + return Version("Channel half-operator mode provider", VF_VENDOR|VF_COMMON); + } +}; + +MODULE_INIT(ModuleHalfop) -- cgit v1.2.3