diff options
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 |
