]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cban.cpp
Argh, i give up
[user/henk/code/inspircd.git] / src / modules / m_cban.cpp
index ff8e3af543ad4b50702d2f271d988bf2c46dd99d..7b245bfb88564f48e296cfb2e6d171c3c2fc49b5 100644 (file)
@@ -1,29 +1,22 @@
-/*      +------------------------------------+
- *      | Inspire Internet Relay Chat Daemon |
- *      +------------------------------------+
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
  *
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                    E-mail:
- *              <brain@chatspike.net>
- *              <Craig@chatspike.net>
- *                <omster@gmail.com>
- * 
- * Written by Craig Edwards, Craig McLure, and others.
  * This program is free but copyrighted software; see
- * the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
-#include <algorithm>
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-#include "configreader.h"
 #include "inspircd.h"
 
 /* $ModDesc: Gives /cban, aka C:lines. Think Q:lines, for channels. */
 
+/** Holds a CBAN item
+ */
 class CBan : public classbase
 {
 public:
@@ -49,17 +42,19 @@ typedef std::vector<CBan> cbanlist;
 /* cbans is declared here, as our type is right above. Don't try move it. */
 cbanlist cbans;
 
-class cmd_cban : public command_t
+/** Handle /CBAN
+ */
+class CommandCban : public Command
 {
  public:
-       cmd_cban(InspIRCd* Me) : command_t(Me, "CBAN", 'o', 1)
+       CommandCban(InspIRCd* Me) : Command(Me, "CBAN", 'o', 1)
        {
                this->source = "m_cban.so";
-               this->
-               syntax = "<channel> [<duration> :<reason>]";
+               this->syntax = "<channel> [<duration> :<reason>]";
+               TRANSLATE4(TR_TEXT,TR_TEXT,TR_TEXT,TR_END);
        }
 
-       CmdResult Handle(const char** parameters, int pcnt, userrec *user)
+       CmdResult Handle(const char** parameters, int pcnt, User *user)
        {
                /* syntax: CBAN #channel time :reason goes here */
                /* 'time' is a human-readable timestring, like 2d3h2s. */
@@ -71,8 +66,8 @@ class cmd_cban : public command_t
                        {
                                if (parameters[0] == iter->chname)
                                {
-                                       unsigned long remaining = (iter->set_on + iter->length) - ServerInstance->Time();
-                                       user->WriteServ( "386 %s %s :Removed CBAN with %lu seconds left before expiry (%s)", user->nick, iter->chname.c_str(), remaining, iter->reason.c_str());
+                                       long remaining = iter->length + ServerInstance->Time();
+                                       user->WriteServ("386 %s %s :Removed CBAN due to expire at %s (%s)", user->nick, iter->chname.c_str(), ServerInstance->TimeString(remaining).c_str(), iter->reason.c_str());
                                        cbans.erase(iter);
                                        break;
                                }
@@ -95,22 +90,23 @@ class cmd_cban : public command_t
                                
                                if(length > 0)
                                {
-                                       user->WriteServ( "385 %s %s :Added %lu second channel ban (%s)", user->nick, parameters[0], length, reason.c_str());
+                                       user->WriteServ("385 %s %s :Added %lu second channel ban (%s)", user->nick, parameters[0], length, reason.c_str());
                                        ServerInstance->WriteOpers("*** %s added %lu second channel ban on %s (%s)", user->nick, length, parameters[0], reason.c_str());
                                }
                                else
                                {
-                                       user->WriteServ( "385 %s %s :Added permenant channel ban (%s)", user->nick, parameters[0], reason.c_str());
-                                       ServerInstance->WriteOpers("*** %s added permenant channel ban on %s (%s)", user->nick, parameters[0], reason.c_str());
+                                       user->WriteServ("385 %s %s :Added permanent channel ban (%s)", user->nick, parameters[0], reason.c_str());
+                                       ServerInstance->WriteOpers("*** %s added permanent channel ban on %s (%s)", user->nick, parameters[0], reason.c_str());
                                }
                        }
                        else
                        {
-                               user->WriteServ( "403 %s %s :Invalid channel name", user->nick, parameters[0]);
+                               user->WriteServ("403 %s %s :Invalid channel name", user->nick, parameters[0]);
                                return CMD_FAILURE;
                        }
                }
 
+               /* we want this routed! */
                return CMD_SUCCESS;
        }
 };
@@ -122,23 +118,21 @@ bool CBanComp(const CBan &ban1, const CBan &ban2)
 
 class ModuleCBan : public Module
 {
-       cmd_cban* mycommand;
+       CommandCban* mycommand;
        
 
  public:
-       ModuleCBan(InspIRCd* Me) : Module::Module(Me)
+       ModuleCBan(InspIRCd* Me) : Module(Me)
        {
                
-               mycommand = new cmd_cban(Me);
+               mycommand = new CommandCban(Me);
                ServerInstance->AddCommand(mycommand);
+               Implementation eventlist[] = { I_OnUserPreJoin, I_OnSyncOtherMetaData, I_OnDecodeMetaData, I_OnStats };
+               ServerInstance->Modules->Attach(eventlist, this, 4);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnUserPreJoin] = 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();
        
@@ -154,7 +148,7 @@ class ModuleCBan : public Module
                return 0;
        }
 
-       virtual int OnUserPreJoin(userrec *user, chanrec *chan, const char *cname)
+       virtual int OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs)
        {
                ExpireBans();
        
@@ -172,7 +166,7 @@ class ModuleCBan : public Module
                return 0;
        }
        
-       virtual void OnSyncOtherMetaData(Module* proto, void* opaque)
+       virtual void OnSyncOtherMetaData(Module* proto, void* opaque, bool displayable)
        {
                for(cbanlist::iterator iter = cbans.begin(); iter != cbans.end(); iter++)
                {
@@ -195,26 +189,27 @@ class ModuleCBan : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR);
+               return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
        }
 
        std::string EncodeCBan(const CBan &ban)
        {
                std::ostringstream stream;      
-               stream << ban.chname << " " << ban.set_by << " " << ban.set_on << " " << ban.length << " " << ban.reason;
-               return stream.str();    
+               stream << ban.chname << " " << ban.set_by << " " << ban.set_on << " " << ban.length << " :" << ban.reason;
+               return stream.str();
        }
 
        CBan DecodeCBan(const std::string &data)
        {
                CBan res;
-               std::istringstream stream(data);
-               stream >> res.chname;
-               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.chname);
+               tokens.GetToken(res.set_by);
+               tokens.GetToken(set_on);
+               res.set_on = set_on;
+               tokens.GetToken(res.length);
+               tokens.GetToken(res.reason);
                return res;
        }
 
@@ -233,8 +228,7 @@ class ModuleCBan : public Module
                                {
                                        if (iter->set_on + iter->length <= ServerInstance->Time())
                                        {
-                                               ServerInstance->Log(DEBUG, "m_cban.so: Ban on %s expired, removing...", iter->chname.c_str());
-                                               ServerInstance->WriteOpers("*** %li second CBAN on %s (%s) set %u seconds ago expired", iter->length, iter->chname.c_str(), iter->reason.c_str(), ServerInstance->Time() - iter->set_on);
+                                               ServerInstance->WriteOpers("*** %li second CBAN on %s (%s) set on %s expired", iter->length, iter->chname.c_str(), iter->reason.c_str(), ServerInstance->TimeString(iter->set_on).c_str());
                                                cbans.erase(iter);
                                                go_again = true;
                                        }
@@ -247,26 +241,5 @@ class ModuleCBan : public Module
        }
 };
 
-class ModuleCBanFactory : public ModuleFactory
-{
- public:
-       ModuleCBanFactory()
-       {
-       }
-       
-       ~ModuleCBanFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleCBan(Me);
-       }
-       
-};
-
+MODULE_INIT(ModuleCBan)
 
-extern "C" void * init_module( void )
-{
-       return new ModuleCBanFactory;
-}