]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqloper.cpp
Extra checks to not set the ssl marker twice on re-handshake (nonfatal but wasteful)
[user/henk/code/inspircd.git] / src / modules / extra / m_sqloper.cpp
index 714374769091c495cc4c1a1fcdf5488889e14146..b4d8520cb74790fc338d9c0a45d91003edeab1b7 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>
@@ -34,9 +34,16 @@ using namespace std;
 #include "inspircd.h"
 #include "helperfuncs.h"
 #include "m_sql.h"
+#include "cmd_oper.h"
 
 /* $ModDesc: Allows storage of oper credentials in an SQL table */
 
+/* Required for the FOREACH_MOD alias (OnOper event) */
+extern int MODCOUNT;
+extern ServerConfig* Config;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
+
 Server *Srv;
 
 class ModuleSQLOper : public Module
@@ -55,23 +62,29 @@ 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();
        }
 
-       virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user)
+       void Implements(char* List)
        {
-               if (command == "OPER")
+               List[I_OnRehash] = List[I_OnPreCommand] = 1;
+       }
+
+       virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user, bool validated)
+       {
+               if ((command == "OPER") && (validated))
                {
                        if (LookupOper(parameters[0],parameters[1],user))
                                return 1;
@@ -139,34 +152,40 @@ class ModuleSQLOper : public Module
                                {
                                        found = true;
                                        // oper up the user.
-                                       for (int j =0; j < Conf->Enumerate("type"); j++)
-                                       {
-                                               std::string TypeName = Conf->ReadValue("type","name",j);
+                                       
+                                       for (int j =0; j < Conf->Enumerate("type"); j++)
+                                       {
+                                               std::string TypeName = Conf->ReadValue("type","name",j);
+                                               Srv->Log(DEBUG,"Scanning opertype: "+TypeName);
                                                std::string pattern = std::string(user->ident) + "@" + std::string(user->host);
-                                               if ((TypeName == rowresult->GetField("type")) && (Srv->MatchText(pattern,rowresult->GetField("hostname"))));
-                                               {
-                                                       /* found this oper's opertype */
+                                                       
+                                               if((TypeName == rowresult->GetField("type")) && OneOfMatches(pattern.c_str(), rowresult->GetField("hostname").c_str()))
+                                               {
+                                                       /* found this oper's opertype */
+                                                       Srv->Log(DEBUG,"Host and type match: "+TypeName+" "+rowresult->GetField("type"));
                                                        std::string HostName = Conf->ReadValue("type","host",j);
-                                                       if (HostName != "")
-                                                               Srv->ChangeHost(user,HostName);
-                                                       strlcpy(user->oper,TypeName.c_str(),NICKMAX);
+                                                       
+                                                       if(HostName != "")
+                                                               Srv->ChangeHost(user,HostName);
+                                                               
+                                                       strlcpy(user->oper,rowresult->GetField("type").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());
-                                                       if (!strchr(user->modes,'o'))
-                                                       {
-                                                               strcat(user->modes,"o");
-                                                               WriteServ(user->fd,"MODE %s :+o",user->nick);
-                                                               Module* Logger = Srv->FindModule("m_sqllog.so");
-                                                               if (Logger)
-                                                                       Logger->OnOper(user,rowresult->GetField("type"));
+                                                       if(!strchr(user->modes,'o'))
+                                                       {
+                                                               strcat(user->modes,"o");
+                                                               WriteServ(user->fd,"MODE %s :+o",user->nick);
+                                                               FOREACH_MOD(I_OnOper,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;
-                                               }
-                                       }
-
+                                                               FOREACH_MOD(I_OnPostOper,OnPostOper(user,rowresult->GetField("type")));
+                                                               log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,rowresult->GetField("type").c_str());
+                                                       }
+                                                               
+                                                       break;
+                                               }
+                                       }
                                }
+                               
                                delete rowresult;
                        }
                        else
@@ -174,6 +193,7 @@ class ModuleSQLOper : public Module
                                // we didn't have a row.
                                found = false;
                        }
+                       
                        delete rowrequest;
                        delete result;
                }
@@ -193,7 +213,6 @@ class ModuleSQLOper : public Module
        virtual ~ModuleSQLOper()
        {
                delete Conf;
-               delete Srv;
        }
        
        virtual Version GetVersion()
@@ -214,9 +233,9 @@ class ModuleSQLOperFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleSQLOper;
+               return new ModuleSQLOper(Me);
        }
        
 };