]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Added IOHookModule stuff to allow for different modules to hook different ports
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 64a55ecd25cec6c101ea656c2d0140f8530951ad..c370c7f842d462f0fa6610dcbfc35f4f3e33c3a6 100644 (file)
@@ -37,7 +37,6 @@ using namespace std;
 #include <sstream>
 #include <vector>
 #include <deque>
-#include <sched.h>
 #ifdef THREADED_DNS
 #include <pthread.h>
 #endif
@@ -58,7 +57,6 @@ using namespace std;
 #include "socketengine.h"
 #include "userprocess.h"
 #include "socket.h"
-#include "dns.h"
 #include "typedefs.h"
 #include "command_parse.h"
 
@@ -76,7 +74,6 @@ extern int MODCOUNT;
 int openSockfd[MAXSOCKS];
 sockaddr_in client,server;
 socklen_t length;
-extern Module* IOHookModule;
 
 extern InspSocket* socket_ref[65535];
 
@@ -89,14 +86,12 @@ SocketEngine* SE = NULL;
 // by an integer, meaning there is no need for a scan/search operation.
 userrec* fd_ref_table[65536];
 
-serverstats* stats = new serverstats;
 Server* MyServer = new Server;
 ServerConfig *Config = new ServerConfig;
 
 user_hash clientlist;
 chan_hash chanlist;
 whowas_hash whowas;
-command_table cmdlist;
 servernamelist servernames;
 char lowermap[255];
 
@@ -139,7 +134,19 @@ std::string InspIRCd::GetRevision()
        return single;
 }
 
-
+void InspIRCd::MakeLowerMap()
+{
+       // initialize the lowercase mapping table
+       for (unsigned int cn = 0; cn < 256; cn++)
+               lowermap[cn] = cn;
+       // lowercase the uppercase chars
+       for (unsigned int cn = 65; cn < 91; cn++)
+               lowermap[cn] = tolower(cn);
+       // now replace the specific chars for scandanavian comparison
+       lowermap[(unsigned)'['] = '{';
+       lowermap[(unsigned)']'] = '}';
+       lowermap[(unsigned)'\\'] = '|';
+}
 
 InspIRCd::InspIRCd(int argc, char** argv)
 {
@@ -171,24 +178,16 @@ InspIRCd::InspIRCd(int argc, char** argv)
        }
 
        strlcpy(Config->MyExecutable,argv[0],MAXBUF);
-       
-       // initialize the lowercase mapping table
-       for (unsigned int cn = 0; cn < 256; cn++)
-               lowermap[cn] = cn;
-       // lowercase the uppercase chars
-       for (unsigned int cn = 65; cn < 91; cn++)
-               lowermap[cn] = tolower(cn);
-       // now replace the specific chars for scandanavian comparison
-       lowermap[(unsigned)'['] = '{';
-       lowermap[(unsigned)']'] = '}';
-       lowermap[(unsigned)'\\'] = '|';
 
+       this->MakeLowerMap();
 
         OpenLog(argv, argc);
         Config->ClearStack();
         Config->Read(true,NULL);
         CheckRoot();
-        SetupCommandTable();
+       this->ModeGrok = new ModeParser();
+       this->Parser = new CommandParser();
+       this->stats = new serverstats();
         AddServerName(Config->ServerName);
         CheckDie();
         stats->BoundPortCount = BindPorts();
@@ -209,9 +208,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
         SE = new SocketEngine();
 
         /* We must load the modules AFTER initializing the socket engine, now */
-        LoadAllModules();
-
-        printf("\nInspIRCd is now running!\n");
 
        return;
 }
@@ -304,7 +300,7 @@ bool InspIRCd::UnloadModule(const char* filename)
                        log(DEBUG,"Erasing module entry...");
                        erase_factory(j);
                         log(DEBUG,"Removing dependent commands...");
-                        remove_commands(filename);
+                        Parser->RemoveCommands(filename);
                        log(DEFAULT,"Module %s unloaded",filename);
                        MODCOUNT--;
                        return true;
@@ -395,8 +391,14 @@ int InspIRCd::Run()
        char* target;
        unsigned int numberactive;
         sockaddr_in sock_us;     // our port number
-        socklen_t uslen;         // length of our port number
+       socklen_t uslen;         // length of our port number
 
+       /* Until THIS point, ServerInstance == NULL */
+       
+        LoadAllModules(this);
+
+        printf("\nInspIRCd is now running!\n");
+       
        if (!Config->nofork)
        {
                freopen("/dev/null","w",stdout);
@@ -525,9 +527,9 @@ int InspIRCd::Run()
                                                 */
                                                if (incomingSockfd >= 0)
                                                {
-                                                       if (IOHookModule)
+                                                       if (Config->GetIOHook(in_port))
                                                        {
-                                                               IOHookModule->OnRawSocketAccept(incomingSockfd, target, in_port);
+                                                               Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port);
                                                        }
                                                        stats->statsAccept++;
                                                        AddClient(incomingSockfd, target, in_port, false, target);