summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircconnection.cpp
Side-by-side diff
Diffstat (limited to 'noncore/net/opieirc/ircconnection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircconnection.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircconnection.cpp b/noncore/net/opieirc/ircconnection.cpp
index 2325cca..88e63f7 100644
--- a/noncore/net/opieirc/ircconnection.cpp
+++ b/noncore/net/opieirc/ircconnection.cpp
@@ -1,14 +1,18 @@
#include <unistd.h>
#include <string.h>
+
+#include <qstringlist.h>
+#include <qdatetime.h>
+
#include "ircconnection.h"
IRCConnection::IRCConnection(IRCServer *server) {
m_server = server;
m_socket = new QSocket(this);
m_connected = FALSE;
m_loggedIn = FALSE;
connect(m_socket, SIGNAL(connected()), this, SLOT(login()));
connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady()));
connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int)));
connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect()));
connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect()));
@@ -19,26 +23,41 @@ void IRCConnection::doConnect() {
ASSERT(!m_connected);
m_socket->connectToHost(m_server->hostname(), m_server->port());
}
/* Send commands to the IRC server */
void IRCConnection::sendLine(QString line) {
while((line.right(1) == "\n") || (line.right(1) == "\r"))
line = line.left(line.length() - 1);
line.append("\r\n");
m_socket->writeBlock(line, line.length());
}
-void IRCConnection::sendCTCP(QString nick, QString line) {
- sendLine("NOTICE " + nick + " :\001"+line+"\001");
+void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
+ sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001");
+}
+
+void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
+ sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001");
+}
+
+void IRCConnection::sendCTCPPing(const QString &nickname) {
+ QDateTime tm;
+ tm.setTime_t(0);
+ QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime()));
+ sendCTCPRequest(nickname, "PING", strtime);
+}
+
+void IRCConnection::whois(const QString &nickname) {
+ sendLine("WHOIS " + nickname);
}
/*
* login() is called right after the connection
* to the IRC server has been established
*/
void IRCConnection::login() {
char hostname[256];
QString loginString;
emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in ..")));
m_connected = TRUE;
@@ -91,12 +110,13 @@ bool IRCConnection::isConnected() {
}
bool IRCConnection::isLoggedIn() {
return m_loggedIn;
}
void IRCConnection::close() {
m_socket->close();
if (m_socket->state()==QSocket::Idle) {
disconnect();
}
}
+