1
0
mirror of https://github.com/anope/anope.git synced 2026-07-06 23:43:14 +02:00

More fixes. Also made db_mysql_live not keep bots updated because thats pointless and made m_asynch_commands respect user language settings.

This commit is contained in:
Adam
2011-02-25 21:41:08 -05:00
parent ee38756982
commit c38b6392c5
20 changed files with 80 additions and 126 deletions
+2 -2
View File
@@ -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"
-2
View File
@@ -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
*/
+2 -2
View File
@@ -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
{
+1 -1
View File
@@ -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] == '#')
+1 -1
View File
@@ -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
{
+1 -1
View File
@@ -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
{
+1 -1
View File
@@ -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] == '#')
+1 -1
View File
@@ -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());
+1 -1
View File
@@ -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());
+5 -76
View File
@@ -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))
+40 -9
View File
@@ -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;
+1 -1
View File
@@ -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)
{
+3 -3
View File
@@ -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.");
+3 -3
View File
@@ -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.");
+3 -3
View File
@@ -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.");
-5
View File
@@ -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);
+1 -1
View File
@@ -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()));
+9 -8
View File
@@ -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;
if (ret != MOD_STOP)
{
FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params));
source.DoReply();
}
FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params));
source.DoReply();
PopLanguage();
}
/**
+1 -1
View File
@@ -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;
+4 -4
View File
@@ -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);
}
}