diff options
author | Florent Le Coz <louiz@louiz.org> | 2013-12-08 04:44:46 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2013-12-08 04:47:05 +0100 |
commit | e2117bcb0abfde30ad503b99da58699cf0f2a95b (patch) | |
tree | 5b52360c243fca76cfa7b1a261511416149857b6 | |
parent | 6fa548a194082648724078cc777da34c30dd40a1 (diff) | |
download | biboumi-e2117bcb0abfde30ad503b99da58699cf0f2a95b.tar.gz biboumi-e2117bcb0abfde30ad503b99da58699cf0f2a95b.tar.bz2 biboumi-e2117bcb0abfde30ad503b99da58699cf0f2a95b.tar.xz biboumi-e2117bcb0abfde30ad503b99da58699cf0f2a95b.zip |
Enforce a simple limit of 400 bytes for IRC messages body
The limit for the whole message is 512 bytes, we limit the body to 400
(instead of doing a calculation based on the command name and the other
parameters), because it's simple, easy and that’s enough.
fixes #2416
-rw-r--r-- | src/irc/irc_client.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index af3df62..0d4d102 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -134,13 +134,27 @@ bool IrcClient::send_channel_message(const std::string& chan_name, const std::st log_warning("Cannot send message to channel " << chan_name << ", it is not joined"); return false; } - this->send_message(IrcMessage("PRIVMSG", {chan_name, body})); + // Cut the message body into 400-bytes parts (because the whole command + // must fit into 512 bytes, that's an easy way to make sure the chan name + // + body fits. I’m lazy.) + std::string::size_type pos = 0; + while (pos < body.size()) + { + this->send_message(IrcMessage("PRIVMSG", {chan_name, body.substr(pos, 400)})); + pos += 400; + } return true; } void IrcClient::send_private_message(const std::string& username, const std::string& body) { - this->send_message(IrcMessage("PRIVMSG", {username, body})); + std::string::size_type pos = 0; + while (pos < body.size()) + { + this->send_message(IrcMessage("PRIVMSG", {username, body.substr(pos, 400)})); + pos += 400; + } + } void IrcClient::send_part_command(const std::string& chan_name, const std::string& status_message) |