1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
23 #include "common-export.h"
26 #include <QStringList>
28 #include <QNetworkProxy>
30 #include <QVariantMap>
38 #include "syncableobject.h"
40 #include "signalproxy.h"
42 #include "ircchannel.h"
50 // TODO: ConnectionInfo to propagate and sync the current state of NetworkConnection, encodings etcpp
52 class COMMON_EXPORT Network : public SyncableObject
57 Q_ENUMS(ConnectionState)
59 Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName)
60 Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer)
61 Q_PROPERTY(QString myNick READ myNick WRITE setMyNick)
62 Q_PROPERTY(int latency READ latency WRITE setLatency)
63 Q_PROPERTY(QByteArray codecForServer READ codecForServer WRITE setCodecForServer)
64 Q_PROPERTY(QByteArray codecForEncoding READ codecForEncoding WRITE setCodecForEncoding)
65 Q_PROPERTY(QByteArray codecForDecoding READ codecForDecoding WRITE setCodecForDecoding)
66 Q_PROPERTY(IdentityId identityId READ identity WRITE setIdentity)
67 Q_PROPERTY(bool isConnected READ isConnected WRITE setConnected)
68 //Q_PROPERTY(Network::ConnectionState connectionState READ connectionState WRITE setConnectionState)
69 Q_PROPERTY(int connectionState READ connectionState WRITE setConnectionState)
70 Q_PROPERTY(bool useRandomServer READ useRandomServer WRITE setUseRandomServer)
71 Q_PROPERTY(QStringList perform READ perform WRITE setPerform)
72 Q_PROPERTY(bool useAutoIdentify READ useAutoIdentify WRITE setUseAutoIdentify)
73 Q_PROPERTY(QString autoIdentifyService READ autoIdentifyService WRITE setAutoIdentifyService)
74 Q_PROPERTY(QString autoIdentifyPassword READ autoIdentifyPassword WRITE setAutoIdentifyPassword)
75 Q_PROPERTY(bool useSasl READ useSasl WRITE setUseSasl)
76 Q_PROPERTY(QString saslAccount READ saslAccount WRITE setSaslAccount)
77 Q_PROPERTY(QString saslPassword READ saslPassword WRITE setSaslPassword)
78 Q_PROPERTY(bool useAutoReconnect READ useAutoReconnect WRITE setUseAutoReconnect)
79 Q_PROPERTY(quint32 autoReconnectInterval READ autoReconnectInterval WRITE setAutoReconnectInterval)
80 Q_PROPERTY(quint16 autoReconnectRetries READ autoReconnectRetries WRITE setAutoReconnectRetries)
81 Q_PROPERTY(bool unlimitedReconnectRetries READ unlimitedReconnectRetries WRITE setUnlimitedReconnectRetries)
82 Q_PROPERTY(bool rejoinChannels READ rejoinChannels WRITE setRejoinChannels)
83 // Custom rate limiting
84 Q_PROPERTY(bool useCustomMessageRate READ useCustomMessageRate WRITE setUseCustomMessageRate)
85 Q_PROPERTY(quint32 msgRateBurstSize READ messageRateBurstSize WRITE setMessageRateBurstSize)
86 Q_PROPERTY(quint32 msgRateMessageDelay READ messageRateDelay WRITE setMessageRateDelay)
87 Q_PROPERTY(bool unlimitedMessageRate READ unlimitedMessageRate WRITE setUnlimitedMessageRate)
90 enum ConnectionState {
100 // http://www.irc.org/tech_docs/005.html
101 // http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt
102 enum ChannelModeType {
103 NOT_A_CHANMODE = 0x00,
110 // Default port assignments according to what many IRC networks have settled on.
111 // Technically not a standard, but it's fairly widespread.
112 // See https://freenode.net/news/port-6697-irc-via-tlsssl
114 PORT_PLAINTEXT = 6667, /// Default port for unencrypted connections
115 PORT_SSL = 6697 /// Default port for encrypted connections
123 bool sslVerify; /// If true, validate SSL certificates
133 // sslVerify only applies when useSsl is true. sslVerify should be enabled by default,
134 // so enabling useSsl offers a more secure default.
135 Server() : port(6667), useSsl(false), sslVerify(true), sslVersion(0), useProxy(false),
136 proxyType(QNetworkProxy::Socks5Proxy), proxyHost("localhost"), proxyPort(8080) {}
138 Server(QString host, uint port, QString password, bool useSsl,
140 : host(std::move(host)), port(port), password(std::move(password)), useSsl(useSsl), sslVerify(sslVerify),
141 sslVersion(0), useProxy(false), proxyType(QNetworkProxy::Socks5Proxy),
142 proxyHost("localhost"), proxyPort(8080) {}
144 bool operator==(const Server &other) const;
145 bool operator!=(const Server &other) const;
147 using ServerList = QList<Server>;
149 Network(const NetworkId &networkid, QObject *parent = nullptr);
152 inline NetworkId networkId() const { return _networkId; }
154 inline SignalProxy *proxy() const { return _proxy; }
155 inline void setProxy(SignalProxy *proxy) { _proxy = proxy; }
157 inline bool isMyNick(const QString &nick) const { return (myNick().toLower() == nick.toLower()); }
158 inline bool isMe(IrcUser *ircuser) const { return (ircuser->nick().toLower() == myNick().toLower()); }
160 bool isChannelName(const QString &channelname) const;
163 * Checks if the target counts as a STATUSMSG
165 * Status messages are prefixed with one or more characters from the server-provided STATUSMSG
166 * if available, otherwise "@" and "+" are assumed. Generally, status messages sent to a
167 * channel are only visible to those with the same or higher permissions, e.g. voiced.
169 * @param[in] target Name of destination, e.g. a channel or query
170 * @returns True if a STATUSMSG, otherwise false
172 bool isStatusMsg(const QString &target) const;
174 inline bool isConnected() const { return _connected; }
175 //Network::ConnectionState connectionState() const;
176 inline int connectionState() const { return _connectionState; }
180 * Translates a user’s prefix to the channelmode associated with it.
181 * @param prefix Prefix to be translated.
183 QString prefixToMode(const QString &prefix) const;
184 inline QString prefixToMode(const QCharRef &prefix) const { return prefixToMode(QString(prefix)); }
185 inline QString prefixesToModes(const QString &prefix) const {
187 for (QChar c : prefix) {
188 modes += prefixToMode(c);
196 * Translates a user’s prefix to the channelmode associated with it.
197 * @param prefix Prefix to be translated.
199 QString modeToPrefix(const QString &mode) const;
200 inline QString modeToPrefix(const QCharRef &mode) const { return modeToPrefix(QString(mode)); }
201 inline QString modesToPrefixes(const QString &mode) const {
203 for (QChar c : mode) {
204 prefixes += modeToPrefix(c);
211 * Sorts the user channelmodes according to priority set by PREFIX
213 * Given a list of channel modes, sorts according to the order of PREFIX, putting the highest
214 * modes first. Any unknown modes are moved to the end in no given order.
216 * If prefix modes cannot be determined from the network, no changes will be made.
218 * @param modes User channelmodes
219 * @return Priority-sorted user channelmodes
221 QString sortPrefixModes(const QString &modes) const;
225 * Sorts the list of users' channelmodes according to priority set by PREFIX
227 * Maintains order of the modes list.
229 * @seealso Network::sortPrefixModes()
231 * @param modesList List of users' channel modes
232 * @return Priority-sorted list of users' channel modes
234 inline QStringList sortPrefixModes(const QStringList &modesList) const {
235 QStringList sortedModesList;
236 // Sort each individual mode string, appending back
237 // Must maintain the order received!
238 for (QString modes : modesList) {
239 sortedModesList << sortPrefixModes(modes);
241 return sortedModesList;
245 ChannelModeType channelModeType(const QString &mode);
246 inline ChannelModeType channelModeType(const QCharRef &mode) { return channelModeType(QString(mode)); }
248 inline const QString &networkName() const { return _networkName; }
249 inline const QString ¤tServer() const { return _currentServer; }
250 inline const QString &myNick() const { return _myNick; }
251 inline int latency() const { return _latency; }
252 inline IrcUser *me() const { return ircUser(myNick()); }
253 inline IdentityId identity() const { return _identity; }
254 QStringList nicks() const;
255 inline QStringList channels() const { return _ircChannels.keys(); }
257 * Gets the list of available capabilities.
259 * @returns QStringList of available capabilities
261 inline const QStringList caps() const { return QStringList(_caps.keys()); }
263 * Gets the list of enabled (acknowledged) capabilities.
265 * @returns QStringList of enabled (acknowledged) capabilities
267 inline const QStringList capsEnabled() const { return _capsEnabled; }
268 inline const ServerList &serverList() const { return _serverList; }
269 inline bool useRandomServer() const { return _useRandomServer; }
270 inline const QStringList &perform() const { return _perform; }
271 inline bool useAutoIdentify() const { return _useAutoIdentify; }
272 inline const QString &autoIdentifyService() const { return _autoIdentifyService; }
273 inline const QString &autoIdentifyPassword() const { return _autoIdentifyPassword; }
274 inline bool useSasl() const { return _useSasl; }
275 inline const QString &saslAccount() const { return _saslAccount; }
276 inline const QString &saslPassword() const { return _saslPassword; }
277 inline bool useAutoReconnect() const { return _useAutoReconnect; }
278 inline quint32 autoReconnectInterval() const { return _autoReconnectInterval; }
279 inline quint16 autoReconnectRetries() const { return _autoReconnectRetries; }
280 inline bool unlimitedReconnectRetries() const { return _unlimitedReconnectRetries; }
281 inline bool rejoinChannels() const { return _rejoinChannels; }
283 // Custom rate limiting
286 * Gets whether or not custom rate limiting is used
288 * @return True if custom rate limiting is enabled, otherwise false.
290 inline bool useCustomMessageRate() const { return _useCustomMessageRate; }
293 * Gets maximum number of messages to send without any delays
297 * Maximum number of messages to send without any delays. A value of 1 disables message
301 inline quint32 messageRateBurstSize() const { return _messageRateBurstSize; }
304 * Gets the delay between messages after the maximum number of undelayed messages have been sent
308 * Delay in milliseconds between messages after the maximum number of undelayed messages have
312 inline quint32 messageRateDelay() const { return _messageRateDelay; }
315 * Gets whether or not all rate limiting is disabled, e.g. for IRC bridges
317 * @return If true, disable rate limiting, otherwise apply configured limits.
319 inline bool unlimitedMessageRate() const { return _unlimitedMessageRate; }
321 NetworkInfo networkInfo() const;
322 void setNetworkInfo(const NetworkInfo &);
324 QString prefixes() const;
325 QString prefixModes() const;
326 void determinePrefixes() const;
328 bool supports(const QString ¶m) const { return _supports.contains(param); }
329 QString support(const QString ¶m) const;
332 * Checks if a given capability is advertised by the server.
334 * These results aren't valid if the network is disconnected or capability negotiation hasn't
335 * happened, and some servers might not correctly advertise capabilities. Don't treat this as
338 * @param[in] capability Name of capability
339 * @returns True if connected and advertised by the server, otherwise false
341 inline bool capAvailable(const QString &capability) const { return _caps.contains(capability.toLower()); }
342 // IRCv3 specs all use lowercase capability names
345 * Checks if a given capability is acknowledged and active.
347 * @param[in] capability Name of capability
348 * @returns True if acknowledged (active), otherwise false
350 inline bool capEnabled(const QString &capability) const { return _capsEnabled.contains(capability.toLower()); }
351 // IRCv3 specs all use lowercase capability names
354 * Gets the value of an available capability, e.g. for SASL, "EXTERNAL,PLAIN".
356 * @param[in] capability Name of capability
357 * @returns Value of capability if one was specified, otherwise empty string
359 QString capValue(const QString &capability) const { return _caps.value(capability.toLower()); }
360 // IRCv3 specs all use lowercase capability names
361 // QHash returns the default constructed value if not found, in this case, empty string
362 // See: https://doc.qt.io/qt-4.8/qhash.html#value
365 * Check if the given authentication mechanism is likely to be supported.
367 * This depends on the server advertising SASL support and either declaring available mechanisms
368 * (SASL 3.2), or just indicating something is supported (SASL 3.1).
370 * @param[in] saslMechanism Desired SASL mechanism
371 * @return True if mechanism supported or unknown, otherwise false
373 bool saslMaybeSupports(const QString &saslMechanism) const;
375 IrcUser *newIrcUser(const QString &hostmask, const QVariantMap &initData = QVariantMap());
376 inline IrcUser *newIrcUser(const QByteArray &hostmask) { return newIrcUser(decodeServerString(hostmask)); }
377 IrcUser *ircUser(QString nickname) const;
378 inline IrcUser *ircUser(const QByteArray &nickname) const { return ircUser(decodeServerString(nickname)); }
379 inline QList<IrcUser *> ircUsers() const { return _ircUsers.values(); }
380 inline quint32 ircUserCount() const { return _ircUsers.count(); }
382 IrcChannel *newIrcChannel(const QString &channelname, const QVariantMap &initData = QVariantMap());
383 inline IrcChannel *newIrcChannel(const QByteArray &channelname) { return newIrcChannel(decodeServerString(channelname)); }
384 IrcChannel *ircChannel(QString channelname) const;
385 inline IrcChannel *ircChannel(const QByteArray &channelname) const { return ircChannel(decodeServerString(channelname)); }
386 inline QList<IrcChannel *> ircChannels() const { return _ircChannels.values(); }
387 inline quint32 ircChannelCount() const { return _ircChannels.count(); }
389 QByteArray codecForServer() const;
390 QByteArray codecForEncoding() const;
391 QByteArray codecForDecoding() const;
392 void setCodecForServer(QTextCodec *codec);
393 void setCodecForEncoding(QTextCodec *codec);
394 void setCodecForDecoding(QTextCodec *codec);
396 QString decodeString(const QByteArray &text) const;
397 QByteArray encodeString(const QString &string) const;
398 QString decodeServerString(const QByteArray &text) const;
399 QByteArray encodeServerString(const QString &string) const;
401 static QByteArray defaultCodecForServer();
402 static QByteArray defaultCodecForEncoding();
403 static QByteArray defaultCodecForDecoding();
404 static void setDefaultCodecForServer(const QByteArray &name);
405 static void setDefaultCodecForEncoding(const QByteArray &name);
406 static void setDefaultCodecForDecoding(const QByteArray &name);
408 inline bool autoAwayActive() const { return _autoAwayActive; }
409 inline void setAutoAwayActive(bool active) { _autoAwayActive = active; }
412 void setNetworkName(const QString &networkName);
413 void setCurrentServer(const QString ¤tServer);
414 void setConnected(bool isConnected);
415 void setConnectionState(int state);
416 virtual void setMyNick(const QString &mynick);
417 void setLatency(int latency);
418 void setIdentity(IdentityId);
420 void setServerList(const QVariantList &serverList);
421 void setUseRandomServer(bool);
422 void setPerform(const QStringList &);
423 void setUseAutoIdentify(bool);
424 void setAutoIdentifyService(const QString &);
425 void setAutoIdentifyPassword(const QString &);
426 void setUseSasl(bool);
427 void setSaslAccount(const QString &);
428 void setSaslPassword(const QString &);
429 virtual void setUseAutoReconnect(bool);
430 virtual void setAutoReconnectInterval(quint32);
431 virtual void setAutoReconnectRetries(quint16);
432 void setUnlimitedReconnectRetries(bool);
433 void setRejoinChannels(bool);
435 // Custom rate limiting
438 * Sets whether or not custom rate limiting is used.
440 * Setting limits too low may get you disconnected from the server!
442 * @param[in] useCustomRate If true, use custom rate limits, otherwise use Quassel defaults.
444 void setUseCustomMessageRate(bool useCustomRate);
447 * Sets maximum number of messages to send without any delays
449 * @param[in] burstSize
451 * Maximum number of messages to send without any delays. A value of 1 disables message
452 * bursting. Cannot be less than 1 as sending 0 messages at a time accomplishes nothing.
455 void setMessageRateBurstSize(quint32 burstSize);
458 * Sets the delay between messages after the maximum number of undelayed messages have been sent
460 * @param[in] messageDelay
462 * Delay in milliseconds between messages after the maximum number of undelayed messages have
466 void setMessageRateDelay(quint32 messageDelay);
469 * Sets whether or not all rate limiting is disabled, e.g. for IRC bridges
471 * Don't use with most normal networks.
473 * @param[in] unlimitedRate If true, disable rate limiting, otherwise apply configured limits.
475 void setUnlimitedMessageRate(bool unlimitedRate);
477 void setCodecForServer(const QByteArray &codecName);
478 void setCodecForEncoding(const QByteArray &codecName);
479 void setCodecForDecoding(const QByteArray &codecName);
481 void addSupport(const QString ¶m, const QString &value = QString());
482 void removeSupport(const QString ¶m);
484 // IRCv3 capability negotiation (can be connected to signals)
487 * Add an available capability, optionally providing a value.
489 * This may happen during first connect, or at any time later if a new capability becomes
490 * available (e.g. SASL service starting).
492 * @param[in] capability Name of the capability
495 * Optional value of the capability, e.g. sasl=plain.
498 void addCap(const QString &capability, const QString &value = QString());
501 * Marks a capability as acknowledged (enabled by the IRC server).
503 * @param[in] capability Name of the capability
505 void acknowledgeCap(const QString &capability);
508 * Removes a capability from the list of available capabilities.
510 * This may happen during first connect, or at any time later if an existing capability becomes
511 * unavailable (e.g. SASL service stopping). This also removes the capability from the list
512 * of acknowledged capabilities.
514 * @param[in] capability Name of the capability
516 void removeCap(const QString &capability);
519 * Clears all capabilities from the list of available capabilities.
521 * This also removes the capability from the list of acknowledged capabilities.
525 inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
526 inline void addIrcChannel(const QString &channel) { newIrcChannel(channel); }
529 QVariantMap initSupports() const;
531 * Get the initial list of available capabilities.
533 * @return QVariantMap of <QString, QString> indicating available capabilities and values
535 QVariantMap initCaps() const;
537 * Get the initial list of enabled (acknowledged) capabilities.
539 * @return QVariantList of QString indicating enabled (acknowledged) capabilities and values
541 QVariantList initCapsEnabled() const { return toVariantList(capsEnabled()); }
542 inline QVariantList initServerList() const { return toVariantList(serverList()); }
543 virtual QVariantMap initIrcUsersAndChannels() const;
546 void initSetSupports(const QVariantMap &supports);
548 * Initialize the list of available capabilities.
550 * @param[in] caps QVariantMap of <QString, QString> indicating available capabilities and values
552 void initSetCaps(const QVariantMap &caps);
554 * Initialize the list of enabled (acknowledged) capabilities.
556 * @param[in] caps QVariantList of QString indicating enabled (acknowledged) capabilities and values
558 inline void initSetCapsEnabled(const QVariantList &capsEnabled) { _capsEnabled = fromVariantList<QString>(capsEnabled); }
559 inline void initSetServerList(const QVariantList &serverList) { _serverList = fromVariantList<Server>(serverList); }
560 virtual void initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels);
563 * Update IrcUser hostmask and username from mask, creating an IrcUser if one does not exist.
565 * @param[in] mask Full nick!user@hostmask string
566 * @return IrcUser of the matching nick if exists, otherwise a new IrcUser
568 IrcUser *updateNickFromMask(const QString &mask);
570 // these slots are to keep the hashlists of all users and the
571 // channel lists up to date
572 void ircUserNickChanged(QString newnick);
574 virtual inline void requestConnect() const { REQUEST(NO_ARG) }
575 virtual inline void requestDisconnect() const { REQUEST(NO_ARG) }
576 virtual inline void requestSetNetworkInfo(const NetworkInfo &info) { REQUEST(ARG(info)) }
578 void emitConnectionError(const QString &);
581 virtual void removeIrcUser(IrcUser *ircuser);
582 virtual void removeIrcChannel(IrcChannel *ircChannel);
583 virtual void removeChansAndUsers();
586 void aboutToBeDestroyed();
587 void networkNameSet(const QString &networkName);
588 void currentServerSet(const QString ¤tServer);
589 void connectedSet(bool isConnected);
590 void connectionStateSet(Network::ConnectionState);
591 // void connectionStateSet(int);
592 void connectionError(const QString &errorMsg);
593 void myNickSet(const QString &mynick);
594 // void latencySet(int latency);
595 void identitySet(IdentityId);
597 void configChanged();
599 // void serverListSet(QVariantList serverList);
600 // void useRandomServerSet(bool);
601 // void performSet(const QStringList &);
602 // void useAutoIdentifySet(bool);
603 // void autoIdentifyServiceSet(const QString &);
604 // void autoIdentifyPasswordSet(const QString &);
605 // void useAutoReconnectSet(bool);
606 // void autoReconnectIntervalSet(quint32);
607 // void autoReconnectRetriesSet(quint16);
608 // void unlimitedReconnectRetriesSet(bool);
609 // void rejoinChannelsSet(bool);
611 // Custom rate limiting (can drive other slots)
614 * Signals enabling or disabling custom rate limiting
616 * @see Network::useCustomMessageRate()
618 * @param[out] useCustomRate
620 void useCustomMessageRateSet(const bool useCustomRate);
623 * Signals a change in maximum number of messages to send without any delays
625 * @see Network::messageRateBurstSize()
627 * @param[out] burstSize
629 void messageRateBurstSizeSet(const quint32 burstSize);
632 * Signals a change in delay between messages after the max. undelayed messages have been sent
634 * @see Network::messageRateDelay()
636 * @param[out] messageDelay
638 void messageRateDelaySet(const quint32 messageDelay);
641 * Signals enabling or disabling all rate limiting
643 * @see Network::unlimitedMessageRate()
645 * @param[out] unlimitedRate
647 void unlimitedMessageRateSet(const bool unlimitedRate);
649 // void codecForServerSet(const QByteArray &codecName);
650 // void codecForEncodingSet(const QByteArray &codecName);
651 // void codecForDecodingSet(const QByteArray &codecName);
653 // void supportAdded(const QString ¶m, const QString &value);
654 // void supportRemoved(const QString ¶m);
656 // IRCv3 capability negotiation (can drive other slots)
658 * Indicates a capability is now available, with optional value in Network::capValue().
660 * @see Network::addCap()
662 * @param[in] capability Name of the capability
664 void capAdded (const QString &capability);
667 * Indicates a capability was acknowledged (enabled by the IRC server).
669 * @see Network::acknowledgeCap()
671 * @param[in] capability Name of the capability
673 void capAcknowledged(const QString &capability);
676 * Indicates a capability was removed from the list of available capabilities.
678 * @see Network::removeCap()
680 * @param[in] capability Name of the capability
682 void capRemoved(const QString &capability);
684 // void ircUserAdded(const QString &hostmask);
685 void ircUserAdded(IrcUser *);
686 // void ircChannelAdded(const QString &channelname);
687 void ircChannelAdded(IrcChannel *);
689 // void connectRequested() const;
690 // void disconnectRequested() const;
691 // void setNetworkInfoRequested(const NetworkInfo &) const;
694 inline virtual IrcChannel *ircChannelFactory(const QString &channelname) { return new IrcChannel(channelname, this); }
695 inline virtual IrcUser *ircUserFactory(const QString &hostmask) { return new IrcUser(hostmask, this); }
698 QPointer<SignalProxy> _proxy;
700 NetworkId _networkId;
701 IdentityId _identity;
705 QString _networkName;
706 QString _currentServer;
708 ConnectionState _connectionState;
710 mutable QString _prefixes;
711 mutable QString _prefixModes;
713 QHash<QString, IrcUser *> _ircUsers; // stores all known nicks for the server
714 QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
715 QHash<QString, QString> _supports; // stores results from RPL_ISUPPORT
717 QHash<QString, QString> _caps; /// Capabilities supported by the IRC server
718 // By synchronizing the supported capabilities, the client could suggest certain behaviors, e.g.
719 // in the Network settings dialog, recommending SASL instead of using NickServ, or warning if
720 // SASL EXTERNAL isn't available.
721 QStringList _capsEnabled; /// Enabled capabilities that received 'CAP ACK'
722 // _capsEnabled uses the same values from the <name>=<value> pairs stored in _caps
724 ServerList _serverList;
725 bool _useRandomServer;
726 QStringList _perform;
728 bool _useAutoIdentify;
729 QString _autoIdentifyService;
730 QString _autoIdentifyPassword;
733 QString _saslAccount;
734 QString _saslPassword;
736 bool _useAutoReconnect;
737 quint32 _autoReconnectInterval;
738 quint16 _autoReconnectRetries;
739 bool _unlimitedReconnectRetries;
740 bool _rejoinChannels;
742 // Custom rate limiting
743 bool _useCustomMessageRate; /// If true, use custom rate limits, otherwise use defaults
744 quint32 _messageRateBurstSize; /// Maximum number of messages to send without any delays
745 quint32 _messageRateDelay; /// Delay in ms. for messages when max. burst messages sent
746 bool _unlimitedMessageRate; /// If true, disable rate limiting, otherwise apply limits
748 QTextCodec *_codecForServer;
749 QTextCodec *_codecForEncoding;
750 QTextCodec *_codecForDecoding;
752 static QTextCodec *_defaultCodecForServer;
753 static QTextCodec *_defaultCodecForEncoding;
754 static QTextCodec *_defaultCodecForDecoding;
756 bool _autoAwayActive; // when this is active handle305 and handle306 don't trigger any output
758 friend class IrcUser;
759 friend class IrcChannel;
763 //! Stores all editable information about a network (as opposed to runtime state).
764 struct COMMON_EXPORT NetworkInfo
768 Network::ServerList serverList;
771 QString autoIdentifyService{"NickServ"};
772 QString autoIdentifyPassword;
775 QString saslPassword;
777 QByteArray codecForServer;
778 QByteArray codecForEncoding;
779 QByteArray codecForDecoding;
781 NetworkId networkId {0};
782 IdentityId identity {1};
784 quint32 messageRateBurstSize {5}; ///< Maximum number of messages to send without any delays
785 quint32 messageRateDelay {2200}; ///< Delay in ms. for messages when max. burst messages sent
787 quint32 autoReconnectInterval {60};
788 quint16 autoReconnectRetries {20};
790 bool rejoinChannels {true};
791 bool useRandomServer {false};
792 bool useAutoIdentify {false};
793 bool useSasl {false};
794 bool useAutoReconnect {true};
795 bool unlimitedReconnectRetries {false};
796 bool useCustomMessageRate {false}; ///< If true, use custom rate limits, otherwise use defaults
797 bool unlimitedMessageRate {false}; ///< If true, disable rate limiting, otherwise apply limits
800 bool operator==(const NetworkInfo &other) const;
801 bool operator!=(const NetworkInfo &other) const;
804 COMMON_EXPORT QDataStream &operator<<(QDataStream &out, const NetworkInfo &info);
805 COMMON_EXPORT QDataStream &operator>>(QDataStream &in, NetworkInfo &info);
806 COMMON_EXPORT QDebug operator<<(QDebug dbg, const NetworkInfo &i);
807 Q_DECLARE_METATYPE(NetworkInfo)
809 COMMON_EXPORT QDataStream &operator<<(QDataStream &out, const Network::Server &server);
810 COMMON_EXPORT QDataStream &operator>>(QDataStream &in, Network::Server &server);
811 COMMON_EXPORT QDebug operator<<(QDebug dbg, const Network::Server &server);
812 Q_DECLARE_METATYPE(Network::Server)