diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-04-15 04:56:50 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-04-15 04:56:50 +0200 |
commit | 5739d418e2b35dfc038fe1a12f8b5c7eeeed6868 (patch) | |
tree | e428fe413cf62850cb4dcda00bf1d753843177b6 /src | |
parent | 0d9c1ba31336f137202471841fd4fc7ca78a5c11 (diff) | |
download | biboumi-5739d418e2b35dfc038fe1a12f8b5c7eeeed6868.tar.gz biboumi-5739d418e2b35dfc038fe1a12f8b5c7eeeed6868.tar.bz2 biboumi-5739d418e2b35dfc038fe1a12f8b5c7eeeed6868.tar.xz biboumi-5739d418e2b35dfc038fe1a12f8b5c7eeeed6868.zip |
Better way to leave the dummy room
Diffstat (limited to 'src')
-rw-r--r-- | src/bridge/bridge.cpp | 4 | ||||
-rw-r--r-- | src/irc/irc_channel.cpp | 6 | ||||
-rw-r--r-- | src/irc/irc_channel.hpp | 1 | ||||
-rw-r--r-- | src/irc/irc_client.cpp | 12 | ||||
-rw-r--r-- | src/irc/irc_client.hpp | 5 |
5 files changed, 26 insertions, 2 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index da10e28..e874ccb 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -44,7 +44,9 @@ void Bridge::shutdown() { for (auto it = this->irc_clients.begin(); it != this->irc_clients.end(); ++it) { - it->second->send_quit_command("Gateway shutdown"); + const std::string exit_message("Gateway shutdown"); + it->second->send_quit_command(exit_message); + it->second->leave_dummy_channel(exit_message); } } diff --git a/src/irc/irc_channel.cpp b/src/irc/irc_channel.cpp index 0604528..7b0e766 100644 --- a/src/irc/irc_channel.cpp +++ b/src/irc/irc_channel.cpp @@ -48,6 +48,12 @@ void IrcChannel::remove_user(const IrcUser* user) } } +void IrcChannel::remove_all_users() +{ + this->users.clear(); + this->self.reset(); +} + DummyIrcChannel::DummyIrcChannel(): IrcChannel(), joining(false) diff --git a/src/irc/irc_channel.hpp b/src/irc/irc_channel.hpp index ab04d60..1c074b5 100644 --- a/src/irc/irc_channel.hpp +++ b/src/irc/irc_channel.hpp @@ -24,6 +24,7 @@ public: const std::map<char, char> prefix_to_mode); IrcUser* find_user(const std::string& name) const; void remove_user(const IrcUser* user); + void remove_all_users(); protected: std::unique_ptr<IrcUser> self; diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 78acce5..f44821e 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -199,7 +199,7 @@ void IrcClient::send_part_command(const std::string& chan_name, const std::strin if (channel->joined == true) { if (chan_name.empty()) - this->bridge->send_muc_leave(Iid(std::string("%") + this->hostname), std::string(this->current_nick), "", true); + this->leave_dummy_channel(status_message); else this->send_message(IrcMessage("PART", {chan_name, status_message})); } @@ -652,3 +652,13 @@ DummyIrcChannel& IrcClient::get_dummy_channel() { return this->dummy_channel; } + +void IrcClient::leave_dummy_channel(const std::string& exit_message) +{ + if (!this->dummy_channel.joined) + return; + this->dummy_channel.joined = false; + this->dummy_channel.joining = false; + this->dummy_channel.remove_all_users(); + this->bridge->send_muc_leave(Iid(std::string("%") + this->hostname), std::string(this->current_nick), exit_message, true); +} diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index 960d36f..811d416 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -198,6 +198,11 @@ public: * Get a reference to the unique dummy channel */ DummyIrcChannel& get_dummy_channel(); + /** + * Leave the dummy channel: forward a message to the user to indicate that + * he left it, and mark it as not joined. + */ + void leave_dummy_channel(const std::string& exit_message); const std::string& get_hostname() const { return this->hostname; } std::string get_nick() const { return this->current_nick; } |