From a51a54bc5979a2491f152abc47ad54e6b63f27c8 Mon Sep 17 00:00:00 2001 From: Dylam De La Torre Date: Tue, 23 Nov 2021 05:21:56 +0100 Subject: Restructure source and resource files (#46) importantly, res is now res/res and css is now res/css --- src/discord/websocket.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/discord/websocket.hpp (limited to 'src/discord/websocket.hpp') diff --git a/src/discord/websocket.hpp b/src/discord/websocket.hpp new file mode 100644 index 0000000..e6a6489 --- /dev/null +++ b/src/discord/websocket.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +class Websocket { +public: + Websocket(); + void StartConnection(std::string url); + + void SetUserAgent(std::string agent); + + void Send(const std::string &str); + void Send(const nlohmann::json &j); + void Stop(); + void Stop(uint16_t code); + bool IsOpen() const; + +private: + void OnMessage(const ix::WebSocketMessagePtr &msg); + + ix::WebSocket m_websocket; + std::string m_agent; + +public: + typedef sigc::signal type_signal_open; + typedef sigc::signal type_signal_close; + typedef sigc::signal type_signal_message; + + type_signal_open signal_open(); + type_signal_close signal_close(); + type_signal_message signal_message(); + +private: + type_signal_open m_signal_open; + type_signal_close m_signal_close; + type_signal_message m_signal_message; +}; -- cgit v1.2.3 From 8c72d4c18d9c27ce1b5cd20f0cb98e5638c8becf Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Thu, 25 Nov 2021 02:57:11 -0500 Subject: dont print identify message to console mainly since i feel its only a matter of time before someone copy pastes it somewhere and itd be my fault also typedef -> using --- src/discord/discord.cpp | 3 +++ src/discord/websocket.cpp | 11 ++++++++++- src/discord/websocket.hpp | 11 ++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src/discord/websocket.hpp') diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 801282c..83db97b 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -2012,7 +2012,10 @@ void DiscordClient::SendIdentify() { msg.ClientState.HighestLastMessageID = "0"; msg.ClientState.ReadStateVersion = 0; msg.ClientState.UserGuildSettingsVersion = -1; + const bool b = m_websocket.GetPrintMessages(); + m_websocket.SetPrintMessages(false); m_websocket.Send(msg); + m_websocket.SetPrintMessages(b); } void DiscordClient::SendResume() { diff --git a/src/discord/websocket.cpp b/src/discord/websocket.cpp index ff50cd3..c7e43e9 100644 --- a/src/discord/websocket.cpp +++ b/src/discord/websocket.cpp @@ -15,6 +15,14 @@ void Websocket::SetUserAgent(std::string agent) { m_agent = agent; } +bool Websocket::GetPrintMessages() const noexcept { + return m_print_messages; +} + +void Websocket::SetPrintMessages(bool show) noexcept { + m_print_messages = show; +} + void Websocket::Stop() { Stop(ix::WebSocketCloseConstants::kNormalClosureCode); } @@ -29,7 +37,8 @@ bool Websocket::IsOpen() const { } void Websocket::Send(const std::string &str) { - printf("sending %s\n", str.c_str()); + if (m_print_messages) + printf("sending %s\n", str.c_str()); m_websocket.sendText(str); } diff --git a/src/discord/websocket.hpp b/src/discord/websocket.hpp index e6a6489..26cd5d4 100644 --- a/src/discord/websocket.hpp +++ b/src/discord/websocket.hpp @@ -13,6 +13,9 @@ public: void SetUserAgent(std::string agent); + bool GetPrintMessages() const noexcept; + void SetPrintMessages(bool show) noexcept; + void Send(const std::string &str); void Send(const nlohmann::json &j); void Stop(); @@ -26,9 +29,9 @@ private: std::string m_agent; public: - typedef sigc::signal type_signal_open; - typedef sigc::signal type_signal_close; - typedef sigc::signal type_signal_message; + using type_signal_open = sigc::signal; + using type_signal_close = sigc::signal; + using type_signal_message = sigc::signal; type_signal_open signal_open(); type_signal_close signal_close(); @@ -38,4 +41,6 @@ private: type_signal_open m_signal_open; type_signal_close m_signal_close; type_signal_message m_signal_message; + + bool m_print_messages = true; }; -- cgit v1.2.3