6#include "GameFramework/GameStateBase.h"
7#include "GameFramework/PlayerState.h"
8#include "OnlineSubsystemUtils.h"
9#include "SocketSubsystem.h"
10#include "Runtime/JsonUtilities/Public/JsonObjectConverter.h"
11#include "Interfaces/IPv4/IPv4Address.h"
12#include "HttpModule.h"
13#if ENGINE_MAJOR_VERSION >= 5
14#include "IPAddressAsyncResolve.h"
15#include "Online/OnlineSessionNames.h"
21 return FString::Printf(TEXT(
"FPVROFindServerTask bWasSuccessful: %d Results: %d"), WasSuccessful(),
SearchSettings->SearchResults.Num());
26 TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HTTPRequest = FHttpModule::Get().CreateRequest();
29 HTTPRequest->SetVerb(
"GET");
35 GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"ModuleId"), ModuleId, GEngineIni);
38 SearchSettings->QuerySettings.Get<
int>(FName(TEXT(
"OrgID")), OrgID);
40 SessionRequestInfo.ModuleID = ModuleId;
43 UE_LOG(LogTemp, Warning, TEXT(
"Request to find Session: ModuleID: %d, OrgID: N/A, Version: %s, Client: %s"),
44 SessionRequestInfo.ModuleID, *SessionRequestInfo.ModuleVersion, *SessionRequestInfo.ClientID);
46 HTTPRequest->ProcessRequest();
62 ServerInfos.FromJson(HTTPResponse->GetContentAsString());
68 UE_LOG_ONLINE(Warning, TEXT(
"PixoVR Master Service Started new Dedicated Server: %s"), *
ServerInfos.
Reply);
80 UE_LOG_ONLINE(Warning, TEXT(
"Failed due to invalid ModuleID."));
89 UE_LOG_ONLINE(Warning, TEXT(
"IPAddress: %s"), *Server.IPAddress);
90 UE_LOG_ONLINE(Warning, TEXT(
"Port: %s"), *Server.Port);
91 UE_LOG_ONLINE(Warning, TEXT(
"SessionID: %s"), *Server.SessionID);
92 UE_LOG_ONLINE(Warning, TEXT(
"MapName: %s"), *Server.MapName);
93 UE_LOG_ONLINE(Warning, TEXT(
"OwningUserName: %s"), *Server.OwningUserName);
117 bWasSuccessful =
true;
123 bWasSuccessful =
false;
133 UE_LOG_ONLINE(Warning, TEXT(
"Failed to find any Sessions."));
136 bWasSuccessful =
false;
144 UE_LOG_ONLINE(Warning, TEXT(
"Sending another Request: %d"),
Counter);
154 UE_LOG_ONLINE(Warning, TEXT(
"HTTP request invalid."),
Counter);
157 bWasSuccessful =
false;
169 FPVROnlineSessionPtr SessionInt = StaticCastSharedPtr<FPVROnlineSession>(Subsystem->GetSessionInterface());
170 SearchSettings->SearchState = bWasSuccessful ? EOnlineAsyncTaskState::Done : EOnlineAsyncTaskState::Failed;
171 SessionInt->CurrentSessionSearch->SearchState = bWasSuccessful ? EOnlineAsyncTaskState::Done : EOnlineAsyncTaskState::Failed;
177 FOnlineSessionSearchResult* NewResult =
new (SessionInt->CurrentSessionSearch->SearchResults) FOnlineSessionSearchResult();
179 FOnlineSession* NewSession = &NewResult->Session;
182 PixoVRSessionInfo->
HostAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
184 int32 HostAddress = 0;
187 GetHostAndPort(HostAddress, HostPort, Server.IPAddress, Server.Port);
188 PixoVRSessionInfo->
HostAddr->SetIp(HostAddress);
189 PixoVRSessionInfo->
HostAddr->SetPort(HostPort);
190 NewSession->SessionSettings.Set(SETTING_MAPNAME, Server.MapName);
191 NewSession->OwningUserName = Server.OwningUserName;
192 NewSession->SessionInfo = MakeShareable(PixoVRSessionInfo);
200 SessionInt->CurrentSessionSearch = NULL;
215 FIPv4Address HostAddress;
216 bool Result = FIPv4Address::Parse(HostIP, HostAddress);
219 ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
222 FResolveInfo* ResolveInfo = SocketSubsystem->GetHostByName(TCHAR_TO_ANSI(*HostIP));
223 while (!ResolveInfo->IsComplete());
224 if (ResolveInfo->GetErrorCode() == 0)
226 const FInternetAddr* Address = &ResolveInfo->GetResolvedAddress();
229 Host = FIPv4Address(IP).Value;
235 UE_LOG(LogTemp, Warning, TEXT(
"FindSession: No SocketSubsystem found."));
240 Host = HostAddress.Value;
245 Port = FCString::Atoi(*HostPort);
const FString ReplyPending
const FString ReplyInvalidModuleID
TSharedPtr< FPVROnlineSession, ESPMode::ThreadSafe > FPVROnlineSessionPtr
static FString ServerVersion
TSharedPtr< class FOnlineSessionSearch > SearchSettings
virtual FString ToString() const override
virtual void Finalize() override
EPVRORequestSessionsReply bFoundSessions
FOnAsyncFindServersComplete FindServersCompleteDelegates
double SessionSearchStartInSeconds
double MaxDedicatedServerWaitTime
void OnRequestSessionResponseReceived(FHttpRequestPtr HTTPRequest, FHttpResponsePtr HTTPResponse, bool InWasSuccessful)
FPVROMPRequestServerInfo ServerInfos
virtual void Initialize() override
double DedicatedServerAquireStart
virtual void Tick() override
bool bDedicatedServerStart
void GetHostAndPort(int32 &Host, int32 &Port, const FString &HostIP, const FString &HostPort)
virtual void TriggerDelegates() override
TSharedPtr< class FInternetAddr > HostAddr
TArray< FPVROMPSessionInfo > CurrentSessions