Use isupport informations to know the user modes when joining

Also remove the duplicate send_self_join methods, user only send_user_join
This commit is contained in:
Florent Le Coz
2014-01-04 01:59:36 +01:00
parent a075517824
commit acf769d83a
9 changed files with 68 additions and 76 deletions
+3 -2
View File
@@ -12,9 +12,10 @@ void IrcChannel::set_self(const std::string& name)
this->self = std::make_unique<IrcUser>(name);
}
IrcUser* IrcChannel::add_user(const std::string& name)
IrcUser* IrcChannel::add_user(const std::string& name,
const std::map<char, char> prefix_to_mode)
{
this->users.emplace_back(std::make_unique<IrcUser>(name));
this->users.emplace_back(std::make_unique<IrcUser>(name, prefix_to_mode));
return this->users.back().get();
}
+3 -1
View File
@@ -5,6 +5,7 @@
#include <memory>
#include <string>
#include <vector>
#include <map>
/**
* Keep the state of a joined channel (the list of occupants with their
@@ -19,7 +20,8 @@ public:
std::string topic;
void set_self(const std::string& name);
IrcUser* get_self() const;
IrcUser* add_user(const std::string& name);
IrcUser* add_user(const std::string& name,
const std::map<char, char> prefix_to_mode);
IrcUser* find_user(const std::string& name);
void remove_user(const IrcUser* user);
+10 -5
View File
@@ -235,11 +235,16 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message)
std::vector<std::string> nicks = utils::split(message.arguments[3], ' ');
for (const std::string& nick: nicks)
{
const IrcUser* user = channel->add_user(nick);
const IrcUser* user = channel->add_user(nick, this->prefix_to_mode);
if (user->nick != channel->get_self()->nick)
{
log_debug("Adding user [" << nick << "] to chan " << chan_name);
this->bridge->send_user_join(this->hostname, chan_name, user);
this->bridge->send_user_join(this->hostname, chan_name, user, false);
}
else
{
// we now know the modes of self, so copy the modes into self
channel->get_self()->modes = user->modes;
}
}
}
@@ -256,8 +261,8 @@ void IrcClient::on_channel_join(const IrcMessage& message)
}
else
{
const IrcUser* user = channel->add_user(nick);
this->bridge->send_user_join(this->hostname, chan_name, user);
const IrcUser* user = channel->add_user(nick, this->prefix_to_mode);
this->bridge->send_user_join(this->hostname, chan_name, user, false);
}
}
@@ -319,7 +324,7 @@ void IrcClient::on_channel_completely_joined(const IrcMessage& message)
{
const std::string chan_name = utils::tolower(message.arguments[1]);
IrcChannel* channel = this->get_channel(chan_name);
this->bridge->send_self_join(this->hostname, chan_name, channel->get_self()->nick);
this->bridge->send_user_join(this->hostname, chan_name, channel->get_self(), true);
this->bridge->send_topic(this->hostname, chan_name, channel->topic);
}
+15 -15
View File
@@ -2,26 +2,26 @@
#include <iostream>
IrcUser::IrcUser(const std::string& name)
IrcUser::IrcUser(const std::string& name,
const std::map<char, char>& prefix_to_mode)
{
if (name.empty())
return ;
const std::string::size_type sep = name.find("!");
const std::map<char, char>::const_iterator prefix = prefix_to_mode.find(name[0]);
const size_t name_begin = prefix == prefix_to_mode.end()? 0: 1;
if (sep == std::string::npos)
{
if (name[0] == '~' || name[0] == '&'
|| name[0] == '@' || name[0] == '%'
|| name[0] == '+')
this->nick = name.substr(1);
else
this->nick = name;
}
this->nick = name.substr(name_begin);
else
{
if (name[0] == '~' || name[0] == '&'
|| name[0] == '@' || name[0] == '%'
|| name[0] == '+')
this->nick = name.substr(1, sep);
else
this->nick = name.substr(0, sep);
this->nick = name.substr(name_begin, sep);
this->host = name.substr(sep+1);
}
if (prefix != prefix_to_mode.end())
this->modes.insert(prefix->second);
}
IrcUser::IrcUser(const std::string& name):
IrcUser(name, {})
{
}
+5 -1
View File
@@ -2,6 +2,8 @@
# define IRC_USER_INCLUDED
#include <string>
#include <map>
#include <set>
/**
* Keeps various information about one IRC channel user
@@ -9,10 +11,12 @@
class IrcUser
{
public:
explicit IrcUser(const std::string& name,
const std::map<char, char>& prefix_to_mode);
explicit IrcUser(const std::string& name);
std::string nick;
std::string host;
std::set<char> modes;
private:
IrcUser(const IrcUser&) = delete;