]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqloper.cpp
Change 974 numeric to 490 to avoid collision with Insp's failed to load module error
[user/henk/code/inspircd.git] / src / modules / extra / m_sqloper.cpp
index e491ec5ecd6f06e747af2e33d76bf7100283331b..6451b0ed4d5c21ced35365e0790f37f9a287ab5e 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2004 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -14,6 +14,8 @@
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include <stdio.h>
 #include <string>
 #include <stdlib.h>
@@ -30,6 +32,7 @@
 #include "channels.h"
 #include "modules.h"
 #include "inspircd.h"
+#include "helperfuncs.h"
 #include "m_sql.h"
 
 /* $ModDesc: Allows storage of oper credentials in an SQL table */
@@ -52,20 +55,26 @@ class ModuleSQLOper : public Module
                return (SQLModule);
        }
 
-       ModuleSQLOper()
+       ModuleSQLOper(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
+               Srv = Me;
                Conf = new ConfigReader();
                ReadConfig();
        }
 
-       virtual void OnRehash()
+       virtual void OnRehash(std::string parameter)
        {
                delete Conf;
                Conf = new ConfigReader();
                ReadConfig();
        }
 
+       void Implements(char* List)
+       {
+               List[I_OnRehash] = List[I_OnPreCommand] = 1;
+       }
+
        virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user)
        {
                if (command == "OPER")
@@ -86,7 +95,7 @@ class ModuleSQLOper : public Module
 
                // sanitize the password (we dont want any mysql insertion exploits!)
                std::string temp = "";
-               for (int q = 0; q < password.length(); q++)
+               for (unsigned int q = 0; q < password.length(); q++)
                {
                        if (password[q] == '\'')
                        {
@@ -100,7 +109,7 @@ class ModuleSQLOper : public Module
                }
                password = temp;
                temp = "";
-               for (int v = 0; v < username.length(); v++)
+               for (unsigned int v = 0; v < username.length(); v++)
                {
                        if (username[v] == '\'')
                        {
@@ -143,9 +152,9 @@ class ModuleSQLOper : public Module
                                                if ((TypeName == rowresult->GetField("type")) && (Srv->MatchText(pattern,rowresult->GetField("hostname"))));
                                                {
                                                        /* found this oper's opertype */
-                                                       Srv->MeshSendAll("| "+std::string(user->nick)+" "+TypeName);
                                                        std::string HostName = Conf->ReadValue("type","host",j);
-                                                       Srv->ChangeHost(user,HostName);
+                                                       if (HostName != "")
+                                                               Srv->ChangeHost(user,HostName);
                                                        strlcpy(user->oper,TypeName.c_str(),NICKMAX);
                                                        WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,rowresult->GetField("type").c_str());
                                                        WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,rowresult->GetField("type").c_str());
@@ -153,10 +162,10 @@ class ModuleSQLOper : public Module
                                                        {
                                                                strcat(user->modes,"o");
                                                                WriteServ(user->fd,"MODE %s :+o",user->nick);
-                                                               Srv->MeshSendAll("M "+std::string(user->nick)+" +o");
                                                                Module* Logger = Srv->FindModule("m_sqllog.so");
                                                                if (Logger)
-                                                                       Logger->OnOper(user);
+                                                                       Logger->OnOper(user,rowresult->GetField("type"));
+                                                               AddOper(user);
                                                                log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,rowresult->GetField("type").c_str());
                                                        }
                                                        break;
@@ -190,7 +199,6 @@ class ModuleSQLOper : public Module
        virtual ~ModuleSQLOper()
        {
                delete Conf;
-               delete Srv;
        }
        
        virtual Version GetVersion()
@@ -211,9 +219,9 @@ class ModuleSQLOperFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSQLOper;
+               return new ModuleSQLOper(Me);
        }
        
 };