Just0Abhi

EosHandler.h

Sep 16th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | Gaming | 0 0
  1. //
  2.  
  3. #pragma once
  4.  
  5. #include "CoreMinimal.h"
  6. #include "Blueprint/UserWidget.h"
  7. #include "Interfaces/OnlineIdentityInterface.h"
  8. #include "Interfaces/OnlineSessionInterface.h"
  9. #include "EosHandler.generated.h"
  10.  
  11. class IOnlineSubsystem;
  12.  
  13. /**
  14.  *
  15.  */
  16. UCLASS()
  17. class EOS_OSS_TUTORIAL_API UEosHandler : public UUserWidget
  18. {
  19.     GENERATED_BODY()
  20. public:
  21.     static void PrintToScreen(const FString& Message, const FColor& Color = FColor::Red, const float Duration = 5.f)
  22.     {
  23.         UE_LOG(LogTemp, Error, TEXT("%s"), *Message);
  24.         if(GEngine)
  25.             GEngine->AddOnScreenDebugMessage(-1, Duration, Color, Message);
  26.     }
  27.  
  28. protected:
  29.     UFUNCTION(BlueprintCallable)
  30.     void Login() const;
  31.  
  32.     UFUNCTION(BlueprintCallable)
  33.     void FindSessions(FName SearchKey, const FString& SearchValue);
  34.  
  35.     UFUNCTION(BlueprintCallable)
  36.     void CreateLobby(FName KeyName = "KeyName", FString KeyValue = "KeyValue");
  37. private:
  38.     IOnlineSubsystem* Subsystem;
  39.     TWeakPtr<IOnlineIdentity> Identity;
  40.     TWeakPtr<IOnlineSession> Session;
  41.  
  42.     FDelegateHandle LoginDelegateHandle, FindSessionsDelegateHandle, CreateLobbyDelegateHandle, JoinSessionDelegateHandle;
  43.  
  44.     FString ConnectString;
  45.  
  46.     UPROPERTY(EditAnywhere)
  47.     FName LobbyName = "LobbyName";
  48.  
  49.     UPROPERTY(EditAnywhere)
  50.     FString Map = "Game/Content/ThirdPerson/Maps/ThirdPersonMap?listen";
  51.  
  52.     FOnlineSessionSearchResult* SessionToJoin;
  53.  
  54.     void HandleLoginCompleted(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error);
  55.  
  56.     void HandleFindSessionsCompleted(const bool bWasSuccessful, TSharedRef<FOnlineSessionSearch> Search);
  57.     void HandleCreateLobbyCompleted(FName EosLobbyName, bool bWasSuccessful);
  58.     void JoinSession();
  59.     void HandleJoinSessionCompleted(FName SessionName, EOnJoinSessionCompleteResult::Type Result);
  60. };
  61.  
Tags: EosHandler.h
Advertisement
Add Comment
Please, Sign In to add comment