]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Added support for <options customversion> to customize the second part of VERSION
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 993348aff092c2686df37145d4aac306d4b97099..b7324a167ec4ae5876f018747c5f9df961f38c47 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -76,16 +76,14 @@ int openSockfd[MAXSOCKS];
 sockaddr_in client,server;
 socklen_t length;
 
-extern InspSocket* socket_ref[65535];
+extern InspSocket* socket_ref[MAX_DESCRIPTORS];
 
 time_t TIME = time(NULL), OLDTIME = time(NULL);
 
-SocketEngine* SE = NULL;
-
 // This table references users by file descriptor.
 // its an array to make it VERY fast, as all lookups are referenced
 // by an integer, meaning there is no need for a scan/search operation.
-userrec* fd_ref_table[65536];
+userrec* fd_ref_table[MAX_DESCRIPTORS];
 
 Server* MyServer = new Server;
 ServerConfig *Config = new ServerConfig;
@@ -227,7 +225,14 @@ std::string InspIRCd::GetVersionString()
 #else
        char dnsengine[] = "singlethread";
 #endif
-       snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,GetRevision().c_str(),Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
+       if (*Config->CustomVersion)
+       {
+               snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s",VERSION,GetRevision().c_str(),Config->ServerName,Config->CustomVersion);
+       }
+       else
+       {
+               snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,GetRevision().c_str(),Config->ServerName,SYSTEM,(unsigned long)OPTIMISATION,SE->GetName().c_str(),dnsengine);
+       }
        return versiondata;
 }
 
@@ -278,6 +283,73 @@ void InspIRCd::erase_module(int j)
 
 }
 
+void InspIRCd::MoveTo(std::string modulename,int slot)
+{
+       unsigned int v2 = 256;
+       log(DEBUG,"Moving %s to slot %d",modulename.c_str(),slot);
+       for (unsigned int v = 0; v < Config->module_names.size(); v++)
+       {
+               if (Config->module_names[v] == modulename)
+               {
+                       // found an instance, swap it with the item at MODCOUNT
+                       v2 = v;
+                       break;
+               }
+       }
+       if (v2 == (unsigned int)slot)
+       {
+               log(DEBUG,"Item %s already in slot %d!",modulename.c_str(),slot);
+       }
+       else if (v2 < 256)
+       {
+               // Swap the module names over
+               Config->module_names[v2] = Config->module_names[slot];
+               Config->module_names[slot] = modulename;
+               // now swap the module factories
+               ircd_module* temp = factory[v2];
+               factory[v2] = factory[slot];
+               factory[slot] = temp;
+               // now swap the module objects
+               Module* temp_module = modules[v2];
+               modules[v2] = modules[slot];
+               modules[slot] = temp_module;
+               // now swap the implement lists (we dont
+               // need to swap the global or recount it)
+               for (int n = 0; n < 255; n++)
+               {
+                       char x = Config->implement_lists[v2][n];
+                       Config->implement_lists[v2][n] = Config->implement_lists[slot][n];
+                       Config->implement_lists[slot][n] = x;
+               }
+               log(DEBUG,"Moved %s to slot successfully",modulename.c_str());
+       }
+       else
+       {
+               log(DEBUG,"Move of %s to slot failed!",modulename.c_str());
+       }
+}
+
+void InspIRCd::MoveToFirst(std::string modulename)
+{
+       MoveTo(modulename,0);
+}
+
+void InspIRCd::MoveToLast(std::string modulename)
+{
+       MoveTo(modulename,MODCOUNT);
+}
+
+void InspIRCd::BuildISupport()
+{
+        // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
+       std::stringstream v;
+       v << "WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS << " MAXBANS=60 NICKLEN=" << NICKMAX;
+       v << " CASEMAPPING=rfc1459 STATUSMSG=@+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=20 AWAYLEN=";
+       v << MAXAWAY << " CHANMODES=ohvb,k,l,psmnti NETWORK=" << Config->Network;
+       Config->data005 = v.str();
+       FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
+}
+
 bool InspIRCd::UnloadModule(const char* filename)
 {
        std::string filename_str = filename;
@@ -306,6 +378,16 @@ bool InspIRCd::UnloadModule(const char* filename)
                                Config->global_implementation[t] -= Config->implement_lists[j][t];
                        }
 
+                       /* We have to renumber implement_lists after unload because the module numbers change!
+                        */
+                       for(int j2 = j; j2 < 254; j2++)
+                       {
+                               for(int t = 0; t < 255; t++)
+                               {
+                                       Config->implement_lists[j2][t] = Config->implement_lists[j2+1][t];
+                               }
+                       }
+
                        FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(modules[j],Config->module_names[j]));
                        // found the module
                        log(DEBUG,"Deleting module...");
@@ -316,6 +398,7 @@ bool InspIRCd::UnloadModule(const char* filename)
                         Parser->RemoveCommands(filename);
                        log(DEFAULT,"Module %s unloaded",filename);
                        MODCOUNT--;
+                       BuildISupport();
                        return true;
                }
        }
@@ -328,7 +411,7 @@ bool InspIRCd::LoadModule(const char* filename)
 {
        char modfile[MAXBUF];
 #ifdef STATIC_LINK
-       snprintf(modfile,MAXBUF,"%s",filename);
+       strlcpy(modfile,filename,MAXBUF);
 #else
        snprintf(modfile,MAXBUF,"%s/%s",Config->ModPath,filename);
 #endif
@@ -404,13 +487,37 @@ bool InspIRCd::LoadModule(const char* filename)
 #endif
        MODCOUNT++;
        FOREACH_MOD(I_OnLoadModule,OnLoadModule(modules[MODCOUNT],filename_str));
+       // now work out which modules, if any, want to move to the back of the queue,
+       // and if they do, move them there.
+       std::vector<std::string> put_to_back;
+       std::vector<std::string> put_to_front;
+       for (unsigned int j = 0; j < Config->module_names.size(); j++)
+       {
+               if (modules[j]->Prioritize() == PRIORITY_LAST)
+               {
+                       put_to_back.push_back(Config->module_names[j]);
+               }
+               else if (modules[j]->Prioritize() == PRIORITY_FIRST)
+               {
+                       put_to_front.push_back(Config->module_names[j]);
+               }
+       }
+       for (unsigned int j = 0; j < put_to_back.size(); j++)
+       {
+               MoveToLast(put_to_back[j]);
+       }
+       for (unsigned int j = 0; j < put_to_front.size(); j++)
+       {
+               MoveToFirst(put_to_front[j]);
+       }
+       BuildISupport();
        return true;
 }
 
 int InspIRCd::Run()
 {
        bool expire_run = false;
-       int activefds[65535];
+       int activefds[MAX_DESCRIPTORS];
        int incomingSockfd;
        int in_port;
        userrec* cu = NULL;
@@ -468,7 +575,7 @@ int InspIRCd::Run()
                }
                
                /* Once a second, do the background processing */
-               if ((TIME != OLDTIME) && ((TIME % 2) == 0))
+               if (TIME != OLDTIME)
                        DoBackgroundUserStuff(TIME);
 
                /* Call the socket engine to wait on the active
@@ -476,13 +583,9 @@ int InspIRCd::Run()
                 * descriptors in its list... dns, modules, users,
                 * servers... so its nice and easy, just one call.
                 */
-               numberactive = SE->Wait(activefds);
-
-               if (!numberactive)
+               if (!(numberactive = SE->Wait(activefds)))
                        continue;
 
-               log(DEBUG,"%d active fds this time around",numberactive);
-
                /**
                 * Now process each of the fd's. For users, we have a fast
                 * lookup table which can find a user by file descriptor, so
@@ -550,7 +653,8 @@ int InspIRCd::Run()
                                        uslen = sizeof(sock_us);
                                        length = sizeof(client);
                                        incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
-                                       if (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen))
+                                       
+                                       if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
                                        {
                                                in_port = ntohs(sock_us.sin_port);
                                                log(DEBUG,"Accepted socket %d",incomingSockfd);
@@ -559,29 +663,21 @@ int InspIRCd::Run()
                                                 * using gethostbyaddr(). That is sucky and we
                                                 * don't do that any more...
                                                 */
-                                               if (incomingSockfd >= 0)
-                                               {
-                                                       NonBlocking(incomingSockfd);
-                                                       if (Config->GetIOHook(in_port))
-                                                       {
-                                                               Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port);
-                                                       }
-                                                       stats->statsAccept++;
-                                                       AddClient(incomingSockfd, target, in_port, false, target);
-                                                       log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
-                                               }
-                                               else
+                                               NonBlocking(incomingSockfd);
+                                               if (Config->GetIOHook(in_port))
                                                {
-                                                       WriteOpers("*** WARNING: accept() failed on port %lu (%s)",(unsigned long)in_port,target);
-                                                       log(DEBUG,"accept failed: %lu",(unsigned long)in_port);
-                                                       stats->statsRefused++;
+                                                       Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, target, in_port);
                                                }
+                                               stats->statsAccept++;
+                                               AddClient(incomingSockfd, target, in_port, false, target);
+                                               log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
                                        }
                                        else
                                        {
-                                               log(DEBUG,"Couldnt look up the port number for fd %lu (OS BROKEN?!)",incomingSockfd);
+                                               log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
                                                shutdown(incomingSockfd,2);
                                                close(incomingSockfd);
+                                               stats->statsRefused++;
                                        }
                                break;