1 /***************************************************************************
2 * Copyright (C) 2005-2020 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
25 #include "corebasichandler.h"
26 #include "corenetwork.h"
31 class CoreUserInputHandler : public CoreBasicHandler
36 CoreUserInputHandler(CoreNetwork* parent = nullptr);
37 inline CoreNetwork* coreNetwork() const { return qobject_cast<CoreNetwork*>(parent()); }
39 void handleUserInput(const BufferInfo& bufferInfo, const QString& text);
40 int lastParamOverrun(const QString& cmd, const QList<QByteArray>& params);
44 * Handle the away command, marking as away or unaway
46 * Applies to the current network unless text begins with "-all".
48 * @param[in] bufferInfo Currently active buffer
49 * @param[in] text Away message, or blank to set unaway
50 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
52 void handleAway(const BufferInfo& bufferInfo, const QString& text, 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);
90 void defaultHandler(QString cmd, const BufferInfo& bufferInfo, const QString& text);
93 * Send a QUIT to the IRC server, optionally skipping the command queue.
95 * @param reason Reason for quitting, often displayed to other IRC clients
96 * @param forceImmediate Immediately quit, skipping queue of other commands
98 void issueQuit(const QString& reason, bool forceImmediate = false);
101 * Issues the away command, marking as away or unaway on the current network
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)
107 void issueAway(const QString& msg, bool autoCheck = true, const bool skipFormatting = false);
110 void timerEvent(QTimerEvent* event) override;
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,
116 const QString& message,
117 std::function<QByteArray(const QString&, const QString&)> encodeFunc,
118 Cipher* cipher = nullptr);
121 QByteArray encrypt(const QString& target, const QByteArray& message, bool* didEncrypt = nullptr) const;
126 BufferInfo bufferInfo;
128 Command(BufferInfo info, QString command)
129 : bufferInfo(std::move(info))
130 , command(std::move(command))
135 QHash<int, Command> _delayedCommands;