forked from OpenGamers/abaddon
allow overriding of gateway + api url
This commit is contained in:
@@ -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
|
* 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
|
* 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
|
* 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
|
#### misc
|
||||||
* linkcolor (string) - color to use for links in messages
|
* linkcolor (string) - color to use for links in messages
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "discord.hpp"
|
#include "discord.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "../util.hpp"
|
#include "../util.hpp"
|
||||||
|
#include "../abaddon.hpp"
|
||||||
|
|
||||||
DiscordClient::DiscordClient(bool mem_store)
|
DiscordClient::DiscordClient(bool mem_store)
|
||||||
: m_http(DiscordAPI)
|
: m_decompress_buf(InflateChunkSize)
|
||||||
, m_decompress_buf(InflateChunkSize)
|
|
||||||
, m_store(mem_store) {
|
, m_store(mem_store) {
|
||||||
m_msg_dispatch.connect(sigc::mem_fun(*this, &DiscordClient::MessageDispatch));
|
m_msg_dispatch.connect(sigc::mem_fun(*this, &DiscordClient::MessageDispatch));
|
||||||
auto dispatch_cb = [this]() {
|
auto dispatch_cb = [this]() {
|
||||||
@@ -24,13 +24,15 @@ DiscordClient::DiscordClient(bool mem_store)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::Start() {
|
void DiscordClient::Start() {
|
||||||
|
m_http.SetBase(GetAPIURL());
|
||||||
|
|
||||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||||
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
||||||
|
|
||||||
m_last_sequence = -1;
|
m_last_sequence = -1;
|
||||||
m_heartbeat_acked = true;
|
m_heartbeat_acked = true;
|
||||||
m_client_connected = true;
|
m_client_connected = true;
|
||||||
m_websocket.StartConnection(DiscordGateway);
|
m_websocket.StartConnection(GetGatewayURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::Stop() {
|
void DiscordClient::Stop() {
|
||||||
@@ -1104,6 +1106,17 @@ void DiscordClient::HandleGatewayHello(const GatewayMessage &msg) {
|
|||||||
SendIdentify();
|
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) {
|
DiscordError DiscordClient::GetCodeFromResponse(const http::response_type &response) {
|
||||||
try {
|
try {
|
||||||
// pull me somewhere else?
|
// pull me somewhere else?
|
||||||
@@ -1576,7 +1589,7 @@ void DiscordClient::HandleGatewayReconnect(const GatewayMessage &msg) {
|
|||||||
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
std::memset(&m_zstream, 0, sizeof(m_zstream));
|
||||||
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
inflateInit2(&m_zstream, MAX_WBITS + 32);
|
||||||
|
|
||||||
m_websocket.StartConnection(DiscordGateway);
|
m_websocket.StartConnection(GetGatewayURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
||||||
@@ -1597,7 +1610,7 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) {
|
|||||||
|
|
||||||
m_websocket.Stop(1000);
|
m_websocket.Stop(1000);
|
||||||
|
|
||||||
m_websocket.StartConnection(DiscordGateway);
|
m_websocket.StartConnection(GetGatewayURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
void DiscordClient::HandleGatewayMessageUpdate(const GatewayMessage &msg) {
|
||||||
|
|||||||
@@ -49,10 +49,6 @@ class Abaddon;
|
|||||||
class DiscordClient {
|
class DiscordClient {
|
||||||
friend class Abaddon;
|
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:
|
public:
|
||||||
DiscordClient(bool mem_store = false);
|
DiscordClient(bool mem_store = false);
|
||||||
void Start();
|
void Start();
|
||||||
@@ -191,6 +187,9 @@ private:
|
|||||||
std::vector<uint8_t> m_decompress_buf;
|
std::vector<uint8_t> m_decompress_buf;
|
||||||
z_stream m_zstream;
|
z_stream m_zstream;
|
||||||
|
|
||||||
|
std::string GetAPIURL();
|
||||||
|
std::string GetGatewayURL();
|
||||||
|
|
||||||
static DiscordError GetCodeFromResponse(const http::response_type &response);
|
static DiscordError GetCodeFromResponse(const http::response_type &response);
|
||||||
|
|
||||||
void ProcessNewGuild(GuildData &guild);
|
void ProcessNewGuild(GuildData &guild);
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#include "httpclient.hpp"
|
#include "httpclient.hpp"
|
||||||
|
|
||||||
//#define USE_LOCAL_PROXY
|
//#define USE_LOCAL_PROXY
|
||||||
HTTPClient::HTTPClient(std::string api_base)
|
HTTPClient::HTTPClient() {
|
||||||
: m_api_base(api_base) {
|
|
||||||
m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks));
|
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) {
|
void HTTPClient::SetUserAgent(std::string agent) {
|
||||||
m_agent = agent;
|
m_agent = agent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
class HTTPClient {
|
class HTTPClient {
|
||||||
public:
|
public:
|
||||||
HTTPClient(std::string api_base);
|
HTTPClient();
|
||||||
|
|
||||||
|
void SetBase(const std::string &url);
|
||||||
|
|
||||||
void SetUserAgent(std::string agent);
|
void SetUserAgent(std::string agent);
|
||||||
void SetAuth(std::string auth);
|
void SetAuth(std::string auth);
|
||||||
|
|||||||
@@ -85,3 +85,11 @@ bool SettingsManager::GetShowAnimations() const {
|
|||||||
bool SettingsManager::GetShowOwnerCrown() const {
|
bool SettingsManager::GetShowOwnerCrown() const {
|
||||||
return GetSettingBool("gui", "owner_crown", true);
|
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;
|
std::string GetMainCSS() const;
|
||||||
bool GetShowAnimations() const;
|
bool GetShowAnimations() const;
|
||||||
bool GetShowOwnerCrown() const;
|
bool GetShowOwnerCrown() const;
|
||||||
|
std::string GetGatewayURL() const;
|
||||||
|
std::string GetAPIBaseURL() const;
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user