Skip to content

Commit ee750b0

Browse files
keith-miller0xaravindhSivasankaran25
authored
Adds support for lists in the Unreal SDK #4029 (#4216)
* Add support for lists in Unreal SDK, resolves #4029 * Some doc and path fixes * Update Unreal SDK docs to show lists are supported * Wrapping Unreal SDK doc update in a feature check --------- Co-authored-by: Aravindh K <karavindh@google.com> Co-authored-by: Sivasankaran R <sivasankaranr@google.com>
1 parent f411326 commit ee750b0

File tree

4 files changed

+210
-6
lines changed

4 files changed

+210
-6
lines changed

sdks/unreal/Agones/Source/Agones/Classes/Classes.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,38 @@ struct FCounterResponse
434434
JsonObject->TryGetNumberField(TEXT("capacity"), Capacity);
435435
}
436436
};
437+
438+
USTRUCT(BlueprintType)
439+
struct FList
440+
{
441+
GENERATED_BODY()
442+
443+
FList()
444+
{
445+
}
446+
447+
UPROPERTY(BlueprintReadOnly, Category = "Agones")
448+
FString Name;
449+
450+
UPROPERTY(BlueprintReadOnly, Category = "Agones")
451+
int64 Capacity = 0;
452+
453+
UPROPERTY(BlueprintReadOnly, Category="Agones")
454+
TArray<FString> Values;
455+
456+
explicit FList(const TSharedPtr<FJsonObject> JsonObject)
457+
{
458+
JsonObject->TryGetStringField(TEXT("name"), Name);
459+
JsonObject->TryGetNumberField(TEXT("capacity"), Capacity);
460+
JsonObject->TryGetStringArrayField(TEXT("values"), Values);
461+
}
462+
};
463+
464+
USTRUCT(BlueprintType)
465+
struct FListValue
466+
{
467+
GENERATED_BODY()
468+
469+
UPROPERTY(BlueprintReadOnly, Category = "Agones")
470+
FString Value;
471+
};

sdks/unreal/Agones/Source/Agones/Private/AgonesComponent.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,101 @@ void UAgonesComponent::GetConnectedPlayers(
643643
Request->ProcessRequest();
644644
}
645645

646+
void UAgonesComponent::GetList(const FString& Key, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate)
647+
{
648+
const FString Path = FString::Printf(TEXT("v1beta1/lists/%s"), *Key);
649+
const FHttpRequestRef Request = BuildAgonesRequest(Path, FHttpVerb::Get, "");
650+
Request->OnProcessRequestComplete().BindWeakLambda(this,
651+
[SuccessDelegate, ErrorDelegate](FHttpRequestPtr HttpRequest, const FHttpResponsePtr HttpResponse, const bool bSucceeded) {
652+
TSharedPtr<FJsonObject> JsonObject;
653+
654+
if (!IsValidJsonResponse(JsonObject, bSucceeded, HttpResponse, ErrorDelegate))
655+
{
656+
return;
657+
}
658+
659+
SuccessDelegate.ExecuteIfBound(FList(JsonObject));
660+
});
661+
Request->ProcessRequest();
662+
}
663+
664+
void UAgonesComponent::UpdateList(const FString& Key, const FList& List, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate)
665+
{
666+
FString Json;
667+
if (!FJsonObjectConverter::UStructToJsonObjectString(List, Json))
668+
{
669+
ErrorDelegate.ExecuteIfBound({TEXT("Failed to serialize request")});
670+
return;
671+
}
672+
673+
const FString Path = FString::Printf(TEXT("v1beta1/lists/%s"), *Key);
674+
const FHttpRequestRef Request = BuildAgonesRequest(Path, FHttpVerb::Patch, Json);
675+
Request->OnProcessRequestComplete().BindWeakLambda(this,
676+
[SuccessDelegate, ErrorDelegate](FHttpRequestPtr HttpRequest, const FHttpResponsePtr HttpResponse, const bool bSucceeded) {
677+
TSharedPtr<FJsonObject> JsonObject;
678+
679+
if (!IsValidJsonResponse(JsonObject, bSucceeded, HttpResponse, ErrorDelegate))
680+
{
681+
return;
682+
}
683+
684+
SuccessDelegate.ExecuteIfBound(FList(JsonObject));
685+
});
686+
Request->ProcessRequest();
687+
}
688+
689+
void UAgonesComponent::AddListValue(const FString& Key, const FString& Value, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate)
690+
{
691+
const FListValue ListValue = {Value};
692+
FString Json;
693+
if (!FJsonObjectConverter::UStructToJsonObjectString(ListValue, Json))
694+
{
695+
ErrorDelegate.ExecuteIfBound({TEXT("Failed to serialize request")});
696+
return;
697+
}
698+
699+
const FString Path = FString::Printf(TEXT("v1beta1/lists/%s:addValue"), *Key);
700+
const FHttpRequestRef Request = BuildAgonesRequest(Path, FHttpVerb::Post, Json);
701+
Request->OnProcessRequestComplete().BindWeakLambda(this,
702+
[SuccessDelegate, ErrorDelegate](FHttpRequestPtr HttpRequest, const FHttpResponsePtr HttpResponse, const bool bSucceeded) {
703+
TSharedPtr<FJsonObject> JsonObject;
704+
705+
if (!IsValidJsonResponse(JsonObject, bSucceeded, HttpResponse, ErrorDelegate))
706+
{
707+
return;
708+
}
709+
710+
SuccessDelegate.ExecuteIfBound(FList(JsonObject));
711+
});
712+
Request->ProcessRequest();
713+
}
714+
715+
void UAgonesComponent::RemoveListValue(const FString& Key, const FString& Value, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate)
716+
{
717+
const FListValue ListValue = {Value};
718+
FString Json;
719+
if (!FJsonObjectConverter::UStructToJsonObjectString(ListValue, Json))
720+
{
721+
ErrorDelegate.ExecuteIfBound({TEXT("Failed to serialize request")});
722+
return;
723+
}
724+
725+
const FString Path = FString::Printf(TEXT("v1beta1/lists/%s:removeValue"), *Key);
726+
const FHttpRequestRef Request = BuildAgonesRequest(Path, FHttpVerb::Post, Json);
727+
Request->OnProcessRequestComplete().BindWeakLambda(this,
728+
[SuccessDelegate, ErrorDelegate](FHttpRequestPtr HttpRequest, const FHttpResponsePtr HttpResponse, const bool bSucceeded) {
729+
TSharedPtr<FJsonObject> JsonObject;
730+
731+
if (!IsValidJsonResponse(JsonObject, bSucceeded, HttpResponse, ErrorDelegate))
732+
{
733+
return;
734+
}
735+
736+
SuccessDelegate.ExecuteIfBound(FList(JsonObject));
737+
});
738+
Request->ProcessRequest();
739+
}
740+
646741
bool UAgonesComponent::IsValidResponse(const bool bSucceeded, const FHttpResponsePtr HttpResponse, FAgonesErrorDelegate ErrorDelegate)
647742
{
648743
if (!bSucceeded)

sdks/unreal/Agones/Source/Agones/Public/AgonesComponent.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ DECLARE_DYNAMIC_DELEGATE_OneParam(FShutdownDelegate, const FEmptyResponse&, Resp
6666

6767
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FConnectedDelegate, const FGameServerResponse&, Response);
6868

69+
DECLARE_DYNAMIC_DELEGATE_OneParam(FListDelegate, const FList&, Response);
70+
6971
class FHttpVerb
7072
{
7173
public:
@@ -352,6 +354,46 @@ class AGONES_API UAgonesComponent final : public UActorComponent
352354
UFUNCTION(BlueprintCallable, Category = "Agones | Beta | Counters")
353355
void SetCounterCapacity(FString Key, int64 Capacity, FSetCounterCapacityDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);
354356

357+
/**
358+
* \brief GetList retrieves the list’s properties with the key, returns the list’s information.
359+
* \param Key - Key to list value
360+
* \param SuccessDelegate - Called on Successful call.
361+
* \param ErrorDelegate - Called on Unsuccessful call.
362+
*/
363+
UFUNCTION(BlueprintCallable, Category = "Agones | Beta | Lists")
364+
void GetList(const FString& Key, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);
365+
366+
/**
367+
* \brief UpdateList updates the list’s properties with the key, such as its capacity and values,
368+
* and returns the updated list details. Use AddListValue or RemoveListValue for modifying the List.Values field.
369+
* \param Key - Key to list value
370+
* \param List - The list to replace the server list with
371+
* \param SuccessDelegate - Called on Successful call.
372+
* \param ErrorDelegate - Called on Unsuccessful call.
373+
*/
374+
UFUNCTION(BlueprintCallable, Category = "Agones | Beta | Lists")
375+
void UpdateList(const FString& Key, const FList& List, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);
376+
377+
/**
378+
* \brief AddListValue adds a new value to a list with the key and returns the list with this addition.
379+
* \param Key - Key to list value
380+
* \param Value - Value to add
381+
* \param SuccessDelegate - Called on Successful call.
382+
* \param ErrorDelegate - Called on Unsuccessful call.
383+
*/
384+
UFUNCTION(BlueprintCallable, Category = "Agones | Beta | Lists")
385+
void AddListValue(const FString& Key, const FString& Value, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);
386+
387+
/**
388+
* \brief RemoveListValue removes a value from the list with the key players and returns updated list.
389+
* \param Key - Key to list value
390+
* \param Value - Value to remove
391+
* \param SuccessDelegate - Called on Successful call.
392+
* \param ErrorDelegate - Called on Unsuccessful call.
393+
*/
394+
UFUNCTION(BlueprintCallable, Category = "Agones | Beta | Lists")
395+
void RemoveListValue(const FString& Key, const FString& Value, FListDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);
396+
355397
private:
356398
DECLARE_DELEGATE_OneParam(FUpdateCounterDelegate, const FEmptyResponse&);
357399
void UpdateCounter(const FString& Key, const int64* Count, const int64* Capacity, const int64* CountDiff, FUpdateCounterDelegate SuccessDelegate, FAgonesErrorDelegate ErrorDelegate);

site/content/en/docs/Guides/Client SDKs/unreal.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Check the [Client SDK Documentation]({{< relref "_index.md" >}}) for more detail
1111

1212
## SDK Functionality
1313

14+
{{% feature expiryVersion="1.51.0" %}}
1415
| Area | Action | Implemented |
1516
|----------------------|--------------------------|-------------------------------|
1617
| Lifecycle | Ready | ✔️ |
@@ -22,12 +23,12 @@ Check the [Client SDK Documentation]({{< relref "_index.md" >}}) for more detail
2223
| Configuration | Watch | ✔️ |
2324
| Metadata | SetAnnotation | ✔️ |
2425
| Metadata | SetLabel | ✔️ |
25-
| Counters | GetCounterCount | ✔️ |
26-
| Counters | SetCounterCount | ✔️ |
27-
| Counters | IncrementCounter | ✔️ |
28-
| Counters | DecrementCounter | ✔️ |
29-
| Counters | SetCounterCapacity | ✔️ |
30-
| Counters | GetCounterCapacity | ✔️ |
26+
| Counters | GetCounterCount | ✔️ |
27+
| Counters | SetCounterCount | ✔️ |
28+
| Counters | IncrementCounter | ✔️ |
29+
| Counters | DecrementCounter | ✔️ |
30+
| Counters | SetCounterCapacity | ✔️ |
31+
| Counters | GetCounterCapacity | ✔️ |
3132
| Lists | AppendListValue ||
3233
| Lists | DeleteListValue ||
3334
| Lists | SetListCapacity ||
@@ -42,6 +43,37 @@ Check the [Client SDK Documentation]({{< relref "_index.md" >}}) for more detail
4243
| Player Tracking | PlayerConnect | ✔️ |
4344
| Player Tracking | PlayerDisconnect | ✔️ |
4445
| Player Tracking | SetPlayerCapacity | ✔️ |
46+
{{% /feature %}}
47+
{{% feature publishVersion="1.51.0" %}}
48+
| Area | Action | Implemented |
49+
|----------------------|--------------------------|-------------------------------|
50+
| Lifecycle | Ready | ✔️ |
51+
| Lifecycle | Health | ✔️ |
52+
| Lifecycle | Reserve | ✔️ |
53+
| Lifecycle | Allocate | ✔️ |
54+
| Lifecycle | Shutdown | ✔️ |
55+
| Configuration | GameServer | ✔️ |
56+
| Configuration | Watch | ✔️ |
57+
| Metadata | SetAnnotation | ✔️ |
58+
| Metadata | SetLabel | ✔️ |
59+
| Counters | GetCounterCount | ✔️ |
60+
| Counters | SetCounterCount | ✔️ |
61+
| Counters | IncrementCounter | ✔️ |
62+
| Counters | DecrementCounter | ✔️ |
63+
| Counters | SetCounterCapacity | ✔️ |
64+
| Counters | GetCounterCapacity | ✔️ |
65+
| Lists | GetList | ✔️ |
66+
| Lists | UpdateList | ✔️ |
67+
| Lists | AddListValue | ✔️ |
68+
| Lists | RemoveListValue | ✔️ |
69+
| Player Tracking | GetConnectedPlayers | ✔️ |
70+
| Player Tracking | GetPlayerCapacity | ✔️ |
71+
| Player Tracking | GetPlayerCount | ✔️ |
72+
| Player Tracking | IsPlayerConnected | ✔️ |
73+
| Player Tracking | PlayerConnect | ✔️ |
74+
| Player Tracking | PlayerDisconnect | ✔️ |
75+
| Player Tracking | SetPlayerCapacity | ✔️ |
76+
{{% /feature %}}
4577

4678
Additional methods have been added for ease of use (both of which are enabled by default):
4779

0 commit comments

Comments
 (0)