diff options
| author | Salanto <62221668+Salanto@users.noreply.github.com> | 2022-06-06 10:14:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-06 19:14:44 +0200 |
| commit | f0a5e48f5ca6834c0f24b167c904a030894f706e (patch) | |
| tree | 0e7ae1497d0164e3a1a3c1d61a88e4f719beb5b5 /include | |
| parent | c4f459b6cce6382cbd7c1960a6738a5a8a45ab8c (diff) | |
Dual-Stack AO2 Client to handle both TCP and Websocket connections seemlessly (#696)
* Replace TCP Serversocket with Websocket
* Have TCP sockets live harmoniously with WS
"like 5 lines" yeah probably lost a bet.
* Update .gitlab-ci.yml
* hack to fix favorites
* Add support for websockets in the favorites list (serverlist.txt)
Make "add_favorite_server" remember the socket type
* Preserve old serverlist style
This will keep new entries compatible with 2.9 and prior clients. Makes parsing the list easier too.
* Add lookup table and correct write code to use lowercase
* I have no idea what a lookup table is, but this looks close enough
* Fix lookup table
* Otherwise backend selection behaviour is inverted
* clang-tidy had one job
* Yet it did not do it.
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
* const p_data
* Switch serverlist.txt to an ini format
* Fixes an Omni bug where : would split the servername
* Utilises internally QSettings properly for low parsing effort and clear structure
* Automatically migrates the legacy serverlist.txt to favorite_servers.ini
* Pleases my OCD
* Replace sample serverlist.
Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
Co-authored-by: stonedDiscord <Tukz@gmx.de>
Co-authored-by: Alex Noir <Varsash@gmail.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/aoapplication.h | 10 | ||||
| -rw-r--r-- | include/datatypes.h | 12 | ||||
| -rw-r--r-- | include/networkmanager.h | 25 |
3 files changed, 36 insertions, 11 deletions
diff --git a/include/aoapplication.h b/include/aoapplication.h index 4809c3f..4c3a83f 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -133,6 +133,8 @@ public: void set_favorite_list(); QVector<server_type> &get_favorite_list() { return favorite_list; } + + // Adds the server to favorite_servers.ini void add_favorite_server(int p_server); void set_server_list(QVector<server_type> &servers) { server_list = servers; } @@ -324,12 +326,14 @@ public: // Append to the currently open demo file if there is one void append_to_demofile(QString packet_string); - // Appends the argument string to serverlist.txt - void write_to_serverlist_txt(QString p_line); - // Returns the contents of serverlist.txt QVector<server_type> read_serverlist_txt(); + /** + * @brief Migrates the favorite serverlist format from txt to ini. + */ + void migrate_serverlist_txt(QFile &p_serverlist_txt); + // Returns the value of p_identifier in the design.ini file in p_design_path QString read_design_ini(QString p_identifier, VPath p_design_path); QString read_design_ini(QString p_identifier, QString p_design_path); diff --git a/include/datatypes.h b/include/datatypes.h index 2f03d39..3289bd8 100644 --- a/include/datatypes.h +++ b/include/datatypes.h @@ -1,13 +1,25 @@ #ifndef DATATYPES_H #define DATATYPES_H +#include <QMap> #include <QString> +enum connection_type { + TCP, + WEBSOCKETS, +}; + +static QMap<QString, connection_type> to_connection_type = { + {"tcp", connection_type::TCP}, + {"ws", connection_type::WEBSOCKETS} +}; + struct server_type { QString name; QString desc; QString ip; int port; + connection_type socket_type; }; struct emote_type { diff --git a/include/networkmanager.h b/include/networkmanager.h index 26a61f2..705fb9e 100644 --- a/include/networkmanager.h +++ b/include/networkmanager.h @@ -6,7 +6,7 @@ #include <QDnsLookup> #include <QNetworkAccessManager> -#include <QTcpSocket> +#include <QtWebSockets/QWebSocket> #include <QTime> #include <QTimer> @@ -21,16 +21,20 @@ enum MSDocumentType { class NetworkManager : public QObject { Q_OBJECT -public: - explicit NetworkManager(AOApplication *parent); - ~NetworkManager() = default; - +private: AOApplication *ao_app; QNetworkAccessManager *http; - QTcpSocket *server_socket; + + union { + QWebSocket *ws; + QTcpSocket *tcp; + } server_socket; + connection_type active_connection_type; + bool connected = false; + QTimer *heartbeat_timer; - const QString DEFAULT_MS_BASEURL = "https://servers.aceattorneyonline.com"; + const QString DEFAULT_MS_BASEURL = "http://servers.aceattorneyonline.com"; QString ms_baseurl = DEFAULT_MS_BASEURL; const int heartbeat_interval = 60 * 5 * 1000; @@ -40,12 +44,17 @@ public: unsigned int s_decryptor = 5; +public: + explicit NetworkManager(AOApplication *parent); + ~NetworkManager() = default; + void connect_to_server(server_type p_server); + void disconnect_from_server(); public slots: void get_server_list(const std::function<void()> &cb); void ship_server_packet(QString p_packet); - void handle_server_packet(); + void handle_server_packet(const QString& p_data); void request_document(MSDocumentType document_type, const std::function<void(QString)> &cb); |
