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"
35 #include "metricsserver.h"
40 class CoreBacklogManager;
41 class CoreBufferSyncer;
42 class CoreBufferViewManager;
45 class CoreIrcListHelper;
47 class CoreNetworkConfig;
48 class CoreSessionEventProcessor;
49 class CoreTransferManager;
52 class EventStringifier;
61 class CoreSession : public QObject
66 CoreSession(UserId, bool restoreState, bool strictIdentEnabled, QObject* parent = nullptr);
68 QList<BufferInfo> buffers() const;
69 inline UserId user() const { return _user; }
70 CoreNetwork* network(NetworkId) const;
71 CoreIdentity* identity(IdentityId) const;
74 * Returns the optionally strict-compliant ident for the given user identity
76 * If strict mode is enabled, this will return the user's Quassel username for any identity,
77 * otherwise this will return the given identity's ident, whatever it may be.
79 * @return The user's ident, compliant with strict mode (when enabled)
81 const QString strictCompliantIdent(const CoreIdentity* identity);
83 inline CoreNetworkConfig* networkConfig() const { return _networkConfig; }
85 Protocol::SessionState sessionState() const;
87 inline SignalProxy* signalProxy() const { return _signalProxy; }
89 const AliasManager& aliasManager() const { return _aliasManager; }
90 AliasManager& aliasManager() { return _aliasManager; }
92 inline EventManager* eventManager() const { return _eventManager; }
93 inline EventStringifier* eventStringifier() const { return _eventStringifier; }
94 inline CoreSessionEventProcessor* sessionEventProcessor() const { return _sessionEventProcessor; }
95 inline CtcpParser* ctcpParser() const { return _ctcpParser; }
96 inline IrcParser* ircParser() const { return _ircParser; }
98 inline CoreIrcListHelper* ircListHelper() const { return _ircListHelper; }
100 inline CoreIgnoreListManager* ignoreListManager() { return &_ignoreListManager; }
101 inline HighlightRuleManager* highlightRuleManager() { return &_highlightRuleManager; }
102 inline CoreTransferManager* transferManager() const { return _transferManager; }
103 inline CoreDccConfig* dccConfig() const { return _dccConfig; }
105 // void attachNetworkConnection(NetworkConnection *conn);
107 //! Return necessary data for restoring the session after restarting the core
108 void restoreSessionState();
111 void addClient(RemotePeer* peer);
112 void addClient(InternalPeer* peer);
115 * Shuts down the session and deletes itself afterwards.
119 void msgFromClient(BufferInfo, QString message);
121 //! Create an identity and propagate the changes to the clients.
122 /** \param identity The identity to be created.
124 void createIdentity(const Identity& identity, const QVariantMap& additional);
125 void createIdentity(const CoreIdentity& identity);
127 //! Remove identity and propagate that fact to the clients.
128 /** \param identity The identity to be removed.
130 void removeIdentity(IdentityId identity);
132 //! Create a network and propagate the changes to the clients.
133 /** \param info The network's settings.
135 void createNetwork(const NetworkInfo& info, const QStringList& persistentChannels = QStringList());
137 //! Remove network and propagate that fact to the clients.
138 /** \param network The id of the network to be removed.
140 void removeNetwork(NetworkId network);
142 //! Rename a Buffer for a given network
143 /* \param networkId The id of the network the buffer belongs to
144 * \param newName The new name of the buffer
145 * \param oldName The old name of the buffer
147 void renameBuffer(const NetworkId& networkId, const QString& newName, const QString& oldName);
149 void changePassword(PeerPtr peer, const QString& userName, const QString& oldPassword, const QString& newPassword);
151 void kickClient(int peerId);
153 QHash<QString, QString> persistentChannels(NetworkId) const;
155 QHash<QString, QByteArray> bufferCiphers(NetworkId id) const;
156 void setBufferCipher(NetworkId id, const QString& bufferName, const QByteArray& cipher) const;
159 * Marks us away (or unaway) on all networks
161 * @param[in] msg Away message, or blank to set unaway
162 * @param[in] skipFormatting If true, skip timestamp formatting codes (e.g. if already done)
164 void globalAway(const QString& msg = QString(), bool skipFormatting = false);
168 void sessionStateReceived(const Protocol::SessionState& sessionState);
170 // void msgFromGui(uint netid, QString buf, QString message);
171 void displayMsg(Message message);
172 void displayStatusMsg(QString, QString);
174 //! Identity has been created.
175 /** This signal is propagated to the clients to tell them that the given identity has been created.
176 * \param identity The new identity.
178 void identityCreated(const Identity& identity);
180 //! Identity has been removed.
181 /** This signal is propagated to the clients to inform them about the removal of the given identity.
182 * \param identity The identity that has been removed.
184 void identityRemoved(IdentityId identity);
186 void networkCreated(NetworkId);
187 void networkRemoved(NetworkId);
188 void networkDisconnected(NetworkId);
190 void passwordChanged(PeerPtr peer, bool success);
192 void disconnectFromCore();
195 void customEvent(QEvent* event) override;
198 void removeClient(Peer* peer);
200 void recvStatusMsgFromServer(QString msg);
201 void recvMessageFromServer(RawMessage msg);
203 void destroyNetwork(NetworkId);
205 void clientsConnected();
206 void clientsDisconnected();
208 void updateIdentityBySender();
210 void saveSessionState() const;
212 void onNetworkDisconnected(NetworkId networkId);
215 void processMessages();
219 /// Hook for converting events to the old displayMsg() handlers
220 Q_INVOKABLE void processMessageEvent(MessageEvent* event);
224 /// Whether or not strict ident mode is enabled, locking users' idents to Quassel username
225 bool _strictIdentEnabled;
227 SignalProxy* _signalProxy;
228 CoreAliasManager _aliasManager;
230 QHash<IdentityId, CoreIdentity*> _identities;
231 QHash<NetworkId, CoreNetwork*> _networks;
232 QSet<NetworkId> _networksPendingDisconnect;
234 CoreBufferSyncer* _bufferSyncer;
235 CoreBacklogManager* _backlogManager;
236 CoreBufferViewManager* _bufferViewManager;
237 CoreDccConfig* _dccConfig;
238 CoreIrcListHelper* _ircListHelper;
239 CoreNetworkConfig* _networkConfig;
241 CoreTransferManager* _transferManager;
243 EventManager* _eventManager;
244 EventStringifier* _eventStringifier; // should eventually move into client
245 CoreSessionEventProcessor* _sessionEventProcessor;
246 CtcpParser* _ctcpParser;
247 IrcParser* _ircParser;
250 * This method obtains the prefixes of the message's sender within a channel, by looking up their channelmodes, and
251 * processing them to prefixes based on the network's settings.
252 * @param sender The hostmask of the sender
253 * @param bufferInfo The BufferInfo object of the buffer
255 QString senderPrefixes(const QString& sender, const BufferInfo& bufferInfo) const;
258 * This method obtains the realname of the message's sender.
259 * @param sender The hostmask of the sender
260 * @param networkId The network the user is on
262 QString realName(const QString& sender, NetworkId networkId) const;
265 * This method obtains the avatar of the message's sender.
266 * @param sender The hostmask of the sender
267 * @param networkId The network the user is on
269 QString avatarUrl(const QString& sender, NetworkId networkId) const;
270 QList<RawMessage> _messageQueue;
271 bool _processMessages;
272 CoreIgnoreListManager _ignoreListManager;
273 CoreHighlightRuleManager _highlightRuleManager;
274 MetricsServer* _metricsServer{nullptr};
277 struct NetworkInternalMessage
280 BufferInfo::Type bufferType;
284 Message::Flags flags;
285 NetworkInternalMessage(Message::Type type,
286 BufferInfo::Type bufferType,
290 Message::Flags flags = Message::None)
292 , bufferType(bufferType)
293 , target(std::move(target))
294 , text(std::move(text))
295 , sender(std::move(sender))
305 BufferInfo::Type bufferType;
309 Message::Flags flags;
311 RawMessage(QDateTime timestamp,
314 BufferInfo::Type bufferType,
318 Message::Flags flags)
319 : timestamp(std::move(timestamp))
320 , networkId(networkId)
322 , bufferType(bufferType)
323 , target(std::move(target))
324 , text(std::move(text))
325 , sender(std::move(sender))
329 RawMessage(NetworkId networkId,
330 const NetworkInternalMessage& msg)
331 : timestamp(QDateTime::currentDateTimeUtc())
332 , networkId(networkId)
334 , bufferType(msg.bufferType)