Don’t use ! as the separator for nicknames, use % instead

It’s now easier to use. The distinction between a nick and a channel name is
based on the first character (by default it's '#' and '&'). The user doesn’t
have to worry about which separator to use anymore.

fix #3066
This commit is contained in:
louiz’
2016-08-10 15:48:28 +02:00
parent 183f53d0ef
commit 0d2dd71de5
10 changed files with 210 additions and 194 deletions
+57 -58
View File
@@ -1,62 +1,70 @@
#include <utils/tolower.hpp>
#include <config/config.hpp>
#include <bridge/bridge.hpp>
#include <irc/iid.hpp>
#include <utils/encoding.hpp>
Iid::Iid(const std::string& iid):
is_channel(false),
is_user(false)
Iid::Iid(const std::string local, const std::string server, Iid::Type type):
type(type),
local(local),
server(server)
{
const std::string fixed_irc_server = Config::get("fixed_irc_server", "");
if (fixed_irc_server.empty())
this->init(iid);
else
this->init_with_fixed_server(iid, fixed_irc_server);
}
Iid::Iid(const std::string& iid, const std::set<char>& chantypes)
{
this->init(iid);
this->set_type(std::set<char>(chantypes));
}
Iid::Iid(const std::string& iid, const std::initializer_list<char>& chantypes):
Iid(iid, std::set<char>(chantypes))
{
}
Iid::Iid(const std::string& iid, const Bridge *bridge)
{
this->init(iid);
const auto chantypes = bridge->get_chantypes(this->server);
this->set_type(chantypes);
}
void Iid::set_type(const std::set<char>& chantypes)
{
if (this->local.empty())
return;
if (chantypes.count(this->local[0]) == 1)
this->type = Iid::Type::Channel;
else
this->type = Iid::Type::User;
}
void Iid::init(const std::string& iid)
{
const std::string::size_type sep = iid.find_first_of("%!");
if (sep != std::string::npos)
const std::string fixed_irc_server = Config::get("fixed_irc_server", "");
if (fixed_irc_server.empty())
{
const std::string::size_type sep = iid.find('%');
if (sep != std::string::npos)
{
if (iid[sep] == '%')
this->is_channel = true;
else
this->is_user = true;
this->set_local(iid.substr(0, sep));
this->set_server(iid.substr(sep + 1));
this->type = Iid::Type::Channel;
}
else
{
this->set_server(iid);
this->type = Iid::Type::Server;
}
}
else
this->set_server(iid);
}
void Iid::init_with_fixed_server(const std::string& iid, const std::string& hostname)
{
this->set_server(hostname);
const std::string::size_type sep = iid.find("!");
// Without any separator, we consider that it's a channel
if (sep == std::string::npos)
{
this->is_channel = true;
this->set_local(iid);
}
else // A separator can be present to differenciate a channel from a user,
// but the part behind it (the hostname) is ignored
{
this->set_local(iid.substr(0, sep));
this->is_user = true;
}
}
Iid::Iid():
is_channel(false),
is_user(false)
{
{
this->set_server(fixed_irc_server);
this->set_local(iid);
}
}
void Iid::set_local(const std::string& loc)
@@ -88,27 +96,18 @@ const std::string& Iid::get_server() const
return this->server;
}
std::string Iid::get_sep() const
{
if (this->is_channel)
return "%";
else if (this->is_user)
return "!";
return "";
}
namespace std {
const std::string to_string(const Iid& iid)
{
if (Config::get("fixed_irc_server", "").empty())
return iid.get_encoded_local() + iid.get_sep() + iid.get_server();
{
if (iid.type == Iid::Type::Server)
return iid.get_server();
else
return iid.get_encoded_local() + iid.separator + iid.get_server();
}
else
{
if (iid.get_sep() == "!")
return iid.get_encoded_local() + iid.get_sep();
else
return iid.get_encoded_local();
}
return iid.get_encoded_local();
}
}