aboutsummaryrefslogtreecommitdiff
path: root/src/UdpTasks/BeaconServer/beaconserver.h
blob: fd8532d0a961b81f54c3d2ba9d615166ad76319c (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef BEACONSERVER_H
#define BEACONSERVER_H

#include <QTimer>
#include <QUdpSocket>
#include <QNetworkDatagram>
#include <QHostInfo>
#include "Core/CoreObject/coreobject.h"
#include "Database/Common/commonactions.h"
#include "Protocols/GameSpy0/gamespy0.h"
#include "Protocols/GameSpy0/securevalidate.h"
#include "UdpTasks/udpdatastructure.h"

class BeaconServer : public QObject
{
    Q_OBJECT
public:
    BeaconServer(const QSharedPointer<CoreObject> &coreObject);

    // activate listener and broadcast
    bool listen();
    bool uplink();

private: // general udp task handles
    QSharedPointer<CoreObject> _coreObject;
    const int _timeOutTime_ms      = 15000; // 15 second soft timeout
    const int _broadcastInterval_s = 60;   //   1 min between beacons

    // udp socket
    QUdpSocket _udpSocket;

    // determine reply to incoming requests
    QStringList replyQuery(const QMultiHash<QString, QString> &query);

private: // udp beacon server

    // heartbeat processing for different protocol types
    void processHeartbeatGamespy0(const QNetworkDatagram &datagram,
                                  const QString          &senderAddress,
                                  const unsigned short   &senderPort,
                                  const QString          &receiveBuffer);

    // timer to sweep up abandoned beacons (timeouts)
    QTimer _sweepTimer;

    // store information about unverified beacons
    QHash<QString, UdpData> _beaconList;

    // helper for replyQuery()
    int _queryId;

private slots: // udp beacon server event slots
    void onUdpRead();
    void onUdpTimedOut();

private: // broadcast heartbeat

    // outbound heartbeat timer and content
    QTimer  _uplinkTimer;
    QString _uplinkData;

private slots: // broadcast heartbeat events
    void onUplinkTimer();
};

#endif // BEACONSERVER_H