diff options
author | Sadie Powell <sadie@witchery.services> | 2024-02-26 22:46:10 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-02-26 23:56:07 +0000 |
commit | 1e87849e5c218cc3d99e259f9ea43493bd8bc633 (patch) | |
tree | 4873ba987dd95addf9d7620485c7a5b1898b931a /include | |
parent | 5fa4acb1950cd21812d577f9ea6f99caaef255eb (diff) |
Rework IRCDMessage/IRCDMessageFlag.
Diffstat (limited to 'include')
-rw-r--r-- | include/messages.h | 32 | ||||
-rw-r--r-- | include/protocol.h | 59 |
2 files changed, 61 insertions, 30 deletions
diff --git a/include/messages.h b/include/messages.h index 206570940..59e483923 100644 --- a/include/messages.h +++ b/include/messages.h @@ -24,7 +24,7 @@ namespace Message struct CoreExport Away : IRCDMessage { - Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Away(Module *creator, const Anope::string &mname = "AWAY") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -32,7 +32,7 @@ namespace Message struct CoreExport Capab : IRCDMessage { - Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Capab(Module *creator, const Anope::string &mname = "CAPAB") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -48,7 +48,7 @@ namespace Message struct CoreExport Invite : IRCDMessage { - Invite(Module *creator, const Anope::string &mname = "INVITE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Invite(Module *creator, const Anope::string &mname = "INVITE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -56,7 +56,7 @@ namespace Message struct CoreExport Join : IRCDMessage { - Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Join(Module *creator, const Anope::string &mname = "JOIN") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; @@ -75,7 +75,7 @@ namespace Message struct CoreExport Kick : IRCDMessage { - Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Kick(Module *creator, const Anope::string &mname = "KICK") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -91,7 +91,7 @@ namespace Message struct CoreExport Mode : IRCDMessage { - Mode(Module *creator, const Anope::string &mname = "MODE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Mode(Module *creator, const Anope::string &mname = "MODE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -107,7 +107,7 @@ namespace Message struct CoreExport Notice : IRCDMessage { - Notice(Module *creator, const Anope::string &mname = "NOTICE") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + Notice(Module *creator, const Anope::string &mname = "NOTICE") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -115,7 +115,7 @@ namespace Message struct CoreExport Part : IRCDMessage { - Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Part(Module *creator, const Anope::string &mname = "PART") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -123,7 +123,7 @@ namespace Message struct CoreExport Ping : IRCDMessage { - Ping(Module *creator, const Anope::string &mname = "PING") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Ping(Module *creator, const Anope::string &mname = "PING") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -131,7 +131,7 @@ namespace Message struct CoreExport Privmsg : IRCDMessage { - Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + Privmsg(Module *creator, const Anope::string &mname = "PRIVMSG") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -139,7 +139,7 @@ namespace Message struct CoreExport Quit : IRCDMessage { - Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + Quit(Module *creator, const Anope::string &mname = "QUIT") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -155,7 +155,7 @@ namespace Message struct CoreExport Stats : IRCDMessage { - Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Stats(Module *creator, const Anope::string &mname = "STATS") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_REQUIRE_USER); SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -163,7 +163,7 @@ namespace Message struct CoreExport Time : IRCDMessage { - Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -171,7 +171,7 @@ namespace Message struct CoreExport Topic : IRCDMessage { - Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + Topic(Module *creator, const Anope::string &mname = "TOPIC") : IRCDMessage(creator, mname, 2) { SetFlag(FLAG_REQUIRE_USER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -179,7 +179,7 @@ namespace Message struct CoreExport Version : IRCDMessage { - Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; @@ -187,7 +187,7 @@ namespace Message struct CoreExport Whois : IRCDMessage { - Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(FLAG_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override; }; diff --git a/include/protocol.h b/include/protocol.h index 4c9f5afd0..728988195 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -319,26 +319,57 @@ public: Server *GetServer() const; }; -enum IRCDMessageFlag -{ - IRCDMESSAGE_SOFT_LIMIT, - IRCDMESSAGE_REQUIRE_SERVER, - IRCDMESSAGE_REQUIRE_USER -}; +/** Base class for protocol module message handlers. */ class CoreExport IRCDMessage : public Service { - Anope::string name; - unsigned param_count; - std::set<IRCDMessageFlag> flags; public: - IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0); - unsigned GetParamCount() const; - virtual void Run(MessageSource &, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) = 0; + /** An enumeration of potential flags a command can have. */ + enum Flag + : uint8_t + { + /** The parameter count is a minimum instead of an exact limit. */ + FLAG_SOFT_LIMIT, + + /** The message must come from a server. */ + FLAG_REQUIRE_SERVER, + + /** The message must come from a user. */ + FLAG_REQUIRE_USER, + + /** The highest flag possible. */ + FLAG_MAX, + }; + +private: + /** The name of the message (e.g. PRIVMSG). */ + const Anope::string name; + + /** The number of parameters this command takes. */ + const size_t param_count; + + /** The flags that are set on the command. */ + std::bitset<FLAG_MAX> flags; + +public: + IRCDMessage(Module *o, const Anope::string &n, size_t pc = 0); + + /** Retrieves the parameter count. */ + inline size_t GetParamCount() const { return param_count; } + + /** Runs the handler for this message. + * @param source Entity that sent the message. + * @param params Message parameters + * @param tags Message tags + */ + virtual void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) = 0; + + /** Sets the flags for this message. */ + inline void SetFlag(Flag flag, bool value = true) { flags.set(flag, value); } - void SetFlag(IRCDMessageFlag f) { flags.insert(f); } - bool HasFlag(IRCDMessageFlag f) const { return flags.count(f); } + /** Determines if a flag is set. */ + inline bool HasFlag(Flag flag) const { return flags[flag]; } }; /** MessageTokenizer allows tokens in the IRC wire format to be read from a string */ |