summaryrefslogtreecommitdiff
path: root/src/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/process.cpp')
-rw-r--r--src/process.cpp95
1 files changed, 64 insertions, 31 deletions
diff --git a/src/process.cpp b/src/process.cpp
index b9798cded..67c5cbf14 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -1,12 +1,20 @@
-/* Main processing code for Services.
+/*
+ * Anope IRC Services
*
- * (C) 2003-2017 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2003-2017 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"
@@ -14,12 +22,12 @@
#include "protocol.h"
#include "servers.h"
#include "users.h"
-#include "regchannel.h"
+#include "event.h"
void Anope::Process(const Anope::string &buffer)
{
/* If debugging, log the buffer */
- Log(LOG_RAWIO) << "Received: " << buffer;
+ Anope::Logger.RawIO("Received: {0}", buffer);
if (buffer.empty())
return;
@@ -31,44 +39,54 @@ void Anope::Process(const Anope::string &buffer)
if (Anope::ProtocolDebug)
{
- Log() << "Source : " << (source.empty() ? "No source" : source);
- Log() << "Command: " << command;
+ Anope::Logger.Log("Source : {0}", source.empty() ? "No source" : source);
+ Anope::Logger.Log("Command: {0}", command);
if (params.empty())
- Log() << "No params";
+ Anope::Logger.Log("No params");
else
- for (unsigned i = 0; i < params.size(); ++i)
- Log() << "params " << i << ": " << params[i];
+ for (unsigned int i = 0; i < params.size(); ++i)
+ Anope::Logger.Log("params {0}: {1}", i, params[i]);
}
if (command.empty())
{
- Log(LOG_DEBUG) << "No command? " << buffer;
+ Anope::Logger.Debug("No command? {0}", buffer);
return;
}
- static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : "";
-
MessageSource src(source);
-
- EventReturn MOD_RESULT;
- FOREACH_RESULT(OnMessage, MOD_RESULT, (src, command, params));
- if (MOD_RESULT == EVENT_STOP)
- return;
- ServiceReference<IRCDMessage> m("IRCDMessage", proto_name + "/" + command.lower());
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::Message::OnMessage, src, command, params);
+
+ ProcessCommand(src, command, params);
+}
+
+void Anope::ProcessCommand(MessageSource &src, const Anope::string &command, const std::vector<Anope::string> &params)
+{
+ static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : "";
+
+ ServiceReference<IRCDMessage> m(proto_name + "/" + command.lower());
if (!m)
{
- Log(LOG_DEBUG) << "unknown message from server (" << buffer << ")";
+ Anope::string buffer = "[" + src.GetSource() + "] " + command;
+ if (!params.empty())
+ {
+ for (unsigned int i = 0; i < params.size() - 1; ++i)
+ buffer += " " + params[i];
+ buffer += " :" + params[params.size() - 1];
+ }
+
+ Anope::Logger.Debug("unknown command from server ({0})", buffer);
return;
}
if (m->HasFlag(IRCDMESSAGE_SOFT_LIMIT) ? (params.size() < m->GetParamCount()) : (params.size() != m->GetParamCount()))
- Log(LOG_DEBUG) << "invalid parameters for " << command << ": " << params.size() << " != " << m->GetParamCount();
+ Anope::Logger.Debug("invalid parameters for {0}: {1} != {2}", command, params.size(), m->GetParamCount());
else if (m->HasFlag(IRCDMESSAGE_REQUIRE_USER) && !src.GetUser())
- Log(LOG_DEBUG) << "unexpected non-user source " << source << " for " << command;
- else if (m->HasFlag(IRCDMESSAGE_REQUIRE_SERVER) && !source.empty() && !src.GetServer())
- Log(LOG_DEBUG) << "unexpected non-server source " << source << " for " << command;
+ Anope::Logger.Debug("unexpected non-user source {0} for {1}", src.GetSource(), command);
+ else if (m->HasFlag(IRCDMESSAGE_REQUIRE_SERVER) && !src.GetServer())
+ Anope::Logger.Debug("unexpected non-server source {0} for {1}", src.GetSource().empty() ? "(no source)" : src.GetSource(), command);
else
m->Run(src, params);
}
@@ -100,11 +118,26 @@ void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope:
}
}
-Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message)
+Anope::string IRCDProto::Format(IRCMessage &message)
{
+ std::stringstream buffer;
+
+ const Anope::string &source = message.GetSource().GetUID();
if (!source.empty())
- return ":" + source + " " + message;
- else
- return message;
+ buffer << ":" << source << " ";
+
+ buffer << message.GetCommand();
+
+ for (unsigned int i = 0; i < message.GetParameters().size(); ++i)
+ {
+ buffer << " ";
+
+ if (i + 1 == message.GetParameters().size())
+ buffer << ":";
+
+ buffer << message.GetParameters()[i];
+ }
+
+ return buffer.str();
}