mirror of
https://github.com/mordentral/AdvancedSessionsPlugin.git
synced 2025-10-23 00:14:24 +00:00
accepted added
This commit is contained in:
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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()!"));
|
||||
|
Reference in New Issue
Block a user