]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqloper.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / extra / m_sqloper.cpp
index 3d9d1bcc47c8b246ec484f24b9cf2a60efd0b622..02ce959f6baf928423fd0b0bf72818b6d4ca8607 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
@@ -49,6 +49,8 @@ public:
                        throw ModuleException("Can't find m_sqlutils.so. Please load m_sqlutils.so before m_sqloper.so.");
 
                OnRehash(NULL,"");
+               Implementation eventlist[] = { I_OnRequest, I_OnRehash, I_OnPreCommand };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
        }
 
        virtual ~ModuleSQLOper()
@@ -58,19 +60,15 @@ public:
                ServerInstance->Modules->DoneWithInterface("HashRequest");
        }
 
-       void Implements(char* List)
-       {
-               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(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"))
                {
@@ -87,7 +85,7 @@ 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;
                
@@ -104,12 +102,13 @@ public:
                         * also hashing it in the module and only passing a remote query containing a hash is more secure.
                         */
 
-                       SQLrequest req = SQLreq(this, target, databaseid, "SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password='?'", username, md5_pass_hash);
+                       SQLrequest req = SQLrequest(this, target, databaseid,
+                                       SQLquery("SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password='?'") % username % md5_pass_hash);
                        
                        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
@@ -140,7 +139,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;
@@ -225,9 +224,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)
                {
@@ -240,7 +239,7 @@ 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(ServerInstance);
                
@@ -260,10 +259,10 @@ public:
                                        user->ChangeDisplayedHost(operhost.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("aeiou", type[0]) ? "an" : "a", irc::Spacify(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);
+                                       user->Oper(type, tname);
 
                                return true;
                        }
@@ -279,4 +278,4 @@ public:
        
 };
 
-MODULE_INIT(ModuleSQLOper);
+MODULE_INIT(ModuleSQLOper)