diff options
author | louiz’ <louiz@louiz.org> | 2018-02-05 22:53:36 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2018-02-05 22:53:36 +0100 |
commit | 56651cb5c29cc50ddf3c62c37167fa0b9389bfde (patch) | |
tree | ca652963cafeb02b0c6c7504b1cfbc27abdafe0b /src/irc | |
parent | ad1e0f8d52189e18df2d5a39228e255798a9de70 (diff) | |
parent | e0d1a0b44add408504e428d6ce4a8a2121ea7a00 (diff) | |
download | biboumi-56651cb5c29cc50ddf3c62c37167fa0b9389bfde.tar.gz biboumi-56651cb5c29cc50ddf3c62c37167fa0b9389bfde.tar.bz2 biboumi-56651cb5c29cc50ddf3c62c37167fa0b9389bfde.tar.xz biboumi-56651cb5c29cc50ddf3c62c37167fa0b9389bfde.zip |
Merge branch 'master' into debian
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/irc_client.cpp | 45 | ||||
-rw-r--r-- | src/irc/irc_client.hpp | 7 |
2 files changed, 34 insertions, 18 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp index 46dbdbe..40078d9 100644 --- a/src/irc/irc_client.cpp +++ b/src/irc/irc_client.cpp @@ -483,12 +483,16 @@ bool IrcClient::send_channel_message(const std::string& chan_name, const std::st } // The max size is 512, taking into account the whole message, not just // the text we send. - // This includes our own nick, username and host (because this will be - // added by the server into our message), in addition to the basic - // components of the message we send (command name, chan name, \r\n et) + // This includes our own nick, constants for username and host (because these + // are notoriously hard to know what the server will use), in addition to the basic + // components of the message we send (command name, chan name, \r\n etc.) // : + NICK + ! + USER + @ + HOST + <space> + PRIVMSG + <space> + CHAN + <space> + : + \r\n + // 63 is the maximum hostname length defined by the protocol. 10 seems to be + // the username limit. + constexpr auto max_username_size = 10; + constexpr auto max_hostname_size = 63; const auto line_size = 512 - - this->current_nick.size() - this->username.size() - this->own_host.size() - + this->current_nick.size() - max_username_size - max_hostname_size - ::strlen(":!@ PRIVMSG ") - chan_name.length() - ::strlen(" :\r\n"); const auto lines = cut(body, line_size); for (const auto& line: lines) @@ -784,7 +788,7 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message) channel->joined = true; this->bridge.send_user_join(this->hostname, chan_name, channel->get_self(), channel->get_self()->get_most_significant_mode(this->sorted_user_modes), true); - this->bridge.send_room_history(this->hostname, chan_name); + this->bridge.send_room_history(this->hostname, chan_name, this->history_limit); this->bridge.send_topic(this->hostname, chan_name, channel->topic, channel->topic_author); } @@ -1017,19 +1021,17 @@ void IrcClient::on_quit(const IrcMessage& message) const std::string& chan_name = pair.first; IrcChannel* channel = pair.second.get(); const IrcUser* user = channel->find_user(message.prefix); + if (!user) + continue; bool self = false; if (user == channel->get_self()) self = true; - if (user) - { - std::string nick = user->nick; - channel->remove_user(user); - Iid iid; - iid.set_local(chan_name); - iid.set_server(this->hostname); - iid.type = Iid::Type::Channel; - this->bridge.send_muc_leave(iid, std::move(nick), txt, self, false); - } + Iid iid; + iid.set_local(chan_name); + iid.set_server(this->hostname); + iid.type = Iid::Type::Channel; + this->bridge.send_muc_leave(iid, user->nick, txt, self, false); + channel->remove_user(user); } } @@ -1073,12 +1075,18 @@ void IrcClient::on_nick(const IrcMessage& message) void IrcClient::on_kick(const IrcMessage& message) { const std::string chan_name = utils::tolower(message.arguments[0]); - const std::string target = message.arguments[1]; + const std::string target_nick = message.arguments[1]; const std::string reason = message.arguments[2]; IrcChannel* channel = this->get_channel(chan_name); if (!channel->joined) return ; - const bool self = channel->get_self()->nick == target; + const IrcUser* target = channel->find_user(target_nick); + if (!target) + { + log_warning("Received a KICK command from a nick absent from the channel."); + return; + } + const bool self = channel->get_self() == target; if (self) channel->joined = false; IrcUser author(message.prefix); @@ -1086,7 +1094,8 @@ void IrcClient::on_kick(const IrcMessage& message) iid.set_local(chan_name); iid.set_server(this->hostname); iid.type = Iid::Type::Channel; - this->bridge.kick_muc_user(std::move(iid), target, reason, author.nick, self); + this->bridge.kick_muc_user(std::move(iid), target_nick, reason, author.nick, self); + channel->remove_user(target); } void IrcClient::on_invite(const IrcMessage& message) diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp index aec6cd9..de5c520 100644 --- a/src/irc/irc_client.hpp +++ b/src/irc/irc_client.hpp @@ -5,6 +5,8 @@ #include <irc/irc_channel.hpp> #include <irc/iid.hpp> +#include <bridge/history_limit.hpp> + #include <network/tcp_client_socket_handler.hpp> #include <network/resolver.hpp> @@ -296,6 +298,11 @@ public: const std::vector<char>& get_sorted_user_modes() const { return this->sorted_user_modes; } std::set<char> get_chantypes() const { return this->chantypes; } + + /** + * Store the history limit that the client asked when joining this room. + */ + HistoryLimit history_limit; private: /** * The hostname of the server we are connected to. |