Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a GUI for users to create deployments and rooms #23

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SDKDemo/Plugins/HathoraSDK/HathoraSDK.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"Name": "HathoraSDK",
"Type": "Runtime",
"LoadingPhase": "Default"
},
{
"Name": "HathoraSDKEditor",
"Type": "Editor",
"LoadingPhase": "PostDefault"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright Epic Games, Inc. All Rights Reserved.
// Copyright 2023 Hathora, Inc.

using UnrealBuildTool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "HathoraSDK.h"
#include "HathoraSDKModule.h"
#include "HathoraSDKConfig.h"
#include "HathoraSDKAppV1.h"
#include "HathoraSDKAuthV1.h"
#include "HathoraSDKDiscoveryV1.h"
#include "HathoraSDKLobbyV3.h"
Expand Down Expand Up @@ -32,6 +33,7 @@ void UHathoraSDK::GetRegionalPings(const FHathoraOnGetRegionalPings& OnComplete,
UHathoraSDK* UHathoraSDK::CreateHathoraSDK()
{
UHathoraSDK* SDK = NewObject<UHathoraSDK>();
SDK->AppV1 = NewObject<UHathoraSDKAppV1>();
SDK->AuthV1 = NewObject<UHathoraSDKAuthV1>();
SDK->DiscoveryV1 = NewObject<UHathoraSDKDiscoveryV1>();
SDK->LobbyV3 = NewObject<UHathoraSDKLobbyV3>();
Expand Down Expand Up @@ -129,13 +131,19 @@ void UHathoraSDK::SetAuthToken(FString Token)
SetCredentials(Config->GetAppId(), Security);
}

FString UHathoraSDK::GetAuthToken()
{
return AuthV1->GetAuthToken();
}

bool UHathoraSDK::IsLoggedIn()
{
return AuthV1->IsLoggedIn();
}

void UHathoraSDK::SetCredentials(FString AppId, FHathoraSDKSecurity Security)
{
AppV1->SetCredentials(AppId, Security);
AuthV1->SetCredentials(AppId, Security);
DiscoveryV1->SetCredentials(AppId, Security);
LobbyV3->SetCredentials(AppId, Security);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ void UHathoraSDKAPI::SetCredentials(FString InAppId, FHathoraSDKSecurity InSecur
this->Security = InSecurity;
}

FString UHathoraSDKAPI::GetAuthToken()
{
return Security.AuthToken;
}

void UHathoraSDKAPI::SendRequest(
FString Method,
FString Endpoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2023 Hathora, Inc.

#include "HathoraSDKAppV1.h"
#include "HathoraSDKModule.h"
#include "HathoraSDK.h"
#include "Serialization/JsonSerializer.h"
#include "Dom/JsonObject.h"
#include "Misc/DateTime.h"

FHathoraApplication UHathoraSDKAppV1::ParseApplication(TSharedPtr<FJsonObject> Object)
{
FHathoraApplication Application;

TSharedPtr<FJsonValue> DeletedBy = Object->TryGetField(TEXT("deletedBy"));

Application.bDeleted = DeletedBy.IsValid() && !DeletedBy->IsNull();

if (Application.bDeleted)
{
Application.DeletedBy = DeletedBy->AsString();

FDateTime::ParseIso8601(
*Object->GetStringField(TEXT("deletedAt")),
Application.DeletedAt
);
}

FDateTime::ParseIso8601(
*Object->GetStringField(TEXT("createdAt")),
Application.CreatedAt
);

Application.CreatedBy = Object->GetStringField(TEXT("createdBy"));
Application.OrgId = Object->GetStringField(TEXT("orgId"));

Application.AuthConfiguration.bGoogleEnabled = Object->HasField(TEXT("google"));
Application.AuthConfiguration.bNicknameEnabled = Object->HasField(TEXT("nickname"));
Application.AuthConfiguration.bAnonymousEnabled = Object->HasField(TEXT("anonymous"));

if (Application.AuthConfiguration.bGoogleEnabled)
{
TSharedPtr<FJsonObject> Google = Object->GetObjectField(TEXT("google"));
Application.AuthConfiguration.Google.ClientId = Google->GetStringField(TEXT("clientId"));
}

Application.AppSecret = Object->GetStringField(TEXT("appSecret"));
Application.AppId = Object->GetStringField(TEXT("appId"));
Application.AppName = Object->GetStringField(TEXT("appName"));

// TODO: deployment?

return Application;
}

void UHathoraSDKAppV1::GetApps(FHathoraOnGetApps OnComplete)
{
SendRequest(
TEXT("GET"),
TEXT("/apps/v1/list"),
[OnComplete](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccess) mutable
{
FHathoraGetAppsResult Result;
if (bSuccess && Response.IsValid())
{
Result.StatusCode = Response->GetResponseCode();
FString Content = Response->GetContentAsString();

if (Result.StatusCode == 200)
{
TArray<TSharedPtr<FJsonValue>> OutArray;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Content);
FJsonSerializer::Deserialize(Reader, OutArray);

for (TSharedPtr<FJsonValue> Value : OutArray)
{
TSharedPtr<FJsonObject> Object = Value->AsObject();
Result.Data.Add(ParseApplication(Object));
}
}
else
{
Result.ErrorMessage = UHathoraSDK::ParseErrorMessage(Content);
}
}
else
{
Result.ErrorMessage = TEXT("[GetApps] Error: unknown error");
}

if (!Result.ErrorMessage.IsEmpty())
{
UE_LOG(LogHathoraSDK, Error, TEXT("[GetApps] Error: %s"), *Result.ErrorMessage);
}

if (!OnComplete.ExecuteIfBound(Result))
{
UE_LOG(LogHathoraSDK, Warning, TEXT("[GetApps] function pointer was not valid, so OnComplete will not be called"));
}
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Kismet/BlueprintFunctionLibrary.h"
#include "HathoraSDK.generated.h"

class UHathoraSDKAppV1;
class UHathoraSDKAuthV1;
class UHathoraSDKDiscoveryV1;
class UHathoraSDKLobbyV3;
Expand Down Expand Up @@ -53,9 +54,15 @@ class HATHORASDK_API UHathoraSDK : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintCallable, Category = "HathoraSDK")
void SetAuthToken(FString Token);

UFUNCTION(BlueprintPure, Category = "HathoraSDK")
FString GetAuthToken();

UFUNCTION(BlueprintPure, Category = "HathoraSDK")
bool IsLoggedIn();

UPROPERTY(BlueprintReadOnly, Category="HathoraSDK")
UHathoraSDKAppV1* AppV1;

UPROPERTY(BlueprintReadOnly, Category="HathoraSDK")
UHathoraSDKAuthV1* AuthV1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class HATHORASDK_API UHathoraSDKAPI : public UBlueprintFunctionLibrary
public:
void SetCredentials(FString AppId, FHathoraSDKSecurity Security);

FString GetAuthToken();

protected:
void SendRequest(
FString Method,
Expand Down
105 changes: 105 additions & 0 deletions SDKDemo/Plugins/HathoraSDK/Source/HathoraSDK/Public/HathoraSDKAppV1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2023 Hathora, Inc.

#pragma once

#include "CoreMinimal.h"
#include "HathoraSDKAPI.h"
#include "HathoraTypes.h"
#include "Misc/DateTime.h"
#include "HathoraSDKAppV1.generated.h"

USTRUCT(BlueprintType)
struct FHathoraGoogleAuthConfiguration
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString ClientId;
};

USTRUCT(BlueprintType)
struct FHathoraApplicationAuthConfiguration
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "Default")
bool bGoogleEnabled = false;

UPROPERTY(BlueprintReadOnly, Category = "Default")
bool bNicknameEnabled = false;

UPROPERTY(BlueprintReadOnly, Category = "Default")
bool bAnonymousEnabled = false;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FHathoraGoogleAuthConfiguration Google;
};

USTRUCT(BlueprintType)
struct FHathoraApplication
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "Default")
bool bDeleted = false;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString DeletedBy;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FDateTime DeletedAt;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FDateTime CreatedAt;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString CreatedBy;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString OrgId;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FHathoraApplicationAuthConfiguration AuthConfiguration;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString AppSecret;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString AppId;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString AppName;

// TODO: deployment?
};

USTRUCT(BlueprintType)
struct FHathoraGetAppsResult
{
GENERATED_BODY()

UPROPERTY(BlueprintReadOnly, Category = "Default")
int32 StatusCode = 0;

UPROPERTY(BlueprintReadOnly, Category = "Default")
FString ErrorMessage;

UPROPERTY(BlueprintReadOnly, Category = "Default")
TArray<FHathoraApplication> Data;
};

UCLASS(BlueprintType)
class HATHORASDK_API UHathoraSDKAppV1 : public UHathoraSDKAPI
{
GENERATED_BODY()

public:
typedef TDelegate<void(const FHathoraGetAppsResult&)> FHathoraOnGetApps;

// Returns an unsorted list of your organization’s applications.
// An application is uniquely identified by an appId.
void GetApps(FHathoraOnGetApps OnComplete);

private:
static FHathoraApplication ParseApplication(TSharedPtr<FJsonObject> Object);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 Hathora, Inc.

using UnrealBuildTool;

public class HathoraSDKEditor : ModuleRules
{
public HathoraSDKEditor(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);


PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);


PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
"WorkspaceMenuStructure",
"InputCore",
"HathoraSDK",
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
Loading