4#include "Misc/FeedbackContext.h"
5#include "UObject/CoreNet.h"
6#include "OnlineSubsystem.h"
7#include "SocketSubsystem.h"
9#if ENGINE_MAJOR_VERSION >= 5
10#include "Online/NboSerializer.h"
12#include "NboSerializer.h"
18 SockAddr(ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr())
25 ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
37 ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
38 bool bSuccess =
false;
44 ListenAddr = SocketSubsystem->GetLocalBindAddr(*GWarn);
47 SockAddr = SocketSubsystem->CreateInternetAddr();
49 ListenSocket = SocketSubsystem->CreateSocket(NAME_DGram, TEXT(
"LAN beacon"),
true);
65 UE_LOG_ONLINE(
Error, TEXT(
"Failed to bind listen socket to addr (%s) for LAN beacon"),
71 UE_LOG_ONLINE(
Error, TEXT(
"Failed to create listen socket for LAN beacon"));
78 ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
80 ListenAddr = SocketSubsystem->GetLocalBindAddr(*GLog);
82 SockAddr = SocketSubsystem->CreateInternetAddr();
84 bool bSuccess =
false;
85 ListenSocket = SocketSubsystem->CreateSocket(NAME_DGram, TEXT(
"Internet beacon"),
true);
105 TriggerOnPortChangedDelegates(
ListenAddr->GetPort());
109 UE_LOG(LogTemp,
Error, TEXT(
"Failed to bind listen socket to addr (%s) for LAN beacon"), *
ListenAddr->ToString(
true));
115 UE_LOG(LogTemp,
Error, TEXT(
"Failed to create listen socket for LAN beacon"));
123 ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
129 ListenAddr = SocketSubsystem->GetLocalBindAddr(*GLog);
131 SockAddr = SocketSubsystem->CreateInternetAddr();
133 bool bSuccess =
false;
134 ListenSocket = SocketSubsystem->CreateSocket(NAME_DGram, TEXT(
"Internet beacon"),
true);
159 TriggerOnPortChangedDelegates(
ListenAddr->GetPort());
163 UE_LOG(LogTemp,
Error, TEXT(
"Failed to bind listen socket to addr (%s) for LAN beacon"), *
ListenAddr->ToString(
true));
169 UE_LOG(LogTemp,
Error, TEXT(
"Failed to create listen socket for LAN beacon"));
172 UE_LOG(LogTemp, Warning, TEXT(
"FPVROBeacon:InitClient: %d %d"), IP, Port);
179 check(PacketData && BufferSize);
188 UE_LOG_ONLINE(
Verbose, TEXT(
"Received %d bytes from %s"), BytesRead, *
SockAddr->ToString(
true));
204 int32 BytesSent = 16;
220 bool bSuccess =
false;
226 AddOnValidQueryPacketDelegate_Handle(QueryDelegate);
230 UE_LOG(LogTemp, Warning, TEXT(
"Listening for LAN beacon requests on %d"),
LanAnnouncePort);
234 UE_LOG(LogTemp, VeryVerbose, TEXT(
"Failed to init LAN beacon %s"), ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetSocketError());
242 AddOnValidQueryPacketDelegate_Handle(QueryDelegate);
249 UE_LOG(LogTemp, Warning, TEXT(
"Failed to init Online beacon %s"), ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetSocketError());
258 bool bSuccess =
true;
261 UE_LOG(LogTemp, Warning, TEXT(
"LanBeacon Search LanBeacon already exists stopping session"));
272 UE_LOG(LogTemp, Warning, TEXT(
"Failed to create socket for lan announce port %s"), ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetSocketError());
281 UE_LOG(LogTemp, VeryVerbose, TEXT(
"Failed to create socket for lan announce port %s"), ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetSocketError());
289#if ENGINE_MAJOR_VERSION >= 5
295 UE_LOG_ONLINE(
Verbose, TEXT(
"Sent query packet..."));
301 AddOnValidResponsePacketDelegate_Handle(ResponseDelegate);
302 AddOnSearchingTimeoutDelegate_Handle(TimeoutDelegate);
306 UE_LOG_ONLINE(Warning, TEXT(
"Failed to send discovery broadcast %s"), ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetSocketError());
312 UE_LOG(LogTemp, VeryVerbose, TEXT(
"LanBeacon Search LanBeacon not valid or bSucces false"));
332 OnValidQueryPacketDelegates.Clear();
333 OnValidResponsePacketDelegates.Clear();
334 OnSearchingTimeoutDelegates.Clear();
344 uint8 PacketData[LAN_BEACON_MAX_PACKET_SIZE];
345 bool bShouldRead =
true;
382 TriggerOnSearchingTimeoutDelegates();
395 << (uint8)FPlatformProperties::IsLittleEndian()
409 << (uint8)FPlatformProperties::IsLittleEndian()
420 bool bSuccess =
false;
426 UE_LOG_ONLINE(Warning, TEXT(
"Failed to send broadcast packet %d"), (int32)ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLastErrorCode());
435 bool bSuccess =
false;
441 UE_LOG(LogTemp, VeryVerbose, TEXT(
"Failed to send broadcast packet %d"), (int32)ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLastErrorCode());
451 bool bIsValid =
false;
455 FNboSerializeFromBuffer PacketReader(Packet,Length);
457 PacketReader >> Version;
461 uint8 Platform = 255;
462 PacketReader >> Platform;
467 PacketReader >> GameId;
478 PacketReader >> ClientNonce;
488 bool bIsValid =
false;
492 FNboSerializeFromBuffer PacketReader(Packet,Length);
494 PacketReader >> Version;
498 uint8 Platform = 255;
499 PacketReader >> Platform;
504 PacketReader >> GameId;
516 PacketReader >> Nonce;
#define PIXOVR_SERVER_QUERY2
#define PIXOVR_SERVER_RESPONSE2
#define PIXOVR_SERVER_RESPONSE1
#define PIXOVR_BEACON_PACKET_HEADER_SIZE
FOnValidResponsePacket::FDelegate FOnValidResponsePacketDelegate
FOnSearchingTimeout::FDelegate FOnSearchingTimeoutDelegate
FOnValidQueryPacket::FDelegate FOnValidQueryPacketDelegate
#define PIXOVR_SERVER_QUERY1
#define PIXOVR_BEACON_PACKET_VERSION
TSharedRef< class FInternetAddr > SockAddr
TSharedPtr< class FInternetAddr > BroadcastAddr
bool InitClient(int32 IP, int32 Port, int32 ListenPort)
bool InitHost(int32 Port)
bool IsListenSocketValid() const
int32 ReceivePacket(uint8 *PacketData, int32 BufferSize)
bool BroadcastPacketFromSocket(uint8 *Packet, int32 Length)
class FSocket * ListenSocket
bool BroadcastPacket(uint8 *Packet, int32 Length)
TSharedPtr< class FInternetAddr > ListenAddr
void CreateClientQueryPacket(FNboSerializeToBuffer &Packet, uint64 ClientNonce)
void CreateHostResponsePacket(FNboSerializeToBuffer &Packet, uint64 ClientNonce)
ELanBeaconState::Type LanBeaconState
bool IsValidLanResponsePacket(const uint8 *Packet, uint32 Length)
bool BroadcastPacket(uint8 *Packet, int32 Length)
void Tick(float DeltaTime)
bool Search(class FNboSerializeToBuffer &Packet, FOnValidResponsePacketDelegate &ResponseDelegate, FOnSearchingTimeoutDelegate &TimeoutDelegate)
class FPVROBeacon * LanBeacon
bool IsValidLanQueryPacket(const uint8 *Packet, uint32 Length, uint64 &ClientNonce)
bool Host(FOnValidQueryPacketDelegate &QueryDelegate, int32 Port=-1)
bool BroadcastPacketFromSocket(uint8 *Packet, int32 Length)
int32 LanPacketPlatformMask