]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_svshold.cpp
Remove unneeded headers from spanningtree. This was done to the rest of the source...
[user/henk/code/inspircd.git] / src / modules / m_svshold.cpp
index 60416209347d05fa07887f8a0ff3219b47eeb5dd..4027dbeb790206f1042a0b2d7dfbbc1dbb22fd7d 100644 (file)
  * ---------------------------------------------------
  */
 
-#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. */
@@ -59,6 +54,7 @@ class cmd_svshold : public command_t
        {
                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)
@@ -66,6 +62,12 @@ class cmd_svshold : public command_t
                /* 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;
                                        }
@@ -145,7 +155,7 @@ class ModuleSVSHold : public Module
        
 
  public:
-       ModuleSVSHold(InspIRCd* Me) : Module::Module(Me)
+       ModuleSVSHold(InspIRCd* Me) : Module(Me)
        {
                mycommand = new cmd_svshold(Me);
                ServerInstance->AddCommand(mycommand);
@@ -186,7 +196,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 +228,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;
        }
 
@@ -263,26 +275,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)