summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-07-14 02:31:12 -0400
committerAdam <Adam@anope.org>2011-07-14 02:31:12 -0400
commitf858164deed48f2dcacd5ffc06a55398a54da7e8 (patch)
tree89c3cf36bd8e94942370135218d67d6d17ee222e /src
parent924f6849fee4598a1a3a7f1a98d96b79e5ffd3b4 (diff)
Rewrote how commands are handled within Anope.
This allows naming commands and having spaces within command names.
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp150
-rw-r--r--src/channels.cpp58
-rw-r--r--src/chanserv.cpp14
-rw-r--r--src/command.cpp64
-rw-r--r--src/commands.cpp183
-rw-r--r--src/config.cpp326
-rw-r--r--src/init.cpp7
-rw-r--r--src/language.cpp9
-rw-r--r--src/logger.cpp36
-rw-r--r--src/main.cpp4
-rw-r--r--src/misc.cpp2
-rw-r--r--src/modes.cpp23
-rw-r--r--src/modulemanager.cpp11
-rw-r--r--src/modules.cpp43
-rw-r--r--src/operserv.cpp289
-rw-r--r--src/protocol.cpp35
-rw-r--r--src/regchannel.cpp20
-rw-r--r--src/servers.cpp1
-rw-r--r--src/users.cpp37
19 files changed, 453 insertions, 859 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index f48a90228..13947c0bb 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -8,6 +8,7 @@
#include "services.h"
#include "modules.h"
#include "commands.h"
+#include "oper.h"
Anope::insensitive_map<BotInfo *> BotListByNick;
Anope::map<BotInfo *> BotListByUID;
@@ -35,30 +36,31 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
this->SetModeInternal(ModeManager::FindUserModeByName(UMODE_PROTECTED));
this->SetModeInternal(ModeManager::FindUserModeByName(UMODE_GOD));
- for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
- {
- LogInfo *l = Config->LogInfos[i];
-
- if (ircd && !ircd->join2msg && !l->Inhabit)
- continue;
-
- for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit)
+ if (Config)
+ for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
{
- const Anope::string &target = *sit;
+ LogInfo *l = Config->LogInfos[i];
+
+ if (ircd && !ircd->join2msg && !l->Inhabit)
+ continue;
- if (target[0] == '#')
+ for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit)
{
- Channel *c = findchan(target);
- if (!c)
- c = new Channel(target);
- c->SetFlag(CH_LOGCHAN);
- c->SetFlag(CH_PERSIST);
-
- if (!c->FindUser(this))
- this->Join(c, &Config->BotModeList);
+ const Anope::string &target = *sit;
+
+ if (target[0] == '#')
+ {
+ Channel *c = findchan(target);
+ if (!c)
+ c = new Channel(target);
+ c->SetFlag(CH_LOGCHAN);
+ c->SetFlag(CH_PERSIST);
+
+ if (!c->FindUser(this))
+ this->Join(c, &Config->BotModeList);
+ }
}
}
- }
}
BotInfo::~BotInfo()
@@ -79,20 +81,20 @@ BotInfo::~BotInfo()
ci->bi = NULL;
}
- for (CommandMap::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end;)
- {
- Command *c = it->second;
- ++it;
-
- if (c->module)
- c->module->DelCommand(this, c);
- }
-
BotListByNick.erase(this->nick);
if (!this->uid.empty())
BotListByUID.erase(this->uid);
}
+void BotInfo::GenerateUID()
+{
+ if (!this->uid.empty())
+ throw CoreException("Bot already has a uid?");
+ this->uid = ts6_uid_retrieve();
+ BotListByUID[this->uid] = this;
+ UserListByUID[this->uid] = this;
+}
+
void BotInfo::SetNewNick(const Anope::string &newnick)
{
UserListByNick.erase(this->nick);
@@ -154,7 +156,7 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci)
void BotInfo::Join(Channel *c, ChannelStatus *status)
{
- if (Config->BSSmartJoin)
+ if (Config && ircdproto && Config->BSSmartJoin)
{
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = c->GetModeList(CMODE_BAN);
@@ -179,7 +181,8 @@ void BotInfo::Join(Channel *c, ChannelStatus *status)
}
c->JoinUser(this);
- ircdproto->SendJoin(this, c, status);
+ if (ircdproto)
+ ircdproto->SendJoin(this, c, status);
FOREACH_MOD(I_OnBotJoin, OnBotJoin(c, this));
}
@@ -198,6 +201,91 @@ void BotInfo::Part(Channel *c, const Anope::string &reason)
void BotInfo::OnMessage(User *u, const Anope::string &message)
{
- mod_run_cmd(this, u, NULL, message);
+ std::vector<Anope::string> params = BuildStringVector(message);
+
+ command_map::iterator it = this->commands.end();
+ unsigned count = 0;
+ for (unsigned max = params.size(); it == this->commands.end() && max > 0; --max)
+ {
+ Anope::string full_command;
+ for (unsigned i = 0; i < max; ++i)
+ full_command += " " + params[i];
+ full_command.erase(full_command.begin());
+
+ ++count;
+ it = this->commands.find(full_command);
+ }
+
+ if (it == this->commands.end())
+ {
+ u->SendMessage(this, _("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->UseStrictPrivMsgString.c_str(), this->nick.c_str());
+ return;
+ }
+
+ service_reference<Command> c(it->second);
+ if (!c)
+ {
+ u->SendMessage(this, _("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->UseStrictPrivMsgString.c_str(), this->nick.c_str());
+ Log(this) << "Command " << it->first << " exists on me, but its service " << it->second << " was not found!";
+ return;
+ }
+
+ // Command requires registered users only
+ if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified())
+ {
+ u->SendMessage(this, NICK_IDENTIFY_REQUIRED);
+ Log(LOG_COMMAND, "denied", this) << "Access denied for unregistered user " << u->GetMask() << " with command " << c->name;
+ return;
+ }
+
+ for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
+ params.erase(params.begin());
+
+ while (c->MaxParams > 0 && params.size() > c->MaxParams)
+ {
+ params[c->MaxParams - 1] += " " + params[c->MaxParams];
+ params.erase(params.begin() + c->MaxParams);
+ }
+
+ CommandSource source;
+ source.u = u;
+ source.c = NULL;
+ source.owner = this;
+ source.service = this;
+ source.command = it->first;
+
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params));
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ source.DoReply();
+ return;
+ }
+
+
+ if (params.size() < c->MinParams)
+ {
+ c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : "");
+ source.DoReply();
+ return;
+ }
+
+ // If the command requires a permission, and they aren't registered or don't have the required perm, DENIED
+ if (!c->permission.empty() && !u->HasCommand(c->permission))
+ {
+ u->SendMessage(this, ACCESS_DENIED);
+ Log(LOG_COMMAND, "denied", this) << "Access denied for user " << u->GetMask() << " with command " << c->name;
+ source.DoReply();
+ return;
+ }
+
+ dynamic_reference<User> user_reference(u);
+ c->Execute(source, params);
+ if (user_reference)
+ {
+ FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params));
+ if (user_reference)
+ source.DoReply();
+ }
}
diff --git a/src/channels.cpp b/src/channels.cpp
index d64a8b378..26ae18308 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -122,27 +122,6 @@ void Channel::JoinUser(User *user)
ircdproto->SendChannel(this);
this->Reset();
}
-
- if (!Config->s_BotServ.empty() && this->ci && this->ci->bi)
- {
- /**
- * We let the bot join even if it was an ignored user, as if we don't,
- * and the ignored user doesnt just leave, the bot will never
- * make it into the channel, leaving the channel botless even for
- * legit users - Rob
- **/
- if (this->users.size() >= Config->BSMinUsers && !this->FindUser(this->ci->bi))
- this->ci->bi->Join(this, &Config->BotModeList);
- /* Only display the greet if the main uplink we're connected
- * to has synced, or we'll get greet-floods when the net
- * recovers from a netsplit. -GD
- */
- if (this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && !user->Account()->greet.empty() && check_access(user, this->ci, CA_GREET) && user->server->IsSynced())
- {
- ircdproto->SendPrivmsg(this->ci->bi, this->name, "[%s] %s", user->Account()->display.c_str(), user->Account()->greet.c_str());
- this->ci->bi->lastmsg = Anope::CurTime;
- }
- }
}
/** Remove a user internally from the channel
@@ -154,6 +133,7 @@ void Channel::DeleteUser(User *user)
update_cs_lastseen(user, this->ci);
Log(user, this, "leaves");
+ FOREACH_MOD(I_OnLeaveChannel, OnLeaveChannel(user, this));
CUserList::iterator cit, cit_end = this->users.end();
for (cit = this->users.begin(); (*cit)->user != user && cit != cit_end; ++cit);
@@ -170,14 +150,13 @@ void Channel::DeleteUser(User *user)
UChannelList::iterator uit, uit_end = user->chans.end();
for (uit = user->chans.begin(); (*uit)->chan != this && uit != uit_end; ++uit);
if (uit == uit_end)
- {
Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistant channel " << this->name << " from " << user->nick << "'s channel list";
- return;
+ else
+ {
+ delete *uit;
+ user->chans.erase(uit);
}
- delete *uit;
- user->chans.erase(uit);
-
/* Channel is persistant, it shouldn't be deleted and the service bot should stay */
if (this->HasFlag(CH_PERSIST) || (this->ci && this->ci->HasFlag(CI_PERSIST)))
return;
@@ -192,12 +171,7 @@ void Channel::DeleteUser(User *user)
if (this->HasFlag(CH_INHABIT))
return;
- /* check for BSMinUsers and part the BotServ bot from the channel
- * Use <= because the bot is included in this->users.size()
- */
- if (!Config->s_BotServ.empty() && this->ci && this->ci->bi && this->users.size() <= Config->BSMinUsers && this->FindUser(this->ci->bi))
- this->ci->bi->Part(this->ci->c);
- else if (this->users.empty())
+ if (this->users.empty())
delete this;
}
@@ -298,10 +272,7 @@ void Channel::SetModeInternal(ChannelMode *cm, const Anope::string &param, bool
return;
}
- BotInfo *bi = NULL;
- if (!Config->s_BotServ.empty())
- bi = findbot(param);
- User *u = bi ? bi : finduser(param);
+ User *u = finduser(param);
if (!u)
{
@@ -411,9 +382,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string &param, bo
return;
}
- BotInfo *bi = NULL;
- if (!Config->s_BotServ.empty())
- bi = findbot(param);
+ BotInfo *bi = findbot(param);
User *u = bi ? bi : finduser(param);
if (!u)
@@ -467,16 +436,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string &param, bo
this->UnsetFlag(CH_PERSIST);
if (ci)
- {
ci->UnsetFlag(CI_PERSIST);
- if (!Config->s_BotServ.empty() && ci->bi && this->FindUser(ci->bi) && Config->BSMinUsers && this->users.size() <= Config->BSMinUsers)
- {
- bool empty = this->users.size() == 1;
- this->ci->bi->Part(this);
- if (empty)
- return;
- }
- }
if (this->users.empty())
{
@@ -780,7 +740,7 @@ void Channel::KickInternal(const Anope::string &source, const Anope::string &nic
{
User *sender = finduser(source);
BotInfo *bi = NULL;
- if (!Config->s_BotServ.empty() && this->ci)
+ if (this->ci && this->ci->bi)
bi = findbot(nick);
User *target = bi ? bi : finduser(nick);
if (!target)
diff --git a/src/chanserv.cpp b/src/chanserv.cpp
index 42d637c38..6a39340ae 100644
--- a/src/chanserv.cpp
+++ b/src/chanserv.cpp
@@ -13,7 +13,6 @@
#include "services.h"
#include "modules.h"
-#include "chanserv.h"
registered_channel_map RegisteredChannelList;
@@ -124,8 +123,7 @@ void check_modes(Channel *c)
/* Check for mode bouncing */
if (c->server_modecount >= 3 && c->chanserv_modecount >= 3)
{
- ircdproto->SendGlobops(NULL, "Warning: unable to set modes on channel %s. Are your servers' U:lines configured correctly?", c->name.c_str());
- Log() << "Bouncy modes on channel " << c->name;
+ Log() << "Warning: unable to set modes on channel " << c->name << ". Are your servers' U:lines configured correctly?";
c->bouncy_modes = 1;
return;
}
@@ -367,11 +365,12 @@ Anope::string get_xop_level(int level)
ChanServTimer::ChanServTimer(Channel *chan) : Timer(Config->CSInhabit), c(chan)
{
- if (!chanserv || !c)
+ BotInfo *bi = findbot(Config->ChanServ);
+ if (!bi || !c)
return;
c->SetFlag(CH_INHABIT);
if (!c->ci || !c->ci->bi)
- chanserv->Bot()->Join(c);
+ bi->Join(c);
else if (!c->FindUser(c->ci->bi))
c->ci->bi->Join(c);
}
@@ -385,8 +384,9 @@ void ChanServTimer::Tick(time_t)
if (!c->ci || !c->ci->bi)
{
- if (chanserv)
- chanserv->Bot()->Part(c);
+ BotInfo *bi = findbot(Config->ChanServ);
+ if (bi)
+ bi->Part(c);
}
else if (c->users.size() == 1 || c->users.size() < Config->BSMinUsers)
c->ci->bi->Part(c);
diff --git a/src/command.cpp b/src/command.cpp
index f13be6ee5..8803edf05 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -7,6 +7,7 @@
#include "services.h"
#include "modules.h"
+#include "commands.h"
void CommandSource::Reply(const char *message, ...)
{
@@ -42,29 +43,25 @@ void CommandSource::DoReply()
const Anope::string &message = *it;
// Send to the user if the reply is more than one line
- if (!this->fantasy || !this->ci || this->reply.size() > 1)
+ if (!this->c || !this->c->ci || this->reply.size() > 1)
u->SendMessage(this->service, message);
- else if (this->ci->botflags.HasFlag(BS_MSG_PRIVMSG))
- ircdproto->SendPrivmsg(this->service, this->ci->name, message.c_str());
- else if (this->ci->botflags.HasFlag(BS_MSG_NOTICE))
- ircdproto->SendNotice(this->service, this->ci->name, message.c_str());
- else if (this->ci->botflags.HasFlag(BS_MSG_NOTICEOPS))
- ircdproto->SendNoticeChanops(this->service, this->ci->c, message.c_str());
+ else if (this->c->ci->botflags.HasFlag(BS_MSG_PRIVMSG))
+ ircdproto->SendPrivmsg(this->service, this->c->name, message.c_str());
+ else if (this->c->ci->botflags.HasFlag(BS_MSG_NOTICE))
+ ircdproto->SendNotice(this->service, this->c->name, message.c_str());
+ else if (this->c->ci->botflags.HasFlag(BS_MSG_NOTICEOPS))
+ ircdproto->SendNoticeChanops(this->service, this->c, message.c_str());
else
u->SendMessage(this->service, message);
}
}
-Command::Command(const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : Flags<CommandFlag>(CommandFlagStrings), MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission)
+Command::Command(Module *owner, const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : Service(owner, sname), Flags<CommandFlag>(CommandFlagStrings), MaxParams(max_params), MinParams(min_params), permission(spermission), module(owner)
{
- this->module = NULL;
- this->service = NULL;
}
Command::~Command()
{
- if (this->module)
- this->module->DelCommand(this->service, this);
}
void Command::SetDesc(const Anope::string &d)
@@ -72,37 +69,52 @@ void Command::SetDesc(const Anope::string &d)
this->desc = d;
}
-const Anope::string &Command::GetDesc() const
+void Command::ClearSyntax()
{
- return this->desc;
+ this->syntax.clear();
}
-void Command::OnServHelp(CommandSource &source)
+void Command::SetSyntax(const Anope::string &s)
{
- source.Reply(" %-14s %s", this->name.c_str(), translate(source.u, (this->GetDesc().c_str())));
+ this->syntax.push_back(s);
}
-bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; }
+void Command::SendSyntax(CommandSource &source)
+{
+ if (!this->syntax.empty())
+ {
+ source.Reply(_("Syntax: \002%s %s\002"), source.command.c_str(), this->syntax[0].c_str());
+ for (unsigned i = 1, j = this->syntax.size(); i < j; ++i)
+ source.Reply(" \002%s %s\002", source.command.c_str(), this->syntax[i].c_str());
+ }
+}
-void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcommand) { }
+void Command::SendSyntax(CommandSource &source, const Anope::string &syntax)
+{
+ source.Reply(_("Syntax: \002%s %s\002"), source.command.c_str(), syntax.c_str());
+ source.Reply(MORE_INFO, Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str(), source.command.c_str());
+}
-void Command::SetPermission(const Anope::string &reststr)
+const Anope::string &Command::GetDesc() const
{
- this->permission = reststr;
+ return this->desc;
}
-bool Command::AddSubcommand(Module *creator, Command *c)
+void Command::OnServHelp(CommandSource &source)
{
- return false;
+ source.Reply(" %-14s %s", source.command.c_str(), translate(source.u, (this->GetDesc().c_str())));
}
-bool Command::DelSubcommand(Command *c)
+bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; }
+
+void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
{
- return false;
+ this->SendSyntax(source);
+ source.Reply(MORE_INFO, Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str(), source.command.c_str());
}
-Command *Command::FindSubcommand(const Anope::string &subcommand)
+void Command::SetPermission(const Anope::string &reststr)
{
- return NULL;
+ this->permission = reststr;
}
diff --git a/src/commands.cpp b/src/commands.cpp
deleted file mode 100644
index fea6e4376..000000000
--- a/src/commands.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-/* Routines for looking up commands in a *Serv command list.
- *
- * (C) 2003-2011 Anope Team
- * Contact us at team@anope.org
- *
- * Please read COPYING and README for further details.
- *
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
- */
-
-#include "services.h"
-#include "modules.h"
-#include "hashcomp.h"
-
-Command *FindCommand(BotInfo *bi, const Anope::string &name)
-{
- if (!bi || bi->Commands.empty() || name.empty())
- return NULL;
-
- CommandMap::iterator it = bi->Commands.find(name);
-
- if (it != bi->Commands.end())
- return it->second;
-
- return NULL;
-}
-
-void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &fullmessage)
-{
- if (!bi || !u)
- return;
-
- spacesepstream sep(fullmessage);
- Anope::string command, message;
-
- if (!sep.GetToken(command))
- return;
- message = sep.GetRemaining();
-
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, message, ci));
- if (MOD_RESULT == EVENT_STOP)
- return;
-
- Command *c = FindCommand(bi, command);
-
- mod_run_cmd(bi, u, ci, c, command, message);
-}
-
-void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope::string &command, const Anope::string &message)
-{
- if (!bi || !u)
- return;
-
- if (!c)
- {
- u->SendMessage(bi, _("Unknown command \002%s\002. \"%s%s HELP\" for help."), command.c_str(), Config->UseStrictPrivMsgString.c_str(), bi->nick.c_str());
- return;
- }
-
- // Command requires registered users only
- if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified())
- {
- u->SendMessage(bi, NICK_IDENTIFY_REQUIRED, Config->UseStrictPrivMsgString.c_str(), Config->s_NickServ.c_str());
- Log(LOG_COMMAND, "denied", bi) << "Access denied for unregistered user " << u->GetMask() << " with command " << command;
- return;
- }
-
- std::vector<Anope::string> params;
- Anope::string curparam, endparam;
- spacesepstream sep(message);
- while (sep.GetToken(curparam))
- {
- // - 1 because params[0] corresponds with a maxparam of 1.
- if (params.size() >= c->MaxParams - 1)
- endparam += curparam + " ";
- else
- params.push_back(curparam);
- }
-
- if (!endparam.empty())
- {
- // Remove trailing space
- endparam.erase(endparam.length() - 1);
-
- // Add it
- params.push_back(endparam);
- }
-
- bool fantasy = ci != NULL;
- if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && ircdproto->IsChannelValid(params[0]))
- ci = cs_findchan(params[0]);
-
- CommandSource source;
- source.u = u;
- source.ci = ci;
- source.owner = bi;
- source.service = fantasy && ci ? ci->bi : c->service;
- source.fantasy = fantasy;
-
- if (params.size() < c->MinParams)
- {
- c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : "");
- source.DoReply();
- return;
- }
-
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params));
- if (MOD_RESULT == EVENT_STOP)
- {
- source.DoReply();
- return;
- }
-
- // If the command requires a permission, and they aren't registered or don't have the required perm, DENIED
- if (!c->permission.empty() && !u->HasCommand(c->permission))
- {
- u->SendMessage(bi, ACCESS_DENIED);
- Log(LOG_COMMAND, "denied", bi) << "Access denied for user " << u->GetMask() << " with command " << command;
- source.DoReply();
- return;
- }
-
- dynamic_reference<User> user_reference(u);
- CommandReturn ret = c->Execute(source, params);
- if (ret != MOD_STOP && user_reference)
- {
- FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params));
- source.DoReply();
- }
-}
-
-/**
- * Prints the help message for a given command.
- * @param bi Client the command is on
- * @param u User
- * @param ci Optional channel the command was executed one (fantasy)
- * @param cmd Command
- */
-void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cmd)
-{
- if (!bi || !u || cmd.empty())
- return;
-
- spacesepstream tokens(cmd);
- Anope::string token;
- tokens.GetToken(token);
-
- Command *c = FindCommand(bi, token);
- Anope::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining();
-
- CommandSource source;
- source.u = u;
- source.ci = ci;
- source.owner = bi;
- source.service = ci ? ci->bi : bi;
- source.fantasy = ci != NULL;
-
- if (!c || (Config->HidePrivilegedCommands && !c->permission.empty() && !u->HasCommand(c->permission)) || !c->OnHelp(source, subcommand))
- source.Reply( _("No help available for \002%s\002."), cmd.c_str());
- else
- {
- source.Reply(" ");
-
- /* Inform the user what permission is required to use the command */
- if (!c->permission.empty())
- source.Reply(_("Access to this command requires the permission \002%s\002 to be present in your opertype."), c->permission.c_str());
-
- /* User isn't identified and needs to be to use this command */
- if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified())
- source.Reply( _("You need to be identified to use this command."));
- /* User doesn't have the proper permission to use this command */
- else if (!c->permission.empty() && !u->HasCommand(c->permission))
- source.Reply(_("You cannot use this command."));
- /* User can use this command */
- else
- source.Reply(_("You can use this command."));
- }
-
- source.DoReply();
-}
diff --git a/src/config.cpp b/src/config.cpp
index 7d3efcb91..0d9341424 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -11,18 +11,17 @@
#include "services.h"
#include "config.h"
+#include "module.h"
/*************************************************************************/
ConfigurationFile services_conf("services.conf", false); // Services configuration file name
ServerConfig *Config = NULL;
-static Anope::string Modules;
static Anope::string UlineServers;
static Anope::string OSNotifications;
static Anope::string BSDefaults;
static Anope::string CSDefaults;
-static Anope::string temp_nsuserhost;
static Anope::string NSDefaults;
/*************************************************************************/
@@ -31,21 +30,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C
{
this->Read();
- if (!temp_nsuserhost.empty())
- {
- size_t at = temp_nsuserhost.find('@');
- if (at == Anope::string::npos)
- {
- this->NSEnforcerUser = temp_nsuserhost;
- this->NSEnforcerHost = this->ServiceHost;
- }
- else
- {
- this->NSEnforcerUser = temp_nsuserhost.substr(0, at);
- this->NSEnforcerHost = temp_nsuserhost.substr(at + 1);
- }
- }
-
if (NSDefaults.empty())
{
this->NSDefFlags.SetFlag(NI_SECURE);
@@ -155,8 +139,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C
this->BSDefFlags.SetFlag(BS_GREET);
else if (option.equals_ci("fantasy"))
this->BSDefFlags.SetFlag(BS_FANTASY);
- else if (option.equals_ci("symbiosis"))
- this->BSDefFlags.SetFlag(BS_SYMBIOSIS);
}
}
@@ -196,23 +178,12 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C
this->Ulines.push_back(uline);
}
- /* Modules Autoload building... :P */
- this->ModulesAutoLoad = BuildStringList(Modules);
-
if (this->LimitSessions)
{
if (this->MaxSessionKill && !this->SessionAutoKillExpiry)
this->SessionAutoKillExpiry = 1800; /* 30 minutes */
}
- if (!this->s_BotServ.empty())
- {
- if (this->BSFantasyCharacter.empty())
- this->BSFantasyCharacter = "!";
- if (this->BSFantasyCharacter.length() > 1)
- Log() << "*** " << this->BSFantasyCharacter << " is more than 1 character long. Only the first character will be used. The others will be ignored.";
- }
-
/* Check the user keys */
if (this->UserKey1 == this->UserKey2 || this->UserKey1 == this->UserKey3 || this->UserKey3 == this->UserKey2)
Log() << "Every UserKey must be different. It's for YOUR safety! Remember that!";
@@ -421,7 +392,7 @@ bool ValidateBantype(ServerConfig *, const Anope::string &, const Anope::string
bool ValidateChanServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_ChanServ.empty())
+ if (!config->ChanServ.empty())
{
if ((value.equals_ci("decription") || value.equals_ci("autokickreason")) && data.GetValue().empty())
throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when ChanServ is enabled!");
@@ -435,7 +406,7 @@ bool ValidateChanServ(ServerConfig *config, const Anope::string &tag, const Anop
bool ValidateMemoServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_MemoServ.empty())
+ if (!config->MemoServ.empty())
{
if (value.equals_ci("description"))
{
@@ -448,7 +419,7 @@ bool ValidateMemoServ(ServerConfig *config, const Anope::string &tag, const Anop
bool ValidateBotServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_BotServ.empty())
+ if (!config->BotServ.empty())
{
if (value.equals_ci("description"))
{
@@ -471,7 +442,7 @@ bool ValidateBotServ(ServerConfig *config, const Anope::string &tag, const Anope
bool ValidateHostServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_HostServ.empty())
+ if (!config->HostServ.empty())
{
if (value.equals_ci("description") && data.GetValue().empty())
throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when HostServ is enabled!");
@@ -494,7 +465,7 @@ bool ValidateLimitSessions(ServerConfig *config, const Anope::string &tag, const
bool ValidateOperServ(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_OperServ.empty())
+ if (!config->OperServ.empty())
{
if (value.equals_ci("description") && data.GetValue().empty())
throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when OperServ is enabled!");
@@ -508,7 +479,7 @@ bool ValidateOperServ(ServerConfig *config, const Anope::string &tag, const Anop
bool ValidateGlobal(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data)
{
- if (!config->s_Global.empty())
+ if (!config->Global.empty())
{
if (value.equals_ci("description") && data.GetValue().empty())
throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when Global is enabled!");
@@ -571,7 +542,7 @@ bool InitUplinks(ServerConfig *config, const Anope::string &)
return true;
}
-bool DoUplink(ServerConfig *config, const Anope::string &, const Anope::string *, ValueList &values, int *)
+static bool DoUplink(ServerConfig *config, const Anope::string &, const Anope::string *, ValueList &values, int *)
{
// Validation variables
Anope::string host = values[0].GetValue(), password = values[3].GetValue();
@@ -592,7 +563,7 @@ bool DoUplink(ServerConfig *config, const Anope::string &, const Anope::string *
return true;
}
-bool DoneUplinks(ServerConfig *config, const Anope::string &)
+static bool DoneUplinks(ServerConfig *config, const Anope::string &)
{
if (config->Uplinks.empty())
throw ConfigException("You must define at least one uplink block!");
@@ -746,27 +717,31 @@ static bool DoneInclude(ServerConfig *config, const Anope::string &)
bool InitModules(ServerConfig *, const Anope::string &)
{
- Modules.clear();
return true;
}
-bool DoModule(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *)
+static bool DoModule(ServerConfig *conf, const Anope::string &, const Anope::string *, ValueList &values, int *)
{
// First we validate that there was a name in the module block
Anope::string module = values[0].GetValue();
ValueItem vi(module);
if (!ValidateNotEmpty(conf, "module", "name", vi))
throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information.");
- // If the string isn't empty, add a space before we add the module name
- if (!Modules.empty())
- Modules += " ";
- // Add the module name to the string
- Modules += values[0].GetValue();
+ conf->ModulesAutoLoad.push_back(module);
return true;
}
-bool DoneModules(ServerConfig *, const Anope::string &)
+static bool DoneModules(ServerConfig *config, const Anope::string &)
{
+ if (Config)
+ {
+ for (std::list<Anope::string>::iterator it = Config->ModulesAutoLoad.begin(); it != Config->ModulesAutoLoad.end(); ++it)
+ if (std::find(config->ModulesAutoLoad.begin(), config->ModulesAutoLoad.end(), *it) == config->ModulesAutoLoad.end())
+ ModuleManager::UnloadModule(ModuleManager::FindModule(*it), NULL);
+ for (std::list<Anope::string>::iterator it = config->ModulesAutoLoad.begin(); it != config->ModulesAutoLoad.end(); ++it)
+ if (std::find(Config->ModulesAutoLoad.begin(), Config->ModulesAutoLoad.end(), *it) == Config->ModulesAutoLoad.end())
+ ModuleManager::LoadModule(*it, NULL);
+ }
return true;
}
@@ -809,7 +784,7 @@ bool InitLogs(ServerConfig *config, const Anope::string &)
return true;
}
-bool DoLogs(ServerConfig *config, const Anope::string &, const Anope::string *, ValueList &values, int *)
+static bool DoLogs(ServerConfig *config, const Anope::string &, const Anope::string *, ValueList &values, int *)
{
//{"target", "source", "logage", "inhabit", "admin", "override", "commands", "servers", "channels", "users", "other", "rawio", "debug"},
Anope::string targets = values[0].GetValue()