1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 ***************************************************************************/
30 #include "corealiasmanager.h"
31 #include "corehighlightrulemanager.h"
32 #include "coreignorelistmanager.h"
39 class CoreBacklogManager;
40 class CoreBufferSyncer;
41 class CoreBufferViewManager;
44 class CoreIrcListHelper;
46 class CoreNetworkConfig;
47 class CoreSessionEventProcessor;
48 class CoreTransferManager;
51 class EventStringifier;
55 class NetworkConnection;
63 class CoreSession : public QObject
68 CoreSession(UserId, bool restoreState, bool strictIdentEnabled, QObject* parent = nullptr);
70 QList<BufferInfo> buffers() const;
71 inline UserId user() const { return _user; }
72 CoreNetwork* network(NetworkId) const;
73 CoreIdentity* identity(IdentityId) const;
76 * Returns the optionally strict-compliant ident for the given user identity
78 * If strict mode is enabled, this will return the user's Quassel username for any identity,
79 * otherwise this will return the given identity's ident, whatever it may be.
81 * @return The user's ident, compliant with strict mode (when enabled)
83 const QString strictCompliantIdent(const CoreIdentity* identity);
85 inline CoreNetworkConfig* networkConfig() const { return _networkConfig; }
86 NetworkConnection* networkConnection(NetworkId) const;
88 Protocol::SessionState sessionState() const;
90 inline SignalProxy* signalProxy() const { return _signalProxy; }
92 const AliasManager& aliasManager() const { return _aliasManager; }
93 AliasManager& aliasManager() { return _aliasManager; }
95 inline EventManager* eventManager() const { return _eventManager; }
96 inline EventStringifier* eventStringifier() const { return _eventStringifier; }
97 inline CoreSessionEventProcessor* sessionEventProcessor() const { return _sessionEventProcessor; }
98 inline CtcpParser* ctcpParser() const { return _ctcpParser; }
99 inline IrcParser* ircParser() const { return _ircParser; }
101 inline CoreIrcListHelper* ircListHelper() const { return _ircListHelper; }
103 inline CoreIgnoreListManager* ignoreListManager() { return &_ignoreListManager; }
104 inline HighlightRuleManager* highlightRuleManager() { return &_highlightRuleManager; }
105 inline CoreTransferManager* transferManager() const { return _transferManager; }
106 inline CoreDccConfig* dccConfig() const { return _dccConfig; }
108 // void attachNetworkConnection(NetworkConnection *conn);
110 //! Return necessary data for restoring the session after restarting the core
111 void restoreSessionState();
114 void addClient(RemotePeer* peer);
115 void addClient(InternalPeer* peer);
118 * Shuts down the session and deletes itself afterwards.
122 void msgFromClient(BufferInfo, QString message);
124 //! Create an identity and propagate the changes to the clients.
125 /** \param identity The identity to be created.
127 void createIdentity(const Identity& identity, const QVariantMap& additional);
128 void createIdentity(const CoreIdentity& identity);
130 //! Remove identity and propagate that fact to the clients.
131 /** \param identity The identity to be removed.
133 void removeIdentity(IdentityId identity);
135 //! Create a network and propagate the changes to the clients.
136 /** \param info The network's settings.
138 void createNetwork(const NetworkInfo& info, const QStringList& persistentChannels = QStringList());
140 //! Remove network and propagate that fact to the clients.
141 /** \param network The id of the network to be removed.
143 void removeNetwork(NetworkId network);
145 //! Rename a Buffer for a given network
146 /* \param networkId The id of the network the buffer belongs to
147 * \param newName The new name of the buffer
148 * \param oldName The old name of the buffer
150 void renameBuffer(const NetworkId& networkId, const QString& newName, const QString& oldName);
152 void changePassword(PeerPtr peer, const QString& userName, const QString& oldPassword, const QString& newPassword);
154 void kickClient(int peerId);
156 QHash<QString, QString> persistentChannels(NetworkId) const;
158 QHash<QString, QByteArray> bufferCiphers(NetworkId id) const;
159 void setBufferCipher(NetworkId id, const QString& bufferName, const QByteArray& cipher) const;
162 * Marks us away (or unaway) on all networks
164 * @param[in] msg Away message, or blank to set unaway
165 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
167 void globalAway(const QString& msg = QString(), const bool skipFormatting = false);
171 void sessionStateReceived(const Protocol::SessionState& sessionState);
173 // void msgFromGui(uint netid, QString buf, QString message);
174 void displayMsg(Message message);
175 void displayStatusMsg(QString, QString);
177 void scriptResult(QString result);
179 //! Identity has been created.
180 /** This signal is propagated to the clients to tell them that the given identity has been created.
181 * \param identity The new identity.
183 void identityCreated(const Identity& identity);
185 //! Identity has been removed.
186 /** This signal is propagated to the clients to inform them about the removal of the given identity.
187 * \param identity The identity that has been removed.
189 void identityRemoved(IdentityId identity);
191 void networkCreated(NetworkId);
192 void networkRemoved(NetworkId);
193 void networkDisconnected(NetworkId);
195 void passwordChanged(PeerPtr peer, bool success);
197 void disconnectFromCore();
200 void customEvent(QEvent* event) override;
203 void removeClient(Peer* peer);
205 void recvStatusMsgFromServer(QString msg);
206 void recvMessageFromServer(NetworkId networkId,
209 const QString& target,
211 const QString& sender = "",
212 Message::Flags flags = Message::None);
214 void destroyNetwork(NetworkId);
216 void scriptRequest(QString script);
218 void clientsConnected();
219 void clientsDisconnected();
221 void updateIdentityBySender();
223 void saveSessionState() const;
225 void onNetworkDisconnected(NetworkId networkId);
228 void processMessages();
231 void initScriptEngine();
233 /// Hook for converting events to the old displayMsg() handlers
234 Q_INVOKABLE void processMessageEvent(MessageEvent* event);
238 /// Whether or not strict ident mode is enabled, locking users' idents to Quassel username
239 bool _strictIdentEnabled;
241 SignalProxy* _signalProxy;
242 CoreAliasManager _aliasManager;
244 QHash<IdentityId, CoreIdentity*> _identities;
245 QHash<NetworkId, CoreNetwork*> _networks;
246 QSet<NetworkId> _networksPendingDisconnect;
248 CoreBufferSyncer* _bufferSyncer;
249 CoreBacklogManager* _backlogManager;
250 CoreBufferViewManager* _bufferViewManager;
251 CoreDccConfig* _dccConfig;
252 CoreIrcListHelper* _ircListHelper;
253 CoreNetworkConfig* _networkConfig;
255 CoreTransferManager* _transferManager;
257 EventManager* _eventManager;
258 EventStringifier* _eventStringifier; // should eventually move into client
259 CoreSessionEventProcessor* _sessionEventProcessor;
260 CtcpParser* _ctcpParser;
261 IrcParser* _ircParser;
263 QScriptEngine* scriptEngine;
266 * This method obtains the prefixes of the message's sender within a channel, by looking up their channelmodes, and
267 * processing them to prefixes based on the network's settings.
268 * @param sender The hostmask of the sender
269 * @param bufferInfo The BufferInfo object of the buffer
271 QString senderPrefixes(const QString& sender, const BufferInfo& bufferInfo) const;
274 * This method obtains the realname of the message's sender.
275 * @param sender The hostmask of the sender
276 * @param networkId The network the user is on
278 QString realName(const QString& sender, NetworkId networkId) const;
281 * This method obtains the avatar of the message's sender.
282 * @param sender The hostmask of the sender
283 * @param networkId The network the user is on
285 QString avatarUrl(const QString& sender, NetworkId networkId) const;
286 QList<RawMessage> _messageQueue;
287 bool _processMessages;
288 CoreIgnoreListManager _ignoreListManager;
289 CoreHighlightRuleManager _highlightRuleManager;
296 BufferInfo::Type bufferType;
300 Message::Flags flags;
302 NetworkId networkId, Message::Type type, BufferInfo::Type bufferType, QString target, QString text, QString sender, Message::Flags flags)
303 : networkId(networkId)
305 , bufferType(bufferType)
306 , target(std::move(target))
307 , text(std::move(text))
308 , sender(std::move(sender))