The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_samode.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 /* $ModDesc: Provides more advanced UnrealIRCd SAMODE command */
00015 
00016 #include "inspircd.h"
00017 
00020 class CommandSamode : public Command
00021 {
00022  public:
00023         CommandSamode (InspIRCd* Instance) : Command(Instance,"SAMODE", "o", 2, false, 0)
00024         {
00025                 this->source = "m_samode.so";
00026                 syntax = "<target> <modes> {<mode-parameters>}";
00027         }
00028 
00029         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
00030         {
00031                 /*
00032                  * Handles an SAMODE request. Notifies all +s users.
00033                  */
00034                 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
00035 
00036                 if (ServerInstance->Modes->GetLastParse().length())
00037                 {
00038                         ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
00039 
00040                         std::deque<std::string> n;
00041                         irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
00042                         std::string one;
00043                         while (spaced.GetToken(one))
00044                                 n.push_back(one);
00045 
00046                         std::string channel = n[0];
00047                         n.pop_front();
00048                         ServerInstance->PI->SendMode(channel, n);
00049 
00050                         /* XXX: Yes, this is right. We dont want to propagate the
00051                          * actual SAMODE command, just the MODE command generated
00052                          * by the Protocol Interface
00053                          */
00054                         return CMD_LOCALONLY;
00055                 }
00056                 else
00057                 {
00058                         user->WriteServ("NOTICE %s :*** Invalid SAMODE sequence.", user->nick.c_str());
00059                 }
00060 
00061                 return CMD_FAILURE;
00062         }
00063 };
00064 
00065 class ModuleSaMode : public Module
00066 {
00067         CommandSamode*  mycommand;
00068  public:
00069         ModuleSaMode(InspIRCd* Me)
00070                 : Module(Me)
00071         {
00072 
00073                 mycommand = new CommandSamode(ServerInstance);
00074                 ServerInstance->AddCommand(mycommand);
00075 
00076         }
00077 
00078         virtual ~ModuleSaMode()
00079         {
00080         }
00081 
00082         virtual Version GetVersion()
00083         {
00084                 return Version("$Id: m_samode.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00085         }
00086 };
00087 
00088 MODULE_INIT(ModuleSaMode)