]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Change command name parameter of OnPostCommand to be a Command*
[user/henk/code/inspircd.git] / src / modules.cpp
index b7ceb072a9801586828435a32240ad199bd6ca21..7f3695adeddb3f4e425a6cf6f01fa114c5db2c80 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 
+#include <fstream>
 #include "inspircd.h"
 #include "xline.h"
 #include "socket.h"
@@ -57,17 +58,6 @@ Version::Version(const std::string &desc, int flags, const std::string& linkdata
 {
 }
 
-Request::Request(Module* src, Module* dst, const char* idstr)
-: id(idstr), source(src), dest(dst)
-{
-}
-
-void Request::Send()
-{
-       if (dest)
-               dest->OnRequest(*this);
-}
-
 Event::Event(Module* src, const std::string &eventid) : source(src), id(eventid) { }
 
 void Event::Send()
@@ -103,8 +93,7 @@ void         Module::OnPostOper(User*, const std::string&, const std::string &) { }
 void           Module::OnInfo(User*) { }
 void           Module::OnWhois(User*, User*) { }
 ModResult      Module::OnUserPreInvite(User*, User*, Channel*, time_t) { return MOD_RES_PASSTHRU; }
-ModResult      Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
-ModResult      Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
+ModResult      Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&, MessageType) { return MOD_RES_PASSTHRU; }
 ModResult      Module::OnUserPreNick(User*, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnUserPostNick(User*, const std::string&) { }
 ModResult      Module::OnPreMode(User*, User*, Channel*, const std::vector<std::string>&) { return MOD_RES_PASSTHRU; }
@@ -114,7 +103,7 @@ void                Module::OnLoadModule(Module*) { }
 void           Module::OnUnloadModule(Module*) { }
 void           Module::OnBackgroundTimer(time_t) { }
 ModResult      Module::OnPreCommand(std::string&, std::vector<std::string>&, LocalUser*, bool, const std::string&) { return MOD_RES_PASSTHRU; }
-void           Module::OnPostCommand(const std::string&, const std::vector<std::string>&, LocalUser*, CmdResult, const std::string&) { }
+void           Module::OnPostCommand(Command*, const std::vector<std::string>&, LocalUser*, CmdResult, const std::string&) { }
 void           Module::OnUserInit(LocalUser*) { }
 ModResult      Module::OnCheckReady(LocalUser*) { return MOD_RES_PASSTHRU; }
 ModResult      Module::OnUserRegister(LocalUser*) { return MOD_RES_PASSTHRU; }
@@ -132,17 +121,10 @@ ModResult Module::OnChangeLocalUserHost(LocalUser*, const std::string&) { return
 ModResult      Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { return MOD_RES_PASSTHRU; }
 ModResult      Module::OnPreTopicChange(User*, Channel*, const std::string&) { return MOD_RES_PASSTHRU; }
 void           Module::OnEvent(Event&) { }
-void           Module::OnRequest(Request&) { }
 ModResult      Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { return MOD_RES_PASSTHRU; }
 void           Module::OnGlobalOper(User*) { }
 void           Module::OnPostConnect(User*) { }
-void           Module::OnStreamSocketAccept(StreamSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { }
-int            Module::OnStreamSocketWrite(StreamSocket*, std::string&) { return -1; }
-void           Module::OnStreamSocketClose(StreamSocket*) { }
-void           Module::OnStreamSocketConnect(StreamSocket*) { }
-int            Module::OnStreamSocketRead(StreamSocket*, std::string&) { return -1; }
-void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&) { }
-void           Module::OnUserNotice(User*, void*, int, const std::string&, char, const CUList&) { }
+void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { }
 void           Module::OnRemoteKill(User*, User*, const std::string&, const std::string&) { }
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { }
 void           Module::OnPostTopicChange(User*, Channel*, const std::string&) { }
@@ -153,7 +135,6 @@ void                Module::OnSyncNetwork(Module*, void*) { }
 void           Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::vector<std::string>&, const std::vector<TranslateType>&) { }
 void           Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { }
 void           Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
-void           Module::OnWallops(User*, const std::string&) { }
 void           Module::OnChangeHost(User*, const std::string&) { }
 void           Module::OnChangeName(User*, const std::string&) { }
 void           Module::OnChangeIdent(User*, const std::string&) { }
@@ -553,12 +534,6 @@ void dynamic_reference_base::resolve()
                value = NULL;
 }
 
-void InspIRCd::SendMode(const std::vector<std::string>& parameters, User *user)
-{
-       this->Modes->Process(parameters, user);
-}
-
-
 void InspIRCd::SendGlobalMode(const std::vector<std::string>& parameters, User *user)
 {
        Modes->Process(parameters, user);
@@ -585,82 +560,45 @@ const std::vector<std::string> ModuleManager::GetAllModuleNames(int filter)
        return retval;
 }
 
-FileReader::FileReader(const std::string &filename)
-{
-       LoadFile(filename);
-}
-
-FileReader::FileReader()
-{
-}
-
-std::string FileReader::Contents()
-{
-       std::string x;
-       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
-       {
-               x.append(*a);
-               x.append("\r\n");
-       }
-       return x;
-}
-
-unsigned long FileReader::ContentSize()
+FileReader::FileReader(const std::string& filename)
 {
-       return this->contentsize;
+       Load(filename);
 }
 
-void FileReader::CalcSize()
+void FileReader::Load(const std::string& filename)
 {
-       unsigned long n = 0;
-       for (file_cache::iterator a = this->fc.begin(); a != this->fc.end(); a++)
-               n += (a->length() + 2);
-       this->contentsize = n;
-}
-
-void FileReader::LoadFile(const std::string &filename)
-{
-       std::map<std::string, file_cache>::iterator file = ServerInstance->Config->Files.find(filename);
-       if (file != ServerInstance->Config->Files.end())
+       // If the file is stored in the file cache then we used that version instead.
+       ConfigFileCache::iterator it = ServerInstance->Config->Files.find(filename);
+       if (it != ServerInstance->Config->Files.end())
        {
-               this->fc = file->second;
+               this->lines = it->second;
        }
        else
        {
-               fc.clear();
-               FILE* f = fopen(filename.c_str(), "r");
-               if (!f)
-                       return;
-               char linebuf[MAXBUF*10];
-               while (fgets(linebuf, sizeof(linebuf), f))
-               {
-                       int len = strlen(linebuf);
-                       if (len)
-                               fc.push_back(std::string(linebuf, len - 1));
-               }
-               fclose(f);
-       }
-       CalcSize();
-}
-
+               lines.clear();
 
-FileReader::~FileReader()
-{
-}
+               std::ifstream stream(filename.c_str());
+               if (!stream.is_open())
+                       throw CoreException(filename + " does not exist or is not readable!");
 
-bool FileReader::Exists()
-{
-       return (!(fc.size() == 0));
-}
+               std::string line;
+               while (std::getline(stream, line))
+               {
+                       lines.push_back(line);
+                       totalSize += line.size() + 2;
+               }
 
-std::string FileReader::GetLine(int x)
-{
-       if ((x<0) || ((unsigned)x>fc.size()))
-               return "";
-       return fc[x];
+               stream.close();
+       }
 }
 
-int FileReader::FileSize()
+std::string FileReader::GetString()
 {
-       return fc.size();
+       std::string buffer;
+       for (file_cache::iterator it = this->lines.begin(); it != this->lines.end(); ++it)
+       {
+               buffer.append(*it);
+               buffer.append("\r\n");
+       }
+       return buffer;
 }