summaryrefslogtreecommitdiff
path: root/src/irc
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-12 23:43:43 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-12 23:48:10 +0100
commit5817a95b5ee89480788832be35679dfcd2ed833b (patch)
treeb4db0db18a195b11f820247b78bfc4df5dba8c14 /src/irc
parentb60cbda4f93bb83e36b29f5cba975b94b833663d (diff)
downloadbiboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.gz
biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.bz2
biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.tar.xz
biboumi-5817a95b5ee89480788832be35679dfcd2ed833b.zip
Basic handling of modes, both ways
Diffstat (limited to 'src/irc')
-rw-r--r--src/irc/irc_channel.hpp1
-rw-r--r--src/irc/irc_client.cpp43
-rw-r--r--src/irc/irc_client.hpp19
3 files changed, 53 insertions, 10 deletions
diff --git a/src/irc/irc_channel.hpp b/src/irc/irc_channel.hpp
index 3786697..c4b6d2c 100644
--- a/src/irc/irc_channel.hpp
+++ b/src/irc/irc_channel.hpp
@@ -26,7 +26,6 @@ public:
private:
std::unique_ptr<IrcUser> self;
std::vector<std::unique_ptr<IrcUser>> users;
-
IrcChannel(const IrcChannel&) = delete;
IrcChannel(IrcChannel&&) = delete;
IrcChannel& operator=(const IrcChannel&) = delete;
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 30b1204..0d8c614 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -162,9 +162,15 @@ void IrcClient::send_part_command(const std::string& chan_name, const std::strin
{
IrcChannel* channel = this->get_channel(chan_name);
if (channel->joined == true)
- {
- this->send_message(IrcMessage("PART", {chan_name, status_message}));
- }
+ this->send_message(IrcMessage("PART", {chan_name, status_message}));
+}
+
+void IrcClient::send_mode_command(const std::string& chan_name, const std::vector<std::string>& arguments)
+{
+ std::vector<std::string> args(arguments);
+ args.insert(args.begin(), chan_name);
+ IrcMessage m("MODE", std::move(args));
+ this->send_message(std::move(m));
}
void IrcClient::send_pong_command(const IrcMessage& message)
@@ -325,3 +331,34 @@ void IrcClient::on_nick(const IrcMessage& message)
}
}
+void IrcClient::on_mode(const IrcMessage& message)
+{
+ const std::string target = message.arguments[0];
+ if (target[0] == '&' || target[0] == '#' ||
+ target[0] == '!' || target[0] == '+')
+ this->on_channel_mode(message);
+ else
+ this->on_user_mode(message);
+}
+
+void IrcClient::on_channel_mode(const IrcMessage& message)
+{
+ // For now, just transmit the modes so the user can know what happens
+ // TODO, actually interprete the mode.
+ Iid iid;
+ iid.chan = message.arguments[0];
+ iid.server = this->hostname;
+ IrcUser user(message.prefix);
+ this->bridge->send_message(iid, "", std::string("Mode ") + iid.chan +
+ " [" + message.arguments[1] +
+ (message.arguments.size() > 2 ? (" " + message.arguments[2]): "")
+ + "] by " + user.nick,
+ true);
+}
+
+void IrcClient::on_user_mode(const IrcMessage& message)
+{
+ this->bridge->send_xmpp_message(this->hostname, "",
+ std::string("User mode for ") + message.arguments[0] +
+ " is [" + message.arguments[1] + "]");
+}
diff --git a/src/irc/irc_client.hpp b/src/irc/irc_client.hpp
index d9ea069..722f850 100644
--- a/src/irc/irc_client.hpp
+++ b/src/irc/irc_client.hpp
@@ -88,6 +88,10 @@ public:
*/
void send_part_command(const std::string& chan_name, const std::string& status_message);
/**
+ * Send the MODE irc command
+ */
+ void send_mode_command(const std::string& chan_name, const std::vector<std::string>& arguments);
+ /**
* Forward the server message received from IRC to the XMPP component
*/
void forward_server_message(const IrcMessage& message);
@@ -118,17 +122,20 @@ public:
* When a message 001 is received, join the rooms we wanted to join, and set our actual nickname
*/
void on_welcome_message(const IrcMessage& message);
- /**
- * When a PART message is received
- */
void on_part(const IrcMessage& message);
+ void on_nick(const IrcMessage& message);
+ void on_mode(const IrcMessage& message);
/**
- * When a NICK message is received
+ * A mode towards our own user is received (note, that is different from a
+ * channel mode towards or own nick, see
+ * http://tools.ietf.org/html/rfc2812#section-3.1.5 VS #section-3.2.3)
*/
- void on_nick(const IrcMessage& message);
+ void on_user_mode(const IrcMessage& message);
/**
- * When a QUIT message is received
+ * A mode towards a channel. Note that this can change the mode of the
+ * channel itself or an IrcUser in it.
*/
+ void on_channel_mode(const IrcMessage& message);
void on_quit(const IrcMessage& message);
private: