diff options
| author | Adam <Adam@drink-coca-cola.info> | 2010-05-14 20:35:38 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2010-06-18 21:01:53 -0400 |
| commit | f049124905bd9f53439293e873003cb027a17b91 (patch) | |
| tree | 352ed9251fd47055dd770aa2d5eabb20247e4b43 /include | |
| parent | 81a45520a773732c9f46785f27aa1956150775d7 (diff) | |
Rewrote the hashing system to use std::tr1::unordered_map
Diffstat (limited to 'include')
| -rw-r--r-- | include/Makefile | 2 | ||||
| -rw-r--r-- | include/account.h | 15 | ||||
| -rw-r--r-- | include/bots.h | 24 | ||||
| -rw-r--r-- | include/channels.h | 4 | ||||
| -rw-r--r-- | include/commands.h | 62 | ||||
| -rw-r--r-- | include/extern.h | 50 | ||||
| -rw-r--r-- | include/hashcomp.h | 58 | ||||
| -rw-r--r-- | include/messages.h | 22 | ||||
| -rw-r--r-- | include/modules.h | 196 | ||||
| -rw-r--r-- | include/regchannel.h | 4 | ||||
| -rw-r--r-- | include/services.h | 25 | ||||
| -rw-r--r-- | include/users.h | 11 |
12 files changed, 221 insertions, 252 deletions
diff --git a/include/Makefile b/include/Makefile index 3d8067aa6..69e2473f6 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,7 +1,7 @@ all: services.h extern.h pseudo.h version.h -version.h: Makefile version.sh services.h pseudo.h messages.h $(SRCS) +version.h: Makefile version.sh services.h pseudo.h $(SRCS) sh version.sh ../version.log $@ services.h: sysconf.h config.h extern.h diff --git a/include/account.h b/include/account.h index 5449bd93a..1a567c317 100644 --- a/include/account.h +++ b/include/account.h @@ -1,3 +1,14 @@ +class NickAlias; +class NickCore; +class NickRequest; + +typedef unordered_map_namespace::unordered_map<ci::string, NickAlias *, hash_compare_ci_string> nickalias_map; +typedef unordered_map_namespace::unordered_map<ci::string, NickCore *, hash_compare_ci_string> nickcore_map; +typedef unordered_map_namespace::unordered_map<ci::string, NickRequest *, hash_compare_ci_string> nickrequest_map; + +extern CoreExport nickalias_map NickAliasList; +extern CoreExport nickcore_map NickCoreList; +extern CoreExport nickrequest_map NickRequestList; /* NickServ nickname structures. */ @@ -76,7 +87,6 @@ class CoreExport NickRequest : public Extensible ~NickRequest(); - NickRequest *next, *prev; char *nick; std::string passcode; std::string password; @@ -100,7 +110,6 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag> */ ~NickAlias(); - NickAlias *next, *prev; char *nick; /* Nickname */ char *last_quit; /* Last quit message */ char *last_realname; /* Last realname */ @@ -135,8 +144,6 @@ class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag> */ ~NickCore(); - NickCore *next, *prev; - std::list<User *> Users; char *display; /* How the nick is displayed */ diff --git a/include/bots.h b/include/bots.h index 3b4987bb7..b73b39879 100644 --- a/include/bots.h +++ b/include/bots.h @@ -8,6 +8,12 @@ * */ +#include "commands.h" + +class BotInfo; +typedef unordered_map_namespace::unordered_map<ci::string, BotInfo *, hash_compare_ci_string> botinfo_map; +extern CoreExport botinfo_map BotList; + /** Flags settable on a bot */ enum BotFlag @@ -16,29 +22,13 @@ enum BotFlag /* 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 : public Extensible, public Flags<BotFlag> { public: - BotInfo *next, *prev; - std::string uid; /* required for UID supporting servers, as opposed to the shitty struct Uid. */ std::string nick; /* Nickname of the bot */ std::string user; /* Its user name */ @@ -48,7 +38,7 @@ class CoreExport BotInfo : public Extensible, public Flags<BotFlag> int16 chancount; /* Number of channels that use the bot. */ /* Dynamic data */ time_t lastmsg; /* Last time we said something */ - CommandHash **cmdTable; + CommandMap Commands; /** Create a new bot. * @param nick The nickname to assign to the bot. diff --git a/include/channels.h b/include/channels.h index 51b830c03..4285a9f21 100644 --- a/include/channels.h +++ b/include/channels.h @@ -8,6 +8,9 @@ * */ +typedef unordered_map_namespace::unordered_map<ci::string, Channel *, hash_compare_ci_string> channel_map; +extern CoreExport channel_map ChannelList; + struct UserData { UserData() @@ -72,7 +75,6 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags> */ ~Channel(); - Channel *next, *prev; std::string name; /* Channel name */ ChannelInfo *ci; /* Corresponding ChannelInfo */ time_t creation_time; /* When channel was created */ diff --git a/include/commands.h b/include/commands.h index 5d43f556b..5d381084e 100644 --- a/include/commands.h +++ b/include/commands.h @@ -14,25 +14,13 @@ #ifndef COMMAND_H_ #define COMMAND_H_ -#define MAX_CMD_HASH 1024 -#define CMD_HASH(x) (((x)[0]&31)<<5 | ((x)[1]&31)) /* Will gen a hash from a string :) */ - -#define HOSTSERV HS_cmdTable /* using HOSTSERV etc. looks nicer than HS_cmdTable for modules */ -#define BOTSERV BS_cmdTable -#define MEMOSERV MS_cmdTable -#define NICKSERV NS_cmdTable -#define CHANSERV CS_cmdTable -#define OPERSERV OS_cmdTable - -#ifndef _WIN32 -#define MDE -#else -#ifndef MODULE_COMPILE -#define MDE __declspec(dllexport) -#else -#define MDE __declspec(dllimport) -#endif -#endif +#include "services.h" + +class Module; +class BotInfo; +class Command; + +typedef std::map<ci::string, Command *> CommandMap; /** The return value from commands. * */ @@ -42,24 +30,9 @@ enum CommandReturn MOD_STOP }; -class Command; - -extern MDE Command *lookup_cmd(Command *list, char *name); -extern MDE void mod_help_cmd(char *service, User *u, CommandHash *cmdTable[], const char *cmd); -extern MDE void mod_run_cmd(const std::string &service, User *u, CommandHash *cmdTable[], const char *cmd); - -struct CommandHash { - char *name; /* Name of the command */ - Command *c; /* Actual command */ - CommandHash *next; /* Next command */ -}; - -extern MDE CommandHash *HOSTSERV[MAX_CMD_HASH]; -extern MDE CommandHash *BOTSERV[MAX_CMD_HASH]; -extern MDE CommandHash *MEMOSERV[MAX_CMD_HASH]; -extern MDE CommandHash *NICKSERV[MAX_CMD_HASH]; -extern MDE CommandHash *CHANSERV[MAX_CMD_HASH]; -extern MDE CommandHash *OPERSERV[MAX_CMD_HASH]; +extern CoreExport Command *FindCommand(BotInfo *bi, const ci::string &cmd); +extern CoreExport void mod_help_cmd(BotInfo *bi, User *u, const ci::string &cmd); +extern CoreExport void mod_run_cmd(BotInfo *bi, User *u, const ci::string &cmd); enum CommandFlag { @@ -76,11 +49,20 @@ enum CommandFlag class CoreExport Command : public Flags<CommandFlag> { public: + /* Maximum paramaters accepted by this command */ size_t MaxParams; + /* Minimum parameters required to use this command */ size_t MinParams; + /* Command name */ ci::string name; + /* Permission needed to use this comand */ std::string permission; + /* Module which owns us */ + Module *module; + /* Service this command is on */ + BotInfo *service; + /** Create a new command. * @param sname The command name * @param min_params The minimum number of parameters the parser will require to execute this command @@ -114,12 +96,6 @@ class CoreExport Command : public Flags<CommandFlag> * @param reststr The permission required to successfully execute this command */ void SetPermission(const std::string &reststr); - - /* Module related stuff */ - int core; /* Can this command be deleted? */ - char *mod_name; /* Name of the module who owns us, NULL for core's */ - char *service; /* Service we provide this command for */ - Command *next; }; #endif diff --git a/include/extern.h b/include/extern.h index 67364c0f5..a10585e69 100644 --- a/include/extern.h +++ b/include/extern.h @@ -46,14 +46,14 @@ E BotInfo *OperServ; /**** botserv.c ****/ -E BotInfo *botlists[256]; -E int nbots; E void get_botserv_stats(long *nrec, long *memuse); E void bs_init(); E void botserv(User *u, char *buf); E void botmsgs(User *u, BotInfo *bi, char *buf); E void botchanmsgs(User *u, ChannelInfo *ci, char *buf); +E BotInfo *findbot(const char *nick); E BotInfo *findbot(const std::string &nick); +E BotInfo *findbot(const ci::string &nick); /** Finds a pseudoclient, given a UID. Useful for TS6 protocol modules. * @param uid The UID to search for @@ -61,7 +61,6 @@ E BotInfo *findbot(const std::string &nick); */ E void bot_join(ChannelInfo *ci); E char *normalizeBuffer(const char *); -E void insert_bot(BotInfo * bi); E void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, const char *reason); E void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, const char *reason); @@ -69,12 +68,11 @@ E void bot_raw_mode(User * requester, ChannelInfo * ci, const char *mode, char * /**** channels.c ****/ -E Channel *chanlist[1024]; - E void get_channel_stats(long *nrec, long *memuse); + E Channel *findchan(const char *chan); -E Channel *firstchan(); -E Channel *nextchan(); +E Channel *findchan(const std::string &chan); +E Channel *findchan(const ci::string &chan); E void ChanSetInternalModes(Channel *c, int ac, const char **av); @@ -112,12 +110,10 @@ E long get_memuse(EList *list); /**** chanserv.c ****/ -E ChannelInfo *chanlists[256]; E LevelInfo levelinfo[]; E void get_chanserv_stats(long *nrec, long *memuse); -E void alpha_insert_chan(ChannelInfo * ci); E void reset_levels(ChannelInfo * ci); E void cs_init(); E void chanserv(User * u, char *buf); @@ -136,7 +132,9 @@ E void record_topic(const char *chan); E void restore_topic(const char *chan); E int check_topiclock(Channel * c, time_t topic_time); +E ChannelInfo *cs_findchan(const char *chan); E ChannelInfo *cs_findchan(const std::string &chan); +E ChannelInfo *cs_findchan(const ci::string &chan); E int check_access(User * user, ChannelInfo * ci, int what); E bool IsFounder(User *user, ChannelInfo *ci); E bool IsRealFounder(User *user, ChannelInfo *ci); @@ -359,18 +357,11 @@ E std::map<ChannelModeName, std::string> DefMLockParams; E std::list<ChannelModeStatus *> BotModes; E void SetDefaultMLock(); -/**** modules.c ****/ -E void modules_unload_all(bool unload_proto); /* Read warnings near function source */ - /**** nickserv.c ****/ -E NickAlias *nalists[1024]; -E NickCore *nclists[1024]; -E NickRequest *nrlists[1024]; E NickRequest *findrequestnick(const char *nick); -E void insert_requestnick(NickRequest * nr); -E void alpha_insert_alias(NickAlias * na); -E void insert_core(NickCore * nc); +E NickRequest *findrequestnick(const std::string &nick); +E NickRequest *findrequestnick(const ci::string &nick); E void get_aliases_stats(long *nrec, long *memuse); E void get_core_stats(long *nrec, long *memuse); E void change_core_display(NickCore * nc); @@ -384,7 +375,10 @@ E void expire_nicks(); E void expire_requests(); E NickAlias *findnick(const char *nick); E NickAlias *findnick(const std::string &nick); -E NickCore *findcore(const char *nick); +E NickAlias *findnick(const ci::string &nick); +E NickCore *findcore(const char *nick); +E NickCore *findcore(const std::string &nick); +E NickCore *findcore(const ci::string &nick); E bool is_on_access(User *u, NickCore *nc); /**** operserv.c ****/ @@ -462,9 +456,6 @@ E void notice_help(const char *source, User *dest, int message, ...); // MARK_DE E Exception *exceptions; E int16 nexceptions; -E Session *sessionlist[1024]; -E int32 nsessions; - E void get_session_stats(long *nrec, long *memuse); E void get_exception_stats(long *nrec, long *memuse); @@ -473,7 +464,7 @@ E void del_session(const char *host); E void expire_exceptions(); -E Session *findsession(const char *host); +E Session *findsession(const std::string &host); E Exception *find_host_exception(const char *host); E Exception *find_hostip_exception(const char *host, const char *hostip); @@ -501,20 +492,19 @@ E int32 TotalWritten; /**** users.c ****/ -E User *userlist[1024]; - E int32 opcnt; E uint32 maxusercnt, usercnt; E time_t maxusertime; E void get_user_stats(long *nusers, long *memuse); -E User *finduser(const std::string &nick); -E User *firstuser(); -E User *nextuser(); +E User *finduser(const char *nick); +E User *finduser(const std::string &nick); +E User *finduser(const ci::string &nick); +E User *find_byuid(const char *uid); +E User *find_byuid(const ci::string &uid); E User *find_byuid(const std::string &uid); -E User *first_uid(); -E User *next_uid(); + E Server *findserver_uid(Server * s, const char *name); E char *TS6SID; diff --git a/include/hashcomp.h b/include/hashcomp.h index becebb48e..a0d456b40 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -15,6 +15,23 @@ #include <string> +#ifndef _WIN32 + #ifdef HASHMAP_DEPRECATED /* If gcc ver > 4.3 */ + /* GCC4.3+ has deprecated hash_map and uses tr1. But of course, uses a different include to MSVC. */ + #include <tr1/unordered_map> + #define unordered_map_namespace std::tr1 + #else + #include <ext/hash_map> + /* Oddball linux namespace for hash_map */ + #define unordered_map_namespace __gnu_cxx + #define unordered_map hash_map + #endif +#else + /* MSVC 2010+ has tr1. Though MSVC and GCC use different includes! */ + #include <unordered_map> + #define unordered_map_namespace std::tr1 +#endif + /******************************************************* * This file contains classes and templates that deal * with the comparison and hashing of 'irc strings'. @@ -30,9 +47,6 @@ * aware of irc::string. *******************************************************/ -#ifndef LOWERMAP -#define LOWERMAP - /** A mapping of uppercase to lowercase, including scandinavian * 'oddities' as specified by RFC1459, e.g. { -> [, and | -> \ */ @@ -72,8 +86,6 @@ unsigned const char ascii_case_insensitive_map[256] = { 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 /* 240-255 */ }; -#endif - /** The irc namespace contains a number of helper classes. */ namespace irc @@ -470,4 +482,40 @@ class spacesepstream : public sepstream spacesepstream(const char *source) : sepstream(source, ' ') { } }; +/** Class used to hash a std::string, given as the third argument to the unordered_map template + */ +class CoreExport hash_compare_std_string +{ + public: + /** Return a hash value for a string + * @param s The string + * @return The hash value + */ + size_t operator()(const std::string &s) const; +}; + +/** Class used to hash a ci::string, given as the third argument to the unordered_map template + */ +class CoreExport hash_compare_ci_string +{ + public: + /** Return a hash value for a string using case insensitivity + * @param s The string + * @return The hash value + */ + size_t operator()(const ci::string &s) const; +}; + +/** Class used to hash a irc::string, given as the third argument to the unordered_map template + */ +class CoreExport hash_compare_irc_string +{ + public: + /** Return a hash value for a string using RFC1459 case sensitivity rules + * @param s The stirng + * @return The hash value + */ + size_t operator()(const irc::string &s) const; +}; + #endif diff --git a/include/messages.h b/include/messages.h deleted file mode 100644 index a5505471e..000000000 --- a/include/messages.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Declarations of IRC message structures, variables, and functions. - * - * (C) 2003-2010 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for furhter details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * - */ - -/*************************************************************************/ -#include "modules.h" - -extern Message messages[]; -extern void moduleAddMsgs(); -extern Message *find_message(const char *name); - - -/*************************************************************************/ diff --git a/include/modules.h b/include/modules.h index f3bc20bfb..d76b8f70b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -104,52 +104,6 @@ do { \ } \ } while(0); - - -/** Priority types which can be returned from Module::Prioritize() - */ -enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; - - - -/*************************************************************************/ - -#define IRCD IRCD_cmdTable -#define MODULE_HASH Module_table -#define EVENT EVENT_cmdTable -#define EVENTHOOKS HOOK_cmdTable - -/********************************************************************** - * Module Returns - **********************************************************************/ -#define MOD_ERR_OK 0 -#define MOD_ERR_MEMORY 1 -#define MOD_ERR_PARAMS 2 -#define MOD_ERR_EXISTS 3 -#define MOD_ERR_NOEXIST 4 -#define MOD_ERR_NOUSER 5 -#define MOD_ERR_NOLOAD 6 -#define MOD_ERR_NOUNLOAD 7 -#define MOD_ERR_SYNTAX 8 -#define MOD_ERR_NODELETE 9 -#define MOD_ERR_UNKNOWN 10 -#define MOD_ERR_FILE_IO 11 -#define MOD_ERR_NOSERVICE 12 -#define MOD_ERR_NO_MOD_NAME 13 - -/*************************************************************************/ -/* Macros to export the Module API functions/variables */ -#ifndef _WIN32 -#define MDE -#else -#ifndef MODULE_COMPILE -#define MDE __declspec(dllexport) -#else -#define MDE __declspec(dllimport) -#endif -#endif -/*************************************************************************/ - #if !defined(_WIN32) #include <dlfcn.h> /* Define these for systems without them */ @@ -169,26 +123,42 @@ enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFOR const char *ano_moderr(); #endif -typedef enum { CORE,PROTOCOL,THIRD,SUPPORTED,QATESTED,ENCRYPTION,DATABASE } MODType; -typedef enum { MOD_OP_LOAD, MOD_OP_UNLOAD } ModuleOperation; - -/*************************************************************************/ -/* Structure for information about a *Serv command. */ +extern CoreExport Module *FindModule(const std::string &name); +int protocol_module_init(); +extern CoreExport Message *createMessage(const char *name, int (*func)(const char *source, int ac, const char **av)); +std::vector<Message *> FindMessage(const std::string &name); +extern CoreExport bool moduleMinVersion(int major,int minor,int patch,int build); -typedef struct ModuleLang_ ModuleLang; -typedef struct ModuleHash_ ModuleHash; -typedef struct Message_ Message; -typedef struct MessageHash_ MessageHash; +enum ModuleReturn +{ + MOD_ERR_OK, + MOD_ERR_MEMORY, + MOD_ERR_PARAMS, + MOD_ERR_EXISTS, + MOD_ERR_NOEXIST, + MOD_ERR_NOUSER, + MOD_ERR_NOLOAD, + MOD_ERR_NOUNLOAD, + MOD_ERR_SYNTAX, + MOD_ERR_NODELETE, + MOD_ERR_UNKNOWN, + MOD_ERR_FILE_IO, + MOD_ERR_NOSERVICE, + MOD_ERR_NO_MOD_NAME +}; -/*************************************************************************/ +/** Priority types which can be returned from Module::Prioritize() + */ +enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; +enum MODType { CORE, PROTOCOL, THIRD, SUPPORTED, QATESTED, ENCRYPTION, DATABASE }; -extern MDE MessageHash *IRCD[MAX_CMD_HASH]; -extern MDE ModuleHash *MODULE_HASH[MAX_CMD_HASH]; +struct Message; +extern CoreExport std::multimap<std::string, Message *> MessageMap; +class Module; +extern CoreExport std::deque<Module *> Modules; -struct ModuleLang_ { - int argc; - char **argv; -}; +/*************************************************************************/ +/* Structure for information about a *Serv command. */ class Version { @@ -247,15 +217,31 @@ class CoreExport Module */ std::list<CallBack *> CallBacks; + /** Handle for this module, obtained from dlopen() + */ ano_module_t handle; + + /** Time this module was created + */ time_t created; + + /** Version of this module + */ std::string version; + + /** Author of the module + */ std::string author; + /** What type this module is + */ MODType type; - MessageHash *msgList[MAX_CMD_HASH]; - ModuleLang lang[NUM_LANGS]; + struct ModuleLang + { + int argc; + char **argv; + } lang[NUM_LANGS]; /** Creates and initialises a new module. * @param loadernick The nickname of the user loading the module. @@ -299,7 +285,7 @@ class CoreExport Module * compiled against * @return The version */ - virtual Version GetVersion() { return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); } + Version GetVersion() { return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); } /** * Allow a module to add a set of language strings to anope @@ -334,20 +320,19 @@ class CoreExport Module /** * Add a module provided command to the given service. - * e.g. AddCommand(NICKSERV,c,MOD_HEAD); - * @param cmdTable the services to add the command to - * @param c the command to add + * @param bi The service to add the command to + * @param c The command to add * @return MOD_ERR_OK on successfully adding the command */ - int AddCommand(CommandHash *cmdTable[], Command * c); + int AddCommand(BotInfo *bi, Command *c); /** * Delete a command from the service given. - * @param cmdTable the cmdTable for the services to remove the command from - * @param name the name of the command to delete from the service + * @param bi The service to remove the command from + * @param c Thec command to delete * @return returns MOD_ERR_OK on success */ - int DelCommand(CommandHash * cmdTable[], const char *name); + int DelCommand(BotInfo *bi, Command *c); /** Called on NickServ HELP * @param u The user requesting help @@ -434,13 +419,13 @@ class CoreExport Module virtual void OnUserNickChange(User *u, const std::string &oldnick) { } /** Called immediatly when a user tries to run a command - * @param service The service + * @param bi The bot the command is being run from * @param u The user * @param cmd The command * @param c The command class (if it exists) * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommandRun(const std::string &service, User *u, const char *cmd, Command *c) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommandRun(BotInfo *bi, User *u, const ci::string &cmd, Command *c) { return EVENT_CONTINUE; } /** Called before a command is due to be executed. * @param u The user executing the command @@ -449,7 +434,7 @@ class CoreExport Module * @param params The parameters the user is sending * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) { return EVENT_CONTINUE; } + virtual EventReturn OnPreCommand(User *u, BotInfo *service, const ci::string &command, const std::vector<ci::string> ¶ms) { return EVENT_CONTINUE; } /** Called after a command has been executed. * @param u The user executing the command @@ -457,7 +442,7 @@ class CoreExport Module * @param command The command the user executed * @param params The parameters the user sent */ - virtual void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) { } + virtual void OnPostCommand(User *u, BotInfo *service, const ci::string &command, const std::vector<ci::string> ¶ms) { } /** Called after the core has finished loading the databases, but before * we connect to the server @@ -714,9 +699,9 @@ class CoreExport Module virtual EventReturn OnPreNickExpire(NickAlias *na) { return EVENT_CONTINUE; } /** Called when a nick drops - * @param nick The nick + * @param na The nick */ - virtual void OnNickExpire(const char *nick) { } + virtual void OnNickExpire(NickAlias *na) { } /** Called when defcon level changes * @param level The level @@ -1238,7 +1223,13 @@ class CoreExport ModuleManager */ static void ClearCallBacks(Module *m); -private: + /** Unloading all modules, NEVER call this when Anope isn't shutting down. + * Ever. + * @param unload_proto true to unload the protocol module + */ + static void UnloadAll(bool unload_proto); + + private: /** Call the module_delete function to safely delete the module * @param m the module to delete */ @@ -1267,51 +1258,10 @@ class CallBack : public Timer } }; -struct ModuleHash_ { - char *name; - Module *m; - ModuleHash *next; -}; - -struct Message_ { - char *name; +struct Message +{ + std::string name; int (*func)(const char *source, int ac, const char **av); - int core; - Message *next; }; -struct MessageHash_ { - char *name; - Message *m; - MessageHash *next; -}; - -/*************************************************************************/ -/* Module Managment Functions */ -MDE Module *findModule(const char *name); /* Find a module */ - -int protocol_module_init(); /* Load the IRCD Protocol Module up*/ - -/*************************************************************************/ -/*************************************************************************/ -/* Command Managment Functions */ -MDE Command *findCommand(CommandHash *cmdTable[], const char *name); /* Find a command */ - -/*************************************************************************/ - -/* Message Managment Functions */ -MDE Message *createMessage(const char *name,int (*func)(const char *source, int ac, const char **av)); -Message *findMessage(MessageHash *msgTable[], const char *name); /* Find a Message */ -MDE int addMessage(MessageHash *msgTable[], Message *m, int pos); /* Add a Message to a Message table */ -MDE int addCoreMessage(MessageHash *msgTable[], Message *m); /* Add a Message to a Message table */ -int delMessage(MessageHash *msgTable[], Message *m); /* Del a Message from a msg table */ -int destroyMessage(Message *m); /* destroy a Message*/ - -/*************************************************************************/ - -MDE bool moduleMinVersion(int major,int minor,int patch,int build); /* Checks if the current version of anope is before or after a given verison */ - -/************************************************************************/ - #endif -/* EOF */ diff --git a/include/regchannel.h b/include/regchannel.h index bd5a50ced..4a571182b 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -8,6 +8,9 @@ * */ +typedef unordered_map_namespace::unordered_map<ci::string, ChannelInfo *, hash_compare_ci_string> registered_channel_map; +extern CoreExport registered_channel_map RegisteredChannelList; + /** Flags used for the ChannelInfo class */ enum ChannelInfoFlag @@ -78,7 +81,6 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag> */ ~ChannelInfo(); - ChannelInfo *next, *prev; std::string name; /* Channel name */ NickCore *founder; NickCore *successor; /* Who gets the channel if the founder diff --git a/include/services.h b/include/services.h index 4a8eb8d77..c05b44eac 100644 --- a/include/services.h +++ b/include/services.h @@ -198,6 +198,7 @@ extern int strncasecmp(const char *, const char *, size_t); #endif /* Miscellaneous definitions. */ +#include "hashcomp.h" #include "defs.h" #include "slist.h" @@ -352,12 +353,12 @@ class ChannelInfo; class Channel; class Server; struct EList; +struct Session; typedef struct bandata_ BanData; typedef struct mailinfo_ MailInfo; typedef struct akill_ Akill; typedef struct exception_ Exception; -typedef struct session_ Session; #include "extensible.h" #include "threadengine.h" @@ -827,8 +828,11 @@ struct exception_ { /*************************************************************************/ -struct session_ { - Session *prev, *next; +typedef unordered_map_namespace::unordered_map<std::string, Session *, hash_compare_std_string> session_map; +extern CoreExport session_map SessionList; + +struct Session +{ char *host; int count; /* Number of clients with this host */ int hits; /* Number of subsequent kills for a host */ @@ -1054,6 +1058,7 @@ class CoreExport Alog } }; +class Message; // XXX class CoreExport Anope { @@ -1065,6 +1070,20 @@ class CoreExport Anope */ static bool Match(const std::string &str, const std::string &mask, bool case_sensitive = false); inline static bool Match(const ci::string &str, const ci::string &mask) { return Match(str.c_str(), mask.c_str(), false); } + + /** Add a message to Anope + * @param name The message name as sent by the IRCd + * @param func A callback function that will be called when this message is received + * @return The new message object + */ + static Message *AddMessage(const std::string &name, int (*func)(const char *source, int ac, const char **av)); + + /** Deletes a message from Anope + * XXX Im not sure what will happen if this function is called indirectly from message function pointed to by this message.. must check + * @param m The message + * @return true if the message was found and deleted, else false + */ + static bool DelMessage(Message *m); }; /*************************************************************************/ diff --git a/include/users.h b/include/users.h index b11c17875..3937e2ebe 100644 --- a/include/users.h +++ b/include/users.h @@ -8,6 +8,15 @@ * */ +/* Hash maps used for users. Note UserListByUID will not be used on non-TS6 IRCds, and should never + * be assumed to have users + */ +typedef unordered_map_namespace::unordered_map<ci::string, User *, hash_compare_ci_string> user_map; +typedef unordered_map_namespace::unordered_map<std::string, User *, hash_compare_std_string> user_uid_map; + +extern CoreExport user_map UserListByNick; +extern CoreExport user_uid_map UserListByUID; + struct ChannelContainer { Channel *chan; @@ -32,8 +41,6 @@ class CoreExport User : public Extensible NickCore *nc; /* NickCore account the user is currently loggged in as */ public: // XXX: exposing a tiny bit too much - User *next, *prev; - std::string nick; /* User's current nick */ char *host; /* User's real hostname */ |
