diff --git a/docs/ENV.md b/docs/ENV.md index 727503ff4..f95c74286 100644 --- a/docs/ENV.md +++ b/docs/ENV.md @@ -18,3 +18,17 @@ Used to change the URL that Chatterino2 uses when trying to get emote set inform Default value: `https://braize.pajlada.com/chatterino/twitchemotes/set/%1/` Arguments: - `%1` = Emote set ID + +### CHATTERINO2_TWITCH_SERVER_HOST +String value used to change what Twitch chat server host to connect to. +Default value: `irc.chat.twitch.tv` + +### CHATTERINO2_TWITCH_SERVER_PORT +Number value used to change what port to use when connecting to Twitch chat servers. +Currently known valid ports for secure usage: 6697, 443. +Currently known valid ports for non-secure usage (CHATTERINO2_TWITCH_SERVER_SECURE set to false): 6667, 80. +Default value: `443` + +### CHATTERINO2_TWITCH_SERVER_SECURE +Bool value used to tell Chatterino whether to try to connect securely (secure irc) to the Twitch chat server. +Default value: `true` diff --git a/src/common/Env.cpp b/src/common/Env.cpp index ff711ec47..908e25f4b 100644 --- a/src/common/Env.cpp +++ b/src/common/Env.cpp @@ -1,5 +1,7 @@ #include "common/Env.hpp" +#include + namespace chatterino { namespace { @@ -15,6 +17,33 @@ namespace { return defaultValue; } + uint16_t readPortEnv(const char *envName, uint16_t defaultValue) + { + auto envString = std::getenv(envName); + if (envString != nullptr) + { + bool ok; + auto val = QString(envString).toUShort(&ok); + if (ok) + { + return val; + } + } + + return defaultValue; + } + + uint16_t readBoolEnv(const char *envName, bool defaultValue) + { + auto envString = std::getenv(envName); + if (envString != nullptr) + { + return QVariant(QString(envString)).toBool(); + } + + return defaultValue; + } + } // namespace Env::Env() @@ -28,6 +57,10 @@ Env::Env() , twitchEmoteSetResolverUrl(readStringEnv( "CHATTERINO2_TWITCH_EMOTE_SET_RESOLVER_URL", "https://braize.pajlada.com/chatterino/twitchemotes/set/%1/")) + , twitchServerHost( + readStringEnv("CHATTERINO2_TWITCH_SERVER_HOST", "irc.chat.twitch.tv")) + , twitchServerPort(readPortEnv("CHATTERINO2_TWITCH_SERVER_PORT", 6697)) + , twitchServerSecure(readBoolEnv("CHATTERINO2_TWITCH_SERVER_SECURE", true)) { } diff --git a/src/common/Env.hpp b/src/common/Env.hpp index 2dc7fa1ba..6dc8077a9 100644 --- a/src/common/Env.hpp +++ b/src/common/Env.hpp @@ -14,6 +14,9 @@ public: const QString recentMessagesApiUrl; const QString linkResolverUrl; const QString twitchEmoteSetResolverUrl; + const QString twitchServerHost; + const uint16_t twitchServerPort; + const bool twitchServerSecure; }; } // namespace chatterino diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index c651a8190..45f50cecd 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -5,6 +5,7 @@ #include "Application.hpp" #include "common/Common.hpp" +#include "common/Env.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/highlights/HighlightController.hpp" #include "messages/Message.hpp" @@ -86,13 +87,12 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection, connection->setPassword(oauthToken); } - connection->setSecure(true); - // https://dev.twitch.tv/docs/irc/guide/#connecting-to-twitch-irc // SSL disabled: irc://irc.chat.twitch.tv:6667 (or port 80) // SSL enabled: irc://irc.chat.twitch.tv:6697 (or port 443) - connection->setHost("irc.chat.twitch.tv"); - connection->setPort(443); + connection->setHost(Env::get().twitchServerHost); + connection->setPort(Env::get().twitchServerPort); + connection->setSecure(Env::get().twitchServerSecure); this->open(type); }