summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc_channel.cpp6
-rw-r--r--src/irc/irc_channel.hpp33
-rw-r--r--src/irc/irc_client.cpp23
-rw-r--r--src/irc/irc_client.hpp17
4 files changed, 77 insertions, 2 deletions
diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp
index 99783fa..0604528 100644
--- a/src/irc/irc_channel.cpp
+++ b/src/irc/irc_channel.cpp
@@ -47,3 +47,9 @@ void IrcChannel::remove_user(const IrcUser* user)
}
}
}
+
+DummyIrcChannel::DummyIrcChannel():
+ IrcChannel(),
+ joining(false)
+{
+}
diff --git a/src/irc/irc_channel.hpp b/src/irc/irc_channel.hpp
index 0160469..ab04d60 100644
--- a/src/irc/irc_channel.hpp
+++ b/src/irc/irc_channel.hpp
@@ -25,13 +25,44 @@ public:
IrcUser* find_user(const std::string& name) const;
void remove_user(const IrcUser* user);
-private:
+protected:
std::unique_ptr<IrcUser> self;
std::vector<std::unique_ptr<IrcUser>> users;
+
+private:
IrcChannel(const IrcChannel&) = delete;
IrcChannel(IrcChannel&&) = delete;
IrcChannel& operator=(const IrcChannel&) = delete;
IrcChannel& operator=(IrcChannel&&) = delete;
};
+/**
+ * A special channel that is not actually linked to any real irc
+ * channel. This is just a channel representing a connection to the
+ * server. If an user wants to maintain the connection to the server without
+ * having to be on any irc channel of that server, he can just join this
+ * dummy channel.
+ * It’s not actually dummy because it’s useful and it does things, but well.
+ */
+class DummyIrcChannel: public IrcChannel
+{
+public:
+ explicit DummyIrcChannel();
+
+ /**
+ * This flag is at true whenever the user wants to join this channel, but
+ * he is not yet connected to the server. When the connection is made, we
+ * check that flag and if it’s true, we inform the user that he has just
+ * joined that channel.
+ * If the user is already connected to the server when he tries to join
+ * the channel, we don’t use that flag, we just join it immediately.
+ */
+ bool joining;
+private:
+ DummyIrcChannel(const DummyIrcChannel&) = delete;
+ DummyIrcChannel(DummyIrcChannel&&) = delete;
+ DummyIrcChannel& operator=(const DummyIrcChannel&) = delete;
+ DummyIrcChannel& operator=(DummyIrcChannel&&) = delete;
+};
+
#endif // IRC_CHANNEL_INCLUDED
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 884f214..e565658 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -280,7 +280,11 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message)
void IrcClient::on_channel_join(const IrcMessage& message)
{
const std::string chan_name = utils::tolower(message.arguments[0]);
- IrcChannel* channel = this->get_channel(chan_name);
+ IrcChannel* channel;
+ if (chan_name.empty())
+ channel = &this->dummy_channel;
+ else
+ channel = this->get_channel(chan_name);
const std::string nick = message.prefix;
if (channel->joined == false)
channel->set_self(nick);
@@ -394,6 +398,18 @@ void IrcClient::on_welcome_message(const IrcMessage& message)
for (const std::string& chan_name: this->channels_to_join)
this->send_join_command(chan_name);
this->channels_to_join.clear();
+ // Indicate that the dummy channel is joined as well, if needed
+ if (this->dummy_channel.joining)
+ {
+ // Simulate a message coming from the IRC server saying that we joined
+ // the channel
+ const IrcMessage join_message(this->get_nick(), "JOIN", {""});
+ this->on_channel_join(join_message);
+ const IrcMessage end_join_message(std::string(this->hostname), "366",
+ {this->get_nick(),
+ "", "End of NAMES list"});
+ this->on_channel_completely_joined(end_join_message);
+ }
}
void IrcClient::on_part(const IrcMessage& message)
@@ -624,3 +640,8 @@ size_t IrcClient::number_of_joined_channels() const
{
return this->channels.size();
}
+
+DummyIrcChannel& IrcClient::get_dummy_channel()
+{
+ return this->dummy_channel;
+}
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index 908db8e..960d36f 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -194,6 +194,14 @@ public:
* Return the number of joined channels
*/
size_t number_of_joined_channels() const;
+ /**
+ * Get a reference to the unique dummy channel
+ */
+ DummyIrcChannel& get_dummy_channel();
+
+ const std::string& get_hostname() const { return this->hostname; }
+ std::string get_nick() const { return this->current_nick; }
+ bool is_welcomed() const { return this->welcomed; }
private:
/**
@@ -217,12 +225,21 @@ private:
*/
std::unordered_map<std::string, std::unique_ptr<IrcChannel>> channels;
/**
+ * A single channel with a iid of the form "hostname" (normal channel have
+ * an iid of the form "chan%hostname".
+ */
+ DummyIrcChannel dummy_channel;
+ /**
* A list of chan we want to join, but we need a response 001 from
* the server before sending the actual JOIN commands. So we just keep the
* channel names in a list, and send the JOIN commands for each of them
* whenever the WELCOME message is received.
*/
std::vector<std::string> channels_to_join;
+ /**
+ * This flag indicates that the server is completely joined (connection
+ * has been established, we are authentified and we have a nick)
+ */
bool welcomed;
/**
* See http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt section 3.3