From 76771aa05f7168ca02c217d3c6de36e84381eb5d Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 1 Dec 2016 19:46:06 -0500 Subject: Split more protocol module message handler declarations into module headers --- include/modules/protocol/bahamut.h | 73 +++ include/modules/protocol/charybdis.h | 4 +- include/modules/protocol/hybrid.h | 4 +- include/modules/protocol/inspircd20.h | 214 +++++++ include/modules/protocol/ngircd.h | 127 ++++ include/modules/protocol/plexus.h | 4 +- include/modules/protocol/ratbox.h | 4 +- include/modules/protocol/unreal.h | 187 ++++++ modules/protocol/bahamut.cpp | 249 ++++---- modules/protocol/charybdis.cpp | 16 +- modules/protocol/hybrid.cpp | 70 ++- modules/protocol/inspircd20.cpp | 1094 +++++++++++++++------------------ modules/protocol/ngircd.cpp | 655 +++++++++----------- modules/protocol/plexus.cpp | 6 +- modules/protocol/ratbox.cpp | 25 +- modules/protocol/rfc1459.cpp | 7 - modules/protocol/unreal.cpp | 787 +++++++++++------------- 17 files changed, 1974 insertions(+), 1552 deletions(-) create mode 100644 include/modules/protocol/bahamut.h create mode 100644 include/modules/protocol/inspircd20.h create mode 100644 include/modules/protocol/ngircd.h create mode 100644 include/modules/protocol/unreal.h diff --git a/include/modules/protocol/bahamut.h b/include/modules/protocol/bahamut.h new file mode 100644 index 000000000..634360f99 --- /dev/null +++ b/include/modules/protocol/bahamut.h @@ -0,0 +1,73 @@ +/* + * Anope IRC Services + * + * Copyright (C) 2003-2016 Anope Team + * + * 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 . + */ + +#pragma once + +namespace bahamut +{ + +class Burst : public IRCDMessage +{ + public: + Burst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Mode : public IRCDMessage +{ + public: + Mode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Nick : public IRCDMessage +{ + public: + Nick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ServerMessage : public IRCDMessage +{ + public: + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SJoin : public IRCDMessage +{ + public: + SJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Topic : public IRCDMessage +{ + public: + Topic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +} // namespace bahamut \ No newline at end of file diff --git a/include/modules/protocol/charybdis.h b/include/modules/protocol/charybdis.h index 36de05544..4d525c49d 100644 --- a/include/modules/protocol/charybdis.h +++ b/include/modules/protocol/charybdis.h @@ -40,10 +40,10 @@ class EUID : public IRCDMessage void Run(MessageSource &source, const std::vector ¶ms) override; }; -class Server : public IRCDMessage +class ServerMessage : public IRCDMessage { public: - Server(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } // SERVER dev.anope.de 1 :charybdis test server void Run(MessageSource &source, const std::vector ¶ms) override; diff --git a/include/modules/protocol/hybrid.h b/include/modules/protocol/hybrid.h index 76c84f33c..9c1444f4d 100644 --- a/include/modules/protocol/hybrid.h +++ b/include/modules/protocol/hybrid.h @@ -64,10 +64,10 @@ class Pong : public IRCDMessage void Run(MessageSource &source, const std::vector ¶ms) override; }; -class Server : public IRCDMessage +class ServerMessage : public IRCDMessage { public: - Server(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/inspircd20.h b/include/modules/protocol/inspircd20.h new file mode 100644 index 000000000..d65b174f9 --- /dev/null +++ b/include/modules/protocol/inspircd20.h @@ -0,0 +1,214 @@ +/* + * Anope IRC Services + * + * Copyright (C) 2016 Anope Team + * + * 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 . + */ + +#pragma once + +namespace inspircd20 +{ + +class Capab : public rfc1459::Capab +{ + public: + Capab(Module *creator) : rfc1459::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChgHost : public IRCDMessage +{ + public: + ChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChgIdent : public IRCDMessage +{ + public: + ChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChgName : public IRCDMessage +{ + public: + ChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Encap : public IRCDMessage +{ + public: + Encap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Endburst : public IRCDMessage +{ + public: + Endburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class FHost : public IRCDMessage +{ + public: + FHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class FIdent : public IRCDMessage +{ + public: + FIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class FJoin : public IRCDMessage +{ + public: + FJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class FMode : public IRCDMessage +{ + public: + FMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class FTopic : public IRCDMessage +{ + public: + FTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Idle : public IRCDMessage +{ + public: + Idle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Metadata : public IRCDMessage +{ + public: + const bool &do_topiclock, &do_mlock; + + Metadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) + : IRCDMessage(creator, "METADATA", 3) + , do_topiclock(handle_topiclock) + , do_mlock(handle_mlock) + { + SetFlag(IRCDMESSAGE_REQUIRE_SERVER); + } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Mode : public IRCDMessage +{ + public: + Mode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Nick : public IRCDMessage +{ + public: + Nick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class OperType : public IRCDMessage +{ + public: + OperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class RSQuit : public IRCDMessage +{ + public: + RSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Save : public IRCDMessage +{ + time_t last_collide = 0; + + public: + Save(Module *creator) : IRCDMessage(creator, "SAVE", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ServerMessage : public IRCDMessage +{ + public: + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SQuit : public rfc1459::SQuit +{ + public: + SQuit(Module *creator) : rfc1459::SQuit(creator) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Time : public IRCDMessage +{ + public: + Time(Module *creator) : IRCDMessage(creator, "TIME", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class UID : public IRCDMessage +{ + ServiceReference sasl; + + public: + UID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +} // namespace inspircd20 + diff --git a/include/modules/protocol/ngircd.h b/include/modules/protocol/ngircd.h new file mode 100644 index 000000000..0bfebea9f --- /dev/null +++ b/include/modules/protocol/ngircd.h @@ -0,0 +1,127 @@ +/* + * Anope IRC Services + * + * Copyright (C) 2011-2016 Anope Team + * Copyright (C) 2011-2012, 2014 Alexander Barton + * + * 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 . + */ + +#pragma once + +namespace ngircd +{ + +class Numeric005 : public IRCDMessage +{ + public: + Numeric005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + // Please see for details. + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChanInfo : public IRCDMessage +{ + public: + ChanInfo(Module *creator) : IRCDMessage(creator, "CHANINFO", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + /* + * CHANINFO is used by servers to inform each other about a channel: its + * modes, channel key, user limits and its topic. The parameter combination + * and is optional, as well as the parameter, so that + * there are three possible forms of this command: + * + * CHANINFO + + * CHANINFO + : + * CHANINFO + : + * + * The parameter must be ignored if a channel has no key (the parameter + * doesn't list the "k" channel mode). In this case should + * contain "*" because the parameter is required by the CHANINFO syntax + * and therefore can't be omitted. The parameter must be ignored when + * a channel has no user limit (the parameter doesn't list the "l" + * channel mode). In this case should be "0". + */ + void Run(MessageSource &source, const std::vector ¶ms); +}; + +class Join : public rfc1459::Join +{ + public: + Join(Module *creator) : rfc1459::Join(creator, "JOIN") { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Metadata : public IRCDMessage +{ + public: + Metadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Mode : public IRCDMessage +{ + public: + Mode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +struct Nick : public IRCDMessage +{ + public: + Nick(Module *creator) : IRCDMessage(creator, "NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class NJoin : public IRCDMessage +{ + public: + NJoin(Module *creator) : IRCDMessage(creator, "NJOIN",2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }; + + /* + * RFC 2813, 4.2.2: Njoin Message: + * The NJOIN message is used between servers only. + * It is used when two servers connect to each other to exchange + * the list of channel members for each channel. + * + * Even though the same function can be performed by using a succession + * of JOIN, this message SHOULD be used instead as it is more efficient. + * + * Received: :dev.anope.de NJOIN #test :DukeP2,@DukeP,%test,+test2 + */ + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Pong : public IRCDMessage +{ + public: + Pong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ServerMessage : public IRCDMessage +{ + public: + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +} // namespace ngircd \ No newline at end of file diff --git a/include/modules/protocol/plexus.h b/include/modules/protocol/plexus.h index d17725be4..b87f3e6c7 100644 --- a/include/modules/protocol/plexus.h +++ b/include/modules/protocol/plexus.h @@ -30,10 +30,10 @@ class Encap : public IRCDMessage void Run(MessageSource &source, const std::vector ¶ms) override; }; -class Server : public IRCDMessage +class ServerMessage : public IRCDMessage { public: - Server(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/ratbox.h b/include/modules/protocol/ratbox.h index e03846142..32710fbea 100644 --- a/include/modules/protocol/ratbox.h +++ b/include/modules/protocol/ratbox.h @@ -41,10 +41,10 @@ class Join : public rfc1459::Join void Run(MessageSource &source, const std::vector ¶ms) override; }; -class Server : public IRCDMessage +class ServerMessage : public IRCDMessage { public: - Server(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/unreal.h b/include/modules/protocol/unreal.h new file mode 100644 index 000000000..305d52bd0 --- /dev/null +++ b/include/modules/protocol/unreal.h @@ -0,0 +1,187 @@ +/* + * Anope IRC Services + * + * Copyright (C) 2003-2016 Anope Team + * + * 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 . + */ + +#pragma once + +namespace unreal +{ + +class ChgHost : public IRCDMessage +{ + public: + ChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChgIdent : public IRCDMessage +{ + public: + ChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ChgName : public IRCDMessage +{ + public: + ChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class MD : public IRCDMessage +{ + public: + MD(Module *creator) : IRCDMessage(creator, "MD", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Mode : public IRCDMessage +{ + public: + Mode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class NetInfo : public IRCDMessage +{ + public: + NetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Nick : public IRCDMessage +{ + public: + Nick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Pong : public IRCDMessage +{ + public: + Pong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Protoctl : public rfc1459::Capab +{ + public: + Protoctl(Module *creator) : rfc1459::Capab(creator, "PROTOCTL") { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SASL : public IRCDMessage +{ + ServiceReference<::SASL::Service> sasl; + + public: + SASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SDesc : public IRCDMessage +{ + public: + SDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SetHost : public IRCDMessage +{ + public: + SetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SetIdent : public IRCDMessage +{ + public: + SetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +struct SetName : IRCDMessage +{ + public: + SetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class ServerMessage : public IRCDMessage +{ + public: + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SID : public IRCDMessage +{ + public: + SID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class SJoin : public IRCDMessage +{ + public: + SJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Topic : public IRCDMessage +{ + public: + Topic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class UID : public IRCDMessage +{ + public: + UID(Module *creator) : IRCDMessage(creator, "UID", 12) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +class Umode2 : public IRCDMessage +{ + public: + Umode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector ¶ms) override; +}; + +} // namespace unreal diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 988cfaead..8e753b443 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -21,6 +21,7 @@ #include "module.h" #include "modules/protocol/rfc1459.h" +#include "modules/protocol/bahamut.h" class ChannelModeFlood : public ChannelModeParam { @@ -317,56 +318,39 @@ class BahamutIRCdProto : public IRCDProto } }; -struct IRCDMessageBurst : IRCDMessage +void bahamut::Burst::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageBurst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Server *s = source.GetServer(); + s->Sync(true); +} - void Run(MessageSource &source, const std::vector ¶ms) override - { - /* If we found a server with the given source, that one just - * finished bursting. If there was no source, then our uplink - * server finished bursting. -GD - */ - Server *s = source.GetServer(); - if (!s) - s = Me->GetLinks().front(); - if (s) - s->Sync(true); - } -}; - -struct IRCDMessageMode : IRCDMessage +void bahamut::Mode::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageMode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector ¶ms) override + if (params.size() > 2 && IRCD->IsChannelValid(params[0])) { - if (params.size() > 2 && IRCD->IsChannelValid(params[0])) - { - Channel *c = Channel::Find(params[0]); - time_t ts = 0; - - try - { - ts = convertTo(params[1]); - } - catch (const ConvertException &) { } - - Anope::string modes = params[2]; - for (unsigned int i = 3; i < params.size(); ++i) - modes += " " + params[i]; + Channel *c = Channel::Find(params[0]); + time_t ts = 0; - if (c) - c->SetModesInternal(source, modes, ts); - } - else + try { - User *u = User::Find(params[0]); - if (u) - u->SetModesInternal(source, "%s", params[1].c_str()); + ts = convertTo(params[1]); } + catch (const ConvertException &) { } + + Anope::string modes = params[2]; + for (unsigned int i = 3; i < params.size(); ++i) + modes += " " + params[i]; + + if (c) + c->SetModesInternal(source, modes, ts); } -}; + else + { + User *u = User::Find(params[0]); + if (u) + u->SetModesInternal(source, "%s", params[1].c_str()); + } +} /* ** NICK - new @@ -386,117 +370,128 @@ struct IRCDMessageMode : IRCDMessage ** parv[0] = new nickname ** parv[1] = hopcount */ -struct IRCDMessageNick : IRCDMessage +void bahamut::Nick::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector ¶ms) override + if (params.size() == 10) { - if (params.size() == 10) + Server *s = Server::Find(params[6]); + if (s == nullptr) { - Server *s = Server::Find(params[6]); - if (s == NULL) - { - Log(LOG_DEBUG) << "User " << params[0] << " introduced from non-existent server " << params[6] << "?"; - return; - } + Log(LOG_DEBUG) << "User " << params[0] << " introduced from non-existent server " << params[6] << "?"; + return; + } - NickServ::Nick *na = NULL; - time_t signon = params[2].is_pos_number_only() ? convertTo(params[2]) : 0, - stamp = params[7].is_pos_number_only() ? convertTo(params[7]) : 0; - if (signon && signon == stamp && NickServ::service) - na = NickServ::service->FindNick(params[0]); + NickServ::Nick *na = nullptr; + time_t signon = 0, stamp = 0; - User::OnIntroduce(params[0], params[4], params[5], "", params[8], s, params[9], signon, params[3], "", na ? na->GetAccount() : NULL); + try + { + signon = convertTo(params[2]); + stamp = convertTo(params[7]); } - else + catch (const ConvertException &) { - User *u = source.GetUser(); - - if (u) - u->ChangeNick(params[0]); } + + if (signon && signon == stamp && NickServ::service) + na = NickServ::service->FindNick(params[0]); + + User::OnIntroduce(params[0], params[4], params[5], "", params[8], s, params[9], signon, params[3], "", na ? na->GetAccount() : nullptr); } -}; + else + { + User *u = source.GetUser(); -struct IRCDMessageServer : IRCDMessage + if (u) + u->ChangeNick(params[0]); + } +} + +void bahamut::ServerMessage::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + unsigned int hops = 0; - void Run(MessageSource &source, const std::vector ¶ms) override + try { - unsigned int hops = Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : 0; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[2]); + hops = convertTo(params[1]); } -}; + catch (const ConvertException &) { } + + new Server(source.GetServer(), params[0], hops, params[2]); +} -struct IRCDMessageSJoin : IRCDMessage +void bahamut::SJoin::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Anope::string modes; + if (params.size() >= 4) + for (unsigned i = 2; i < params.size(); ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); - void Run(MessageSource &source, const std::vector ¶ms) override - { - Anope::string modes; - if (params.size() >= 4) - for (unsigned i = 2; i < params.size(); ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); + std::list users; - std::list users; + /* For some reason, bahamut will send a SJOIN from the user joining a channel + * if the channel already existed + */ + if (source.GetUser()) + { + rfc1459::Join::SJoinUser sju; + sju.second = source.GetUser(); + users.push_back(sju); + } + else + { + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; - /* For some reason, bahamut will send a SJOIN from the user joining a channel - * if the channel already existed - */ - if (source.GetUser()) + while (sep.GetToken(buf)) { rfc1459::Join::SJoinUser sju; - sju.second = source.GetUser(); - users.push_back(sju); - } - else - { - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) + /* Get prefixes from the nick */ + for (char ch; !buf.empty() && (ch = ModeManager::GetStatusChar(buf[0]));) + { + buf.erase(buf.begin()); + sju.first.AddMode(ch); + } + + sju.second = User::Find(buf); + if (!sju.second) { - rfc1459::Join::SJoinUser sju; - - /* Get prefixes from the nick */ - for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) - { - buf.erase(buf.begin()); - sju.first.AddMode(ch); - } - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; - continue; - } - - users.push_back(sju); + Log(LOG_DEBUG) << "SJOIN for non-existent user " << buf << " on " << params[1]; + continue; } + + users.push_back(sju); } + } + + time_t ts = Anope::CurTime; - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo(params[0]) : Anope::CurTime; - rfc1459::Join::SJoin(source, params[1], ts, modes, users); + try + { + ts = convertTo(params[0]); } -}; + catch (const ConvertException &) { } -struct IRCDMessageTopic : IRCDMessage + rfc1459::Join::SJoin(source, params[1], ts, modes, users); +} + +void bahamut::Topic::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } + Channel *c = Channel::Find(params[0]); + time_t ts = Anope::CurTime; - void Run(MessageSource &source, const std::vector ¶ms) override + try { - Channel *c = Channel::Find(params[0]); - if (c) - c->ChangeTopicInternal(source.GetUser(), params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo(params[2]) : Anope::CurTime); + ts = convertTo(params[2]); } -}; + catch (const ConvertException &) { } + + if (c) + c->ChangeTopicInternal(source.GetUser(), params[1], params[3], ts); +} class ProtoBahamut : public Module , public EventHook @@ -524,12 +519,12 @@ class ProtoBahamut : public Module rfc1459::Whois message_whois; /* Our message handlers */ - IRCDMessageBurst message_burst; - IRCDMessageMode message_mode, message_svsmode; - IRCDMessageNick message_nick; - IRCDMessageServer message_server; - IRCDMessageSJoin message_sjoin; - IRCDMessageTopic message_topic; + bahamut::Burst message_burst; + bahamut::Mode message_mode, message_svsmode; + bahamut::Nick message_nick; + bahamut::ServerMessage message_server; + bahamut::SJoin message_sjoin; + bahamut::Topic message_topic; public: ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR) diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index b13dc99fc..5cc9f4c62 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -233,17 +233,25 @@ void charybdis::EUID::Run(MessageSource &source, const std::vector(params[2]) : Anope::CurTime, params[3], params[7], na ? na->GetAccount() : NULL); + time_t ts = Anope::CurTime; + + try + { + ts = convertTo(params[2]); + } + catch (const ConvertException &) { } + + User::OnIntroduce(params[0], params[4], (params[8] != "*" ? params[8] : params[5]), params[5], params[6], source.GetServer(), params[10], ts, params[3], params[7], na ? na->GetAccount() : NULL); } // we can't use this function from ratbox because we set a local variable here // SERVER dev.anope.de 1 :charybdis test server -void charybdis::Server::Run(MessageSource &source, const std::vector ¶ms) +void charybdis::ServerMessage::Run(MessageSource &source, const std::vector ¶ms) { // Servers other then our immediate uplink are introduced via SID if (params[1] != "1") return; - new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); IRCD->SendPing(Me->GetName(), params[0]); } @@ -291,7 +299,7 @@ class ProtoCharybdis : public Module hybrid::Nick message_nick; charybdis::Pass message_pass; hybrid::Pong message_pong; - charybdis::Server message_server; + charybdis::ServerMessage message_server; hybrid::SID message_sid; hybrid::SJoin message_sjoin; ratbox::TB message_tb; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 638a4037a..c28c9ebf5 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -375,7 +375,15 @@ void hybrid::Join::Run(MessageSource &source, const std::vector & /* :0MCAAAAAB NICK newnick 1350157102 */ void hybrid::Nick::Run(MessageSource &source, const std::vector ¶ms) { - source.GetUser()->ChangeNick(params[0], convertTo(params[1])); + time_t ts = Anope::CurTime; + + try + { + ts = convertTo(params[1]); + } + catch (const ConvertException &) { } + + source.GetUser()->ChangeNick(params[0], ts); } struct IRCDMessagePass : IRCDMessage @@ -397,21 +405,28 @@ void hybrid::Pong::Run(MessageSource &source, const std::vector & /* 0 1 2 */ /* SERVER hades.arpa 1 :ircd-hybrid test server */ -void hybrid::Server::Run(MessageSource &source, const std::vector ¶ms) +void hybrid::ServerMessage::Run(MessageSource &source, const std::vector ¶ms) { /* Servers other than our immediate uplink are introduced via SID */ if (params[1] != "1") return; - new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); IRCD->SendPing(Me->GetName(), params[0]); } void hybrid::SID::Run(MessageSource &source, const std::vector ¶ms) { - unsigned int hops = params[1].is_pos_number_only() ? convertTo(params[1]) : 0; - new ::Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); + unsigned int hops = 0; + + try + { + hops = convertTo(params[1]); + } + catch (const ConvertException &) { } + + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); IRCD->SendPing(Me->GetName(), params[0]); } @@ -435,7 +450,7 @@ void hybrid::SJoin::Run(MessageSource &source, const std::vector rfc1459::Join::SJoinUser sju; /* Get prefixes from the nick */ - for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) + for (char ch; !buf.empty() && (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); sju.first.AddMode(ch); @@ -451,7 +466,14 @@ void hybrid::SJoin::Run(MessageSource &source, const std::vector users.push_back(sju); } - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo(params[0]) : Anope::CurTime; + time_t ts = Anope::CurTime; + + try + { + ts = convertTo(params[0]); + } + catch (const ConvertException &) { } + rfc1459::Join::SJoin(source, params[1], ts, modes, users); } @@ -467,7 +489,18 @@ void hybrid::SVSMode::Run(MessageSource &source, const std::vector(params[1]) != u->timestamp) + time_t ts; + + try + { + ts = convertTo(params[1]); + } + catch (const ConvertException &) + { + return; + } + + if (ts != u->timestamp) return; u->SetModesInternal(source, "%s", params[2].c_str()); @@ -477,9 +510,16 @@ void hybrid::TBurst::Run(MessageSource &source, const std::vector { Anope::string setter; sepstream(params[3], '!').GetToken(setter, 0); - time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo(params[2]) : Anope::CurTime; Channel *c = Channel::Find(params[1]); + time_t topic_time = Anope::CurTime; + + try + { + topic_time = convertTo(params[2]); + } + catch (const ConvertException &ex) { } + if (c) c->ChangeTopicInternal(NULL, setter, params[4], topic_time); } @@ -517,10 +557,18 @@ void hybrid::UID::Run(MessageSource &source, const std::vector &p if (params[8] != "0" && params[8] != "*") na = NickServ::FindNick(params[8]); + time_t ts = 0; + + try + { + ts = convertTo(params[2]); + } + catch (const ConvertException &) { } + /* Source is always the server */ User::OnIntroduce(params[0], params[4], params[5], "", ip, source.GetServer(), - params[9], params[2].is_pos_number_only() ? convertTo(params[2]) : 0, + params[9], ts, params[3], params[7], na ? na->GetAccount() : NULL); } @@ -568,7 +616,7 @@ class ProtoHybrid : public Module hybrid::Nick message_nick; IRCDMessagePass message_pass; hybrid::Pong message_pong; - hybrid::Server message_server; + hybrid::ServerMessage message_server; hybrid::SID message_sid; hybrid::SJoin message_sjoin; hybrid::SVSMode message_svsmode; diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index c2c09c95d..0f5469cea 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -24,6 +24,7 @@ #include "modules/chanserv/mode.h" #include "modules/chanserv/set.h" #include "modules/protocol/rfc1459.h" +#include "modules/protocol/inspircd20.h" struct SASLUser { @@ -631,380 +632,328 @@ namespace InspIRCdExtban }; } -struct IRCDMessageCapab : rfc1459::Capab +void inspircd20::Capab::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageCapab(Module *creator) : rfc1459::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector ¶ms) override + if (params[0].equals_cs("START")) { - if (params[0].equals_cs("START")) + if (params.size() >= 2) + spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : 0); + + if (spanningtree_proto_ver < 1202) { - if (params.size() >= 2) - spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : 0); + Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); + Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Anope::Quitting = true; + return; + } - if (spanningtree_proto_ver < 1202) - { - Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); - Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; - Anope::Quitting = true; - return; - } + /* reset CAPAB */ + Servers::Capab.insert("SERVERS"); + Servers::Capab.insert("CHGHOST"); + Servers::Capab.insert("CHGIDENT"); + Servers::Capab.insert("TOPICLOCK"); + IRCD->CanSVSHold = false; + } + else if (params[0].equals_cs("CHANMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; - /* reset CAPAB */ - Servers::Capab.insert("SERVERS"); - Servers::Capab.insert("CHGHOST"); - Servers::Capab.insert("CHGIDENT"); - Servers::Capab.insert("TOPICLOCK"); - IRCD->CanSVSHold = false; - } - else if (params[0].equals_cs("CHANMODES") && params.size() > 1) + while (ssep.GetToken(capab)) { - spacesepstream ssep(params[1]); - Anope::string capab; + if (capab.find('=') == Anope::string::npos) + continue; + + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); + char symbol = 0; + + if (modechar.empty()) + continue; - while (ssep.GetToken(capab)) + if (modechar.length() == 2) { - if (capab.find('=') == Anope::string::npos) - continue; - - Anope::string modename = capab.substr(0, capab.find('=')); - Anope::string modechar = capab.substr(capab.find('=') + 1); - char symbol = 0; - - if (modechar.empty()) - continue; - - if (modechar.length() == 2) - { - symbol = modechar[0]; - modechar = modechar.substr(1); - } - - ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); - if (cm == nullptr) - { - Log(this->GetOwner()) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar; - continue; - } - - char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast(cm))->symbol : 0; - if (symbol != modesymbol) - { - Log(this->GetOwner()) << "Warning: Channel mode " << modename << " has a misconfigured status character"; - continue; - } + symbol = modechar[0]; + modechar = modechar.substr(1); } - } - if (params[0].equals_cs("USERMODES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string capab; - while (ssep.GetToken(capab)) + ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); + if (cm == nullptr) { - if (capab.find('=') == Anope::string::npos) - continue; - - Anope::string modename = capab.substr(0, capab.find('=')); - Anope::string modechar = capab.substr(capab.find('=') + 1); - - if (modechar.empty()) - continue; - - UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); - if (um == nullptr) - { - Log(this->GetOwner()) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar; - continue; - } + Log(this->GetOwner()) << "Warning: Uplink has unknown channel mode " << modename << "=" << modechar; + continue; } - } - else if (params[0].equals_cs("MODULES") && params.size() > 1) - { - spacesepstream ssep(params[1]); - Anope::string module; - while (ssep.GetToken(module)) + char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast(cm))->symbol : 0; + if (symbol != modesymbol) { - if (module.equals_cs("m_svshold.so")) - IRCD->CanSVSHold = true; - else if (module.find("m_rline.so") == 0) - { - Servers::Capab.insert("RLINE"); - const Anope::string ®exengine = Config->GetBlock("options")->Get("regexengine"); - if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) - Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies."; - } - else if (module.equals_cs("m_topiclock.so")) - Servers::Capab.insert("TOPICLOCK"); + Log(this->GetOwner()) << "Warning: Channel mode " << modename << " has a misconfigured status character"; + continue; } } - else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1) + } + if (params[0].equals_cs("USERMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + + while (ssep.GetToken(capab)) { - spacesepstream ssep(params[1]); - Anope::string module; + if (capab.find('=') == Anope::string::npos) + continue; - while (ssep.GetToken(module)) + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); + + if (modechar.empty()) + continue; + + UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); + if (um == nullptr) { - if (module.equals_cs("m_services_account.so")) - Servers::Capab.insert("SERVICES"); - else if (module.equals_cs("m_chghost.so")) - Servers::Capab.insert("CHGHOST"); - else if (module.equals_cs("m_chgident.so")) - Servers::Capab.insert("CHGIDENT"); + Log(this->GetOwner()) << "Warning: Uplink has unknown user mode " << modename << "=" << modechar; + continue; } } - else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) + } + else if (params[0].equals_cs("MODULES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string module; + + while (ssep.GetToken(module)) { - spacesepstream ssep(params[1]); - Anope::string capab; - while (ssep.GetToken(capab)) + if (module.equals_cs("m_svshold.so")) + IRCD->CanSVSHold = true; + else if (module.find("m_rline.so") == 0) { - if (capab.find("MAXMODES=") != Anope::string::npos) - { - Anope::string maxmodes(capab.begin() + 9, capab.end()); - IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo(maxmodes) : 3; - } - else if (capab == "GLOBOPS=1") - Servers::Capab.insert("GLOBOPS"); + Servers::Capab.insert("RLINE"); + const Anope::string ®exengine = Config->GetBlock("options")->Get("regexengine"); + if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) + Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << regexengine << ". This may cause inconsistencies."; } + else if (module.equals_cs("m_topiclock.so")) + Servers::Capab.insert("TOPICLOCK"); } - else if (params[0].equals_cs("END")) + } + else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string module; + + while (ssep.GetToken(module)) { - if (!Servers::Capab.count("SERVICES")) + if (module.equals_cs("m_services_account.so")) + Servers::Capab.insert("SERVICES"); + else if (module.equals_cs("m_chghost.so")) + Servers::Capab.insert("CHGHOST"); + else if (module.equals_cs("m_chgident.so")) + Servers::Capab.insert("CHGIDENT"); + } + } + else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + while (ssep.GetToken(capab)) + { + if (capab.find("MAXMODES=") != Anope::string::npos) { - Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); - Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; - Anope::Quitting = true; - return; + Anope::string maxmodes(capab.begin() + 9, capab.end()); + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo(maxmodes) : 3; } - if (!ModeManager::FindUserModeByName("PRIV")) - { - Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); - Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; - Anope::Quitting = true; - return; - } - if (!IRCD->CanSVSHold) - Log() << "SVSHOLD missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGHOST")) - Log() << "CHGHOST missing, Usage disabled until module is loaded."; - if (!Servers::Capab.count("CHGIDENT")) - Log() << "CHGIDENT missing, Usage disabled until module is loaded."; + else if (capab == "GLOBOPS=1") + Servers::Capab.insert("GLOBOPS"); } - - rfc1459::Capab::Run(source, params); } -}; - -struct IRCDMessageChgHost : IRCDMessage -{ - IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } - - void Run(MessageSource &source, const std::vector ¶ms) override + else if (params[0].equals_cs("END")) { - User *u = User::Find(params[0]); - if (!u || u->server != Me) + if (!Servers::Capab.count("SERVICES")) + { + Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; + Anope::Quitting = true; return; - - u->SetDisplayedHost(params[1]); - Uplink::Send(u, "FHOST", params[1]); + } + if (!ModeManager::FindUserModeByName("PRIV")) + { + Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; + return; + } + if (!IRCD->CanSVSHold) + Log() << "SVSHOLD missing, Usage disabled until module is loaded."; + if (!Servers::Capab.count("CHGHOST")) + Log() << "CHGHOST missing, Usage disabled until module is loaded."; + if (!Servers::Capab.count("CHGIDENT")) + Log() << "CHGIDENT missing, Usage disabled until module is loaded."; } -}; -struct IRCDMessageChgIdent : IRCDMessage -{ - IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } + rfc1459::Capab::Run(source, params); +} - void Run(MessageSource &source, const std::vector ¶ms) override - { - User *u = User::Find(params[0]); - if (!u || u->server != Me) - return; +void inspircd20::ChgHost::Run(MessageSource &source, const std::vector ¶ms) +{ + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - u->SetIdent(params[1]); - Uplink::Send(u, "FIDENT", params[1]); - } -}; + u->SetDisplayedHost(params[1]); + Uplink::Send(u, "FHOST", params[1]); +} -struct IRCDMessageChgName : IRCDMessage +void inspircd20::ChgIdent::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - void Run(MessageSource &source, const std::vector ¶ms) override - { - User *u = User::Find(params[0]); - if (!u || u->server != Me) - return; - - u->SetRealname(params[1]); - Uplink::Send(u, "FNAME", params[1]); - } -}; + u->SetIdent(params[1]); + Uplink::Send(u, "FIDENT", params[1]); +} -struct IRCDMessageEncap : IRCDMessage +void inspircd20::ChgName::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - void Run(MessageSource &source, const std::vector ¶ms) override - { - if (Anope::Match(Me->GetSID(), params[0]) == false) - return; + u->SetRealname(params[1]); + Uplink::Send(u, "FNAME", params[1]); +} - const Anope::string &command = params[1]; - std::vector encap_params(params.begin() + 2, params.end()); +void inspircd20::Encap::Run(MessageSource &source, const std::vector ¶ms) +{ + if (Anope::Match(Me->GetSID(), params[0]) == false) + return; - Anope::ProcessCommand(source, command, encap_params); - } -}; + const Anope::string &command = params[1]; + std::vector encap_params(params.begin() + 2, params.end()); -struct IRCDMessageEndburst : IRCDMessage -{ - IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + Anope::ProcessCommand(source, command, encap_params); +} - void Run(MessageSource &source, const std::vector ¶ms) override - { - Server *s = source.GetServer(); +void inspircd20::Endburst::Run(MessageSource &source, const std::vector ¶ms) +{ + Server *s = source.GetServer(); - Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName(); + Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName(); - s->Sync(true); - } -}; + s->Sync(true); +} -struct IRCDMessageFHost : IRCDMessage +void inspircd20::FHost::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageFHost(Module *creator) : IRCDMessage(creator, "FHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - void Run(MessageSource &source, const std::vector ¶ms) override - { - User *u = source.GetUser(); - if (u->HasMode("CLOAK")) - u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK")); - u->SetDisplayedHost(params[0]); - } -}; + User *u = source.GetUser(); + if (u->HasMode("CLOAK")) + u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK")); + u->SetDisplayedHost(params[0]); +} -struct IRCDMessageFIdent : IRCDMessage +void inspircd20::FIdent::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + source.GetUser()->SetIdent(params[0]); +} - void Run(MessageSource &source, const std::vector ¶ms) override +void inspircd20::FJoin::Run(MessageSource &source, const std::vector ¶ms) +{ + Anope::string modes; + if (params.size() >= 3) { - source.GetUser()->SetIdent(params[0]); + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); } -}; -struct IRCDMessageFJoin : IRCDMessage -{ - IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + std::list users; - void Run(MessageSource &source, const std::vector ¶ms) override + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) { - Anope::string modes; - if (params.size() >= 3) + rfc1459::Join::SJoinUser sju; + + /* Loop through prefixes and find modes for them */ + for (char c; !buf.empty() && (c = buf[0]) != ',';) { - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); + buf.erase(buf.begin()); + sju.first.AddMode(c); } + /* Erase the , */ + if (!buf.empty()) + buf.erase(buf.begin()); - std::list users; - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) + sju.second = User::Find(buf); + if (!sju.second) { - rfc1459::Join::SJoinUser sju; - - /* Loop through prefixes and find modes for them */ - for (char c; (c = buf[0]) != ',' && c;) - { - buf.erase(buf.begin()); - sju.first.AddMode(c); - } - /* Erase the , */ - if (!buf.empty()) - buf.erase(buf.begin()); - - sju.second = User::Find(buf); - if (!sju.second) - { - Log(LOG_DEBUG) << "FJOIN for non-existent user " << buf << " on " << params[0]; - continue; - } - - users.push_back(sju); + Log(LOG_DEBUG) << "FJOIN for non-existent user " << buf << " on " << params[0]; + continue; } - time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : Anope::CurTime; - rfc1459::Join::SJoin(source, params[0], ts, modes, users); + users.push_back(sju); } -}; -struct IRCDMessageFMode : IRCDMessage -{ - IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - void Run(MessageSource &source, const std::vector ¶ms) override - { - /* :source FMODE #test 12345678 +nto foo */ + time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : Anope::CurTime; + rfc1459::Join::SJoin(source, params[0], ts, modes, users); +} - Anope::string modes = params[2]; - for (unsigned n = 3; n < params.size(); ++n) - modes += " " + params[n]; +void inspircd20::FMode::Run(MessageSource &source, const std::vector ¶ms) +{ + /* :source FMODE #test 12345678 +nto foo */ - Channel *c = Channel::Find(params[0]); - time_t ts; + Anope::string modes = params[2]; + for (unsigned n = 3; n < params.size(); ++n) + modes += " " + params[n]; - try - { - ts = convertTo(params[1]); - } - catch (const ConvertException &) - { - ts = 0; - } + Channel *c = Channel::Find(params[0]); + time_t ts; - if (c) - c->SetModesInternal(source, modes, ts); + try + { + ts = convertTo(params[1]); + } + catch (const ConvertException &) + { + ts = 0; } -}; -struct IRCDMessageFTopic : IRCDMessage + if (c) + c->SetModesInternal(source, modes, ts); +} + +void inspircd20::FTopic::Run(MessageSource &source, const std::vector ¶ms) { - IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } + /* :source FTOPIC channel topicts setby :topic */ - void Run(MessageSource &source, const std::vector ¶ms) override - { - /* :source FTOPIC channel topicts setby :topic */ + Channel *c = Channel::Find(params[0]); + time_t ts = Anope::CurTime; - Channel *c = Channel::Find(params[0]); - if (c) - c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo(params[1]) : Anope::CurTime); + try + { + ts = convertTo(params[1]); } -}; + catch (const ConvertException &) { } -struct IRCDMessageIdle : IRCDMessage -{ - IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } + if (c) + c->ChangeTopicInternal(NULL, params[2], params[3], ts); +} - void Run(MessageSource &source, const std::vector ¶ms) override +void inspircd20::Idle::Run(MessageSource &source, const std::vector ¶ms) +{ + ServiceBot *bi = ServiceBot::Find(params[0]); + if (bi) { - ServiceBot *bi = ServiceBot::Find(params[0]); - if (bi) - { - Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg); - } - else - { - User *u = User::Find(params[0]); - if (u && u->server == Me) - Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0); - } + Uplink::Send(bi, "IDLE", source.GetSource(), Anope::StartTime, Anope::CurTime - bi->lastmsg); } -}; + else + { + User *u = User::Find(params[0]); + if (u && u->server == Me) + Uplink::Send(u, "IDLE", source.GetSource(), Anope::StartTime, 0); + } +} /* * source = numeric of the sending server @@ -1012,349 +961,304 @@ struct IRCDMessageIdle : IRCDMessage * params[1] = metadata name * params[2] = data */ -struct IRCDMessageMetadata : IRCDMessage +void inspircd20::Metadata::Run(MessageSource &source, const std::vector ¶ms) { - const bool &do_topiclock, &do_mlock; - - IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) - : IRCDMessage(creator, "METADATA", 3) - , do_topiclock(handle_topiclock) - , do_mlock(handle_mlock) - { - SetFlag(IRCDMESSAGE_REQUIRE_SERVER); - } - - void Run(MessageSource &source, const std::vector ¶ms) override + if (isdigit(params[0][0])) { - if (isdigit(params[0][0])) + if (params[1].equals_cs("accountname")) { - if (params[1].equals_cs("accountname")) - { - User *u = User::Find(params[0]); - NickServ::Account *nc = NickServ::FindAccount(params[2]); - if (u && nc) - u->Login(nc); - } + User *u = User::Find(params[0]); + NickServ::Account *nc = NickServ::FindAccount(params[2]); + if (u && nc) + u->Login(nc); + } - /* - * possible incoming ssl_cert messages: - * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> - * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) - */ - else if (params[1].equals_cs("ssl_cert")) + /* + * possible incoming ssl_cert messages: + * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> + * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) + */ + else if (params[1].equals_cs("ssl_cert")) + { + User *u = User::Find(params[0]); + if (!u) + return; + u->Extend("ssl", true); + Anope::string data = params[2].c_str(); + size_t pos1 = data.find(' ') + 1; + size_t pos2 = data.find(' ', pos1); + if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. { - User *u = User::Find(params[0]); - if (!u) - return; - u->Extend("ssl", true); - Anope::string data = params[2].c_str(); - size_t pos1 = data.find(' ') + 1; - size_t pos2 = data.find(' ', pos1); - if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. - { - u->fingerprint = data.substr(pos1, pos2 - pos1); - } - EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); + u->fingerprint = data.substr(pos1, pos2 - pos1); } + EventManager::Get()->Dispatch(&Event::Fingerprint::OnFingerprint, u); } - // We deliberately ignore non-bursting servers to avoid pseudoserver fights - else if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + } + // We deliberately ignore non-bursting servers to avoid pseudoserver fights + else if ((params[0][0] == '#') && (!source.GetServer()->IsSynced())) + { + Channel *c = Channel::Find(params[0]); + if (c && c->ci) { - Channel *c = Channel::Find(params[0]); - if (c && c->ci) + if ((do_mlock) && (params[1] == "mlock")) + { + ModeLocks *modelocks = c->ci->GetExt("modelocks"); + Anope::string modes; + if (modelocks) + modes = modelocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); + + // Mode lock string is not what we say it is? + if (modes != params[2]) + Uplink::Send(Me, "METADATA", c->name, "mlock", modes); + } + else if ((do_topiclock) && (params[1] == "topiclock")) { - if ((do_mlock) && (params[1] == "mlock")) - { - ModeLocks *modelocks = c->ci->GetExt("modelocks"); - Anope::string modes; - if (modelocks) - modes = modelocks->GetMLockAsString(c->ci, false).replace_all_cs("+", "").replace_all_cs("-", ""); - - // Mode lock string is not what we say it is? - if (modes != params[2]) - Uplink::Send(Me, "METADATA", c->name, "mlock", modes); - } - else if ((do_topiclock) && (params[1] == "topiclock")) - { - bool mystate = c->ci->IsTopicLock(); - bool serverstate = (params[2] == "1"); - if (mystate != serverstate) - Uplink::Send(Me, "METADATA", c->name, "topiclock", mystate ? "1" : ""); - } + bool mystate = c->ci->IsTopicLock(); + bool serverstate = (params[2] == "1"); + if (mystate != serverstate) + Uplink::Send(Me, "METADATA", c->name, "topiclock", mysta