aboutsummaryrefslogtreecommitdiff
path: root/src/TcpTasks/SyncClient/syncclient.h
blob: 8cf253ff914b61fc35683e3d694cf7ab295633e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef SYNCCLIENT_H
#define SYNCCLIENT_H

#include <QTimer>
#include <QTcpSocket>
#include <QHostAddress>

#include "Core/CoreObject/coreobject.h"
#include "Database/Common/commonactions.h"
#include "Protocols/GameSpy0/gamespy0.h"
#include "Protocols/GameSpy0/securevalidate.h"

class SyncClient: public QObject
{
    Q_OBJECT
public:
    SyncClient(const QSharedPointer<CoreObject> &coreObject,
               const QString                    &remoteHost,
               const unsigned short int         &remotePort);

private:
    QSharedPointer<CoreObject> _coreObject;
    const int _timeOutTime_ms = 7500;

    // tcp client handles
    QTcpSocket _tcpSocket;
    QTimer     _timeOut;
    QString    _rxBuffer = "";
    QString    _clientLabel;

    // helpers
    int _queryId = 0;

    // functions
    QStringList replyQuery(const QMultiHash<QString, QString> &query);

private: // update sync time in database
    bool updateSyncedServer(const QString        &serverAddress,
                            const unsigned short &serverPort);

private slots:
    void onSyncConnect();
    void onSyncRead();
    void onSyncDisconnect();
    void onSyncTimeOut();

signals:
};

#endif // SYNCCLIENT_H