]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_hostchange.cpp
None of the modules use an extern InspIRCd* any more
[user/henk/code/inspircd.git] / src / modules / m_hostchange.cpp
index 0d7060f8b7a1e29d0f404d4c1e0f21a53f3583e6..2fe7ddbb89a4b4d6bcf1764655e48986b6662352 100644 (file)
@@ -20,29 +20,47 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "inspircd.h"
 
 /* $ModDesc: Provides masking of user hostnames in a different way to m_cloaking */
 
+
+
+class Host : public classbase
+{
+ public:
+       std::string action;
+       std::string newhost;
+};
+
+typedef std::map<std::string,Host*> hostchanges_t;
+
 class ModuleHostChange : public Module
 {
  private:
 
-       Server *Srv;
+       
        ConfigReader *Conf;
+       hostchanges_t hostchanges;
        std::string MySuffix;
         
  public:
-       ModuleHostChange(Server* Me)
+       ModuleHostChange(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
-                Conf = new ConfigReader;
-               MySuffix = Conf->ReadValue("host","suffix",0);
+               
+               Conf = new ConfigReader;
+               OnRehash("");
        }
        
        virtual ~ModuleHostChange()
        {
-               delete Conf;
+               DELETE(Conf);
+       }
+
+       Priority Prioritize()
+       {
+               return (Priority)ServerInstance->PriorityAfter("m_cloaking.so");
        }
 
        void Implements(char* List)
@@ -50,11 +68,26 @@ class ModuleHostChange : public Module
                List[I_OnRehash] = List[I_OnUserConnect] = 1;
        }
 
-       virtual void OnRehash(std::string parameter)
+       virtual void OnRehash(const std::string &parameter)
        {
-               delete Conf;
+               DELETE(Conf);
                Conf = new ConfigReader;
                MySuffix = Conf->ReadValue("host","suffix",0);
+               for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
+               {
+                       DELETE(i->second);
+               }
+               hostchanges.clear();
+               for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
+               {
+                       std::string mask = Conf->ReadValue("hostchange","mask",index);
+                       std::string action = Conf->ReadValue("hostchange","action",index);
+                       std::string newhost = Conf->ReadValue("hostchange","value",index);
+                       Host* x = new Host;
+                       x->action = action;
+                       x->newhost = newhost;
+                       hostchanges[mask] = x;
+               }
        }
        
        virtual Version GetVersion()
@@ -66,23 +99,22 @@ class ModuleHostChange : public Module
        
        virtual void OnUserConnect(userrec* user)
        {
-               for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
+               for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
                {
-                       std::string mask = Conf->ReadValue("hostchange","mask",index);
-                       if (Srv->MatchText(std::string(user->ident)+"@"+std::string(user->host),mask))
+                       if (ServerInstance->MatchText(std::string(user->ident)+"@"+std::string(user->host),i->first))
                        {
-                               std::string newhost = "";
+                               Host* h = (Host*)i->second;
                                // host of new user matches a hostchange tag's mask
-                               std::string action = Conf->ReadValue("hostchange","action",index);
-                               if (action == "set")
+                               std::string newhost = "";
+                               if (h->action == "set")
                                {
-                                       newhost = Conf->ReadValue("hostchange","value",index);
+                                       newhost = h->newhost;
                                }
-                               else if (action == "suffix")
+                               else if (h->action == "suffix")
                                {
                                        newhost = MySuffix;
                                }
-                               else if (action == "addnick")
+                               else if (h->action == "addnick")
                                {
                                        // first take their nick and strip out non-dns, leaving just [A-Z0-9\-]
                                        std::string complete = "";
@@ -103,8 +135,9 @@ class ModuleHostChange : public Module
                                }
                                if (newhost != "")
                                {
-                                       Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Setting your VHost: " + newhost);
-                                       Srv->ChangeHost(user,newhost);
+                                       user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your virtual host: " + newhost);
+                                       if (!user->ChangeDisplayedHost(newhost.c_str()))
+                                               user->WriteServ("NOTICE "+std::string(user->nick)+" :Could not set your virtual host: " + newhost);
                                        return;
                                }
                        }
@@ -125,7 +158,7 @@ class ModuleHostChangeFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleHostChange(Me);
        }