]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_swhois.cpp
Add config <options:disablehmac> to support disabling of HMAC, and tidy up to detect...
[user/henk/code/inspircd.git] / src / modules / m_swhois.cpp
index 4b62db699ad680c399c980cce1abff04d2b2f765..3dcdb10f2bb92e46536cc36585f1d4689d971dc8 100644 (file)
@@ -2,12 +2,9 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *                       E-mail:
- *                <brain@chatspike.net>
- *               <Craig@chatspike.net>
- *     
- * Written by Craig Edwards, Craig McLure, and others.
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
  *
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-
 #include "inspircd.h"
 
 /* $ModDesc: Provides the SWHOIS command which allows setting of arbitary WHOIS lines */
 
-
-
+/** Handle /SWHOIS
+ */
 class cmd_swhois : public command_t
 {
        
@@ -93,7 +89,7 @@ class ModuleSWhois : public Module
                ServerInstance->AddCommand(mycommand);
        }
 
-       void OnRehash(const std::string &parameter)
+       void OnRehash(userrec* user, const std::string &parameter)
        {
                DELETE(Conf);
                Conf = new ConfigReader(ServerInstance);
@@ -101,18 +97,25 @@ class ModuleSWhois : public Module
 
        void Implements(char* List)
        {
-               List[I_OnWhois] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnOper] = 1;
+               List[I_OnDecodeMetaData] = List[I_OnWhoisLine] = List[I_OnSyncUserMetaData] = List[I_OnUserQuit] = List[I_OnCleanup] = List[I_OnRehash] = List[I_OnPostCommand] = 1;
        }
 
        // :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
-       virtual void OnWhois(userrec* source, userrec* dest)
+       int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
        {
-               std::string* swhois;
-               dest->GetExt("swhois", swhois);
-               if (swhois)
+               /* We use this and not OnWhois because this triggers for remote, too */
+               if (numeric == 312)
                {
-                       source->WriteServ("320 %s %s :%s",source->nick,dest->nick,swhois->c_str());
+                       /* Insert our numeric before 312 */
+                       std::string* swhois;
+                       dest->GetExt("swhois", swhois);
+                       if (swhois)
+                       {
+                               ServerInstance->SendWhoisLine(user, dest, 320, "%s %s :%s",user->nick,dest->nick,swhois->c_str());
+                       }
                }
+               /* Dont block anything */
+               return 0;
        }
 
        // Whenever the linking module wants to send out data, but doesnt know what the data
@@ -138,7 +141,7 @@ class ModuleSWhois : public Module
        }
 
        // when a user quits, tidy up their metadata
-       virtual void OnUserQuit(userrec* user, const std::string &message)
+       virtual void OnUserQuit(userrec* user, const std::string &message, const std::string &oper_message)
        {
                std::string* swhois;
                user->GetExt("swhois", swhois);
@@ -188,34 +191,59 @@ class ModuleSWhois : public Module
                }
        }
        
-       virtual void OnOper(userrec* user, const std::string &opertype)
+       virtual void OnPostCommand(const std::string &command, const char **params, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
        {
-               for(int i =0; i < Conf->Enumerate("type"); i++)
+               if ((command != "OPER") || (result != CMD_SUCCESS))
+                       return;
+               
+               std::string swhois;
+               
+               for (int i = 0; i < Conf->Enumerate("oper"); i++)
                {
-                       std::string type = Conf->ReadValue("type", "name", i);
+                       std::string name = Conf->ReadValue("oper", "name", i);
                        
-                       if(strcmp(type.c_str(), user->oper) == 0)
+                       if (name == params[0])
                        {
-                               std::string swhois = Conf->ReadValue("type", "swhois", i);
+                               swhois = Conf->ReadValue("oper", "swhois", i);
+                               break;
+                       }
+               }
+               
+               if (!swhois.length())
+               {
+                       for (int i = 0; i < Conf->Enumerate("type"); i++)
+                       {
+                               std::string type = Conf->ReadValue("type", "name", i);
                                
-                               if(swhois.length())
+                               if (type == user->oper)
                                {
-                                       std::string* old;
-                                       if(user->GetExt("swhois", old))
-                                       {
-                                               user->Shrink("swhois");
-                                               DELETE(old);
-                                       }
-                       
-                                       std::string* text = new std::string(swhois);
-                                       user->Extend("swhois", text);
-                                       
+                                       swhois = Conf->ReadValue("type", "swhois", i);
                                        break;
                                }
                        }
-               }               
+               }
+
+               std::string *old;
+               if (user->GetExt("swhois", old))
+               {
+                       user->Shrink("swhois");
+                       DELETE(old);
+               }
+               
+               if (!swhois.length())
+                       return;
+               
+               std::string *text = new std::string(swhois);
+               user->Extend("swhois", text);
+               std::deque<std::string>* metadata = new std::deque<std::string>;
+               metadata->push_back(user->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;
        }
-       
+
        virtual ~ModuleSWhois()
        {
                DELETE(Conf);
@@ -223,7 +251,7 @@ class ModuleSWhois : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,0,VF_VENDOR);
+               return Version(1,1,0,0,VF_VENDOR,API_VERSION);
        }
 };