9#define Verbose(pmt, ...) UE_LOG(LogMultiplayerManagerComponent, Verbose, TEXT(pmt), ##__VA_ARGS__)
10#define Log(pmt, ...) UE_LOG(LogMultiplayerManagerComponent, Log, TEXT(pmt), ##__VA_ARGS__)
11#define Warn(pmt, ...) UE_LOG(LogMultiplayerManagerComponent, Warning, TEXT(pmt), ##__VA_ARGS__)
12#define Error(pmt, ...) UE_LOG(LogMultiplayerManagerComponent, Error, TEXT(pmt), ##__VA_ARGS__)
13#define Fatal(pmt, ...) UE_LOG(LogMultiplayerManagerComponent, Fatal, TEXT(pmt), ##__VA_ARGS__)
20 PrimaryComponentTick.bCanEverTick =
true;
22 Log(
"Multiplayer Manager Component has been created.");
26 AgonesSDK = CreateDefaultSubobject<UAgonesComponent>(TEXT(
"AgonesSDK"));
36 Log(
"Are we a server?");
38 Log(
"We are! Start Playing with Server.");
43 if (IOnlineSubsystem*
const OnlineSubsystem = IOnlineSubsystem::Get())
45 Log(
"Get the online subsystem.");
46 FPVROnlineSessionPtr SessionInt = StaticCastSharedPtr<FPVROnlineSession>(OnlineSubsystem->GetSessionInterface());
47 if (SessionInt.IsValid())
49 auto NamedSession = SessionInt->GetFirstNamedSession();
50 Log(
"Found first named session.");
53 FSetLabelDelegate SetLabelSuccessDelegate;
55 FAgonesErrorDelegate SetLabelFailDelegate;
57 Log(
"Online Session was already created!");
59 NamedSession->SessionSettings.Get(SETTING_MAPNAME, MapName);
60 AgonesSDK->SetLabel(
"SessionID", NamedSession->GetSessionIdStr(), SetLabelSuccessDelegate, SetLabelFailDelegate);
61 AgonesSDK->SetLabel(
"MapName", MapName, SetLabelSuccessDelegate, SetLabelFailDelegate);
62 AgonesSDK->SetLabel(
"OwningUserName", NamedSession->OwningUserName, SetLabelSuccessDelegate, SetLabelFailDelegate);
63 AgonesSDK->SetLabel(
"SessionName", NamedSession->SessionName.ToString(), SetLabelSuccessDelegate, SetLabelFailDelegate);
89 Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
96 Verbose(
"Game server %s changed with state %s at address %s and health checks are %s", *Response.ObjectMeta.Name, *Response.Status.State, *Response.Status.Address, Response.Spec.Health.bDisabled ? TEXT(
"Disabled") : TEXT(
"Enabled"));
99 if (Response.Status.State.Equals(
"Ready", ESearchCase::Type::IgnoreCase) && !
bWasMetaDataSet)
101 Log(
"Server is ready.");
103 if (!FParse::Value(FCommandLine::Get(), TEXT(
"-PIXOVR_MODULE_ID="), ModuleID))
106 if (GConfig && !GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"ModuleId"), ModuleID, GEngineIni))
108 Fatal(
"No Module ID available.");
113 if (!FParse::Value(FCommandLine::Get(), TEXT(
"-PIXOVR_ORG_ID="), OrgID))
116 Error(
"No Org ID available.");
119 FString ModuleVersion = TEXT(
"0.1.0");
120 if (!FParse::Value(FCommandLine::Get(), TEXT(
"-PIXOVR_MODULE_VERSION="), ModuleVersion))
123 if (GConfig && !GConfig->GetString(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"ModuleVersion"), ModuleVersion, GEngineIni))
125 Fatal(
"No Module Version available.");
130 AgonesSDK->SetLabel(
"ModuleID", FString::FromInt(ModuleID), {}, {});
131 AgonesSDK->SetLabel(
"ModuleVersion", ModuleVersion, {}, {});
133 Log(
"Flagging that meta data was set.");
141 Log(
"Online Session was Created!");
144 Warn(
"No session was created successfully.");
149 if (IOnlineSubsystem*
const OnlineSubsystem = IOnlineSubsystem::Get())
151 FPVROnlineSessionPtr SessionInt = StaticCastSharedPtr<FPVROnlineSession>(OnlineSubsystem->GetSessionInterface());
152 if (SessionInt.IsValid())
154 auto NamedSession = SessionInt->GetNamedSession(SessionName);
157 AgonesSDK->SetLabel(
"SessionID", NamedSession->GetSessionIdStr(), {}, {});
159 NamedSession->SessionSettings.Get(SETTING_MAPNAME, MapName);
160 AgonesSDK->SetLabel(
"MapName", MapName, {}, {});
161 AgonesSDK->SetLabel(
"OwningUserName", NamedSession->OwningUserName, {}, {});
163 AgonesSDK->SetLabel(
"SessionName", SessionName.ToString(), {}, {});
171 if (IOnlineSubsystem*
const OnlineSubsystem = IOnlineSubsystem::Get())
176 PVROSubsystem->
SetUserInfo(InUserName, InUserOrgId);
183 if (IOnlineSubsystem*
const OnlineSubsystem = IOnlineSubsystem::Get())
195 UGameInstance* GameInstance = GetWorld()->GetGameInstance();
199 if (IOnlineSubsystem*
const OnlineSubsystem = IOnlineSubsystem::Get())
201 IOnlineSessionPtr Session = OnlineSubsystem->GetSessionInterface();
202 if (Session.IsValid())
204 TSharedPtr<FOnlineSessionSearch> SearchSettings = MakeShareable(
new FOnlineSessionSearch());
205 SearchSettings->QuerySettings.Set(FName(TEXT(
"OrgID")), InOrgId, EOnlineComparisonOp::Equals);
206 SearchSettings->QuerySettings.Set(FName(TEXT(
"ModuleID")), InModuleId, EOnlineComparisonOp::Equals);
207 SearchSettings->QuerySettings.Set(FName(TEXT(
"UserName")), InUserName, EOnlineComparisonOp::Equals);
208 SearchSettings->QuerySettings.Set(FName(TEXT(
"ModuleVersion")), InModuleVersion, EOnlineComparisonOp::Equals);
209 SearchSettings->TimeoutInSeconds = InTimeoutInSeconds;
211 TSharedRef<FOnlineSessionSearch> SearchSettingsRef = SearchSettings.ToSharedRef();
213 ULocalPlayer*
const Player = GameInstance->GetFirstGamePlayer();
214 Session->FindSessions(*Player->GetPreferredUniqueNetId().GetUniqueNetId(), SearchSettingsRef);
219 Warn(
"No suitable Online Subsystem is available.");
DEFINE_LOG_CATEGORY_STATIC(LogMultiplayerManagerComponent, Verbose, All)
TSharedPtr< FPVROnlineSession, ESPMode::ThreadSafe > FPVROnlineSessionPtr
void SetModuleInfo(int InModuleId, FString InModuleVersion)
void SetUserInfo(FString InUserName, int InUserOrgId)
void OnSetLabelFail(const FAgonesError &Error)
UFUNCTION(Category = "Multiplayer | Manager")
void SetUserInfo(FString InUserName, int InUserOrgId)
UFUNCTION(BlueprintCallable, Category = "Multiplayer | Manager")
void SetModuleInfo(int InModuleId, FString InModuleVersion)
UFUNCTION(BlueprintCallable, Category = "Multiplayer | Manager")
FGameServerDelegate GameServerDelegate
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool FindSessions(float InTimeoutInSeconds=120.f, int InOrgId=-1, int InModuleId=-1, FString InUserName="", FString InModuleVersion="")
UFUNCTION(BlueprintCallable, Category = "Multiplayer | Manager")
void OnSetLabelSuccess(const FEmptyResponse &Response)
UFUNCTION(Category = "Multiplayer | Manager")
virtual void OnSessionCreated(FName SessionName, bool bSuccessful)
UFUNCTION(BlueprintCallable, Category = "Multiplayer | Manager")
virtual void BeginPlay() override
virtual void OnGameServerChanged(const FGameServerResponse &Response)
UFUNCTION(BlueprintCallable, Category = "Multiplayer | Manager")
UMultiplayerManagerComponent()
bool bWasMetaDataSet
UPROPERTY(BlueprintReadOnly)
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override
UAgonesComponent * AgonesSDK