summaryrefslogtreecommitdiff
path: root/modules/extra/m_async_commands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/extra/m_async_commands.cpp')
-rw-r--r--modules/extra/m_async_commands.cpp49
1 files changed, 40 insertions, 9 deletions
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> &params)
{
- 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;