aboutsummaryrefslogtreecommitdiff
path: root/src/UdpTasks/BeaconServer/Receive/udponread.cpp
blob: b6d93d5885fbc28327cd235247f7a975bc1e8704 (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
#include "../beaconserver.h"

void BeaconServer::onUdpRead()
{
    while ( _udpSocket.hasPendingDatagrams() )
    {
        // get sender and payload
        QNetworkDatagram    datagram        = _udpSocket.receiveDatagram();
        QString             senderAddress   = QHostAddress( datagram.senderAddress().toIPv4Address() ).toString();
        int                 senderPort      = datagram.senderPort();
        QString             receiveBuffer   = datagram.data();
        receiveBuffer = receiveBuffer.toLatin1();

        // shorthand label
        QString senderAddressLabel = QStringLiteral("%1:%2").arg(senderAddress, QString::number(senderPort));
        _coreObject->Log.logEvent("udp", QStringLiteral("%1 sent '%2'").arg(senderAddressLabel, receiveBuffer ) );

        // ignore empty data packets (query port forwarded to a game port)
        if (receiveBuffer.length() <= 0)
            continue;

        // determine protocol and response based on the first character (backslash, byte value, ... )
        unsigned short protocol_chooser = receiveBuffer.at(0).unicode();
        if (protocol_chooser != 92)
            continue;

        // Protocol is GameSpy v0 (\key\value format) used by Unreal/UT, Postal 2, Rune, Deus Ex, Serious Sam, others
        processHeartbeatGamespy0(datagram, senderAddress, senderPort, receiveBuffer);

    } // while pending datagrams
}