From ca3eacbd790a7e50a7fe5070e975c10255a1e174 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 10 Jul 2021 03:11:59 -0400 Subject: dont use unordered collections (reduce memory a bit) --- discord/discord.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'discord/discord.hpp') diff --git a/discord/discord.hpp b/discord/discord.hpp index cfce016..6138ea3 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -6,9 +6,8 @@ #include #include #include -#include +#include #include -#include #include #include #include @@ -85,8 +84,8 @@ public: std::optional GetBan(Snowflake guild_id, Snowflake user_id) const; Snowflake GetMemberHoistedRole(Snowflake guild_id, Snowflake user_id, bool with_color = false) const; std::optional GetMemberHighestRole(Snowflake guild_id, Snowflake user_id) const; - std::unordered_set GetUsersInGuild(Snowflake id) const; - std::unordered_set GetChannelsInGuild(Snowflake id) const; + std::set GetUsersInGuild(Snowflake id) const; + std::set GetChannelsInGuild(Snowflake id) const; bool HasGuildPermission(Snowflake user_id, Snowflake guild_id, Permission perm) const; @@ -184,8 +183,8 @@ public: PresenceStatus GetUserStatus(Snowflake id) const; - std::unordered_map GetRelationships() const; - std::unordered_set GetRelationships(RelationshipType type) const; + std::map GetRelationships() const; + std::set GetRelationships(RelationshipType type) const; std::optional GetRelationship(Snowflake id) const; private: @@ -255,14 +254,14 @@ private: std::string m_token; void AddUserToGuild(Snowflake user_id, Snowflake guild_id); - std::unordered_map> m_guild_to_users; + std::map> m_guild_to_users; - std::unordered_map> m_guild_to_channels; - std::unordered_map m_guild_join_requests; + std::map> m_guild_to_channels; + std::map m_guild_join_requests; - std::unordered_map m_user_to_status; + std::map m_user_to_status; - std::unordered_map m_user_relationships; + std::map m_user_relationships; UserData m_user_data; UserSettings m_user_settings; @@ -273,7 +272,7 @@ private: std::atomic m_client_connected = false; std::atomic m_ready_received = false; - std::unordered_map m_event_map; + std::map m_event_map; void LoadEventMap(); std::thread m_heartbeat_thread; -- cgit v1.2.3 From b2b55eb06ead0b118607ef55d38343d6a1fcef29 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 10 Jul 2021 03:42:14 -0400 Subject: disconnect action should interrupt reconnect --- discord/discord.cpp | 12 ++++++++---- discord/discord.hpp | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'discord/discord.hpp') diff --git a/discord/discord.cpp b/discord/discord.cpp index ffab9b6..52dfab9 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -32,10 +32,13 @@ void DiscordClient::Start() { m_last_sequence = -1; m_heartbeat_acked = true; m_client_connected = true; + m_client_started = true; m_websocket.StartConnection(GetGatewayURL()); } void DiscordClient::Stop() { + m_client_started = false; + if (!m_client_connected) return; inflateEnd(&m_zstream); @@ -53,7 +56,7 @@ void DiscordClient::Stop() { } bool DiscordClient::IsStarted() const { - return m_client_connected; + return m_client_started; } bool DiscordClient::IsStoreValid() const { @@ -1683,7 +1686,8 @@ void DiscordClient::HandleGatewayInvalidSession(const GatewayMessage &msg) { m_websocket.Stop(1000); - Glib::signal_timeout().connect_once([this] { m_websocket.StartConnection(GetGatewayURL()); }, 1000); + if (m_client_started) + Glib::signal_timeout().connect_once([this] { if (m_client_started) m_websocket.StartConnection(GetGatewayURL()); }, 1000); } bool IsCompleteMessageObject(const nlohmann::json &j) { @@ -1887,8 +1891,8 @@ void DiscordClient::HandleSocketClose(uint16_t code) { m_store.ClearAll(); m_guild_to_users.clear(); - if (!m_reconnecting && close_code != GatewayCloseCode::Normal) { - Glib::signal_timeout().connect_once([this] { HandleGatewayReconnect(GatewayMessage()); }, 1000); + if (m_client_started && !m_reconnecting && close_code != GatewayCloseCode::Normal) { + Glib::signal_timeout().connect_once([this] { if (m_client_started) HandleGatewayReconnect(GatewayMessage()); }, 1000); m_reconnecting = true; } diff --git a/discord/discord.hpp b/discord/discord.hpp index 6138ea3..918b1cb 100644 --- a/discord/discord.hpp +++ b/discord/discord.hpp @@ -271,6 +271,7 @@ private: Websocket m_websocket; std::atomic m_client_connected = false; std::atomic m_ready_received = false; + bool m_client_started = false; std::map m_event_map; void LoadEventMap(); -- cgit v1.2.3