Another big update today.
[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
31 #define DEFAULT_PORT 6667
32
33 /*! \file */
34
35 /*! \class Server
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 sendStatusMsg(QString);
66     void sendMessage(QString buffer, QString msg);
67     void disconnected();
68
69   private slots:
70     void run();
71     void socketHasData();
72     void socketError(QAbstractSocket::SocketError);
73     void socketConnected();
74     void socketDisconnected();
75     void socketStateChanged(QAbstractSocket::SocketState);
76
77     /* Message Handlers */
78     /* handleXxxxFromServer(QString prefix, QStringList params); */
79     void handleNoticeFromServer(QString, QStringList);
80     void handlePingFromServer(QString, QStringList);
81
82     void defaultHandlerForServer(QString cmd, QString prefix, QStringList params);
83
84   private:
85     QString network;
86     QTcpSocket socket;
87     QHash<QString, Buffer*> buffers;
88
89     void handleServerMsg(QString rawMsg);
90     void handleUserMsg(QString usrMsg);
91
92     class ParseError : public Exception {
93       public:
94         ParseError(QString cmd, QString prefix, QStringList params);
95     };
96
97     class UnknownCmdError : public Exception {
98       public:
99         UnknownCmdError(QString cmd, QString prefix, QStringList params);
100     };
101 };
102
103 #endif