- CoreNetwork(const NetworkId &networkid, CoreSession *session);
- ~CoreNetwork();
- inline virtual const QMetaObject *syncMetaObject() const { return &Network::staticMetaObject; }
-
- inline CoreIdentity *identityPtr() const { return coreSession()->identity(identity()); }
- inline CoreSession *coreSession() const { return _coreSession; }
- inline CoreNetworkConfig *networkConfig() const { return coreSession()->networkConfig(); }
-
- inline IrcServerHandler *ircServerHandler() const { return _ircServerHandler; }
- inline CoreUserInputHandler *userInputHandler() const { return _userInputHandler; }
- inline CtcpHandler *ctcpHandler() const { return _ctcpHandler; }
- inline CoreIgnoreListManager *ignoreListManager() { return coreSession()->ignoreListManager(); }
-
- //! Decode a string using the server (network) decoding.
- inline QString serverDecode(const QByteArray &string) const { return decodeServerString(string); }
-
- //! Decode a string using a channel-specific encoding if one is set (and use the standard encoding else).
- QString channelDecode(const QString &channelName, const QByteArray &string) const;
-
- //! Decode a string using an IrcUser-specific encoding, if one exists (using the standaed encoding else).
- QString userDecode(const QString &userNick, const QByteArray &string) const;
-
- //! Encode a string using the server (network) encoding.
- inline QByteArray serverEncode(const QString &string) const { return encodeServerString(string); }
-
- //! Encode a string using the channel-specific encoding, if set, and use the standard encoding else.
- QByteArray channelEncode(const QString &channelName, const QString &string) const;
-
- //! Encode a string using the user-specific encoding, if set, and use the standard encoding else.
- QByteArray userEncode(const QString &userNick, const QString &string) const;
-
- inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
-
- inline bool isAutoWhoInProgress(const QString &channel) const { return _autoWhoPending.value(channel.toLower(), 0); }
-
- inline UserId userId() const { return _coreSession->user(); }
+ CoreNetwork(const NetworkId &networkid, CoreSession *session);
+ ~CoreNetwork();
+ inline virtual const QMetaObject *syncMetaObject() const { return &Network::staticMetaObject; }
+
+ inline CoreIdentity *identityPtr() const { return coreSession()->identity(identity()); }
+ inline CoreSession *coreSession() const { return _coreSession; }
+ inline CoreNetworkConfig *networkConfig() const { return coreSession()->networkConfig(); }
+
+ inline CoreUserInputHandler *userInputHandler() const { return _userInputHandler; }
+ inline CoreIgnoreListManager *ignoreListManager() { return coreSession()->ignoreListManager(); }
+
+ //! Decode a string using the server (network) decoding.
+ inline QString serverDecode(const QByteArray &string) const { return decodeServerString(string); }
+
+ //! Decode a string using a channel-specific encoding if one is set (and use the standard encoding else).
+ QString channelDecode(const QString &channelName, const QByteArray &string) const;
+
+ //! Decode a string using an IrcUser-specific encoding, if one exists (using the standaed encoding else).
+ QString userDecode(const QString &userNick, const QByteArray &string) const;
+
+ //! Encode a string using the server (network) encoding.
+ inline QByteArray serverEncode(const QString &string) const { return encodeServerString(string); }
+
+ //! Encode a string using the channel-specific encoding, if set, and use the standard encoding else.
+ QByteArray channelEncode(const QString &channelName, const QString &string) const;
+
+ //! Encode a string using the user-specific encoding, if set, and use the standard encoding else.
+ QByteArray userEncode(const QString &userNick, const QString &string) const;
+
+ inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
+
+ inline QByteArray readChannelCipherKey(const QString &channel) const { return _cipherKeys.value(channel.toLower()); }
+ inline void storeChannelCipherKey(const QString &channel, const QByteArray &key) { _cipherKeys[channel.toLower()] = key; }
+
+ inline bool isAutoWhoInProgress(const QString &channel) const { return _autoWhoPending.value(channel.toLower(), 0); }
+
+ inline UserId userId() const { return _coreSession->user(); }
+
+ inline QAbstractSocket::SocketState socketState() const { return socket.state(); }
+ inline bool socketConnected() const { return socket.state() == QAbstractSocket::ConnectedState; }
+ inline QHostAddress localAddress() const { return socket.localAddress(); }
+ inline QHostAddress peerAddress() const { return socket.peerAddress(); }
+ inline quint16 localPort() const { return socket.localPort(); }
+ inline quint16 peerPort() const { return socket.peerPort(); }
+
+ QList<QList<QByteArray>> splitMessage(const QString &cmd, const QString &message, std::function<QList<QByteArray>(QString &)> cmdGenerator);
+
+ // IRCv3 capability negotiation
+
+ /**
+ * Checks if a given capability is enabled.
+ *
+ * @param[in] capability Name of capability
+ * @returns True if enabled, otherwise false
+ */
+ inline bool capEnabled(const QString &capability) const { return _capsSupported.contains(capability); }
+
+ /**
+ * Checks if capability negotiation is currently ongoing.
+ *
+ * @returns True if in progress, otherwise false
+ */
+ inline bool capNegotiationInProgress() const { return !_capsQueued.empty(); }
+
+ /**
+ * Gets the value of an enabled or pending capability, e.g. sasl=plain.
+ *
+ * @param[in] capability Name of capability
+ * @returns Value of capability if one was specified, otherwise empty string
+ */
+ QString capValue(const QString &capability) const;
+
+ /**
+ * Gets the next capability to request, removing it from the queue.
+ *
+ * @returns Name of capability to request
+ */
+ QString takeQueuedCap();
+
+ // Specific capabilities for easy reference
+
+ /**
+ * Gets the status of the sasl authentication capability.
+ *
+ * http://ircv3.net/specs/extensions/sasl-3.2.html
+ *
+ * @returns True if SASL authentication is enabled, otherwise false
+ */
+ inline bool useCapSASL() const { return capEnabled("sasl"); }
+
+ /**
+ * Gets the status of the away-notify capability.
+ *
+ * http://ircv3.net/specs/extensions/away-notify-3.1.html
+ *
+ * @returns True if away-notify is enabled, otherwise false
+ */
+ inline bool useCapAwayNotify() const { return capEnabled("away-notify"); }
+
+ /**
+ * Gets the status of the account-notify capability.
+ *
+ * http://ircv3.net/specs/extensions/account-notify-3.1.html
+ *
+ * @returns True if account-notify is enabled, otherwise false
+ */
+ inline bool useCapAccountNotify() const { return capEnabled("account-notify"); }
+
+ /**
+ * Gets the status of the extended-join capability.
+ *
+ * http://ircv3.net/specs/extensions/extended-join-3.1.html
+ *
+ * @returns True if extended-join is enabled, otherwise false
+ */
+ inline bool useCapExtendedJoin() const { return capEnabled("extended-join"); }
+
+ /**
+ * Gets the status of the userhost-in-names capability.
+ *
+ * http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
+ *
+ * @returns True if userhost-in-names is enabled, otherwise false
+ */
+ inline bool useCapUserhostInNames() const { return capEnabled("userhost-in-names"); }
+
+ /**
+ * Gets the status of the multi-prefix capability.
+ *
+ * http://ircv3.net/specs/extensions/multi-prefix-3.1.html
+ *
+ * @returns True if multi-prefix is enabled, otherwise false
+ */
+ inline bool useCapMultiPrefix() const { return capEnabled("multi-prefix"); }