summaryrefslogtreecommitdiff
path: root/src/messages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/messages.cpp')
-rw-r--r--src/messages.cpp88
1 files changed, 48 insertions, 40 deletions
diff --git a/src/messages.cpp b/src/messages.cpp
index ee02cc473..c778de383 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -1,12 +1,20 @@
-/* Common message handlers
+/*
+ * Anope IRC Services
*
- * (C) 2003-2016 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2003-2016 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "services.h"
@@ -19,6 +27,9 @@
#include "messages.h"
#include "servers.h"
#include "channels.h"
+#include "event.h"
+#include "bots.h"
+#include "modules/operserv/stats.h"
using namespace Message;
@@ -26,7 +37,8 @@ void Away::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &msg = !params.empty() ? params[0] : "";
- FOREACH_MOD(OnUserAway, (source.GetUser(), msg));
+ EventManager::Get()->Dispatch(&Event::UserAway::OnUserAway, source.GetUser(), msg);
+
if (!msg.empty())
Log(source.GetUser(), "away") << "is now away: " << msg;
else
@@ -61,8 +73,8 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> &params
if (!targ || targ->server != Me || !c || c->FindUser(targ))
return;
-
- FOREACH_MOD(OnInvite, (source.GetUser(), c, targ));
+
+ EventManager::Get()->Dispatch(&Event::Invite::OnInvite, source.GetUser(), c, targ);
}
void Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
@@ -84,9 +96,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
Channel *c = cc->chan;
++it;
- FOREACH_MOD(OnPrePartChannel, (user, c));
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, user, c);
cc->chan->DeleteUser(user);
- FOREACH_MOD(OnPartChannel, (user, c, c->name, ""));
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, user, c, c->name, "");
}
continue;
}
@@ -119,14 +131,14 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
/* Their TS is newer, don't accept any modes from them */
else if (ts > c->creation_time)
keep_their_modes = false;
-
+
/* Update the modes for the channel */
if (keep_their_modes && !modes.empty())
/* If we are syncing, mlock is checked later in Channel::Sync. It is important to not check it here
* so that Channel::SetCorrectModes can correctly detect the presence of channel mode +r.
*/
c->SetModesInternal(source, modes, ts, !c->syncing);
-
+
for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it)
{
const ChannelStatus &status = it->first;
@@ -147,8 +159,8 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
* they aren't allowed to have (secureops etc).
*/
c->SetCorrectModes(u, true);
-
- FOREACH_MOD(OnJoinChannel, (u, c));
+
+ EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, u, c);
}
/* Channel is done syncing */
@@ -187,13 +199,13 @@ void Kick::Run(MessageSource &source, const std::vector<Anope::string> &params)
void Kill::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
User *u = User::Find(params[0]);
- BotInfo *bi;
+ ServiceBot *bi;
if (!u)
return;
/* Recover if someone kills us. */
- if (u->server == Me && (bi = dynamic_cast<BotInfo *>(u)))
+ if (u->server == Me && (bi = dynamic_cast<ServiceBot *>(u)))
{
static time_t last_time = 0;
@@ -240,7 +252,7 @@ void MOTD::Run(MessageSource &source, const std::vector<Anope::string> &params)
if (s != Me)
return;
- FILE *f = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").c_str(), "r");
+ FILE *f = fopen(Config->GetBlock("serverinfo")->Get<Anope::string>("motd").c_str(), "r");
if (f)
{
IRCD->SendNumeric(375, source.GetSource(), ":- %s Message of the Day", s->GetName().c_str());
@@ -266,10 +278,10 @@ void Notice::Run(MessageSource &source, const std::vector<Anope::string> &params
/* ignore channel notices */
if (!IRCD->IsChannelValid(params[0]))
{
- BotInfo *bi = BotInfo::Find(params[0]);
+ ServiceBot *bi = ServiceBot::Find(params[0]);
if (!bi)
return;
- FOREACH_MOD(OnBotNotice, (u, bi, message));
+ EventManager::Get()->Dispatch(&Event::BotNotice::OnBotNotice, u, bi, message);
}
}
@@ -289,9 +301,10 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> &params)
continue;
Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason");
- FOREACH_MOD(OnPrePartChannel, (u, c));
+
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, u, c);
c->DeleteUser(u);
- FOREACH_MOD(OnPartChannel, (u, c, c->name, !reason.empty() ? reason : ""));
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, u, c, c->name, reason);
}
}
@@ -312,7 +325,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
Channel *c = Channel::Find(receiver);
if (c)
{
- FOREACH_MOD(OnPrivmsg, (u, c, message));
+ EventManager::Get()->Dispatch(&Event::Privmsg::OnPrivmsg, u, c, message);
}
}
else
@@ -332,7 +345,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
}
else if (!IRCD->RequiresID && Config->UseStrictPrivmsg)
{
- BotInfo *bi = BotInfo::Find(receiver);
+ ServiceBot *bi = ServiceBot::Find(receiver);
if (!bi)
return;
Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << u->nick;
@@ -340,7 +353,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
return;
}
- BotInfo *bi = BotInfo::Find(botname, nick_only);
+ ServiceBot *bi = ServiceBot::Find(botname, nick_only);
if (bi)
{
@@ -361,11 +374,10 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &param
return;
}
- EventReturn MOD_RESULT;
- FOREACH_RESULT(OnBotPrivmsg, MOD_RESULT, (u, bi, message));
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message);
if (MOD_RESULT == EVENT_STOP)
return;
-
+
bi->OnMessage(u, message);
}
}
@@ -404,7 +416,7 @@ void SQuit::Run(MessageSource &source, const std::vector<Anope::string> &params)
s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
}
-void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
+void Message::Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
User *u = source.GetUser();
@@ -426,14 +438,8 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
else
{
- for (unsigned i = 0; i < Oper::opers.size(); ++i)
- {
- Oper *o = Oper::opers[i];
-
- const NickAlias *na = NickAlias::Find(o->name);
- if (na)
- IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str());
- }
+ for (Oper *o : Serialize::GetObjects<Oper *>())
+ IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->GetName().c_str(), o->GetType()->GetName().replace_all_cs(" ", "_").c_str());
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
}
@@ -441,9 +447,11 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
break;
case 'u':
{
+ ::Stats *s = Serialize::GetObject<::Stats *>();
long uptime = static_cast<long>(Anope::CurTime - Anope::StartTime);
+
IRCD->SendNumeric(242, source.GetSource(), ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
- IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, MaxUserCount);
+ IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, s ? s->GetMaxUserCount() : 0);
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
break;
} /* case 'u' */
@@ -487,11 +495,11 @@ void Whois::Run(MessageSource &source, const std::vector<Anope::string> &params)
if (u && u->server == Me)
{
- const BotInfo *bi = BotInfo::Find(u->GetUID());
+ const ServiceBot *bi = ServiceBot::Find(u->GetUID());
IRCD->SendNumeric(311, source.GetSource(), "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
if (bi)
IRCD->SendNumeric(307, source.GetSource(), "%s :is a registered nick", bi->nick.c_str());
- IRCD->SendNumeric(312, source.GetSource(), "%s %s :%s", u->nick.c_str(), Me->GetName().c_str(), Config->GetBlock("serverinfo")->Get<const Anope::string>("description").c_str());
+ IRCD->SendNumeric(312, source.GetSource(), "%s %s :%s", u->nick.c_str(), Me->GetName().c_str(), Config->GetBlock("serverinfo")->Get<Anope::string>("description").c_str());
if (bi)
IRCD->SendNumeric(317, source.GetSource(), "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(bi->signon));
IRCD->SendNumeric(318, source.GetSource(), "%s :End of /WHOIS list.", u->nick.c_str());