summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-02-26 17:43:24 +0100
committerFlorent Le Coz <louiz@louiz.org>2015-02-26 17:43:24 +0100
commit82256d40a32e1401c7884b1c9ff26ea77d775d3d (patch)
tree0661670f87c6cca2b43f2a35bc5c5d71ccfff78a /src/irc
parentc01befb054075ab414fd602859e5999a138aa5bf (diff)
parentc307df85c8e7d9bcd4570269bf13c3e92c3f5954 (diff)
downloadbiboumi-82256d40a32e1401c7884b1c9ff26ea77d775d3d.tar.gz
biboumi-82256d40a32e1401c7884b1c9ff26ea77d775d3d.tar.bz2
biboumi-82256d40a32e1401c7884b1c9ff26ea77d775d3d.tar.xz
biboumi-82256d40a32e1401c7884b1c9ff26ea77d775d3d.zip
Merge branch 'fixed_server'
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/iid.cpp41
-rw-r--r--src/irc/iid.hpp4
2 files changed, 44 insertions, 1 deletions
diff --git a/src/irc/iid.cpp b/src/irc/iid.cpp
index 0bb991f..9d39129 100644
--- a/src/irc/iid.cpp
+++ b/src/irc/iid.cpp
@@ -1,4 +1,5 @@
#include <utils/tolower.hpp>
+#include <config/config.hpp>
#include <irc/iid.hpp>
@@ -6,6 +7,16 @@ Iid::Iid(const std::string& iid):
is_channel(false),
is_user(false)
{
+ 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);
+}
+
+
+void Iid::init(const std::string& iid)
+{
const std::string::size_type sep = iid.find_first_of("%!");
if (sep != std::string::npos)
{
@@ -20,6 +31,26 @@ Iid::Iid(const std::string& iid):
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(const Iid& other):
is_channel(other.is_channel),
is_user(other.is_user),
@@ -66,6 +97,14 @@ std::string Iid::get_sep() const
namespace std {
const std::string to_string(const Iid& iid)
{
- return iid.get_local() + iid.get_sep() + iid.get_server();
+ if (Config::get("fixed_irc_server", "").empty())
+ return iid.get_local() + iid.get_sep() + iid.get_server();
+ else
+ {
+ if (iid.get_sep() == "!")
+ return iid.get_local() + iid.get_sep();
+ else
+ return iid.get_local();
+ }
}
}
diff --git a/src/irc/iid.hpp b/src/irc/iid.hpp
index d30cbaa..91779b2 100644
--- a/src/irc/iid.hpp
+++ b/src/irc/iid.hpp
@@ -57,6 +57,10 @@ public:
std::string get_sep() const;
private:
+
+ void init(const std::string& iid);
+ void init_with_fixed_server(const std::string& iid, const std::string& hostname);
+
std::string local;
std::string server;