From c9f52b7223685d2e7fca925594171f94dd8c6e3b Mon Sep 17 00:00:00 2001 From: TrickyLeifa Date: Wed, 15 May 2024 00:00:17 +0200 Subject: Ported to CMake, ... * Ported the project to CMake * Android and Mac support dropped for the time being. * Tests, BASS and Discord-RPC are now options * Restructured and reformated the project. * Merged `include` and `src` * Renamed `resource` to `data` * Renamed various files * External libraries headers are no longer included in `src` * Replaced header guards with #pragma once * Multiple refactors (keywords, headers) * Added Qt6 compatibility * Removed various unused functions and headers * Reworked AOPacket * When content is passed to AOPacket, it should be ensured that the content is already decoded. * Encoding/decoding are now static methods. * Fixed various memory leaks * Removed animation code for AOImage * AOImage is always using static images * Simplified ChatLogPiece --- src/networkmanager.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/networkmanager.h (limited to 'src/networkmanager.h') diff --git a/src/networkmanager.h b/src/networkmanager.h new file mode 100644 index 00000000..984f30f8 --- /dev/null +++ b/src/networkmanager.h @@ -0,0 +1,72 @@ +#pragma once + +#include "aoapplication.h" +#include "aopacket.h" + +#include +#include +#include +#include +#include + +#include + +enum MSDocumentType +{ + PrivacyPolicy, + Motd, + ClientVersion +}; + +class NetworkManager : public QObject +{ + Q_OBJECT + +public: + explicit NetworkManager(AOApplication *parent); + ~NetworkManager() = default; + + void connect_to_server(server_type p_server); + void disconnect_from_server(); + +public Q_SLOTS: + void get_server_list(); + void ship_server_packet(AOPacket p_packet); + void join_to_server(); + void handle_server_packet(const QString &p_data); + + void request_document(MSDocumentType document_type, const std::function &cb); + void send_heartbeat(); + +Q_SIGNALS: + void server_connected(bool state); + +private Q_SLOTS: + void ms_request_finished(QNetworkReply *reply); + +private: + AOApplication *ao_app; + QNetworkAccessManager *http; + + union + { + QWebSocket *ws; + QTcpSocket *tcp; + } server_socket; + connection_type active_connection_type; + bool connected = false; + + QTimer *heartbeat_timer; + + const QString DEFAULT_MS_BASEURL = "http://servers.aceattorneyonline.com"; + QString ms_baseurl = DEFAULT_MS_BASEURL; + + const int heartbeat_interval = 60 * 5 * 1000; + + bool partial_packet = false; + QString temp_packet; + + unsigned int s_decryptor = 5; + + QString get_user_agent() const { return QStringLiteral("AttorneyOnline/%1 (Desktop)").arg(ao_app->get_version_string()); } +}; -- cgit