summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-12-01 10:59:06 -0500
committerAdam <Adam@anope.org>2016-12-01 11:01:19 -0500
commitd95bc84eda5c131374b7097f9de7f59418bd9b6a (patch)
tree3433830c1ea4babbf0c80b8bf961ae5c5cb0cc38
parent9a87674a95cf8153e343d89ec1a686fc43781a3c (diff)
Allow encap handlers to recall message processing, make protocol/inspircd do this
-rw-r--r--include/anope.h1
-rw-r--r--modules/protocol/inspircd20.cpp80
-rw-r--r--src/process.cpp25
3 files changed, 74 insertions, 32 deletions
diff --git a/include/anope.h b/include/anope.h
index 192ad271c..19d9f9501 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -534,6 +534,7 @@ namespace Anope
* @param Raw message from the uplink
*/
extern void Process(const Anope::string &);
+ extern void ProcessCommand(MessageSource &source, const Anope::string &command, const std::vector<Anope::string> &params);
/** Does a blocking dns query and returns the first IP.
* @param host host to look up
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index cdba96abe..c2c09c95d 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -797,6 +797,51 @@ struct IRCDMessageCapab : rfc1459::Capab
}
};
+struct IRCDMessageChgHost : IRCDMessage
+{
+ IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params) override
+ {
+ User *u = User::Find(params[0]);
+ if (!u || u->server != Me)
+ return;
+
+ u->SetDisplayedHost(params[1]);
+ Uplink::Send(u, "FHOST", params[1]);
+ }
+};
+
+struct IRCDMessageChgIdent : IRCDMessage
+{
+ IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params) override
+ {
+ User *u = User::Find(params[0]);
+ if (!u || u->server != Me)
+ return;
+
+ u->SetIdent(params[1]);
+ Uplink::Send(u, "FIDENT", params[1]);
+ }
+};
+
+struct IRCDMessageChgName : IRCDMessage
+{
+ IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { }
+
+ void Run(MessageSource &source, const std::vector<Anope::string> &params) override
+ {
+ User *u = User::Find(params[0]);
+ if (!u || u->server != Me)
+ return;
+
+ u->SetRealname(params[1]);
+ Uplink::Send(u, "FNAME", params[1]);
+ }
+};
+
struct IRCDMessageEncap : IRCDMessage
{
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
@@ -806,33 +851,10 @@ struct IRCDMessageEncap : IRCDMessage
if (Anope::Match(Me->GetSID(), params[0]) == false)
return;
- if (params[1] == "CHGIDENT")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
+ const Anope::string &command = params[1];
+ std::vector<Anope::string> encap_params(params.begin() + 2, params.end());
- u->SetIdent(params[3]);
- Uplink::Send(u, "FIDENT", params[3]);
- }
- else if (params[1] == "CHGHOST")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
-
- u->SetDisplayedHost(params[3]);
- Uplink::Send(u, "FHOST", params[3]);
- }
- else if (params[1] == "CHGNAME")
- {
- User *u = User::Find(params[2]);
- if (!u || u->server != Me)
- return;
-
- u->SetRealname(params[3]);
- Uplink::Send(u, "FNAME", params[3]);
- }
+ Anope::ProcessCommand(source, command, encap_params);
}
};
@@ -1364,6 +1386,9 @@ class ProtoInspIRCd20 : public Module
/* Our message handlers */
IRCDMessageCapab message_capab;
+ IRCDMessageChgHost message_chghost;
+ IRCDMessageChgIdent message_chgident;
+ IRCDMessageChgName message_chgname;
IRCDMessageEncap message_encap;
IRCDMessageEndburst message_endburst;
IRCDMessageFHost message_fhost;
@@ -1417,6 +1442,9 @@ class ProtoInspIRCd20 : public Module
, message_topic(this)
, message_capab(this)
+ , message_chghost(this)
+ , message_chgident(this)
+ , message_chgname(this)
, message_encap(this)
, message_endburst(this)
, message_fhost(this)
diff --git a/src/process.cpp b/src/process.cpp
index 356a3b695..0d463b8d1 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -55,25 +55,38 @@ void Anope::Process(const Anope::string &buffer)
return;
}
- static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : "";
-
MessageSource src(source);
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];
+ }
+
+ Log(LOG_DEBUG) << "unknown command from server (" << 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();
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;
+ Log(LOG_DEBUG) << "unexpected non-user source " << src.GetSource() << " for " << command;
+ else if (m->HasFlag(IRCDMESSAGE_REQUIRE_SERVER) && !src.GetServer())
+ Log(LOG_DEBUG) << "unexpected non-server source " << src.GetSource() << " for " << command;
else
m->Run(src, params);
}