diff options
author | Manuel Schneider | 2014-05-28 00:37:28 +0200 |
---|---|---|
committer | Manuel Schneider | 2014-05-28 00:37:28 +0200 |
commit | afc69ca4ffb0e11d9d06b8ddd31ee40963f86f17 (patch) | |
tree | f7284ba33e98d2bb6e099f248c7b127282efa99f /src/client/net/serverdiscovery.h | |
parent | Remove TODO. User get visual feedback via cam icon. (diff) | |
download | pvs2-afc69ca4ffb0e11d9d06b8ddd31ee40963f86f17.tar.gz pvs2-afc69ca4ffb0e11d9d06b8ddd31ee40963f86f17.tar.xz pvs2-afc69ca4ffb0e11d9d06b8ddd31ee40963f86f17.zip |
Outsource serverDiscovery.
Diffstat (limited to 'src/client/net/serverdiscovery.h')
-rw-r--r-- | src/client/net/serverdiscovery.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h new file mode 100644 index 0000000..093b841 --- /dev/null +++ b/src/client/net/serverdiscovery.h @@ -0,0 +1,51 @@ +#ifndef SERVERDISCOVERY_H +#define SERVERDISCOVERY_H + +#include <QObject> +#include <QUdpSocket> +#include <QTimer> +#include "../../shared/networkmessage.h" + +class ServerDiscovery : public QObject +{ + Q_OBJECT + + public: + enum class ErrorType{ + InvalidIpList, + InvalidHash + }; + + explicit ServerDiscovery(QObject *parent = 0); + ~ServerDiscovery(); + + void start(const QByteArray& sessionName); + void stop(); + inline bool isActive(){ return _discoveryTimer.isActive(); } + + private: + QTimer _discoveryTimer; + int _hashErrorCount; + int _ipErrorCount; + QByteArray _nameBytes; + QByteArray _salt2; + QUdpSocket _discoverySocket; + NetworkMessage _packet; + + static const int UDPBUFSIZ = 9000; + static const int SALT_LEN = 18; + +public: + signals: + void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash); + void error(ErrorType e, int count); + + public slots: + + private slots: + void doDiscovery(); + void onUdpReadyRead(); + +}; + +#endif // SERVERDISCOVERY_H |