Documentation for the Unreal C++ Library
Loading...
Searching...
No Matches
PVROBeacon.h
Go to the documentation of this file.
1// Copyright(c) 2023 PixoVR, LLC. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "OnlineSubsystemTypes.h"
7#include "OnlineDelegateMacros.h"
8#include "Misc/ConfigCacheIni.h"
9#if ENGINE_MAJOR_VERSION >= 5
10#include "Online/LANBeacon.h"
11#endif
12
13#define PIXOVR_BEACON_PACKET_VERSION (uint8)10
14#define PIXOVR_BEACON_PACKET_HEADER_SIZE 16
15#define PIXOVR_SERVER_QUERY1 (uint8)'S'
16#define PIXOVR_SERVER_QUERY2 (uint8)'Q'
17#define PIXOVR_SERVER_RESPONSE1 (uint8)'S'
18#define PIXOVR_SERVER_RESPONSE2 (uint8)'R'
19
20class FInternetAddr;
21class FNboSerializeToBuffer;
22
23DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnValidQueryPacket, uint8*, int32, uint64);
24typedef FOnValidQueryPacket::FDelegate FOnValidQueryPacketDelegate;
25
26DECLARE_MULTICAST_DELEGATE_TwoParams(FOnValidResponsePacket, uint8*, int32);
27typedef FOnValidResponsePacket::FDelegate FOnValidResponsePacketDelegate;
28
29DECLARE_MULTICAST_DELEGATE(FOnSearchingTimeout);
30typedef FOnSearchingTimeout::FDelegate FOnSearchingTimeoutDelegate;
31
33typedef FOnPortChanged::FDelegate FOnPortChangedDelegate;
34
38class PIXOVRMULTIPLAYER_API FPVROBeacon
39{
41 TSharedPtr<class FInternetAddr> BroadcastAddr;
43 class FSocket* ListenSocket;
45 TSharedPtr<class FInternetAddr> ListenAddr;
47 TSharedRef<class FInternetAddr> SockAddr;
48
49public:
52
54 virtual ~FPVROBeacon();
55
57 bool IsListenSocketValid() const;
58
66 bool Init(int32 Port);
67
75 bool InitHost(int32 Port);
76
86 bool InitClient(int32 IP, int32 Port, int32 ListenPort);
87
97 int32 ReceivePacket(uint8* PacketData, int32 BufferSize);
98
105 bool BroadcastPacket(uint8* Packet, int32 Length);
106
113 bool BroadcastPacketFromSocket(uint8* Packet, int32 Length);
114
115 DEFINE_ONLINE_DELEGATE_ONE_PARAM(OnPortChanged, int32);
116};
117
118#define PIXOVR_ANNOUNCE_PORT 14001
119#define PIXOVR_UNIQUE_ID 9999
120#define PIXOVR_QUERY_TIMEOUT 5
121#define PIXOVR_PLATFORMMASK 0xffffffff
122
126class PIXOVRMULTIPLAYER_API FPVROSession
127{
128protected:
138 bool IsValidLanQueryPacket(const uint8* Packet, uint32 Length, uint64& ClientNonce);
139
148 bool IsValidLanResponsePacket(const uint8* Packet, uint32 Length);
149
150public:
151
154
156
158
160
162
165
168
171
174
176 ELanBeaconState::Type LanBeaconState;
177
179 uint64 LanNonce;
180
183
185 LanAnnouncePort(PIXOVR_ANNOUNCE_PORT),
186 LanGameUniqueId(PIXOVR_UNIQUE_ID),
187 LanPacketPlatformMask(PIXOVR_PLATFORMMASK),
188 LanQueryTimeout(PIXOVR_QUERY_TIMEOUT),
189 LanBeacon(NULL),
190 LanBeaconState(ELanBeaconState::NotUsingLanBeacon),
191 LanNonce(0),
192 LanQueryTimeLeft(0.0f)
193 {
194 if (!GConfig->GetInt(TEXT("LANSession"), TEXT("LanAnnouncePort"), LanAnnouncePort, GEngineIni))
195 {
196 LanAnnouncePort = PIXOVR_ANNOUNCE_PORT;
197 }
198 if (!GConfig->GetInt(TEXT("LANSession"), TEXT("LanGameUniqueId"), LanGameUniqueId, GEngineIni))
199 {
200 LanGameUniqueId = PIXOVR_UNIQUE_ID;
201 }
202 }
203
205 {
206 StopLANSession();
207 }
208
215 bool Host(FOnValidQueryPacketDelegate& QueryDelegate, int32 Port = -1);
216
226 bool Search(class FNboSerializeToBuffer& Packet, FOnValidResponsePacketDelegate& ResponseDelegate, FOnSearchingTimeoutDelegate& TimeoutDelegate);
227
231 void StopLANSession();
232
233 void Tick(float DeltaTime);
234
236 void CreateHostResponsePacket(FNboSerializeToBuffer& Packet, uint64 ClientNonce);
237 void CreateClientQueryPacket(FNboSerializeToBuffer& Packet, uint64 ClientNonce);
238
245 bool BroadcastPacket(uint8* Packet, int32 Length);
246
253 bool BroadcastPacketFromSocket(uint8* Packet, int32 Length);
254
255 ELanBeaconState::Type GetBeaconState() const
256 {
257 return LanBeaconState;
258 }
259
260 DEFINE_ONLINE_DELEGATE_THREE_PARAM(OnValidQueryPacket, uint8*, int32, uint64);
261 DEFINE_ONLINE_DELEGATE_TWO_PARAM(OnValidResponsePacket, uint8*, int32);
262 DEFINE_ONLINE_DELEGATE(OnSearchingTimeout);
263};
#define PIXOVR_QUERY_TIMEOUT
Definition PVROBeacon.h:120
#define PIXOVR_PLATFORMMASK
Definition PVROBeacon.h:121
DECLARE_MULTICAST_DELEGATE_ThreeParams(FOnValidQueryPacket, uint8 *, int32, uint64)
FOnValidResponsePacket::FDelegate FOnValidResponsePacketDelegate
Definition PVROBeacon.h:27
FOnPortChanged::FDelegate FOnPortChangedDelegate
Definition PVROBeacon.h:33
#define PIXOVR_ANNOUNCE_PORT
Definition PVROBeacon.h:118
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnValidResponsePacket, uint8 *, int32)
DECLARE_MULTICAST_DELEGATE_OneParam(FOnPortChanged, int32)
#define PIXOVR_UNIQUE_ID
Definition PVROBeacon.h:119
FOnSearchingTimeout::FDelegate FOnSearchingTimeoutDelegate
Definition PVROBeacon.h:30
FOnValidQueryPacket::FDelegate FOnValidQueryPacketDelegate
Definition PVROBeacon.h:24
DECLARE_MULTICAST_DELEGATE(FOnSearchingTimeout)
TSharedRef< class FInternetAddr > SockAddr
Definition PVROBeacon.h:47
TSharedPtr< class FInternetAddr > BroadcastAddr
Definition PVROBeacon.h:41
class FSocket * ListenSocket
Definition PVROBeacon.h:43
TSharedPtr< class FInternetAddr > ListenAddr
Definition PVROBeacon.h:45
DEFINE_ONLINE_DELEGATE_ONE_PARAM(OnPortChanged, int32)
ELanBeaconState::Type LanBeaconState
Definition PVROBeacon.h:176
ELanBeaconState::Type GetBeaconState() const
Definition PVROBeacon.h:255
uint64 LanNonce
Definition PVROBeacon.h:179
int32 ClientSessionPort
Definition PVROBeacon.h:159
DEFINE_ONLINE_DELEGATE_THREE_PARAM(OnValidQueryPacket, uint8 *, int32, uint64)
virtual ~FPVROSession()
Definition PVROBeacon.h:204
int32 LanAnnouncePort
Definition PVROBeacon.h:153
DEFINE_ONLINE_DELEGATE_TWO_PARAM(OnValidResponsePacket, uint8 *, int32)
class FPVROBeacon * LanBeacon
Definition PVROBeacon.h:173
float LanQueryTimeout
Definition PVROBeacon.h:170
DEFINE_ONLINE_DELEGATE(OnSearchingTimeout)
int32 HostSessionPort
Definition PVROBeacon.h:157
float LanQueryTimeLeft
Definition PVROBeacon.h:182
int32 LanGameUniqueId
Definition PVROBeacon.h:164
int32 LanPacketPlatformMask
Definition PVROBeacon.h:167
int32 HostSessionAddress
Definition PVROBeacon.h:155