~singpolyma/biboumi

e2117bcb0abfde30ad503b99da58699cf0f2a95b — Florent Le Coz 9 years ago 6fa548a
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
1 files changed, 16 insertions(+), 2 deletions(-)

M src/irc/irc_client.cpp
M src/irc/irc_client.cpp => src/irc/irc_client.cpp +16 -2
@@ 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)