Thanks to CriErr for the following submission via a pull request.

Made some small modifications to them but they are mostly the same.


Former-commit-id: f304534c4f34dd92a3e6d96a87e3f2652321b1ae
This commit is contained in:
mordentral
2017-11-22 09:50:03 -05:00
parent 64218a7f5b
commit 483ffd5f6b
2 changed files with 47 additions and 12 deletions

View File

@@ -13,7 +13,7 @@
#include "Engine/GameInstance.h"
#include "OnlineSessionInterface.h"
#include "UObjectIterator.h"
//#include "UObjectIterator.h"
#include "AdvancedSessionsLibrary.generated.h"
@@ -67,6 +67,25 @@ public:
// Get the Unique Build ID from a session search result
UFUNCTION(BlueprintPure, Category = "Online|AdvancedSessions|SessionInfo")
static void GetUniqueBuildID(FBlueprintSessionResult SessionResult, int32 &UniqueBuildId);
// Thanks CriErr for submission
// Get session property Key Name value
UFUNCTION(BlueprintCallable, Category = "Online|AdvancedSessions|SessionInfo")
static FName GetSessionPropertyKey(const FSessionPropertyKeyPair& SessionProperty);
// Find session property by Name
UFUNCTION(BlueprintCallable, Category = "Online|AdvancedSessions|SessionInfo", meta = (ExpandEnumAsExecs = "Result"))
static void FindSessionPropertyByName(const TArray<FSessionPropertyKeyPair>& ExtraSettings, FName SettingsName, EBlueprintResultSwitch &Result, FSessionPropertyKeyPair& OutProperty);
// Find session property index by Name
UFUNCTION(BlueprintCallable, Category = "Online|AdvancedSessions|SessionInfo", meta = (ExpandEnumAsExecs = "Result"))
static void FindSessionPropertyIndexByName(const TArray<FSessionPropertyKeyPair>& ExtraSettings, FName SettingName, EBlueprintResultSwitch &Result, int32& OutIndex);
/// Removed the Index_None part of the last function, that isn't accessible in blueprint, better to return success/failure
// End Thanks CriErr :p
// Get session custom information key/value as Byte (For Enums)
UFUNCTION(BlueprintCallable, Category = "Online|AdvancedSessions|SessionInfo", meta = (ExpandEnumAsExecs = "SearchResult"))

View File

@@ -22,6 +22,31 @@ void UAdvancedSessionsLibrary::GetUniqueBuildID(FBlueprintSessionResult SessionR
UniqueBuildId = SessionResult.OnlineResult.Session.SessionSettings.BuildUniqueId;
}
FName UAdvancedSessionsLibrary::GetSessionPropertyKey(const FSessionPropertyKeyPair& SessionProperty)
{
return SessionProperty.Key;
}
void UAdvancedSessionsLibrary::FindSessionPropertyByName(const TArray<FSessionPropertyKeyPair>& ExtraSettings, FName SettingName, EBlueprintResultSwitch &Result, FSessionPropertyKeyPair& OutProperty)
{
const FSessionPropertyKeyPair* prop = ExtraSettings.FindByPredicate([&](const FSessionPropertyKeyPair& it) {return it.Key == SettingName; });
if (prop)
{
Result = EBlueprintResultSwitch::OnSuccess;
OutProperty = *prop;
return;
}
Result = EBlueprintResultSwitch::OnFailure;
}
void UAdvancedSessionsLibrary::FindSessionPropertyIndexByName(const TArray<FSessionPropertyKeyPair>& ExtraSettings, FName SettingName, EBlueprintResultSwitch &Result, int32& OutIndex)
{
OutIndex = ExtraSettings.IndexOfByPredicate([&](const FSessionPropertyKeyPair& it) {return it.Key == SettingName; });
Result = OutIndex != INDEX_NONE ? EBlueprintResultSwitch::OnSuccess : EBlueprintResultSwitch::OnFailure;
}
void UAdvancedSessionsLibrary::AddOrModifyExtraSettings(UPARAM(ref) TArray<FSessionPropertyKeyPair> & SettingsArray, UPARAM(ref) TArray<FSessionPropertyKeyPair> & NewOrChangedSettings, TArray<FSessionPropertyKeyPair> & ModifiedSettingsArray)
{
ModifiedSettingsArray = SettingsArray;
@@ -413,15 +438,6 @@ void UAdvancedSessionsLibrary::GetPlayerName(APlayerController *PlayerController
void UAdvancedSessionsLibrary::GetNumberOfNetworkPlayers(UObject* WorldContextObject, int32 &NumNetPlayers)
{
//Get an actor to GetWorld() from
/*TObjectIterator<AActor> Itr;
if (!Itr)
{
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get iterator!"));
return;
}*/
//~~~~~~~~~~~~
//Get World
UWorld* TheWorld = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
@@ -430,6 +446,6 @@ void UAdvancedSessionsLibrary::GetNumberOfNetworkPlayers(UObject* WorldContextOb
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get World()!"));
return;
}
TArray<class APlayerState*>& PlayerArray = (TheWorld->GetGameState()->PlayerArray);
NumNetPlayers = PlayerArray.Num();
NumNetPlayers = TheWorld->GetGameState()->PlayerArray.Num();
}