Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Fill out your copyright notice in the Description page of Project Settings.
#include "CarCarCar.h"
#include "UBP_FuncLib.h"
#include "OnlineSubsystem.h"
#include "Runtime/Engine/Classes/Engine/GameInstance.h"
FString UUBP_FuncLib::GetSessionResultKeyValue(const FBlueprintSessionResult& Result, FName keyName)
{
FString keyValue;
Result.OnlineResult.Session.SessionSettings.Get(keyName, keyValue);
return keyValue;
}
void UUBP_FuncLib::UpdateSession(TArray<FName> KeyIDs,TArray<FString> KeyValues, bool RefreshOnlinedata)
{
auto Sessions = IOnlineSubsystem::Get()->GetSessionInterface();
if (Sessions.IsValid() && KeyIDs.Num() > 0 && KeyValues.Num() > 0 && KeyIDs.Num() == KeyValues.Num())
{
FOnlineSessionSettings Settings;
for (int32 i = 0; i < KeyIDs.Num(); ++i)
{
FOnlineSessionSetting Setting(KeyValues[i]);
Settings.Set(KeyIDs[i], Setting);
}
Sessions->UpdateSession(GameSessionName, Settings, RefreshOnlinedata);
UE_LOG(LogClass, Log, TEXT("Updated Session"));
}
else
{
UE_LOG(LogClass, Log, TEXT("Not Updated Session"));
FFrame::KismetExecutionMessage(TEXT("Sessions not supported by Online Subsystem"), ELogVerbosity::Warning);
}
}
TArray<FString> UUBP_FuncLib::SessionSettingsToString(const FBlueprintSessionResult& Result)
{
TArray<FString> SessionSettings = TArray<FString>();
for (FSessionSettings::TConstIterator It(Result.OnlineResult.Session.SessionSettings.Settings); It; ++It)
{
UE_LOG(LogClass, Log, TEXT("Test SessionToString"));
FName Key = It.Key();
const FOnlineSessionSetting& Setting = It.Value();
SessionSettings.Add(Key.ToString());
SessionSettings.Add(Setting.ToString());
}
return SessionSettings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.