summaryrefslogtreecommitdiff
path: root/src/irc/irc_client.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc/irc_client.hpp')
-rw-r--r--src/irc/irc_client.hpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index fd97fe6..cfb3d21 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -16,8 +16,14 @@
#include <vector>
#include <string>
#include <stack>
+#include <deque>
#include <map>
#include <set>
+#include <utils/tokens_bucket.hpp>
+
+class IrcClient;
+
+using MessageCallback = std::function<void(const IrcClient*, const IrcMessage&)>;
class Bridge;
@@ -28,7 +34,7 @@ class Bridge;
class IrcClient: public TCPClientSocketHandler
{
public:
- explicit IrcClient(std::shared_ptr<Poller>& poller, std::string hostname,
+ explicit IrcClient(std::shared_ptr<Poller>& poller, std::string hostname,
std::string nickname, std::string username,
std::string realname, std::string user_hostname,
Bridge& bridge);
@@ -68,6 +74,10 @@ public:
*/
IrcChannel* get_channel(const std::string& name);
/**
+ * Return the channel with this name. Nullptr if it is not found
+ */
+ const IrcChannel* find_channel(const std::string& name) const;
+ /**
* Returns true if the channel is joined
*/
bool is_channel_joined(const std::string& name);
@@ -80,8 +90,9 @@ public:
* (actually, into our out_buf and signal the poller that we want to wach
* for send events to be ready)
*/
- void send_message(IrcMessage&& message);
+ void send_message(IrcMessage message, MessageCallback callback={}, bool throttle=true);
void send_raw(const std::string& txt);
+ void actual_send(std::pair<IrcMessage, MessageCallback>&& message_pair);
/**
* Send the PONG irc command
*/
@@ -110,7 +121,8 @@ public:
* Send a PRIVMSG command for a channel
* Return true if the message was actually sent
*/
- bool send_channel_message(const std::string& chan_name, const std::string& body);
+ bool send_channel_message(const std::string& chan_name, const std::string& body,
+ MessageCallback callback);
/**
* Send a PRIVMSG command for an user
*/
@@ -289,7 +301,7 @@ public:
const std::vector<char>& get_sorted_user_modes() const { return this->sorted_user_modes; }
std::set<char> get_chantypes() const { return this->chantypes; }
-
+ void set_throttle_limit(long int limit);
/**
* Store the history limit that the client asked when joining this room.
*/
@@ -327,6 +339,10 @@ private:
*/
Bridge& bridge;
/**
+ * Where messaged are stored when they are throttled.
+ */
+ std::deque<std::pair<IrcMessage, MessageCallback>> message_queue{};
+ /**
* The list of joined channels, indexed by name
*/
std::unordered_map<std::string, std::unique_ptr<IrcChannel>> channels;
@@ -385,6 +401,8 @@ private:
* the WebIRC protocole.
*/
Resolver dns_resolver;
+ TokensBucket tokens_bucket;
+ long int get_throttle_limit() const;
};