allow customizing twitch server parameters through environment variables (#1449)

This commit is contained in:
pajlada 2019-12-21 10:11:23 +01:00 committed by GitHub
parent 142e967c58
commit d5001b97f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 4 deletions

View file

@ -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/` Default value: `https://braize.pajlada.com/chatterino/twitchemotes/set/%1/`
Arguments: Arguments:
- `%1` = Emote set ID - `%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`

View file

@ -1,5 +1,7 @@
#include "common/Env.hpp" #include "common/Env.hpp"
#include <QVariant>
namespace chatterino { namespace chatterino {
namespace { namespace {
@ -15,6 +17,33 @@ namespace {
return defaultValue; 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 } // namespace
Env::Env() Env::Env()
@ -28,6 +57,10 @@ Env::Env()
, twitchEmoteSetResolverUrl(readStringEnv( , twitchEmoteSetResolverUrl(readStringEnv(
"CHATTERINO2_TWITCH_EMOTE_SET_RESOLVER_URL", "CHATTERINO2_TWITCH_EMOTE_SET_RESOLVER_URL",
"https://braize.pajlada.com/chatterino/twitchemotes/set/%1/")) "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))
{ {
} }

View file

@ -14,6 +14,9 @@ public:
const QString recentMessagesApiUrl; const QString recentMessagesApiUrl;
const QString linkResolverUrl; const QString linkResolverUrl;
const QString twitchEmoteSetResolverUrl; const QString twitchEmoteSetResolverUrl;
const QString twitchServerHost;
const uint16_t twitchServerPort;
const bool twitchServerSecure;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -5,6 +5,7 @@
#include "Application.hpp" #include "Application.hpp"
#include "common/Common.hpp" #include "common/Common.hpp"
#include "common/Env.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/highlights/HighlightController.hpp" #include "controllers/highlights/HighlightController.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
@ -86,13 +87,12 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection,
connection->setPassword(oauthToken); connection->setPassword(oauthToken);
} }
connection->setSecure(true);
// https://dev.twitch.tv/docs/irc/guide/#connecting-to-twitch-irc // https://dev.twitch.tv/docs/irc/guide/#connecting-to-twitch-irc
// SSL disabled: irc://irc.chat.twitch.tv:6667 (or port 80) // SSL disabled: irc://irc.chat.twitch.tv:6667 (or port 80)
// SSL enabled: irc://irc.chat.twitch.tv:6697 (or port 443) // SSL enabled: irc://irc.chat.twitch.tv:6697 (or port 443)
connection->setHost("irc.chat.twitch.tv"); connection->setHost(Env::get().twitchServerHost);
connection->setPort(443); connection->setPort(Env::get().twitchServerPort);
connection->setSecure(Env::get().twitchServerSecure);
this->open(type); this->open(type);
} }