X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_opermodes.cpp;h=33ebb57a04c37dee58af5306916585f4abe891e3;hb=aa05a6fd4d5c11dc8e8adc469134a2802446fe9f;hp=f0c8dfa0711fec32cf05781ba13f62d9ab65d99d;hpb=5097707f6003a4a4e77b246148bbcbe67c767d6c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_opermodes.cpp b/src/modules/m_opermodes.cpp index f0c8dfa07..33ebb57a0 100644 --- a/src/modules/m_opermodes.cpp +++ b/src/modules/m_opermodes.cpp @@ -1,113 +1,67 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ +/* + * InspIRCd -- Internet Relay Chat Daemon * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. - * This program is free but copyrighted software; see - * the file COPYING for details. + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007-2008 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2005-2007 Craig Edwards * - * --------------------------------------------------- + * 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 . */ -using namespace std; - -// Hostname ModesOnOper (+x mode) module for inspircd. -// version 1.0.0.1 by brain (C. J. Edwards) Mar 2004. -// -// When loaded this module will automatically set the -// +x mode on all connecting clients. -// -// Setting +x on a client causes the module to change the -// dhost entry (displayed host) for each user who has the -// mode, ModesOnOper their host. Unlike unreal, the algorithm -// is non-reversible as uncloaked hosts are passed along -// the server->server link, and all encoding of hosts is -// done locally on the server by this module. - -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -/* $ModDesc: Sets (and unsets) modes on opers when they oper up */ +#include "inspircd.h" class ModuleModesOnOper : public Module { - private: - - Server *Srv; - ConfigReader *Conf; - public: - ModuleModesOnOper() + Version GetVersion() CXX11_OVERRIDE { - Srv = new Server; - Conf = new ConfigReader; + return Version("Sets (and unsets) modes on opers when they oper up", VF_VENDOR); } - - virtual ~ModuleModesOnOper() - { - delete Conf; - delete Srv; - } - - virtual Version GetVersion() - { - return Version(1,0,0,1,VF_VENDOR); - } - - virtual void OnOper(userrec* user) + + void OnPostOper(User* user, const std::string &opertype, const std::string &opername) CXX11_OVERRIDE { + if (!IS_LOCAL(user)) + return; + // whenever a user opers, go through the oper types, find their , // and if they have one apply their modes. The mode string can contain +modes // to add modes to the user or -modes to take modes from the user. - for (int j =0; j < Conf->Enumerate("type"); j++) - { - std::string typen = Conf->ReadValue("type","name",j); - if (!strcmp(typen.c_str(),user->oper)) - { - std::string ThisOpersModes = Conf->ReadValue("type","modes",j); - if (ThisOpersModes != "") - { - char* modes[2]; - modes[0] = user->nick; - modes[1] = (char*)ThisOpersModes.c_str(); - Srv->SendMode(modes,2,user); - } - break; - } - } + std::string ThisOpersModes = user->oper->getConfig("modes"); + if (!ThisOpersModes.empty()) + { + ApplyModes(user, ThisOpersModes); + } } -}; -// stuff down here is the module-factory stuff. For basic modules you can ignore this. - -class ModuleModesOnOperFactory : public ModuleFactory -{ - public: - ModuleModesOnOperFactory() - { - } - - ~ModuleModesOnOperFactory() - { - } - - virtual Module * CreateModule() + void ApplyModes(User *u, std::string &smodes) { - return new ModuleModesOnOper; - } - -}; + char first = *(smodes.c_str()); + if ((first != '+') && (first != '-')) + smodes = "+" + smodes; + std::string buf; + std::stringstream ss(smodes); + std::vector modes; -extern "C" void * init_module( void ) -{ - return new ModuleModesOnOperFactory; -} + modes.push_back(u->nick); + // split into modes and mode params + while (ss >> buf) + modes.push_back(buf); + + ServerInstance->Parser.CallHandler("MODE", modes, u); + } +}; +MODULE_INIT(ModuleModesOnOper)