fixed bug in handleNick() where the determination wheter it was your nickchange or...
[quassel.git] / src / core / 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 <QAbstractSocket>
25 #include <QString>
26 #include <QStringList>
27 #include <QTcpSocket>
28 #include <QThread>
29 #include <QTimer>
30
31 #include "message.h"
32 #include "signalproxy.h"
33
34 class NetworkInfo;
35
36 class IrcServerHandler;
37 class UserInputHandler;
38 class CtcpHandler;
39 class CoreSession;
40
41 /*!
42  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
43  * We have this running in its own thread mainly to not block other server objects or the core if something goes wrong,
44  * e.g. if some scripts starts running wild...
45  */
46
47 class Server : public QThread {
48   Q_OBJECT
49
50 public:
51   Server(UserId uid, uint networkId, QString network);
52   ~Server();
53
54   UserId userId() const { return _userId; } 
55
56   // serverState state();
57   bool isConnected() const { return socket.state() == QAbstractSocket::ConnectedState; }
58
59   uint networkId() const;
60   QString networkName();  // hasbeen getNetwork()
61
62   NetworkInfo *networkInfo() { return _networkInfo; }
63   IrcServerHandler *ircServerHandler() {return _ircServerHandler; }
64   UserInputHandler *userInputHandler() {return _userInputHandler; }
65   CtcpHandler *ctcpHandler() {return _ctcpHandler; }
66   
67 public slots:
68   // void setServerOptions();
69   void connectToIrc(QString net);
70   void disconnectFromIrc(QString net);
71   void userInput(uint netid, QString buffer, QString msg);
72
73   void putRawLine(QString input);
74   void putCmd(QString cmd, QStringList params, QString prefix = 0);
75
76   //void exitThread();
77
78 signals:
79   void serverState(QString net, QVariantMap data);
80   void recvRawServerMsg(QString);
81   void displayStatusMsg(QString);
82   //void displayMsg(Message msg);
83   void displayMsg(Message::Type, QString target, QString text, QString sender = "", quint8 flags = Message::None);
84   void connected(uint networkId);
85   void disconnected(uint networkId);
86
87   void synchronizeClients();
88   
89   void queryRequested(QString network, QString nick);
90
91
92 private slots:
93   void run();
94   void socketHasData();
95   void socketError(QAbstractSocket::SocketError);
96   void socketConnected();
97   void socketDisconnected();
98   void socketStateChanged(QAbstractSocket::SocketState);
99
100 private:
101   UserId _userId;
102   uint _networkId;
103
104   QTcpSocket socket;
105
106   IrcServerHandler *_ircServerHandler;
107   UserInputHandler *_userInputHandler;
108   CtcpHandler *_ctcpHandler;
109
110   NetworkInfo *_networkInfo;
111
112   QVariantMap networkSettings;
113   QVariantMap identity;
114
115   CoreSession *coreSession() const;
116   
117   class ParseError : public Exception {
118   public:
119     ParseError(QString cmd, QString prefix, QStringList params);
120   };
121
122   class UnknownCmdError : public Exception {
123   public:
124     UnknownCmdError(QString cmd, QString prefix, QStringList params);
125   };
126     
127 };
128
129 #endif