summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/builtinmodes.h1
-rw-r--r--include/ctables.h32
-rw-r--r--include/extensible.h26
-rw-r--r--include/modules/cap.h4
-rw-r--r--include/parammode.h2
-rw-r--r--include/users.h26
6 files changed, 50 insertions, 41 deletions
diff --git a/include/builtinmodes.h b/include/builtinmodes.h
index 96838ce5e..62ccaf62d 100644
--- a/include/builtinmodes.h
+++ b/include/builtinmodes.h
@@ -39,6 +39,7 @@ class ModeChannelBan : public ListModeBase
*/
class ModeChannelKey : public ParamMode<ModeChannelKey, LocalStringExt>
{
+ static const std::string::size_type maxkeylen = 32;
public:
ModeChannelKey();
ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
diff --git a/include/ctables.h b/include/ctables.h
index a69f5c86f..abf65f561 100644
--- a/include/ctables.h
+++ b/include/ctables.h
@@ -163,36 +163,16 @@ class CoreExport CommandBase : public ServiceProvider
* @param maxpara Maximum number of parameters this command may have - extra parameters
* will be tossed into one last space-seperated param.
*/
- CommandBase(Module* me, const std::string &cmd, int minpara = 0, int maxpara = 0) :
- ServiceProvider(me, cmd, SERVICE_COMMAND), flags_needed(0), min_params(minpara), max_params(maxpara),
- use_count(0), disabled(false), works_before_reg(false), allow_empty_last_param(true),
- Penalty(1)
- {
- }
+ CommandBase(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
- virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
- {
- return ROUTE_LOCALONLY;
- }
+ virtual RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
/** Encode a parameter for server->server transmission.
* Used for parameters for which the translation type is TR_CUSTOM.
* @param parameter The parameter to encode. Can be modified in place.
* @param index The parameter index (0 == first parameter).
*/
- virtual void EncodeParameter(std::string& parameter, int index)
- {
- }
-
- /** Decode a parameter from server->server transmission.
- * Not currently used in this version of InspIRCd.
- * Used for parameters for which the translation type is TR_CUSTOM.
- * @param parameter The parameter to decode. Can be modified in place.
- * @param index The parameter index (0 == first parameter).
- */
- virtual void DecodeParameter(std::string& parameter, int index)
- {
- }
+ virtual void EncodeParameter(std::string& parameter, int index);
/** Disable or enable this command.
* @param setting True to disable the command.
@@ -229,11 +209,7 @@ class CoreExport Command : public CommandBase
*/
bool force_manual_route;
- Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0)
- : CommandBase(me, cmd, minpara, maxpara)
- , force_manual_route(false)
- {
- }
+ Command(Module* me, const std::string& cmd, unsigned int minpara = 0, unsigned int maxpara = 0);
/** Handle the command from a user.
* @param parameters The parameters for the command.
diff --git a/include/extensible.h b/include/extensible.h
index 86e0d6b07..a2c104377 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -38,7 +38,20 @@ enum SerializeFormat
class CoreExport ExtensionItem : public ServiceProvider, public usecountbase
{
public:
- ExtensionItem(const std::string& key, Module* owner);
+ /** Extensible subclasses
+ */
+ enum ExtensibleType
+ {
+ EXT_USER,
+ EXT_CHANNEL,
+ EXT_MEMBERSHIP
+ };
+
+ /** Type (subclass) of Extensible that this ExtensionItem is valid for
+ */
+ const ExtensibleType type;
+
+ ExtensionItem(const std::string& key, ExtensibleType exttype, Module* owner);
virtual ~ExtensionItem();
/** Serialize this item into a string
*
@@ -119,7 +132,7 @@ class CoreExport ExtensionManager
class CoreExport LocalExtItem : public ExtensionItem
{
public:
- LocalExtItem(const std::string& key, Module* owner);
+ LocalExtItem(const std::string& key, ExtensibleType exttype, Module* owner);
virtual ~LocalExtItem();
virtual std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
virtual void unserialize(SerializeFormat format, Extensible* container, const std::string& value);
@@ -130,7 +143,8 @@ template <typename T, typename Del = stdalgo::defaultdeleter<T> >
class SimpleExtItem : public LocalExtItem
{
public:
- SimpleExtItem(const std::string& Key, Module* parent) : LocalExtItem(Key, parent)
+ SimpleExtItem(const std::string& Key, ExtensibleType exttype, Module* parent)
+ : LocalExtItem(Key, exttype, parent)
{
}
@@ -175,7 +189,7 @@ class SimpleExtItem : public LocalExtItem
class CoreExport LocalStringExt : public SimpleExtItem<std::string>
{
public:
- LocalStringExt(const std::string& key, Module* owner);
+ LocalStringExt(const std::string& key, ExtensibleType exttype, Module* owner);
virtual ~LocalStringExt();
std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
};
@@ -183,7 +197,7 @@ class CoreExport LocalStringExt : public SimpleExtItem<std::string>
class CoreExport LocalIntExt : public LocalExtItem
{
public:
- LocalIntExt(const std::string& key, Module* owner);
+ LocalIntExt(const std::string& key, ExtensibleType exttype, Module* owner);
virtual ~LocalIntExt();
std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
intptr_t get(const Extensible* container) const;
@@ -195,7 +209,7 @@ class CoreExport LocalIntExt : public LocalExtItem
class CoreExport StringExtItem : public ExtensionItem
{
public:
- StringExtItem(const std::string& key, Module* owner);
+ StringExtItem(const std::string& key, ExtensibleType exttype, Module* owner);
virtual ~StringExtItem();
std::string* get(const Extensible* container) const;
std::string serialize(SerializeFormat format, const Extensible* container, void* item) const;
diff --git a/include/modules/cap.h b/include/modules/cap.h
index 1b33e05bb..cc1cb8d8c 100644
--- a/include/modules/cap.h
+++ b/include/modules/cap.h
@@ -43,7 +43,9 @@ class GenericCap
public:
LocalIntExt ext;
const std::string cap;
- GenericCap(Module* parent, const std::string &Cap) : ext("cap_" + Cap, parent), cap(Cap)
+ GenericCap(Module* parent, const std::string& Cap)
+ : ext("cap_" + Cap, ExtensionItem::EXT_USER, parent)
+ , cap(Cap)
{
}
diff --git a/include/parammode.h b/include/parammode.h
index b0005262e..b00082bd6 100644
--- a/include/parammode.h
+++ b/include/parammode.h
@@ -56,7 +56,7 @@ class ParamMode : public ParamModeBase
*/
ParamMode(Module* Creator, const std::string& Name, char modeletter, ParamSpec ps = PARAM_SETONLY)
: ParamModeBase(Creator, Name, modeletter, ps)
- , ext("parammode_" + Name, Creator)
+ , ext("parammode_" + Name, ExtensionItem::EXT_CHANNEL, Creator)
{
}
diff --git a/include/users.h b/include/users.h
index ceee4396b..fa8f610bc 100644
--- a/include/users.h
+++ b/include/users.h
@@ -248,6 +248,19 @@ class CoreExport User : public Extensible
std::bitset<ModeParser::MODEID_MAX> modes;
public:
+ /** To execute a function for each local neighbor of a user, inherit from this class and
+ * pass an instance of it to User::ForEachNeighbor().
+ */
+ class ForEachNeighborHandler
+ {
+ public:
+ /** Method to execute for each local neighbor of a user.
+ * Derived classes must implement this.
+ * @param user Current neighbor
+ */
+ virtual void Execute(LocalUser* user) = 0;
+ };
+
/** List of Memberships for this user
*/
typedef insp::intrusive_list<Membership> ChanList;
@@ -535,12 +548,15 @@ class CoreExport User : public Extensible
*/
void WriteCommon(const char* text, ...) CUSTOM_PRINTF(2, 3);
- /** Write a quit message to all common users, as in User::WriteCommonExcept but with a specific
- * quit message for opers only.
- * @param normal_text Normal user quit message
- * @param oper_text Oper only quit message
+ /** Execute a function once for each local neighbor of this user. By default, the neighbors of a user are the users
+ * who have at least one common channel with the user. Modules are allowed to alter the set of neighbors freely.
+ * This function is used for example to send something conditionally to neighbors, or to send different messages
+ * to different users depending on their oper status.
+ * @param handler Function object to call, inherited from ForEachNeighborHandler.
+ * @param include_self True to include this user in the set of neighbors, false otherwise.
+ * Modules may override this. Has no effect if this user is not local.
*/
- void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text);
+ void ForEachNeighbor(ForEachNeighborHandler& handler, bool include_self = true);
/** Dump text to a user target, splitting it appropriately to fit
* @param linePrefix text to prefix each complete line with