]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_chghost.cpp
Wahhhhhhhhhhhh bwahahaha. Mass commit to tidy up tons of messy include lists
[user/henk/code/inspircd.git] / src / modules / m_chghost.cpp
index 8a2e696bc3917ecde9028b74959a1cd230edd40c..fdb438c91a2eaebcd2711b2f6f8f4da6a9e676b9 100644 (file)
@@ -21,47 +21,49 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "helperfuncs.h"
+
+#include "inspircd.h"
 
 /* $ModDesc: Provides support for the CHGHOST command */
 
-Server *Srv;
 
 
 class cmd_chghost : public command_t
 {
  public:
-         cmd_chghost () : command_t("CHGHOST",'o',2)
-        {
-                this->source = "m_chghost.so";
-        }
+ cmd_chghost (InspIRCd* Instance) : command_t(Instance,"CHGHOST",'o',2)
+       {
+               this->source = "m_chghost.so";
+               syntax = "<nick> <newhost>";
+       }
         
-        void Handle(char **parameters, int pcnt, userrec *user)
+       void Handle(const char** parameters, int pcnt, userrec *user)
        {
-                if (strlen(parameters[1]) > 64)
-                {
-                        WriteServ(user->fd,"NOTICE %s :*** CHGHOST: Host too long",user->nick);
-                       return;
-                }
-               for (unsigned int x = 0; x < strlen(parameters[1]); x++)
+               const char * x = parameters[1];
+
+               for (; *x; x++)
                {
-                       if (((tolower(parameters[1][x]) < 'a') || (tolower(parameters[1][x]) > 'z')) && (parameters[1][x] != '.'))
+                       if (((tolower(*x) < 'a') || (tolower(*x) > 'z')) && (*x != '.'))
                        {
-                               if (((parameters[1][x] < '0') || (parameters[1][x]> '9')) && (parameters[1][x] != '-'))
+                               if (((*x < '0') || (*x > '9')) && (*x != '-'))
                                {
-                                       Srv->SendTo(NULL,user,"NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
+                                       user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname");
                                        return;
                                }
                        }
-               }       
-               userrec* dest = Srv->FindNick(std::string(parameters[0]));
+               }
+               if ((parameters[1] - x) > 63)
+               {
+                       user->WriteServ("NOTICE %s :*** CHGHOST: Host too long",user->nick);
+                       return;
+               }
+               userrec* dest = ServerInstance->FindNick(parameters[0]);
                if (dest)
                {
-                       Srv->ChangeHost(dest,parameters[1]);
-                       if (!Srv->IsUlined(user->server))
+                       if ((dest->ChangeDisplayedHost(parameters[1])) && (!ServerInstance->ULine(user->server)))
                        {
                                // fix by brain - ulines set hosts silently
-                               Srv->SendOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+std::string(dest->nick)+" become "+std::string(parameters[1]));
+                               ServerInstance->WriteOpers(std::string(user->nick)+" used CHGHOST to make the displayed host of "+dest->nick+" become "+parameters[1]);
                        }
                }
        }
@@ -72,12 +74,12 @@ class ModuleChgHost : public Module
 {
        cmd_chghost* mycommand;
  public:
-       ModuleChgHost(Server* Me)
+       ModuleChgHost(InspIRCd* Me)
                : Module::Module(Me)
        {
-               Srv = Me;
-               mycommand = new cmd_chghost();
-               Srv->AddCommand(mycommand);
+               
+               mycommand = new cmd_chghost(ServerInstance);
+               ServerInstance->AddCommand(mycommand);
        }
 
        void Implements(char* List)
@@ -108,7 +110,7 @@ class ModuleChgHostFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule(Server* Me)
+       virtual Module * CreateModule(InspIRCd* Me)
        {
                return new ModuleChgHost(Me);
        }