Fixed AllServers enum option when Finding servers, now searches twice, once for clients, once for dedicated servers.

This is because Steam splits the two queries up and doesn't allow combining them.


Added initial Workshop Items support for viewing subscribed items details and information.


Former-commit-id: 3153b6dbabf811e864a16408e816df5a03f5c0a3
This commit is contained in:
mordentral
2017-02-24 12:19:27 -05:00
parent fd410f8c5f
commit de94bf6648
6 changed files with 314 additions and 120 deletions

View File

@@ -12,6 +12,7 @@ UFindSessionsCallbackProxyAdvanced::UFindSessionsCallbackProxyAdvanced(const FOb
, Delegate(FOnFindSessionsCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted))
, bUseLAN(false)
{
bRunSecondSearch = false;
}
UFindSessionsCallbackProxyAdvanced* UFindSessionsCallbackProxyAdvanced::FindSessionsAdvanced(UObject* WorldContextObject, class APlayerController* PlayerController, int MaxResults, bool bUseLAN, EBPServerPresenceSearchType ServerTypeToSearch, const TArray<FSessionsSearchSetting> &Filters, bool bEmptyServersOnly, bool bNonEmptyServersOnly, bool bSecureServersOnly, int MinSlotsAvailable)
@@ -40,6 +41,9 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
auto Sessions = Helper.OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
{
// Re-initialize here, otherwise I think there might be issues with people re-calling search for some reason before it is destroyed
bRunSecondSearch = false;
DelegateHandle = Sessions->AddOnFindSessionsCompleteDelegate_Handle(Delegate);
SearchObject = MakeShareable(new FOnlineSessionSearch);
@@ -81,6 +85,18 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
if (MinSlotsAvailable != 0)
tem.Set(SEARCH_MINSLOTSAVAILABLE, MinSlotsAvailable, EOnlineComparisonOp::GreaterThanEquals);
// Filter results
if (SearchSettings.Num() > 0)
{
for (int i = 0; i < SearchSettings.Num(); i++)
{
// Function that was added to make directly adding a FVariant possible
tem.HardSet(SearchSettings[i].PropertyKeyPair.Key, SearchSettings[i].PropertyKeyPair.Data, SearchSettings[i].ComparisonOp);
}
}
switch (ServerSearchType)
{
@@ -99,28 +115,26 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
case EBPServerPresenceSearchType::AllServers:
default:
{
// tem.Set(SEARCH_DEDICATED_ONLY, false, EOnlineComparisonOp::Equals);
// tem.Set(SEARCH_PRESENCE, false, EOnlineComparisonOp::Equals);
bRunSecondSearch = true;
SearchObjectDedicated = MakeShareable(new FOnlineSessionSearch);
SearchObjectDedicated->MaxSearchResults = MaxResults;
SearchObjectDedicated->bIsLanQuery = bUseLAN;
FOnlineSearchSettingsEx DedicatedOnly = tem;
tem.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
DedicatedOnly.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals);
SearchObjectDedicated->QuerySettings = DedicatedOnly;
}
break;
}
// Filter results
if (SearchSettings.Num() > 0)
{
for (int i = 0; i < SearchSettings.Num(); i++)
{
// Function that was added to make directly adding a FVariant possible
tem.HardSet(SearchSettings[i].PropertyKeyPair.Key, SearchSettings[i].PropertyKeyPair.Data, SearchSettings[i].ComparisonOp);
}
}
// Copy the derived temp variable over to it's base class
SearchObject->QuerySettings = tem;
Sessions->FindSessions(*Helper.UserID, SearchObject.ToSharedRef());
// OnQueryCompleted will get called, nothing more to do now
return;
}
@@ -131,8 +145,7 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
}
// Fail immediately
TArray<FBlueprintSessionResult> Results;
OnFailure.Broadcast(Results);
OnFailure.Broadcast(SessionSearchResults);
}
void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
@@ -140,7 +153,7 @@ void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
FOnlineSubsystemBPCallHelperAdvanced Helper(TEXT("FindSessionsCallback"), GEngine->GetWorldFromContextObject(WorldContextObject));
Helper.QueryIDFromPlayerController(PlayerControllerWeakPtr.Get());
if (Helper.IsValid())
if (!bRunSecondSearch && Helper.IsValid())
{
auto Sessions = Helper.OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
@@ -149,51 +162,43 @@ void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
}
}
TArray<FBlueprintSessionResult> Results;
if (bSuccess && SearchObject.IsValid())
{
// Just log the results for now, will need to add a blueprint-compatible search result struct
for (auto& Result : SearchObject->SearchResults)
{
/* bool bAddResult = true;
FString ResultText = FString::Printf(TEXT("Found a session. Ping is %d"), Result.PingInMs);
// Filter results
if (SearchSettings.Num() > 0)
{
FOnlineSessionSetting * setting;
for (int i = 0; i < SearchSettings.Num(); i++)
{
setting = Result.Session.SessionSettings.Settings.Find(SearchSettings[i].PropertyKeyPair.Key);
FFrame::KismetExecutionMessage(*ResultText, ELogVerbosity::Log);
// Couldn't find this key
if (!setting)
continue;
if (!CompareVariants(setting->Data, SearchSettings[i].PropertyKeyPair.Data, SearchSettings[i].ComparisonOp))
{
bAddResult = false;
break;
}
}
}*/
//if (bAddResult)
//{
FString ResultText = FString::Printf(TEXT("Found a session. Ping is %d"), Result.PingInMs);
FFrame::KismetExecutionMessage(*ResultText, ELogVerbosity::Log);
FBlueprintSessionResult BPResult;
BPResult.OnlineResult = Result;
Results.Add(BPResult);
//}
FBlueprintSessionResult BPResult;
BPResult.OnlineResult = Result;
SessionSearchResults.Add(BPResult);
}
if (!bRunSecondSearch)
{
OnSuccess.Broadcast(SessionSearchResults);
return;
}
OnSuccess.Broadcast(Results);
}
else
{
OnFailure.Broadcast(Results);
if (!bRunSecondSearch)
{
// Need to account for only one of the searches failing
if(SessionSearchResults.Num() > 0)
OnSuccess.Broadcast(SessionSearchResults);
else
OnFailure.Broadcast(SessionSearchResults);
return;
}
}
if (bRunSecondSearch && ServerSearchType == EBPServerPresenceSearchType::AllServers)
{
bRunSecondSearch = false;
auto Sessions = Helper.OnlineSub->GetSessionInterface();
Sessions->FindSessions(*Helper.UserID, SearchObjectDedicated.ToSharedRef());
}
}

View File

@@ -1,32 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "OnlineSubSystemHeader.h"
#include "SteamFuncs/AdvancedSteamWorkshopLibrary.h"
// This is taken directly from UE4 - OnlineSubsystemSteamPrivatePCH.h as a fix for the array_count macro
// @todo Steam: Steam headers trigger secure-C-runtime warnings in Visual C++. Rather than mess with _CRT_SECURE_NO_WARNINGS, we'll just
// disable the warnings locally. Remove when this is fixed in the SDK
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4996)
#endif
#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX
#pragma push_macro("ARRAY_COUNT")
#undef ARRAY_COUNT
#include <steam/steam_api.h>
#pragma pop_macro("ARRAY_COUNT")
#endif
// @todo Steam: See above
#ifdef _MSC_VER
#pragma warning(pop)
#endif
//General Log
DEFINE_LOG_CATEGORY(AdvancedSteamWorkshopLog);

View File

@@ -9,6 +9,7 @@
USteamWSRequestUGCDetailsCallbackProxy::USteamWSRequestUGCDetailsCallbackProxy(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
NumSecondsBeforeTimeout = 4.0f;
}
@@ -31,59 +32,23 @@ void USteamWSRequestUGCDetailsCallbackProxy::Activate()
return;
}
#endif
OnFailure.Broadcast();
OnFailure.Broadcast(FBPSteamWorkshopItemDetails());
}
void USteamWSRequestUGCDetailsCallbackProxy::OnUGCRequestUGCDetails(SteamUGCRequestUGCDetailsResult_t *pResult, bool bIOFailure)
{
#if PLATFORM_WINDOWS || PLATFORM_MAC || PLATFORM_LINUX
if (bIOFailure)
if (bIOFailure || !pResult)
{
OnFailure.Broadcast();
OnFailure.Broadcast(FBPSteamWorkshopItemDetails());
return;
}
SteamUGCDetails_t hUGCDetails = pResult->m_details;
GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Green, hUGCDetails.m_rgchTitle);
GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Green, hUGCDetails.m_rgchDescription);
OnSuccess.Broadcast();
OnSuccess.Broadcast(FBPSteamWorkshopItemDetails(pResult->m_details));
return;
#endif
OnFailure.Broadcast();
/*
PublishedFileId_t m_nPublishedFileId;
EResult m_eResult; // The result of the operation.
EWorkshopFileType m_eFileType; // Type of the file
AppId_t m_nCreatorAppID; // ID of the app that created this file.
AppId_t m_nConsumerAppID; // ID of the app that will consume this file.
char m_rgchTitle[k_cchPublishedDocumentTitleMax]; // title of document
char m_rgchDescription[k_cchPublishedDocumentDescriptionMax]; // description of document
uint64 m_ulSteamIDOwner; // Steam ID of the user who created this content.
uint32 m_rtimeCreated; // time when the published file was created
uint32 m_rtimeUpdated; // time when the published file was last updated
uint32 m_rtimeAddedToUserList; // time when the user added the published file to their list (not always applicable)
ERemoteStoragePublishedFileVisibility m_eVisibility; // visibility
bool m_bBanned; // whether the file was banned
bool m_bAcceptedForUse; // developer has specifically flagged this item as accepted in the Workshop
bool m_bTagsTruncated; // whether the list of tags was too long to be returned in the provided buffer
char m_rgchTags[k_cchTagListMax]; // comma separated list of all tags associated with this file
// file/url information
UGCHandle_t m_hFile; // The handle of the primary file
UGCHandle_t m_hPreviewFile; // The handle of the preview file
char m_pchFileName[k_cchFilenameMax]; // The cloud filename of the primary file
int32 m_nFileSize; // Size of the primary file
int32 m_nPreviewFileSize; // Size of the preview file
char m_rgchURL[k_cchPublishedFileURLMax]; // URL (for a video or a website)
// voting information
uint32 m_unVotesUp; // number of votes up
uint32 m_unVotesDown; // number of votes down
float m_flScore; // calculated score
uint32 m_unNumChildren; // if m_eFileType == k_EWorkshopFileTypeCollection, then this number will be the number of children contained within the collection
*/
OnFailure.Broadcast(FBPSteamWorkshopItemDetails());
}