More good news:
[quassel.git] / network / server.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _SERVER_H_
22 #define _SERVER_H_
23
24 #include <QtCore>
25 #include <QTimer>
26 #include <QtNetwork>
27
28 #include "global.h"
29 #include "buffer.h"
30 #include "message.h"
31
32 #define DEFAULT_PORT 6667
33
34
35 /*!
36  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
37  * We have this running in its own thread mainly to not block other server objects or the core if something goes wrong,
38  * e.g. if some scripts starts running wild...
39  */
40
41 class Server : public QThread {
42   Q_OBJECT
43
44   public:
45     Server(QString network);
46     ~Server();
47
48     // serverState state();
49     bool isConnected() { return socket.state() == QAbstractSocket::ConnectedState; }
50     QString getNetwork() { return network; }
51
52   public slots:
53     // void setServerOptions();
54     void connectToIrc(QString net);
55     void disconnectFromIrc(QString net);
56     void userInput(QString net, QString buffer, QString msg);
57
58     void putRawLine(QString input);
59     void putCmd(QString cmd, QStringList params, QString prefix = 0);
60
61     //void exitThread();
62
63   signals:
64     void recvRawServerMsg(QString);
65     void displayStatusMsg(QString);
66     void displayMsg(QString buffer, Message msg);
67     void disconnected();
68
69     void nickAdded(QString network, QString nick, VarMap props);
70     void nickRenamed(QString network, QString oldnick, QString newnick);
71     void nickRemoved(QString network, QString nick);
72     void nickUpdated(QString network, QString nick, VarMap props);
73     void modeSet(QString network, QString target, QString mode);
74     void topicSet(QString network, QString buffer, QString topic);
75     void setNicks(QString network, QString buffer, QStringList nicks);
76     void ownNickSet(QString network, QString newNick);
77
78
79   private slots:
80     void run();
81     void socketHasData();
82     void socketError(QAbstractSocket::SocketError);
83     void socketConnected();
84     void socketDisconnected();
85     void socketStateChanged(QAbstractSocket::SocketState);
86
87     /* Message Handlers */
88
89     /* void handleUser(QString, Buffer *) */
90     void handleUserJoin(QString, Buffer *);
91     void handleUserQuote(QString, Buffer *);
92     void handleUserSay(QString, Buffer *);
93
94
95     /* void handleServer(QString, QStringList); */
96     void handleServerJoin(QString, QStringList);
97     void handleServerKick(QString, QStringList);
98     void handleServerNick(QString, QStringList);
99     void handleServerNotice(QString, QStringList);
100     void handleServerPart(QString, QStringList);
101     void handleServerPing(QString, QStringList);
102     void handleServerPrivmsg(QString, QStringList);
103     void handleServerQuit(QString, QStringList);
104
105     void handleServer001(QString, QStringList);   // RPL_WELCOME
106     void handleServer331(QString, QStringList);   // RPL_NOTOPIC
107     void handleServer332(QString, QStringList);   // RPL_TOPIC
108     void handleServer333(QString, QStringList);   // Topic set by...
109     void handleServer353(QString, QStringList);   // RPL_NAMREPLY
110
111     void defaultServerHandler(QString cmd, QString prefix, QStringList params);
112     void defaultUserHandler(QString cmd, QString msg, Buffer *buf);
113
114   private:
115     QString network;
116     QTcpSocket socket;
117     QHash<QString, Buffer*> buffers;
118
119     QString currentNick;
120     QString currentServer;
121     VarMap networkSettings;
122     VarMap identity;
123     VarMap nicks;  // stores all known nicks for the server
124
125     void handleServerMsg(QString rawMsg);
126     void handleUserMsg(QString buffer, QString usrMsg);
127
128     QString updateNickFromMask(QString mask);
129
130     class ParseError : public Exception {
131       public:
132         ParseError(QString cmd, QString prefix, QStringList params);
133     };
134
135     class UnknownCmdError : public Exception {
136       public:
137         UnknownCmdError(QString cmd, QString prefix, QStringList params);
138     };
139 };
140
141 #endif