diff --git a/Binaries/Win32/UE4-AdvancedSessions-Win32-DebugGame.lib.REMOVED.git-id b/Binaries/Win32/UE4-AdvancedSessions-Win32-DebugGame.lib.REMOVED.git-id index 163d32a..93a8d78 100644 --- a/Binaries/Win32/UE4-AdvancedSessions-Win32-DebugGame.lib.REMOVED.git-id +++ b/Binaries/Win32/UE4-AdvancedSessions-Win32-DebugGame.lib.REMOVED.git-id @@ -1 +1 @@ -a76786bb53d1bc69ee7cdab9e4aa673802d31bf2 \ No newline at end of file +74159387ae4c0dfa551782c1a573d879e76e7c94 \ No newline at end of file diff --git a/Binaries/Win32/UE4-AdvancedSessions-Win32-Shipping.lib.REMOVED.git-id b/Binaries/Win32/UE4-AdvancedSessions-Win32-Shipping.lib.REMOVED.git-id index b3807e2..dae5ab4 100644 --- a/Binaries/Win32/UE4-AdvancedSessions-Win32-Shipping.lib.REMOVED.git-id +++ b/Binaries/Win32/UE4-AdvancedSessions-Win32-Shipping.lib.REMOVED.git-id @@ -1 +1 @@ -21bebdf84ebf3baa91d180db157a1f2e0dfbc4c0 \ No newline at end of file +e9c0072ee5f48736c5b6cb9d80f1d42378271f15 \ No newline at end of file diff --git a/Binaries/Win32/UE4-AdvancedSessions.lib.REMOVED.git-id b/Binaries/Win32/UE4-AdvancedSessions.lib.REMOVED.git-id index 9652fcb..9980f2e 100644 --- a/Binaries/Win32/UE4-AdvancedSessions.lib.REMOVED.git-id +++ b/Binaries/Win32/UE4-AdvancedSessions.lib.REMOVED.git-id @@ -1 +1 @@ -4ace3e4516cc2a4e8f0b950cd9ceb22f25edfd00 \ No newline at end of file +ae6509d9c9a5a5b53e37150891505d9cebbc4071 \ No newline at end of file diff --git a/Binaries/Win64/UE4-AdvancedSessions-Win64-DebugGame.lib.REMOVED.git-id b/Binaries/Win64/UE4-AdvancedSessions-Win64-DebugGame.lib.REMOVED.git-id index 6d8ed93..2af150a 100644 --- a/Binaries/Win64/UE4-AdvancedSessions-Win64-DebugGame.lib.REMOVED.git-id +++ b/Binaries/Win64/UE4-AdvancedSessions-Win64-DebugGame.lib.REMOVED.git-id @@ -1 +1 @@ -d2f96ab9defedded126a4780a18c04ff4d92b8bc \ No newline at end of file +23b76fcc5841b5a13d093c31596b816e921eb107 \ No newline at end of file diff --git a/Binaries/Win64/UE4-AdvancedSessions-Win64-Shipping.lib.REMOVED.git-id b/Binaries/Win64/UE4-AdvancedSessions-Win64-Shipping.lib.REMOVED.git-id index 2b6587f..a4d578a 100644 --- a/Binaries/Win64/UE4-AdvancedSessions-Win64-Shipping.lib.REMOVED.git-id +++ b/Binaries/Win64/UE4-AdvancedSessions-Win64-Shipping.lib.REMOVED.git-id @@ -1 +1 @@ -aff3301f274803705d0ef3315be24a6b3be274cf \ No newline at end of file +1f54a896a8f905d9794a64b999ee51afdcf6bdd4 \ No newline at end of file diff --git a/Binaries/Win64/UE4-AdvancedSessions.lib.REMOVED.git-id b/Binaries/Win64/UE4-AdvancedSessions.lib.REMOVED.git-id index 23ee66c..7d84b58 100644 --- a/Binaries/Win64/UE4-AdvancedSessions.lib.REMOVED.git-id +++ b/Binaries/Win64/UE4-AdvancedSessions.lib.REMOVED.git-id @@ -1 +1 @@ -e3d98226a589c3853040dbd109aec7be7dcc3742 \ No newline at end of file +23dbc3bb8dea26aeb165cdc493930866032ed598 \ No newline at end of file diff --git a/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.dll b/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.dll index 0cac63c..09d840e 100644 Binary files a/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.dll and b/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.dll differ diff --git a/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.pdb.REMOVED.git-id b/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.pdb.REMOVED.git-id index cf16f13..450b523 100644 --- a/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.pdb.REMOVED.git-id +++ b/Binaries/Win64/UE4Editor-AdvancedSessions-Win64-DebugGame.pdb.REMOVED.git-id @@ -1 +1 @@ -0f13228cdcdc42445bc1fe94748f423a786a21fe \ No newline at end of file +205342f06ff0dfeee1431d6af7534a2d20c9f38f \ No newline at end of file diff --git a/Binaries/Win64/UE4Editor-AdvancedSessions.dll b/Binaries/Win64/UE4Editor-AdvancedSessions.dll index ead71b0..7b7a7cc 100644 Binary files a/Binaries/Win64/UE4Editor-AdvancedSessions.dll and b/Binaries/Win64/UE4Editor-AdvancedSessions.dll differ diff --git a/Binaries/Win64/UE4Editor-AdvancedSessions.pdb.REMOVED.git-id b/Binaries/Win64/UE4Editor-AdvancedSessions.pdb.REMOVED.git-id index 7f6d332..88b39aa 100644 --- a/Binaries/Win64/UE4Editor-AdvancedSessions.pdb.REMOVED.git-id +++ b/Binaries/Win64/UE4Editor-AdvancedSessions.pdb.REMOVED.git-id @@ -1 +1 @@ -a9c3ed5d5005d7bc7bc08b55f03238128b11d6f4 \ No newline at end of file +3396b004f2ab8bd88779046049c8cfe099e3a6b9 \ No newline at end of file diff --git a/Binaries/Win64/UE4Editor-Win64-DebugGame.modules b/Binaries/Win64/UE4Editor-Win64-DebugGame.modules index b884360..080634d 100644 --- a/Binaries/Win64/UE4Editor-Win64-DebugGame.modules +++ b/Binaries/Win64/UE4Editor-Win64-DebugGame.modules @@ -1,6 +1,6 @@ { "Changelist" : 3142249, - "BuildId" : "8ec6c032-25a1-4060-b513-5852f4db170c", + "BuildId" : "4ef07da3-e88a-4906-9396-c2b96c225a4a", "Modules" : { "AdvancedSessions" : "UE4Editor-AdvancedSessions-Win64-DebugGame.dll" diff --git a/Binaries/Win64/UE4Editor.modules b/Binaries/Win64/UE4Editor.modules index acc1eda..fabe5fe 100644 --- a/Binaries/Win64/UE4Editor.modules +++ b/Binaries/Win64/UE4Editor.modules @@ -1,6 +1,6 @@ { "Changelist" : 3142249, - "BuildId" : "049386af-3641-4a3d-b799-3557f9ac0157", + "BuildId" : "4870daf4-0b02-459b-9258-609d8c5a2c4b", "Modules" : { "AdvancedSessions" : "UE4Editor-AdvancedSessions.dll" diff --git a/Source/AdvancedSessions/Classes/AdvancedFriendsGameInstance.h b/Source/AdvancedSessions/Classes/AdvancedFriendsGameInstance.h index bc60b22..6fc783b 100644 --- a/Source/AdvancedSessions/Classes/AdvancedFriendsGameInstance.h +++ b/Source/AdvancedSessions/Classes/AdvancedFriendsGameInstance.h @@ -32,6 +32,9 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AdvancedFriendsInterface) bool bCallFriendInterfaceEventsOnPlayerControllers; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AdvancedFriendsInterface) + bool bCallIdentityInterfaceEventsOnPlayerControllers; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AdvancedFriendsInterface) bool bCallVoiceInterfaceEventsOnPlayerControllers; @@ -73,6 +76,24 @@ public: FOnPlayerTalkingStateChangedDelegate PlayerTalkingStateChangedDelegate; FDelegateHandle PlayerTalkingStateChangedDelegateHandle; + + // Called when the designated LocalUser has changed login state + UFUNCTION(BlueprintImplementableEvent , Category = "AdvancedIdentity", meta = (DisplayName = "OnPlayerLoginChanged")) + void OnPlayerLoginChanged(int32 PlayerNum); + + void OnPlayerLoginChangedMaster(int32 PlayerNum); + FOnLoginChangedDelegate PlayerLoginChangedDelegate; + FDelegateHandle PlayerLoginChangedDelegateHandle; + + // Called when the designated LocalUser has changed login status + UFUNCTION(BlueprintImplementableEvent, Category = "AdvancedIdentity", meta = (DisplayName = "OnPlayerLoginStatusChanged")) + void OnPlayerLoginStatusChanged(int32 PlayerNum, EBPLoginStatus &PreviousStatus, EBPLoginStatus &NewStatus, FBPUniqueNetId & NewPlayerUniqueNetID); + + void OnPlayerLoginStatusChangedMaster(int32 PlayerNum, ELoginStatus::Type PreviousStatus, ELoginStatus::Type NewStatus, const FUniqueNetId & NewPlayerUniqueNetID); + FOnLoginStatusChangedDelegate PlayerLoginStatusChangedDelegate; + FDelegateHandle PlayerLoginStatusChangedDelegateHandle; + + //*** Session Invite Received From Friend ***// // REMOVED BECAUSE IT NEVER GETS CALLED /*FOnSessionInviteReceivedDelegate SessionInviteReceivedDelegate; diff --git a/Source/AdvancedSessions/Classes/AdvancedFriendsInterface.h b/Source/AdvancedSessions/Classes/AdvancedFriendsInterface.h index 488e97f..f3f34e0 100644 --- a/Source/AdvancedSessions/Classes/AdvancedFriendsInterface.h +++ b/Source/AdvancedSessions/Classes/AdvancedFriendsInterface.h @@ -40,6 +40,14 @@ public: UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnPlayerVoiceStateChanged")) void OnPlayerVoiceStateChanged(FBPUniqueNetId PlayerId, bool bIsTalking); + // Called when the designated LocalUser has changed login state + UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnPlayerLoginChanged")) + void OnPlayerLoginChanged(int32 PlayerNum); + + // Called when the designated LocalUser has changed login state + UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnPlayerLoginStatusChanged")) + void OnPlayerLoginStatusChanged(EBPLoginStatus &PreviousStatus, EBPLoginStatus &NewStatus, FBPUniqueNetId & PlayerUniqueNetID); + // REMOVED BECAUSE IT WAS NEVER BEING CALLED // Called when the designated LocalUser has received a session invite, use JoinSession on result to connect //UFUNCTION(BlueprintImplementableEvent, meta = (FriendlyName = "OnSessionInviteReceived")) diff --git a/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h b/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h new file mode 100644 index 0000000..4363988 --- /dev/null +++ b/Source/AdvancedSessions/Classes/AdvancedIdentityLibrary.h @@ -0,0 +1,75 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once +#include "OnlineSubSystemHeader.h" +#include "Kismet/BlueprintFunctionLibrary.h" +#include "Online.h" +#include "OnlineSubsystem.h" +#include "OnlineIdentityInterface.h" +#include "OnlineUserInterface.h" +#include "OnlinePresenceInterface.h" +#include "Engine/GameInstance.h" + +#include "UObjectIterator.h" + +#include "AdvancedIdentityLibrary.generated.h" + + +//General Advanced Sessions Log +DECLARE_LOG_CATEGORY_EXTERN(AdvancedIdentityLog, Log, All); + +UCLASS() +class UAdvancedIdentityLibrary : public UBlueprintFunctionLibrary +{ + GENERATED_BODY() +public: + //********* Identity Functions *************// + + // Get the login status of a local player + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity", meta = (ExpandEnumAsExecs = "Result")) + static void GetLoginStatus(const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result); + + // Get a players nickname + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity") + static void GetPlayerNickname(const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname); + + //********* User Account Functions *************// + + // Get a users account + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) + static void GetUserAccount(const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result); + + // Get all known users accounts + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) + static void GetAllUserAccounts(TArray & AccountInfos, EBlueprintResultSwitch &Result); + + // Get a user account access token + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity|UserAccount") + static void GetUserAccountAccessToken(const FBPUserOnlineAccount & AccountInfo, FString & AccessToken); + + // Get a user account Auth attribute (depends on subsystem) + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) + static void GetUserAccountAuthAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, FString & AuthAttribute, EBlueprintResultSwitch &Result); + + // Set a user account attribute (depends on subsystem) + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) + static void SetUserAccountAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, const FString & NewAttributeValue, EBlueprintResultSwitch &Result); + + // Get user ID + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity|UserAccount") + static void GetUserID(const FBPUserOnlineAccount & AccountInfo, FBPUniqueNetId & UniqueNetID); + + // Get user accounts real name if possible + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity|UserAccount") + static void GetUserAccountRealName(const FBPUserOnlineAccount & AccountInfo, FString & UserName); + + // Get user account display name if possible + UFUNCTION(BlueprintPure, Category = "Online|AdvancedIdentity|UserAccount") + static void GetUserAccountDisplayName(const FBPUserOnlineAccount & AccountInfo, FString & DisplayName); + + // Get user account attribute (depends on subsystem) + UFUNCTION(BlueprintCallable, Category = "Online|AdvancedIdentity|UserAccount", meta = (ExpandEnumAsExecs = "Result")) + static void GetUserAccountAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, FString & AttributeValue, EBlueprintResultSwitch &Result); + + +}; diff --git a/Source/AdvancedSessions/Classes/BlueprintDataDefinitions.h b/Source/AdvancedSessions/Classes/BlueprintDataDefinitions.h index 0edf066..2ae9cba 100644 --- a/Source/AdvancedSessions/Classes/BlueprintDataDefinitions.h +++ b/Source/AdvancedSessions/Classes/BlueprintDataDefinitions.h @@ -13,6 +13,50 @@ #include "OnlineSubsystemUtilsClasses.h" #include "BlueprintDataDefinitions.generated.h" +UENUM(BlueprintType) +enum EBPUserPrivileges +{ + /** Whether the user can play at all, online or offline - may be age restricted */ + CanPlay, + /** Whether the user can play in online modes */ + CanPlayOnline, + /** Whether the user can use voice and text chat */ + CanCommunicateOnline, + /** Whether the user can use content generated by other users */ + CanUseUserGeneratedContent +}; + + +UENUM(BlueprintType) +enum class EBPLoginStatus : uint8 +{ + /** Player has not logged in or chosen a local profile */ + NotLoggedIn, + /** Player is using a local profile but is not logged in */ + UsingLocalProfile, + /** Player has been validated by the platform specific authentication service */ + LoggedIn +}; + + +USTRUCT(BlueprintType) +struct FBPUserOnlineAccount +{ + GENERATED_USTRUCT_BODY() + +public: + TSharedPtr UserAccountInfo; + + FBPUserOnlineAccount() + { + + } + + FBPUserOnlineAccount(TSharedPtr UserAccount) + { + UserAccountInfo = UserAccount; + } +}; UENUM() enum class ESessionSettingSearchResult : uint8 @@ -23,7 +67,7 @@ enum class ESessionSettingSearchResult : uint8 // Did not find the setting NotFound, - // Was not the correct ype + // Was not the correct type WrongType }; diff --git a/Source/AdvancedSessions/Classes/GetUserPrivilegeCallbackProxy.h b/Source/AdvancedSessions/Classes/GetUserPrivilegeCallbackProxy.h new file mode 100644 index 0000000..426263f --- /dev/null +++ b/Source/AdvancedSessions/Classes/GetUserPrivilegeCallbackProxy.h @@ -0,0 +1,45 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. +#pragma once + +#include "OnlineSubSystemHeader.h" +#include "BlueprintDataDefinitions.h" +#include "OnlineIdentityInterface.h" +#include "GetUserPrivilegeCallbackProxy.generated.h" + +DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FBlueprintGetUserPrivilegeDelegate,/* const &FBPUniqueNetId, PlayerID,*/ EBPUserPrivileges, QueriedPrivilege, bool, HadPrivilege); + +UCLASS(MinimalAPI) +class UGetUserPrivilegeCallbackProxy : public UOnlineBlueprintCallProxyBase +{ + GENERATED_UCLASS_BODY() + + // Called when there is a successful destroy + UPROPERTY(BlueprintAssignable) + FBlueprintGetUserPrivilegeDelegate OnSuccess; + + // Called when there is an unsuccessful destroy + UPROPERTY(BlueprintAssignable) + FEmptyOnlineDelegate OnFailure; + + // Logs out of the identity interface + UFUNCTION(BlueprintCallable, meta=(BlueprintInternalUseOnly = "true", WorldContext="WorldContextObject"), Category = "Online|AdvancedIdentity") + static UGetUserPrivilegeCallbackProxy* GetUserPrivilege(UObject* WorldContextObject, const EBPUserPrivileges & PrivilegeToCheck, const FBPUniqueNetId & PlayerUniqueNetID); + + // UOnlineBlueprintCallProxyBase interface + virtual void Activate() override; + // End of UOnlineBlueprintCallProxyBase interface + +private: + // Internal callback when the operation completes, calls out to the public success/failure callbacks + void OnCompleted(const FUniqueNetId& PlayerID, EUserPrivileges::Type Privilege, uint32 Result); + +private: + // The player controller triggering things + FBPUniqueNetId PlayerUniqueNetID; + + // Privilege to check + EBPUserPrivileges UserPrivilege; + + // The world context object in which this call is taking place + UObject* WorldContextObject; +}; diff --git a/Source/AdvancedSessions/Classes/LoginUserCallbackProxy.h b/Source/AdvancedSessions/Classes/LoginUserCallbackProxy.h new file mode 100644 index 0000000..768b156 --- /dev/null +++ b/Source/AdvancedSessions/Classes/LoginUserCallbackProxy.h @@ -0,0 +1,51 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. +#pragma once + +#include "OnlineSubSystemHeader.h" +#include "OnlineIdentityInterface.h" +#include "LoginUserCallbackProxy.generated.h" + +UCLASS(MinimalAPI) +class ULoginUserCallbackProxy : public UOnlineBlueprintCallProxyBase +{ + GENERATED_UCLASS_BODY() + + // Called when there is a successful destroy + UPROPERTY(BlueprintAssignable) + FEmptyOnlineDelegate OnSuccess; + + // Called when there is an unsuccessful destroy + UPROPERTY(BlueprintAssignable) + FEmptyOnlineDelegate OnFailure; + + // Logs out of the identity interface + UFUNCTION(BlueprintCallable, meta=(BlueprintInternalUseOnly = "true", WorldContext="WorldContextObject"), Category = "Online|AdvancedIdentity") + static ULoginUserCallbackProxy* LoginUser(UObject* WorldContextObject, class APlayerController* PlayerController, FString UserID, FString UserToken); + + // UOnlineBlueprintCallProxyBase interface + virtual void Activate() override; + // End of UOnlineBlueprintCallProxyBase interface + +private: + // Internal callback when the operation completes, calls out to the public success/failure callbacks + void OnCompleted(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& ErrorVal); + +private: + // The player controller triggering things + TWeakObjectPtr PlayerControllerWeakPtr; + + // The user ID + FString UserID; + + // The user pass / token + FString UserToken; + + // The delegate executed by the online subsystem + FOnLoginCompleteDelegate Delegate; + + // Handle to the registered OnDestroySessionComplete delegate + FDelegateHandle DelegateHandle; + + // The world context object in which this call is taking place + UObject* WorldContextObject; +}; diff --git a/Source/AdvancedSessions/Classes/LogoutUserCallbackProxy.h b/Source/AdvancedSessions/Classes/LogoutUserCallbackProxy.h new file mode 100644 index 0000000..7096649 --- /dev/null +++ b/Source/AdvancedSessions/Classes/LogoutUserCallbackProxy.h @@ -0,0 +1,45 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. +#pragma once + +#include "OnlineSubSystemHeader.h" +#include "OnlineIdentityInterface.h" +#include "LogoutUserCallbackProxy.generated.h" + +UCLASS(MinimalAPI) +class ULogoutUserCallbackProxy : public UOnlineBlueprintCallProxyBase +{ + GENERATED_UCLASS_BODY() + + // Called when there is a successful destroy + UPROPERTY(BlueprintAssignable) + FEmptyOnlineDelegate OnSuccess; + + // Called when there is an unsuccessful destroy + UPROPERTY(BlueprintAssignable) + FEmptyOnlineDelegate OnFailure; + + // Logs out of the identity interface + UFUNCTION(BlueprintCallable, meta=(BlueprintInternalUseOnly = "true", WorldContext="WorldContextObject"), Category = "Online|AdvancedIdentity") + static ULogoutUserCallbackProxy* LogoutUser(UObject* WorldContextObject, class APlayerController* PlayerController); + + // UOnlineBlueprintCallProxyBase interface + virtual void Activate() override; + // End of UOnlineBlueprintCallProxyBase interface + +private: + // Internal callback when the operation completes, calls out to the public success/failure callbacks + void OnCompleted(int LocalUserNum, bool bWasSuccessful); + +private: + // The player controller triggering things + TWeakObjectPtr PlayerControllerWeakPtr; + + // The delegate executed by the online subsystem + FOnLogoutCompleteDelegate Delegate; + + // Handle to the registered OnDestroySessionComplete delegate + FDelegateHandle DelegateHandle; + + // The world context object in which this call is taking place + UObject* WorldContextObject; +}; diff --git a/Source/AdvancedSessions/Private/AdvancedFriendsGameInstance.cpp b/Source/AdvancedSessions/Private/AdvancedFriendsGameInstance.cpp index 224784a..c375276 100644 --- a/Source/AdvancedSessions/Private/AdvancedFriendsGameInstance.cpp +++ b/Source/AdvancedSessions/Private/AdvancedFriendsGameInstance.cpp @@ -8,11 +8,14 @@ DEFINE_LOG_CATEGORY(AdvancedFriendsInterfaceLog); UAdvancedFriendsGameInstance::UAdvancedFriendsGameInstance(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) , bCallFriendInterfaceEventsOnPlayerControllers(true) + , bCallIdentityInterfaceEventsOnPlayerControllers(true) , bCallVoiceInterfaceEventsOnPlayerControllers(true) , bEnableTalkingStatusDelegate(true) , SessionInviteReceivedDelegate(FOnSessionInviteReceivedDelegate::CreateUObject(this, &ThisClass::OnSessionInviteReceivedMaster)) , SessionInviteAcceptedDelegate(FOnSessionUserInviteAcceptedDelegate::CreateUObject(this, &ThisClass::OnSessionInviteAcceptedMaster)) , PlayerTalkingStateChangedDelegate(FOnPlayerTalkingStateChangedDelegate::CreateUObject(this, &ThisClass::OnPlayerTalkingStateChangedMaster)) + , PlayerLoginChangedDelegate(FOnLoginChangedDelegate::CreateUObject(this, &ThisClass::OnPlayerLoginChangedMaster)) + , PlayerLoginStatusChangedDelegate(FOnLoginStatusChangedDelegate::CreateUObject(this, &ThisClass::OnPlayerLoginStatusChangedMaster)) { } @@ -48,6 +51,18 @@ void UAdvancedFriendsGameInstance::Shutdown() } } + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (IdentityInterface.IsValid()) + { + IdentityInterface->ClearOnLoginChangedDelegate_Handle(PlayerLoginChangedDelegateHandle); + + + // I am just defaulting to player 1 + IdentityInterface->ClearOnLoginStatusChangedDelegate_Handle(0, PlayerLoginStatusChangedDelegateHandle); + } + + Super::Shutdown(); } @@ -87,6 +102,21 @@ void UAdvancedFriendsGameInstance::Init() } } + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (IdentityInterface.IsValid()) + { + PlayerLoginChangedDelegateHandle = IdentityInterface->AddOnLoginChangedDelegate_Handle(PlayerLoginChangedDelegate); + + // Just defaulting to player 1 + PlayerLoginStatusChangedDelegateHandle = IdentityInterface->AddOnLoginStatusChangedDelegate_Handle(0, PlayerLoginStatusChangedDelegate); + } + else + { + UE_LOG(AdvancedFriendsInterfaceLog, Warning, TEXT("UAdvancedFriendsInstance Failed to get identity interface!")); + } + + Super::Init(); } @@ -128,6 +158,58 @@ void UAdvancedFriendsGameInstance::Init() } }*/ +void UAdvancedFriendsGameInstance::OnPlayerLoginStatusChangedMaster(int32 PlayerNum, ELoginStatus::Type PreviousStatus, ELoginStatus::Type NewStatus, const FUniqueNetId & NewPlayerUniqueNetID) +{ + EBPLoginStatus OrigStatus = (EBPLoginStatus)PreviousStatus; + EBPLoginStatus CurrentStatus = (EBPLoginStatus)NewStatus; + FBPUniqueNetId PlayerID; + PlayerID.SetUniqueNetId(&NewPlayerUniqueNetID); + + OnPlayerLoginStatusChanged(PlayerNum, OrigStatus,CurrentStatus,PlayerID); + + + if (bCallIdentityInterfaceEventsOnPlayerControllers) + { + APlayerController* Player = UGameplayStatics::GetPlayerController(GetWorld(), PlayerNum); + + if (Player != NULL) + { + //Run the Event specific to the actor, if the actor has the interface, otherwise ignore + if (Player->GetClass()->ImplementsInterface(UAdvancedFriendsInterface::StaticClass())) + { + IAdvancedFriendsInterface::Execute_OnPlayerLoginStatusChanged(Player, OrigStatus, CurrentStatus, PlayerID); + } + } + else + { + UE_LOG(AdvancedFriendsInterfaceLog, Warning, TEXT("UAdvancedFriendsInstance Failed to get a controller with the specified index in OnPlayerLoginStatusChangedMaster!")); + } + } +} + +void UAdvancedFriendsGameInstance::OnPlayerLoginChangedMaster(int32 PlayerNum) +{ + OnPlayerLoginChanged(PlayerNum); + + if (bCallIdentityInterfaceEventsOnPlayerControllers) + { + APlayerController* Player = UGameplayStatics::GetPlayerController(GetWorld(), PlayerNum); + + if (Player != NULL) + { + //Run the Event specific to the actor, if the actor has the interface, otherwise ignore + if (Player->GetClass()->ImplementsInterface(UAdvancedFriendsInterface::StaticClass())) + { + IAdvancedFriendsInterface::Execute_OnPlayerLoginChanged(Player, PlayerNum); + } + } + else + { + UE_LOG(AdvancedFriendsInterfaceLog, Warning, TEXT("UAdvancedFriendsInstance Failed to get a controller with the specified index in OnPlayerLoginChanged!")); + } + } +} + void UAdvancedFriendsGameInstance::OnPlayerTalkingStateChangedMaster(TSharedRef PlayerId, bool bIsTalking) { FBPUniqueNetId PlayerTalking; diff --git a/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp b/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp new file mode 100644 index 0000000..e0dc47a --- /dev/null +++ b/Source/AdvancedSessions/Private/AdvancedIdentityLibrary.cpp @@ -0,0 +1,198 @@ +// Fill out your copyright notice in the Description page of Project Settings. +#include "OnlineSubSystemHeader.h" +#include "AdvancedIdentityLibrary.h" + +//General Log +DEFINE_LOG_CATEGORY(AdvancedIdentityLog); + +void UAdvancedIdentityLibrary::GetPlayerNickname(const FBPUniqueNetId & UniqueNetID, FString & PlayerNickname) +{ + if (!UniqueNetID.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetPlayerNickname was passed a bad player uniquenetid!")); + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (!IdentityInterface.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetPlayerNickname Failed to get identity interface!")); + return; + } + + PlayerNickname = IdentityInterface->GetPlayerNickname(*UniqueNetID.GetUniqueNetId()); +} + + +void UAdvancedIdentityLibrary::GetLoginStatus(const FBPUniqueNetId & UniqueNetID, EBPLoginStatus & LoginStatus, EBlueprintResultSwitch &Result) +{ + if(!UniqueNetID.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetLoginStatus was passed a bad player uniquenetid!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (!IdentityInterface.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetLoginStatus Failed to get identity interface!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + LoginStatus = (EBPLoginStatus)IdentityInterface->GetLoginStatus(*UniqueNetID.GetUniqueNetId()); + EBlueprintResultSwitch::OnSuccess; +} + + +void UAdvancedIdentityLibrary::GetAllUserAccounts(TArray & AccountInfos, EBlueprintResultSwitch &Result) +{ + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (!IdentityInterface.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetAllUserAccounts Failed to get identity interface!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + TArray> accountInfos = IdentityInterface->GetAllUserAccounts(); + + for (int i = 0; i < accountInfos.Num(); ++i) + { + AccountInfos.Add(FBPUserOnlineAccount(accountInfos[i])); + } + + Result = EBlueprintResultSwitch::OnSuccess; +} + +void UAdvancedIdentityLibrary::GetUserAccount(const FBPUniqueNetId & UniqueNetId, FBPUserOnlineAccount & AccountInfo, EBlueprintResultSwitch &Result) +{ + IOnlineIdentityPtr IdentityInterface = Online::GetIdentityInterface(); + + if (!IdentityInterface.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccount Failed to get identity interface!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + TSharedPtr accountInfo = IdentityInterface->GetUserAccount(*UniqueNetId.GetUniqueNetId()); + + if (!accountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccount Failed to get the account!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + AccountInfo.UserAccountInfo = accountInfo; + Result = EBlueprintResultSwitch::OnSuccess; +} + +void UAdvancedIdentityLibrary::GetUserAccountAccessToken(const FBPUserOnlineAccount & AccountInfo, FString & AccessToken) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountAccessToken was passed an invalid account!")); + return; + } + + AccessToken = AccountInfo.UserAccountInfo->GetAccessToken(); +} + +void UAdvancedIdentityLibrary::GetUserAccountAuthAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, FString & AuthAttribute, EBlueprintResultSwitch &Result) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountAuthAttribute was passed an invalid account!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + if (!AccountInfo.UserAccountInfo->GetAuthAttribute(AttributeName, AuthAttribute)) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountAuthAttribute couldn't find the attribute!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + Result = EBlueprintResultSwitch::OnSuccess; +} + +void UAdvancedIdentityLibrary::SetUserAccountAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, const FString & NewAttributeValue, EBlueprintResultSwitch &Result) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("SetUserAccountAuthAttribute was passed an invalid account!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + if (!AccountInfo.UserAccountInfo->SetUserAttribute(AttributeName, NewAttributeValue)) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("SetUserAccountAuthAttribute was unable to set the attribute!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + Result = EBlueprintResultSwitch::OnSuccess; +} + +void UAdvancedIdentityLibrary::GetUserID(const FBPUserOnlineAccount & AccountInfo, FBPUniqueNetId & UniqueNetID) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserID was passed an invalid account!")); + return; + } + + + UniqueNetID.SetUniqueNetId(AccountInfo.UserAccountInfo->GetUserId()); +} + +void UAdvancedIdentityLibrary::GetUserAccountRealName(const FBPUserOnlineAccount & AccountInfo, FString & UserName) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountRealName was passed an invalid account!")); + return; + } + + + UserName = AccountInfo.UserAccountInfo->GetRealName(); +} + +void UAdvancedIdentityLibrary::GetUserAccountDisplayName(const FBPUserOnlineAccount & AccountInfo, FString & DisplayName) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountDisplayName was passed an invalid account!")); + return; + } + + + DisplayName = AccountInfo.UserAccountInfo->GetDisplayName(); +} + +void UAdvancedIdentityLibrary::GetUserAccountAttribute(const FBPUserOnlineAccount & AccountInfo, const FString & AttributeName, FString & AttributeValue, EBlueprintResultSwitch &Result) +{ + if (!AccountInfo.UserAccountInfo.IsValid()) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountAttribute was passed an invalid account!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + if (!AccountInfo.UserAccountInfo->GetUserAttribute(AttributeName, AttributeValue)) + { + UE_LOG(AdvancedIdentityLog, Warning, TEXT("GetUserAccountAttribute failed to get user attribute!")); + Result = EBlueprintResultSwitch::OnFailure; + return; + } + + Result = EBlueprintResultSwitch::OnSuccess; +} \ No newline at end of file diff --git a/Source/AdvancedSessions/Private/GetUserPrivilegeCallbackProxy.cpp b/Source/AdvancedSessions/Private/GetUserPrivilegeCallbackProxy.cpp new file mode 100644 index 0000000..e88edac --- /dev/null +++ b/Source/AdvancedSessions/Private/GetUserPrivilegeCallbackProxy.cpp @@ -0,0 +1,40 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. + +#include "OnlineSubSystemHeader.h" +#include "GetUserPrivilegeCallbackProxy.h" + +////////////////////////////////////////////////////////////////////////// +// UGetUserPrivilegeCallbackProxy + +UGetUserPrivilegeCallbackProxy::UGetUserPrivilegeCallbackProxy(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ +} + +UGetUserPrivilegeCallbackProxy* UGetUserPrivilegeCallbackProxy::GetUserPrivilege(UObject* WorldContextObject, const EBPUserPrivileges & PrivilegeToCheck, const FBPUniqueNetId & PlayerUniqueNetID) +{ + UGetUserPrivilegeCallbackProxy* Proxy = NewObject(); + Proxy->PlayerUniqueNetID.SetUniqueNetId(PlayerUniqueNetID.GetUniqueNetId()); + Proxy->UserPrivilege = PrivilegeToCheck; + Proxy->WorldContextObject = WorldContextObject; + return Proxy; +} + +void UGetUserPrivilegeCallbackProxy::Activate() +{ + auto Identity = Online::GetIdentityInterface(); + + if (Identity.IsValid()) + { + Identity->GetUserPrivilege(*PlayerUniqueNetID.GetUniqueNetId(), (EUserPrivileges::Type)UserPrivilege, IOnlineIdentity::FOnGetUserPrivilegeCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted)); + return; + } + + // Fail immediately + OnFailure.Broadcast(); +} + +void UGetUserPrivilegeCallbackProxy::OnCompleted(const FUniqueNetId& PlayerID, EUserPrivileges::Type Privilege, uint32 PrivilegeResult) +{ + OnSuccess.Broadcast(/*PlayerID,*/ (EBPUserPrivileges)Privilege, PrivilegeResult == 0); +} diff --git a/Source/AdvancedSessions/Private/LoginUserCallbackProxy.cpp b/Source/AdvancedSessions/Private/LoginUserCallbackProxy.cpp new file mode 100644 index 0000000..af762d3 --- /dev/null +++ b/Source/AdvancedSessions/Private/LoginUserCallbackProxy.cpp @@ -0,0 +1,81 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. + +#include "OnlineSubSystemHeader.h" +#include "LoginUserCallbackProxy.h" + +////////////////////////////////////////////////////////////////////////// +// ULoginUserCallbackProxy + +ULoginUserCallbackProxy::ULoginUserCallbackProxy(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) + , Delegate(FOnLoginCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted)) +{ +} + +ULoginUserCallbackProxy* ULoginUserCallbackProxy::LoginUser(UObject* WorldContextObject, class APlayerController* PlayerController, FString UserID, FString UserToken) +{ + ULoginUserCallbackProxy* Proxy = NewObject(); + Proxy->PlayerControllerWeakPtr = PlayerController; + Proxy->UserID = UserID; + Proxy->UserToken = UserToken; + Proxy->WorldContextObject = WorldContextObject; + return Proxy; +} + +void ULoginUserCallbackProxy::Activate() +{ + + if (!PlayerControllerWeakPtr.IsValid()) + { + OnFailure.Broadcast(); + return; + } + + ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); + + if (!Player) + { + OnFailure.Broadcast(); + return; + } + + auto Identity = Online::GetIdentityInterface(); + + if (Identity.IsValid()) + { + DelegateHandle = Identity->AddOnLoginCompleteDelegate_Handle(Player->GetControllerId(), Delegate); + FOnlineAccountCredentials AccountCreds(Identity->GetAuthType(), UserID, UserToken); + Identity->Login(Player->GetControllerId(), AccountCreds); + return; + } + + // Fail immediately + OnFailure.Broadcast(); +} + +void ULoginUserCallbackProxy::OnCompleted(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& ErrorVal) +{ + if (PlayerControllerWeakPtr.IsValid()) + { + ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); + + if (Player) + { + auto Identity = Online::GetIdentityInterface(); + + if (Identity.IsValid()) + { + Identity->ClearOnLoginCompleteDelegate_Handle(Player->GetControllerId(), DelegateHandle); + } + } + } + + if (bWasSuccessful) + { + OnSuccess.Broadcast(); + } + else + { + OnFailure.Broadcast(); + } +} diff --git a/Source/AdvancedSessions/Private/LogoutUserCallbackProxy.cpp b/Source/AdvancedSessions/Private/LogoutUserCallbackProxy.cpp new file mode 100644 index 0000000..3424396 --- /dev/null +++ b/Source/AdvancedSessions/Private/LogoutUserCallbackProxy.cpp @@ -0,0 +1,80 @@ +// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. + +#include "OnlineSubSystemHeader.h" +#include "LogoutUserCallbackProxy.h" + +////////////////////////////////////////////////////////////////////////// +// ULogoutUserCallbackProxy + +ULogoutUserCallbackProxy::ULogoutUserCallbackProxy(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) + , Delegate(FOnLogoutCompleteDelegate::CreateUObject(this, &ThisClass::OnCompleted)) +{ +} + +ULogoutUserCallbackProxy* ULogoutUserCallbackProxy::LogoutUser(UObject* WorldContextObject, class APlayerController* PlayerController) +{ + ULogoutUserCallbackProxy* Proxy = NewObject(); + Proxy->PlayerControllerWeakPtr = PlayerController; + Proxy->WorldContextObject = WorldContextObject; + return Proxy; +} + +void ULogoutUserCallbackProxy::Activate() +{ + + if (!PlayerControllerWeakPtr.IsValid()) + { + OnFailure.Broadcast(); + return; + } + + + ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); + + if (!Player) + { + OnFailure.Broadcast(); + return; + } + + auto Identity = Online::GetIdentityInterface(); + + if (Identity.IsValid()) + { + DelegateHandle = Identity->AddOnLogoutCompleteDelegate_Handle(Player->GetControllerId(), Delegate); + Identity->Logout(Player->GetControllerId()); + return; + } + + // Fail immediately + OnFailure.Broadcast(); +} + +void ULogoutUserCallbackProxy::OnCompleted(int LocalUserNum, bool bWasSuccessful) +{ + + if (PlayerControllerWeakPtr.IsValid()) + { + ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); + + if (Player) + { + auto Identity = Online::GetIdentityInterface(); + + if (Identity.IsValid()) + { + Identity->ClearOnLogoutCompleteDelegate_Handle(Player->GetControllerId(), DelegateHandle); + } + } + } + + if (bWasSuccessful) + { + OnSuccess.Broadcast(); + } + else + { + OnFailure.Broadcast(); + } +}