From afc69ca4ffb0e11d9d06b8ddd31ee40963f86f17 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Wed, 28 May 2014 00:37:28 +0200 Subject: Outsource serverDiscovery. --- src/client/net/serverdiscovery.h | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/client/net/serverdiscovery.h (limited to 'src/client/net/serverdiscovery.h') 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 +#include +#include +#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 -- cgit v1.2.3-55-g7522