]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_swhois.cpp
Fix potential for duplicate SID if the SID is auto generated.
[user/henk/code/inspircd.git] / src / modules / m_swhois.cpp
index 193191ab5723e285874e5d08636bee65a01ea307..09d9d94afc2a1a18a769547c69fae81abe83b28f 100644 (file)
@@ -11,9 +11,6 @@
  * ---------------------------------------------------
  */
 
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 #include "inspircd.h"
 
 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
@@ -28,50 +25,74 @@ class cmd_swhois : public command_t
        {
                this->source = "m_swhois.so";
                syntax = "<nick> <swhois>";
+               TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
        }
 
        CmdResult Handle(const char** parameters, int pcnt, userrec* user)
        {
                userrec* dest = ServerInstance->FindNick(parameters[0]);
-               if(dest)
+               
+               if (!dest)
                {
-                       std::string line;
-                       for(int i = 1; i < pcnt; i++)
-                       {
-                               if (i != 1)
-                                       line.append(" ");
-                                       
-                               line.append(parameters[i]);
-                       }
-                       
-                       std::string* text;
-                       dest->GetExt("swhois", text);
-       
-                       if(text)
-                       {
-                               // We already had it set...
-                               
-                               if (!ServerInstance->ULine(user->server))
-                                       // Ulines set SWHOISes silently
-                                       ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str());
+                       user->WriteServ("401 %s %s :No such nick/channel", user->nick, parameters[0]);
+                       return CMD_FAILURE;
+               }
+
+               if (!*parameters[1])
+               {
+                       user->WriteServ("NOTICE %s :*** SWHOIS: Whois line must be specified", user->nick);
+                       return CMD_FAILURE;
+               }
+               
+               std::string line;
+               for (int i = 1; i < pcnt; i++)
+               {
+                       if (i != 1)
+                               line.append(" ");
                                
-                               dest->Shrink("swhois");
-                               DELETE(text);
-                       }
-                       else if(!ServerInstance->ULine(user->server))
-                       {
+                       line.append(parameters[i]);
+               }
+               
+               std::string* text;
+               dest->GetExt("swhois", text);
+
+               if (text)
+               {
+                       // We already had it set...
+                       
+                       if (!ServerInstance->ULine(user->server))
                                // Ulines set SWHOISes silently
-                               ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
-                       }
+                               ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois from '%s' to '%s'", user->nick, dest->nick, text->c_str(), line.c_str());
                        
-                       text = new std::string(line);
-                       dest->Extend("swhois", text);
-
-                       return CMD_SUCCESS;
+                       dest->Shrink("swhois");
+                       DELETE(text);
+               }
+               else if (!ServerInstance->ULine(user->server))
+               {
+                       // Ulines set SWHOISes silently
+                       ServerInstance->WriteOpers("*** %s used SWHOIS to set %s's extra whois to '%s'", user->nick, dest->nick, line.c_str());
                }
+               
+               text = new std::string(line);
+               dest->Extend("swhois", text);
+
+               /* Bug #376 - feature request -
+                * To cut down on the amount of commands services etc have to recognise, this only sends METADATA across the network now
+                * not an actual SWHOIS command. Any SWHOIS command sent from services will be automatically translated to METADATA by this.
+                * Sorry w00t i know this was your fix, but i got bored and wanted to clear down the tracker :)
+                * -- Brain
+                */
+               std::deque<std::string>* metadata = new std::deque<std::string>;
+               metadata->push_back(dest->nick);
+               metadata->push_back("swhois");          // The metadata id
+               metadata->push_back(*text);             // The value to send
+               Event event((char*)metadata,(Module*)this,"send_metadata");
+               event.Send(ServerInstance);
+               delete metadata;
 
-               return CMD_FAILURE;
+               return CMD_LOCALONLY;
        }
+
 };
 
 class ModuleSWhois : public Module
@@ -251,32 +272,8 @@ class ModuleSWhois : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
-       }
-};
-
-
-class ModuleSWhoisFactory : public ModuleFactory
-{
- public:
-       ModuleSWhoisFactory()
-       {
-       }
-       
-       ~ModuleSWhoisFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSWhois(Me);
+               return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
        }
-       
 };
 
-
-extern "C" DllExport void * init_module( void )
-{
-       return new ModuleSWhoisFactory;
-}
-
+MODULE_INIT(ModuleSWhois)