Skip to content
Snippets Groups Projects
Commit bf3d4ac9 authored by Giovanni Vindiola's avatar Giovanni Vindiola :speech_balloon:
Browse files

Fix for VoiceChat Rejoin Crash

parent 1e5543ab
No related branches found
No related tags found
No related merge requests found
...@@ -58,6 +58,7 @@ void AARNOPlayerController::DoLogin() ...@@ -58,6 +58,7 @@ void AARNOPlayerController::DoLogin()
} }
TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(0); TSharedPtr<const FUniqueNetId> UserId = Identity->GetUniquePlayerId(0);
FPlatformUserId PlatformUserId = Identity->GetPlatformUserIdFromUniqueNetId(*UserId); FPlatformUserId PlatformUserId = Identity->GetPlatformUserIdFromUniqueNetId(*UserId);
UE_LOG(LogTemp, Display, TEXT("Logging into VOIP...")); UE_LOG(LogTemp, Display, TEXT("Logging into VOIP..."));
VoiceChatUser->Login( VoiceChatUser->Login(
...@@ -65,6 +66,7 @@ void AARNOPlayerController::DoLogin() ...@@ -65,6 +66,7 @@ void AARNOPlayerController::DoLogin()
UserId->ToString(), UserId->ToString(),
TEXT(""), TEXT(""),
FOnVoiceChatLoginCompleteDelegate::CreateUObject(this, &AARNOPlayerController::OnLoginComplete)); FOnVoiceChatLoginCompleteDelegate::CreateUObject(this, &AARNOPlayerController::OnLoginComplete));
} }
void AARNOPlayerController::BeginPlay() void AARNOPlayerController::BeginPlay()
...@@ -103,15 +105,18 @@ void AARNOPlayerController::JoinVoiceLobby_Implementation(const FString& InLobby ...@@ -103,15 +105,18 @@ void AARNOPlayerController::JoinVoiceLobby_Implementation(const FString& InLobby
if (Error.WasSuccessful()) if (Error.WasSuccessful())
{ {
// Player has been connected to lobby. // Player has been connected to lobby.
UE_LOG(LogTemp, Display, TEXT("Player:%s has been connected to lobby."), *UserId.ToString());
} }
else else
{ {
// Could not connect to lobby. // Could not connect to lobby.
UE_LOG(LogTemp, Display, TEXT("Player:%s Could not connect to lobby."), *UserId.ToString());
} }
}) })
)) ))
{ {
// Call failed to start. // Call failed to start.
UE_LOG(LogTemp, Display, TEXT("Connect Lobby failed."));
} }
} }
...@@ -180,6 +185,13 @@ void AARNOPlayerController::UnmuteVOIP() ...@@ -180,6 +185,13 @@ void AARNOPlayerController::UnmuteVOIP()
void AARNOPlayerController::BeginDestroy() void AARNOPlayerController::BeginDestroy()
{ {
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (this->VoiceChatUser != nullptr && VoiceChat != nullptr)
{
VoiceChat->ReleaseUser(this->VoiceChatUser);
this->VoiceChatUser = nullptr;
}
Super::BeginDestroy(); Super::BeginDestroy();
} }
...@@ -191,9 +203,6 @@ void AARNOPlayerController::JoinVoiceChannel_Implementation(const FString& InCha ...@@ -191,9 +203,6 @@ void AARNOPlayerController::JoinVoiceChannel_Implementation(const FString& InCha
UE_LOG(LogTemp, Display, TEXT("VOIP: No valid voice chat user found when joining Voice Channel.")); UE_LOG(LogTemp, Display, TEXT("VOIP: No valid voice chat user found when joining Voice Channel."));
return; return;
} }
IVoiceChat* VoiceChat = IVoiceChat::Get();
VoiceChat->Uninitialize();
DoLogin();
VoiceChatUser->JoinChannel( VoiceChatUser->JoinChannel(
InChannelName, InChannelName,
......
...@@ -48,6 +48,8 @@ void AarnocMainGameModeBase::PostLogin(APlayerController* NewPlayer) ...@@ -48,6 +48,8 @@ void AarnocMainGameModeBase::PostLogin(APlayerController* NewPlayer)
TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId(); TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId();
check(UniqueNetId != nullptr); check(UniqueNetId != nullptr);
PCUniqueNetIdMap.Add(NewPlayer, UniqueNetId);
// Get the online session interface. // Get the online session interface.
IOnlineSubsystem* Subsystem = Online::GetSubsystem(NewPlayer->GetWorld()); IOnlineSubsystem* Subsystem = Online::GetSubsystem(NewPlayer->GetWorld());
IOnlineSessionPtr Session = Subsystem->GetSessionInterface(); IOnlineSessionPtr Session = Subsystem->GetSessionInterface();
...@@ -83,6 +85,7 @@ void AarnocMainGameModeBase::PostLogin(APlayerController* NewPlayer) ...@@ -83,6 +85,7 @@ void AarnocMainGameModeBase::PostLogin(APlayerController* NewPlayer)
// Not the correct type of player controller. // Not the correct type of player controller.
return; return;
} }
UNetConnection* IncomingNetConnection = Cast<UNetConnection>(CustomPC->Player); UNetConnection* IncomingNetConnection = Cast<UNetConnection>(CustomPC->Player);
if (!IsValid(IncomingNetConnection) || !IncomingNetConnection->PlayerId.IsValid()) if (!IsValid(IncomingNetConnection) || !IncomingNetConnection->PlayerId.IsValid())
{ {
...@@ -141,7 +144,8 @@ void AarnocMainGameModeBase::PreLogout(APlayerController* InPlayerController) ...@@ -141,7 +144,8 @@ void AarnocMainGameModeBase::PreLogout(APlayerController* InPlayerController)
// Get the unique player ID. // Get the unique player ID.
TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId(); TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId();
check(UniqueNetId != nullptr); //check(UniqueNetId != nullptr);
if (UniqueNetId == nullptr) return;
// Get the online session interface. // Get the online session interface.
IOnlineSubsystem* Subsystem = Online::GetSubsystem(InPlayerController->GetWorld()); IOnlineSubsystem* Subsystem = Online::GetSubsystem(InPlayerController->GetWorld());
...@@ -190,7 +194,7 @@ void AarnocMainGameModeBase::RegisterExistingPlayers() ...@@ -190,7 +194,7 @@ void AarnocMainGameModeBase::RegisterExistingPlayers()
TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId(); TSharedPtr<const FUniqueNetId> UniqueNetId = UniqueNetIdRepl.GetUniqueNetId();
check(UniqueNetId != nullptr); check(UniqueNetId != nullptr);
PCUniqueNetIdMap.Add(PlayerController, UniqueNetId);
UE_LOG(LogTemp, Display, TEXT("Register UserId: %s"), *UniqueNetId.Get()->ToString()); UE_LOG(LogTemp, Display, TEXT("Register UserId: %s"), *UniqueNetId.Get()->ToString());
IOnlineSubsystem* Subsystem = Online::GetSubsystem(PlayerController->GetWorld()); IOnlineSubsystem* Subsystem = Online::GetSubsystem(PlayerController->GetWorld());
...@@ -211,38 +215,50 @@ void AarnocMainGameModeBase::Logout(AController* Exiting) ...@@ -211,38 +215,50 @@ void AarnocMainGameModeBase::Logout(AController* Exiting)
{ {
return; return;
} }
APlayerController* PC = Cast<APlayerController>(Exiting); AARNOPlayerController* PC = Cast<AARNOPlayerController>(Exiting);
if (!IsValid(PC)) if (!IsValid(PC))
{ {
return; return;
} }
if (!PC->IsLocalPlayerController() || !IsValid(PC->Player)) //if (!PC->IsLocalPlayerController() || !IsValid(PC->Player))
{ //{
return; // return;
} //}
//
//UNetConnection* PCNet = Cast<UNetConnection>(PC->Player); //UNetConnection* PCNet = Cast<UNetConnection>(PC->Player);
/* PCNet is invalid and needs another method to get the Unique Net ID*/
//if (!IsValid(PCNet) || !PCNet->PlayerId.IsValid()) //if (!IsValid(PCNet) || !PCNet->PlayerId.IsValid())
//{ //{
// return; // return;
//} //}
//TSharedRef<const FUniqueNetId> UserId = GetControllerUniqueNetId(PC).ToSharedRef(); //TSharedPtr<const FUniqueNetId> UserId = GetControllerUniqueNetId(PC);
//TSharedRef<const FUniqueNetId> UserId = PCNet->PlayerId.GetUniqueNetId().ToSharedRef(); //TSharedRef<const FUniqueNetId> UserId = PCNet->PlayerId.GetUniqueNetId().ToSharedRef();
//TSharedRef<const FUniqueNetId> UserId = PCUniqueNetIdMap.Find(PC)->ToSharedRef(); if (!PCUniqueNetIdMap.Contains(Exiting))
if (!PCUniqueNetIdMap.Find(PC))
{ {
Super::Logout(Exiting);
return; return;
} }
TSharedRef<const FUniqueNetId> UserId = PCUniqueNetIdMap.Find(PC)->ToSharedRef();
UE_LOG(LogTemp, Display, TEXT("Logout UserId: %s"), *UserId.Get().ToString()); TSharedRef<const FUniqueNetId> UserId = PCUniqueNetIdMap.Find(Exiting)->ToSharedRef();
//if (!PC->PlayerId.IsValid()) return;
UE_LOG(LogTemp, Display, TEXT("Logout UserId: %s"), *UserId->ToString());
IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld()); IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
TSharedPtr<IOnlineIdentity, ESPMode::ThreadSafe> Identity = Subsystem->GetIdentityInterface(); TSharedPtr<IOnlineIdentity, ESPMode::ThreadSafe> Identity = Subsystem->GetIdentityInterface();
TSharedPtr<IOnlineVoiceAdmin, ESPMode::ThreadSafe> VoiceAdmin = Online::GetVoiceAdminInterface(Subsystem); TSharedPtr<IOnlineVoiceAdmin, ESPMode::ThreadSafe> VoiceAdmin = Online::GetVoiceAdminInterface(Subsystem);
// Get the online session interface. // Get the online session interface.
IOnlineSessionPtr Session = Subsystem->GetSessionInterface(); IOnlineSessionPtr Session = Subsystem->GetSessionInterface();
if (Session->GetNamedSession(NAME_GameSession) == nullptr)
{
Super::Logout(Exiting);
return;
}
// You'll need to use the same channel as when you issued credentials in the first place. // You'll need to use the same channel as when you issued credentials in the first place.
FString ChannelName = Session->GetNamedSession(NAME_GameSession)->GetSessionIdStr(); FString ChannelName = Session->GetNamedSession(NAME_GameSession)->GetSessionIdStr();
...@@ -259,9 +275,16 @@ void AarnocMainGameModeBase::Logout(AController* Exiting) ...@@ -259,9 +275,16 @@ void AarnocMainGameModeBase::Logout(AController* Exiting)
{ {
// User couldn't be kicked. They've already left the server at this point, so // User couldn't be kicked. They've already left the server at this point, so
// all you can really do is log the error. // all you can really do is log the error.
UE_LOG(LogTemp, Display, TEXT("KickParticipant Unsuccesful"));
}
else
{
UE_LOG(LogTemp, Display, TEXT("LocalUserId: %s, TargetUserId: %s, Voice Participant Kicked."), *LocalUserId.ToString(), *TargetUserId.ToString());
} }
})); }));
PCUniqueNetIdMap.Remove(Exiting);
// This must be at the end, or the player's unique net ID will have been unset. // This must be at the end, or the player's unique net ID will have been unset.
Super::Logout(Exiting); Super::Logout(Exiting);
} }
...@@ -278,6 +301,7 @@ TSharedPtr<const FUniqueNetId> AarnocMainGameModeBase::GetControllerUniqueNetId( ...@@ -278,6 +301,7 @@ TSharedPtr<const FUniqueNetId> AarnocMainGameModeBase::GetControllerUniqueNetId(
ULocalPlayer* LocalPlayer = InPlayerController->GetLocalPlayer(); ULocalPlayer* LocalPlayer = InPlayerController->GetLocalPlayer();
if (IsValid(LocalPlayer)) if (IsValid(LocalPlayer))
{ {
UE_LOG(LogTemp, Error, TEXT("GetControllerUniqueNetId returning"));
return LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId(); return LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId();
} }
} }
......
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
void RegisterExistingPlayers(); void RegisterExistingPlayers();
virtual void Logout(AController* Exiting) override; virtual void Logout(AController* Exiting) override;
TSharedPtr<const FUniqueNetId> GetControllerUniqueNetId(APlayerController* InPlayerController); TSharedPtr<const FUniqueNetId> GetControllerUniqueNetId(APlayerController* InPlayerController);
TMap<APlayerController*, TSharedPtr<const FUniqueNetId>> PCUniqueNetIdMap; TMap<AController*, FUniqueNetIdPtr> PCUniqueNetIdMap;
private: private:
bool bExistingPlayersRegistered; bool bExistingPlayersRegistered;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment