]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Port m_blockcaps to new api, remove OnExtendedMode and OnDisplayList events entirely
[user/henk/code/inspircd.git] / src / modules.cpp
index 680bd950afc37b650afd2a35f922c8abd5f064dc..2c72943ec9cbf078b5798a07adc31ba928721873 100644 (file)
  * ---------------------------------------------------
  */
 
-using namespace std;
-
 #include "inspircd_config.h"
 #include "inspircd.h"
-#include "inspircd_io.h"
+#include "configreader.h"
 #include <unistd.h>
 #include <sys/errno.h>
 #include <time.h>
 #include <string>
-#ifdef GCC3
-#include <ext/hash_map>
-#else
-#include <hash_map>
-#endif
 #include <map>
 #include <sstream>
 #include <vector>
@@ -54,105 +47,19 @@ using namespace std;
 extern ServerConfig *Config;
 extern InspIRCd* ServerInstance;
 extern int MODCOUNT;
-extern std::vector<Module*> modules;
-extern std::vector<ircd_module*> factory;
+extern ModuleList modules;
+extern FactoryList factory;
 extern std::vector<InspSocket*> module_sockets;
 extern std::vector<userrec*> local_users;
 extern time_t TIME;
-class Server;
 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 extern user_hash clientlist;
 extern chan_hash chanlist;
 extern command_table cmdlist;
-ExtModeList EMode;
-
-// returns true if an extended mode character is in use
-bool ModeDefined(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
-bool ModeIsListMode(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
-
-bool ModeDefinedOper(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
-               {
-                       return true;
-               }
-       }
-       return false;
-}
 
-// returns number of parameters for a custom mode when it is switched on
-int ModeDefinedOn(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return i->params_when_on;
-               }
-       }
-       return 0;
-}
-
-// returns number of parameters for a custom mode when it is switched on
-int ModeDefinedOff(char modechar, int type)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == type))
-               {
-                       return i->params_when_off;
-               }
-       }
-       return 0;
-}
-
-// returns true if an extended mode character is in use
-bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
-{
-       if (ModeDefined(modechar,type)) {
-               return false;
-       }
-       EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
-       return true;
-}
+class Server;
 
-// turns a mode into a listmode
-void ModeMakeList(char modechar)
-{
-       for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
-       {
-               if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
-               {
-                       i->list = true;
-                       return;
-               }
-       }
-       return;
-}
+featurelist Features;
 
 // version is a simple class for holding a modules version number
 
@@ -166,7 +73,7 @@ Request::Request(char* anydata, Module* src, Module* dst) : data(anydata), sourc
 
 char* Request::GetData()
 {
-       return this->data;
+       return (char*)this->data;
 }
 
 Module* Request::GetSource()
@@ -195,7 +102,7 @@ Event::Event(char* anydata, Module* src, const std::string &eventid) : data(anyd
 
 char* Event::GetData()
 {
-       return this->data;
+       return (char*)this->data;
 }
 
 Module* Event::GetSource()
@@ -227,7 +134,6 @@ void                Module::OnUserPart(userrec* user, chanrec* channel, const std::string &par
 void           Module::OnRehash(const std::string &parameter) { }
 void           Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
 int            Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
-int            Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params) { return false; }
 void           Module::OnMode(userrec* user, void* dest, int target_type, const std::string &text) { };
 Version                Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
 void           Module::OnOper(userrec* user, const std::string &opertype) { };
@@ -245,7 +151,6 @@ int         Module::OnKill(userrec* source, userrec* dest, const std::string &reason) {
 void           Module::OnLoadModule(Module* mod,const std::string &name) { };
 void           Module::OnUnloadModule(Module* mod,const std::string &name) { };
 void           Module::OnBackgroundTimer(time_t curtime) { };
-void           Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
 int            Module::OnPreCommand(const std::string &command, char **parameters, int pcnt, userrec *user, bool validated) { return 0; };
 bool           Module::OnCheckReady(userrec* user) { return true; };
 void           Module::OnUserRegister(userrec* user) { };
@@ -324,12 +229,12 @@ void Server::AddSocket(InspSocket* sock)
 
 void Server::RemoveSocket(InspSocket* sock)
 {
-        for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
-        {
-                InspSocket* s = (InspSocket*)*a;
-                if (s == sock)
+       for (std::vector<InspSocket*>::iterator a = module_sockets.begin(); a < module_sockets.end(); a++)
+       {
+               InspSocket* s = (InspSocket*)*a;
+               if (s == sock)
                        s->MarkAsClosed();
-        }
+       }
 }
 
 long Server::PriorityAfter(const std::string &modulename)
@@ -356,6 +261,37 @@ long Server::PriorityBefore(const std::string &modulename)
        return PRIORITY_DONTCARE;
 }
 
+bool Server::PublishFeature(const std::string &FeatureName, Module* Mod)
+{
+       if (Features.find(FeatureName) == Features.end())
+       {
+               Features[FeatureName] = Mod;
+               return true;
+       }
+       return false;
+}
+
+bool Server::UnpublishFeature(const std::string &FeatureName)
+{
+       featurelist::iterator iter = Features.find(FeatureName);
+       
+       if (iter == Features.end())
+               return false;
+
+       Features.erase(iter);
+       return true;
+}
+
+Module* Server::FindFeature(const std::string &FeatureName)
+{
+       featurelist::iterator iter = Features.find(FeatureName);
+
+       if (iter == Features.end())
+               return NULL;
+
+       return iter->second;
+}
+
 void Server::RehashServer()
 {
        WriteOpers("*** Rehashing config file");
@@ -499,7 +435,7 @@ void Server::AddCommand(command_t *f)
 
 void Server::SendMode(char **parameters, int pcnt, userrec *user)
 {
-       ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
+       //ServerInstance->ModeGrok->ServerMode(parameters,pcnt,user);
 }
 
 void Server::Send(int Socket, const std::string &s)
@@ -642,45 +578,9 @@ Admin Server::GetAdmin()
 }
 
 
-
-bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
-{
-       if (((modechar >= 'A') && (modechar <= 'Z')) || ((modechar >= 'a') && (modechar <= 'z')))
-       {
-               if (type == MT_SERVER)
-               {
-                       ModuleException e("Modes of type MT_SERVER are reserved for future expansion");
-                       throw(e);
-                       return false;
-               }
-               if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
-               {
-                       ModuleException e("Parameters on MT_CLIENT modes are not supported");
-                       throw(e);
-                       return false;
-               }
-               if ((params_when_on>1) || (params_when_off>1))
-               {
-                       ModuleException e("More than one parameter for an MT_CHANNEL mode is not yet supported");
-                       throw(e);
-                       return false;
-               }
-               return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
-       }
-       else
-       {
-               ModuleException e("Muppet modechar detected.");
-               throw(e);
-       }
-       return false;
-}
-
-bool Server::AddExtendedListMode(char modechar)
+bool Server::AddMode(ModeHandler* mh, const unsigned char mode)
 {
-       bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
-       if (res)
-               ModeMakeList(modechar);
-       return res;
+       return ServerInstance->ModeGrok->AddMode(mh,mode);
 }
 
 int Server::CountUsers(chanrec* c)
@@ -688,7 +588,6 @@ int Server::CountUsers(chanrec* c)
        return usercount(c);
 }
 
-
 bool Server::UserToPseudo(userrec* user, const std::string &message)
 {
        unsigned int old_fd = user->fd;
@@ -704,8 +603,8 @@ bool Server::UserToPseudo(userrec* user, const std::string &message)
        }
 
        ServerInstance->SE->DelFd(old_fd);
-        shutdown(old_fd,2);
-        close(old_fd);
+       shutdown(old_fd,2);
+       close(old_fd);
        return true;
 }
 
@@ -722,29 +621,29 @@ bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &me
        std::string oldhost = alive->host;
        std::string oldident = alive->ident;
        kill_link(alive,message.c_str());
-        if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
-        {
+       if (find(local_users.begin(),local_users.end(),alive) != local_users.end())
+       {
                local_users.erase(find(local_users.begin(),local_users.end(),alive));
                log(DEBUG,"Delete local user");
-        }
+       }
        // Fix by brain - cant write the user until their fd table entry is updated
        fd_ref_table[zombie->fd] = zombie;
        Write(zombie->fd,":%s!%s@%s NICK %s",oldnick.c_str(),oldident.c_str(),oldhost.c_str(),zombie->nick);
-        for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
-        {
-                if (((ucrec*)(*i))->channel != NULL)
-                {
+       for (std::vector<ucrec*>::const_iterator i = zombie->chans.begin(); i != zombie->chans.end(); i++)
+       {
+               if (((ucrec*)(*i))->channel != NULL)
+               {
                                chanrec* Ptr = ((ucrec*)(*i))->channel;
                                WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
-                               if (Ptr->topicset)
-                               {
-                                       WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
-                                       WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
-                               }
-                               userlist(zombie,Ptr);
-                               WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
-                }
-        }
+                               if (Ptr->topicset)
+                               {
+                                       WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
+                                       WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
+                               }
+                               userlist(zombie,Ptr);
+                               WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
+               }
+       }
        if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->fd != FD_MAGIC_NUMBER))
                local_users.push_back(zombie);
 
@@ -754,21 +653,25 @@ bool Server::PseudoToUser(userrec* alive, userrec* zombie, const std::string &me
 void Server::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
 {
        add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       apply_lines(APPLY_GLINES);
 }
 
 void Server::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
 {
        add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
+       apply_lines(APPLY_QLINES);
 }
 
 void Server::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
 {
        add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
+       apply_lines(APPLY_ZLINES);
 }
 
 void Server::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
 {
        add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       apply_lines(APPLY_KLINES);
 }
 
 void Server::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
@@ -806,31 +709,35 @@ long Server::CalcDuration(const std::string &delta)
        return duration(delta.c_str());
 }
 
+/*
+ * XXX why on *earth* is this in modules.cpp...? I think
+ * perhaps we need a server.cpp for Server:: stuff where possible. -- w00t
+ */
 bool Server::IsValidMask(const std::string &mask)
 {
        char* dest = (char*)mask.c_str();
-        if (strchr(dest,'!')==0)
-                return false;
-        if (strchr(dest,'@')==0)
-                return false;
-        for (char* i = dest; *i; i++)
-                if (*i < 32)
-                        return false;
-        for (char* i = dest; *i; i++)
-                if (*i > 126)
-                        return false;
-        unsigned int c = 0;
-        for (char* i = dest; *i; i++)
-                if (*i == '!')
-                        c++;
-        if (c>1)
-                return false;
-        c = 0;
-        for (char* i = dest; *i; i++)
-                if (*i == '@')
-                        c++;
-        if (c>1)
-                return false;
+       if (strchr(dest,'!')==0)
+               return false;
+       if (strchr(dest,'@')==0)
+               return false;
+       for (char* i = dest; *i; i++)
+               if (*i < 32)
+                       return false;
+       for (char* i = dest; *i; i++)
+               if (*i > 126)
+                       return false;
+       unsigned int c = 0;
+       for (char* i = dest; *i; i++)
+               if (*i == '!')
+                       c++;
+       if (c>1)
+               return false;
+       c = 0;
+       for (char* i = dest; *i; i++)
+               if (*i == '@')
+                       c++;
+       if (c>1)
+               return false;
 
        return true;
 }
@@ -872,9 +779,9 @@ ConfigReader::~ConfigReader()
        //~ if (this->cache)
                //~ delete this->cache;
        if (this->errorlog)
-               delete this->errorlog;
+               DELETE(this->errorlog);
        if(this->privatehash)
-               delete this->data;
+               DELETE(this->data);
 }