X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fmodules.h;h=b36326b1b6b5b5874dfef96552852caa07cb9c49;hb=635cb9d65f6d7f6758ae8ed874da00c8d94b6e39;hp=2b578e58cf65db63eedf08e29740eb7f0e1661f5;hpb=4f9abe96a4301a740d4a5fd7932550d88d60a3fc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/modules.h b/include/modules.h index 2b578e58c..b36326b1b 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1,18 +1,20 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2020 Matt Schatz * Copyright (C) 2019 iwalkalone * Copyright (C) 2013 Adam * Copyright (C) 2012-2016, 2018 Attila Molnar - * Copyright (C) 2012-2013, 2016-2020 Sadie Powell + * Copyright (C) 2012-2013, 2017-2020 Sadie Powell * Copyright (C) 2012 Robby * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2008 Thomas Stagner * Copyright (C) 2007-2009 Robin Burchell - * Copyright (C) 2007-2008, 2010 Craig Edwards * Copyright (C) 2007 Oliver Lupton - * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006-2007 Dennis Friis + * Copyright (C) 2006 John Brooks + * Copyright (C) 2003-2008, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -35,7 +37,6 @@ #include "base.h" #include "ctables.h" #include "inspsocket.h" -#include "timer.h" #include "mode.h" /** Used to specify the behaviour of a module. */ @@ -57,44 +58,72 @@ enum ModuleFlags VF_OPTCOMMON = 8 }; +/** The event was explicitly allowed. */ #define MOD_RES_ALLOW (ModResult(1)) + +/** The event was not explicitly allowed or denied. */ #define MOD_RES_PASSTHRU (ModResult(0)) + +/** The event was explicitly denied. */ #define MOD_RES_DENY (ModResult(-1)) -/** Used to represent an allow/deny module result. - * Not constructed as an enum because it reverses the value logic of some functions; - * the compiler will inline accesses to have the same efficiency as integer operations. - */ -struct ModResult { - int res; - ModResult() : res(0) {} - explicit ModResult(int r) : res(r) {} - inline bool operator==(const ModResult& r) const +/** Represents the result of a module event. */ +class ModResult +{ + private: + /** The underlying result value. */ + char result; + + public: + /** Creates a new instance of the ModResult class which defaults to MOD_RES_PASSTHRU. */ + ModResult() + : result(0) + { + } + + /** Creates a new instance of the ModResult class with the specified value. */ + explicit ModResult(char res) + : result(res) + { + } + + /** Determines whether this ModResult has.the same value as \p res */ + inline bool operator==(const ModResult& res) const { - return res == r.res; + return result == res.result; } - inline bool operator!=(const ModResult& r) const + + /** Determines whether this ModResult has.a different value to \p res */ + inline bool operator!=(const ModResult& res) const { - return res != r.res; + return result != res.result; } + + /** Determines whether a non-MOD_RES_PASSTHRU result has been set. */ inline bool operator!() const { - return !res; + return !result; } + + /** Checks whether the result is an MOD_RES_ALLOW or MOD_RES_PASSTHRU when the default is to allow. */ inline bool check(bool def) const { - return (res == 1 || (res == 0 && def)); + return (result == 1 || (result == 0 && def)); } - /** - * Merges two results, preferring ALLOW to DENY - */ - inline ModResult operator+(const ModResult& r) const + + /* Merges two results preferring MOD_RES_ALLOW to MOD_RES_DENY. */ + inline ModResult operator+(const ModResult& res) const { - if (res == r.res || r.res == 0) + // If the results are identical or the other result is MOD_RES_PASSTHRU + // then return this result. + if (result == res.result || res.result == 0) return *this; - if (res == 0) - return r; - // they are different, and neither is passthru + + // If this result is MOD_RES_PASSTHRU then return the other result. + if (result == 0) + return res; + + // Otherwise, they are different, and neither is MOD_RES_PASSTHRU. return MOD_RES_ALLOW; } }; @@ -204,23 +233,78 @@ enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER } */ enum Implementation { - I_OnUserConnect, I_OnUserPreQuit, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, - I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, - I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick, - I_OnUserPostMessage, I_OnUserMessageBlocked, I_OnMode, I_OnShutdown, - I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit, I_OnUserPostInit, - I_OnChangeHost, I_OnChangeRealName, I_OnAddLine, I_OnDelLine, I_OnExpireLine, - I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnLoadModule, - I_OnUnloadModule, I_OnBackgroundTimer, I_OnPreCommand, I_OnCheckReady, I_OnCheckInvite, - I_OnRawMode, I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnCheckChannelBan, I_OnExtBanCheck, - I_OnPreChangeHost, I_OnPreTopicChange, I_OnConnectionFail, - I_OnPostTopicChange, I_OnPostConnect, I_OnPostDeoper, - I_OnPreChangeRealName, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, - I_OnPostOper, I_OnPostCommand, I_OnCommandBlocked, I_OnPostJoin, - I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, - I_OnUserMessage, I_OnPassCompare, I_OnNumeric, - I_OnPreRehash, I_OnModuleRehash, I_OnChangeIdent, I_OnSetUserIP, - I_OnServiceAdd, I_OnServiceDel, I_OnUserWrite, + I_On005Numeric, + I_OnAcceptConnection, + I_OnAddLine, + I_OnBackgroundTimer, + I_OnBuildNeighborList, + I_OnChangeHost, + I_OnChangeRealHost, + I_OnChangeIdent, + I_OnChangeRealName, + I_OnChannelDelete, + I_OnChannelPreDelete, + I_OnCheckBan, + I_OnCheckChannelBan, + I_OnCheckInvite, + I_OnCheckKey, + I_OnCheckLimit, + I_OnCheckReady, + I_OnCommandBlocked, + I_OnConnectionFail, + I_OnDecodeMetaData, + I_OnDelLine, + I_OnExpireLine, + I_OnExtBanCheck, + I_OnGarbageCollect, + I_OnKill, + I_OnLoadModule, + I_OnMode, + I_OnModuleRehash, + I_OnNumeric, + I_OnOper, + I_OnPassCompare, + I_OnPostCommand, + I_OnPostConnect, + I_OnPostDeoper, + I_OnPostJoin, + I_OnPostOper, + I_OnPostTopicChange, + I_OnPreChangeHost, + I_OnPreChangeRealName, + I_OnPreCommand, + I_OnPreMode, + I_OnPreRehash, + I_OnPreTopicChange, + I_OnRawMode, + I_OnSendSnotice, + I_OnServiceAdd, + I_OnServiceDel, + I_OnSetConnectClass, + I_OnSetUserIP, + I_OnShutdown, + I_OnUnloadModule, + I_OnUserConnect, + I_OnUserDisconnect, + I_OnUserInit, + I_OnUserInvite, + I_OnUserJoin, + I_OnUserKick, + I_OnUserMessage, + I_OnUserMessageBlocked, + I_OnUserPart, + I_OnUserPostInit, + I_OnUserPostMessage, + I_OnUserPostNick, + I_OnUserPreInvite, + I_OnUserPreJoin, + I_OnUserPreKick, + I_OnUserPreMessage, + I_OnUserPreNick, + I_OnUserPreQuit, + I_OnUserQuit, + I_OnUserRegister, + I_OnUserWrite, I_END }; @@ -569,6 +653,13 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnChangeHost(User* user, const std::string &newhost); + /** Called whenever a user's real hostname is changed. + * This event triggers after the host has been set. + * @param user The user whos host is being changed + * @param newhost The new hostname being set + */ + virtual void OnChangeRealHost(User* user, const std::string& newhost); + /** Called whenever a user's real name is changed. * This event triggers after the name has been set. * @param user The user who's real name is being changed @@ -959,6 +1050,7 @@ class CoreExport Module : public classbase, public usecountbase class CoreExport ModuleManager : public fakederef { public: + typedef std::multimap DataProviderMap; typedef std::vector ServiceList; private: @@ -1001,7 +1093,7 @@ class CoreExport ModuleManager : public fakederef Module::List EventHandlers[I_END]; /** List of data services keyed by name */ - std::multimap DataProviders; + DataProviderMap DataProviders; /** A list of ServiceProviders waiting to be registered. * Non-NULL when constructing a Module, NULL otherwise.