]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_swhois.cpp
This works, not sure why. Someone find out why we cant use && !isock->HasResult(...
[user/henk/code/inspircd.git] / src / modules / m_swhois.cpp
index d635654a524fd1229b02031dc35f95f05dc3d677..cd82bce67a0232cf2e77b383533372fcee69ab0f 100644 (file)
  */
 
 #include "inspircd.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 
 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
 
 /** Handle /SWHOIS
  */
-class cmd_swhois : public command_t
+class CommandSwhois : public Command
 {
        
  public:
-       cmd_swhois (InspIRCd* Instance) : command_t(Instance,"SWHOIS",'o',2)
+       CommandSwhois (InspIRCd* Instance) : Command(Instance,"SWHOIS",'o',2)
        {
                this->source = "m_swhois.so";
                syntax = "<nick> <swhois>";
+               TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
        }
 
-       CmdResult Handle(const char** parameters, int pcnt, userrec* user)
+       CmdResult Handle(const char** parameters, int pcnt, User* user)
        {
-               userrec* dest = ServerInstance->FindNick(parameters[0]);
+               User* dest = ServerInstance->FindNick(parameters[0]);
                
                if (!dest)
                {
@@ -78,14 +76,28 @@ class cmd_swhois : public command_t
                text = new std::string(line);
                dest->Extend("swhois", text);
 
-               return CMD_SUCCESS;
+               /* 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_LOCALONLY;
        }
 
 };
 
 class ModuleSWhois : public Module
 {
-       cmd_swhois* mycommand;
+       CommandSwhois* mycommand;
        
        ConfigReader* Conf;
        
@@ -94,11 +106,11 @@ class ModuleSWhois : public Module
        {
                
                Conf = new ConfigReader(ServerInstance);
-               mycommand = new cmd_swhois(ServerInstance);
+               mycommand = new CommandSwhois(ServerInstance);
                ServerInstance->AddCommand(mycommand);
        }
 
-       void OnRehash(userrec* user, const std::string &parameter)
+       void OnRehash(User* user, const std::string &parameter)
        {
                DELETE(Conf);
                Conf = new ConfigReader(ServerInstance);
@@ -110,7 +122,7 @@ class ModuleSWhois : public Module
        }
 
        // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
-       int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
+       int OnWhoisLine(User* user, User* dest, int &numeric, std::string &text)
        {
                /* We use this and not OnWhois because this triggers for remote, too */
                if (numeric == 312)
@@ -128,11 +140,11 @@ class ModuleSWhois : public Module
        }
 
        // Whenever the linking module wants to send out data, but doesnt know what the data
-       // represents (e.g. it is metadata, added to a userrec or chanrec by a module) then
+       // represents (e.g. it is metadata, added to a User or Channel by a module) then
        // this method is called. We should use the ProtoSendMetaData function after we've
        // corrected decided how the data should look, to send the metadata on its way if
        // it is ours.
-       virtual void OnSyncUserMetaData(userrec* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
+       virtual void OnSyncUserMetaData(User* user, Module* proto, void* opaque, const std::string &extname, bool displayable)
        {
                // check if the linking module wants to know about OUR metadata
                if (extname == "swhois")
@@ -150,7 +162,7 @@ class ModuleSWhois : public Module
        }
 
        // when a user quits, tidy up their metadata
-       virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
+       virtual void OnUserQuit(User* user, const std::string &message, const std::string &oper_message)
        {
                std::string* swhois;
                user->GetExt("swhois", swhois);
@@ -166,7 +178,7 @@ class ModuleSWhois : public Module
        {
                if (target_type == TYPE_USER)
                {
-                       userrec* user = (userrec*)item;
+                       User* user = (User*)item;
                        std::string* swhois;
                        user->GetExt("swhois", swhois);
                        if (swhois)
@@ -189,7 +201,7 @@ class ModuleSWhois : public Module
                // check if its our metadata key, and its associated with a user
                if ((target_type == TYPE_USER) && (extname == "swhois"))
                {
-                       userrec* dest = (userrec*)target;
+                       User* dest = (User*)target;
                        // if they dont already have an swhois field, accept the remote server's
                        std::string* text;
                        if (!dest->GetExt("swhois", text))
@@ -200,7 +212,7 @@ class ModuleSWhois : public Module
                }
        }
        
-       virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
+       virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, User *user, CmdResult result, const std::string &original_line)
        {
                if ((command != "OPER") || (result != CMD_SUCCESS))
                        return;
@@ -260,7 +272,7 @@ class ModuleSWhois : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
+               return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
        }
 };