~singpolyma/biboumi

483e17020dc4f19223001ab36da0dc48a15a0d3e — Florent Le Coz 9 years ago 9df757f
Be verbose about the connection status, and some errors
2 files changed, 42 insertions(+), 1 deletions(-)

M src/irc/irc_client.cpp
M src/irc/irc_client.hpp
M src/irc/irc_client.cpp => src/irc/irc_client.cpp +24 -1
@@ 33,11 33,14 @@ void IrcClient::on_connected()
{
  this->send_nick_command(this->username);
  this->send_user_command(this->username, this->username);
  this->send_gateway_message("Connected to IRC server.");
}

void IrcClient::on_connection_close()
{
  log_warning("Connection closed by remote server.");
  static const std::string message = "Connection closed by remote server.";
  this->send_gateway_message(message);
  log_warning(message);
}

IrcChannel* IrcClient::get_channel(const std::string& name)


@@ 191,6 194,11 @@ void IrcClient::forward_server_message(const IrcMessage& message)
  this->bridge->send_xmpp_message(this->hostname, from, body);
}

void IrcClient::send_gateway_message(const std::string& message, const std::string& from)
{
  this->bridge->send_xmpp_message(this->hostname, from, message);
}

void IrcClient::set_and_forward_user_list(const IrcMessage& message)
{
  const std::string chan_name = utils::tolower(message.arguments[2]);


@@ 286,6 294,20 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message)
  this->bridge->send_topic(this->hostname, chan_name, channel->topic);
}

void IrcClient::on_erroneous_nickname(const IrcMessage& message)
{
  const std::string error_msg = message.arguments.size() >= 3 ?
    message.arguments[2]: "Erroneous nickname";
  this->send_gateway_message(error_msg + ": " + message.arguments[1], message.prefix);
}

void IrcClient::on_generic_error(const IrcMessage& message)
{
  const std::string error_msg = message.arguments.size() >= 3 ?
    message.arguments[2]: "Unspecified error";
  this->send_gateway_message(message.arguments[1] + ": " + error_msg, message.prefix);
}

void IrcClient::on_welcome_message(const IrcMessage& message)
{
  this->current_nick = message.arguments[0];


@@ 334,6 356,7 @@ void IrcClient::on_error(const IrcMessage& message)
    std::string own_nick = channel->get_self()->nick;
    this->bridge->send_muc_leave(std::move(iid), std::move(own_nick), leave_message, true);
  }
  this->send_gateway_message(std::string("ERROR: ") + leave_message);
}

void IrcClient::on_quit(const IrcMessage& message)

M src/irc/irc_client.hpp => src/irc/irc_client.hpp +18 -0
@@ 100,6 100,12 @@ public:
   */
  void send_quit_command();
  /**
   * Send a message to the gateway user, not generated by the IRC server,
   * but that might be useful because we want to be verbose (for example we
   * might want to notify the user about the connexion state)
   */
  void send_gateway_message(const std::string& message, const std::string& from="");
  /**
   * Forward the server message received from IRC to the XMPP component
   */
  void forward_server_message(const IrcMessage& message);


@@ 139,6 145,14 @@ public:
   */
  void on_channel_completely_joined(const IrcMessage& message);
  /**
   * We tried to set an invalid nickname
   */
  void on_erroneous_nickname(const IrcMessage& message);
  /**
   * Handles most errors from the server by just forwarding the message to the user.
   */
  void on_generic_error(const IrcMessage& message);
  /**
   * When a message 001 is received, join the rooms we wanted to join, and set our actual nickname
   */
  void on_welcome_message(const IrcMessage& message);


@@ 208,6 222,8 @@ typedef void (IrcClient::*irc_callback_t)(const IrcMessage&);

static const std::unordered_map<std::string, irc_callback_t> irc_callbacks = {
  {"NOTICE", &IrcClient::forward_server_message},
  {"002", &IrcClient::forward_server_message},
  {"003", &IrcClient::forward_server_message},
  {"RPL_MOTDSTART", &IrcClient::empty_motd},
  {"375", &IrcClient::empty_motd},
  {"RPL_MOTD", &IrcClient::on_motd_line},


@@ 220,6 236,8 @@ static const std::unordered_map<std::string, irc_callback_t> irc_callbacks = {
  {"332", &IrcClient::on_topic_received},
  {"TOPIC", &IrcClient::on_topic_received},
  {"366", &IrcClient::on_channel_completely_joined},
  {"432", &IrcClient::on_erroneous_nickname},
  {"461", &IrcClient::on_generic_error},
  {"001", &IrcClient::on_welcome_message},
  {"PART", &IrcClient::on_part},
  {"ERROR", &IrcClient::on_error},