]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlauth.cpp
Wheeeeee
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlauth.cpp
index 6b05ee521f8907aba943359e541e964ca50cface..e73abe0cc54952815205c7171c3990822563962c 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -40,32 +40,30 @@ public:
        ModuleSQLAuth(InspIRCd* Me)
        : Module::Module(Me)
        {
-               ServerInstance->UseInterface("SQLutils");
-               ServerInstance->UseInterface("SQL");
+               ServerInstance->Modules->UseInterface("SQLutils");
+               ServerInstance->Modules->UseInterface("SQL");
 
-               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_sqlauth.so.");
 
-               SQLprovider = ServerInstance->FindFeature("SQL");
+               SQLprovider = ServerInstance->Modules->FindFeature("SQL");
                if (!SQLprovider)
                        throw ModuleException("Can't find an SQL provider module. Please load one before attempting to load m_sqlauth.");
 
                OnRehash(NULL,"");
+               Implementation eventlist[] = { I_OnUserDisconnect, I_OnCheckReady, I_OnRequest, I_OnRehash, I_OnUserRegister };
+               ServerInstance->Modules->Attach(eventlist, this, 5);
        }
 
        virtual ~ModuleSQLAuth()
        {
-               ServerInstance->DoneWithInterface("SQL");
-               ServerInstance->DoneWithInterface("SQLutils");
+               ServerInstance->Modules->DoneWithInterface("SQL");
+               ServerInstance->Modules->DoneWithInterface("SQLutils");
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnUserDisconnect] = List[I_OnCheckReady] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = 1;
-       }
 
-       virtual void OnRehash(userrec* user, const std::string &parameter)
+       virtual void OnRehash(User* user, const std::string &parameter)
        {
                ConfigReader Conf(ServerInstance);
                
@@ -86,7 +84,7 @@ public:
                }
        }       
 
-       virtual int OnUserRegister(userrec* user)
+       virtual int OnUserRegister(User* user)
        {
                if ((!allowpattern.empty()) && (ServerInstance->MatchText(user->nick,allowpattern)))
                {
@@ -96,20 +94,21 @@ public:
                
                if (!CheckCredentials(user))
                {
-                       userrec::QuitUser(ServerInstance,user,killreason);
+                       User::QuitUser(ServerInstance,user,killreason);
                        return 1;
                }
                return 0;
        }
 
-       bool CheckCredentials(userrec* user)
+       bool CheckCredentials(User* user)
        {
-               SQLrequest req = SQLreq(this, SQLprovider, databaseid, "SELECT ? FROM ? WHERE ? = '?' AND ? = ?'?')", userfield, usertable, userfield, user->nick, passfield, encryption, user->password);
+               SQLrequest req = SQLrequest(this, SQLprovider, databaseid, SQLquery("SELECT ? FROM ? WHERE ? = '?' AND ? = ?'?')") % userfield % usertable % userfield % user->nick %
+                               passfield % encryption % user->password);
                        
                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
@@ -122,18 +121,18 @@ public:
                else
                {
                        if (verbose)
-                               ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, req.error.Str());
+                               ServerInstance->SNO->WriteToSnoMask('A', "Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, req.error.Str());
                        return false;
                }
        }
        
-       virtual char* OnRequest(Request* request)
+       virtual const char* OnRequest(Request* request)
        {
                if(strcmp(SQLRESID, request->GetId()) == 0)
                {
                        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();
                        
                        if(user)
@@ -148,13 +147,13 @@ public:
                                        else if (verbose)
                                        {
                                                /* No rows in result, this means there was no record matching the user */
-                                               ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick, user->ident, user->host);
+                                               ServerInstance->SNO->WriteToSnoMask('A', "Forbidden connection from %s!%s@%s (SQL query returned no matches)", user->nick, user->ident, user->host);
                                                user->Extend("sqlauth_failed");
                                        }
                                }
                                else if (verbose)
                                {
-                                       ServerInstance->WriteOpers("Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str());
+                                       ServerInstance->SNO->WriteToSnoMask('A', "Forbidden connection from %s!%s@%s (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str());
                                        user->Extend("sqlauth_failed");
                                }
                        }
@@ -165,20 +164,20 @@ public:
 
                        if (!user->GetExt("sqlauthed"))
                        {
-                               userrec::QuitUser(ServerInstance,user,killreason);
+                               User::QuitUser(ServerInstance,user,killreason);
                        }
                        return SQLSUCCESS;
                }               
                return NULL;
        }
        
-       virtual void OnUserDisconnect(userrec* user)
+       virtual void OnUserDisconnect(User* user)
        {
                user->Shrink("sqlauthed");
                user->Shrink("sqlauth_failed");         
        }
        
-       virtual bool OnCheckReady(userrec* user)
+       virtual bool OnCheckReady(User* user)
        {
                return user->GetExt("sqlauthed");
        }
@@ -190,5 +189,4 @@ public:
        
 };
 
-MODULE_INIT(ModuleSQLAuth);
-
+MODULE_INIT(ModuleSQLAuth)