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

Updated arnocMainGameModeBase

parent 9e3322a9
No related branches found
No related tags found
No related merge requests found
...@@ -159,6 +159,85 @@ void AarnocMainGameModeBase::RegisterExistingPlayers() ...@@ -159,6 +159,85 @@ void AarnocMainGameModeBase::RegisterExistingPlayers()
bExistingPlayersRegistered = true; bExistingPlayersRegistered = true;
} }
void AarnocMainGameModeBase::Logout(AController* Exiting)
{
if (!IsValid(Exiting))
{
return;
}
APlayerController* PC = Cast<APlayerController>(Exiting);
if (!IsValid(PC))
{
return;
}
if (!PC->IsLocalPlayerController() || !IsValid(PC->Player))
{
return;
}
UNetConnection* PCNet = Cast<UNetConnection>(PC->Player);
if (!IsValid(PCNet) || !PCNet->PlayerId.IsValid())
{
return;
}
TSharedRef<const FUniqueNetId> UserId = GetControllerUniqueNetId(PC).ToSharedRef();
IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
TSharedPtr<IOnlineIdentity, ESPMode::ThreadSafe> Identity = Subsystem->GetIdentityInterface();
TSharedPtr<IOnlineVoiceAdmin, ESPMode::ThreadSafe> VoiceAdmin = Online::GetVoiceAdminInterface(Subsystem);
// Get the online session interface.
IOnlineSessionPtr Session = Subsystem->GetSessionInterface();
// You'll need to use the same channel as when you issued credentials in the first place.
FString ChannelName = Session->GetNamedSession("MyLocalSessionName")->GetSessionIdStr();
VoiceAdmin->KickParticipant(
*Identity->GetUniquePlayerId(0), // This will get the "dedicated server" ID.
ChannelName,
*UserId,
FOnVoiceAdminKickParticipantComplete::CreateLambda([](
const FOnlineError& Result,
const FUniqueNetId& LocalUserId,
const FUniqueNetId& TargetUserId)
{
if (!Result.WasSuccessful())
{
// User couldn't be kicked. They've already left the server at this point, so
// all you can really do is log the error.
}
}));
// This must be at the end, or the player's unique net ID will have been unset.
Super::Logout(Exiting);
}
TSharedPtr<const FUniqueNetId> AarnocMainGameModeBase::GetControllerUniqueNetId(APlayerController* InPlayerController)
{
if (!IsValid(InPlayerController))
{
return nullptr;
}
if (InPlayerController->IsLocalPlayerController())
{
ULocalPlayer* LocalPlayer = InPlayerController->GetLocalPlayer();
if (IsValid(LocalPlayer))
{
return LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId();
}
}
UNetConnection* RemoteNetConnection = Cast<UNetConnection>(InPlayerController->Player);
if (IsValid(RemoteNetConnection))
{
return RemoteNetConnection->PlayerId.GetUniqueNetId();
}
UE_LOG(LogTemp, Error, TEXT("Player controller does not have a valid remote network connection"));
return nullptr;
}
void AarnocMainGameModeBase::IssuedCredentialsForPlayer(const FOnlineError& Result, const FUniqueNetId& LocalUserId, void AarnocMainGameModeBase::IssuedCredentialsForPlayer(const FOnlineError& Result, const FUniqueNetId& LocalUserId,
const TArray<FVoiceAdminChannelCredentials>& Credentials, FString InChannelName, AARNOPlayerController* NewPlayer) const TArray<FVoiceAdminChannelCredentials>& Credentials, FString InChannelName, AARNOPlayerController* NewPlayer)
{ {
......
...@@ -24,6 +24,8 @@ public: ...@@ -24,6 +24,8 @@ public:
virtual void PostLogin(APlayerController* NewPlayer) override; virtual void PostLogin(APlayerController* NewPlayer) override;
void RegisterExistingPlayers(); void RegisterExistingPlayers();
virtual void Logout(AController* Exiting) override;
TSharedPtr<const FUniqueNetId> GetControllerUniqueNetId(APlayerController* InPlayerController);
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