~singpolyma/biboumi

41e8a3ba9b57e67aec5d0d30112338664afbd6e4 — Florent Le Coz 8 years ago e3ea0d6
Send a proper error on IRC message 438 (nickname change too fast)

fix #2576
2 files changed, 24 insertions(+), 0 deletions(-)

M src/irc/irc_client.cpp
M src/irc/irc_client.hpp
M src/irc/irc_client.cpp => src/irc/irc_client.cpp +19 -0
@@ 478,6 478,25 @@ void IrcClient::on_nickname_conflict(const IrcMessage& message)
  }
}

void IrcClient::on_nickname_change_too_fast(const IrcMessage& message)
{
  const std::string nickname = message.arguments[1];
  std::string txt;
  if (message.arguments.size() >= 3)
    txt = message.arguments[2];
  this->on_generic_error(message);
  for (auto it = this->channels.begin(); it != this->channels.end(); ++it)
  {
    Iid iid;
    iid.set_local(it->first);
    iid.set_server(this->hostname);
    iid.is_channel = true;
    this->bridge->send_presence_error(iid, nickname,
                                      "cancel", "not-acceptable",
                                      "", txt);
  }
}

void IrcClient::on_generic_error(const IrcMessage& message)
{
  const std::string error_msg = message.arguments.size() >= 3 ?

M src/irc/irc_client.hpp => src/irc/irc_client.hpp +5 -0
@@ 172,6 172,10 @@ public:
   */
  void on_nickname_conflict(const IrcMessage& message);
  /**
   * Idem, but for when the user changes their nickname too quickly
   */
  void on_nickname_change_too_fast(const IrcMessage& message);
  /**
   * Handles most errors from the server by just forwarding the message to the user.
   */
  void on_generic_error(const IrcMessage& message);


@@ 317,6 321,7 @@ static const std::unordered_map<std::string, irc_callback_t> irc_callbacks = {
  {"366", &IrcClient::on_channel_completely_joined},
  {"432", &IrcClient::on_erroneous_nickname},
  {"433", &IrcClient::on_nickname_conflict},
  {"438", &IrcClient::on_nickname_change_too_fast},
  {"001", &IrcClient::on_welcome_message},
  {"PART", &IrcClient::on_part},
  {"ERROR", &IrcClient::on_error},