Fixed duplicating lobby results (forgot to use second array second time around).

Changed HasOnlineSubsystem to use a better function

Not running second search for AllServers enum when the subsystem isn't steam
Steam is the only subsystem that actually uses the flags that deal with that.


Former-commit-id: b07eadc87eaf82584ec63b6b4e91ace69fd5023f
This commit is contained in:
morden
2017-02-25 15:04:46 -05:00
parent cc9cc9b390
commit e9523733c1
4 changed files with 80 additions and 47 deletions

View File

@@ -99,9 +99,9 @@ enum class EBlueprintAsyncResultSwitch : uint8
UENUM(BlueprintType) UENUM(BlueprintType)
enum class EBPServerPresenceSearchType : uint8 enum class EBPServerPresenceSearchType : uint8
{ {
AllServers,
ClientServersOnly, ClientServersOnly,
DedicatedServersOnly, DedicatedServersOnly
AllServers
}; };
// Wanted this to be switchable in the editor // Wanted this to be switchable in the editor

View File

@@ -52,6 +52,7 @@ private:
void OnCompleted(bool bSuccess); void OnCompleted(bool bSuccess);
bool bRunSecondSearch; bool bRunSecondSearch;
bool bIsOnSecondSearch;
TArray<FBlueprintSessionResult> SessionSearchResults; TArray<FBlueprintSessionResult> SessionSearchResults;

View File

@@ -296,7 +296,7 @@ void UAdvancedSessionsLibrary::GetSessionPropertyFloat(const TArray<FSessionProp
bool UAdvancedSessionsLibrary::HasOnlineSubsystem(FName SubSystemName) bool UAdvancedSessionsLibrary::HasOnlineSubsystem(FName SubSystemName)
{ {
return((IOnlineSubsystem::Get(SubSystemName) != NULL)); return IOnlineSubsystem::DoesInstanceExist(SubSystemName);
} }
void UAdvancedSessionsLibrary::GetNetPlayerIndex(APlayerController *PlayerController, int32 &NetPlayerIndex) void UAdvancedSessionsLibrary::GetNetPlayerIndex(APlayerController *PlayerController, int32 &NetPlayerIndex)

View File

@@ -13,6 +13,7 @@ UFindSessionsCallbackProxyAdvanced::UFindSessionsCallbackProxyAdvanced(const FOb
, bUseLAN(false) , bUseLAN(false)
{ {
bRunSecondSearch = false; bRunSecondSearch = false;
bIsOnSecondSearch = 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) 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)
@@ -43,6 +44,7 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
{ {
// Re-initialize here, otherwise I think there might be issues with people re-calling search for some reason before it is destroyed // Re-initialize here, otherwise I think there might be issues with people re-calling search for some reason before it is destroyed
bRunSecondSearch = false; bRunSecondSearch = false;
bIsOnSecondSearch = false;
DelegateHandle = Sessions->AddOnFindSessionsCompleteDelegate_Handle(Delegate); DelegateHandle = Sessions->AddOnFindSessionsCompleteDelegate_Handle(Delegate);
@@ -54,26 +56,26 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
// Create temp filter variable, because I had to re-define a blueprint version of this, it is required. // Create temp filter variable, because I had to re-define a blueprint version of this, it is required.
FOnlineSearchSettingsEx tem; FOnlineSearchSettingsEx tem;
/* // Search only for dedicated servers (value is true/false) /* // Search only for dedicated servers (value is true/false)
#define SEARCH_DEDICATED_ONLY FName(TEXT("DEDICATEDONLY")) #define SEARCH_DEDICATED_ONLY FName(TEXT("DEDICATEDONLY"))
// Search for empty servers only (value is true/false) // Search for empty servers only (value is true/false)
#define SEARCH_EMPTY_SERVERS_ONLY FName(TEXT("EMPTYONLY")) #define SEARCH_EMPTY_SERVERS_ONLY FName(TEXT("EMPTYONLY"))
// Search for non empty servers only (value is true/false) // Search for non empty servers only (value is true/false)
#define SEARCH_NONEMPTY_SERVERS_ONLY FName(TEXT("NONEMPTYONLY")) #define SEARCH_NONEMPTY_SERVERS_ONLY FName(TEXT("NONEMPTYONLY"))
// Search for secure servers only (value is true/false) // Search for secure servers only (value is true/false)
#define SEARCH_SECURE_SERVERS_ONLY FName(TEXT("SECUREONLY")) #define SEARCH_SECURE_SERVERS_ONLY FName(TEXT("SECUREONLY"))
// Search for presence sessions only (value is true/false) // Search for presence sessions only (value is true/false)
#define SEARCH_PRESENCE FName(TEXT("PRESENCESEARCH")) #define SEARCH_PRESENCE FName(TEXT("PRESENCESEARCH"))
// Search for a match with min player availability (value is int) // Search for a match with min player availability (value is int)
#define SEARCH_MINSLOTSAVAILABLE FName(TEXT("MINSLOTSAVAILABLE")) #define SEARCH_MINSLOTSAVAILABLE FName(TEXT("MINSLOTSAVAILABLE"))
// Exclude all matches where any unique ids in a given array are present (value is string of the form "uniqueid1;uniqueid2;uniqueid3") // Exclude all matches where any unique ids in a given array are present (value is string of the form "uniqueid1;uniqueid2;uniqueid3")
#define SEARCH_EXCLUDE_UNIQUEIDS FName(TEXT("EXCLUDEUNIQUEIDS")) #define SEARCH_EXCLUDE_UNIQUEIDS FName(TEXT("EXCLUDEUNIQUEIDS"))
// User ID to search for session of // User ID to search for session of
#define SEARCH_USER FName(TEXT("SEARCHUSER")) #define SEARCH_USER FName(TEXT("SEARCHUSER"))
// Keywords to match in session search // Keywords to match in session search
#define SEARCH_KEYWORDS FName(TEXT("SEARCHKEYWORDS"))*/ #define SEARCH_KEYWORDS FName(TEXT("SEARCHKEYWORDS"))*/
if(bEmptyServersOnly) if (bEmptyServersOnly)
tem.Set(SEARCH_EMPTY_SERVERS_ONLY, true, EOnlineComparisonOp::Equals); tem.Set(SEARCH_EMPTY_SERVERS_ONLY, true, EOnlineComparisonOp::Equals);
if (bNonEmptyServersOnly) if (bNonEmptyServersOnly)
@@ -108,24 +110,28 @@ void UFindSessionsCallbackProxyAdvanced::Activate()
case EBPServerPresenceSearchType::DedicatedServersOnly: case EBPServerPresenceSearchType::DedicatedServersOnly:
{ {
tem.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals); //tem.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals);
} }
break; break;
case EBPServerPresenceSearchType::AllServers: case EBPServerPresenceSearchType::AllServers:
default: default:
{ {
bRunSecondSearch = true; // Only steam uses the separate searching flags currently
if (IOnlineSubsystem::DoesInstanceExist("STEAM"))
{
bRunSecondSearch = true;
SearchObjectDedicated = MakeShareable(new FOnlineSessionSearch); SearchObjectDedicated = MakeShareable(new FOnlineSessionSearch);
SearchObjectDedicated->MaxSearchResults = MaxResults; SearchObjectDedicated->MaxSearchResults = MaxResults;
SearchObjectDedicated->bIsLanQuery = bUseLAN; SearchObjectDedicated->bIsLanQuery = bUseLAN;
FOnlineSearchSettingsEx DedicatedOnly = tem; FOnlineSearchSettingsEx DedicatedOnly = tem;
tem.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals); tem.Set(SEARCH_PRESENCE, true, EOnlineComparisonOp::Equals);
DedicatedOnly.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals); //DedicatedOnly.Set(SEARCH_DEDICATED_ONLY, true, EOnlineComparisonOp::Equals);
SearchObjectDedicated->QuerySettings = DedicatedOnly; SearchObjectDedicated->QuerySettings = DedicatedOnly;
}
} }
break; break;
} }
@@ -162,23 +168,48 @@ void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
} }
} }
if (bSuccess && SearchObject.IsValid()) if (bSuccess)
{ {
// Just log the results for now, will need to add a blueprint-compatible search result struct if (bIsOnSecondSearch)
for (auto& Result : SearchObject->SearchResults)
{ {
FString ResultText = FString::Printf(TEXT("Found a session. Ping is %d"), Result.PingInMs); if (SearchObjectDedicated.IsValid())
{
// Just log the results for now, will need to add a blueprint-compatible search result struct
for (auto& Result : SearchObjectDedicated->SearchResults)
{
FString ResultText = FString::Printf(TEXT("Found a session. Ping is %d"), Result.PingInMs);
FFrame::KismetExecutionMessage(*ResultText, ELogVerbosity::Log); FFrame::KismetExecutionMessage(*ResultText, ELogVerbosity::Log);
FBlueprintSessionResult BPResult; FBlueprintSessionResult BPResult;
BPResult.OnlineResult = Result; BPResult.OnlineResult = Result;
SessionSearchResults.Add(BPResult); SessionSearchResults.Add(BPResult);
}
OnSuccess.Broadcast(SessionSearchResults);
return;
}
} }
if (!bRunSecondSearch) else
{ {
OnSuccess.Broadcast(SessionSearchResults); if (SearchObject.IsValid())
return; {
// Just log the results for now, will need to add a blueprint-compatible search result struct
for (auto& Result : SearchObject->SearchResults)
{
FString ResultText = FString::Printf(TEXT("Found a session. Ping is %d"), Result.PingInMs);
FFrame::KismetExecutionMessage(*ResultText, ELogVerbosity::Log);
FBlueprintSessionResult BPResult;
BPResult.OnlineResult = Result;
SessionSearchResults.Add(BPResult);
}
if (!bRunSecondSearch)
{
OnSuccess.Broadcast(SessionSearchResults);
return;
}
}
} }
} }
else else
@@ -186,7 +217,7 @@ void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
if (!bRunSecondSearch) if (!bRunSecondSearch)
{ {
// Need to account for only one of the searches failing // Need to account for only one of the searches failing
if(SessionSearchResults.Num() > 0) if (SessionSearchResults.Num() > 0)
OnSuccess.Broadcast(SessionSearchResults); OnSuccess.Broadcast(SessionSearchResults);
else else
OnFailure.Broadcast(SessionSearchResults); OnFailure.Broadcast(SessionSearchResults);
@@ -197,6 +228,7 @@ void UFindSessionsCallbackProxyAdvanced::OnCompleted(bool bSuccess)
if (bRunSecondSearch && ServerSearchType == EBPServerPresenceSearchType::AllServers) if (bRunSecondSearch && ServerSearchType == EBPServerPresenceSearchType::AllServers)
{ {
bRunSecondSearch = false; bRunSecondSearch = false;
bIsOnSecondSearch = true;
auto Sessions = Helper.OnlineSub->GetSessionInterface(); auto Sessions = Helper.OnlineSub->GetSessionInterface();
Sessions->FindSessions(*Helper.UserID, SearchObjectDedicated.ToSharedRef()); Sessions->FindSessions(*Helper.UserID, SearchObjectDedicated.ToSharedRef());
} }