Fix an issue with the event loop
[quassel.git] / src / core / ircserverhandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-10 by the Quassel Project                          *
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) version 3.                                           *
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 IRCSERVERHANDLER_H
22 #define IRCSERVERHANDLER_H
23
24 #include "corebasichandler.h"
25 #include "netsplit.h"
26
27 class IrcServerHandler : public CoreBasicHandler {
28   Q_OBJECT
29
30 public:
31   IrcServerHandler(CoreNetwork *parent);
32   ~IrcServerHandler();
33
34   void handleServerMsg(QByteArray rawMsg);
35
36 public slots:
37   void handleJoin(const QString &prefix, const QList<QByteArray> &params);
38   void handleMode(const QString &prefix, const QList<QByteArray> &params);
39   void handleNotice(const QString &prefix, const QList<QByteArray> &params);
40   void handlePing(const QString &prefix, const QList<QByteArray> &params);
41   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
42   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
43   void handle005(const QString &prefix, const QList<QByteArray> &params);   // RPL_ISUPPORT
44   void handle301(const QString &prefix, const QList<QByteArray> &params);   // RPL_AWAY
45   void handle305(const QString &prefix, const QList<QByteArray> &params);   // RPL_UNAWAY
46   void handle306(const QString &prefix, const QList<QByteArray> &params);   // RPL_NOWAWAY
47   void handle307(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVICE
48   void handle310(const QString &prefix, const QList<QByteArray> &params);   // RPL_SUSERHOST
49   void handle311(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISUSER
50   void handle312(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVER
51   void handle313(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISOPERATOR
52   void handle314(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOWASUSER
53   void handle315(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHO
54   void handle317(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISIDLE
55   void handle318(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHOIS
56   void handle319(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISCHANNELS
57   void handle320(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISVIRT (is identified to services)
58   void handle322(const QString &prefix, const QList<QByteArray> &params);   // RPL_LIST
59   void handle323(const QString &prefix, const QList<QByteArray> &params);   // RPL_LISTEND
60   void handle324(const QString &prefix, const QList<QByteArray> &params);   // RPL_CHANNELMODEIS
61   void handle328(const QString &prefix, const QList<QByteArray> &params);   // RPL_??? (channel homepage)
62   void handle329(const QString &prefix, const QList<QByteArray> &params);   // RPL_??? (channel creation time)
63   void handle330(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISACCOUNT (quakenet/snircd/undernet)
64   void handle331(const QString &prefix, const QList<QByteArray> &params);   // RPL_NOTOPIC
65   void handle332(const QString &prefix, const QList<QByteArray> &params);   // RPL_TOPIC
66   void handle333(const QString &prefix, const QList<QByteArray> &params);   // Topic set by...
67   void handle341(const QString &prefix, const QList<QByteArray> &params);   // RPL_INVITING
68   void handle352(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOREPLY
69   void handle353(const QString &prefix, const QList<QByteArray> &params);   // RPL_NAMREPLY
70   void handle369(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHOWAS
71   void handle432(const QString &prefix, const QList<QByteArray> &params);   // ERR_ERRONEUSNICKNAME
72   void handle433(const QString &prefix, const QList<QByteArray> &params);   // ERR_NICKNAMEINUSE
73   void handle437(const QString &prefix, const QList<QByteArray> &params);   // ERR_UNAVAILRESOURCE
74
75   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);
76
77 private slots:
78   //! Joins after a netsplit
79   /** This slot handles a bulk-join after a netsplit is over
80     * \param channel The channel the users joined
81     * \param users   The list of users that joind the channel
82     * \param modes   The list of modes the users get set
83     * \param quitMessage The message we received when the netsplit occured
84     */
85   void handleNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString &quitMessage);
86
87   //! Quits after a netsplit
88   /** This slot handles a bulk-quit after a netsplit occured
89     * \param channel The channel the users quitted
90     * \param users   The list of users that got split
91     * \param quitMessage The message we received when the netsplit occured
92     */
93   void handleNetsplitQuit(const QString &channel, const QStringList &users, const QString &quitMessage);
94
95   //! Netsplit finished
96   /** This slot deletes the netsplit object that sent the finished() signal
97     */
98   void handleNetsplitFinished();
99
100   void handleEarlyNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes);
101
102   //! Destroy any existing netsplits
103   /** This slot deletes all netsplit objects
104     * Used to get rid of existing netsplits on network reconnect
105     */
106   void destroyNetsplits();
107
108 private:
109   void tryNextNick(const QString &errnick, bool erroneus = false);
110   bool checkParamCount(const QString &methodName, const QList<QByteArray> &params, int minParams);
111
112   // holds the target for numeric replies or is invalid otherwise
113   inline const QString &target() const { return _target; }
114
115   bool _whois;
116   QString _target;
117
118   // structure to organize netsplits
119   // key: quit message
120   // value: the corresponding netsplit object
121   QHash<QString, Netsplit*> _netsplits;
122
123 #ifdef HAVE_QCA2
124   QByteArray decrypt(const QString &target, const QByteArray &message, bool isTopic = false);
125 #endif
126 };
127
128 #endif