diff options
| author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-08 20:06:21 +0000 |
|---|---|---|
| committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-08 20:06:21 +0000 |
| commit | 458be36a321615c0f3004a6abde7e14d40f5da32 (patch) | |
| tree | 711be83fc6f2d49f9d31015db51730cdac57f687 | |
| parent | 38ad96c57c520dd84c8de21766f5de082a844a99 (diff) | |
Rewrote all of the old C style flag systems into a new Flag class which everything inherits from. This breaks reading and writing flags to the old databases (and probably many other things aswell) - Don't use it
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2636 5417fbe8-f217-4b02-8779-1006273d7864
76 files changed, 994 insertions, 859 deletions
diff --git a/include/account.h b/include/account.h index 09db33955..075b15e9e 100644 --- a/include/account.h +++ b/include/account.h @@ -1,6 +1,69 @@ /* NickServ nickname structures. */ +/** Flags set on NickAliases + */ +enum NickNameFlag +{ + NS_BEGIN, + + /* Nick may not be registered or used */ + NS_FORBIDDEN, + /* Nick never expires */ + NS_NO_EXPIRE, + /* Nick is being held after a kill */ + NS_KILL_HELD, + /* SVSNICK has been sent but nick has not yet changed. + * An enforcer will be introduced when it does change. */ + NS_GUESTED, + + NS_END +}; + +/** Flags set on NickCores + */ +enum NickCoreFlag +{ + NI_BEGIN, + + /* Kill others who take this nick */ + NI_KILLPROTECT, + /* Dont recognize unless IDENTIFIED */ + NI_SECURE, + /* Use PRIVMSG instead of NOTICE */ + NI_MSG, + /* Don't allow user to change memo limit */ + NI_MEMO_HARDMAX, + /* Notify of memos at signon and un-away */ + NI_MEMO_SIGNON, + /* Notify of new memos when sent */ + NI_MEMO_RECEIVE, + /* Don't show in LIST to non-servadmins */ + NI_PRIVATE, + /* Don't show email in INFO */ + NI_HIDE_EMAIL, + /* Don't show last seen address in INFO */ + NI_HIDE_MASK, + /* Don't show last quit message in INFO */ + NI_HIDE_QUIT, + /* Kill in 20 seconds instead of in 60 */ + NI_KILL_QUICK, + /* Kill immediatly */ + NI_KILL_IMMED, + /* User gets email on memo */ + NI_MEMO_MAIL, + /* Don't show services access status */ + NI_HIDE_STATUS, + /* Nickname is suspended */ + NI_SUSPENDED, + /* Autoop nickname in channels */ + NI_AUTOOP, + /* Nick won't expire */ + NI_NOEXPIRE, + + NI_END +}; + /** XXX: this really needs to die with fire and be merged with metadata into NickCore or something. */ class NickRequest @@ -24,7 +87,7 @@ class NickRequest class NickCore; -class CoreExport NickAlias : public Extensible +class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag> { public: NickAlias(); @@ -36,11 +99,10 @@ class CoreExport NickAlias : public Extensible char *last_usermask; /* Last usermask */ time_t time_registered; /* When the nick was registered */ time_t last_seen; /* When it was seen online for the last time */ - uint16 status; /* See NS_* below */ NickCore *nc; /* I'm an alias of this */ }; -class CoreExport NickCore : public Extensible +class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag> { public: NickCore(); @@ -53,7 +115,6 @@ class CoreExport NickCore : public Extensible char *greet; /* Greet associated to the nick */ uint32 icq; /* ICQ # associated to the nick */ char *url; /* URL associated to the nick */ - uint32 flags; /* See NI_* below */ uint16 language; /* Language selected by nickname owner (LANG_*) */ std::vector<std::string> access; /* Access list, vector of strings */ MemoInfo memos; diff --git a/include/bots.h b/include/bots.h index 38ad5534d..80ac08c1f 100644 --- a/include/bots.h +++ b/include/bots.h @@ -9,10 +9,33 @@ * */ +/** Flags settable on a bot + */ +enum BotFlag +{ + BI_BEGIN, + + /* This bot can only be assigned by IRCops */ + BI_PRIVATE, + /* The following flags are used to determin what bot really is what. + * Since you *could* have ChanServ really named BotServ or something stupid, + * this keeps track of them and allows them to be renamed in the config + * at any time, even if they already exist in the database + */ + BI_CHANSERV, + BI_BOTSERV, + BI_HOSTSERV, + BI_OPERSERV, + BI_MEMOSERV, + BI_NICKSERV, + BI_GLOBAL, + + BI_END +}; struct CommandHash; -class CoreExport BotInfo +class CoreExport BotInfo : public Extensible, public Flags<BotFlag> { public: BotInfo *next, *prev; @@ -22,7 +45,6 @@ class CoreExport BotInfo char *user; /* Its user name */ char *host; /* Its hostname */ char *real; /* Its real name */ - int16 flags; /* Bot flags -- see BI_* below */ time_t created; /* Birth date ;) */ int16 chancount; /* Number of channels that use the bot. */ /* Dynamic data */ diff --git a/include/extern.h b/include/extern.h index 821bc2190..21a4987ff 100644 --- a/include/extern.h +++ b/include/extern.h @@ -123,7 +123,7 @@ E Entry *elist_find_mask(EList *list, const char *mask); E long get_memuse(EList *list); -#define whosends(ci) ((!(ci) || !((ci)->botflags & BS_SYMBIOSIS) || !(ci)->bi || !(ci)->c || (ci)->c->usercount < BSMinUsers) ? findbot(s_ChanServ) : (ci)->bi) +#define whosends(ci) ((!(ci) || !((ci)->botflags.HasFlag(BS_SYMBIOSIS)) || !(ci)->bi || !(ci)->c || (ci)->c->usercount < BSMinUsers) ? findbot(s_ChanServ) : (ci)->bi) /**** chanserv.c ****/ @@ -257,7 +257,7 @@ E bool RestrictMail; E time_t MailDelay; E bool DontQuoteAddresses; -E int NSDefFlags; +E Flags<NickCoreFlag> NSDefFlags; E unsigned NSDefLanguage; E time_t NSRegDelay; E time_t NSResendDelay; @@ -280,7 +280,7 @@ E bool NSEmailReg; E bool NSModeOnID; E bool NSAddAccessOnReg; -E int CSDefFlags; +E Flags<ChannelInfoFlag> CSDefFlags; E unsigned CSMaxReg; E time_t CSExpire; E int CSDefBantype; @@ -298,7 +298,7 @@ E time_t MSSendDelay; E bool MSNotifyAll; E unsigned MSMemoReceipt; -E int BSDefFlags; +E Flags<BotServFlag> BSDefFlags; E time_t BSKeepData; E unsigned BSMinUsers; E unsigned BSBadWordsMax; @@ -720,14 +720,13 @@ E Server *serv_uplink; E uint32 uplink_capab; E CapabInfo capab_info[]; -E Server *first_server(int flags); -E Server *next_server(int flags); +E Server *first_server(ServerFlag flag); +E Server *next_server(ServerFlag flag); E int is_ulined(const char *server); E int is_sync(Server *server); -E Server *new_server(Server * uplink, const char *name, const char *desc, - uint16 flags, const char *suid); +E Server *new_server(Server * uplink, const char *name, const char *desc, ServerFlag flag, const char *suid); E Server *findserver(Server *s, const char *name); diff --git a/include/modules.h b/include/modules.h index bd128a3bc..d5fddcc44 100644 --- a/include/modules.h +++ b/include/modules.h @@ -217,7 +217,7 @@ struct ModuleLang_ { char **argv; }; -enum CommandFlags +enum CommandFlag { CFLAG_ALLOW_UNREGISTERED = 1, CFLAG_ALLOW_FORBIDDEN = 2, @@ -229,9 +229,8 @@ enum CommandFlags /** Every services command is a class, inheriting from Command. */ -class CoreExport Command +class CoreExport Command : public Flags<CommandFlag> { - int flags; public: size_t MaxParams; size_t MinParams; @@ -264,22 +263,6 @@ class CoreExport Command */ virtual void OnSyntaxError(User *u); - /** Set a certain flag on this command. - * @param flag The CommandFlag to set on this command. - */ - void SetFlag(CommandFlags flag); - - /** Remove a certain flag from this command. - * @param flag The CommandFlag to unset. - */ - void UnsetFlag(CommandFlags flag); - - /** Check whether a certain flag is set on this command. - * @param flag The CommandFlag to check. - * @return bool True if the flag is set, false else. - */ - bool HasFlag(CommandFlags flag) const; - /** Set which command permission (e.g. chanserv/forbid) is required for this command. * @param reststr The permission required to successfully execute this command */ diff --git a/include/regchannel.h b/include/regchannel.h index 73a0666ab..710437374 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -9,7 +9,51 @@ * */ -class CoreExport ChannelInfo : public Extensible +/** Flags used for the ChannelInfo class + */ +enum ChannelInfoFlag +{ + CI_BEGIN, + + /* ChanServ is currently holding the channel */ + CI_INHABIT, + /* Retain the topic even after the channel is emptied */ + CI_KEEPTOPIC, + /* Don't allow non-authorized users to be opped */ + CI_SECUREOPS, + /* Hide channel from ChanServ LIST command */ + CI_PRIVATE, + /* Topic can only be changed by SET TOPIC */ + CI_TOPICLOCK, + /* Only users on the access list may join */ + CI_RESTRICTED, + /* Don't allow ChanServ and BotServ commands to do bad things to users with higher access levels */ + CI_PEACE, + /* Don't allow any privileges unless a user is IDENTIFIED with NickServ */ + CI_SECURE, + /* Don't allow the channel to be registered or used */ + CI_FORBIDDEN, + /* Channel does not expire */ + CI_NO_EXPIRE, + /* Channel memo limit may not be changed */ + CI_MEMO_HARDMAX, + /* Send notice to channel on use of OP/DEOP */ + CI_OPNOTICE, + /* Stricter control of channel founder status */ + CI_SECUREFOUNDER, + /* Sign kicks with the user who did the kick */ + CI_SIGNKICK, + /* Sign kicks if level is < than the one defined by the SIGNKIGK level */ + CI_SIGNKICK_LEVEL, + /* Uses XOP */ + CI_XOP, + /* Channel is suspended */ + CI_SUSPENDED, + + CI_END +}; + +class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag> { private: std::map<ChannelModeName, std::string> Params; /* Map of parameters by mode name */ @@ -36,7 +80,6 @@ class CoreExport ChannelInfo : public Extensible char last_topic_setter[NICKMAX]; /* Who set the last topic */ time_t last_topic_time; /* When the last topic was set */ - uint32 flags; /* See below */ char *forbidby; char *forbidreason; @@ -53,7 +96,7 @@ class CoreExport ChannelInfo : public Extensible /* For BotServ */ BotInfo *bi; /* Bot used on this channel */ - uint32 botflags; /* BS_* below */ + Flags<BotServFlag> botflags; int16 *ttb; /* Times to ban for each kicker */ uint16 bwcount; diff --git a/include/services.h b/include/services.h index 738c4b283..1680d4d1a 100644 --- a/include/services.h +++ b/include/services.h @@ -418,18 +418,65 @@ class CoreExport Extensible }; +/** Class with the ability to keep flags on items, they should extend from this + * where T is an enum. + */ +template <class T> +class CoreExport Flags +{ + protected: + std::bitset<128> Flag_Values; + + public: + /** Add a flag to this item + * @param Value The flag + */ + void SetFlag(T Value) + { + Flag_Values[(size_t)Value] = true; + } + + /** Remove a flag from this item + * @param Value The flag + */ + void UnsetFlag(T Value) + { + Flag_Values[(size_t)Value] = false; + } + + /** Check if this item has a flag + * @param Value The flag + * @return true or false + */ + const bool HasFlag(T Value) const + { + return Flag_Values[(size_t)Value]; + } + + /** Check how many flags are set + * @return The number of flags set + */ + const size_t FlagCount() const + { + return Flag_Values.count(); + } + + /** Unset all of the flags + */ + void ClearFlags() + { + Flag_Values.reset(); + } +}; + /*************************************************************************/ /* forward declarations, mostly used by older code */ class User; class ChannelInfo; class Channel; +class EList; -typedef struct server_ Server; -typedef struct c_elist EList; -typedef struct c_elist_entry Entry; -typedef struct memo_ Memo; -typedef struct badword_ BadWord; typedef struct bandata_ BanData; typedef struct userdata_ UserData; typedef struct mailinfo_ MailInfo; @@ -584,12 +631,24 @@ struct ircdcapab_ { /*************************************************************************/ +/** Memo Flags + */ +enum MemoFlag +{ + /* Memo is unread */ + MF_UNREAD, + /* SEnder requests a receipt */ + MF_RECEIPT, + /* Memo is a notification of receipt */ + MF_NOTIFYS +}; + /* Memo info structures. Since both nicknames and channels can have memos, * we encapsulate memo data in a MemoList to make it easier to handle. */ - -struct memo_ { +class CoreExport Memo : public Flags<MemoFlag> +{ + public: uint32 number; /* Index number -- not necessarily array position! */ - uint16 flags; time_t time; /* When it was sent */ char sender[NICKMAX]; char *text; @@ -636,7 +695,8 @@ enum AccessLevel * wouldn't get very far. ;) ) */ /* Access levels for users. */ -struct ChanAccess { +struct ChanAccess +{ uint16 in_use; /* 1 if this entry is in use, else 0 */ int16 level; NickCore *nc; /* Guaranteed to be non-NULL if in use, NULL if not */ @@ -644,11 +704,22 @@ struct ChanAccess { std::string creator; }; -/* AutoKick data. */ -struct AutoKick +/** Flags for auto kick + */ +enum AutoKickFlag { - uint16 flags; + /* This auto kick entry is in use */ + AK_USED, + /* Is by nick core, not mask */ + AK_ISNICK, + /* This entry is stuck */ + AK_STUCK +}; +/* AutoKick data. */ +class CoreExport AutoKick : public Flags<AutoKickFlag> +{ + public: /* Only one of these can be in use */ std::string mask; NickCore *nc; @@ -658,63 +729,28 @@ struct AutoKick time_t addtime; }; -#define AK_USED 0x0001 -#define AK_ISNICK 0x0002 -#define AK_STUCK 0x0004 +/** Flags for badwords + */ +enum BadWordType +{ + /* Always kicks if the word is said */ + BW_ANY, + /* User must way the entire word */ + BW_SINGLE, + /* The word has to start with the badword */ + BW_START, + /* The word has to end with the badword */ + BW_END +}; /* Structure used to contain bad words. */ - -struct badword_ { +struct BadWord +{ uint16 in_use; char *word; - uint16 type; /* BW_* below */ + BadWordType type; }; -#define BW_ANY 0 -#define BW_SINGLE 1 -#define BW_START 2 -#define BW_END 3 - -#include "regchannel.h" - -/* Retain topic even after last person leaves channel */ -#define CI_KEEPTOPIC 0x00000001 -/* Don't allow non-authorized users to be opped */ -#define CI_SECUREOPS 0x00000002 -/* Hide channel from ChanServ LIST command */ -#define CI_PRIVATE 0x00000004 -/* Topic can only be changed by SET TOPIC */ -#define CI_TOPICLOCK 0x00000008 -/* Those not allowed ops are kickbanned */ -#define CI_RESTRICTED 0x00000010 -/* Don't allow ChanServ and BotServ commands to do bad things to bigger levels */ -#define CI_PEACE 0x00000020 -/* Don't allow any privileges unless a user is IDENTIFY'd with NickServ */ -#define CI_SECURE 0x00000040 -/* Don't allow the channel to be registered or used */ -#define CI_FORBIDDEN 0x00000080 -/* Channel password is encrypted */ -#define CI_ENCRYPTEDPW 0x00000100 -/* Channel does not expire */ -#define CI_NO_EXPIRE 0x00000200 -/* Channel memo limit may not be changed */ -#define CI_MEMO_HARDMAX 0x00000400 -/* Send notice to channel on use of OP/DEOP */ -#define CI_OPNOTICE 0x00000800 -/* Stricter control of channel founder status */ -#define CI_SECUREFOUNDER 0x00001000 -/* Always sign kicks */ -#define CI_SIGNKICK 0x00002000 -/* Sign kicks if level is < than the one defined by the SIGNKICK level */ -#define CI_SIGNKICK_LEVEL 0x00004000 -/* Use the xOP lists */ -#define CI_XOP 0x00008000 -/* Channel is suspended */ -#define CI_SUSPENDED 0x00010000 - -/* TEMPORARY - ChanServ is on the channel. */ -#define CI_INHABIT 0x80000000 - /* Indices for cmd_access[]: */ #define CA_INVITE 0 #define CA_AKICK 1 @@ -759,22 +795,37 @@ struct badword_ { #define CA_SIZE 39 /* BotServ SET flags */ -#define BS_DONTKICKOPS 0x00000001 -#define BS_DONTKICKVOICES 0x00000002 -#define BS_FANTASY 0x00000004 -#define BS_SYMBIOSIS 0x00000008 -#define BS_GREET 0x00000010 -#define BS_NOBOT 0x00000020 - -/* BotServ Kickers flags */ -#define BS_KICK_BOLDS 0x80000000 -#define BS_KICK_COLORS 0x40000000 -#define BS_KICK |
