]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_knock.cpp
Set EOL to WINDOWS-style always for Visual Studio files.
[user/henk/code/inspircd.git] / src / modules / m_knock.cpp
index 474dd4014aad49305618933d634f968fbb69c1c1..9beaa699eb58a4237668d07b84dc5132b7c4e7d4 100644 (file)
@@ -1,136 +1 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
- *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-#include <stdio.h>
-#include <string>
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
-
-/* $ModDesc: Provides support for /KNOCK and mode +K */
-
-Server *Srv;
-        
-void handle_knock(char **parameters, int pcnt, userrec *user)
-{
-       chanrec* c = Srv->FindChannel(parameters[0]);
-       std::string line = "";
-
-       for (int i = 1; i < pcnt - 1; i++)
-       {
-               line = line + std::string(parameters[i]) + " ";
-       }
-       line = line + std::string(parameters[pcnt-1]);
-
-       if (c->IsCustomModeSet('K'))
-       {
-               WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
-               return;
-       }
-       if (c->inviteonly)
-       {
-               WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,user,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str());
-               WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
-               return;
-       }
-       else
-       {
-               WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
-               return;
-       }
-}
-
-
-class ModuleKnock : public Module
-{
- public:
-       ModuleKnock()
-       {
-               Srv = new Server;
-               
-               Srv->AddExtendedMode('K',MT_CHANNEL,false,0,0);
-               Srv->AddCommand("KNOCK",handle_knock,0,2);
-       }
-
-        virtual void On005Numeric(std::string &output)
-        {
-                std::stringstream line(output);
-                std::string temp1, temp2;
-                while (!line.eof())
-                {
-                        line >> temp1;
-                        if (temp1.substr(0,10) == "CHANMODES=")
-                        {
-                                // append the chanmode to the end
-                                temp1 = temp1.substr(10,temp1.length());
-                                temp1 = "CHANMODES=" + temp1 + "K";
-                        }
-                        temp2 = temp2 + temp1 + " ";
-                }
-                output = temp2.substr(0,temp2.length()-1) + std::string(" KNOCK");
-        }
-
-       virtual ~ModuleKnock()
-       {
-               delete Srv;
-       }
-       
-       virtual Version GetVersion()
-       {
-               return Version(1,0,0,1);
-       }
-       
-       virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
-       {
-               // check if this is our mode character...
-               if ((modechar == 'K') && (type == MT_CHANNEL))
-               {
-                       return 1;
-               }
-               else
-               {
-                       return 0;
-               }
-       }
-
-};
-
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
-
-class ModuleKnockFactory : public ModuleFactory
-{
- public:
-       ModuleKnockFactory()
-       {
-       }
-       
-       ~ModuleKnockFactory()
-       {
-       }
-       
-       virtual Module * CreateModule()
-       {
-               return new ModuleKnock;
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleKnockFactory;
-}
-
+/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "channels.h"\r#include "modules.h"\r\r/* $ModDesc: Provides support for /KNOCK and mode +K */\r\r/** Handles the /KNOCK command\r */\rclass cmd_knock : public command_t\r{\r public:\r    cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)\r     {\r              this->source = "m_knock.so";\r           syntax = "<channel> <reason>";\r }\r      \r       CmdResult Handle (const char** parameters, int pcnt, userrec *user)\r    {\r              chanrec* c = ServerInstance->FindChan(parameters[0]);\r\r         if (!c)\r                {\r                      user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);\r                       return CMD_FAILURE;\r            }\r\r             std::string line;\r\r             if (c->IsModeSet('K'))\r         {\r                      user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);\r                  return CMD_FAILURE;\r            }\r\r             for (int i = 1; i < pcnt - 1; i++)\r             {\r                      line = line + std::string(parameters[i]) + " ";\r                }\r              line = line + std::string(parameters[pcnt-1]);\r\r                if (!c->modes[CM_INVITEONLY])\r          {\r                      user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);\r                        return CMD_FAILURE;\r            }\r\r             c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName,  "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());\r          user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);\r               return CMD_SUCCESS;\r    }\r};\r\r/** Handles channel mode +K\r */\rclass Knock : public ModeHandler\r{\r public:\r      Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }\r\r      ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)\r {\r              if (adding)\r            {\r                      if (!channel->IsModeSet('K'))\r                  {\r                              channel->SetMode('K',true);\r                            return MODEACTION_ALLOW;\r                       }\r              }\r              else\r           {\r                      if (channel->IsModeSet('K'))\r                   {\r                              channel->SetMode('K',false);\r                           return MODEACTION_ALLOW;\r                       }\r              }\r\r             return MODEACTION_DENY;\r        }\r};\r\rclass ModuleKnock : public Module\r{\r      cmd_knock* mycommand;\r  Knock* kn;\r public:\r    ModuleKnock(InspIRCd* Me) : Module(Me)\r {\r              \r               kn = new Knock(ServerInstance);\r                if (!ServerInstance->AddMode(kn, 'K'))\r                 throw ModuleException("Could not add new modes!");\r             mycommand = new cmd_knock(ServerInstance);\r             ServerInstance->AddCommand(mycommand);\r }\r\r     void Implements(char* List)\r    {\r      }\r\r     virtual ~ModuleKnock()\r {\r              ServerInstance->Modes->DelMode(kn);\r            DELETE(kn);\r    }\r\r     virtual Version GetVersion()\r   {\r              return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);\r       }\r};\r\rMODULE_INIT(ModuleKnock)\r
\ No newline at end of file