diff options
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); |
