]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_svshold.cpp
Only valid targets for encap are now server ids
[user/henk/code/inspircd.git] / src / modules / m_svshold.cpp
index 60416209347d05fa07887f8a0ff3219b47eeb5dd..a101254292b31583dc69ef84966955fab3123538 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
  * ---------------------------------------------------
  */
 
-#include <algorithm>
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-#include "configreader.h"
 #include "inspircd.h"
 
 /* $ModDesc: Implements SVSHOLD. Like Q:Lines, but can only be added/removed by Services. */
@@ -52,20 +47,27 @@ SVSHoldMap HoldMap;
 
 /** Handle /SVSHold
  */
-class cmd_svshold : public command_t
+class CommandSvshold : public Command
 {
  public:
-       cmd_svshold(InspIRCd* Me) : command_t(Me, "SVSHOLD", 'o', 1)
+       CommandSvshold(InspIRCd* Me) : Command(Me, "SVSHOLD", "o", 1)
        {
                this->source = "m_svshold.so";
                this->syntax = "<nickname> [<duration> :<reason>]";
+               TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle(const char** parameters, int pcnt, userrec *user)
+       CmdResult Handle(const char* const* parameters, int pcnt, User *user)
        {
                /* syntax: svshold nickname time :reason goes here */
                /* 'time' is a human-readable timestring, like 2d3h2s. */
 
+               if (!ServerInstance->ULine(user->server))
+               {
+                       /* don't allow SVSHOLD from non-ulined clients */
+                       return CMD_FAILURE;
+               }
+
                if (pcnt == 1)
                {
                        SVSHoldMap::iterator n = HoldMap.find(parameters[0]);
@@ -76,8 +78,16 @@ class cmd_svshold : public command_t
                                {
                                        if (parameters[0] == assign((*iter)->nickname))
                                        {
-                                               unsigned long remaining = ((*iter)->set_on + (*iter)->length) - ServerInstance->Time();
-                                               user->WriteServ( "386 %s %s :Removed SVSHOLD with %lu seconds left before expiry (%s)", user->nick, (*iter)->nickname.c_str(), remaining, (*iter)->reason.c_str());
+                                               unsigned long remaining = 0;
+                                               if ((*iter)->length)
+                                               {
+                                                       remaining = ((*iter)->set_on + (*iter)->length) - ServerInstance->Time();
+                                                       user->WriteServ( "386 %s %s :Removed SVSHOLD with %lu seconds left before expiry (%s)", user->nick, (*iter)->nickname.c_str(), remaining, (*iter)->reason.c_str());
+                                               }
+                                               else
+                                               {
+                                                       user->WriteServ( "386 %s %s :Removed permanent SVSHOLD (%s)", user->nick, (*iter)->nickname.c_str(), (*iter)->reason.c_str());
+                                               }
                                                SVSHolds.erase(iter);
                                                break;
                                        }
@@ -115,12 +125,12 @@ class cmd_svshold : public command_t
                                if(length > 0)
                                {
                                        user->WriteServ( "385 %s %s :Added %lu second SVSHOLD (%s)", user->nick, parameters[0], length, reason.c_str());
-                                       ServerInstance->WriteOpers("*** %s added %lu second SVSHOLD on %s (%s)", user->nick, length, parameters[0], reason.c_str());
+                                       ServerInstance->SNO->WriteToSnoMask('A', "%s added %lu second SVSHOLD on %s (%s)", user->nick, length, parameters[0], reason.c_str());
                                }
                                else
                                {
                                        user->WriteServ( "385 %s %s :Added permanent SVSHOLD on %s (%s)", user->nick, parameters[0], parameters[0], reason.c_str());
-                                       ServerInstance->WriteOpers("*** %s added permanent SVSHOLD on %s (%s)", user->nick, parameters[0], reason.c_str());
+                                       ServerInstance->SNO->WriteToSnoMask('A', "%s added permanent SVSHOLD on %s (%s)", user->nick, parameters[0], reason.c_str());
                                }
                        }
                        else
@@ -141,22 +151,20 @@ bool SVSHoldComp(const SVSHold* ban1, const SVSHold* ban2)
 
 class ModuleSVSHold : public Module
 {
-       cmd_svshold *mycommand;
+       CommandSvshold *mycommand;
        
 
  public:
-       ModuleSVSHold(InspIRCd* Me) : Module::Module(Me)
+       ModuleSVSHold(InspIRCd* Me) : Module(Me)
        {
-               mycommand = new cmd_svshold(Me);
+               mycommand = new CommandSvshold(Me);
                ServerInstance->AddCommand(mycommand);
+               Implementation eventlist[] = { I_OnUserPreNick, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 4);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnUserPreNick] = List[I_OnSyncOtherMetaData] = List[I_OnDecodeMetaData] = List[I_OnStats] = 1;
-       }
        
-       virtual int OnStats(char symbol, userrec* user, string_list &results)
+       virtual int OnStats(char symbol, User* user, string_list &results)
        {
                ExpireBans();
        
@@ -172,7 +180,7 @@ class ModuleSVSHold : public Module
                return 0;
        }
 
-       virtual int OnUserPreNick(userrec *user, const std::string &newnick)
+       virtual int OnUserPreNick(User *user, const std::string &newnick)
        {
                ExpireBans();
        
@@ -186,7 +194,7 @@ class ModuleSVSHold : public Module
                return 0;
        }
        
-       virtual void OnSyncOtherMetaData(Module* proto, void* opaque)
+       virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable)
        {
                for(SVSHoldMap::iterator iter = HoldMap.begin(); iter != HoldMap.end(); iter++)
                {
@@ -218,25 +226,27 @@ class ModuleSVSHold : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,1,0,1,VF_VENDOR|VF_COMMON,API_VERSION);
+               return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
        }
 
        std::string EncodeSVSHold(const SVSHold* ban)
        {
                std::ostringstream stream;      
-               stream << ban->nickname << " " << ban->set_by << " " << ban->set_on << " " << ban->length << " " << ban->reason;
+               stream << ban->nickname << " " << ban->set_by << " " << ban->set_on << " " << ban->length << " :" << ban->reason;
                return stream.str();    
        }
 
        SVSHold* DecodeSVSHold(const std::string &data)
        {
                SVSHold* res = new SVSHold();
-               std::istringstream stream(data);
-               stream >> res->nickname;
-               stream >> res->set_by;
-               stream >> res->set_on;
-               stream >> res->length;
-               res->reason = stream.str();
+               int set_on;
+               irc::tokenstream tokens(data);
+               tokens.GetToken(res->nickname);
+               tokens.GetToken(res->set_by);
+               tokens.GetToken(set_on);
+               res->set_on = set_on;
+               tokens.GetToken(res->length);
+               tokens.GetToken(res->reason);
                return res;
        }
 
@@ -250,8 +260,8 @@ class ModuleSVSHold : public Module
                        {
                                if ((*iter)->set_on + (*iter)->length <= ServerInstance->Time())
                                {
-                                       ServerInstance->Log(DEBUG, "m_svshold.so: hold on %s expired, removing...", (*iter)->nickname.c_str());
-                                       ServerInstance->WriteOpers("*** %li second SVSHOLD on %s (%s) set %u seconds ago expired", (*iter)->length, (*iter)->nickname.c_str(), (*iter)->reason.c_str(), ServerInstance->Time() - (*iter)->set_on);
+                                       ServerInstance->Logs->Log("m_svshold",DEBUG, "m_svshold.so: hold on %s expired, removing...", (*iter)->nickname.c_str());
+                                       ServerInstance->SNO->WriteToSnoMask('A',"%li second SVSHOLD on %s (%s) set %u seconds ago expired", (*iter)->length, (*iter)->nickname.c_str(), (*iter)->reason.c_str(), ServerInstance->Time() - (*iter)->set_on);
                                        HoldMap.erase(assign((*iter)->nickname));
                                        delete *iter;
                                        safeiter = iter;
@@ -263,26 +273,4 @@ class ModuleSVSHold : public Module
        }
 };
 
-class ModuleSVSHoldFactory : public ModuleFactory
-{
- public:
-       ModuleSVSHoldFactory()
-       {
-       }
-       
-       ~ModuleSVSHoldFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSVSHold(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleSVSHoldFactory;
-}
+MODULE_INIT(ModuleSVSHold)