summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircconnection.cpp
Unidiff
Diffstat (limited to 'noncore/net/opieirc/ircconnection.cpp') (more/less context) (show 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 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <string.h> 2#include <string.h>
3
4#include <qstringlist.h>
5#include <qdatetime.h>
6
3#include "ircconnection.h" 7#include "ircconnection.h"
4 8
5IRCConnection::IRCConnection(IRCServer *server) { 9IRCConnection::IRCConnection(IRCServer *server) {
6 m_server = server; 10 m_server = server;
7 m_socket = new QSocket(this); 11 m_socket = new QSocket(this);
8 m_connected = FALSE; 12 m_connected = FALSE;
9 m_loggedIn = FALSE; 13 m_loggedIn = FALSE;
10 connect(m_socket, SIGNAL(connected()), this, SLOT(login())); 14 connect(m_socket, SIGNAL(connected()), this, SLOT(login()));
11 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady())); 15 connect(m_socket, SIGNAL(readyRead()), this, SLOT(dataReady()));
12 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int))); 16 connect(m_socket, SIGNAL(error(int)), this, SLOT(error(int)));
13 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect())); 17 connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(disconnect()));
14 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect())); 18 connect(m_socket, SIGNAL(delayedCloseFinished()), this, SLOT(disconnect()));
@@ -19,26 +23,41 @@ void IRCConnection::doConnect() {
19 ASSERT(!m_connected); 23 ASSERT(!m_connected);
20 m_socket->connectToHost(m_server->hostname(), m_server->port()); 24 m_socket->connectToHost(m_server->hostname(), m_server->port());
21} 25}
22 26
23/* Send commands to the IRC server */ 27/* Send commands to the IRC server */
24void IRCConnection::sendLine(QString line) { 28void IRCConnection::sendLine(QString line) {
25 while((line.right(1) == "\n") || (line.right(1) == "\r")) 29 while((line.right(1) == "\n") || (line.right(1) == "\r"))
26 line = line.left(line.length() - 1); 30 line = line.left(line.length() - 1);
27 line.append("\r\n"); 31 line.append("\r\n");
28 m_socket->writeBlock(line, line.length()); 32 m_socket->writeBlock(line, line.length());
29} 33}
30 34
31void IRCConnection::sendCTCP(QString nick, QString line) { 35void IRCConnection::sendCTCPReply(const QString &nickname, const QString &type, const QString &args) {
32 sendLine("NOTICE " + nick + " :\001"+line+"\001"); 36 sendLine("NOTICE " + nickname + " :\001" + type + " " + args + "\001");
37}
38
39void IRCConnection::sendCTCPRequest(const QString &nickname, const QString &type, const QString &args) {
40 sendLine("PRIVMSG " + nickname + " :\001" + type + " " + args + "\001");
41}
42
43void IRCConnection::sendCTCPPing(const QString &nickname) {
44 QDateTime tm;
45 tm.setTime_t(0);
46 QString strtime = QString::number(tm.secsTo(QDateTime::currentDateTime()));
47 sendCTCPRequest(nickname, "PING", strtime);
48}
49
50void IRCConnection::whois(const QString &nickname) {
51 sendLine("WHOIS " + nickname);
33} 52}
34 53
35/* 54/*
36 * login() is called right after the connection 55 * login() is called right after the connection
37 * to the IRC server has been established 56 * to the IRC server has been established
38 */ 57 */
39void IRCConnection::login() { 58void IRCConnection::login() {
40 char hostname[256]; 59 char hostname[256];
41 QString loginString; 60 QString loginString;
42 61
43 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in .."))); 62 emit outputReady(IRCOutput(OUTPUT_CLIENTMESSAGE, tr("Connected, logging in ..")));
44 m_connected = TRUE; 63 m_connected = TRUE;
@@ -91,12 +110,13 @@ bool IRCConnection::isConnected() {
91} 110}
92 111
93bool IRCConnection::isLoggedIn() { 112bool IRCConnection::isLoggedIn() {
94 return m_loggedIn; 113 return m_loggedIn;
95} 114}
96 115
97void IRCConnection::close() { 116void IRCConnection::close() {
98 m_socket->close(); 117 m_socket->close();
99 if (m_socket->state()==QSocket::Idle) { 118 if (m_socket->state()==QSocket::Idle) {
100 disconnect(); 119 disconnect();
101 } 120 }
102} 121}
122