45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#pragma once
|
|
#include <QObject>
|
|
#include <QTcpSocket>
|
|
#include <QSslSocket>
|
|
#include <QString>
|
|
#include <vector>
|
|
#include "Protocol.hpp"
|
|
|
|
struct ShardInfo {
|
|
QString name;
|
|
uint32_t players_online;
|
|
uint32_t your_characters;
|
|
QString status;
|
|
};
|
|
|
|
class NetworkManager : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
NetworkManager(QObject* parent = nullptr);
|
|
~NetworkManager();
|
|
|
|
bool connectToServer(const QString& host, int port);
|
|
bool sendAuth(const QString& username, const QByteArray& hashedPassword);
|
|
bool sendRegister(const QString& email, const QString& username, const QByteArray& hashedPassword, const QByteArray& confirmHash);
|
|
void requestServerList(uint64_t sessionId);
|
|
|
|
signals:
|
|
void authSuccess(uint64_t sessionId);
|
|
void authFailed(const QString& reason);
|
|
void registerSuccess();
|
|
void registerFailed(const QString& reason);
|
|
void serverListReceived(const std::vector<ShardInfo>& shards);
|
|
void networkError(const QString& error);
|
|
|
|
private slots:
|
|
void onReadyRead();
|
|
void onSslErrors(const QList<QSslError>& errors);
|
|
|
|
private:
|
|
QSslSocket* socket_;
|
|
uint32_t requestCounter_;
|
|
|
|
void processPacket(const QByteArray& data);
|
|
};
|