summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/protocol/bahamut.cpp47
-rw-r--r--modules/protocol/charybdis.cpp38
-rw-r--r--modules/protocol/hybrid.cpp48
-rw-r--r--modules/protocol/inspircd20.cpp49
-rw-r--r--modules/protocol/ngircd.cpp47
-rw-r--r--modules/protocol/plexus.cpp38
-rw-r--r--modules/protocol/ratbox.cpp42
-rw-r--r--modules/protocol/rfc1459.cpp509
-rw-r--r--modules/protocol/unreal.cpp49
9 files changed, 695 insertions, 172 deletions
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index a32a7606d..9b0adefb0 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -17,7 +17,10 @@
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
+/* Dependencies: anope_protocol.rfc1459 */
+
#include "module.h"
+#include "modules/protocol/rfc1459.h"
class ChannelModeFlood : public ChannelModeParam
{
@@ -435,14 +438,14 @@ struct IRCDMessageSJoin : IRCDMessage
if (!modes.empty())
modes.erase(modes.begin());
- std::list<Message::Join::SJoinUser> users;
+ std::list<rfc1459::Join::SJoinUser> users;
/* For some reason, bahamut will send a SJOIN from the user joining a channel
* if the channel already existed
*/
if (source.GetUser())
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
sju.second = source.GetUser();
users.push_back(sju);
}
@@ -453,7 +456,7 @@ struct IRCDMessageSJoin : IRCDMessage
while (sep.GetToken(buf))
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
/* Get prefixes from the nick */
for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));)
@@ -474,7 +477,7 @@ struct IRCDMessageSJoin : IRCDMessage
}
time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
- Message::Join::SJoin(source, params[1], ts, modes, users);
+ rfc1459::Join::SJoin(source, params[1], ts, modes, users);
}
};
@@ -496,24 +499,24 @@ class ProtoBahamut : public Module
BahamutIRCdProto ircd_proto;
/* Core message handlers */
- Message::Away message_away;
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Join message_join;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
IRCDMessageBurst message_burst;
diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp
index c69fbaf5f..105939df2 100644
--- a/modules/protocol/charybdis.cpp
+++ b/modules/protocol/charybdis.cpp
@@ -259,25 +259,25 @@ class ProtoCharybdis : public Module
CharybdisProto ircd_proto;
/* Core message handlers */
- Message::Away message_away;
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::Mode message_mode;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Topic message_topic;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::Mode message_mode;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Topic message_topic;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
hybrid::BMask message_bmask;
diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp
index c1d85bcf8..638a4037a 100644
--- a/modules/protocol/hybrid.cpp
+++ b/modules/protocol/hybrid.cpp
@@ -18,6 +18,8 @@
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
+/* Dependencies: anope_protocol.rfc1459 */
+
#include "module.h"
#include "modules/protocol/hybrid.h"
@@ -366,7 +368,7 @@ void hybrid::Join::Run(MessageSource &source, const std::vector<Anope::string> &
std::vector<Anope::string> p = params;
p.erase(p.begin());
- return Message::Join::Run(source, p);
+ return rfc1459::Join::Run(source, p);
}
/* 0 1 */
@@ -423,14 +425,14 @@ void hybrid::SJoin::Run(MessageSource &source, const std::vector<Anope::string>
if (!modes.empty())
modes.erase(modes.begin());
- std::list<Message::Join::SJoinUser> users;
+ std::list<rfc1459::Join::SJoinUser> users;
spacesepstream sep(params[params.size() - 1]);
Anope::string buf;
while (sep.GetToken(buf))
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
/* Get prefixes from the nick */
for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));)
@@ -450,7 +452,7 @@ void hybrid::SJoin::Run(MessageSource &source, const std::vector<Anope::string>
}
time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
- Message::Join::SJoin(source, params[1], ts, modes, users);
+ rfc1459::Join::SJoin(source, params[1], ts, modes, users);
}
/*
@@ -538,25 +540,25 @@ class ProtoHybrid : public Module
HybridProto ircd_proto;
/* Core message handlers */
- Message::Away message_away;
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::Mode message_mode;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Topic message_topic;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::Mode message_mode;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Topic message_topic;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
hybrid::CertFP message_certfp;
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index f8bf9b30e..a0f0e067f 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -17,10 +17,13 @@
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
+/* Dependencies: anope_protocol.rfc1459 */
+
#include "module.h"
#include "modules/sasl.h"
#include "modules/chanserv/mode.h"
#include "modules/chanserv/set.h"
+#include "modules/protocol/rfc1459.h"
struct SASLUser
{
@@ -628,9 +631,9 @@ namespace InspIRCdExtban
};
}
-struct IRCDMessageCapab : Message::Capab
+struct IRCDMessageCapab : rfc1459::Capab
{
- IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
+ IRCDMessageCapab(Module *creator) : rfc1459::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
@@ -790,7 +793,7 @@ struct IRCDMessageCapab : Message::Capab
Log() << "CHGIDENT missing, Usage disabled until module is loaded.";
}
- Message::Capab::Run(source, params);
+ rfc1459::Capab::Run(source, params);
}
};
@@ -885,13 +888,13 @@ struct IRCDMessageFJoin : IRCDMessage
modes.erase(modes.begin());
}
- std::list<Message::Join::SJoinUser> users;
+ std::list<rfc1459::Join::SJoinUser> users;
spacesepstream sep(params[params.size() - 1]);
Anope::string buf;
while (sep.GetToken(buf))
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
/* Loop through prefixes and find modes for them */
for (char c; (c = buf[0]) != ',' && c;)
@@ -914,7 +917,7 @@ struct IRCDMessageFJoin : IRCDMessage
}
time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime;
- Message::Join::SJoin(source, params[0], ts, modes, users);
+ rfc1459::Join::SJoin(source, params[0], ts, modes, users);
}
};
@@ -1249,9 +1252,9 @@ struct IRCDMessageServer : IRCDMessage
}
};
-struct IRCDMessageSQuit : Message::SQuit
+struct IRCDMessageSQuit : rfc1459::SQuit
{
- IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { }
+ IRCDMessageSQuit(Module *creator) : rfc1459::SQuit(creator) { }
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
@@ -1267,7 +1270,7 @@ struct IRCDMessageSQuit : Message::SQuit
IRCD->SendServer(s);
}
else
- Message::SQuit::Run(source, params);
+ rfc1459::SQuit::Run(source, params);
}
};
@@ -1344,20 +1347,20 @@ class ProtoInspIRCd20 : public Module
ServiceReference<ModeLocks> mlocks;
/* Core message handlers */
- Message::Away message_away;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::Stats message_stats;
- Message::Topic message_topic;
+ rfc1459::Away message_away;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Join message_join;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::Stats message_stats;
+ rfc1459::Topic message_topic;
/* Our message handlers */
IRCDMessageCapab message_capab;
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index aa2c23a80..be8225b96 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -18,7 +18,10 @@
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
+/* Dependencies: anope_protocol.rfc1459 */
+
#include "module.h"
+#include "modules/protocol/rfc1459.h"
class ngIRCdProto : public IRCDProto
{
@@ -291,9 +294,9 @@ struct IRCDMessageChaninfo : IRCDMessage
}
};
-struct IRCDMessageJoin : Message::Join
+struct IRCDMessageJoin : rfc1459::Join
{
- IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { }
+ IRCDMessageJoin(Module *creator) : rfc1459::Join(creator, "JOIN") { }
/*
* <@po||ux> DukeP: RFC 2813, 4.2.1: the JOIN command on server-server links
@@ -320,7 +323,7 @@ struct IRCDMessageJoin : Message::Join
std::vector<Anope::string> new_params;
new_params.push_back(channel);
- Message::Join::Run(source, new_params);
+ rfc1459::Join::Run(source, new_params);
if (!modes.empty())
{
@@ -492,14 +495,14 @@ struct IRCDMessageNJoin : IRCDMessage
*/
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
- std::list<Message::Join::SJoinUser> users;
+ std::list<rfc1459::Join::SJoinUser> users;
commasepstream sep(params[1]);
Anope::string buf;
while (sep.GetToken(buf))
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
/* Get prefixes from the nick */
for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));)
@@ -517,7 +520,7 @@ struct IRCDMessageNJoin : IRCDMessage
users.push_back(sju);
}
- Message::Join::SJoin(source, params[0], 0, "", users);
+ rfc1459::Join::SJoin(source, params[0], 0, "", users);
}
};
@@ -613,22 +616,22 @@ class ProtongIRCd : public Module
ngIRCdProto ircd_proto;
/* Core message handlers */
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg, message_squery;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg, message_squery;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
IRCDMessage005 message_005;
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index 02d2a4d6e..6a3fff270 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -294,25 +294,25 @@ class ProtoPlexus : public Module
PlexusProto ircd_proto;
/* Core message handlers */
- Message::Away message_away;
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::Mode message_mode;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Topic message_topic;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::Mode message_mode;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Topic message_topic;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
hybrid::BMask message_bmask;
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index 223902457..3620ad4e6 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -152,7 +152,7 @@ void ratbox::Encap::Run(MessageSource &source, const std::vector<Anope::string>
void ratbox::Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
{
if (params.size() == 1 && params[0] == "0")
- return Message::Join::Run(source, params);
+ return rfc1459::Join::Run(source, params);
if (params.size() < 2)
return;
@@ -160,7 +160,7 @@ void ratbox::Join::Run(MessageSource &source, const std::vector<Anope::string> &
std::vector<Anope::string> p = params;
p.erase(p.begin());
- return Message::Join::Run(source, p);
+ return rfc1459::Join::Run(source, p);
}
struct IRCDMessagePass : IRCDMessage
@@ -215,25 +215,25 @@ class ProtoRatbox : public Module
RatboxProto ircd_proto;
/* Core message handlers */
- Message::Away message_away;
- Message::Capab message_capab;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Kick message_kick;
- Message::Kill message_kill;
- Message::Mode message_mode;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Topic message_topic;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Capab message_capab;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill;
+ rfc1459::Mode message_mode;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Topic message_topic;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
hybrid::BMask message_bmask;
diff --git a/modules/protocol/rfc1459.cpp b/modules/protocol/rfc1459.cpp
new file mode 100644
index 000000000..22889c682
--- /dev/null
+++ b/modules/protocol/rfc1459.cpp
@@ -0,0 +1,509 @@
+/*
+ * Anope IRC Services
+ *
+ * Copyright (C) 2005-2016 Anope Team <team@anope.org>
+ *
+ * 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.
+ *
+ * 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 "module.h"
+#include "modules/protocol/rfc1459.h"
+#include "modules/operserv/stats.h"
+
+using namespace rfc1459;
+
+void Away::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &msg = !params.empty() ? params[0] : "";
+
+ EventManager::Get()->Dispatch(&Event::UserAway::OnUserAway, source.GetUser(), msg);
+
+ if (!msg.empty())
+ Log(source.GetUser(), "away") << "is now away: " << msg;
+ else
+ Log(source.GetUser(), "away") << "is no longer away";
+}
+
+void Capab::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ if (params.size() == 1)
+ {
+ spacesepstream sep(params[0]);
+ Anope::string token;
+ while (sep.GetToken(token))
+ Servers::Capab.insert(token);
+ }
+ else
+ for (unsigned i = 0; i < params.size(); ++i)
+ Servers::Capab.insert(params[i]);
+}
+
+void Error::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Log(LOG_TERMINAL) << "ERROR: " << params[0];
+ Anope::QuitReason = "Received ERROR from uplink: " + params[0];
+ Anope::Quitting = true;
+}
+
+void Invite::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *targ = User::Find(params[0]);
+ Channel *c = Channel::Find(params[1]);
+
+ if (!targ || targ->server != Me || !c || c->FindUser(targ))
+ return;
+
+ EventManager::Get()->Dispatch(&Event::Invite::OnInvite, source.GetUser(), c, targ);
+}
+
+void Join::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *user = source.GetUser();
+ const Anope::string &channels = params[0];
+
+ Anope::string channel;
+ commasepstream sep(channels);
+
+ while (sep.GetToken(channel))
+ {
+ /* Special case for /join 0 */
+ if (channel == "0")
+ {
+ for (User::ChanUserList::iterator it = user->chans.begin(), it_end = user->chans.end(); it != it_end; )
+ {
+ ChanUserContainer *cc = it->second;
+ Channel *c = cc->chan;
+ ++it;
+
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, user, c);
+ cc->chan->DeleteUser(user);
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, user, c, c->name, "");
+ }
+ continue;
+ }
+
+ std::list<SJoinUser> users;
+ users.push_back(std::make_pair(ChannelStatus(), user));
+
+ Channel *chan = Channel::Find(channel);
+ SJoin(source, channel, chan ? chan->creation_time : Anope::CurTime, "", users);
+ }
+}
+
+void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users)
+{
+ bool created;
+ Channel *c = Channel::FindOrCreate(chan, created, ts ? ts : Anope::CurTime);
+ bool keep_their_modes = true;
+
+ if (created)
+ c->syncing = true;
+ /* Some IRCds do not include a TS */
+ else if (!ts)
+ ;
+ /* Our creation time is newer than what the server gave us, so reset the channel to the older time */
+ else if (c->creation_time > ts)
+ {
+ c->creation_time = ts;
+ c->Reset();
+ }
+ /* 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;
+ User *u = it->second;
+ keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts
+
+ if (c->FindUser(u))
+ continue;
+
+ /* Add the user to the channel */
+ c->JoinUser(u, keep_their_modes ? &status : NULL);
+
+ /* Check if the user is allowed to join */
+ if (c->CheckKick(u))
+ continue;
+
+ /* Set whatever modes the user should have, and remove any that
+ * they aren't allowed to have (secureops etc).
+ */
+ c->SetCorrectModes(u, true);
+
+ EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, u, c);
+ }
+
+ /* Channel is done syncing */
+ if (c->syncing)
+ {
+ /* Sync the channel (mode lock, topic, etc) */
+ /* the channel is synced when the netmerge is complete */
+ Server *src = source.GetServer() ? source.GetServer() : Me;
+ if (src && src->IsSynced())
+ {
+ c->Sync();
+
+ if (c->CheckDelete())
+ c->QueueForDeletion();
+ }
+ }
+}
+
+void Kick::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &channel = params[0];
+ const Anope::string &users = params[1];
+ const Anope::string &reason = params.size() > 2 ? params[2] : "";
+
+ Channel *c = Channel::Find(channel);
+ if (!c)
+ return;
+
+ Anope::string user;
+ commasepstream sep(users);
+
+ while (sep.GetToken(user))
+ c->KickInternal(source, user, reason);
+}
+
+void Kill::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *u = User::Find(params[0]);
+ ServiceBot *bi;
+
+ if (!u)
+ return;
+
+ /* Recover if someone kills us. */
+ if (u->server == Me && (bi = dynamic_cast<ServiceBot *>(u)))
+ {
+ static time_t last_time = 0;
+
+ if (last_time == Anope::CurTime)
+ {
+ Anope::QuitReason = "Kill loop detected. Are Services U:Lined?";
+ Anope::Quitting = true;
+ return;
+ }
+ last_time = Anope::CurTime;
+
+ bi->OnKill();
+ }
+ else
+ u->KillInternal(source, params[1]);
+}
+
+void rfc1459::Mode::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Anope::string buf;
+ for (unsigned i = 1; i < params.size(); ++i)
+ buf += " " + params[i];
+
+ if (IRCD->IsChannelValid(params[0]))
+ {
+ Channel *c = Channel::Find(params[0]);
+
+ if (c)
+ c->SetModesInternal(source, buf.substr(1), 0);
+ }
+ else
+ {
+ User *u = User::Find(params[0]);
+
+ if (u)
+ u->SetModesInternal(source, "%s", buf.substr(1).c_str());
+ }
+}
+
+/* XXX We should cache the file somewhere not open/read/close it on every request */
+void MOTD::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Server *s = Server::Find(params[0]);
+ if (s != Me)
+ return;
+
+ 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());
+ char buf[BUFSIZE];
+ while (fgets(buf, sizeof(buf), f))
+ {
+ buf[strlen(buf) - 1] = 0;
+ IRCD->SendNumeric(372, source.GetSource(), ":- %s", buf);
+ }
+ fclose(f);
+ IRCD->SendNumeric(376, source.GetSource(), ":End of /MOTD command.");
+ }
+ else
+ IRCD->SendNumeric(422, source.GetSource(), ":- MOTD file not found! Please contact your IRC administrator.");
+}
+
+void Notice::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Anope::string message = params[1];
+
+ User *u = source.GetUser();
+
+ /* ignore channel notices */
+ if (!IRCD->IsChannelValid(params[0]))
+ {
+ ServiceBot *bi = ServiceBot::Find(params[0]);
+ if (!bi)
+ return;
+ EventManager::Get()->Dispatch(&Event::BotNotice::OnBotNotice, u, bi, message);
+ }
+}
+
+void Part::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *u = source.GetUser();
+ const Anope::string &reason = params.size() > 1 ? params[1] : "";
+
+ Anope::string channel;
+ commasepstream sep(params[0]);
+
+ while (sep.GetToken(channel))
+ {
+ Channel *c = Channel::Find(channel);
+
+ if (!c || !u->FindChannel(c))
+ continue;
+
+ Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason");
+
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, u, c);
+ c->DeleteUser(u);
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, u, c, c->name, reason);
+ }
+}
+
+void Ping::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ IRCD->SendPong(params.size() > 1 ? params[1] : Me->GetSID(), params[0]);
+}
+
+void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &receiver = params[0];
+ Anope::string message = params[1];
+
+ User *u = source.GetUser();
+
+ if (IRCD->IsChannelValid(receiver))
+ {
+ Channel *c = Channel::Find(receiver);
+ if (c)
+ {
+ EventManager::Get()->Dispatch(&Event::Privmsg::OnPrivmsg, u, c, message);
+ }
+ }
+ else
+ {
+ /* If a server is specified (nick@server format), make sure it matches
+ * us, and strip it off. */
+ Anope::string botname = receiver;
+ size_t s = receiver.find('@');
+ bool nick_only = false;
+ if (s != Anope::string::npos)
+ {
+ Anope::string servername(receiver.begin() + s + 1, receiver.end());
+ botname = botname.substr(0, s);
+ nick_only = true;
+ if (!servername.equals_ci(Me->GetName()))
+ return;
+ }
+ else if (!IRCD->RequiresID && Config->UseStrictPrivmsg)
+ {
+ ServiceBot *bi = ServiceBot::Find(receiver);
+ if (!bi)
+ return;
+ Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << u->nick;
+ u->SendMessage(bi, _("\"/msg %s\" is no longer supported. Use \"/msg %s@%s\" or \"/%s\" instead."), bi->nick.c_str(), bi->nick.c_str(), Me->GetName().c_str(), bi->nick.c_str());
+ return;
+ }
+
+ ServiceBot *bi = ServiceBot::Find(botname, nick_only);
+
+ if (bi)
+ {
+ if (message[0] == '\1' && message[message.length() - 1] == '\1')
+ {
+ if (message.substr(0, 6).equals_ci("\1PING "))
+ {
+ Anope::string buf = message;
+ buf.erase(buf.begin());
+ buf.erase(buf.end() - 1);
+ IRCD->SendCTCP(bi, u->nick, "%s", buf.c_str());
+ }
+ else if (message.substr(0, 9).equals_ci("\1VERSION\1"))
+ {
+ Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
+ IRCD->SendCTCP(bi, u->nick, "VERSION Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str());
+ }
+ return;
+ }
+
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message);
+ if (MOD_RESULT == EVENT_STOP)
+ return;
+
+ bi->OnMessage(u, message);
+ }
+ }
+
+ return;
+}
+
+void Quit::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ const Anope::string &reason = params[0];
+ User *user = source.GetUser();
+
+ Log(user, "quit") << "quit (Reason: " << (!reason.empty() ? reason : "no reason") << ")";
+
+ user->Quit(reason);
+}
+
+void SQuit::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Server *s = Server::Find(params[0]);
+
+ if (!s)
+ {
+ Log(LOG_DEBUG) << "SQUIT for nonexistent server " << params[0];
+ return;
+ }
+
+ if (s == Me)
+ {
+ if (Me->GetLinks().empty())
+ return;
+
+ s = Me->GetLinks().front();
+ }
+
+ s->Delete(s->GetName() + " " + s->GetUplink()->GetName());
+}
+
+void rfc1459::Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *u = source.GetUser();
+
+ switch (params[0][0])
+ {
+ case 'l':
+ if (u->HasMode("OPER"))
+ {
+ IRCD->SendNumeric(211, source.GetSource(), "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
+ IRCD->SendNumeric(211, source.GetSource(), "%s %d %d %d %d %d %d %ld", Config->Uplinks[Anope::CurrentUplink].host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - Anope::StartTime));
+ }
+
+ IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ break;
+ case 'o':
+ case 'O':
+ /* Check whether the user is an operator */
+ if (!u->HasMode("OPER") && Config->GetBlock("options")->Get<bool>("hidestatso"))
+ IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ else
+ {
+ 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]);
+ }
+
+ 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, s ? s->GetMaxUserCount() : 0);
+ IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ break;
+ } /* case 'u' */
+
+ default:
+ IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ }
+
+ return;
+}
+
+void Time::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ time_t t;
+ time(&t);
+ struct tm *tm = localtime(&t);
+ char buf[64];
+ strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
+ IRCD->SendNumeric(391, source.GetSource(), "%s :%s", Me->GetName().c_str(), buf);
+ return;
+}
+
+void Topic::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Channel *c = Channel::Find(params[0]);
+ if (c)
+ c->ChangeTopicInternal(source.GetUser(), source.GetSource(), params[1], Anope::CurTime);
+
+ return;
+}
+
+void Version::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
+ IRCD->SendNumeric(351, source.GetSource(), "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str());
+}
+
+void Whois::Run(MessageSource &source, const std::vector<Anope::string> &params)
+{
+ User *u = User::Find(params[0]);
+
+ if (u && u->server == Me)
+ {
+ 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<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());
+ }
+ else
+ IRCD->SendNumeric(401, source.GetSource(), "%s :No such user.", params[0].c_str());
+}
+
+class ProtoRFC1459 : public Module
+{
+ public:
+ ProtoRFC1459(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR)
+ {
+ }
+};
+
+MODULE_INIT(ProtoRFC1459)
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index d805e60cb..0f97da8ae 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -17,10 +17,13 @@
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
+/* Dependencies: anope_protocol.rfc1459 */
+
#include "module.h"
#include "modules/chanserv/mode.h"
#include "modules/sasl.h"
#include "modules/operserv/stats.h"
+#include "modules/protocol/rfc1459.h"
static Anope::string UplinkSID;
@@ -842,9 +845,9 @@ struct IRCDMessagePong : IRCDMessage
}
};
-struct IRCDMessageProtoctl : Message::Capab
+struct IRCDMessageProtoctl : rfc1459::Capab
{
- IRCDMessageProtoctl(Module *creator) : Message::Capab(creator, "PROTOCTL") { }
+ IRCDMessageProtoctl(Module *creator) : rfc1459::Capab(creator, "PROTOCTL") { }
void Run(MessageSource &source, const std::vector<Anope::string> &params) override
{
@@ -858,7 +861,7 @@ struct IRCDMessageProtoctl : Message::Capab
}
}
- Message::Capab::Run(source, params);
+ rfc1459::Capab::Run(source, params);
}
};
@@ -983,7 +986,7 @@ struct IRCDMessageSJoin : IRCDMessage
modes.erase(modes.begin());
std::list<Anope::string> bans, excepts, invites;
- std::list<Message::Join::SJoinUser> users;
+ std::list<rfc1459::Join::SJoinUser> users;
spacesepstream sep(params[params.size() - 1]);
Anope::string buf;
@@ -1009,7 +1012,7 @@ struct IRCDMessageSJoin : IRCDMessage
}
else
{
- Message::Join::SJoinUser sju;
+ rfc1459::Join::SJoinUser sju;
/* Get prefixes from the nick */
for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));)
@@ -1030,7 +1033,7 @@ struct IRCDMessageSJoin : IRCDMessage
}
time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime;
- Message::Join::SJoin(source, params[1], ts, modes, users);
+ rfc1459::Join::SJoin(source, params[1], ts, modes, users);
if (!bans.empty() || !excepts.empty() || !invites.empty())
{
@@ -1179,23 +1182,23 @@ class ProtoUnreal : public Module
ServiceReference<ModeLocks> mlocks;
/* Core message handlers */
- Message::Away message_away;
- Message::Error message_error;
- Message::Invite message_invite;
- Message::Join message_join;
- Message::Kick message_kick;
- Message::Kill message_kill, message_svskill;
- Message::MOTD message_motd;
- Message::Notice message_notice;
- Message::Part message_part;
- Message::Ping message_ping;
- Message::Privmsg message_privmsg;
- Message::Quit message_quit;
- Message::SQuit message_squit;
- Message::Stats message_stats;
- Message::Time message_time;
- Message::Version message_version;
- Message::Whois message_whois;
+ rfc1459::Away message_away;
+ rfc1459::Error message_error;
+ rfc1459::Invite message_invite;
+ rfc1459::Join message_join;
+ rfc1459::Kick message_kick;
+ rfc1459::Kill message_kill, message_svskill;
+ rfc1459::MOTD message_motd;
+ rfc1459::Notice message_notice;
+ rfc1459::Part message_part;
+ rfc1459::Ping message_ping;
+ rfc1459::Privmsg message_privmsg;
+ rfc1459::Quit message_quit;
+ rfc1459::SQuit message_squit;
+ rfc1459::Stats message_stats;
+ rfc1459::Time message_time;
+ rfc1459::Version message_version;
+ rfc1459::Whois message_whois;
/* Our message handlers */
IRCDMessageChgHost message_chghost;