qa: Replace deprecated qVariantFromValue() by QVariant::fromValue()
[quassel.git] / src / core / coresessioneventprocessor.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 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  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "basichandler.h"
24 #include "corenetwork.h"
25 #include "networkevent.h"
26
27 class CoreSession;
28 class CtcpEvent;
29 class IrcEvent;
30 class IrcEventNumeric;
31 class Netsplit;
32
33 #ifdef HAVE_QCA2
34 class KeyEvent;
35 #endif
36
37 class CoreSessionEventProcessor : public BasicHandler
38 {
39     Q_OBJECT
40
41 public:
42     explicit CoreSessionEventProcessor(CoreSession* session);
43
44     inline CoreSession* coreSession() const { return _coreSession; }
45
46     Q_INVOKABLE void processIrcEventNumeric(IrcEventNumeric* event);
47
48     Q_INVOKABLE void processIrcEventAuthenticate(IrcEvent* event);  /// SASL authentication
49     Q_INVOKABLE void processIrcEventCap(IrcEvent* event);           /// CAP framework negotiation
50     Q_INVOKABLE void processIrcEventAccount(IrcEvent* event);       /// account-notify received
51     Q_INVOKABLE void processIrcEventAway(IrcEvent* event);          /// away-notify received
52     Q_INVOKABLE void processIrcEventChghost(IrcEvent* event);       /// chghost received
53     Q_INVOKABLE void processIrcEventInvite(IrcEvent* event);
54     Q_INVOKABLE void processIrcEventJoin(IrcEvent* event);
55     Q_INVOKABLE void lateProcessIrcEventKick(IrcEvent* event);
56     Q_INVOKABLE void processIrcEventMode(IrcEvent* event);
57     Q_INVOKABLE void processIrcEventNick(IrcEvent* event);  /// Nickname changes
58     Q_INVOKABLE void lateProcessIrcEventNick(IrcEvent* event);
59     Q_INVOKABLE void processIrcEventPart(IrcEvent* event);  /// Leaving a channel
60     Q_INVOKABLE void lateProcessIrcEventPart(IrcEvent* event);
61     Q_INVOKABLE void processIrcEventPing(IrcEvent* event);
62     Q_INVOKABLE void processIrcEventPong(IrcEvent* event);
63     Q_INVOKABLE void processIrcEventQuit(IrcEvent* event);
64     Q_INVOKABLE void lateProcessIrcEventQuit(IrcEvent* event);
65     Q_INVOKABLE void processIrcEventTopic(IrcEvent* event);
66     Q_INVOKABLE void processIrcEventError(IrcEvent* event);  /// ERROR message from server
67 #ifdef HAVE_QCA2
68     Q_INVOKABLE void processKeyEvent(KeyEvent* event);
69 #endif
70
71     Q_INVOKABLE void processIrcEvent001(IrcEventNumeric* event);  // RPL_WELCOME
72     Q_INVOKABLE void processIrcEvent005(IrcEvent* event);         // RPL_ISUPPORT
73     Q_INVOKABLE void processIrcEvent221(IrcEvent* event);         // RPL_UMODEIS
74     Q_INVOKABLE void processIrcEvent250(IrcEvent* event);         // RPL_STATSCONN
75     Q_INVOKABLE void processIrcEvent265(IrcEvent* event);         // RPL_LOCALUSERS
76     Q_INVOKABLE void processIrcEvent266(IrcEvent* event);         // RPL_GLOBALUSERS
77     Q_INVOKABLE void processIrcEvent301(IrcEvent* event);         // RPL_AWAY
78     Q_INVOKABLE void processIrcEvent305(IrcEvent* event);         // RPL_UNAWAY
79     Q_INVOKABLE void processIrcEvent306(IrcEvent* event);         // RPL_NOWAWAY
80     Q_INVOKABLE void processIrcEvent307(IrcEvent* event);         // RPL_WHOISSERVICE
81     Q_INVOKABLE void processIrcEvent310(IrcEvent* event);         // RPL_SUSERHOST
82     Q_INVOKABLE void processIrcEvent311(IrcEvent* event);         // RPL_WHOISUSER
83     Q_INVOKABLE void processIrcEvent312(IrcEvent* event);         // RPL_WHOISSERVER
84     Q_INVOKABLE void processIrcEvent313(IrcEvent* event);         // RPL_WHOISOPERATOR
85     Q_INVOKABLE void processIrcEvent315(IrcEvent* event);         // RPL_ENDOFWHO
86     Q_INVOKABLE void processIrcEvent317(IrcEvent* event);         // RPL_WHOISIDLE
87     Q_INVOKABLE void processIrcEvent322(IrcEvent* event);         // RPL_LIST
88     Q_INVOKABLE void processIrcEvent323(IrcEvent* event);         // RPL_LISTEND
89     Q_INVOKABLE void processIrcEvent324(IrcEvent* event);         // RPL_CHANNELMODEIS
90     Q_INVOKABLE void processIrcEvent330(IrcEvent* event);         // RPL_WHOISACCOUNT (quakenet/snircd/undernet)
91     Q_INVOKABLE void processIrcEvent331(IrcEvent* event);         // RPL_NOTOPIC
92     Q_INVOKABLE void processIrcEvent332(IrcEvent* event);         // RPL_TOPIC
93     Q_INVOKABLE void processIrcEvent352(IrcEvent* event);         // RPL_WHOREPLY
94     Q_INVOKABLE void processIrcEvent353(IrcEvent* event);         // RPL_NAMREPLY
95     Q_INVOKABLE void processIrcEvent354(IrcEvent* event);         // RPL_WHOSPCRPL
96     Q_INVOKABLE void processIrcEvent403(IrcEventNumeric* event);  // ERR_NOSUCHCHANNEL
97     Q_INVOKABLE void processIrcEvent432(IrcEventNumeric* event);  // ERR_ERRONEUSNICKNAME
98     Q_INVOKABLE void processIrcEvent433(IrcEventNumeric* event);  // ERR_NICKNAMEINUSE
99     Q_INVOKABLE void processIrcEvent437(IrcEventNumeric* event);  // ERR_UNAVAILRESOURCE
100
101     // Q_INVOKABLE void processIrcEvent(IrcEvent *event);
102
103     /* CTCP handlers */
104     Q_INVOKABLE void processCtcpEvent(CtcpEvent* event);
105
106     Q_INVOKABLE void handleCtcpAction(CtcpEvent* event);
107     Q_INVOKABLE void handleCtcpClientinfo(CtcpEvent* event);
108     Q_INVOKABLE void handleCtcpDcc(CtcpEvent* event);
109     Q_INVOKABLE void handleCtcpPing(CtcpEvent* event);
110     Q_INVOKABLE void handleCtcpTime(CtcpEvent* event);
111     Q_INVOKABLE void handleCtcpVersion(CtcpEvent* event);
112     Q_INVOKABLE void defaultHandler(const QString& ctcpCmd, CtcpEvent* event);
113
114 signals:
115     void newEvent(Event* event);
116
117 protected:
118     bool checkParamCount(IrcEvent* event, int minParams);
119     inline CoreNetwork* coreNetwork(NetworkEvent* e) const { return qobject_cast<CoreNetwork*>(e->network()); }
120     void tryNextNick(NetworkEvent* e, const QString& errnick, bool erroneous = false);
121
122 private slots:
123     //! Joins after a netsplit
124     /** This slot handles a bulk-join after a netsplit is over
125      * \param net     The network
126      * \param channel The channel the users joined
127      * \param users   The list of users that joind the channel
128      * \param modes   The list of modes the users get set
129      * \param quitMessage The message we received when the netsplit occured
130      */
131     void handleNetsplitJoin(Network* net, const QString& channel, const QStringList& users, const QStringList& modes, const QString& quitMessage);
132
133     //! Quits after a netsplit
134     /** This slot handles a bulk-quit after a netsplit occured
135      * \param net     The network
136      * \param channel The channel the users quitted
137      * \param users   The list of users that got split
138      * \param quitMessage The message we received when the netsplit occured
139      */
140     void handleNetsplitQuit(Network* net, const QString& channel, const QStringList& users, const QString& quitMessage);
141
142     //! Netsplit finished
143     /** This slot deletes the netsplit object that sent the finished() signal
144      */
145     void handleNetsplitFinished();
146
147     void handleEarlyNetsplitJoin(Network* net, const QString& channel, const QStringList& users, const QStringList& modes);
148
149     //! Destroy any existing netsplits
150     /** This slot deletes all netsplit objects
151      * Used to get rid of existing netsplits on network reconnect
152      * \param network The network we want to clear
153      */
154     void destroyNetsplits(NetworkId network);
155
156 private:
157     CoreSession* _coreSession;
158
159     // structure to organize netsplits
160     // key: quit message
161     // value: the corresponding netsplit object
162     QHash<Network*, QHash<QString, Netsplit*>> _netsplits;
163
164     /**
165      * Process given WHO reply information, updating user data, channel modes, etc as needed
166      *
167      * This takes information from WHO and WHOX replies, processing information that's common
168      * between them.
169      *
170      * @param[in] net                 Network object for the IRC server
171      * @param[in] targetChannel       Target channel, or * if unspecified
172      * @param[in] ircUser             IrcUser representing the desired nick
173      * @param[in] server              Nick server name
174      * @param[in] user                Nick username
175      * @param[in] host                Nick hostname
176      * @param[in] awayStateAndModes   Nick away-state and modes (e.g. G@)
177      * @param[in] realname            Nick realname
178      */
179     void processWhoInformation(Network* net,
180                                const QString& targetChannel,
181                                IrcUser* ircUser,
182                                const QString& server,
183                                const QString& user,
184                                const QString& host,
185                                const QString& awayStateAndModes,
186                                const QString& realname);
187 };