summaryrefslogtreecommitdiffstats
path: root/src/net/pvsServiceDiscovery.h
blob: 58e0ab6d901a2ec5dc39db4302a1046f2e3fc9a5 (plain) (blame)
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
/*
# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# src/net/pvsServiceDiscovery.cpp
#    - handle console broadcasts, tell client to connect on match
# -----------------------------------------------------------------------------
*/

#ifndef PVSSERVICEDISCOVERY_H_
#define PVSSERVICEDISCOVERY_H_

#include <QtNetwork/QUdpSocket>
#include <QtCore/QDateTime>

class PVS;
class PVSDiscoveredServer;
typedef QList<PVSDiscoveredServer*> tServerList;

class PVSServiceDiscovery : public QObject
{
    Q_OBJECT
public:
    PVSServiceDiscovery(PVS* client);
    virtual ~PVSServiceDiscovery();
    void connectToSession(QString name, QString passwd);
    bool nameExists(QString name);
    QStringList getAllServers();
    void handleDiscovery(QHostAddress host, int port, QByteArray hash);

protected:
    void timerEvent(QTimerEvent *event);

private Q_SLOTS:
    void sock_dataArrival();
    void sendServerToGui(PVSDiscoveredServer*);

private:
    void setTimerInterval();
    QUdpSocket _sock;
    QString _sessionName;
    QString _sessionPasswd;
    PVS *_client;
    QDateTime _last; ///< to protect us from being abused as a ddos zombie
    tServerList _servers;
    int _currentServer;
    int _timerId;
};

#endif /* PVSSERVICEDISCOVERY_H_ */