diff options
Diffstat (limited to 'include/modules')
54 files changed, 2486 insertions, 585 deletions
diff --git a/include/modules/botserv.h b/include/modules/botserv.h new file mode 100644 index 000000000..09183b53a --- /dev/null +++ b/include/modules/botserv.h @@ -0,0 +1,22 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#pragma once + +namespace BotServ +{ + class BotServService : public Service + { + public: + BotServService(Module *m) : Service(m, "BotServService", "BotServ") + { + } + + }; + static ServiceReference<BotServService> service("BotServService", "BotServ"); +} diff --git a/include/modules/bs_badwords.h b/include/modules/bs_badwords.h index 678512c96..87986ee62 100644 --- a/include/modules/bs_badwords.h +++ b/include/modules/bs_badwords.h @@ -17,7 +17,7 @@ enum BadWordType { /* Always kicks if the word is said */ BW_ANY, - /* User must way the entire word */ + /* User must say the entire word */ BW_SINGLE, /* The word has to start with the badword */ BW_START, @@ -26,48 +26,77 @@ enum BadWordType }; /* Structure used to contain bad words. */ -struct BadWord +class BadWord : public Serialize::Object { - Anope::string chan; - Anope::string word; - BadWordType type; - - virtual ~BadWord() { } protected: - BadWord() { } + using Serialize::Object::Object; + public: + virtual ~BadWord() = default; + + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual Anope::string GetWord() anope_abstract; + virtual void SetWord(const Anope::string &) anope_abstract; + + virtual BadWordType GetType() anope_abstract; + virtual void SetType(const BadWordType &) anope_abstract; }; -struct BadWords +static Serialize::TypeReference<BadWord> badword("BadWord"); + +struct BadWords : public Service { - virtual ~BadWords() { } + BadWords(Module *me) : Service(me, "BadWords", "badwords") { } /** Add a badword to the badword list * @param word The badword * @param type The type (SINGLE START END) * @return The badword */ - virtual BadWord* AddBadWord(const Anope::string &word, BadWordType type) = 0; + virtual BadWord* AddBadWord(ChanServ::Channel *, const Anope::string &word, BadWordType type) anope_abstract; + + virtual std::vector<BadWord *> GetBadWords(ChanServ::Channel *ci) anope_abstract; /** Get a badword structure by index * @param index The index * @return The badword */ - virtual BadWord* GetBadWord(unsigned index) const = 0; + virtual BadWord* GetBadWord(ChanServ::Channel *, unsigned index) anope_abstract; /** Get how many badwords are on this channel * @return The number of badwords in the vector */ - virtual unsigned GetBadWordCount() const = 0; + virtual unsigned GetBadWordCount(ChanServ::Channel *) anope_abstract; /** Remove a badword * @param index The index of the badword */ - virtual void EraseBadWord(unsigned index) = 0; + virtual void EraseBadWord(ChanServ::Channel *, unsigned index) anope_abstract; /** Clear all badwords from the channel */ - virtual void ClearBadWords() = 0; - - virtual void Check() = 0; + virtual void ClearBadWords(ChanServ::Channel *) anope_abstract; }; +static ServiceReference<BadWords> badwords("BadWords", "badwords"); + +namespace Event +{ + struct CoreExport BadWordEvents : Events + { + /** Called before a badword is added to the badword list + * @param ci The channel + * @param bw The badword + */ + virtual void OnBadWordAdd(ChanServ::Channel *ci, const BadWord *bw) anope_abstract; + + /** Called before a badword is deleted from a channel + * @param ci The channel + * @param bw The badword + */ + virtual void OnBadWordDel(ChanServ::Channel *ci, const BadWord *bw) anope_abstract; + }; +} + +template<> struct EventName<Event::BadWordEvents> { static constexpr const char *const name = "Badwords"; }; diff --git a/include/modules/bs_bot.h b/include/modules/bs_bot.h new file mode 100644 index 000000000..fe6534309 --- /dev/null +++ b/include/modules/bs_bot.h @@ -0,0 +1,38 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport BotCreate : Events + { + /** Called when a new bot is made + * @param bi The bot + */ + virtual void OnBotCreate(ServiceBot *bi) anope_abstract; + }; + + struct CoreExport BotChange : Events + { + /** Called when a bot is changed + * @param bi The bot + */ + virtual void OnBotChange(ServiceBot *bi) anope_abstract; + }; + + struct CoreExport BotDelete : Events + { + /** Called when a bot is deleted + * @param bi The bot + */ + virtual void OnBotDelete(ServiceBot *bi) anope_abstract; + }; +} + +template<> struct EventName<Event::BotCreate> { static constexpr const char *const name = "OnBotCreate"; }; +template<> struct EventName<Event::BotChange> { static constexpr const char *const name = "OnBotChange"; }; +template<> struct EventName<Event::BotDelete> { static constexpr const char *const name = "OnBotDelete"; }; diff --git a/include/modules/bs_info.h b/include/modules/bs_info.h new file mode 100644 index 000000000..1ebd58c89 --- /dev/null +++ b/include/modules/bs_info.h @@ -0,0 +1,21 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +namespace Event +{ + struct CoreExport ServiceBotEvent : Events + { + /** Called when a user uses botserv/info on a bot or channel. + */ + virtual void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract; + }; + extern CoreExport EventHandlers<ServiceBotEvent> OnServiceBot; +} + +template<> struct EventName<Event::ServiceBotEvent> { static constexpr const char *const name = "OnServiceBot"; }; diff --git a/include/modules/bs_kick.h b/include/modules/bs_kick.h index 61cd987d5..1346d7427 100644 --- a/include/modules/bs_kick.h +++ b/include/modules/bs_kick.h @@ -11,36 +11,122 @@ * */ -/* Indices for TTB (Times To Ban) */ -enum +class KickerData : public Serialize::Object { - TTB_BOLDS, - TTB_COLORS, - TTB_REVERSES, - TTB_UNDERLINES, - TTB_BADWORDS, - TTB_CAPS, - TTB_FLOOD, - TTB_REPEAT, - TTB_ITALICS, - TTB_AMSGS, - TTB_SIZE + protected: + using Serialize::Object::Object; + + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual bool GetAmsgs() anope_abstract; + virtual void SetAmsgs(const bool &) anope_abstract; + + virtual bool GetBadwords() anope_abstract; + virtual void SetBadwords(const bool &) anope_abstract; + + virtual bool GetBolds() anope_abstract; + virtual void SetBolds(const bool &) anope_abstract; + + virtual bool GetCaps() anope_abstract; + virtual void SetCaps(const bool &) anope_abstract; + + virtual bool GetColors() anope_abstract; + virtual void SetColors(const bool &) anope_abstract; + + virtual bool GetFlood() anope_abstract; + virtual void SetFlood(const bool &) anope_abstract; + + virtual bool GetItalics() anope_abstract; + virtual void SetItalics(const bool &) anope_abstract; + + virtual bool GetRepeat() anope_abstract; + virtual void SetRepeat(const bool &) anope_abstract; + + virtual bool GetReverses() anope_abstract; + virtual void SetReverses(const bool &) anope_abstract; + + virtual bool GetUnderlines() anope_abstract; + virtual void SetUnderlines(const bool &) anope_abstract; + + virtual int16_t GetTTBBolds() anope_abstract; + virtual void SetTTBBolds(const int16_t &) anope_abstract; + + virtual int16_t GetTTBColors() anope_abstract; + virtual void SetTTBColors(const int16_t &) anope_abstract; + + virtual int16_t GetTTBReverses() anope_abstract; + virtual void SetTTBReverses(const int16_t &) anope_abstract; + + virtual int16_t GetTTBUnderlines() anope_abstract; + virtual void SetTTBUnderlines(const int16_t &) anope_abstract; + + virtual int16_t GetTTBBadwords() anope_abstract; + virtual void SetTTBBadwords(const int16_t &) anope_abstract; + + virtual int16_t GetTTBCaps() anope_abstract; + virtual void SetTTBCaps(const int16_t &) anope_abstract; + + virtual int16_t GetTTBFlood() anope_abstract; + virtual void SetTTBFlood(const int16_t &) anope_abstract; + + virtual int16_t GetTTBRepeat() anope_abstract; + virtual void SetTTBRepeat(const int16_t &) anope_abstract; + + virtual int16_t GetTTBItalics() anope_abstract; + virtual void SetTTBItalics(const int16_t &) anope_abstract; + + virtual int16_t GetTTBAmsgs() anope_abstract; + virtual void SetTTBAmsgs(const int16_t &) anope_abstract; + + virtual int16_t GetCapsMin() anope_abstract; + virtual void SetCapsMin(const int16_t &) anope_abstract; + + virtual int16_t GetCapsPercent() anope_abstract; + virtual void SetCapsPercent(const int16_t &) anope_abstract; + + virtual int16_t GetFloodLines() anope_abstract; + virtual void SetFloodLines(const int16_t &) anope_abstract; + + virtual int16_t GetFloodSecs() anope_abstract; + virtual void SetFloodSecs(const int16_t &) anope_abstract; + + virtual int16_t GetRepeatTimes() anope_abstract; + virtual void SetRepeatTimes(const int16_t &) anope_abstract; + + virtual bool GetDontKickOps() anope_abstract; + virtual void SetDontKickOps(const bool &) anope_abstract; + + virtual bool GetDontKickVoices() anope_abstract; + virtual void SetDontKickVoices(const bool &) anope_abstract; }; -struct KickerData +static Serialize::TypeReference<KickerData> kickerdata("KickerData"); + +inline KickerData *GetKickerData(ChanServ::Channel *ci) { - bool amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines; - int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */ - int16_t capsmin, capspercent; /* For CAPS kicker */ - int16_t floodlines, floodsecs; /* For FLOOD kicker */ - int16_t repeattimes; /* For REPEAT kicker */ + KickerData *kd = ci->GetRef<KickerData *>(kickerdata); + if (!kd && kickerdata) + { + kd = kickerdata.Create(); + kd->SetChannel(ci); + } + return kd; +} - bool dontkickops, dontkickvoices; +namespace Event +{ + struct CoreExport BotBan : Events + { + /** Called when a bot places a ban + * @param u User being banned + * @param ci Channel the ban is placed on + * @param mask The mask being banned + */ + virtual void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) anope_abstract; + }; +} - protected: - KickerData() { } +template<> struct EventName<Event::BotBan> { static constexpr const char *const name = "OnBotBan"; }; - public: - virtual ~KickerData() { } - virtual void Check(ChannelInfo *ci) = 0; -}; diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h new file mode 100644 index 000000000..35fc3c332 --- /dev/null +++ b/include/modules/chanserv.h @@ -0,0 +1,634 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#pragma once + +#include "event.h" +#include "channels.h" +#include "modules/nickserv.h" +#include "modules/memoserv.h" +#include "bots.h" + +namespace ChanServ +{ + static struct + { + Anope::string name; + Anope::string desc; + } descriptions[] = { + {"ACCESS_CHANGE", _("Allowed to modify the access list")}, + {"ACCESS_LIST", _("Allowed to view the access list")}, + {"AKICK", _("Allowed to use the AKICK command")}, + {"ASSIGN", _("Allowed to assign/unassign a bot")}, + {"AUTOHALFOP", _("Automatic halfop upon join")}, + {"AUTOOP", _("Automatic channel operator status upon join")}, + {"AUTOOWNER", _("Automatic owner upon join")}, + {"AUTOPROTECT", _("Automatic protect upon join")}, + {"AUTOVOICE", _("Automatic voice on join")}, + {"BADWORDS", _("Allowed to modify channel badwords list")}, + {"BAN", _("Allowed to ban users")}, + {"FANTASIA", _("Allowed to use fantasy commands")}, + {"FOUNDER", _("Allowed to issue commands restricted to channel founders")}, + {"GETKEY", _("Allowed to use GETKEY command")}, + {"GREET", _("Greet message displayed on join")}, + {"HALFOP", _("Allowed to (de)halfop users")}, + {"HALFOPME", _("Allowed to (de)halfop him/herself")}, + {"INFO", _("Allowed to get full INFO output")}, + {"INVITE", _("Allowed to use the INVITE command")}, + {"KICK", _("Allowed to use the KICK command")}, + {"MEMO", _("Allowed to read channel memos")}, + {"MODE", _("Allowed to use the MODE command")}, + {"NOKICK", _("Prevents users being kicked by Services")}, + {"OP", _("Allowed to (de)op users")}, + {"OPME", _("Allowed to (de)op him/herself")}, + {"OWNER", _("Allowed to (de)owner users")}, + {"OWNERME", _("Allowed to (de)owner him/herself")}, + {"PROTECT", _("Allowed to (de)protect users")}, + {"PROTECTME", _("Allowed to (de)protect him/herself")}, + {"SAY", _("Allowed to use SAY and ACT commands")}, + {"SET", _("Allowed to set channel settings")}, + {"SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used")}, + {"TOPIC", _("Allowed to change channel topics")}, + {"UNBAN", _("Allowed to unban users")}, + {"VOICE", _("Allowed to (de)voice users")}, + {"VOICEME", _("Allowed to (de)voice him/herself")} + }; + + /* A privilege, probably configured using a privilege{} block. Most + * commands require specific privileges to be executed. + */ + struct CoreExport Privilege + { + Anope::string name; + Anope::string desc; + /* Rank relative to other privileges */ + int rank; + int level; + + Privilege(const Anope::string &n, const Anope::string &d, int r, int l) : name(n), desc(d), rank(r), level(l) + { + if (this->desc.empty()) + for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) + if (descriptions[j].name.equals_ci(name)) + this->desc = descriptions[j].desc; + } + + bool operator==(const Privilege &other) const + { + return this->name.equals_ci(other.name); + } + }; + + class Channel; + using registered_channel_map = Anope::hash_map<Channel *>; + + class Level : public Serialize::Object + { + public: + using Serialize::Object::Object; + + virtual Channel *GetChannel() anope_abstract; + virtual void SetChannel(Channel *) anope_abstract; + + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; + + virtual int GetLevel() anope_abstract; + virtual void SetLevel(const int &) anope_abstract; + }; + + static Serialize::TypeReference<Level> level("Level"); + + class Mode : public Serialize::Object + { + public: + using Serialize::Object::Object; + + virtual Channel *GetChannel() anope_abstract; + virtual void SetChannel(Channel *) anope_abstract; + + virtual Anope::string GetMode() anope_abstract; + virtual void SetMode(const Anope::string &) anope_abstract; + + virtual Anope::string GetParam() anope_abstract; + virtual void SetParam(const Anope::string &) anope_abstract; + }; + + static Serialize::TypeReference<Mode> mode("CSKeepMode"); + + class ChanServService : public Service + { + public: + ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ") + { + } + + virtual Channel *Find(const Anope::string &name) anope_abstract; + virtual registered_channel_map& GetChannels() anope_abstract; + + /* Have ChanServ hold the channel, that is, join and set +nsti and wait + * for a few minutes so no one can join or rejoin. + */ + virtual void Hold(::Channel *c) anope_abstract; + + virtual void AddPrivilege(Privilege p) anope_abstract; + virtual void RemovePrivilege(Privilege &p) anope_abstract; + virtual Privilege *FindPrivilege(const Anope::string &name) anope_abstract; + virtual std::vector<Privilege> &GetPrivileges() anope_abstract; + virtual void ClearPrivileges() anope_abstract; + }; + static ServiceReference<ChanServService> service("ChanServService", "ChanServ"); + + inline Channel *Find(const Anope::string name) + { + return service ? service->Find(name) : nullptr; + } + + namespace Event + { + struct CoreExport PreChanExpire : Events + { + /** Called before a channel expires + * @param ci The channel + * @param expire Set to true to allow the chan to expire + */ + virtual void OnPreChanExpire(Channel *ci, bool &expire) anope_abstract; + }; + static EventHandlersReference<PreChanExpire> OnPreChanExpire; + + struct CoreExport ChanExpire : Events + { + /** Called before a channel expires + * @param ci The channel + */ + virtual void OnChanExpire(Channel *ci) anope_abstract; + }; + static EventHandlersReference<ChanExpire> OnChanExpire; + } + + /* It matters that Base is here before Extensible (it is inherited by Serializable) + */ + class CoreExport Channel : public Serialize::Object + { + public: + ::Channel *c = nullptr; /* Pointer to channel, if the channel exists */ + + protected: + using Serialize::Object::Object; + + public: + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; + + virtual Anope::string GetDesc() anope_abstract; + virtual void SetDesc(const Anope::string &) anope_abstract; + + virtual time_t GetTimeRegistered() anope_abstract; + virtual void SetTimeRegistered(const time_t &) anope_abstract; + + virtual time_t GetLastUsed() anope_abstract; + virtual void SetLastUsed(const time_t &) anope_abstract; + + virtual Anope::string GetLastTopic() anope_abstract; + virtual void SetLastTopic(const Anope::string &) anope_abstract; + + virtual Anope::string GetLastTopicSetter() anope_abstract; + virtual void SetLastTopicSetter(const Anope::string &) anope_abstract; + + virtual time_t GetLastTopicTime() anope_abstract; + virtual void SetLastTopicTime(const time_t &) anope_abstract; + + virtual int16_t GetBanType() anope_abstract; + virtual void SetBanType(const int16_t &) anope_abstract; + + virtual time_t GetBanExpire() anope_abstract; + virtual void SetBanExpire(const time_t &) anope_abstract; + + virtual BotInfo *GetBI() anope_abstract; + virtual void SetBI(BotInfo *) anope_abstract; + + virtual ServiceBot *GetBot() anope_abstract; + virtual void SetBot(ServiceBot *) anope_abstract; + + /** Is the user the real founder? + * @param user The user + * @return true or false + */ + virtual bool IsFounder(const User *user) anope_abstract; + + /** Change the founder of the channel + * @params nc The new founder + */ + virtual void SetFounder(NickServ::Account *nc) anope_abstract; + + /** Get the founder of the channel + * @return The founder + */ + virtual NickServ::Account *GetFounder() anope_abstract; + + virtual void SetSuccessor(NickServ::Account *nc) anope_abstract; + virtual NickServ::Account *GetSuccessor() anope_abstract; + + /** Find which bot should send mode/topic/etc changes for this channel + * @return The bot + */ + ServiceBot *WhoSends() + { + if (this) + if (ServiceBot *bi = GetBot()) + return bi; + + ServiceBot *ChanServ = Config->GetClient("ChanServ"); + if (ChanServ) + return ChanServ; + + //XXX +// if (!BotListByNick->empty()) +// return BotListByNick->begin()->second; + + return NULL; + } + + /** Get an entry from the channel access list by index + * + * @param index The index in the access list vector + * @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds + * + * Retrieves an entry from the access list that matches the given index. + */ + virtual ChanAccess *GetAccess(unsigned index) /*const*/ anope_abstract; + + /** Retrieve the access for a user or group in the form of a vector of access entries + * (as multiple entries can affect a single user). + */ + virtual AccessGroup AccessFor(const User *u, bool |
