forked from OpenGamers/abaddon
allow overriding of gateway + api url
This commit is contained in:
parent
c3b2bbd647
commit
5866836d5d
@ -189,6 +189,8 @@ For example, memory_db would be set by adding `memory_db = true` under the line
|
||||
* css (string) - path to the main CSS file
|
||||
* animations (true or false, default true) - use animated images where available (e.g. server icons, emojis, avatars). false means static images will be used
|
||||
* owner_crown (true or false, default true) - show a crown next to the owner
|
||||
* gateway (string) - override url for Discord gateway. must be json format and use zlib stream compression
|
||||
* api_base (string) - override base url for Discord API
|
||||
|
||||
#### misc
|
||||
* linkcolor (string) - color to use for links in messages
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "discord.hpp"
|
||||
#include <cassert>
|
||||
#include "../util.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
|
||||
DiscordClient::DiscordClient(bool mem_store)
|
||||
: m_http(DiscordAPI)
|
||||
, m_decompress_buf(InflateChunkSize)
|
||||
: m_decompress_buf(InflateChunkSize)
|
||||
, m_store(mem_store) {
|
||||
m_msg_dispatch.connect(sigc::mem_fun(*this, &DiscordClient::MessageDispatch));
|
||||
auto dispatch_cb = [this]() {
|
||||
@ -24,13 +24,15 @@ DiscordClient::DiscordClient(bool mem_store)
|
||||
}
|
||||
|
||||
void DiscordClient::Start() {
|
||||
m_http.SetBase(GetAPIURL());
|
||||
|
||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
||||
|
||||
m_last_sequence = -1;
|
||||
m_heartbeat_acked = true;
|
||||
m_client_connected = true;
|
||||
m_websocket.StartConnection(DiscordGateway);
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
}
|
||||
|
||||
void DiscordClient::Stop() {
|
||||
@ -1104,6 +1106,17 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) {
|
||||
SendIdentify();
|
||||
}
|
||||
|
||||
// perhaps this should be set by the main class
|
||||
std::string DiscordClient::GetAPIURL() {
|
||||
static const auto url = Abaddon::Get().GetSettings().GetAPIBaseURL();
|
||||
return url;
|
||||
}
|
||||
|
||||
std::string DiscordClient::GetGatewayURL() {
|
||||
static const auto url = Abaddon::Get().GetSettings().GetGatewayURL();
|
||||
return url;
|
||||
}
|
||||
|
||||
DiscordError DiscordClient::GetCodeFromResponse(const http::response_type &response) {
|
||||
try {
|
||||
// pull me somewhere else?
|
||||
@ -1576,7 +1589,7 @@ void DiscordClient::HandleGatewayReconnect(const GatewayMessage &msg) {
|
||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
||||
|
||||
m_websocket.StartConnection(DiscordGateway);
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
||||
@ -1597,7 +1610,7 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
||||
|
||||
m_websocket.Stop(1000);
|
||||
|
||||
m_websocket.StartConnection(DiscordGateway);
|
||||
m_websocket.StartConnection(GetGatewayURL());
|
||||
}
|
||||
|
||||
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||
|
@ -49,10 +49,6 @@ class Abaddon;
|
||||
class DiscordClient {
|
||||
friend class Abaddon;
|
||||
|
||||
public:
|
||||
static const constexpr char *DiscordGateway = "wss://gateway.discord.gg/?v=9&encoding=json&compress=zlib-stream";
|
||||
static const constexpr char *DiscordAPI = "https://discord.com/api/v9";
|
||||
|
||||
public:
|
||||
DiscordClient(bool mem_store = false);
|
||||
void Start();
|
||||
@ -191,6 +187,9 @@ private:
|
||||
std::vector<uint8_t> m_decompress_buf;
|
||||
z_stream m_zstream;
|
||||
|
||||
std::string GetAPIURL();
|
||||
std::string GetGatewayURL();
|
||||
|
||||
static DiscordError GetCodeFromResponse(const http::response_type &response);
|
||||
|
||||
void ProcessNewGuild(GuildData &guild);
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include "httpclient.hpp"
|
||||
|
||||
//#define USE_LOCAL_PROXY
|
||||
HTTPClient::HTTPClient(std::string api_base)
|
||||
: m_api_base(api_base) {
|
||||
HTTPClient::HTTPClient() {
|
||||
m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks));
|
||||
}
|
||||
|
||||
void HTTPClient::SetBase(const std::string &url) {
|
||||
m_api_base = url;
|
||||
}
|
||||
|
||||
void HTTPClient::SetUserAgent(std::string agent) {
|
||||
m_agent = agent;
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
class HTTPClient {
|
||||
public:
|
||||
HTTPClient(std::string api_base);
|
||||
HTTPClient();
|
||||
|
||||
void SetBase(const std::string &url);
|
||||
|
||||
void SetUserAgent(std::string agent);
|
||||
void SetAuth(std::string auth);
|
||||
|
@ -85,3 +85,11 @@ bool SettingsManager::GetShowAnimations() const {
|
||||
bool SettingsManager::GetShowOwnerCrown() const {
|
||||
return GetSettingBool("gui", "owner_crown", true);
|
||||
}
|
||||
|
||||
std::string SettingsManager::GetGatewayURL() const {
|
||||
return GetSettingString("discord", "gateway", "wss://gateway.discord.gg/?v=9&encoding=json&compress=zlib-stream");
|
||||
}
|
||||
|
||||
std::string SettingsManager::GetAPIBaseURL() const {
|
||||
return GetSettingString("discord", "api_base", "https://discord.com/api/v9");
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ public:
|
||||
std::string GetMainCSS() const;
|
||||
bool GetShowAnimations() const;
|
||||
bool GetShowOwnerCrown() const;
|
||||
std::string GetGatewayURL() const;
|
||||
std::string GetAPIBaseURL() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user