summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc_client.cpp32
-rw-r--r--src/irc/irc_client.hpp11
2 files changed, 35 insertions, 8 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index d179aaa..f9ebfa0 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -20,7 +20,7 @@ using namespace std::string_literals;
using namespace std::chrono_literals;
IrcClient::IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& username, Bridge* bridge):
- SocketHandler(poller),
+ TCPSocketHandler(poller),
hostname(hostname),
username(username),
current_nick(username),
@@ -77,8 +77,9 @@ void IrcClient::on_connection_failed(const std::string& reason)
for (const std::string& channel: this->channels_to_join)
{
Iid iid(channel + "%" + this->hostname);
- this->bridge->send_join_failed(iid, this->current_nick,
- "cancel", "item-not-found", reason);
+ this->bridge->send_presence_error(iid, this->current_nick,
+ "cancel", "item-not-found",
+ "", reason);
}
}
else // try the next port
@@ -93,9 +94,11 @@ void IrcClient::on_connected()
this->send_pending_data();
}
-void IrcClient::on_connection_close()
+void IrcClient::on_connection_close(const std::string& error_msg)
{
- static const std::string message = "Connection closed by remote server.";
+ std::string message = "Connection closed by remote server.";
+ if (!error_msg.empty())
+ message += ": " + error_msg;
const IrcMessage error{"ERROR", {message}};
this->on_error(error);
log_warning(message);
@@ -475,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 ?
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index 7dff1db..9bef04a 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -5,7 +5,7 @@
#include <irc/irc_channel.hpp>
#include <irc/iid.hpp>
-#include <network/socket_handler.hpp>
+#include <network/tcp_socket_handler.hpp>
#include <unordered_map>
#include <memory>
@@ -21,7 +21,7 @@ class Bridge;
* Represent one IRC client, i.e. an endpoint connected to a single IRC
* server, through a TCP socket, receiving and sending commands to it.
*/
-class IrcClient: public SocketHandler
+class IrcClient: public TCPSocketHandler
{
public:
explicit IrcClient(std::shared_ptr<Poller> poller, const std::string& hostname, const std::string& username, Bridge* bridge);
@@ -41,7 +41,7 @@ public:
/**
* Close the connection, remove us from the poller
*/
- void on_connection_close() override final;
+ void on_connection_close(const std::string& error) override final;
/**
* Parse the data we have received so far and try to get one or more
* complete messages from it.
@@ -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},