diff options
-rw-r--r-- | data/example.conf | 4 | ||||
-rw-r--r-- | include/bots.h | 2 | ||||
-rw-r--r-- | include/commands.h | 4 | ||||
-rw-r--r-- | modules/core/cs_list.cpp | 2 | ||||
-rw-r--r-- | modules/core/cs_saset.cpp | 2 | ||||
-rw-r--r-- | modules/core/cs_set.cpp | 2 | ||||
-rw-r--r-- | modules/core/ns_list.cpp | 2 | ||||
-rw-r--r-- | modules/core/ns_saset.cpp | 2 | ||||
-rw-r--r-- | modules/core/ns_set.cpp | 2 | ||||
-rw-r--r-- | modules/extra/db_mysql_live.cpp | 81 | ||||
-rw-r--r-- | modules/extra/m_async_commands.cpp | 49 | ||||
-rw-r--r-- | modules/extra/m_xmlrpc_main.cpp | 2 | ||||
-rw-r--r-- | modules/protocol/inspircd11.cpp | 6 | ||||
-rw-r--r-- | modules/protocol/inspircd12.cpp | 6 | ||||
-rw-r--r-- | modules/protocol/inspircd20.cpp | 6 | ||||
-rw-r--r-- | src/bots.cpp | 5 | ||||
-rw-r--r-- | src/botserv.cpp | 2 | ||||
-rw-r--r-- | src/commands.cpp | 17 | ||||
-rw-r--r-- | src/language.cpp | 2 | ||||
-rw-r--r-- | src/protocol.cpp | 8 |
20 files changed, 80 insertions, 126 deletions
diff --git a/data/example.conf b/data/example.conf index 3eb1c0125..4d5361b9e 100644 --- a/data/example.conf +++ b/data/example.conf @@ -290,8 +290,8 @@ options * For information on how to make db_mysql_live use asynchronous queries see * m_async_commands. * - * At this time db_mysql_live only supports pulling data in real time from the four - * main tables: anope_bs_core, anope_cs_info, anope_ns_alias, and anope_ns_core. + * At this time db_mysql_live only supports pulling data in real time from the three + * main tables: anope_cs_info, anope_ns_alias, and anope_ns_core. * */ database = "db_plain" diff --git a/include/bots.h b/include/bots.h index 2ae6fdbc0..4253802ff 100644 --- a/include/bots.h +++ b/include/bots.h @@ -51,8 +51,6 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END> */ virtual ~BotInfo(); - void SetIdent(const Anope::string &sident); - /** Change the nickname for the bot. * @param newnick The nick to change to */ diff --git a/include/commands.h b/include/commands.h index 8320c531a..89735211c 100644 --- a/include/commands.h +++ b/include/commands.h @@ -30,8 +30,8 @@ enum CommandReturn extern CoreExport Command *FindCommand(BotInfo *bi, const Anope::string &cmd); extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cmd); -extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &message, ChannelInfo *ci); -extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, ChannelInfo *ci); +extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &message); +extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope::string &command, const Anope::string &message); enum CommandFlag { diff --git a/modules/core/cs_list.cpp b/modules/core/cs_list.cpp index a330b5edd..4f1a95952 100644 --- a/modules/core/cs_list.cpp +++ b/modules/core/cs_list.cpp @@ -37,7 +37,7 @@ class CommandCSList : public Command if (Config->CSListOpersOnly && !u->HasMode(UMODE_OPER)) { source.Reply(LanguageString::ACCESS_DENIED); - return MOD_STOP; + return MOD_CONT; } if (pattern[0] == '#') diff --git a/modules/core/cs_saset.cpp b/modules/core/cs_saset.cpp index 50a6f0bc9..876a487a3 100644 --- a/modules/core/cs_saset.cpp +++ b/modules/core/cs_saset.cpp @@ -55,7 +55,7 @@ class CommandCSSASet : public Command for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; Log(LOG_ADMIN, u, this, ci) << params[1] << " " << cmdparams; - mod_run_cmd(ChanServ, u, c, params[1], cmdparams, false); + mod_run_cmd(ChanServ, u, NULL, c, params[1], cmdparams); } else { diff --git a/modules/core/cs_set.cpp b/modules/core/cs_set.cpp index 55817d219..e089d4a2a 100644 --- a/modules/core/cs_set.cpp +++ b/modules/core/cs_set.cpp @@ -59,7 +59,7 @@ class CommandCSSet : public Command Anope::string cmdparams = ci->name; for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; - mod_run_cmd(ChanServ, u, c, params[1], cmdparams, false); + mod_run_cmd(ChanServ, u, NULL, c, params[1], cmdparams); } else { diff --git a/modules/core/ns_list.cpp b/modules/core/ns_list.cpp index 7350a471c..9d49ce2f5 100644 --- a/modules/core/ns_list.cpp +++ b/modules/core/ns_list.cpp @@ -53,7 +53,7 @@ class CommandNSList : public Command if (Config->NSListOpersOnly && !u->HasMode(UMODE_OPER)) /* reverse the help logic */ { source.Reply(LanguageString::ACCESS_DENIED); - return MOD_STOP; + return MOD_CONT; } if (pattern[0] == '#') diff --git a/modules/core/ns_saset.cpp b/modules/core/ns_saset.cpp index 0aeab4d95..993a090fc 100644 --- a/modules/core/ns_saset.cpp +++ b/modules/core/ns_saset.cpp @@ -62,7 +62,7 @@ class CommandNSSASet : public Command Log(LOG_ADMIN, u, this) << params[1] << " " << cmdparams; else Log(LOG_ADMIN, u, this) << params[1] << " for " << params[0]; - mod_run_cmd(NickServ, u, c, params[1], cmdparams, false); + mod_run_cmd(NickServ, u, NULL, c, params[1], cmdparams); } else source.Reply(_("Unknown SASET option \002%s\002."), cmd.c_str()); diff --git a/modules/core/ns_set.cpp b/modules/core/ns_set.cpp index 3bd9a0eae..86272c084 100644 --- a/modules/core/ns_set.cpp +++ b/modules/core/ns_set.cpp @@ -57,7 +57,7 @@ class CommandNSSet : public Command Log(LOG_COMMAND, u, this) << params[0] << " " << cmdparams; else Log(LOG_COMMAND, u, this) << params[0]; - mod_run_cmd(NickServ, u, c, params[0], cmdparams, false); + mod_run_cmd(NickServ, u, NULL, c, params[0], cmdparams); } else source.Reply(LanguageString::NICK_SET_UNKNOWN_OPTION, params[0].c_str()); diff --git a/modules/extra/db_mysql_live.cpp b/modules/extra/db_mysql_live.cpp index c5e645be6..30e5a93c7 100644 --- a/modules/extra/db_mysql_live.cpp +++ b/modules/extra/db_mysql_live.cpp @@ -33,43 +33,6 @@ class SQLCache : public Timer } }; -class BotInfoUpdater : public SQLInterface, public SQLCache -{ - public: - BotInfoUpdater(Module *m) : SQLInterface(m) { } - - void OnResult(const SQLResult &r) - { - BotInfoUpdater::Process(r); - } - - static void Process(const SQLResult &res) - { - try - { - BotInfo *bi = findbot(res.Get(0, "nick")); - if (!bi) - bi = new BotInfo(res.Get(0, "nick"), res.Get(0, "user"), res.Get(0, "host"), res.Get(0, "rname")); - else - { - bi->SetIdent(res.Get(0, "user")); - bi->host = res.Get(0, "host"); - bi->realname = res.Get(0, "rname"); - } - - if (res.Get(0, "flags").equals_cs("PRIVATE")) - bi->SetFlag(BI_PRIVATE); - bi->created = convertTo<time_t>(res.Get(0, "created")); - bi->chancount = convertTo<uint32>(res.Get(0, "chancount")); - } - catch (const SQLException &ex) - { - Log(LOG_DEBUG) << ex.GetReason(); - } - catch (const ConvertException &) { } - } -}; - class ChanInfoUpdater : public SQLInterface, public SQLCache { public: @@ -242,7 +205,6 @@ class MySQLLiveModule : public Module service_reference<SQLProvider> SQL; service_reference<AsynchCommandsService> ACS; - BotInfoUpdater botinfoupdater; ChanInfoUpdater chaninfoupdater; NickInfoUpdater nickinfoupdater; NickCoreUpdater nickcoreupdater; @@ -280,53 +242,20 @@ class MySQLLiveModule : public Module public: MySQLLiveModule(const Anope::string &modname, const Anope::string &creator) : - Module(modname, creator), SQL("mysql/main"), ACS("asynch_commands"), botinfoupdater(this), + Module(modname, creator), SQL("mysql/main"), ACS("asynch_commands"), chaninfoupdater(this), nickinfoupdater(this), nickcoreupdater(this) { - Implementation i[] = { I_OnFindBot, I_OnFindChan, I_OnFindNick, I_OnFindCore, I_OnPreShutdown }; - ModuleManager::Attach(i, this, 5); + Implementation i[] = { I_OnFindChan, I_OnFindNick, I_OnFindCore, I_OnPreShutdown }; + ModuleManager::Attach(i, this, 4); } void OnPreShutdown() { - Implementation i[] = { I_OnFindBot, I_OnFindChan, I_OnFindNick, I_OnFindCore }; - for (size_t j = 0; j < 4; ++j) + Implementation i[] = { I_OnFindChan, I_OnFindNick, I_OnFindCore }; + for (size_t j = 0; j < 3; ++j) ModuleManager::Detach(i[j], this); } - void OnFindBot(const Anope::string &nick) - { - if (botinfoupdater.Check(nick)) - return; - - try - { - Anope::string query = "SELECT * FROM `anope_bs_core` WHERE `nick` = '" + this->Escape(nick) + "'"; - CommandMutex *current_command = this->CurrentCommand(); - if (current_command) - { - current_command->Unlock(); - try - { - SQLResult res = this->RunQuery(query); - current_command->Lock(); - BotInfoUpdater::Process(res); - } - catch (const SQLException &ex) - { - current_command->Lock(); - throw; - } - } - else - this->RunQuery(&botinfoupdater, query); - } - catch (const SQLException &ex) - { - Log(LOG_DEBUG) << "OnBotChan: " << ex.GetReason(); - } - } - void OnFindChan(const Anope::string &chname) { if (chaninfoupdater.Check(chname)) diff --git a/modules/extra/m_async_commands.cpp b/modules/extra/m_async_commands.cpp index 4f251431c..b97be4788 100644 --- a/modules/extra/m_async_commands.cpp +++ b/modules/extra/m_async_commands.cpp @@ -1,6 +1,7 @@ #include "module.h" #include "async_commands.h" +static bool ignore_pre_command = false; static Pipe *me; static CommandMutex *current_command = NULL; static std::list<CommandMutex *> commands; @@ -9,8 +10,8 @@ static Mutex main_mutex; class AsynchCommandMutex : public CommandMutex { - bool destroy; public: + bool destroy; bool started; AsynchCommandMutex(CommandSource &s, Command *c, const std::vector<Anope::string> &p) : CommandMutex(s, c, p), destroy(false), started(false) @@ -35,6 +36,12 @@ class AsynchCommandMutex : public CommandMutex User *u = this->source.u; BotInfo *bi = this->source.owner; + + ignore_pre_command = true; + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, command, params)); + if (MOD_RESULT == EVENT_STOP) + return; if (!command->permission.empty() && !u->Account()->HasCommand(command->permission)) { @@ -44,13 +51,11 @@ class AsynchCommandMutex : public CommandMutex else { CommandReturn ret = command->Execute(source, params); - - if (ret == MOD_CONT) + if (ret != MOD_STOP) { FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, command, params)); + source.DoReply(); } - - source.DoReply(); } main_mutex.Unlock(); @@ -59,13 +64,17 @@ class AsynchCommandMutex : public CommandMutex void Lock() { if (this->destroy) - { this->Exit(); - } this->processing = true; me->Notify(); this->mutex.Lock(); + + if (this->destroy) + { + this->Unlock(); + this->Exit(); + } } void Unlock() @@ -111,6 +120,8 @@ class ModuleAsynchCommands : public Module, public Pipe, public AsynchCommandsSe Implementation i[] = { I_OnObjectDestroy, I_OnPreCommand }; ModuleManager::Attach(i, this, 2); + ModuleManager::SetPriority(this, PRIORITY_FIRST); + ModuleManager::RegisterService(this); } @@ -132,12 +143,21 @@ class ModuleAsynchCommands : public Module, public Pipe, public AsynchCommandsSe EventReturn OnPreCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) { - AsynchCommandMutex *cm = new AsynchCommandMutex(source, command, params); + if (ignore_pre_command) + { + ignore_pre_command = false; + return EVENT_CONTINUE; + } + else if (current_command) + return EVENT_CONTINUE; + + CommandSource source_copy = source; + AsynchCommandMutex *cm = new AsynchCommandMutex(source_copy, command, params); try { // Give processing to the command thread - Log(LOG_DEBUG_2) << "Waiting for command thread " << cm->command->name << " from " << source.u->nick; + Log(LOG_DEBUG_2) << "Waiting for command thread " << cm->command->name << " from " << source_copy.u->nick; current_command = cm; threadEngine.Start(cm); main_mutex.Lock(); @@ -163,11 +183,20 @@ class ModuleAsynchCommands : public Module, public Pipe, public AsynchCommandsSe // Thread engine will pick this up later if (cm->GetExitState() || !cm->processing) continue; + else if (cm->destroy) + { + if (cm->started) + cm->mutex.Unlock(); + else + delete cm; + continue; + } Log(LOG_DEBUG_2) << "Waiting for command thread " << cm->command->name << " from " << cm->source.u->nick; current_command = cm; // Unlock to give processing back to the command thread + PushLanguage("anope", cm->source.u->Account() ? cm->source.u->Account()->language : ""); if (!cm->started) { try @@ -177,6 +206,7 @@ class ModuleAsynchCommands : public Module, public Pipe, public AsynchCommandsSe catch (const CoreException &) { delete cm; + PopLanguage(); continue; } } @@ -184,6 +214,7 @@ class ModuleAsynchCommands : public Module, public Pipe, public AsynchCommandsSe cm->mutex.Unlock(); // Relock to regain processing once the command thread hangs for any reason main_mutex.Lock(); + PopLanguage(); current_command = NULL; diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp index b33e9555e..39c4cca19 100644 --- a/modules/extra/m_xmlrpc_main.cpp +++ b/modules/extra/m_xmlrpc_main.cpp @@ -89,7 +89,7 @@ class MyXMLRPCEvent : public XMLRPCEvent else request->reply("online", "yes"); - mod_run_cmd(bi, *u, command, false); + mod_run_cmd(bi, *u, NULL, command); if (created && u) { diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index c6dafc81a..a8868817c 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -529,21 +529,21 @@ class InspircdIRCdMessage : public IRCdMessage send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_globops module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_servicesmod) { send_cmd("", "ERROR :m_services is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_hidechansmod) { send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server deos not have the m_hidechans module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_svsholdmod) ircdproto->SendGlobops(OperServ, "SVSHOLD missing, Usage disabled until module is loaded."); diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 958709b06..d2ae35c9f 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -644,21 +644,21 @@ class Inspircd12IRCdMessage : public InspircdIRCdMessage send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope"); quitmsg = "Remote server does not have the m_globops module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_servicesmod) { send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_hidechansmod) { send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_svsholdmod) ircdproto->SendGlobops(OperServ, "SVSHOLD missing, Usage disabled until module is loaded."); diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index e1e339635..a0fd55481 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -360,7 +360,7 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage send_cmd("", "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"); quitmsg = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; quitting = true; - return MOD_STOP; + return false; } /* reset CAPAB */ @@ -627,14 +627,14 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!ModeManager::FindUserModeByName(UMODE_PRIV)) { send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope"); quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; quitting = true; - return MOD_STOP; + return false; } if (!has_svsholdmod) ircdproto->SendGlobops(OperServ, "SVSHOLD missing, Usage disabled until module is loaded."); diff --git a/src/bots.cpp b/src/bots.cpp index 1f3f29009..b77031c00 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -111,11 +111,6 @@ BotInfo::~BotInfo() } } -void BotInfo::SetIdent(const Anope::string &sident) -{ - this->ident = sident; -} - void BotInfo::SetNewNick(const Anope::string &newnick) { UserListByNick.erase(this->nick); diff --git a/src/botserv.cpp b/src/botserv.cpp index 5f321a125..e65118921 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -343,7 +343,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) message = ci->name + " " + message; message = command + " " + message; - mod_run_cmd(ChanServ, u, message, ci); + mod_run_cmd(ChanServ, u, ci, message); } FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(command, u, ci, sep.GetRemaining())); diff --git a/src/commands.cpp b/src/commands.cpp index b2e3b7192..c9f66b25a 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -26,7 +26,7 @@ Command *FindCommand(BotInfo *bi, const Anope::string &name) return NULL; } -void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, ChannelInfo *ci) +void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &fullmessage) { if (!bi || !u) return; @@ -45,10 +45,10 @@ void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, Channel Command *c = FindCommand(bi, command); - mod_run_cmd(bi, u, c, command, message, ci); + mod_run_cmd(bi, u, ci, c, command, message); } -void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, ChannelInfo *ci) +void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope::string &command, const Anope::string &message) { if (!bi || !u) return; @@ -166,12 +166,13 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, } CommandReturn ret = c->Execute(source, params); - if (ret == MOD_STOP) - return; - - FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params)); + if (ret != MOD_STOP) + { + FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params)); + source.DoReply(); + } - source.DoReply(); + PopLanguage(); } /** diff --git a/src/language.cpp b/src/language.cpp index 01ff01f81..5d2ced124 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -69,7 +69,7 @@ const char *anope_gettext(const char *string) std::pair<Anope::string, Anope::string> lang_info; if (!language_stack.empty()) lang_info = language_stack.top(); - if (lang_info.first.empty() || lang_info.second.empty()) + if (*string == 0 || lang_info.first.empty() || lang_info.second.empty()) return string; ++_nl_msg_cat_cntr; diff --git a/src/protocol.cpp b/src/protocol.cpp index 220b33622..35c9d8c0b 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -438,14 +438,14 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope if (!u->HasMode(UMODE_OPER) && Config->CSOpersOnly) u->SendMessage(ChanServ, LanguageString::ACCESS_DENIED); else - mod_run_cmd(bi, u, message, false); + mod_run_cmd(bi, u, NULL, message); } else if (bi == HostServ) { if (!ircd->vhost) u->SendMessage(HostServ, _("%s is currently offline."), Config->s_HostServ.c_str()); else - mod_run_cmd(bi, u, message, false); + mod_run_cmd(bi, u, NULL, message); } else if (bi == OperServ) { @@ -458,11 +458,11 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope else { Log(OperServ) << u->nick << ": " << message; - mod_run_cmd(bi, u, message, false); + mod_run_cmd(bi, u, NULL, message); } } else - mod_run_cmd(bi, u, message, false); + mod_run_cmd(bi, u, NULL, message); } } |