X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_knock.cpp;h=8d2aa4543065be26e7b410ef41007c6d664cd37d;hb=571714e28b26cc59cbc8d27098a5ba981240ee2d;hp=a6d0812feaa1c0c70680a060aebd3c43ea832297;hpb=37034b9f6e4837bbc2d89d70ead8d9965d04855c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp index a6d0812fe..8d2aa4543 100644 --- a/src/modules/m_knock.cpp +++ b/src/modules/m_knock.cpp @@ -1,101 +1,137 @@ -// Globops and +g support module by C.J.Edwards +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2004-2006, 2008 Craig Edwards + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2007 Robin Burchell + * + * 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 -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -/* $ModDesc: Provides support for unreal-style GLOBOPS and umode +g */ +#include "inspircd.h" -Server *Srv; - -void handle_globops(char **parameters, int pcnt, userrec *user) +/* $ModDesc: Provides support for /KNOCK and channel mode +K */ + +/** Handles the /KNOCK command + */ +class CommandKnock : public Command { - std::string line = "*** GLOBOPS - From " + std::string(user->nick) + ": "; - for (int i = 0; i < pcnt; i++) + public: + bool sendnotice; + bool sendnumeric; + CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2, 2) { - line = line + std::string(parameters[i]) + " "; + syntax = " "; + Penalty = 5; + TRANSLATE3(TR_TEXT, TR_TEXT, TR_END); } - Srv->SendToModeMask("og",WM_AND,line); -} - -class ModuleGlobops : public Module -{ - public: - ModuleGlobops() + CmdResult Handle (const std::vector ¶meters, User *user) { - Srv = new Server; - - if (!Srv->AddExtendedMode('g',MT_CLIENT,true,0,0)) + Channel* c = ServerInstance->FindChan(parameters[0]); + if (!c) { - Srv->Log(DEFAULT,"*** m_globops: ERROR, failed to allocate user mode +g!"); - printf("Could not claim usermode +g for this module!"); - exit(0); + user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str()); + return CMD_FAILURE; } - Srv->AddCommand("GLOBOPS",handle_globops,'o',1); - } - - virtual ~ModuleGlobops() - { - delete Srv; - } - - virtual Version GetVersion() - { - return Version(1,0,0,1); - } - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) - { - // check if this is our mode character... - if ((modechar == 'g') && (type == MT_CLIENT)) - { - // we dont actually do anything with the mode in this module - - // just tell the core its been claimed and is ok to give users. - return 1; + + if (c->HasUser(user)) + { + user->WriteNumeric(480, "%s :Can't KNOCK on %s, you are already on that channel.", user->nick.c_str(), c->name.c_str()); + return CMD_FAILURE; } - else + + if (c->IsModeSet('K')) { - // this mode isn't ours, we have to bail and return 0 to not handle it. - return 0; + user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick.c_str(), c->name.c_str()); + return CMD_FAILURE; } + + if (!c->IsModeSet('i')) + { + user->WriteNumeric(480, "%s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick.c_str(), c->name.c_str()); + return CMD_FAILURE; + } + + if (sendnotice) + c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), parameters[1].c_str()); + + if (sendnumeric) + c->WriteChannelWithServ(ServerInstance->Config->ServerName, "710 %s %s %s :is KNOCKing: %s", c->name.c_str(), c->name.c_str(), user->GetFullHost().c_str(), parameters[1].c_str()); + + user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str()); + return CMD_SUCCESS; } - virtual void OnOper(userrec* user) + RouteDescriptor GetRouting(User* user, const std::vector& parameters) { - char* modes[2]; // only two parameters - modes[0] = user->nick; // first parameter is the nick - modes[1] = "+g"; // second parameter is the mode - Srv->SendMode(modes,2,user); // send these, forming the command "MODE +g" + return ROUTE_OPT_BCAST; } - }; -// stuff down here is the module-factory stuff. For basic modules you can ignore this. +/** Handles channel mode +K + */ +class Knock : public SimpleChannelModeHandler +{ + public: + Knock(Module* Creator) : SimpleChannelModeHandler(Creator, "noknock", 'K') { } +}; -class ModuleGlobopsFactory : public ModuleFactory +class ModuleKnock : public Module { + CommandKnock cmd; + Knock kn; public: - ModuleGlobopsFactory() + ModuleKnock() : cmd(this), kn(this) { } - - ~ModuleGlobopsFactory() + + void init() { + ServerInstance->Modules->AddService(kn); + ServerInstance->Modules->AddService(cmd); + + ServerInstance->Modules->Attach(I_OnRehash, this); + OnRehash(NULL); } - - virtual Module * CreateModule() + + void OnRehash(User* user) { - return new ModuleGlobops; - } - -}; + std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify"); + irc::string notify(knocknotify.c_str()); + if (notify == "numeric") + { + cmd.sendnotice = false; + cmd.sendnumeric = true; + } + else if (notify == "both") + { + cmd.sendnotice = true; + cmd.sendnumeric = true; + } + else + { + cmd.sendnotice = true; + cmd.sendnumeric = false; + } + } -extern "C" void * init_module( void ) -{ - return new ModuleGlobopsFactory; -} + virtual Version GetVersion() + { + return Version("Provides support for /KNOCK and channel mode +K", VF_OPTCOMMON | VF_VENDOR); + } +}; +MODULE_INIT(ModuleKnock)