30f2d1d62f906d3e8b32ddeab47e2ebd72475b33
[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 handleInvite(const QString &prefix, const QList<QByteArray> &params);
38   void handleJoin(const QString &prefix, const QList<QByteArray> &params);
39   void handleKick(const QString &prefix, const QList<QByteArray> &params);
40   void handleMode(const QString &prefix, const QList<QByteArray> &params);
41   void handleNick(const QString &prefix, const QList<QByteArray> &params);
42   void handleNotice(const QString &prefix, const QList<QByteArray> &params);
43   void handlePart(const QString &prefix, const QList<QByteArray> &params);
44   void handlePing(const QString &prefix, const QList<QByteArray> &params);
45   void handlePong(const QString &prefix, const QList<QByteArray> &params);
46   void handlePrivmsg(const QString &prefix, const QList<QByteArray> &params);
47   void handleQuit(const QString &prefix, const QList<QByteArray> &params);
48   void handleTopic(const QString &prefix, const QList<QByteArray> &params);
49   void handleCap(const QString &prefix, const QList<QByteArray> &params);   // CAP framework
50   void handleAuthenticate();                                                // SASL auth - no params
51   void handle001(const QString &prefix, const QList<QByteArray> &params);   // RPL_WELCOME
52   void handle005(const QString &prefix, const QList<QByteArray> &params);   // RPL_ISUPPORT
53   void handle221(const QString &prefix, const QList<QByteArray> &params);   // RPL_UMODEIS
54   void handle250(const QString &prefix, const QList<QByteArray> &params);   // RPL_STATSDLINE
55   void handle265(const QString &prefix, const QList<QByteArray> &params);   // RPL_LOCALUSERS
56   void handle266(const QString &prefix, const QList<QByteArray> &params);   // RPL_GLOBALUSERS
57   void handle301(const QString &prefix, const QList<QByteArray> &params);   // RPL_AWAY
58   void handle305(const QString &prefix, const QList<QByteArray> &params);   // RPL_UNAWAY
59   void handle306(const QString &prefix, const QList<QByteArray> &params);   // RPL_NOWAWAY
60   void handle307(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVICE
61   void handle310(const QString &prefix, const QList<QByteArray> &params);   // RPL_SUSERHOST
62   void handle311(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISUSER
63   void handle312(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISSERVER
64   void handle313(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISOPERATOR
65   void handle314(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOWASUSER
66   void handle315(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHO
67   void handle317(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISIDLE
68   void handle318(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHOIS
69   void handle319(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISCHANNELS
70   void handle320(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOISVIRT (is identified to services)
71   void handle322(const QString &prefix, const QList<QByteArray> &params);   // RPL_LIST
72   void handle323(const QString &prefix, const QList<QByteArray> &params);   // RPL_LISTEND
73   void handle324(const QString &prefix, const QList<QByteArray> &params);   // RPL_CHANNELMODEIS
74   void handle328(const QString &prefix, const QList<QByteArray> &params);   // RPL_??? (channel homepage)
75   void handle329(const QString &prefix, const QList<QByteArray> &params);   // RPL_??? (channel creation time)
76   void handle331(const QString &prefix, const QList<QByteArray> &params);   // RPL_NOTOPIC
77   void handle332(const QString &prefix, const QList<QByteArray> &params);   // RPL_TOPIC
78   void handle333(const QString &prefix, const QList<QByteArray> &params);   // Topic set by...
79   void handle341(const QString &prefix, const QList<QByteArray> &params);   // RPL_INVITING
80   void handle352(const QString &prefix, const QList<QByteArray> &params);   // RPL_WHOREPLY
81   void handle353(const QString &prefix, const QList<QByteArray> &params);   // RPL_NAMREPLY
82   void handle369(const QString &prefix, const QList<QByteArray> &params);   // RPL_ENDOFWHOWAS
83   void handle432(const QString &prefix, const QList<QByteArray> &params);   // ERR_ERRONEUSNICKNAME
84   void handle433(const QString &prefix, const QList<QByteArray> &params);   // ERR_NICKNAMEINUSE
85   void handle437(const QString &prefix, const QList<QByteArray> &params);   // ERR_UNAVAILRESOURCE
86
87   void defaultHandler(QString cmd, const QString &prefix, const QList<QByteArray> &params);
88
89 private slots:
90   //! Joins after a netsplit
91   /** This slot handles a bulk-join after a netsplit is over
92     * \param channel The channel the users joined
93     * \param users   The list of users that joind the channel
94     * \param modes   The list of modes the users get set
95     * \param quitMessage The message we received when the netsplit occured
96     */
97   void handleNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString &quitMessage);
98
99   //! Quits after a netsplit
100   /** This slot handles a bulk-quit after a netsplit occured
101     * \param channel The channel the users quitted
102     * \param users   The list of users that got split
103     * \param quitMessage The message we received when the netsplit occured
104     */
105   void handleNetsplitQuit(const QString &channel, const QStringList &users, const QString &quitMessage);
106
107   //! Netsplit finished
108   /** This slot deletes the netsplit object that sent the finished() signal
109     */
110   void handleNetsplitFinished();
111
112   void handleEarlyNetsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes);
113
114   //! Destroy any existing netsplits
115   /** This slot deletes all netsplit objects
116     * Used to get rid of existing netsplits on network reconnect
117     */
118   void destroyNetsplits();
119
120 private:
121   void tryNextNick(const QString &errnick, bool erroneus = false);
122   bool checkParamCount(const QString &methodName, const QList<QByteArray> &params, int minParams);
123
124   // holds the target for numeric replies or is invalid otherwise
125   inline const QString &target() const { return _target; }
126
127   bool _whois;
128   QString _target;
129
130   // structure to organize netsplits
131   // key: quit message
132   // value: the corresponding netsplit object
133   QHash<QString, Netsplit*> _netsplits;
134
135 #ifdef HAVE_QCA2
136   QByteArray decrypt(const QString &target, const QByteArray &message, bool isTopic = false);
137 #endif
138 };
139
140 #endif