Skip to content

Commit

Permalink
Replace DiscoveryV1 with DiscoveryV2 (#29)
Browse files Browse the repository at this point in the history
* Replace DiscoveryV1 with DiscoveryV2

This will enable Dallas region for ping checks
  • Loading branch information
jchu231 authored Jun 1, 2024
1 parent be7802d commit 04825c4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "HathoraSDKModule.h"
#include "HathoraSDKConfig.h"
#include "HathoraSDKAuthV1.h"
#include "HathoraSDKDiscoveryV1.h"
#include "HathoraSDKDiscoveryV2.h"
#include "HathoraSDKLobbyV3.h"
#include "HathoraSDKProcessesV2.h"
#include "HathoraSDKRoomV2.h"
Expand All @@ -17,7 +17,7 @@ void UHathoraSDK::GetRegionalPings(const FHathoraOnGetRegionalPings& OnComplete,
{
UHathoraSDK* SDK = UHathoraSDK::CreateHathoraSDK();
SDK->AddToRoot(); // make sure this doesn't get garbage collected
SDK->DiscoveryV1->GetRegionalPings(
SDK->DiscoveryV2->GetRegionalPings(
FHathoraOnGetRegionalPings::CreateLambda(
[OnComplete, SDK](const FHathoraRegionPings& Result)
{
Expand All @@ -33,7 +33,7 @@ UHathoraSDK* UHathoraSDK::CreateHathoraSDK()
{
UHathoraSDK* SDK = NewObject<UHathoraSDK>();
SDK->AuthV1 = NewObject<UHathoraSDKAuthV1>();
SDK->DiscoveryV1 = NewObject<UHathoraSDKDiscoveryV1>();
SDK->DiscoveryV2 = NewObject<UHathoraSDKDiscoveryV2>();
SDK->LobbyV3 = NewObject<UHathoraSDKLobbyV3>();
SDK->ProcessesV2 = NewObject<UHathoraSDKProcessesV2>();
SDK->RoomV2 = NewObject<UHathoraSDKRoomV2>();
Expand Down Expand Up @@ -137,7 +137,7 @@ bool UHathoraSDK::IsLoggedIn()
void UHathoraSDK::SetCredentials(FString AppId, FHathoraSDKSecurity Security)
{
AuthV1->SetCredentials(AppId, Security);
DiscoveryV1->SetCredentials(AppId, Security);
DiscoveryV2->SetCredentials(AppId, Security);
LobbyV3->SetCredentials(AppId, Security);
ProcessesV2->SetCredentials(AppId, Security);
RoomV2->SetCredentials(AppId, Security);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright 2023 Hathora, Inc.

#include "HathoraSDKDiscoveryV1.h"
#include "HathoraSDKDiscoveryV2.h"
#include "HathoraSDKModule.h"
#include "HathoraSDKConfig.h"
#include "JsonObjectConverter.h"
#include "Icmp.h"

void UHathoraSDKDiscoveryV1::GetPingServiceEndpoints(const FHathoraOnGetPingServiceEndpoints& OnComplete)
void UHathoraSDKDiscoveryV2::GetPingServiceEndpoints(const FHathoraOnGetPingServiceEndpoints& OnComplete)
{
SendRequest(
TEXT("GET"),
TEXT("/discovery/v1/ping"),
TEXT("/discovery/v2/ping"),
[OnComplete](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccess) mutable
{
TArray<FHathoraDiscoveredPingEndpoint> PingEndpointsResult;
Expand All @@ -30,7 +30,7 @@ void UHathoraSDKDiscoveryV1::GetPingServiceEndpoints(const FHathoraOnGetPingServ
});
}

void UHathoraSDKDiscoveryV1::GetRegionalPings(const FHathoraOnGetRegionalPings& OnComplete, int32 InNumPingsPerRegion)
void UHathoraSDKDiscoveryV2::GetRegionalPings(const FHathoraOnGetRegionalPings& OnComplete, int32 InNumPingsPerRegion)
{
if (InNumPingsPerRegion <= 0)
{
Expand All @@ -41,7 +41,7 @@ void UHathoraSDKDiscoveryV1::GetRegionalPings(const FHathoraOnGetRegionalPings&
OnGetRegionalPingsComplete = OnComplete;
NumPingsPerRegion = InNumPingsPerRegion;
GetPingServiceEndpoints(
UHathoraSDKDiscoveryV1::FHathoraOnGetPingServiceEndpoints::CreateLambda(
UHathoraSDKDiscoveryV2::FHathoraOnGetPingServiceEndpoints::CreateLambda(
[this](const TArray<FHathoraDiscoveredPingEndpoint>& Endpoints)
{
PingEndpoints = Endpoints;
Expand All @@ -53,7 +53,7 @@ void UHathoraSDKDiscoveryV1::GetRegionalPings(const FHathoraOnGetRegionalPings&
);
}

void UHathoraSDKDiscoveryV1::PingEachRegion()
void UHathoraSDKDiscoveryV2::PingEachRegion()
{
// recursively call this function until we have pinged each region
// the desired number of times, and then aggregate the results and return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2023 Hathora, Inc.

#include "LatentActions/DiscoveryV1/HathoraDiscoveryV1GetPingServiceEndpoints.h"
#include "LatentActions/DiscoveryV2/HathoraDiscoveryV2GetPingServiceEndpoints.h"
#include "HathoraSDKModule.h"

UHathoraDiscoveryV1GetPingServiceEndpoints *UHathoraDiscoveryV1GetPingServiceEndpoints::GetPingServiceEndpoints(
UHathoraSDKDiscoveryV1 *HathoraSDKDiscoveryV1,
UHathoraDiscoveryV2GetPingServiceEndpoints *UHathoraDiscoveryV2GetPingServiceEndpoints::GetPingServiceEndpoints(
UHathoraSDKDiscoveryV2 *HathoraSDKDiscoveryV2,
UObject *WorldContextObject
) {
UHathoraDiscoveryV1GetPingServiceEndpoints *Action = NewObject<UHathoraDiscoveryV1GetPingServiceEndpoints>();
Action->HathoraSDKDiscoveryV1 = HathoraSDKDiscoveryV1;
UHathoraDiscoveryV2GetPingServiceEndpoints *Action = NewObject<UHathoraDiscoveryV2GetPingServiceEndpoints>();
Action->HathoraSDKDiscoveryV2 = HathoraSDKDiscoveryV2;
Action->RegisterWithGameInstance(WorldContextObject);
return Action;
}

void UHathoraDiscoveryV1GetPingServiceEndpoints::Activate()
void UHathoraDiscoveryV2GetPingServiceEndpoints::Activate()
{
if (!IsValid(this) || !IsValid(HathoraSDKDiscoveryV1))
if (!IsValid(this) || !IsValid(HathoraSDKDiscoveryV2))
{
UE_LOG(LogHathoraSDK, Error, TEXT("GetPingServiceEndpoints failed because the underlying Hathora API is not valid."));

Expand All @@ -27,8 +27,8 @@ void UHathoraDiscoveryV1GetPingServiceEndpoints::Activate()
return;
}

HathoraSDKDiscoveryV1->GetPingServiceEndpoints(
UHathoraSDKDiscoveryV1::FHathoraOnGetPingServiceEndpoints::CreateLambda(
HathoraSDKDiscoveryV2->GetPingServiceEndpoints(
UHathoraSDKDiscoveryV2::FHathoraOnGetPingServiceEndpoints::CreateLambda(
[this](const TArray<FHathoraDiscoveredPingEndpoint>& Endpoints)
{
OnComplete.Broadcast(Endpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "HathoraSDK.generated.h"

class UHathoraSDKAuthV1;
class UHathoraSDKDiscoveryV1;
class UHathoraSDKDiscoveryV2;
class UHathoraSDKLobbyV3;
class UHathoraSDKProcessesV2;
class UHathoraSDKRoomV2;
Expand Down Expand Up @@ -60,7 +60,7 @@ class HATHORASDK_API UHathoraSDK : public UBlueprintFunctionLibrary
UHathoraSDKAuthV1* AuthV1;

UPROPERTY(BlueprintReadOnly, Category="HathoraSDK")
UHathoraSDKDiscoveryV1* DiscoveryV1;
UHathoraSDKDiscoveryV2* DiscoveryV2;

UPROPERTY(BlueprintReadOnly, Category="HathoraSDK")
UHathoraSDKLobbyV3* LobbyV3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "CoreMinimal.h"
#include "HathoraSDKAPI.h"
#include "HathoraTypes.h"
#include "HathoraSDKDiscoveryV1.generated.h"
#include "HathoraSDKDiscoveryV2.generated.h"

UCLASS(BlueprintType)
class HATHORASDK_API UHathoraSDKDiscoveryV1 : public UHathoraSDKAPI
class HATHORASDK_API UHathoraSDKDiscoveryV2 : public UHathoraSDKAPI
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum class EHathoraCloudRegion : uint8
Los_Angeles,
Washington_DC,
Chicago,
Dallas,
London,
Frankfurt,
Mumbai,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#include "CoreMinimal.h"
#include "Kismet/BlueprintAsyncActionBase.h"
#include "HathoraTypes.h"
#include "HathoraSDKDiscoveryV1.h"
#include "HathoraDiscoveryV1GetPingServiceEndpoints.generated.h"
#include "HathoraSDKDiscoveryV2.h"
#include "HathoraDiscoveryV2GetPingServiceEndpoints.generated.h"

UDELEGATE()
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(
FHathoraDiscoveryV1GetPingServiceEndpointsComplete, const TArray<FHathoraDiscoveredPingEndpoint>&, Endpoints
FHathoraDiscoveryV2GetPingServiceEndpointsComplete, const TArray<FHathoraDiscoveredPingEndpoint>&, Endpoints
);

UCLASS()
class HATHORASDK_API UHathoraDiscoveryV1GetPingServiceEndpoints : public UBlueprintAsyncActionBase
class HATHORASDK_API UHathoraDiscoveryV2GetPingServiceEndpoints : public UBlueprintAsyncActionBase
{
GENERATED_BODY()

Expand All @@ -28,17 +28,17 @@ class HATHORASDK_API UHathoraDiscoveryV1GetPingServiceEndpoints : public UBluepr
BlueprintCallable,
meta =
(BlueprintInternalUseOnly = "true",
Category = "HathoraSDK | DiscoveryV1",
Category = "HathoraSDK | DiscoveryV2",
WorldContext = "WorldContextObject")
)
static UHathoraDiscoveryV1GetPingServiceEndpoints *GetPingServiceEndpoints(
UHathoraSDKDiscoveryV1 *HathoraSDKDiscoveryV1,
static UHathoraDiscoveryV2GetPingServiceEndpoints *GetPingServiceEndpoints(
UHathoraSDKDiscoveryV2 *HathoraSDKDiscoveryV2,
UObject *WorldContextObject
);

UPROPERTY(BlueprintAssignable)
FHathoraDiscoveryV1GetPingServiceEndpointsComplete OnComplete;
FHathoraDiscoveryV2GetPingServiceEndpointsComplete OnComplete;

UPROPERTY()
UHathoraSDKDiscoveryV1 *HathoraSDKDiscoveryV1;
UHathoraSDKDiscoveryV2 *HathoraSDKDiscoveryV2;
};

0 comments on commit 04825c4

Please sign in to comment.