AuthenticateAsGuest (Unreal Engine)

- Declaration

static void AuthenticateAsGuest(const FString& Server, const FString& UserName, CavrnusAuthRecv OnSuccess, CavrnusError OnFailure);

Delegates Options:

typedef TFunction<void(const FCavrnusAuthentication&)> CavrnusAuthRecv;

typedef TFunction<void(const FString&)> CavrnusError;

DECLARE_DYNAMIC_DELEGATE_OneParam(FCavrnusAuthRecv, FCavrnusAuthentication, Auth);

DECLARE_DYNAMIC_DELEGATE_OneParam(FCavrnusError, FString, Error);

- Description

Creates a guest user account with a given name and joins as that user.

This is a good way of immediately getting your customers into a space without requiring any inputs from them.

Keep in mind that Guest accounts have limited permissions, which can be customized in the Management Console.

OnFailure generally shouldn’t trigger outside of rare cases.

OnSuccess provides a FCavrnusAuthentication which you can then store/load on your local machine to use on a future run without requiring the user to re-login.

- Blueprint Sample

 

image-20240312-233948.png

- Code Sample

AuthenticateAsGuestClass.h:

#include "Types/CavrnusAuthentication.h" #include "Types/CavrnusCallbackTypes.h" #include "AuthenticateAsGuestClass.generated.h" UCLASS() class MODULE_API UAuthenticateAsGuestClass { UAuthenticateAsGuestClass(); void Authenticate(); void OnAuthSuccess(FCavrnusAuthentication Authentication); void OnAuthFailure(FString Error); private: FCavrnusAuthRecv AuthSuccess; FCavrnusError AuthFailure; UPROPERTY() FString ServerAddress; UPROPERTY() FString GuestName; UPROPERTY() FCavrnusAuthentication Authentication; };

AuthenticateAsGuestClass.cpp

#include "AuthenticateAsGuestClass.h" #include "CavrnusFunctionLibrary.h" UAuthenticateAsGuestClass::UAuthenticateAsGuestClass() { AuthSuccess.BindUFunction(this, GET_FUNCTION_NAME_CHECKED(UAuthenticateAsGuestClass, OnAuthSuccess)); AuthFailure.BindUFunction(this, GET_FUNCTION_NAME_CHECKED(UAuthenticateAsGuestClass, OnAuthFailure)); } void UAuthenticateAsGuestClass::Authenticate() { UCavrnusFunctionLibrary::AuthenticateAsGuest( ServerAddress, GuestName, AuthSuccess, AuthFailure); } void UAuthenticateAsGuestClass::OnAuthSuccess(FCavrnusAuthentication Auth) { Authentication = Auth; UE_LOG(LogTemp, Log, TEXT("Successfully authenticated")); } void UAuthenticateAsGuestClass::OnAuthFailure(FString ErrorMessage) { Authentication = FCavrnusAuthentication(); UE_LOG(LogTemp, Error, TEXT("Failed to authenticate, error: %s"), *ErrorMessage); }

Â