// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. #include "OnlineSubSystemHeader.h" #include "GetFriendsCallbackProxy.h" ////////////////////////////////////////////////////////////////////////// // UGetFriendsCallbackProxy DEFINE_LOG_CATEGORY(AdvancedGetFriendsLog); UGetFriendsCallbackProxy::UGetFriendsCallbackProxy(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) , FriendListReadCompleteDelegate(FOnReadFriendsListComplete::CreateUObject(this, &ThisClass::OnReadFriendsListCompleted)) { } UGetFriendsCallbackProxy* UGetFriendsCallbackProxy::GetAndStoreFriendsList(UObject* WorldContextObject, class APlayerController* PlayerController) { UGetFriendsCallbackProxy* Proxy = NewObject(); Proxy->PlayerControllerWeakPtr = PlayerController; Proxy->WorldContextObject = WorldContextObject; return Proxy; } void UGetFriendsCallbackProxy::Activate() { if (!PlayerControllerWeakPtr.IsValid()) { // Fail immediately UE_LOG(AdvancedGetFriendsLog, Warning, TEXT("GetFriends Failed received a bad player controller!")); TArray EmptyArray; OnFailure.Broadcast(EmptyArray); return; } IOnlineFriendsPtr Friends = Online::GetFriendsInterface(); if (Friends.IsValid()) { ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); Friends->ReadFriendsList(Player->GetControllerId(), EFriendsLists::ToString((EFriendsLists::Type::Default)), FriendListReadCompleteDelegate); return; } // Fail immediately TArray EmptyArray; OnFailure.Broadcast(EmptyArray); } void UGetFriendsCallbackProxy::OnReadFriendsListCompleted(int32 LocalUserNum, bool bWasSuccessful, const FString& ListName, const FString& ErrorString) { if (bWasSuccessful) { IOnlineFriendsPtr Friends = Online::GetFriendsInterface(); if (Friends.IsValid()) { ULocalPlayer* Player = Cast(PlayerControllerWeakPtr->Player); TArray FriendsListOut; TArray< TSharedRef > FriendList; Friends->GetFriendsList(LocalUserNum, ListName, FriendList); for (int32 i = 0; i < FriendList.Num(); i++) { TSharedRef Friend = FriendList[i]; FBPFriendInfo BPF; BPF.OnlineState = ((EBPOnlinePresenceState::Type)((int32)Friend->GetPresence().Status.State)); BPF.DisplayName = Friend->GetDisplayName(); BPF.RealName = Friend->GetRealName(); BPF.UniqueNetId.SetUniqueNetId(Friend->GetUserId()); BPF.bIsPlayingSameGame = Friend->GetPresence().bIsPlayingThisGame; BPF.PresenceInfo.bIsOnline = Friend->GetPresence().bIsOnline; BPF.PresenceInfo.bIsPlaying = Friend->GetPresence().bIsPlaying; BPF.PresenceInfo.PresenceState = ((EBPOnlinePresenceState::Type)((int32)Friend->GetPresence().Status.State)); BPF.PresenceInfo.StatusString = Friend->GetPresence().Status.StatusStr; BPF.PresenceInfo.bIsJoinable = Friend->GetPresence().bIsJoinable; BPF.PresenceInfo.bIsPlayingThisGame = Friend->GetPresence().bIsPlayingThisGame; FriendsListOut.Add(BPF); } OnSuccess.Broadcast(FriendsListOut); } } else { TArray EmptyArray; OnFailure.Broadcast(EmptyArray); } }