From 662dfa6c181a8c1d97a0c65499679e0eb1b399e2 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 24 Jan 2015 14:49:10 +0100 Subject: Add User::ForEachNeighbor() --- include/users.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'include') diff --git a/include/users.h b/include/users.h index ceee4396b..6f319018f 100644 --- a/include/users.h +++ b/include/users.h @@ -248,6 +248,19 @@ class CoreExport User : public Extensible std::bitset 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 ChanList; @@ -542,6 +555,16 @@ class CoreExport User : public Extensible */ void WriteCommonQuit(const std::string &normal_text, const std::string &oper_text); + /** 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 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 * @param textStream the text to send to the user -- cgit v1.2.3