]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_cap.cpp
Merge pull request #92 from Robby-/insp20-headers
[user/henk/code/inspircd.git] / src / modules / m_cap.cpp
index 2b700a5ae013d0262d82a5554610576451384be9..36674b9c5a41c41f5f88629e65d3a2cadcaca470 100644 (file)
@@ -1,16 +1,23 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
  *
- * ---------------------------------------------------
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include "m_cap.h"
 
@@ -35,8 +42,11 @@ CAP END
 class CommandCAP : public Command
 {
  public:
-       CommandCAP (InspIRCd* Instance, Module* mod) : Command(Instance, mod, "CAP", 0, 1, true)
+       LocalIntExt reghold;
+       CommandCAP (Module* mod) : Command(mod, "CAP", 1),
+               reghold("CAP_REGHOLD", mod)
        {
+               works_before_reg = true;
        }
 
        CmdResult Handle (const std::vector<std::string> &parameters, User *user)
@@ -45,7 +55,7 @@ class CommandCAP : public Command
 
                if (subcommand == "REQ")
                {
-                       CapData Data;
+                       CapEvent Data(creator, "cap_req");
 
                        Data.type = subcommand;
                        Data.user = user;
@@ -64,37 +74,35 @@ class CommandCAP : public Command
                                Data.wanted.push_back(cap_);
                        }
 
-                       user->Extend("CAP_REGHOLD");
-                       Event event((char*) &Data, this->creator, "cap_req");
-                       event.Send(this->ServerInstance);
+                       reghold.set(user, 1);
+                       Data.Send();
 
                        if (Data.ack.size() > 0)
                        {
                                std::string AckResult = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined();
-                               user->WriteServ("CAP * ACK :%s", AckResult.c_str());
+                               user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), AckResult.c_str());
                        }
 
                        if (Data.wanted.size() > 0)
                        {
                                std::string NakResult = irc::stringjoiner(" ", Data.wanted, 0, Data.wanted.size() - 1).GetJoined();
-                               user->WriteServ("CAP * NAK :%s", NakResult.c_str());
+                               user->WriteServ("CAP %s NAK :%s", user->nick.c_str(), NakResult.c_str());
                        }
                }
                else if (subcommand == "END")
                {
-                       user->Shrink("CAP_REGHOLD");
+                       reghold.set(user, 0);
                }
                else if ((subcommand == "LS") || (subcommand == "LIST"))
                {
-                       CapData Data;
+                       CapEvent Data(creator, subcommand == "LS" ? "cap_ls" : "cap_list");
 
                        Data.type = subcommand;
                        Data.user = user;
                        Data.creator = this->creator;
 
-                       user->Extend("CAP_REGHOLD");
-                       Event event((char*) &Data, this->creator, subcommand == "LS" ? "cap_ls" : "cap_list");
-                       event.Send(this->ServerInstance);
+                       reghold.set(user, 1);
+                       Data.Send();
 
                        std::string Result;
                        if (Data.wanted.size() > 0)
@@ -102,26 +110,25 @@ class CommandCAP : public Command
                        else
                                Result = "";
 
-                       user->WriteServ("CAP * %s :%s", subcommand.c_str(), Result.c_str());
+                       user->WriteServ("CAP %s %s :%s", user->nick.c_str(), subcommand.c_str(), Result.c_str());
                }
                else if (subcommand == "CLEAR")
                {
-                       CapData Data;
+                       CapEvent Data(creator, "cap_clear");
 
                        Data.type = subcommand;
                        Data.user = user;
                        Data.creator = this->creator;
 
-                       user->Extend("CAP_REGHOLD");
-                       Event event((char*) &Data, this->creator, "cap_clear");
-                       event.Send(this->ServerInstance);
+                       reghold.set(user, 1);
+                       Data.Send();
 
                        std::string Result = irc::stringjoiner(" ", Data.ack, 0, Data.ack.size() - 1).GetJoined();
-                       user->WriteServ("CAP * ACK :%s", Result.c_str());
+                       user->WriteServ("CAP %s ACK :%s", user->nick.c_str(), Result.c_str());
                }
                else
                {
-                       user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "* %s :Invalid CAP subcommand", subcommand.c_str());
+                       user->WriteNumeric(ERR_INVALIDCAPSUBCOMMAND, "%s %s :Invalid CAP subcommand", user->nick.c_str(), subcommand.c_str());
                }
 
                return CMD_FAILURE;
@@ -130,33 +137,34 @@ class CommandCAP : public Command
 
 class ModuleCAP : public Module
 {
-       CommandCAP newcommand;
+       CommandCAP cmd;
  public:
-       ModuleCAP(InspIRCd* Me)
-               : Module(Me), newcommand(Me, this)
+       ModuleCAP()
+               : cmd(this)
        {
-               ServerInstance->AddCommand(&newcommand);
+               ServerInstance->AddCommand(&cmd);
+               ServerInstance->Extensions.Register(&cmd.reghold);
 
                Implementation eventlist[] = { I_OnCheckReady };
                ServerInstance->Modules->Attach(eventlist, this, 1);
        }
 
-       virtual bool OnCheckReady(User* user)
+       ModResult OnCheckReady(LocalUser* user)
        {
                /* Users in CAP state get held until CAP END */
-               if (user->GetExt("CAP_REGHOLD"))
-                       return false;
+               if (cmd.reghold.get(user))
+                       return MOD_RES_DENY;
 
-               return true;
+               return MOD_RES_PASSTHRU;
        }
 
-       virtual ~ModuleCAP()
+       ~ModuleCAP()
        {
        }
 
-       virtual Version GetVersion()
+       Version GetVersion()
        {
-               return Version("$Id$", VF_VENDOR, API_VERSION);
+               return Version("Client CAP extension support", VF_VENDOR);
        }
 };