]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqloper.cpp
/usr/local/include/openssl/pqueue.h:73: error: ISO C++ does not support `long long'
[user/henk/code/inspircd.git] / src / modules / extra / m_sqloper.cpp
index df99a6dc4b9f0a6b07ba7f34cfc4cd2611d3d2bb..53066287072c30d14d0d3b3abbba5cf719eab855 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <string>
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
 #include "configreader.h"
 
 #include "m_sqlv2.h"
 
 class ModuleSQLOper : public Module
 {
-       InspIRCd* Srv;
        Module* SQLutils;
        Module* HashModule;
        std::string databaseid;
 
 public:
        ModuleSQLOper(InspIRCd* Me)
-       : Module::Module(Me), Srv(Me)
+       : Module::Module(Me)
        {
-               ServerInstance->UseInterface("SQLutils");
-               ServerInstance->UseInterface("SQL");
-               ServerInstance->UseInterface("HashRequest");
+               ServerInstance->Modules->UseInterface("SQLutils");
+               ServerInstance->Modules->UseInterface("SQL");
+               ServerInstance->Modules->UseInterface("HashRequest");
 
                /* Attempt to locate the md5 service provider, bail if we can't find it */
-               HashModule = ServerInstance->FindModule("m_md5.so");
+               HashModule = ServerInstance->Modules->Find("m_md5.so");
                if (!HashModule)
                        throw ModuleException("Can't find m_md5.so. Please load m_md5.so before m_sqloper.so.");
 
-               SQLutils = ServerInstance->FindModule("m_sqlutils.so");
+               SQLutils = ServerInstance->Modules->Find("m_sqlutils.so");
                if (!SQLutils)
                        throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so.");
 
@@ -55,9 +53,9 @@ public:
 
        virtual ~ModuleSQLOper()
        {
-               ServerInstance->DoneWithInterface("SQL");
-               ServerInstance->DoneWithInterface("SQLutils");
-               ServerInstance->DoneWithInterface("HashRequest");
+               ServerInstance->Modules->DoneWithInterface("SQL");
+               ServerInstance->Modules->DoneWithInterface("SQLutils");
+               ServerInstance->Modules->DoneWithInterface("HashRequest");
        }
 
        void Implements(char* List)
@@ -65,14 +63,14 @@ public:
                List[I_OnRequest] = List[I_OnRehash] = List[I_OnPreCommand] = 1;
        }
 
-       virtual void OnRehash(userrec* user, const std::string &parameter)
+       virtual void OnRehash(User* user, const std::string &parameter)
        {
-               ConfigReader Conf(Srv);
+               ConfigReader Conf(ServerInstance);
                
                databaseid = Conf.ReadValue("sqloper", "dbid", 0); /* Database ID of a database configured for the service provider module */
        }
 
-       virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
+       virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
        {
                if ((validated) && (command == "OPER"))
                {
@@ -89,11 +87,11 @@ public:
                return 0;
        }
 
-       bool LookupOper(userrec* user, const std::string &username, const std::string &password)
+       bool LookupOper(User* user, const std::string &username, const std::string &password)
        {
                Module* target;
                
-               target = Srv->FindFeature("SQL");
+               target = ServerInstance->Modules->FindFeature("SQL");
 
                if (target)
                {
@@ -111,7 +109,7 @@ public:
                        if (req.Send())
                        {
                                /* When we get the query response from the service provider we will be given an ID to play with,
-                                * just an ID number which is unique to this query. We need a way of associating that ID with a userrec
+                                * just an ID number which is unique to this query. We need a way of associating that ID with a User
                                 * so we insert it into a map mapping the IDs to users.
                                 * Thankfully m_sqlutils provides this, it will associate a ID with a user or channel, and if the user quits it removes the
                                 * association. This means that if the user quits during a query we will just get a failed lookup from m_sqlutils - telling
@@ -142,7 +140,7 @@ public:
                {
                        SQLresult* res = static_cast<SQLresult*>(request);
 
-                       userrec* user = GetAssocUser(this, SQLutils, res->id).S().user;
+                       User* user = GetAssocUser(this, SQLutils, res->id).S().user;
                        UnAssociate(this, SQLutils, res->id).S();
 
                        char* tried_user = NULL;
@@ -227,9 +225,9 @@ public:
                return NULL;
        }
 
-       void LoginFail(userrec* user, const std::string &username, const std::string &pass)
+       void LoginFail(User* user, const std::string &username, const std::string &pass)
        {
-               command_t* oper_command = ServerInstance->Parser->GetHandler("OPER");
+               Command* oper_command = ServerInstance->Parser->GetHandler("OPER");
 
                if (oper_command)
                {
@@ -242,9 +240,9 @@ public:
                }
        }
 
-       bool OperUser(userrec* user, const std::string &username, const std::string &password, const std::string &pattern, const std::string &type)
+       bool OperUser(User* user, const std::string &username, const std::string &password, const std::string &pattern, const std::string &type)
        {
-               ConfigReader Conf(Srv);
+               ConfigReader Conf(ServerInstance);
                
                for (int j = 0; j < Conf.Enumerate("type"); j++)
                {
@@ -261,8 +259,8 @@ public:
                                if (operhost.size())
                                        user->ChangeDisplayedHost(operhost.c_str());
 
-                               Srv->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s", user->nick, user->ident, user->host, type.c_str());
-                               user->WriteServ("381 %s :You are now an IRC operator of type %s", user->nick, type.c_str());
+                               ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s", user->nick, user->ident, user->host, type.c_str());
+                               user->WriteServ("381 %s :You are now %s %s",user->nick, strchr("aeiouAEIOU", type[0]) ? "an" : "a", irc::Spacify(type.c_str()));
 
                                if (!user->modes[UM_OPERATOR])
                                        user->Oper(type);
@@ -281,27 +279,4 @@ public:
        
 };
 
-class ModuleSQLOperFactory : public ModuleFactory
-{
- public:
-       ModuleSQLOperFactory()
-       {
-       }
-       
-       ~ModuleSQLOperFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleSQLOper(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleSQLOperFactory;
-}
-
+MODULE_INIT(ModuleSQLOper)