accepted added

This commit is contained in:
mordentral
2016-01-14 14:06:20 -05:00
parent f91d4ec4ea
commit f06519ee98
5 changed files with 73 additions and 4 deletions

View File

@@ -42,6 +42,16 @@ public:
virtual void Shutdown() override;
virtual void Init() override;
//*** Session invite received by local ***//
FOnSessionInviteReceivedDelegate SessionInviteReceivedDelegate;
FDelegateHandle SessionInviteReceivedDelegateHandle;
void OnSessionInviteReceivedMaster(TSharedPtr<const FUniqueNetId> PersonInvited, TSharedPtr<const FUniqueNetId> PersonInviting, const FOnlineSessionSearchResult& SessionToJoin);
// After a session invite has been accepted by the local player this event is triggered, call JoinSession on the session result to join it
UFUNCTION(BlueprintImplementableEvent, Category = "AdvancedFriends")
void OnSessionInviteReceived(int32 LocalPlayerNum, FBPUniqueNetId PersonInviting, const FBlueprintSessionResult& SessionToJoin);
//*** Session invite accepted by local ***//
FOnSessionUserInviteAcceptedDelegate SessionInviteAcceptedDelegate;
FDelegateHandle SessionInviteAcceptedDelegateHandle;

View File

@@ -28,6 +28,10 @@ class IAdvancedFriendsInterface
GENERATED_IINTERFACE_BODY()
public:
// Called when the designated LocalUser has accepted a session invite, use JoinSession on result to connect
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnSessionInviteAccepted"))
void OnSessionInviteReceived(FBPUniqueNetId PersonInviting, const FBlueprintSessionResult& SearchResult);
// Called when the designated LocalUser has accepted a session invite, use JoinSession on result to connect
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "OnSessionInviteAccepted"))
void OnSessionInviteAccepted(FBPUniqueNetId PersonInviting, const FBlueprintSessionResult& SearchResult);

View File

@@ -128,7 +128,7 @@ public:
//********** Misc Player Info Functions *********//
// Get the number of network players
UFUNCTION(BlueprintPure, Category = "Online|AdvancedSessions|PlayerInfo|Misc")
UFUNCTION(BlueprintPure, Category = "Online|AdvancedSessions|PlayerInfo|Misc", meta = (bIgnoreSelf = "true", WorldContext = "WorldContextObject", DisplayName = "GetNumNetworkPlayers"))
static void GetNumberOfNetworkPlayers(int32 &NumNetPlayers);
// Get the network player index of the given controller

View File

@@ -10,6 +10,7 @@ UAdvancedFriendsGameInstance::UAdvancedFriendsGameInstance(const FObjectInitiali
, bCallFriendInterfaceEventsOnPlayerControllers(true)
, bCallVoiceInterfaceEventsOnPlayerControllers(true)
, bEnableTalkingStatusDelegate(true)
, SessionInviteReceivedDelegate(FOnSessionInviteReceivedDelegate::CreateUObject(this, &ThisClass::OnSessionInviteReceivedMaster))
, SessionInviteAcceptedDelegate(FOnSessionUserInviteAcceptedDelegate::CreateUObject(this, &ThisClass::OnSessionInviteAcceptedMaster))
, PlayerTalkingStateChangedDelegate(FOnPlayerTalkingStateChangedDelegate::CreateUObject(this, &ThisClass::OnPlayerTalkingStateChangedMaster))
{
@@ -156,6 +157,59 @@ void UAdvancedFriendsGameInstance::OnPlayerTalkingStateChangedMaster(TSharedRef<
}
}
void UAdvancedFriendsGameInstance::OnSessionInviteReceivedMaster(TSharedPtr<const FUniqueNetId> PersonInvited, TSharedPtr<const FUniqueNetId> PersonInviting, const FOnlineSessionSearchResult& SessionToJoin)
{
if (SessionToJoin.IsValid())
{
FBlueprintSessionResult BluePrintResult;
BluePrintResult.OnlineResult = SessionToJoin;
FBPUniqueNetId PInvited;
PInvited.SetUniqueNetId(PersonInvited);
FBPUniqueNetId PInviting;
PInviting.SetUniqueNetId(PersonInviting);
TArray<APlayerController*> PlayerList;
GEngine->GetAllLocalPlayerControllers(PlayerList);
APlayerController* Player = NULL;
int32 LocalPlayer = 0;
for (int i = 0; i < PlayerList->Num(); i++)
{
if (PlayerList[i]->PlayerState->UniqueId == PersonInvited)
{
PlayerNum = i;
Player = PlayerList[i];
break;
}
}
OnSessionInviteReceived(LocalPlayer, PInviting, BluePrintResult);
IAdvancedFriendsInterface* TheInterface = NULL;
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_OnSessionInviteReceived(Player, PInviting, BluePrintResult);
}
}
else
{
UE_LOG(AdvancedFriendsInterfaceLog, Warning, TEXT("UAdvancedFriendsInstance Failed to get a controller with the specified index in OnSessionInviteReceived!"));
}
}
else
{
UE_LOG(AdvancedFriendsInterfaceLog, Warning, TEXT("UAdvancedFriendsInstance Return a bad search result in OnSessionInviteReceived!"));
}
}
void UAdvancedFriendsGameInstance::OnSessionInviteAcceptedMaster(const bool bWasSuccessful, int32 LocalPlayer, TSharedPtr<const FUniqueNetId> PersonInviting, const FOnlineSessionSearchResult& SessionToJoin)
{
if (bWasSuccessful)

View File

@@ -377,16 +377,17 @@ void UAdvancedSessionsLibrary::GetPlayerName(APlayerController *PlayerController
void UAdvancedSessionsLibrary::GetNumberOfNetworkPlayers(int32 &NumNetPlayers)
{
//Get an actor to GetWorld() from
TObjectIterator<AActor> Itr;
/*TObjectIterator<AActor> Itr;
if (!Itr)
{
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get iterator!"));
return;
}
}*/
//~~~~~~~~~~~~
//Get World
UWorld* TheWorld = Itr->GetWorld();
UWorld* TheWorld = GEngine->GetWorldFromContextObject(WorldContextObject)
if (!TheWorld)
{
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get World()!"));