Skip to content

Commit

Permalink
Release 2.10.0 (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Gehorsam authored Apr 4, 2024
1 parent 7dd3a72 commit 0f8ab37
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/).
### Unreleased

### [2.10.0] - 2024-04-04
### Changed
- Changed `ENakamaErrorCode` enum casts to match official GRPC error codes. *Any user client code checking against specific error values should be aware of this change.*

### Added
- Added `UNakamaClient.BanGroupUsers`.

### [2.9.9] - 2024-03-28
### Fixed
- Fixed return payload of `UNakamaRealtimeClient.FollowUsers`.
Expand Down
2 changes: 1 addition & 1 deletion Nakama/Nakama.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 2400,
"VersionName": "2.9.9",
"VersionName": "2.10.0",
"FriendlyName": "Nakama client",
"Description": "A UE4 and UE5 client for the Nakama server.",
"Category": "HeroicLabs.Nakama",
Expand Down
116 changes: 116 additions & 0 deletions Nakama/Source/NakamaUnreal/Private/NakamaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,32 @@ void UNakamaClient::KickGroupUsers(
KickGroupUsers(Session, GroupId, UserIds, successCallback, errorCallback);
}

void UNakamaClient::BanGroupUsers(
UNakamaSession* Session,
const FString& GroupId,
const TArray<FString>& UserIds,
FOnBanGroupUsers Success,
FOnError Error)
{
auto successCallback = [this, Success]()
{
if(!FNakamaUtils::IsClientActive(this))
return;

Success.Broadcast();
};

auto errorCallback = [this, Error](const FNakamaError& error)
{
if(!FNakamaUtils::IsClientActive(this))
return;

Error.Broadcast(error);
};

BanGroupUsers(Session, GroupId, UserIds, successCallback, errorCallback);
}

void UNakamaClient::DemoteGroupUsers(
UNakamaSession* Session,
const FString& GroupId,
Expand Down Expand Up @@ -6000,6 +6026,96 @@ void UNakamaClient::KickGroupUsers(
HttpRequest->ProcessRequest();
}

void UNakamaClient::BanGroupUsers(
UNakamaSession* Session,
const FString& GroupId,
const TArray<FString>& UserIds,
TFunction<void()> SuccessCallback,
TFunction<void(const FNakamaError& Error)> ErrorCallback)
{
// Setup the endpoint
const FString Endpoint = FString::Printf(TEXT("/v2/group/%s/ban"), *GroupId);

// Verify the session
if (!IsSessionValid(Session, ErrorCallback))
{
return;
}

// Setup the query parameters
TMultiMap<FString, FString> QueryParams;
if (UserIds.Num() > 0)
{
for (const FString& UserId : UserIds)
{
QueryParams.Add(TEXT("user_ids"), UserId);
}
}

// Make the request
const auto HttpRequest = MakeRequest(Endpoint, TEXT(""), ENakamaRequestMethod::POST, QueryParams, Session->GetAuthToken());

// Lock the ActiveRequests mutex to protect concurrent access
FScopeLock Lock(&ActiveRequestsMutex);

// Add the HttpRequest to ActiveRequests
ActiveRequests.Add(HttpRequest);

// Bind the response callback and handle the response
HttpRequest->OnProcessRequestComplete().BindLambda([SuccessCallback, ErrorCallback, this](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bSuccess) {

if (!IsValidLowLevel())
{
return;
}

// Lock the ActiveRequests mutex to protect concurrent access
FScopeLock Lock(&ActiveRequestsMutex);

if (ActiveRequests.Contains(Request))
{
if (bSuccess && Response.IsValid())
{
const FString ResponseBody = Response->GetContentAsString();

// Check if Request was successful
if (IsResponseSuccessful(Response->GetResponseCode()))
{
// Check for Success Callback
if (SuccessCallback)
{
SuccessCallback();
}
}
else
{
// Check for Error Callback
if (ErrorCallback)
{
const FNakamaError Error(ResponseBody);
ErrorCallback(Error);
}
}
}
else
{
// Handle Invalid Response
if (ErrorCallback)
{
const FNakamaError RequestError = CreateRequestFailureError();
ErrorCallback(RequestError);
}
}

// Remove the HttpRequest from ActiveRequests
ActiveRequests.Remove(Request);
}
});

// Process the request
HttpRequest->ProcessRequest();
}

void UNakamaClient::JoinGroup(
UNakamaSession* Session,
const FString& GroupId,
Expand Down
36 changes: 26 additions & 10 deletions Nakama/Source/NakamaUnreal/Private/NakamaError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,39 @@ ENakamaErrorCode FNakamaError::ConvertNakamaErrorCode(int32 CodeValue)
switch (CodeValue)
{
case 0:
return ENakamaErrorCode::Unknown;
return ENakamaErrorCode::Ok;
case 1:
return ENakamaErrorCode::NotFound;
return ENakamaErrorCode::Cancelled;
case 2:
return ENakamaErrorCode::AlreadyExists;
return ENakamaErrorCode::Unknown;
case 3:
return ENakamaErrorCode::InvalidArgument;
case 4:
return ENakamaErrorCode::Unauthenticated;
return ENakamaErrorCode::DeadlineExceeded;
case 5:
return ENakamaErrorCode::NotFound;
case 6:
return ENakamaErrorCode::AlreadyExists;
case 7:
return ENakamaErrorCode::PermissionDenied;
case -1:
return ENakamaErrorCode::ConnectionError;
case -2:
return ENakamaErrorCode::InternalError;
case -3:
return ENakamaErrorCode::CancelledByUser;
case 8:
return ENakamaErrorCode::ResourceExhausted;
case 9:
return ENakamaErrorCode::FailedPrecondition;
case 10:
return ENakamaErrorCode::Aborted;
case 11:
return ENakamaErrorCode::OutOfRange;
case 12:
return ENakamaErrorCode::Unimplemented;
case 13:
return ENakamaErrorCode::Internal;
case 14:
return ENakamaErrorCode::Unavailable;
case 15:
return ENakamaErrorCode::DataLoss;
case 16:
return ENakamaErrorCode::Unauthenticated;
default:
return ENakamaErrorCode::Unknown;
}
Expand Down
36 changes: 36 additions & 0 deletions Nakama/Source/NakamaUnreal/Public/NakamaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,24 @@ class NAKAMAUNREAL_API UNakamaClient : public UObject
FOnError Error
);

/**
* Ban one or more users from the group.
*
* @param GroupId The id of the group.
* @param UserIds The ids of the users to ban.
* @param Session The session of the user.
* @param Success Delegate called upon successfully banning users from the group.
* @param Error Delegate called if an error occurs, detailing the failure.
*/
UFUNCTION(Category = "Nakama|Groups")
void BanGroupUsers(
UNakamaSession* Session,
const FString& GroupId,
const TArray<FString>& UserIds,
FOnBanGroupUsers Success,
FOnError Error
);

/**
* Demote a set of users in a group to the next role down.
*
Expand Down Expand Up @@ -2311,6 +2329,24 @@ class NAKAMAUNREAL_API UNakamaClient : public UObject
TFunction<void(const FNakamaError& Error)> ErrorCallback
);


/**
* Ban one or more users from the group.
*
* @param GroupId The id of the group.
* @param UserIds The ids of the users to ban.
* @param Session The session of the user.
* @param SuccessCallback Callback invoked upon successfully banning users from the group.
* @param ErrorCallback Callback invoked if an error occurs, detailing the failure.
*/
void BanGroupUsers(
UNakamaSession *Session,
const FString& GroupId,
const TArray<FString>& UserIds,
TFunction<void()> SuccessCallback,
TFunction<void(const FNakamaError& Error)> ErrorCallback
);

/**
* Join a group if it has open membership or request to join it.
*
Expand Down
24 changes: 16 additions & 8 deletions Nakama/Source/NakamaUnreal/Public/NakamaError.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@
UENUM(BlueprintType)
enum class ENakamaErrorCode : uint8
{
Unknown = 0 UMETA(DisplayName = "Unknown"),
NotFound = 1 UMETA(DisplayName = "Not Found"),
AlreadyExists = 2 UMETA(DisplayName = "Already Exists"),
Ok = 0 UMETA(DisplayName = "Ok"),
Cancelled = 1 UMETA(DisplayName = "Cancelled"),
Unknown = 2 UMETA(DisplayName = "Unknown"),
InvalidArgument = 3 UMETA(DisplayName = "Invalid Argument"),
Unauthenticated = 4 UMETA(DisplayName = "Unauthenticated"),
PermissionDenied = 5 UMETA(DisplayName = "Permission Denied"),
ConnectionError = 6 UMETA(DisplayName = "Connection Error"), // -1
InternalError = 7 UMETA(DisplayName = "Internal Error"), // -2
CancelledByUser = 8 UMETA(DisplayName = "Cancelled By User"), //-3
DeadlineExceeded = 4 UMETA(DisplayName = "Deadline Exceeded"),
NotFound = 5 UMETA(DisplayName = "Not Found"),
AlreadyExists = 6 UMETA(DisplayName = "Already Exists"),
PermissionDenied = 7 UMETA(DisplayName = "Permission Denied"),
ResourceExhausted = 8 UMETA(DisplayName = "Resource Exhausted"),
FailedPrecondition = 9 UMETA(DisplayName = "Failed Precondition"),
Aborted = 10 UMETA(DisplayName = "Aborted"),
OutOfRange = 11 UMETA(DisplayName = "Out Of Range"),
Unimplemented = 12 UMETA(DisplayName = "Unimplemented"),
Internal = 13 UMETA(DisplayName = "Internal"),
Unavailable = 14 UMETA(DisplayName = "Unavailable"),
DataLoss = 15 UMETA(DisplayName = "Data Loss"),
Unauthenticated = 16 UMETA(DisplayName = "Unauthenticated")
};

USTRUCT(BlueprintType)
Expand Down

0 comments on commit 0f8ab37

Please sign in to comment.