]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_opermodes.cpp
Add sanity checks to the ssl modules so that theres no possibility of an out of range...
[user/henk/code/inspircd.git] / src / modules / m_opermodes.cpp
index dbc34bcb5e6a11449395a5f50ec71824187229b3..fea793c0416b66f24bb6c44e4529b1366adb63a4 100644 (file)
  * ---------------------------------------------------
  */
 
-#include <stdio.h>
-#include <vector>
-#include "users.h"
-#include "channels.h"
 #include "inspircd.h"
-#include "modules.h"
 
 /* $ModDesc: Sets (and unsets) modes on opers when they oper up */
 
@@ -29,7 +24,7 @@ class ModuleModesOnOper : public Module
 
  public:
        ModuleModesOnOper(InspIRCd* Me)
-               : Module::Module(Me)
+               : Module(Me)
        {
                
                Conf = new ConfigReader(ServerInstance);
@@ -67,14 +62,14 @@ class ModuleModesOnOper : public Module
                        if (!strcmp(typen.c_str(),user->oper))
                        {
                                std::string ThisOpersModes = Conf->ReadValue("type","modes",j);
-                               char first = *(ThisOpersModes.c_str());
-                               if ((first != '+') && (first != '-'))
-                                       ThisOpersModes = "+" + ThisOpersModes;
-                               if (ThisOpersModes != "")
+                               if (!ThisOpersModes.empty())
                                {
+                                       char first = *(ThisOpersModes.c_str());
+                                       if ((first != '+') && (first != '-'))
+                                               ThisOpersModes = "+" + ThisOpersModes;
+
                                        std::string buf;
                                        stringstream ss(ThisOpersModes);
-
                                        vector<string> tokens;
 
                                        // split ThisOperModes into modes and mode params
@@ -82,32 +77,25 @@ class ModuleModesOnOper : public Module
                                                tokens.push_back(buf);
 
                                        int size = tokens.size() + 1;
-                                       const char* modes[size];
+                                       const char** modes = new const char*[size];
                                        modes[0] = user->nick;
-                                       modes[1] = (char*)tokens[0].c_str();
 
-                                       if (tokens.size() > 1)
+                                       // process mode params
+                                       int i = 1;
+                                       for (unsigned int k = 0; k < tokens.size(); k++)
                                        {
-                                               // process mode params
-                                               int i = 2;
-                                               for (unsigned int k = 1; k < tokens.size(); k++)
-                                               {
-                                                       modes[i] = (char*)tokens[k].c_str();
-                                                       ServerInstance->Log(DEBUG, "m_opermodes.so: got mode param: %s", modes[i]);
-                                                       i++;
-                                               }
+                                               modes[i] = tokens[k].c_str();
+                                               i++;
                                        }
+
                                        std::deque<std::string> n;
-                                       Event rmode((char *)&n, NULL, "send_mode");
-                                       n.push_back(user->nick);
-                                       n.push_back(modes[0]);
-                                       for (unsigned int j = 1; j < tokens.size(); j++)
-                                       {
+                                       Event rmode((char *)&n, NULL, "send_mode_explicit");
+                                       for (unsigned int j = 0; j < tokens.size(); j++)
                                                n.push_back(modes[j]);
-                                       }
+
                                        rmode.Send(ServerInstance);
-                                       ServerInstance->Log(DEBUG, "m_opermodes.so: new modes for %s: %s", modes[0], modes[1]);
                                        ServerInstance->SendMode(modes, size, user);
+                                       delete [] modes;
                                }
                                break;
                        }
@@ -115,29 +103,4 @@ class ModuleModesOnOper : public Module
        }
 };
 
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
-
-class ModuleModesOnOperFactory : public ModuleFactory
-{
- public:
-       ModuleModesOnOperFactory()
-       {
-       }
-       
-       ~ModuleModesOnOperFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleModesOnOper(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleModesOnOperFactory;
-}
-
+MODULE_INIT(ModuleModesOnOper)