]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Annotations
[user/henk/code/inspircd.git] / src / modules.cpp
index fc772c7976951bf6e28ffb3589cf830ff14b4c20..f5e83c0930eee8d28353f3ffae25e7c773fb1c03 100644 (file)
  * ---------------------------------------------------
  */
 
-#include "inspircd_config.h"
-//#include "inspircd.h"
 #include "configreader.h"
-#include <unistd.h>
-#include <sys/errno.h>
-#include <time.h>
-#include <string>
-#include <map>
-#include <sstream>
-#include <vector>
-#include <deque>
 #include "users.h"
-#include "ctables.h"
-#include "globals.h"
 #include "modules.h"
-#include "dynamic.h"
 #include "wildcard.h"
 #include "mode.h"
 #include "xline.h"
-#include "commands.h"
-#include "inspstring.h"
-#include "helperfuncs.h"
-#include "hashcomp.h"
 #include "socket.h"
 #include "socketengine.h"
-#include "typedefs.h"
-#include "modules.h"
 #include "command_parse.h"
 #include "dns.h"
 #include "inspircd.h"
 
-extern time_t TIME;
-extern command_table cmdlist;
-
-class Server;
-
 // version is a simple class for holding a modules version number
-
 Version::Version(int major, int minor, int revision, int build, int flags)
 : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags)
 {
@@ -157,6 +132,7 @@ void                Module::OnLoadModule(Module* mod,const std::string &name) { };
 void           Module::OnUnloadModule(Module* mod,const std::string &name) { };
 void           Module::OnBackgroundTimer(time_t curtime) { };
 int            Module::OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated) { return 0; };
+void           Module::OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result) { };
 bool           Module::OnCheckReady(userrec* user) { return true; };
 void           Module::OnUserRegister(userrec* user) { };
 int            Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason) { return 0; };
@@ -174,7 +150,7 @@ void                Module::OnEvent(Event* event) { return; };
 char*          Module::OnRequest(Request* request) { return NULL; };
 int            Module::OnOperCompare(const std::string &password, const std::string &input) { return 0; };
 void           Module::OnGlobalOper(userrec* user) { };
-void           Module::OnGlobalConnect(userrec* user) { };
+void           Module::OnPostConnect(userrec* user) { };
 int            Module::OnAddBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
 int            Module::OnDelBan(userrec* source, chanrec* channel,const std::string &banmask) { return 0; };
 void           Module::OnRawSocketAccept(int fd, const std::string &ip, int localport) { };
@@ -214,25 +190,8 @@ void               Module::OnChannelDelete(chanrec* chan) { };
 Priority       Module::Prioritize() { return PRIORITY_DONTCARE; }
 void           Module::OnSetAway(userrec* user) { };
 void           Module::OnCancelAway(userrec* user) { };
+int            Module::OnUserList(userrec* user, chanrec* Ptr) { return 0; };
 
-/* server is a wrapper class that provides methods to all of the C-style
- * exports in the core
- */
-
-void InspIRCd::AddSocket(InspSocket* sock)
-{
-       this->module_sockets.push_back(sock);
-}
-
-void InspIRCd::RemoveSocket(InspSocket* sock)
-{
-       for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++)
-       {
-               InspSocket* s = (InspSocket*)*a;
-               if (s == sock)
-                       s->MarkAsClosed();
-       }
-}
 
 long InspIRCd::PriorityAfter(const std::string &modulename)
 {
@@ -308,18 +267,6 @@ void InspIRCd::RehashServer()
        this->Config->Read(false,NULL);
 }
 
-void InspIRCd::DelSocket(InspSocket* sock)
-{
-       for (std::vector<InspSocket*>::iterator a = this->module_sockets.begin(); a < this->module_sockets.end(); a++)
-       {
-               if (*a == sock)
-               {
-                       this->module_sockets.erase(a);
-                       return;
-               }
-       }
-}
-
 /* This is ugly, yes, but hash_map's arent designed to be
  * addressed in this manner, and this is a bit of a kludge.
  * Luckily its a specialist function and rarely used by
@@ -343,11 +290,6 @@ bool InspIRCd::MatchText(const std::string &sliteral, const std::string &spatter
        return match(sliteral.c_str(),spattern.c_str());
 }
 
-bool InspIRCd::IsUlined(const std::string &server)
-{
-       return is_uline(server.c_str());
-}
-
 bool InspIRCd::CallCommandHandler(const std::string &commandname, const char** parameters, int pcnt, userrec* user)
 {
        return this->Parser->CallHandler(commandname,parameters,pcnt,user);
@@ -369,7 +311,7 @@ void InspIRCd::AddCommand(command_t *f)
 
 void InspIRCd::SendMode(const char** parameters, int pcnt, userrec *user)
 {
-       this->ModeGrok->Process(parameters,pcnt,user,true);
+       this->Modes->Process(parameters,pcnt,user,true);
 }
 
 void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstream &TextStream)
@@ -390,22 +332,22 @@ void InspIRCd::DumpText(userrec* User, const std::string &LinePrefix, stringstre
 
 userrec* InspIRCd::FindDescriptor(int socket)
 {
-       return ((socket < MAX_DESCRIPTORS && socket > -1) ? this->fd_ref_table[socket] : NULL);
+       return reinterpret_cast<userrec*>(this->SE->GetRef(socket));
 }
 
 bool InspIRCd::AddMode(ModeHandler* mh, const unsigned char mode)
 {
-       return this->ModeGrok->AddMode(mh,mode);
+       return this->Modes->AddMode(mh,mode);
 }
 
 bool InspIRCd::AddModeWatcher(ModeWatcher* mw)
 {
-       return this->ModeGrok->AddModeWatcher(mw);
+       return this->Modes->AddModeWatcher(mw);
 }
 
 bool InspIRCd::DelModeWatcher(ModeWatcher* mw)
 {
-       return this->ModeGrok->DelModeWatcher(mw);
+       return this->Modes->DelModeWatcher(mw);
 }
 
 bool InspIRCd::AddResolver(Resolver* r)
@@ -415,19 +357,18 @@ bool InspIRCd::AddResolver(Resolver* r)
 
 bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
 {
-       unsigned int old_fd = user->fd;
+       unsigned int old_fd = user->GetFd();
        user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
        user->FlushWriteBuf();
        user->ClearBuffer();
-       user->fd = FD_MAGIC_NUMBER;
+       user->SetFd(FD_MAGIC_NUMBER);
 
        if (find(local_users.begin(),local_users.end(),user) != local_users.end())
        {
                local_users.erase(find(local_users.begin(),local_users.end(),user));
-               log(DEBUG,"Delete local user");
        }
 
-       this->SE->DelFd(old_fd);
+       this->SE->DelFd(user);
        shutdown(old_fd,2);
        close(old_fd);
        return true;
@@ -435,10 +376,9 @@ bool InspIRCd::UserToPseudo(userrec* user, const std::string &message)
 
 bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &message)
 {
-       log(DEBUG,"PseudoToUser");
-       zombie->fd = alive->fd;
+       zombie->SetFd(alive->GetFd());
        FOREACH_MOD_I(this,I_OnUserQuit,OnUserQuit(alive,message));
-       alive->fd = FD_MAGIC_NUMBER;
+       alive->SetFd(FD_MAGIC_NUMBER);
        alive->FlushWriteBuf();
        alive->ClearBuffer();
        // save these for later
@@ -449,10 +389,8 @@ bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &
        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
-       this->fd_ref_table[zombie->fd] = zombie;
        zombie->Write(":%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++)
        {
@@ -469,69 +407,63 @@ bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &
                                zombie->WriteServ("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))
+       if ((find(local_users.begin(),local_users.end(),zombie) == local_users.end()) && (zombie->GetFd() != FD_MAGIC_NUMBER))
                local_users.push_back(zombie);
-
        return true;
 }
 
 void InspIRCd::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);
+       XLines->add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       XLines->apply_lines(APPLY_GLINES);
 }
 
 void InspIRCd::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);
+       XLines->add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
+       XLines->apply_lines(APPLY_QLINES);
 }
 
 void InspIRCd::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);
+       XLines->add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
+       XLines->apply_lines(APPLY_ZLINES);
 }
 
 void InspIRCd::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);
+       XLines->add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       XLines->apply_lines(APPLY_KLINES);
 }
 
 void InspIRCd::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
 {
-       add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+       XLines->add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
 }
 
 bool InspIRCd::DelGLine(const std::string &hostmask)
 {
-       return del_gline(hostmask.c_str());
+       return XLines->del_gline(hostmask.c_str());
 }
 
 bool InspIRCd::DelQLine(const std::string &nickname)
 {
-       return del_qline(nickname.c_str());
+       return XLines->del_qline(nickname.c_str());
 }
 
 bool InspIRCd::DelZLine(const std::string &ipaddr)
 {
-       return del_zline(ipaddr.c_str());
+       return XLines->del_zline(ipaddr.c_str());
 }
 
 bool InspIRCd::DelKLine(const std::string &hostmask)
 {
-       return del_kline(hostmask.c_str());
+       return XLines->del_kline(hostmask.c_str());
 }
 
 bool InspIRCd::DelELine(const std::string &hostmask)
 {
-       return del_eline(hostmask.c_str());
-}
-
-long InspIRCd::CalcDuration(const std::string &delta)
-{
-       return duration(delta.c_str());
+       return XLines->del_eline(hostmask.c_str());
 }
 
 /*