55539e64ce6366dc9fb820a4ed623ea56a9bd43b
[quassel.git] / src / core / coreuserinputhandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 #ifndef COREUSERINPUTHANDLER_H
22 #define COREUSERINPUTHANDLER_H
23
24 #include "corebasichandler.h"
25 #include "corenetwork.h"
26
27 class Cipher;
28 class Server;
29
30 class CoreUserInputHandler : public CoreBasicHandler
31 {
32     Q_OBJECT
33
34 public:
35     CoreUserInputHandler(CoreNetwork *parent = nullptr);
36     inline CoreNetwork *coreNetwork() const { return qobject_cast<CoreNetwork *>(parent()); }
37
38     void handleUserInput(const BufferInfo &bufferInfo, const QString &text);
39     int lastParamOverrun(const QString &cmd, const QList<QByteArray> &params);
40
41 public slots:
42     /**
43      * Handle the away command, marking as away or unaway
44      *
45      * Applies to the current network unless text begins with "-all".
46      *
47      * @param[in] bufferInfo      Currently active buffer
48      * @param[in] text            Away message, or blank to set unaway
49      * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
50      */
51     void handleAway(const BufferInfo &bufferInfo, const QString &text,
52                     const bool skipFormatting = false);
53     void handleBan(const BufferInfo &bufferInfo, const QString &text);
54     void handleUnban(const BufferInfo &bufferInfo, const QString &text);
55     void handleCtcp(const BufferInfo &bufferInfo, const QString &text);
56     void handleDelkey(const BufferInfo &bufferInfo, const QString &text);
57     void handleDeop(const BufferInfo& bufferInfo, const QString &nicks);
58     void handleDehalfop(const BufferInfo& bufferInfo, const QString &nicks);
59     void handleDevoice(const BufferInfo& bufferInfo, const QString &nicks);
60     void handleInvite(const BufferInfo &bufferInfo, const QString &text);
61     void handleJoin(const BufferInfo &bufferInfo, const QString &text);
62     void handleKeyx(const BufferInfo &bufferInfo, const QString &text);
63     void handleKick(const BufferInfo &bufferInfo, const QString &text);
64     void handleKill(const BufferInfo &bufferInfo, const QString &text);
65     void handleList(const BufferInfo &bufferInfo, const QString &text);
66     void handleMe(const BufferInfo &bufferInfo, const QString &text);
67     void handleMode(const BufferInfo &bufferInfo, const QString &text);
68     void handleMsg(const BufferInfo &bufferInfo, const QString &text);
69     void handleNick(const BufferInfo &bufferInfo, const QString &text);
70     void handleNotice(const BufferInfo &bufferInfo, const QString &text);
71     void handleOper(const BufferInfo &bufferInfo, const QString &text);
72     void handleOp(const BufferInfo& bufferInfo, const QString &nicks);
73     void handleHalfop(const BufferInfo& bufferInfo, const QString &nicks);
74     void handlePart(const BufferInfo &bufferInfo, const QString &text);
75     void handlePing(const BufferInfo &bufferInfo, const QString &text);
76     void handlePrint(const BufferInfo &bufferInfo, const QString &text);
77     void handleQuery(const BufferInfo &bufferInfo, const QString &text);
78     void handleQuit(const BufferInfo &bufferInfo, const QString &text);
79     void handleQuote(const BufferInfo &bufferInfo, const QString &text);
80     void handleSay(const BufferInfo &bufferInfo, const QString &text);
81     void handleSetkey(const BufferInfo &bufferInfo, const QString &text);
82     void handleShowkey(const BufferInfo &bufferInfo, const QString &text);
83     void handleTopic(const BufferInfo &bufferInfo, const QString &text);
84     void handleVoice(const BufferInfo &bufferInfo, const QString &text);
85     void handleWait(const BufferInfo &bufferInfo, const QString &text);
86     void handleWho(const BufferInfo &bufferInfo, const QString &text);
87     void handleWhois(const BufferInfo &bufferInfo, const QString &text);
88     void handleWhowas(const BufferInfo &bufferInfo, const QString &text);
89
90     void defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &text);
91
92     /**
93      * Send a QUIT to the IRC server, optionally skipping the command queue.
94      *
95      * @param reason          Reason for quitting, often displayed to other IRC clients
96      * @param forceImmediate  Immediately quit, skipping queue of other commands
97      */
98     void issueQuit(const QString &reason, bool forceImmediate = false);
99
100     /**
101      * Issues the away command, marking as away or unaway on the current network
102      *
103      * @param[in] msg             Away message, or blank to set unaway
104      * @param[in] autoCheck       If true, always set away, defaulting to the identity away message
105      * @param[in] skipFormatting  If true, skip timestamp formatting codes (e.g. if already done)
106      */
107     void issueAway(const QString &msg, bool autoCheck = true, const bool skipFormatting = false);
108
109 protected:
110     void timerEvent(QTimerEvent *event);
111
112 private:
113     void doMode(const BufferInfo& bufferInfo, const QChar &addOrRemove, const QChar &mode, const QString &nickList);
114     void banOrUnban(const BufferInfo &bufferInfo, const QString &text, bool ban);
115     void putPrivmsg(const QString &target, const QString &message, std::function<QByteArray(const QString &, const QString &)> encodeFunc, Cipher *cipher = nullptr);
116
117 #ifdef HAVE_QCA2
118     QByteArray encrypt(const QString &target, const QByteArray &message, bool *didEncrypt = nullptr) const;
119 #endif
120
121     struct Command {
122         BufferInfo bufferInfo;
123         QString command;
124         Command(const BufferInfo &info, const QString &command) : bufferInfo(info), command(command) {}
125         Command() {}
126     };
127
128     QHash<int, Command> _delayedCommands;
129 };
130
131
132 #endif