-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_client.h
83 lines (71 loc) · 3.18 KB
/
metadata_client.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef METADATA_CLIENT_H
#define METADATA_CLIENT_H
// ------------------------------------------------------------------------------------------------------------------
#include "metadata.h"
#include <QObject>
#include <QAbstractSocket>
// ------------------------------------------------------------------------------------------------------------------
class QTcpSocket;
class CUdpHolePunchingClient;
// ------------------------------------------------------------------------------------------------------------------
class IMetadataClient : public QObject
{
Q_OBJECT
public:
IMetadataClient(QObject *parent, QString username, QHostAddress serverHost, uint16_t serverPort);
virtual void updateAvailableChannels() = 0;
virtual void joinChannel(QString channel, QString password) = 0;
virtual void leaveChannel() = 0;
virtual void connect() = 0;
virtual const ChannelMetadata* currentChannel() const = 0;
virtual QList<ChannelMetadata> channels() const = 0;
virtual ChannelMetadata channel(QString name) const = 0;
QHostAddress host() const { return m_ServerHost; }
QString username() const { return m_Username; }
uint16_t port() const { return m_ServerPort; }
private:
QString m_Username;
QHostAddress m_ServerHost;
uint16_t m_ServerPort;
};
// ------------------------------------------------------------------------------------------------------------------
class CLanMetadataClient : public IMetadataClient
{
Q_OBJECT
public:
CLanMetadataClient(QObject* parent, QString username, QHostAddress serverHost, uint16_t serverPort);
virtual void updateAvailableChannels() override;
virtual void joinChannel(QString channel, QString password) override;
virtual void leaveChannel() override;
virtual void connect() override;
virtual const ChannelMetadata* currentChannel() const override;
virtual QList<ChannelMetadata> channels() const override;
virtual ChannelMetadata channel(QString name) const override;
uint16_t prefferedVoicePort() const;
private:
void handleIdentificationAction(QDataStream &stream);
void handlePortDiscoveryAction(QDataStream &stream);
void handleConnectAction(QDataStream &stream);
void handleClientJoinedAction(QDataStream &stream);
void handleOverviewAction(QDataStream &stream);
void handleDisconnectAction(QDataStream &stream);
public slots:
void onSocketReadyRead();
void onSocketError(QAbstractSocket::SocketError socketError);
signals:
void identificationSuccessful();
void identificationFailed(QString reason);
void channelsUpdated();
void connectionSuccessful(); // Wenn User erfolgreich Voice Channel betreten hat
void connectionFailed(QString reason);
void currentChannelUpdated(); // Wenn aktueller Channel aktualisiert wurde
void serverConnectionError(QAbstractSocket::SocketError socketError);
private:
uint16_t m_PreferredVoicePort;
CUdpHolePunchingClient *m_HolePunchClient;
QTcpSocket *m_Socket;
QString m_CurrentChannelName;
QMap<QString, ChannelMetadata> m_CachedChannels;
};
// ------------------------------------------------------------------------------------------------------------------
#endif // METADATA_CLIENT_H