]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_svshold.cpp
Conversions. :D
[user/henk/code/inspircd.git] / src / modules / m_svshold.cpp
index 945125c75d33b49068fd81578ff76f98bafafec7..a056c9d84e2a5c0300c98cdff6a50fa9a4661f78 100644 (file)
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #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. */
 
@@ -66,6 +66,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 +82,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;
                                        }
@@ -119,7 +133,7 @@ class cmd_svshold : public command_t
                                }
                                else
                                {
-                                       user->WriteServ( "385 %s %s :Added permanent SVSHOLD on %s (%s)", user->nick, parameters[0], reason.c_str());
+                                       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());
                                }
                        }
@@ -145,7 +159,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 +200,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++)
                {
@@ -224,76 +238,45 @@ class ModuleSVSHold : public Module
        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;
        }
 
        void ExpireBans()
        {
-               bool go_again = true;
-
-               while (go_again)
+               SVSHoldlist::iterator iter,safeiter;
+               for (iter = SVSHolds.begin(); iter != SVSHolds.end(); iter++)
                {
-                       go_again = false;
-       
-                       for (SVSHoldlist::iterator iter = SVSHolds.begin(); iter != SVSHolds.end(); iter++)
+                       /* 0 == permanent, don't mess with them! -- w00t */
+                       if ((*iter)->length != 0)
                        {
-                               /* 0 == permanent, don't mess with them! -- w00t */
-                               if ((*iter)->length != 0)
+                               if ((*iter)->set_on + (*iter)->length <= ServerInstance->Time())
                                {
-                                       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);
-                                               HoldMap.erase(assign((*iter)->nickname));
-
-                                               delete *iter;
-
-                                               SVSHolds.erase(iter);
-
-                                               go_again = true;
-                                       }
+                                       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);
+                                       HoldMap.erase(assign((*iter)->nickname));
+                                       delete *iter;
+                                       safeiter = iter;
+                                       --iter;
+                                       SVSHolds.erase(safeiter);
                                }
-       
-                               if (go_again == true)
-                                       break;
                        }
                }
        }
 };
 
-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);