Support multi-prefix
See http://ircv3.net/specs/extensions/multi-prefix-3.1.html ref #3103
This commit is contained in:
@@ -151,6 +151,9 @@ void IrcClient::on_connected()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->send_message({"CAP", {"REQ", "multi-prefix"}});
|
||||||
|
this->send_message({"CAP", {"END"}});
|
||||||
|
|
||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
auto options = Database::get_irc_server_options(this->bridge.get_bare_jid(),
|
auto options = Database::get_irc_server_options(this->bridge.get_bare_jid(),
|
||||||
this->get_hostname());
|
this->get_hostname());
|
||||||
|
|||||||
+14
-4
@@ -7,8 +7,20 @@ IrcUser::IrcUser(const std::string& name,
|
|||||||
{
|
{
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return ;
|
return ;
|
||||||
const std::map<char, char>::const_iterator prefix = prefix_to_mode.find(name[0]);
|
|
||||||
const std::string::size_type name_begin = prefix == prefix_to_mode.end()? 0: 1;
|
// One or more prefix (with multi-prefix support) may come before the
|
||||||
|
// actual nick
|
||||||
|
std::string::size_type name_begin = 0;
|
||||||
|
while (name_begin != name.size())
|
||||||
|
{
|
||||||
|
const auto prefix = prefix_to_mode.find(name[name_begin]);
|
||||||
|
// This is not a prefix
|
||||||
|
if (prefix == prefix_to_mode.end())
|
||||||
|
break;
|
||||||
|
this->modes.insert(prefix->second);
|
||||||
|
name_begin++;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string::size_type sep = name.find("!", name_begin);
|
const std::string::size_type sep = name.find("!", name_begin);
|
||||||
if (sep == std::string::npos)
|
if (sep == std::string::npos)
|
||||||
this->nick = name.substr(name_begin);
|
this->nick = name.substr(name_begin);
|
||||||
@@ -17,8 +29,6 @@ IrcUser::IrcUser(const std::string& name,
|
|||||||
this->nick = name.substr(name_begin, sep-name_begin);
|
this->nick = name.substr(name_begin, sep-name_begin);
|
||||||
this->host = name.substr(sep+1);
|
this->host = name.substr(sep+1);
|
||||||
}
|
}
|
||||||
if (prefix != prefix_to_mode.end())
|
|
||||||
this->modes.insert(prefix->second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IrcUser::IrcUser(const std::string& name):
|
IrcUser::IrcUser(const std::string& name):
|
||||||
|
|||||||
+9
-1
@@ -8,7 +8,6 @@
|
|||||||
TEST_CASE("Irc user parsing")
|
TEST_CASE("Irc user parsing")
|
||||||
{
|
{
|
||||||
const std::map<char, char> prefixes{{'!', 'a'}, {'@', 'o'}};
|
const std::map<char, char> prefixes{{'!', 'a'}, {'@', 'o'}};
|
||||||
|
|
||||||
IrcUser user1("!nick!~some@host.bla", prefixes);
|
IrcUser user1("!nick!~some@host.bla", prefixes);
|
||||||
CHECK(user1.nick == "nick");
|
CHECK(user1.nick == "nick");
|
||||||
CHECK(user1.host == "~some@host.bla");
|
CHECK(user1.host == "~some@host.bla");
|
||||||
@@ -22,6 +21,15 @@ TEST_CASE("Irc user parsing")
|
|||||||
CHECK(user2.modes.find('a') == user2.modes.end());
|
CHECK(user2.modes.find('a') == user2.modes.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("multi-prefix")
|
||||||
|
{
|
||||||
|
const std::map<char, char> prefixes{{'!', 'a'}, {'@', 'o'}, {'~', 'f'}};
|
||||||
|
IrcUser user("!@~nick", prefixes);
|
||||||
|
CHECK(user.nick == "nick");
|
||||||
|
CHECK(user.modes.size() == 3);
|
||||||
|
CHECK(user.modes.find('f') != user.modes.end());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let Catch know how to display Iid objects
|
* Let Catch know how to display Iid objects
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user