/* * InspIRCd -- Internet Relay Chat Daemon * * Copyright (C) 2013, 2018-2019, 2021-2024 Sadie Powell * Copyright (C) 2012-2016 Attila Molnar * Copyright (C) 2012 Robby * Copyright (C) 2010 Daniel De Graaf * * This file is part of InspIRCd. InspIRCd 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 . */ #pragma once #include "servercommand.h" #include "commandbuilder.h" #include "remoteuser.h" #include "modules/away.h" namespace SpanningTree { class CommandAway; class CommandNick; class CommandPing; class CommandPong; class CommandServer; } using SpanningTree::CommandAway; using SpanningTree::CommandNick; using SpanningTree::CommandPing; using SpanningTree::CommandPong; using SpanningTree::CommandServer; class CommandRConnect final : public Command { public: CommandRConnect(Module* Creator); CmdResult Handle(User* user, const Params& parameters) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override; }; class CommandRSQuit final : public Command { public: CommandRSQuit(Module* Creator); CmdResult Handle(User* user, const Params& parameters) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override; }; class CommandMap final : public Command { public: CommandMap(Module* Creator); CmdResult Handle(User* user, const Params& parameters) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override; }; class CommandMetadata final : public ServerCommand { public: CommandMetadata(Module* Creator) : ServerCommand(Creator, "METADATA", 2) { } CmdResult Handle(User* user, Params& params) override; class Builder final : public CmdBuilder { public: Builder(const Extensible* ext, const std::string& key, const std::string& val); Builder(const std::string& key, const std::string& val); }; }; class CommandUID final : public ServerOnlyServerCommand { public: CommandUID(Module* Creator) : ServerOnlyServerCommand(Creator, "UID", 11) { } CmdResult HandleServer(TreeServer* server, CommandBase::Params& params); class Builder final : public CmdBuilder { public: Builder(User* user); }; }; class CommandOpertype final : public UserOnlyServerCommand { public: CommandOpertype(Module* Creator) : UserOnlyServerCommand(Creator, "OPERTYPE", 1) { } CmdResult HandleRemote(RemoteUser* user, Params& params); class Builder final : public CmdBuilder { public: Builder(User* user, const std::shared_ptr& oper, bool automatic = false); }; }; class TreeSocket; class FwdFJoinBuilder; class CommandFJoin final : public ServerCommand { /** Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes. * This does not update the timestamp of the target channel, this must be done separately. */ static void RemoveStatus(Channel* c); /** * Lowers the TS on the given channel: removes all modes, unsets all extensions, * clears the topic and removes all pending invites. * @param chan The target channel whose TS to lower * @param TS The new TS to set * @param newname The new name of the channel; must be the same or a case change of the current name */ static void LowerTS(Channel* chan, time_t TS, const std::string& newname); static void ProcessModeUUIDPair(const std::string& item, TreeServer* sourceserver, Channel* chan, Modes::ChangeList* modechangelist, FwdFJoinBuilder& fwdfjoin); public: CommandFJoin(Module* Creator) : ServerCommand(Creator, "FJOIN", 3) { } CmdResult Handle(User* user, Params& params) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override { return ROUTE_LOCALONLY; } class Builder : public CmdBuilder { /** Maximum possible Membership::Id length in decimal digits, used for determining whether a user will fit into * a message or not */ static constexpr size_t membid_max_digits = 20; static constexpr size_t maxline = 510; std::string::size_type pos; protected: void add(Membership* memb, std::string::const_iterator mbegin, std::string::const_iterator mend); public: Builder(Channel* chan, TreeServer* source = Utils->TreeRoot); void add(Membership* memb) { const std::string modes = memb->GetAllPrefixModes(); add(memb, modes.begin(), modes.end()); } void clear(); const std::string& finalize(); }; }; class CommandFMode final : public ServerCommand { public: CommandFMode(Module* Creator) : ServerCommand(Creator, "FMODE", 3) { } CmdResult Handle(User* user, Params& params) override; }; class CommandFTopic final : public ServerCommand { public: CommandFTopic(Module* Creator) : ServerCommand(Creator, "FTOPIC", 4, 5) { } CmdResult Handle(User* user, Params& params) override; class Builder final : public CmdBuilder { public: Builder(Channel* chan); Builder(User* user, Channel* chan); }; }; class CommandFHost final : public UserOnlyServerCommand { public: CommandFHost(Module* Creator) : UserOnlyServerCommand(Creator, "FHOST", 2) { } CmdResult HandleRemote(RemoteUser* user, Params& params); }; class CommandFIdent final : public UserOnlyServerCommand { public: CommandFIdent(Module* Creator) : UserOnlyServerCommand(Creator, "FIDENT", 2) { } CmdResult HandleRemote(RemoteUser* user, Params& params); }; class CommandFName final : public UserOnlyServerCommand { public: CommandFName(Module* Creator) : UserOnlyServerCommand(Creator, "FNAME", 1) { } CmdResult HandleRemote(RemoteUser* user, Params& params); }; class CommandIJoin final : public UserOnlyServerCommand { public: CommandIJoin(Module* Creator) : UserOnlyServerCommand(Creator, "IJOIN", 2) { } CmdResult HandleRemote(RemoteUser* user, Params& params); }; class CommandResync final : public ServerOnlyServerCommand { public: CommandResync(Module* Creator) : ServerOnlyServerCommand(Creator, "RESYNC", 1) { } CmdResult HandleServer(TreeServer* server, Params& parameters); RouteDescriptor GetRouting(User* user, const Params& parameters) override { return ROUTE_LOCALONLY; } }; class SpanningTree::CommandAway final : public UserOnlyServerCommand { private: Away::EventProvider awayevprov; public: CommandAway(Module* Creator) : UserOnlyServerCommand(Creator, "AWAY", 0, 2) , awayevprov(Creator) { } CmdResult HandleRemote(::RemoteUser* user, Params& parameters); class Builder final : public CmdBuilder { public: Builder(User* user); }; }; class XLine; class CommandAddLine final : public ServerCommand { public: CommandAddLine(Module* Creator) : ServerCommand(Creator, "ADDLINE", 6, 6) { } CmdResult Handle(User* user, Params& parameters) override; class Builder final : public CmdBuilder { public: Builder(XLine* xline, User* user = ServerInstance->FakeClient); }; }; class CommandDelLine final : public ServerCommand { public: CommandDelLine(Module* Creator) : ServerCommand(Creator, "DELLINE", 2, 2) { } CmdResult Handle(User* user, Params& parameters) override; }; class CommandEncap final : public ServerCommand { public: CommandEncap(Module* Creator) : ServerCommand(Creator, "ENCAP", 2) { } CmdResult Handle(User* user, Params& parameters) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override; }; class CommandIdle final : public UserOnlyServerCommand { public: CommandIdle(Module* Creator) : UserOnlyServerCommand(Creator, "IDLE", 1) { } CmdResult HandleRemote(RemoteUser* user, Params& parameters); RouteDescriptor GetRouting(User* user, const Params& parameters) override { return ROUTE_UNICAST(parameters[0]); } }; class SpanningTree::CommandNick final : public UserOnlyServerCommand { public: CommandNick(Module* Creator) : UserOnlyServerCommand(Creator, "NICK", 2) { } CmdResult HandleRemote(::RemoteUser* user, Params& parameters); }; class SpanningTree::CommandPing final : public ServerCommand { public: CommandPing(Module* Creator) : ServerCommand(Creator, "PING", 1) { } CmdResult Handle(User* user, Params& parameters) override; RouteDescriptor GetRouting(User* user, const Params& parameters) override { return ROUTE_UNICAST(parameters[0]); } }; class SpanningTree::CommandPong final : public ServerOnlyServerCommand { public: CommandPong(Module* Creator) : ServerOnlyServerCommand(Creator, "PONG", 1) { } CmdResult HandleServer(TreeServer* server, Params& parameters); RouteDescriptor GetRouting(User* user, const Params& parameters) override { return ROUTE_UNICAST(parameters[0]); } }; class DllExport CommandSave final : public ServerCommand { public: /** Timestamp of the uuid nick of all users who collided and got their nick changed to uuid */ static constexpr time_t SavedTimestamp = 100; CommandSave(Module* Creator) : ServerCommand(Creator, "SAVE", 2) { } CmdResult Handle(User* user, Params& parameters) override; }; class SpanningTree::CommandServer final : public ServerOnlyServerCommand { static void HandleExtra(TreeServer* newserver, Params& params); public: CommandServer(Module* Creator) : ServerOnlyServerCommand(Creator, "SERVER", 3) { } CmdResult HandleServer(TreeServer* server, Params& parameters); class Builder final : public CmdBuilder { void push_property(const char* key, const std::string& val) { push(key).push_raw('=').push_raw(val); } public: Builder(TreeServer* server); }; }; class CommandSQuit final : public ServerOnlyServerCommand { public: CommandSQuit(Module* Creator) : ServerOnlyServerCommand(Creator, "SQUIT", 2) { } CmdResult HandleServer(TreeServer* server, Params& parameters); }; class CommandSNONotice final : public ServerCommand { public: CommandSNONotice(Module* Creator) : ServerCommand(Creator, "SNONOTICE", 2) { } CmdResult Handle(User* user, Params& parameters) override; }; class CommandEndBurst final : public ServerOnlyServerCommand { public: CommandEndBurst(Module* Creator) : ServerOnlyServerCommand(Creator, "ENDBURST") { } CmdResult HandleServer(TreeServer* server, Params& parameters); }; class CommandSInfo final : public ServerOnlyServerCommand { public: CommandSInfo(Module* Creator) : ServerOnlyServerCommand(Creator, "SINFO", 2) { } CmdResult HandleServer(TreeServer* server, Params& parameters); class Builder final : public CmdBuilder { public: Builder(TreeServer* server, const char* type, const std::string& value); }; }; class CommandNum final : public ServerOnlyServerCommand { public: CommandNum(Module* Creator) : ServerOnlyServerCommand(Creator, "NUM", 3) { } CmdResult HandleServer(TreeServer* server, Params& parameters); RouteDescriptor GetRouting(User* user, const Params& parameters) override; class Builder final : public CmdBuilder { public: Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric); }; }; class CommandLMode final : public ServerCommand { public: CommandLMode(Module* Creator) : ServerCommand(Creator, "LMODE", 3) { } CmdResult Handle(User* user, Params& params) override; }; class SpanningTreeCommands final { public: CommandMetadata metadata; CommandUID uid; CommandOpertype opertype; CommandFJoin fjoin; CommandIJoin ijoin; CommandResync resync; CommandFMode fmode; CommandFTopic ftopic; CommandFHost fhost; CommandFHost frhost; CommandFIdent fident; CommandFName fname; SpanningTree::CommandAway away; CommandAddLine addline; CommandDelLine delline; CommandEncap encap; CommandIdle idle; SpanningTree::CommandNick nick; SpanningTree::CommandPing ping; SpanningTree::CommandPong pong; CommandSave save; SpanningTree::CommandServer server; CommandSQuit squit; CommandSNONotice snonotice; CommandEndBurst endburst; CommandSInfo sinfo; CommandNum num; CommandLMode lmode; SpanningTreeCommands(ModuleSpanningTree* module); };