diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_opermotd.cpp | 12 | ||||
-rw-r--r-- | src/modules/m_randquote.cpp | 63 |
3 files changed, 29 insertions, 58 deletions
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index 5ae530608..0659f631c 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -360,12 +360,12 @@ class ModuleSSLGnuTLS : public Module FileReader reader; - reader.LoadFile(certfile); - std::string cert_string = reader.Contents(); + reader.Load(certfile); + std::string cert_string = reader.GetString(); gnutls_datum_t cert_datum = { (unsigned char*)cert_string.data(), static_cast<unsigned int>(cert_string.length()) }; - reader.LoadFile(keyfile); - std::string key_string = reader.Contents(); + reader.Load(keyfile); + std::string key_string = reader.GetString(); gnutls_datum_t key_datum = { (unsigned char*)key_string.data(), static_cast<unsigned int>(key_string.length()) }; // If this fails, no SSL port will work. At all. So, do the smart thing - throw a ModuleException @@ -431,8 +431,8 @@ class ModuleSSLGnuTLS : public Module if (!dhfile.empty()) { // Try to load DH params from file - reader.LoadFile(dhfile); - std::string dhstring = reader.Contents(); + reader.Load(dhfile); + std::string dhstring = reader.GetString(); gnutls_datum_t dh_datum = { (unsigned char*)dhstring.data(), static_cast<unsigned int>(dhstring.length()) }; if ((ret = gnutls_dh_params_import_pkcs3(dh_params, &dh_datum, GNUTLS_X509_FMT_PEM)) < 0) diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp index b228dc8b7..aa5767b4c 100644 --- a/src/modules/m_opermotd.cpp +++ b/src/modules/m_opermotd.cpp @@ -107,9 +107,15 @@ class ModuleOpermotd : public Module ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd"); onoper = conf->getBool("onoper", true); - FileReader f(conf->getString("file", "opermotd")); - for (int i=0, filesize = f.FileSize(); i < filesize; i++) - cmd.opermotd.push_back(f.GetLine(i)); + try + { + FileReader reader(conf->getString("file", "opermotd")); + cmd.opermotd = reader.GetVector(); + } + catch (CoreException&) + { + // Nothing happens here as we do the error handling in ShowOperMOTD. + } if (conf->getBool("processcolors")) InspIRCd::ProcessColors(cmd.opermotd); diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 62d3022cf..8b9ffd6e9 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -25,73 +25,38 @@ #include "inspircd.h" -static FileReader *quotes = NULL; - -std::string prefix; -std::string suffix; - -/** Handle /RANDQUOTE - */ -class CommandRandquote : public Command -{ - public: - CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0) - { - } - - CmdResult Handle (const std::vector<std::string>& parameters, User *user) - { - std::string str; - int fsize; - - fsize = quotes->FileSize(); - str = quotes->GetLine(ServerInstance->GenRandomInt(fsize)); - user->WriteNotice(prefix + str + suffix); - - return CMD_SUCCESS; - } -}; - class ModuleRandQuote : public Module { - CommandRandquote cmd; - public: - ModuleRandQuote() - : cmd(this) - { - } + private: + std::string prefix; + std::string suffix; + std::vector<std::string> quotes; + public: void init() CXX11_OVERRIDE { ConfigTag* conf = ServerInstance->Config->ConfValue("randquote"); - - std::string q_file = conf->getString("file","quotes"); prefix = conf->getString("prefix"); suffix = conf->getString("suffix"); + FileReader reader(conf->getString("file", "quotes")); + quotes = reader.GetVector(); - quotes = new FileReader(q_file); - if (!quotes->Exists()) - { - throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function."); - } - ServerInstance->Modules->AddService(cmd); Implementation eventlist[] = { I_OnUserConnect }; ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } - ~ModuleRandQuote() + void OnUserConnect(LocalUser* user) CXX11_OVERRIDE { - delete quotes; + if (!quotes.empty()) + { + unsigned long random = ServerInstance->GenRandomInt(quotes.size()); + user->WriteNotice(prefix + quotes[random] + suffix); + } } Version GetVersion() CXX11_OVERRIDE { - return Version("Provides random quotes on connect.",VF_VENDOR); - } - - void OnUserConnect(LocalUser* user) CXX11_OVERRIDE - { - cmd.Handle(std::vector<std::string>(), user); + return Version("Provides random quotes on connect.", VF_VENDOR); } }; |