diff options
| author | Adam <Adam@anope.org> | 2011-02-25 21:41:08 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-02-25 21:41:08 -0500 |
| commit | c38b6392c5956628f51faaa6085367dd32199e61 (patch) | |
| tree | 8933d0997016756b15e10a7ad88a5d51c04d841e /modules/extra | |
| parent | ee387569821b45581063f6bc349cccc643f9a293 (diff) | |
More fixes. Also made db_mysql_live not keep bots updated because thats pointless and made m_asynch_commands respect user language settings.
Diffstat (limited to 'modules/extra')
| -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 |
3 files changed, 46 insertions, 86 deletions
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) { |
