diff options
author | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-05-05 01:55:04 -0400 |
commit | 1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b (patch) | |
tree | 4486f0784bdf050fd7eb225c0cb9df352ce1f45a /include | |
parent | 781defb7076ddfddf723ca08cd0a518b6657b64f (diff) |
Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in.
Diffstat (limited to 'include')
-rw-r--r-- | include/account.h | 4 | ||||
-rw-r--r-- | include/anope.h | 1 | ||||
-rw-r--r-- | include/bots.h | 7 | ||||
-rw-r--r-- | include/channels.h | 4 | ||||
-rw-r--r-- | include/config.h | 850 | ||||
-rw-r--r-- | include/defs.h | 3 | ||||
-rw-r--r-- | include/modes.h | 13 | ||||
-rw-r--r-- | include/module.h | 2 | ||||
-rw-r--r-- | include/modules.h | 89 | ||||
-rw-r--r-- | include/protocol.h | 5 | ||||
-rw-r--r-- | include/servers.h | 4 | ||||
-rw-r--r-- | include/users.h | 2 |
12 files changed, 174 insertions, 810 deletions
diff --git a/include/account.h b/include/account.h index 98827fd81..b5edd7ec2 100644 --- a/include/account.h +++ b/include/account.h @@ -219,6 +219,10 @@ class CoreExport NickCore : public Serializable, public Extensible */ Anope::string GetAccess(unsigned entry) const; + /** Get the number of entries on the access list for this account. + */ + unsigned GetAccessCount() const; + /** Find an entry in the nick's access list * * @param entry The nick!ident@host entry to search for diff --git a/include/anope.h b/include/anope.h index 8e24d12da..90c0e4c36 100644 --- a/include/anope.h +++ b/include/anope.h @@ -333,6 +333,7 @@ namespace Anope }; template<typename T> class map : public std::map<string, T, ci::less> { }; + template<typename T> class multimap : public std::multimap<string, T, ci::less> { }; template<typename T> class hash_map : public std::tr1::unordered_map<string, T, hash_ci, compare> { }; static const char *const compiled = __TIME__ " " __DATE__; diff --git a/include/bots.h b/include/bots.h index 3b42424bd..42345d8ea 100644 --- a/include/bots.h +++ b/include/bots.h @@ -23,6 +23,8 @@ extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID; /* A service bot (NickServ, ChanServ, a BotServ bot, etc). */ class CoreExport BotInfo : public User, public Serializable { + /* Channels this bot is assigned to */ + Serialize::Checker<std::set<ChannelInfo *> > channels; public: time_t created; /* Last time this bot said something (via privmsg) */ @@ -63,10 +65,9 @@ class CoreExport BotInfo : public User, public Serializable */ void SetNewNick(const Anope::string &newnick); - /** Rejoins all channels that this bot is assigned to. - * Used on /kill, rename, etc. + /** Return the channels this bot is assigned to */ - void RejoinAll(); + const std::set<ChannelInfo *> &GetChannels() const; /** Assign this bot to a given channel, removing the existing assigned bot if one exists. * @param u The user assigning the bot, or NULL diff --git a/include/channels.h b/include/channels.h index 118864c8a..56d0edd2c 100644 --- a/include/channels.h +++ b/include/channels.h @@ -264,10 +264,6 @@ class CoreExport Channel : public Base, public Extensible */ void ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts = Anope::CurTime); - /** Hold the channel open using ChanServ - */ - void Hold(); - /** Set the correct modes, or remove the ones granted without permission, * for the specified user. * @param user The user to give/remove modes to/from diff --git a/include/config.h b/include/config.h index 901fe0138..ca09c347f 100644 --- a/include/config.h +++ b/include/config.h @@ -16,319 +16,113 @@ #include "account.h" #include "regchannel.h" #include "users.h" +#include "opertype.h" +#include <stack> -/** A configuration key and value pair - */ -typedef std::pair<Anope::string, Anope::string> KeyVal; - -/** A list of related configuration keys and values - */ -typedef std::vector<KeyVal> KeyValList; - -/** An entire config file, built up of KeyValLists - */ -typedef std::multimap<Anope::string, KeyValList> ConfigDataHash; - -// Required forward definitions - -/** Types of data in the core config - */ -enum ConfigDataType -{ - DT_NOTHING, // No data - DT_INTEGER, // Integer - DT_UINTEGER, // Unsigned Integer - DT_LUINTEGER, // Long Unsigned Integer - DT_STRING, // Anope::string - DT_BOOLEAN, // Boolean - DT_HOSTNAME, // Hostname syntax - DT_NOSPACES, // No spaces - DT_IPADDRESS, // IP address (v4, v6) - DT_TIME, // Time value - DT_NORELOAD = 32, // Item can't be reloaded after startup - DT_ALLOW_WILD = 64, // Allow wildcards/CIDR in DT_IPADDRESS - DT_ALLOW_NEWLINE = 128, // New line characters allowed in DT_STRING - DT_ALLOW_EMPTY = 256 // Allow empty value -}; - -/** Holds a config value, either string, integer or boolean. - * Callback functions receive one or more of these, either on - * their own as a reference, or in a reference to a deque of them. - * The callback function can then alter the values of the ValueItem - * classes to validate the settings. - */ -class CoreExport ValueItem -{ - private: - /** Actual data */ - Anope::string v; - public: - /** Initialize with nothing */ - ValueItem(); - /** Initialize with an int */ - ValueItem(int); - /** Initialize with a bool */ - ValueItem(bool); - /** Initialize with an Anope::string */ - ValueItem(const Anope::string &); - /** Initialize with a long */ - ValueItem(long); - /** Change value to an Anope::string */ - void Set(const Anope::string &); - /** Change value to an int */ - void Set(int); - /** Get value as an int */ - int GetInteger() const; - /** Get value as a string */ - const char *GetString() const; - /** Get value as an Anope::string */ - inline const Anope::string &GetValue() const { return v; } - /** Get value as a bool */ - bool GetBool() const; -}; - -/** The base class of the container 'ValueContainer' - * used internally by the core to hold core values. - */ -class ValueContainerBase +namespace Configuration { - public: - /** Constructor */ - ValueContainerBase() { } - /** Destructor */ - virtual ~ValueContainerBase() { } -}; - -/** ValueContainer is used to contain pointers to different - * core values such as the server name, maximum number of - * clients etc. - * It is specialized to hold a data type, then pointed at - * a value in the ServerConfig class. When the value has been - * read and validated, the Set method is called to write the - * value safely in a type-safe manner. - */ -template<typename T> class ValueContainer : public ValueContainerBase -{ - private: - /** Contained item */ - T val; - public: - /** Initialize with nothing */ - ValueContainer() : ValueContainerBase(), val(NULL) { } - /** Initialize with a value of type T */ - ValueContainer(T Val) : ValueContainerBase(), val(Val) { } - /** Initialize with a copy */ - ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } - ValueContainer &operator=(const ValueContainer &Val) - { - val = Val.val; - return *this; - } - /** Change value to type T of size s */ - void Set(const T newval, size_t s) + class Block { - memcpy(val, newval, s); - } -}; + friend class Conf; -/** This a specific version of ValueContainer to handle Anope::string specially - */ -template<> class ValueContainer<Anope::string *> : public ValueContainerBase -{ - private: - /** Contained item */ - Anope::string *val; - public: - /** Initialize with nothing */ - ValueContainer() : ValueContainerBase(), val(NULL) { } - /** Initialize with an std::string */ - ValueContainer(Anope::string *Val) : ValueContainerBase(), val(Val) { } - /** Initialize with a copy */ - ValueContainer(const ValueContainer &Val) : ValueContainerBase(), val(Val.val) { } - ValueContainer &operator=(const ValueContainer &Val) - { - val = Val.val; - return *this; - } + public: + typedef Anope::map<Anope::string> item_map; + typedef Anope::multimap<Block> block_map; - /** Change value to given Anope::string */ - void Set(const Anope::string &newval) - { - *val = newval; - } - /** Change value to given char pointer */ - void Set(const char *newval) - { - *val = newval; - } -}; + private: + Anope::string name; + item_map items; + block_map blocks; -/** A specialization of ValueContainer to hold a pointer to a bool - */ -typedef ValueContainer<bool *> ValueContainerBool; + public: + Block(const Anope::string &); + const Anope::string &GetName() const; + int CountBlock(const Anope::string &name); + Block* GetBlock(const Anope::string &name, int num = 0); -/** A specialization of ValueContainer to hold a pointer to - * an unsigned int - */ -typedef ValueContainer<unsigned *> ValueContainerUInt; - -/** A specialization of ValueContainer to hold a pointer to - * a long unsigned int - */ -typedef ValueContainer<long unsigned *> ValueContainerLUInt; - -/** A specialization of ValueContainer to hold a pointer to - * an int - */ -typedef ValueContainer<int *> ValueContainerInt; - -/** A specialization of ValueContainer to hold a pointer to - * a time_t - */ -typedef ValueContainer<time_t *> ValueContainerTime; - -/** A specialization of ValueContainer to hold a pointer to - * an Anope::string - */ -typedef ValueContainer<Anope::string *> ValueContainerString; - -/** A set of ValueItems used by multi-value validator functions - */ -typedef std::deque<ValueItem> ValueList; - -/** A callback for validating a single value - */ -typedef bool (*Validator)(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &); -/** A callback for validating multiple value entries - */ -typedef bool (*MultiValidator)(ServerConfig *, const Anope::string &, const Anope::string *, ValueList &, int *); -/** A callback indicating the end of a group of entries - */ -typedef bool (*MultiNotify)(ServerConfig *, const Anope::string &); - -/** Represents a configuration file - */ -class ConfigurationFile -{ - Anope::string name; - bool executable; - FILE *fp; - public: - ConfigurationFile(const Anope::string &, bool); - ~ConfigurationFile(); - const Anope::string &GetName() const; + template<typename T> T Get(const Anope::string &tag, const Anope::string &def = "") const + { + const Anope::string &value = this->Get<const Anope::string &>(tag, def); + try + { + return convertTo<T>(value); + } + catch (const ConvertException &) + { + return T(); + } + } - bool IsOpen() const; - bool Open(); - void Close(); - bool End() const; - Anope::string Read(); -}; + bool Set(const Anope::string &tag, const Anope::string &value); + const item_map* GetItems() const; + }; -/** Holds all of the core configuration items - */ -class CoreExport ConfigItems -{ - public: - /** Holds a core configuration item and its callbacks - */ - struct Item - { - /** Tag name */ - Anope::string tag; - /** Value name */ - Anope::string value; - /** Default, if not defined */ - Anope::string default_value; - /** Value containers */ - ValueContainerBase *val; - /** Data types */ - int datatype; - /** Validation function */ - Validator validation_function; - } *Values; + template<> const Anope::string& Block::Get(const Anope::string &tag, const Anope::string& def) const; + template<> time_t Block::Get(const Anope::string &tag, const Anope::string &def) const; + template<> const char* Block::Get(const Anope::string &tag, const Anope::string &def) const; + template<> bool Block::Get(const Anope::string &tag, const Anope::string &def) const; - /** Holds a core configuration item and its callbacks - * where there may be more than one item + /** Represents a configuration file */ - struct MultiItem + class File { - /** Tag name */ - Anope::string tag; - /** One or more items within tag */ - Anope::string items[17]; - /** One or more defaults for items within tags */ - Anope::string items_default[17]; - /** One or more data types */ - int datatype[17]; - /** Initialization function */ - MultiNotify init_function; - /** Validation function */ - MultiValidator validation_function; - /** Completion function */ - MultiNotify finish_function; - } *MultiValues; - - ConfigItems(ServerConfig *conf); - ~ConfigItems(); -}; + Anope::string name; + bool executable; + FILE *fp; + public: + File(const Anope::string &, bool); + ~File(); + const Anope::string &GetName() const; + + bool IsOpen() const; + bool Open(); + void Close(); + bool End() const; + Anope::string Read(); + }; -/** This class holds the bulk of the runtime configuration for Anope. - * It allows for reading new config values, accessing configuration files, - * and storage of the configuration data needed to run Anope. - */ -class CoreExport ServerConfig -{ - private: - /** Check that there is only one of each configuration item - */ - bool CheckOnce(const Anope::string &); - public: - /** This holds all the information in the config file, - * it's indexed by tag name to a vector of key/values. - */ - ConfigDataHash config_data; - /** Construct a new ServerConfig - */ - ServerConfig(); + struct Uplink; - /** Read the entire configuration into memory - * and initialize this class. All other methods - * should be used only by the core. - */ - void Read(); - /** Load the configuration file into 'this'. With the new config parser everything is parsed into - * tag/key/value at load-time rather than at read-value time. - */ - void LoadConf(ConfigurationFile &file); - // Both these return true if the value existed or false otherwise - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false); - /** Writes 'length' chars into 'result' as a string - */ - bool ConfValue(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, Anope::string &, bool = false); - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, int, int &); - /** Tries to convert the value to an integer and write it to 'result' - */ - bool ConfValueInteger(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int, int &); - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, int); - /** Returns true if the value exists and has a true value, false otherwise - */ - bool ConfValueBool(ConfigDataHash &, const Anope::string &, const Anope::string &, const Anope::string &, int); - /** Returns the number of occurences of tag in the config file - */ - int ConfValueEnum(const ConfigDataHash &, const Anope::string &); - /** Returns the numbers of vars inside the index'th 'tag in the config file - */ - int ConfVarEnum(ConfigDataHash &, const Anope::string &, int); - void ValidateHostname(const Anope::string &, const Anope::string &, const Anope::string &) const; - void ValidateIP(const Anope::string &p, const Anope::string &, const Anope::string &, bool) const; - void ValidateNoSpaces(const Anope::string &, const Anope::string &, const Anope::string &) const; + struct Conf : Block + { + /* options:readtimeout */ + time_t ReadTimeout; + /* options:useprivmsg */ + bool UsePrivmsg; + /* If we should default to privmsging clients */ + bool DefPrivmsg; + /* Default language */ + Anope::string DefLanguage; + + /* either "/msg " or "/" */ + Anope::string StrictPrivmsg; + /* List of uplink servers to try and connect to */ + std::vector<Uplink> Uplinks; + /* A vector of our logfile options */ + std::vector<LogInfo> LogInfos; + /* Array of ulined servers */ + std::vector<Anope::string> Ulines; + /* List of available opertypes */ + std::vector<OperType *> MyOperTypes; + /* List of pairs of opers and their opertype from the config */ + std::vector<Oper *> Opers; + /* Map of fantasy commands */ + CommandInfo::map Fantasy; + /* Command groups */ + std::vector<CommandGroup> CommandGroups; + /* List of modules to autoload */ + std::vector<Anope::string> ModulesAutoLoad; + + /* module configuration blocks */ + std::map<Anope::string, Block *> modules; + + Conf(); + + void LoadConf(File &file); + + Block *GetModule(Module *); + Block *GetModule(const Anope::string &name); + }; struct Uplink { @@ -338,352 +132,10 @@ class CoreExport ServerConfig bool ipv6; Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { } - bool operator==(const Uplink &other) const - { - if (this->host != other.host) - return false; - if (this->port != other.port) - return false; - if (this->password != other.password) - return false; - if (this->ipv6 != other.ipv6) - return false; - return true; - } + inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && ipv6 == other.ipv6; } inline bool operator!=(const Uplink &other) const { return !(*this == other); } }; - - /** Below here is a list of variables which contain the config files values - */ - /* Host to bind to */ - Anope::string LocalHost; - /* List of uplink servers to try and connect to */ - std::vector<Uplink *> Uplinks; - - /* Our server name */ - Anope::string ServerName; - /* Our servers description */ - Anope::string ServerDesc; - - /* Name of the network were on */ - Anope::string NetworkName; - /* The max legnth of nicks */ - unsigned NickLen; - /* Max length of idents */ - unsigned UserLen; - /* Max lenght of hostnames */ - unsigned HostLen; - /* Max length of channel names */ - unsigned ChanLen; - /* Max length of b/e/I lists */ - unsigned ListSize; - - /* User and group to run as */ - Anope::string User; - Anope::string Group; - - /* Casemapping to use */ - Anope::string CaseMap; - - /* Max length of passwords */ - unsigned PassLen; - - /* Filename for the PID file */ - Anope::string PIDFilename; - /* MOTD filename */ - Anope::string MOTDFilename; - - Anope::string BotServ; - Anope::string ChanServ; - Anope::string Global; - Anope::string HostServ; - Anope::string NickServ; - Anope::string OperServ; - Anope::string MemoServ; - - /* True if its ok to not be able to save backs */ - bool NoBackupOkay; - /* Do password checking when new people register */ - bool StrictPasswords; - /* How many times you're allowed to give a bad password before being killed */ - unsigned BadPassLimit; - /* How long before bad passwords are forgotten */ - time_t BadPassTimeout; - /* Delay between automatic database updates */ - time_t UpdateTimeout; - /* Delay between checks for expired nicks and channels */ - time_t ExpireTimeout; - /* How long to wait for something from the uplink, this is passed to select() */ - time_t ReadTimeout; - /* How often to send program errors */ - time_t WarningTimeout; - /* How long to process things such as timers to see if there is anything to calll */ - time_t TimeoutCheck; - /* Number of days backups are kept */ - int KeepBackups; - /* Forbidding requires a reason */ - bool ForceForbidReason; - /* Services should use privmsgs instead of notices */ - bool UsePrivmsg; - /* Services only respond to full PRIVMSG client@services.server.name messages */ - bool UseStrictPrivMsg; - /* This is not a configurable option. - * Config::Config will set it depending on the value of UseStrictPrivMsg */ - Anope::string UseStrictPrivMsgString; - /* Number of seconds between consecutive uses of the REGISTER command - * Not to be confused with NSRegDelay */ - unsigned NickRegDelay; - /* Max number if news items allowed in the list */ - unsigned NewsCount; - /* Default mlock modes */ - Anope::string MLock; - /* Unmlockable modes */ - Anope::string NoMLock; - /* Modes that are required to be on registered channels */ - Anope::string CSRequire; - /* Use server side mlock */ - bool UseServerSideMLock; - /* Use server side topic lock */ - bool UseServerSideTopicLock; - /* The max length for reasons (cs_kick, cs_ban, etc) */ - unsigned CSReasonMax; - /* Default botmodes on channels, defaults to ao */ - Anope::string BotModes; - /* How long to wait between connection attempts */ - int RetryWait; - /* If services should hide unprivileged commands */ - bool HidePrivilegedCommands; - /* If set, nicks cant be owned/everything is entirely account based */ - bool NoNicknameOwnership; - /* Regex engine to use */ - Anope::string RegexEngine; - - /* A vector of our logfile options */ - std::vector<LogInfo *> LogInfos; - - /* Services can use email */ - bool UseMail; - /* Path to the sendmail executable */ - Anope::string SendMailPath; - /* Address to send from */ - Anope::string SendFrom; - /* Only opers can have services send mail */ - bool RestrictMail; - /* Delay between sending mail */ - time_t MailDelay; - /* Don't quote the To: address */ - bool DontQuoteAddresses; - /* Mail messages to send */ - Anope::string MailRegistrationSubject, MailRegistrationMessage; - Anope::string MailResetSubject, MailResetMessage; - Anope::string MailEmailchangeSubject, MailEmailchangeMessage; - Anope::string MailMemoSubject, MailMemoMessage; - - /* Prefix of guest nicks when a user gets forced off of a nick */ - Anope::string NSGuestNickPrefix; - /* Allow users to set kill immed on */ - bool NSAllowKillImmed; - /* Don't allow nicks to use /ns group to regroup nicks */ - bool NSNoGroupChange; - /* Default flags for newly registered nicks */ - std::set<Anope::string> NSDefFlags; - /* All languages Anope is aware about */ - Anope::string Languages; - /* Default language used by services */ - Anope::string NSDefLanguage; - /* Users must be connected this long before they can register - * Not to be confused with NickRegDelay */ - time_t NSRegDelay; - /* Time before the registering mail will be resent */ - time_t NSResendDelay; - /* How long before nicks expire */ - time_t NSExpire; - /* How long before suspended nicks expire */ - time_t NSSuspendExpire; - /* Time before unconfirmed nicks expire */ - time_t NSUnconfirmedExpire; - /* Force email when registering */ - bool NSForceEmail; - /* Force users to validate new email addresses */ - bool NSConfirmEmailChanges; - /* Max number of nicks in a group */ - unsigned NSMaxAliases; - /* Max number of allowed strings on the access list */ - unsigned NSAccessMax; - /* Enforcer client user name */ - Anope::string NSEnforcerUser; - /* Enforcer client hostname */ - Anope::string NSEnforcerHost; - /* How long before recovered nicks are released */ - time_t NSReleaseTimeout; - /* Max number of entries that can be returned from the list command */ - unsigned NSListMax; - /* Only allow usermode +a etc on real services admins */ - bool NSSecureAdmins; - /* Services opers must be /operd on the ircd aswell */ - bool NSStrictPrivileges; - /* Type of confirmation to use, or to disable registration completely */ - Anope::string NSRegistration; - /* A message sent to unregistered users on connect */ - Anope::string NSUnregisteredNotice; - /* Core NickServ modules */ - Anope::string NickCoreModules; - /* Set the proper channel modes on users when they identify */ - bool NSModeOnID; - /* Add the users hostnask their access list when they register */ - bool NSAddAccessOnReg; - /* Maximum number of channels on AJoin */ - unsigned AJoinMax; - /* Kill & killquick delays before force changing off users */ - time_t NSKillQuick; - time_t NSKill; - /* Modes set on a user when they identify */ - Anope::string NSModesOnID; - /* Restore nick/channels on recover */ - bool NSRestoreOnRecover; - /* Whether or not to use SASL */ - bool NSSASL; - /* If set, hides netsplits in the last_quit field of nicks */ - bool NSHideNetSplitQuit; - - /* Core ChanServ modules */ - Anope::string ChanCoreModules; - /* Default flags for newly registered channels */ - std::set<Anope::string> CSDefFlags; - /* Max number of channels a user can own */ - unsigned CSMaxReg; - /* Time before a channel expires */ - time_t CSExpire; - /* How long before suspended channels expire */ - time_t CSSuspendExpire; - /* How long before forbidden channels expire */ - time_t CSForbidExpire; - /* Default ban type to use for channels */ - int CSDefBantype; - /* Max number of entries allowed on channel access lists */ - unsigned CSAccessMax; - /* Max number of entries allowed on autokick lists */ - unsigned CSAutokickMax; - /* Default autokick reason */ - Anope::string CSAutokickReason; - /* Time ChanServ should stay in the channel to hold it to keep users from getting in */ - time_t CSInhabit; - /* Max number of entries allowed to be returned from the LIST command */ - unsigned CSListMax; - /* true to make ChanServ oper only */ - bool CSOpersOnly; - - /* Max number of memos allowed */ - unsigned MSMaxMemos; - /* Time you must wait between sending memos */ - time_t MSSendDelay; - /* Notify all of the aliases of the core the memo was sent to */ - bool MSNotifyAll; - /* Who can use memos reciepts */ - unsigned MSMemoReceipt; - - /* Valid chars allowed in vhosts */ - Anope::string VhostChars; - /* Allow undotted vhosts? */ - bool VhostUndotted; - /* Chars disallowed at the beginning or end of vhosts */ - Anope::string VhostDisallowBE; - - /* Core BotServ modules */ - Anope::string BotCoreModules; - /* Default BotServ flags */ - std::set<Anope::string> BSDefFlags; - /* How long before botserv forgets a user. This is used for flood kickers etc */ - time_t BSKeepData; - /* Min number of users to have in the channel before the service bot joins */ - unsigned BSMinUsers; - /* Max number of words allowed on the badwordslist */ - unsigned BSBadWordsMax; - /* BotServ bot only joins if it would normally allowed to, abides by bans etc */ - bool BSSmartJoin; - /* Dont tell users what badword they used */ - bool BSGentleBWReason; - /* Case sensitive badwords matching */ - bool BSCaseSensitive; - /* Char to use for the fantasy char, eg ! */ - Anope::string BSFantasyCharacter; - - /* Only show /stats o to opers */ - bool HideStatsO; - /* Send out a global when services shut down or restart */ - bool GlobalOnCycle; - /* Don't include the opers name in globals */ - bool AnonymousGlobal; - /* Dont allow users to register nicks with oper names in them */ - bool RestrictOperNicks; - /* Message to send when shutting down */ - Anope::string GlobalOnCycleMessage; - /* Message to send when starting up */ - Anope::string GlobalOnCycleUP; - /* Super admin is allowed */ - bool SuperAdmin; - /* Default expiry time for akills */ - time_t AutokillExpiry; - /* Default expiry time for chan kills */ - time_t ChankillExpiry; - /* Default expiry time for SNLine Expire */ - time_t SNLineExpiry; - /* Default expiry time for SQLines */ - time_t SQLineExpiry; - /* Actually akill the user when the akill is added */ - bool AkillOnAdd; - /* Kill users on SNLine */ - bool KillonSNline; - /* Kill users on SQline */ - bool KillonSQline; - /* Add the akillers nick to the akill reason */ - bool AddAkiller; - /* Add akill ids to akill reason */ - bool AkillIds; - - /* Limit sessions */ - bool LimitSessions; - /* The default session limit */ - unsigned DefSessionLimit; - /* How long before exceptions expire */ - time_t ExceptionExpiry; - /* How many times to kill before adding an KILL */ - unsigned MaxSessionKill; - /* Max limit that can be used for exceptions */ - unsigned MaxSessionLimit; - /* How long session akills should last */ - time_t SessionAutoKillExpiry; - /* Number of bits to use when comparing session IPs */ - unsigned SessionIPv4CIDR; - unsigned SessionIPv6CIDR; - /* Reason to use for session kills */ - Anope::string SessionLimitExceeded; - /* Optional second reason */ - Anope::string SessionLimitDetailsLoc; - /* OperServ requires you to be an operator */ - bool OSOpersOnly; - - /* List of modules to autoload */ - std::list<Anope::string> ModulesAutoLoad; - - /* Seed to use for RNG */ - unsigned long Seed; - - /* Numeric */ - Anope::string Numeric; - /* Array of ulined servers */ - std::list<Anope::string> Ulines; - - /* List of available opertypes */ - std::list<OperType *> MyOperTypes; - /* List of pairs of opers and their opertype from the config */ - std::vector<Oper *> Opers; - - /* Map of fantasy commands */ - CommandInfo::map Fantasy; - - std::vector<CommandGroup> CommandGroups; -}; +} /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception. * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or @@ -707,115 +159,7 @@ class ConfigException : public CoreException virtual ~ConfigException() throw() { } }; -enum -{ - CONF_NO_ERROR, - CONF_INT_NEGATIVE = 1 << 1, - CONF_VALUE_NOT_FOUND = 1 << 2 -}; - -/** Allows reading of values from configuration files - * This class allows a module to read from either the main configuration file (services.conf) or from - * a module-specified configuration file. It may either be instantiated with one parameter or none. - * Constructing the class using one parameter allows you to specify a path to your own configuration - * file, otherwise, inspircd.conf is read. - */ -class CoreExport ConfigReader -{ - ServerConfig *conf; - protected: - /** True if an error occured reading the config file - */ - bool readerror; - /** Error code - */ - long error; - public: - /** Default constructor. - * This constructor initialises the ConfigReader class to read the configuration file(s). - */ - ConfigReader(); - /** Overloaded constructor. - * This constructor initialises the ConfigReader class to read a user-specified config file - */ - ConfigReader(const Anope::string &); - /** Overloaded constructor - * This constructor initialises the ConfigReader class to use a user sepcific ServerConfig object, - */ - ConfigReader(ServerConfig *); - /** Default destructor. - * This method destroys the ConfigReader class. - */ - ~ConfigReader(); - /** Retrieves a value from the config file. - * This method retrieves a value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. - */ - Anope::string ReadValue(const Anope::string &, const Anope::string &, int, bool = false); - /** Retrieves a value from the config file. - * This method retrieves a value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. If the - * tag is not found the default value is returned instead. - */ - Anope::string ReadValue(const Anope::string &, const Anope::string &, const Anope::string &, int, bool = false); - /** Retrieves a boolean value from the config file. - * This method retrieves a boolean value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" - * and "true" in the config file count as true to ReadFlag, and any other value counts as false. - */ - bool ReadFlag(const Anope::string &, const Anope::string &, int); - /** Retrieves a boolean value from the config file. - * This method retrieves a boolean value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. The values "1", "yes" - * and "true" in the config file count as true to ReadFlag, and any other value counts as false. - * If the tag is not found, the default value is used instead. - */ - bool ReadFlag(const Anope::string &, const Anope::string &, const Anope::string &, int); - /** Retrieves an integer value from the config file. - * This method retrieves an integer value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. Any invalid integer - * values in the tag will cause the objects error value to be set, and any call to GetError() will - * return CONF_INVALID_NUMBER to be returned. need_positive is set if the number must be non-negative. - * If a negative number is placed into a tag which is specified positive, 0 will be returned and GetError() - * will return CONF_INT_NEGATIVE. Note that need_positive is not suitable to get an unsigned int - you - * should cast the result to achieve that effect. - */ - int ReadInteger(const Anope::string &, const Anope::string &, int, bool); - /** Retrieves an integer value from the config file. - * This method retrieves an integer value from the config file. Where multiple copies of the tag - * exist in the config file, index indicates which of the values to retrieve. Any invalid integer - * values in the tag will cause the objects error value to be set, and any call to GetError() will - * return CONF_INVALID_NUMBER to be returned. needs_unsigned is set if the number must be unsigned. - * If a signed number is placed into a tag which is specified unsigned, 0 will be returned and GetError() - * will return CONF_NOT_UNSIGNED. If the tag is not found, the default value is used instead. - */ - int ReadInteger(const Anope::string &, const Anope::string &, const Anope::string &, int, bool); - /** Returns the last error to occur. - * Valid errors can be found by looking in modules.h. Any nonzero value indicates an error condition. - * A call to GetError() resets the error flag back to 0. - */ - long GetError(); - /** Counts the number of times a given tag appears in the config file. - * This method counts the number of times a tag appears in a config file, for use where - * there are several tags of the same kind, e.g. with opers and connect types. It can be - * used with the index value of ConfigReader::ReadValue to loop through all copies of a - * multiple instance tag. - */ - int Enumerate(const Anope::string &) const; - /** Returns true if a config file is valid. - * This method is partially implemented and will only return false if the config - * file does not exist or could not be opened. - */ - bool Verify(); - /** Returns the number of items within a tag. - * For example if the tag was <test tag="blah" data="foo"> then this - * function would return 2. Spaces and newlines both qualify as valid seperators - * between values. - */ - int EnumerateValues(const Anope::string &, int); -}; - -extern ConfigurationFile ServicesConf; -extern CoreExport ServerConfig *Config; +extern Configuration::File ServicesConf; +extern CoreExport Configuration::Conf *Config; #endif // CONFIG_H diff --git a/include/defs.h b/include/defs.h index 34e900717..8e1f17898 100644 --- a/include/defs.h +++ b/include/defs.h @@ -20,9 +20,11 @@ class ChanAccess; class Channel; class ChannelInfo; class ChannelStatus; +struct ChanUserContainer; class ClientSocket; class Command; class CommandSource; +namespace Configuration { class Conf; } class ConnectionSocket; namespace DNS { class Packet; } class Entry; @@ -42,7 +44,6 @@ class ReferenceBase; class Regex; class Serializable; class Server; -class ServerConfig; class Socket; class Thread; class User; diff --git a/include/modes.h b/include/modes.h index f5a1296c5..2d9755817 100644 --- a/include/modes.h +++ b/include/modes.h @@ -205,6 +205,8 @@ class CoreExport ChannelStatus { Anope::string modes; public: + ChannelStatus(); + ChannelStatus(const Anope::string &modes); void AddMode(char c); void DelMode(char c); bool HasMode(char c) const; @@ -308,11 +310,6 @@ class CoreExport ModeManager /* Number of generic channel and user modes we are tracking */ static unsigned GenericChannelModes; static unsigned GenericUserModes; - /* Default channel mode lock */ - static std::list<std::pair<Anope::string, Anope::string> > ModeLockOn; - static std::list<Anope::string> ModeLockOff; - /* Default modes bots have on channels */ - static ChannelStatus DefaultBotModes; /** Add a user mode to Anope * @param um A UserMode or UserMode derived class @@ -398,12 +395,6 @@ class CoreExport ModeManager static void StackerDel(User *u); static void StackerDel(Channel *c); static void StackerDel(Mode *m); - - /** Updates the default mode locks and default bot modes - * @param config The configuration to read from. This is often called - * during a config reload. - */ - static void UpdateDefaultMLock(ServerConfig *config); }; /** Represents a mask set on a channel (b/e/I) diff --git a/include/module.h b/include/module.h index 08ba8a4bd..6ff54a31f 100644 --- a/include/module.h +++ b/include/module.h @@ -12,7 +12,6 @@ #ifndef MODULE_H #define MODULE_H -/* Just include everything for now */ #include "access.h" #include "account.h" #include "anope.h" @@ -47,6 +46,7 @@ #include "users.h" #include "xline.h" +#include "chanserv.h" #include "global.h" #include "memoserv.h" #include "nickserv.h" diff --git a/include/modules.h b/include/modules.h index e9846f609..5ff58751f 100644 --- a/include/modules.h +++ b/include/modules.h @@ -112,8 +112,6 @@ if (true) \ else \ static_cast<void>(0) -class ConfigReader; - /** Possible return types from events. */ enum EventReturn @@ -278,20 +276,27 @@ class CoreExport Module : public Extensible * before they will be called. */ - /** Called when the ircd notifies that a user has been kicked from a channel. - * @param c The channel the user has been kicked from. - * @param target The user that has been kicked. - * @param source The nick of the sender. + /** Called before a user has been kicked from a channel. + * @param source The kicker + * @param cu The user, channel, and status of the user being kicked + * @param kickmsg The reason for the kick. + */ + virtual void OnPreUserKicked(MessageSource &source, ChanUserContainer *cu, const Anope::string &kickmsg) { } + + /** Called when a user has been kicked from a channel. + * @param source The kicker + * @param target The user being kicked + * @param channel The channel the user was kicked from, which may no longer exist + * @param status The status the kicked user had on the channel before they were kicked * @param kickmsg The reason for the kick. */ - virtual void OnUserKicked(Channel *c, User *target, MessageSource &source, const Anope::string &kickmsg) { } + virtual void OnUserKicked(MessageSource &source, User *target, const Anope::string &channel, ChannelStatus &status, const Anope::string &kickmsg) { } /** Called when Services' configuration is being (re)loaded. * @param conf The config that is being built now and will replace the global Config object - * @param reader A config reader for conf * @throws A ConfigException to abort the config (re)loading process. */ - virtual void OnReload(ServerConfig *conf, ConfigReader &reader) { } + virtual void OnReload(Configuration::Conf *conf) { } /** Called before a bot is assigned to a channel. * @param sender The user assigning the bot @@ -299,7 +304,11 @@ class CoreExport Module : public Extensible * @param bi The bot being assigned. * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to deny the assign. */ - virtual EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { return EVENT_CONTINUE; } + virtual EventReturn OnPreBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { return EVENT_CONTINUE; } + + /** Called when a bot is assigned ot a channel + */ + virtual void OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { } /** Called before a bot is unassigned from a channel. * @param sender The user unassigning the bot @@ -387,12 +396,6 @@ class CoreExport Module : public Extensible */ virtual EventReturn OnBotNoFantasyAccess(CommandSource &source, Command *c, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) { return EVENT_CONTINUE; } - /** Called after a bot joins a channel - * @param c The channel - * @param bi The bot - */ - virtual void OnBotJoin(Channel *c, BotInfo *bi) { } - /** Called when a bot places a ban * @param u User being banned * @param ci Channel the ban is placed on @@ -442,13 +445,6 @@ class CoreExport Module : public Extensible */ virtual void OnLeaveChannel(User *u, Channel *c) { } - /** Called before a user joins a channel - * @param u The user - * @param c The channel - * @return EVENT_STOP to allow the user to join the channel through restrictions, EVENT_CONTINUE to let other modules decide - */ - virtual EventReturn OnPreJoinChannel(User *u, Channel *c) { return EVENT_CONTINUE; } - /** Called when a user joins a channel * @param u The user * @param channel The channel @@ -551,13 +547,15 @@ class CoreExport Module : public Extensible */ virtual void OnServerQuit(Server *server) { } - /** Called on a QUIT + /** Called when a user quits, or is killed * @param u The user * @param msg The quit message */ virtual void OnUserQuit(User *u, const Anope::string &msg) { } - /** Called when a user disconnects, before and after being internally removed from + /** Called when a user is quit, before and after being internally removed from + * This is different from OnUserQuit, which takes place at the time of the quit. + * This happens shortly after when all message processing is finished. * all lists (channels, user list, etc) * @param u The user */ @@ -721,9 +719,10 @@ class CoreExport Module : public Extensible virtual void OnNickLogout(User *u) { } /** Called when a nick is registered + * @param user The user registering the nick, of any * @param The nick */ - virtual void OnNickRegister(NickAlias *na) { } + virtual void OnNickRegister(User *user, NickAlias *na) { } /** Called when a nick is suspended * @param na The nick alias @@ -740,6 +739,11 @@ class CoreExport Module : public Extensible */ virtual void OnDelNick(NickAlias *na) { } + /** Called when a nickcore is created + * @param nc The nickcore + */ + virtual void OnNickCoreCreate(NickCore *nc) { } + /** Called on delcore() * @param nc pointer to the NickCore */ @@ -963,6 +967,21 @@ class CoreExport Module : public Extensible */ virtual EventReturn OnCheckModes(Channel *c) { return EVENT_CONTINUE; } + /** Called when a channel is synced. + * Channels are synced after a sjoin is finished processing + * for a newly created channel to set the correct modes, topic, + * set. + */ + virtual void OnChannelSync(Channel *c) { } + + /** Called to set the correct modes on the user on the given channel + * @param user The user + * @param chan The channel + * @param access The user's access on the channel + * @param give_modes If giving modes is desired + */ + virtual void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool give_modes) { } + virtual void OnSerializeCheck(Serialize::Type *) { } virtual void OnSerializableConstruct(Serializable *) { } virtual void OnSerializableDestruct(Serializable *) { } @@ -994,6 +1013,12 @@ class CoreExport Module : public Extensible * @return EVENT_STOP to prevent the protocol module from processing this message */ virtual EventReturn OnMessage(MessageSource &source, Anope::string &command, std::vector<Anope::string> ¶m) { return EVENT_CONTINUE; } + + /** Called to determine if a chnanel mode can be set by a user + * @param u The user + * @param cm The mode + */ + virtual EventReturn OnCanSet(User *u, const ChannelMode *cm) { return EVENT_CONTINUE; } }; /** Implementation-specific flags which may be set in ModuleManager::Attach() @@ -1003,7 +1028,7 @@ enum Implementation I_BEGIN, /* NickServ */ I_OnPreNickExpire, I_OnNickExpire, I_OnNickForbidden, I_OnNickGroup, I_OnNickLogout, I_OnNickIdentify, I_OnNickDrop, - I_OnNickRegister, I_OnNickSuspended, I_OnNickUnsuspended, I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, + I_OnNickRegister, I_OnNickSuspended, I_OnNickUnsuspended, I_OnDelNick, I_OnNickCoreCreate, I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearCert, I_OnNickAddCert, I_OnNickEraseCert, I_OnNickInfo, I_OnCheckAuthentication, I_OnNickUpdate, I_OnSetNickOption, @@ -1011,11 +1036,11 @@ enum Implementation I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd, I_OnAccessDel, I_OnAccessClear, I_OnLevelChange, I_OnChanRegistered, I_OnChanUnsuspend, I_OnCreateChan, I_OnDelChan, I_OnChannelCreate, I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick, I_OnCheckModes, - I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnSetChannelOption, + I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv, I_OnSetChannelOption, I_OnChannelSync, I_OnSetCorrectModes, /* BotServ */ - I_OnBotJoin, I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign, - I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel, + I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnPreBotAssign, I_OnBotAssign, I_OnBotUnAssign, + I_OnPreUserKicked, I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel, /* HostServ */ I_OnSetVhost, I_OnDeleteVhost, @@ -1024,7 +1049,7 @@ enum Implementation I_OnMemoSend, I_OnMemoDel, /* Users */ - I_OnUserConnect, I_OnUserNickChange, I_OnUserQuit, I_OnPreUserLogoff, I_OnPostUserLogoff, I_OnPreJoinChannel, + I_OnUserConnect, I_OnUserNickChange, I_OnUserQuit, I_OnPreUserLogoff, I_OnPostUserLogoff, I_OnJoinChannel, I_OnPrePartChannel, I_OnPartChannel, I_OnLeaveChannel, I_OnFingerprint, I_OnUserAway, I_OnInvite, /* OperServ */ @@ -1044,7 +1069,7 @@ enum Implementation I_OnEncrypt, I_OnDecrypt, I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd, I_OnMLock, I_OnUnMLock, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnPrivmsg, I_OnLog, I_OnDnsRequest, - I_OnMessage, + I_OnMessage, I_OnCanSet, I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate, I_OnSerializeTypeCreate, I_END diff --git a/include/protocol.h b/include/protocol.h index 2de0c8e08..874fbbe2c 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -31,7 +31,6 @@ class CoreExport IRCDProto : public Service virtual void SendModeInternal(const BotInfo *, const Channel *, const Anope::string &); virtual void SendModeInternal(const BotInfo *, const User *, const Anope::string &); virtual void SendKickInternal(const BotInfo *, const Channel *, const User *, const Anope::string &); - virtual void SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); virtual void SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg); virtual void SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf); virtual void SendQuitInternal(const User *u, const Anope::string &buf); @@ -127,8 +126,6 @@ class CoreExport IRCDProto : public Service virtual void SendKick(const BotInfo *bi, const Channel *chan, const User *user, const char *fmt, ...); - /* Sends a message using SendPrivmsg or SendNotice, depending on the default message method. */ - virtual void SendMessage(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); virtual void SendNotice(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); virtual void SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); virtual void SendAction(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...); @@ -193,7 +190,7 @@ class CoreExport IRCDProto : public Service virtual void SendBOB() { } virtual void SendEOB() { } - virtual void SendSVSHold(const Anope::string &) { } + virtual void SendSVSHold(const Anope::string &, time_t) { } virtual void SendSVSHoldDel(const Anope::string &) { } virtual void SendSWhois(const BotInfo *bi, const Anope::string &, const Anope::string &) { } diff --git a/include/servers.h b/include/servers.h index bf0acb523..fe5f40365 100644 --- a/include/servers.h +++ b/include/servers.h @@ -121,6 +121,10 @@ class CoreExport Server : public Extensible */ const Anope::string &GetSID() const; + /** Retrieves the reason this server is quitting + */ + const Anope::string &GetQuitReason() const; + /** Get the list of links this server has, or NULL if it has none * @return A list of servers */ diff --git a/include/users.h b/include/users.h index 4248ce744..00ff5e410 100644 --- a/include/users.h +++ b/include/users.h @@ -212,7 +212,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe /** Get the account the user is logged in using * @return The account or NULL */ - virtual NickCore *Account() const; + NickCore *Account() const; /** Check if the user is identified for their nick * @param check_nick True to check if the user is identified to the nickname they are on too |