summaryrefslogtreecommitdiff
path: root/src/irc/irc_client.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-03 00:22:32 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-03 00:22:32 +0100
commit87aaacdb420341bf3619922332d58b95249971bc (patch)
tree8f819241c8e78b23f5e2036c22ac637092e4293c /src/irc/irc_client.cpp
parente332d7a2c0900aec488ab508c3e9e389d2a71e32 (diff)
downloadbiboumi-87aaacdb420341bf3619922332d58b95249971bc.tar.gz
biboumi-87aaacdb420341bf3619922332d58b95249971bc.tar.bz2
biboumi-87aaacdb420341bf3619922332d58b95249971bc.tar.xz
biboumi-87aaacdb420341bf3619922332d58b95249971bc.zip
Rename libirc and libxmpp to irc and xmpp
Diffstat (limited to 'src/irc/irc_client.cpp')
-rw-r--r--src/irc/irc_client.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
new file mode 100644
index 0000000..83d1b0d
--- /dev/null
+++ b/src/irc/irc_client.cpp
@@ -0,0 +1,72 @@
+#include <irc/irc_client.hpp>
+#include <irc/irc_message.hpp>
+
+#include <iostream>
+#include <stdexcept>
+
+IrcClient::IrcClient()
+{
+ std::cout << "IrcClient()" << std::endl;
+}
+
+IrcClient::~IrcClient()
+{
+ std::cout << "~IrcClient()" << std::endl;
+}
+
+void IrcClient::on_connected()
+{
+}
+
+void IrcClient::on_connection_close()
+{
+ std::cout << "Connection closed by remote server." << std::endl;
+ this->close();
+}
+
+void IrcClient::parse_in_buffer()
+{
+ while (true)
+ {
+ auto pos = this->in_buf.find("\r\n");
+ if (pos == std::string::npos)
+ break ;
+ IrcMessage message(this->in_buf.substr(0, pos));
+ this->in_buf = this->in_buf.substr(pos + 2, std::string::npos);
+ std::cout << message << std::endl;
+ }
+}
+
+void IrcClient::send_message(IrcMessage&& message)
+{
+ std::string res;
+ if (!message.prefix.empty())
+ res += ":" + std::move(message.prefix) + " ";
+ res += std::move(message.command);
+ for (const std::string& arg: message.arguments)
+ {
+ if (arg.find(" ") != std::string::npos)
+ {
+ res += " :" + arg;
+ break;
+ }
+ res += " " + arg;
+ }
+ res += "\r\n";
+ this->send_data(std::move(res));
+}
+
+void IrcClient::send_user_command(const std::string& username, const std::string& realname)
+{
+ this->send_message(IrcMessage("USER", {username, "NONE", "NONE", realname}));
+}
+
+void IrcClient::send_nick_command(const std::string& nick)
+{
+ this->send_message(IrcMessage("NICK", {nick}));
+}
+
+void IrcClient::send_join_command(const std::string& chan_name)
+{
+ this->send_message(IrcMessage("JOIN", {chan_name}));
+}