after reconnect error !JoinChannel ErrorCode errors.com.epicgames.voicechat.not_permitted
sorry for the English translation, not my language.
The problem is the following.
I will briefly describe the logic.
A game about space, multiplayer. ships are flying, collecting resources from asteroids (While I’m writing it, 10 or more of them will be released))). A dedicated server on another computer in my office.
To fly into the starbase is to go to the local map on the client. and when the game starts, the player is logged in and if he has in the mysql users table on the same neighboring computer that is accessible by ip after authorization, either to the local card or immediately connects to the server card and his position is replicated. as well as shells and other small things. I don’t use standard motion functions. But it doesn’t matter. The player also gets to the server from the base.
And so I add a voice chat.
The player has a collider in which the intersection with another collider of the player is determined.
void AStarshipPawn::OnBeginOverlapRoomSphere(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
UE_LOG(LogTemp, Warning, TEXT("OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode) return;
if (!GalaxyGameMode->HasAuthority()) return;
if (StarshipData.Health <= 0.f) return;
if (StarshipData.UserId == EMPTY_INT_VALUE) return;
if(USphereComponent* SphereComponent = Cast<USphereComponent>(OtherComp))
{
UE_LOG(LogTemp, Warning, TEXT("1 OnBeginOverlapRoomSphere %s"), *SphereComponent->GetName())
if (AGalaxyPlayerController* PlayerController = Cast<AGalaxyPlayerController>(GetOwner()))
{
if(!PlayerController->VoiceChatComponent) return;
if(!PlayerController->VoiceChatComponent->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("*!ServerVoiceChat"));
return;
}
UE_LOG(LogTemp, Warning, TEXT("2 OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
if(PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Role == EVoiceRoomRole::Participant) return;
UE_LOG(LogTemp, Warning, TEXT("3 OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
if(AStarshipPawn* Starship = Cast<AStarshipPawn>(OtherActor))
{
if (Starship->StarshipData.Health <= 0.f) return;
if (Starship->StarshipData.UserId == EMPTY_INT_VALUE) return;
if (StarshipData.UserId == Starship->StarshipData.UserId) return;
UE_LOG(LogTemp, Warning, TEXT("4 OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
if(AGalaxyPlayerController* OtherPlayerController = Cast<AGalaxyPlayerController>(Starship->GetOwner()))
{
if(!OtherPlayerController->VoiceChatComponent) return;
if(!OtherPlayerController->VoiceChatComponent->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("**!ServerVoiceChat"));
return;
}
if(OtherPlayerController->VoiceChatComponent->IsServerRoleOwner())
{
UE_LOG(LogTemp, Warning, TEXT("oTHER PLAYER role"));
return;
}
UE_LOG(LogTemp, Warning, TEXT("5 OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
if(PlayerController->VoiceChatComponent->ServerAddOverlapShip(StarshipData.UserId, Starship->StarshipData.UserId))
{
UE_LOG(LogTemp, Warning, TEXT("1 AddOverlapShip %s => %s"), *FString::FromInt(StarshipData.UserId), *FString::FromInt(Starship->StarshipData.UserId));
}
if(OtherPlayerController->VoiceChatComponent->ServerAddOverlapShip(Starship->StarshipData.UserId, StarshipData.UserId))
{
UE_LOG(LogTemp, Warning, TEXT("2 AddOverlapShip %s => %s"), *FString::FromInt(Starship->StarshipData.UserId), *FString::FromInt(StarshipData.UserId));
}
UE_LOG(LogTemp, Warning, TEXT("6 OnBeginOverlapRoomSphere %s"), *FString::SanitizeFloat(RoomSphere->GetUnscaledSphereRadius()))
int IndexCollision;
if(GalaxyGameMode->VoiceComponent->BeginCollision(StarshipData.UserId, Starship->StarshipData.UserId, IndexCollision))
{
UE_LOG(LogTemp, Warning, TEXT("BeginCollision => %s"), *FString::FromInt(IndexCollision));
if(OtherPlayerController->VoiceChatComponent->IsServerRoleNull() && PlayerController->VoiceChatComponent->IsServerRoleNull() && PlayerController->VoiceChatComponent->ArrayOverlapShip.Num() >= 1)
{
UE_LOG(LogTemp, Warning, TEXT("OtherPlayerController IsServerRoleNull"));
UE_LOG(LogTemp, Warning, TEXT("PlayerController IsServerRoleNull"));
UE_LOG(LogTemp, Warning, TEXT("PlayerController->VoiceChatComponent->ArrayOverlapShip.Num(%s)"), *FString::FromInt(PlayerController->VoiceChatComponent->ArrayOverlapShip.Num()));
if(PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus)
{
UE_LOG(LogTemp, Warning, TEXT("Already Attempt Create room => %s"), *FString::FromInt(StarshipData.UserId));
return;
}
UE_LOG(LogTemp, Warning, TEXT("Attempt Create room => %s"), *FString::FromInt(StarshipData.UserId));
GalaxyGameMode->VoiceComponent->CreateSingleRoom(StarshipData.UserId, PlayerController->VoiceChatComponent->ArrayOverlapShip);
}
if(OtherPlayerController->VoiceChatComponent->IsServerRoleNull() && PlayerController->VoiceChatComponent->IsServerRoleOwner() && PlayerController->VoiceChatComponent->ArrayOverlapShip.Num() >= 1)
{
UE_LOG(LogTemp, Warning, TEXT("OtherPlayerController IsServerRoleNull"));
UE_LOG(LogTemp, Warning, TEXT("PlayerController IsServerRoleOwner"));
UE_LOG(LogTemp, Warning, TEXT("PlayerController->VoiceChatComponent->ArrayOverlapShip.Num(%s)"), *FString::FromInt(PlayerController->VoiceChatComponent->ArrayOverlapShip.Num()));
if(PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus)
{
UE_LOG(LogTemp, Warning, TEXT("Already Attempt Create room => %s"), *FString::FromInt(StarshipData.UserId));
return;
}
UE_LOG(LogTemp, Warning, TEXT("Attempt add to room => %s"), *FString::FromInt(StarshipData.UserId));
GalaxyGameMode->VoiceComponent->CreateSingleRoom(StarshipData.UserId, PlayerController->VoiceChatComponent->ArrayOverlapShip);
}
}
}
}
}
}
}
and
void AStarshipPawn::OnEndOverlapRoomSphere(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int OtherBodyIndex)
{
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode) return;
if (!GalaxyGameMode->HasAuthority()) return;
if (StarshipData.Health <= 0.f) return;
if (StarshipData.UserId == EMPTY_INT_VALUE) return;
if(USphereComponent* SphereComponent = Cast<USphereComponent>(OtherComp))
{
UE_LOG(LogTemp, Warning, TEXT("OnEndOverlapRoomSphere %s"), *SphereComponent->GetName());
if (AGalaxyPlayerController* PlayerController = Cast<AGalaxyPlayerController>(GetOwner()))
{
if(!PlayerController->VoiceChatComponent) return;
if(!PlayerController->VoiceChatComponent->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("+!ServerVoiceChat"));
return;
}
if(!PlayerController->VoiceChatComponent->IsServerRoleParticipant())
{
UE_LOG(LogTemp, Warning, TEXT("OnEndOverlapRoomSphere !IsRoleParticipant"));
return;
}
if(AStarshipPawn* Starship = Cast<AStarshipPawn>(OtherActor))
{
if (Starship->StarshipData.Health <= 0.f) return;
if (Starship->StarshipData.UserId == EMPTY_INT_VALUE) return;
if (StarshipData.UserId == Starship->StarshipData.UserId) return;
if(AGalaxyPlayerController* OtherPlayerController = Cast<AGalaxyPlayerController>(Starship->GetOwner()))
{
if(!OtherPlayerController->VoiceChatComponent) return;
if(!OtherPlayerController->VoiceChatComponent->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("++!ServerVoiceChat"));
return;
}
if(PlayerController->VoiceChatComponent->ServerRemoveOverlapShip(StarshipData.UserId, Starship->StarshipData.UserId))
{
}
if(OtherPlayerController->VoiceChatComponent->ServerRemoveOverlapShip(Starship->StarshipData.UserId, StarshipData.UserId))
{
}
int IndexCollision;
if(GalaxyGameMode->VoiceComponent->EndCollision(StarshipData.UserId, Starship->StarshipData.UserId, IndexCollision))
{
UE_LOG(LogTemp, Warning, TEXT("EndCollision => %s"), *FString::FromInt(IndexCollision));
}
if(PlayerController->VoiceChatComponent->IsServerRoleParticipant() && OtherPlayerController->VoiceChatComponent->IsServerRoleOwner())
{
if(OtherPlayerController->VoiceChatComponent->ArrayOverlapShip.Num() > 0)
{
if(OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus)
{
UE_LOG(LogTemp, Warning, TEXT("Already Begin leave room => %s"), *FString::FromInt(StarshipData.UserId));
return;
}
UE_LOG(LogTemp, Warning, TEXT("Begin leave room => %s"), *FString::FromInt(OtherPlayerController->VoiceChatComponent->ArrayOverlapShip.Num()));
GalaxyGameMode->VoiceComponent->CreateSingleRoom(Starship->StarshipData.UserId, OtherPlayerController->VoiceChatComponent->ArrayOverlapShip);
PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer();
PlayerController->VoiceChatComponent->ActionCloseRoom();
} else
{
UE_LOG(LogTemp, Warning, TEXT("Begin close room => %s"), *FString::FromInt(OtherPlayerController->VoiceChatComponent->ArrayOverlapShip.Num()));
UE_LOG(LogTemp, Warning, TEXT("Begin close room => %s"), *FString::FromInt(OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Index));
UE_LOG(LogTemp, Warning, TEXT("Begin close room => %s"), *FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom.Num()));
if(OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Index != INDEX_NONE && OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Index < GalaxyGameMode->VoiceComponent->ArrayRoom.Num())
{
UE_LOG(LogTemp, Warning, TEXT("Players %s"), *FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom[OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Index].ArrayPlayers.Num()));
for (const int& Player : GalaxyGameMode->VoiceComponent->ArrayRoom[OtherPlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.Index].ArrayPlayers)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(Player))
{
if (!GalaxyGameMode->ServerMapPlayers[Player]) continue;
if (!GalaxyGameMode->ServerMapPlayers[Player]->GetPawn()) continue;
GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ActionCloseRoom();
}
}
}
}
}
}
}
}
}
}
and when he clicks go to the hangar from space or exit the game when he is on the server
void UVoiceChatComponent::ServerForceLogoutAction(const int& NearestIndex, const EVoiceChatStatus& NewVoiceChatStatus)
{
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
StarshipPawn->RoomSphere->SetSphereRadius(0.f);
const int& IndexCollision = GalaxyGameMode->VoiceComponent->ArrayCollision.FindLastByPredicate(
[this](const FCollision& Collision)
{
return Collision.Players.Contains(StarshipPawn->StarshipData.UserId);
});
if (IndexCollision != INDEX_NONE)
{
GalaxyGameMode->VoiceComponent->ArrayCollision.RemoveAt(IndexCollision);
}
if (IsServerRoleNull())
{
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
}
else if (IsServerRoleParticipant() || IsServerRoleOwner())
{
if (ServerVoiceChatDataPlayer.Index < GalaxyGameMode->VoiceComponent->ArrayRoom.Num())
{
const int& RoomIndex = ServerVoiceChatDataPlayer.Index;
FVoiceTestRoom VoiceTestRoom = GalaxyGameMode->VoiceComponent->ArrayRoom[RoomIndex];
const int& FindIndexRemovedPlayer = VoiceTestRoom.ArrayPlayers.FindLastByPredicate(
[this](const int& Player)
{
return Player == StarshipPawn->StarshipData.UserId;
});
if (FindIndexRemovedPlayer != INDEX_NONE && FindIndexRemovedPlayer < VoiceTestRoom.ArrayPlayers.Num())
{
//Удаляем себя из списка участников
VoiceTestRoom.ArrayPlayers.RemoveAt(FindIndexRemovedPlayer);
if (VoiceTestRoom.ArrayPlayers.Num() == 1)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<
int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
if (GalaxyGameMode->ServerMapPlayers.Contains(VoiceTestRoom.ArrayPlayers[0]))
{
if (GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]])
{
if (GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->GetPawn())
{
const int& Index = GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->
ArrayOverlapShip.FindLastByPredicate(
[this](const int& OverlapShip)
{
return OverlapShip == StarshipPawn->StarshipData.UserId;
});
if (Index != INDEX_NONE && Index < GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent
->ArrayOverlapShip.Num())
{
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ArrayOverlapShip.RemoveAt(
Index);
}
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ActionCloseRoom();
}
}
}
}
else if (VoiceTestRoom.ArrayPlayers.Num() >= 2)
{
for (const int& Player : VoiceTestRoom.ArrayPlayers)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(Player))
{
if (GalaxyGameMode->ServerMapPlayers[Player])
{
if (GalaxyGameMode->ServerMapPlayers[Player]->GetPawn())
{
const int& Index = GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.
FindLastByPredicate(
[this](const int& OverlapShip)
{
return OverlapShip == StarshipPawn->
StarshipData.UserId;
});
if (Index != INDEX_NONE && Index < GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.
Num())
{
GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.RemoveAt(Index);
}
}
}
}
}
GalaxyGameMode->VoiceComponent->CreateSingleRoom(VoiceTestRoom.OwnerId, VoiceTestRoom.ArrayPlayers);
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<
int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
}
UE_LOG(LogTemp, Warning, TEXT("RoomIndex %s"), *FString::FromInt(RoomIndex));
UE_LOG(LogTemp, Warning, TEXT("GalaxyGameMode->VoiceComponent->ArrayRoom %s"),
*FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom.Num()));
// GalaxyGameMode->VoiceComponent->ArrayRoom[RoomIndex] = VoiceTestRoom;
}
}
}
}
void UVoiceChatComponent::ActionCreateRoom(const int OwnerId, const FString& ChannelName, const FString& RoomIdString,
const FString& ClientBaseUrlString,
const FString& Token, const TArray<FRoomParticipantData>& ArrayParticipants)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
const EVoiceChatStatus& OldStatus = VoiceChatData.Status;
UE_LOG(LogTemp, Warning, TEXT("CreateRoom %s => %s"), *ChannelName, *FString::FromInt(OwnerId));
VoiceChatData.Owner = OwnerId;
VoiceChatData.ChannelName = ChannelName;
VoiceChatData.RoomIdString = RoomIdString;
VoiceChatData.ClientBaseUrlString = ClientBaseUrlString;
VoiceChatData.Token = Token;
VoiceChatData.ArrayParticipants = ArrayParticipants;
if (OldStatus == EVoiceChatStatus::Create)
{
VoiceChatData.Status = EVoiceChatStatus::Update;
}
else
{
VoiceChatData.Status = EVoiceChatStatus::Create;
}
VoiceChatData.HangarId = -1;
VoiceChatData.Text = TEXT("");
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::ActionCloseRoom()
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
VoiceChatData.RoomIdString = EMPTY_STRING_VALUE;
VoiceChatData.Status = EVoiceChatStatus::Close;
VoiceChatData.HangarId = -1;
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::OtherAction(const int& HangarId, const EVoiceChatStatus& VoiceChatStatus)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
VoiceChatData.Status = VoiceChatStatus;
VoiceChatData.HangarId = HangarId;
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceComponent::CreateSingleRoom(const int& OwnerId, const TArray<int> ArrayParticipants)
{
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetOwner());
if (!GalaxyGameMode) return;
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyGameMode->ServerMapPlayers.Contains(OwnerId)) return;
AGalaxyPlayerController* PlayerController = GalaxyGameMode->ServerMapPlayers[OwnerId];
if (!PlayerController) return;
if (PlayerController->VoiceChatComponent == nullptr) return;
PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus = true;
AStarshipPawn* StarshipPawn = Cast<AStarshipPawn>(PlayerController->GetPawn());
if (!StarshipPawn) return;
FServerStruct Server;
if (!GalaxyGameInstance->TableDataAsset->GetServer(GalaxyGameMode->ServerName, Server))
{
UE_LOG(LogTemp, Warning, TEXT("Dont Server %s"), *GalaxyGameMode->ServerName.ToString())
return;
}
FParticipantsRoom ParticipantsRoom;
FParticipant ParticipantOwner;
ParticipantOwner.puid = OwnerId;
ParticipantOwner.clientIp = Server.Ip;
ParticipantOwner.hardMuted = false;
ParticipantsRoom.participants.Add(ParticipantOwner);
for (const int& OverlapShip : ArrayParticipants)
{
if(GalaxyGameMode->ServerMapPlayers.Contains(OverlapShip))
{
if(GalaxyGameMode->ServerMapPlayers[OverlapShip])
{
if(GalaxyGameMode->ServerMapPlayers[OverlapShip]->GetPawn())
{
FParticipant Participant;
Participant.puid = OverlapShip;
Participant.clientIp = Server.Ip;
Participant.hardMuted = false;
ParticipantsRoom.participants.Add(Participant);
GalaxyGameMode->ServerMapPlayers[OverlapShip]->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus = true;
}
}
}
}
const FString& ChannelName = FString::FromInt(OwnerId);
UE_LOG(LogTemp, Warning, TEXT("participants %s %s"), *FString::FromInt(ParticipantsRoom.participants.Num()), *ChannelName)
FString StringParticipants;
FJsonObjectConverter::UStructToJsonObjectString<FParticipantsRoom>(ParticipantsRoom, StringParticipants);
FString ProductId;
FString SandboxId;
FString DeploymentId;
FString ClientId;
FString ClientSecret;
FString EncryptionKey;
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ProductId"), ProductId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("SandboxId"), SandboxId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("DeploymentId"), DeploymentId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientId"), ClientId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientSecret"), ClientSecret, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientEncryptionKey"), EncryptionKey, GEngineIni);
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
HttpRequest->AppendToHeader(TEXT("Accept"), TEXT("application/json"));
HttpRequest->AppendToHeader(
TEXT("Authorization"), *FString::Printf(TEXT("Bearer %s"), *GalaxyGameMode->ServerAccessToken));
HttpRequest->SetContentAsString(StringParticipants);
HttpRequest->SetURL(
FString::Printf(
TEXT("https://api.epicgames.dev/rtc/v1/%s/room/%s"), *DeploymentId,
*ChannelName));
HttpRequest->SetVerb("POST");
HttpRequest->OnProcessRequestComplete().BindLambda(
[this, OwnerId, ChannelName, PlayerController, StarshipPawn](FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
bool bWasSuccessful)
{
if (!bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("!bWasSuccessful CreateRoom"))
return;
}
UE_LOG(LogTemp, Warning, TEXT("Create Room content [%s]"), *HttpResponse->GetContentAsString());
TSharedPtr<FJsonObject> JsonObject;
if (!FJsonSerializer::Deserialize(
TJsonReaderFactory<>::Create(HttpResponse->GetContentAsString()), JsonObject) && JsonObject.IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("!Deserialize %s"), *HttpResponse->GetContentAsString());
return;
}
FString ErrorCodeString;
if (UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyErrorCode, JsonObject, ErrorCodeString))
{
TSharedPtr<FJsonValue> ErrorMessageObject = JsonObject->TryGetField(
UGalaxyGameInstance::ResponseKeyErrorMessage);
UE_LOG(LogTemp, Warning, TEXT("%s"), *ErrorMessageObject->AsString())
return;
}
FString RoomIdString;
if (!UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyRoomId, JsonObject, RoomIdString))
{
UE_LOG(LogTemp, Warning, TEXT("!RoomIdString"))
return;
}
FString DeploymentIdString;
if (UVoiceComponent::ParseString(TEXT("deploymentId"), JsonObject, DeploymentIdString))
{
UE_LOG(LogTemp, Warning, TEXT("DeploymentIdString %s"), *DeploymentIdString);
}
FString ClientBaseUrlString;
if (UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyClientBaseUrl, JsonObject,
ClientBaseUrlString))
{
UE_LOG(LogTemp, Warning, TEXT("ClientBaseUrlString %s"), *ClientBaseUrlString);
}
TArray<FRoomParticipant> ArrayRoomParticipant;
if (!UVoiceComponent::ParseParticipants(JsonObject, ArrayRoomParticipant))
{
UE_LOG(LogTemp, Warning, TEXT("!ArrayRoomParticipant"))
return;
}
if (ArrayRoomParticipant.Num() == 0)
{
UE_LOG(LogTemp, Warning, TEXT("ArrayRoomParticipant == 0"))
return;
}
TArray<FRoomParticipantData> ArrayParticipants = TArray<FRoomParticipantData>();
TMap<int, FString> MapToken = TMap<int, FString>();
for (const FRoomParticipant& RoomParticipant : ArrayRoomParticipant)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(RoomParticipant.puid))
{
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]) return;
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()) return;
if (AStarshipPawn* Starship = Cast<AStarshipPawn>(GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()))
{
FRoomParticipantData RoomParticipantData;
RoomParticipantData.UserId = Starship->StarshipData.UserId;
RoomParticipantData.UserEmail = Starship->StarshipData.UserEmail;
RoomParticipantData.UserName = Starship->StarshipData.UserName;
RoomParticipantData.UserIcon = Starship->StarshipData.UserIcon;
ArrayParticipants.Add(RoomParticipantData);
MapToken.Add(RoomParticipant.puid, RoomParticipant.token);
UE_LOG(LogTemp, Warning, TEXT("%s Token %s"), *FString::FromInt(RoomParticipant.puid), *RoomParticipant.token);
}
}
}
const int& IndexRoom = ArrayRoom.FindLastByPredicate(
[this, OwnerId](const FVoiceTestRoom& VoiceTestRoom)
{
return VoiceTestRoom.OwnerId == OwnerId;
});
const int& NewIndexRoom = ArrayRoom.Num();
for (const FRoomParticipant& RoomParticipant : ArrayRoomParticipant)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(RoomParticipant.puid))
{
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]) continue;
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()) continue;
UE_LOG(LogTemp, Warning, TEXT("Uid %s => %s"), *ChannelName, *FString::FromInt(RoomParticipant.puid));
GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer(
IndexRoom == INDEX_NONE ? NewIndexRoom : IndexRoom, EVoiceRoomRole::Participant);
GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->VoiceChatComponent->ActionCreateRoom(
OwnerId,
ChannelName,
RoomIdString,
ClientBaseUrlString,
MapToken[RoomParticipant.puid],
ArrayParticipants
);
}
}
UE_LOG(LogTemp, Warning, TEXT("Create %s => %s"), *ChannelName, *FString::FromInt(ArrayParticipants.Num()));
if(IndexRoom == INDEX_NONE)
{
FVoiceTestRoom VoiceTestRoom;
VoiceTestRoom.OwnerId = OwnerId;
VoiceTestRoom.RoomId = NewIndexRoom;
VoiceTestRoom.RoomName = OwnerId;
VoiceTestRoom.ArrayPlayers.Empty();
VoiceTestRoom.ArrayPlayers = TArray<int>();
for (const FRoomParticipantData& RoomParticipant : ArrayParticipants)
{
VoiceTestRoom.ArrayPlayers.Add(RoomParticipant.UserId);
}
ArrayRoom.Add(VoiceTestRoom);
} else
{
ArrayRoom[IndexRoom].ArrayPlayers.Empty();
ArrayRoom[IndexRoom].ArrayPlayers = TArray<int>();
for (const FRoomParticipantData& RoomParticipant : ArrayParticipants)
{
ArrayRoom[IndexRoom].ArrayPlayers.Add(RoomParticipant.UserId);
}
}
PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer(IndexRoom == INDEX_NONE ? NewIndexRoom : IndexRoom, EVoiceRoomRole::Owner);
});
HttpRequest->ProcessRequest();
}
void UVoiceChatComponent::Server_ToggleEnableVoiceChat_Implementation(bool bVoiceChat)
{
UE_LOG(LogTemp, Warning, TEXT("***********************************Server_ToggleEnableVoiceChat*************************************"));
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
this->bServerVoiceEnable = bVoiceChat;
if (this->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("ServerVoiceChat"));
StarshipPawn->RoomSphere->SetSphereRadius(15000.f, true);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("!ServerVoiceChat"));
StarshipPawn->RoomSphere->SetSphereRadius(0.f, false);
}
UE_LOG(LogTemp, Warning, TEXT("***********************************Server_ToggleEnableVoiceChat*************************************"));
}
it’s only on the server
Client code
void UVoiceChatComponent::ToggleEnableVoiceChat(bool bVoiceChat)
{
if (bVoiceChat)
{
AttemptVoiceChatConnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
Server_ToggleEnableVoiceChat(true);
}));
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
Server_ToggleEnableVoiceChat(false);
}));
}
}
void UVoiceChatComponent::OnRep_VoiceChatData()
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyHUD) return;
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
if (!GalaxyScreen) return;
if (VoiceChatData.Status == EVoiceChatStatus::DontCreate)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Dont")));
}
else if (VoiceChatData.Status == EVoiceChatStatus::Create || VoiceChatData.Status == EVoiceChatStatus::Update)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Connecting...")));
GalaxyScreen->UserVerticalBox->ClearChildren();
for (const FRoomParticipantData& RoomParticipantData : VoiceChatData.ArrayParticipants)
{
if (RoomParticipantData.UserId == StarshipPawn->StarshipData.UserId) continue;
UVoiceUserItem* VoiceUserItem = CreateWidget<UVoiceUserItem>(GalaxyPlayerController,
GalaxyGameInstance->ItemDataAsset->VoiceUserItemClass);
VoiceUserItem->PlayerName = FString::FromInt(RoomParticipantData.UserId);
VoiceUserItem->TextBlockUserName->SetText(FText::FromString(RoomParticipantData.UserName));
VoiceUserItem->TextBlockUserEmail->SetText(FText::FromString(RoomParticipantData.UserEmail));
VoiceUserItem->SetRenderOpacity(1.f);
GalaxyScreen->UserVerticalBox->AddChildToVerticalBox(VoiceUserItem);
}
if (VoiceChatData.Status == EVoiceChatStatus::Create && !VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE) && !VoiceChatData.Token.
Equals(EMPTY_STRING_VALUE))
{
AttemptConnectAndJoinChannel(VoiceChatData.Token, VoiceChatData.ClientBaseUrlString, VoiceChatData.RoomIdString);
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::ForceExit)
{
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::ForceExit"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionForceExit();
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionForceExit();
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Hangar)
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Hangar ") + VoiceChatData.RoomIdString, true, true, FColor::Red, 45.f);
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Hangar"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionEnterStarbase(VoiceChatData.HangarId);
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionEnterStarbase(VoiceChatData.HangarId);
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Die)
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Die ") + VoiceChatData.RoomIdString, true, true, FColor::Red, 45.f);
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Die"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionDie(VoiceChatData.HangarId);
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionDie(VoiceChatData.HangarId);
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Close)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Closing...")));
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Close"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this, GalaxyScreen](bool IsSuccess)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyHUD) return;
if (IsSuccess)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Close")));
}
else
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Close !IsSuccess")));
}
GalaxyScreen->UserVerticalBox->ClearChildren();
}));
}
}
void UVoiceChatComponent::AttemptVoiceChatConnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat)
return;
if (!VoiceChat->Initialize())
{
VoiceChat->Initialize(FOnVoiceChatInitializeCompleteDelegate::CreateLambda(
[this, OnCompleteToggleConnect](const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
return;
ToggleVoiceChatConnect(OnCompleteToggleConnect);
}));
}
else
{
ToggleVoiceChatConnect(OnCompleteToggleConnect);
}
}
void UVoiceChatComponent::AttemptVoiceChatDisconnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat)
{
return;
}
if (!VoiceChat->Initialize())
{
VoiceChat->Initialize(FOnVoiceChatInitializeCompleteDelegate::CreateLambda(
[this, OnCompleteToggleConnect](const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
return;
}
ToggleVoiceChatDisconnect(OnCompleteToggleConnect);
}));
}
else
{
ToggleVoiceChatDisconnect(OnCompleteToggleConnect);
}
}
void UVoiceChatComponent::AttemptVoiceChatLogout(const FString& Cell, const FString& RoomIdString, FOnCompleteLogout OnCompleteLogout)
{
if (VoiceChatUser == nullptr)
{
return;
}
UE_LOG(LogTemp, Warning, TEXT("Attempt leave %s"), *Cell)
VoiceChatUser->LeaveChannel(RoomIdString,
FOnVoiceChatChannelLeaveCompleteDelegate::CreateLambda(
[this, OnCompleteLogout](
const FString& ChannelName, const FVoiceChatResult& Result)
{
// if (VoiceChatUser->IsLoggingIn())
// {
// UE_LOG(LogTemp, Warning, TEXT("AttemptVoiceChatLogout LeaveChannel IsLoggingIn %s"), *ChannelName)
// return;
// }
VoiceChatUser->Logout(FOnVoiceChatLogoutCompleteDelegate::CreateLambda(
[this, OnCompleteLogout](const FString& PlayerName, const FVoiceChatResult& Result)
{
OnCompleteLogout.ExecuteIfBound(Result.IsSuccess());
}));
}));
}
void UVoiceChatComponent::AttemptVoiceChatLogin(const FString& Cell, const FString& Token, FOnCompleteLogin OnCompleteLogin)
{
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE)
{
GEngine->AddOnScreenDebugMessage(-1, 25.f, FColor::Red, TEXT("****AttemptVoiceChatLogin Error User Id"));
return;
}
const FString& Puid = FString::FromInt(StarshipPawn->StarshipData.UserId);
const FPlatformUserId& PlatformId = FPlatformMisc::GetPlatformUserForUserIndex(StarshipPawn->StarshipData.UserId);
UE_LOG(LogTemp, Warning, TEXT("Attempt login %s"), *Cell)
VoiceChatUser->Login(
PlatformId,
Puid, Token,
FOnVoiceChatLoginCompleteDelegate::CreateLambda(
[this, OnCompleteLogin, Puid](const FString& PlayerName, const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("VoiceChat->Login ") + Result.ErrorDesc, true, true, FColor::Red,
10.f);
return;
}
if (!VoiceChatUser->IsLoggedIn())
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("(**************!VoiceChatUser->IsLoggedIn()*****************"), true, true,
FColor::Red, 10.f);
return;
}
OnCompleteLogin.ExecuteIfBound(Puid);
}));
}
void UVoiceChatComponent::AttemptVoiceChatJoin(const FString& Cell, const FString& RoomIdString, const FString& ClientBaseUrlString,
const FString& Token, const FString& Puid)
{
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
FRoomCredentials RoomCredentials;
RoomCredentials.override_userid = TEXT("");
RoomCredentials.client_base_url = ClientBaseUrlString;
RoomCredentials.participant_token = Token;
FString ChannelCredentials;
FVoiceChatChannel3dProperties Properties;
Properties.AttenuationModel = EVoiceChatAttenuationModel::InverseByDistance;
Properties.MaxDistance = 1000000.f;
Properties.MinDistance = 1000.f;
Properties.Rolloff = 0.5f;
FJsonObjectConverter::UStructToJsonObjectString<FRoomCredentials>(RoomCredentials, ChannelCredentials);
UE_LOG(LogTemp, Warning, TEXT("Attempt join %s"), *Cell)
if(VoiceChatUser == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("VoiceChatUser == nullptr"), *Cell)
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("VoiceChatUser == nullptr")));
return;
}
if(VoiceChatUser->IsLoggedIn())
{
VoiceChatUser->JoinChannel(RoomIdString, ChannelCredentials, EVoiceChatChannelType::NonPositional,
FOnVoiceChatChannelJoinCompleteDelegate::CreateLambda(
[this, Puid, RoomIdString, GalaxyScreen](
const FString& ChannelName, const FVoiceChatResult& Result)
{
UE_LOG(LogTemp, Warning, TEXT("On JoinChannel %s"), *ChannelName)
if (!Result.IsSuccess())
{
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorDesc %s"), *Result.ErrorDesc)
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorCode %s"), *Result.ErrorCode)
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorNum %s"), *FString::FromInt(Result.ErrorNum))
switch (Result.ResultCode)
{
case EVoiceChatResult::Success:
UE_LOG(LogTemp, Warning, TEXT("Success JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::InvalidState:
UE_LOG(LogTemp, Warning, TEXT("InvalidState JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotInitialized:
UE_LOG(LogTemp, Warning, TEXT("NotInitialized JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotConnected:
UE_LOG(LogTemp, Warning, TEXT("NotConnected JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotLoggedIn:
UE_LOG(LogTemp, Warning, TEXT("NotLoggedIn JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotPermitted:
UE_LOG(LogTemp, Warning, TEXT("NotPermitted JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::Throttled:
UE_LOG(LogTemp, Warning, TEXT("Throttled JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::InvalidArgument:
UE_LOG(LogTemp, Warning, TEXT("InvalidArgument JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::CredentialsInvalid:
UE_LOG(LogTemp, Warning, TEXT("CredentialsInvalid JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::CredentialsExpired:
UE_LOG(LogTemp, Warning, TEXT("CredentialsExpired JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ClientTimeout:
UE_LOG(LogTemp, Warning, TEXT("ClientTimeout JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ServerTimeout:
UE_LOG(LogTemp, Warning, TEXT("ServerTimeout JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::DnsFailure:
UE_LOG(LogTemp, Warning, TEXT("DnsFailure JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ConnectionFailure:
UE_LOG(LogTemp, Warning, TEXT("ConnectionFailure JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ImplementationError:
UE_LOG(LogTemp, Warning, TEXT("ImplementationError JoinChannel %s"), *ChannelName)
break;
default: ;
}
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("!JoinChannel ") + Result.ErrorDesc));
return;
}
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(ChannelName));
UE_LOG(LogTemp, Warning, TEXT("[%s RoomIdString %s]"), *Puid, *RoomIdString)
}), Properties);
} else
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("!VoiceChatUser->IsLoggedIn()")));
}
}
and after we switch from the server to the local map and return to the server. returns an error
EOS_EResult=EOS_RTC_RoomAlreadyExists
but it continues to work. it is difficult to debug this point
this is already on the published game when tested over the network
and when you run the editor, dialog boxes pop up
EOSSharedTypes.h 63 line check(IsInGameThread());
static CallbackReturnType EOS_CALL CallbackImpl(const CallbackParamType* Data, CallbackExtraParams... ExtraParams)
{
TEOSGlobalCallback* CallbackThis = (TEOSGlobalCallback*)Data->ClientData;
check(CallbackThis);
if (CallbackThis->bIsGameThreadCallback)
{
check(IsInGameThread());
}
TSharedPtr <OwningType> Pinned = CallbackThis->Owner.Pin();
if (Pinned.IsValid())
{
check(CallbackThis->CallbackLambda);
if constexpr (std::is_void<CallbackReturnType>::value)
{
CallbackThis->CallbackLambda(Data, ExtraParams...);
}
else
{
return CallbackThis->CallbackLambda(Data, ExtraParams...);
}
}
if constexpr (!std::is_void<CallbackReturnType>::value)
{
// we need to return _something_ to compile.
return CallbackReturnType{};
}
}
and I can’t figure out what’s wrong.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Component/VoiceComponent.h"
#include "EngineUtils.h"
#include "VoiceChatResult.h"
#include "VoiceChat.h"
#include "GalaxyGameInstance.h"
#include "HttpModule.h"
#include "JsonObjectConverter.h"
#include "Component/VoiceChatComponent.h"
#include "Interfaces/IHttpRequest.h"
#include "Interfaces/IHttpResponse.h"
#include "GameMode/GalaxyGameMode.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Net/UnrealNetwork.h"
#include "Pawn/StarshipPawn.h"
#include "PlayerController/GalaxyPlayerController.h"
#include "DataAsset/TableDataAsset.h"
#include "Engine/Engine.h"
#include "GameFramework/GameStateBase.h"
#include "Misc/ConfigCacheIni.h"
#include "Struct/RoomParticipant.h"
#include "Struct/RoomParticipantData.h"
#include "Struct/ServerStruct.h"
#include "Struct/VoicePoint.h"
#include "Struct/VoiceGroup.h"
float UVoiceComponent::MaxDistance = 30000.f;
UVoiceComponent::UVoiceComponent()
{
PrimaryComponentTick.bCanEverTick = false;
}
void UVoiceComponent::BeginPlay()
{
Super::BeginPlay();
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
GalaxyGameMode = Cast<AGalaxyGameMode>(GetOuter());
}
TMap<int, TArray<FVoicePoint>> UVoiceComponent::GroupPoints(const TArray<FVoicePoint>& Points)
{
TMap<int, TArray<FVoicePoint>> Groups;
for (const auto& Point : Points)
{
int32 GroupIndex = -1;
bool FoundGroup = false;
for (const auto& KVP : Groups)
{
if (Distance(Point.Vector, KVP.Value[0].Vector) < MaxDistance)
{
GroupIndex = KVP.Key; // Точка попадает в существующую группу
FoundGroup = true;
break;
}
}
if (!FoundGroup)
{
GroupIndex = Groups.Num(); // Создаем новую группу
}
Groups.FindOrAdd(GroupIndex).Add(FVoicePoint(Point.UserId, Point.Vector)); // Добавляем точку в группу
}
return Groups;
}
void UVoiceComponent::GroupPointsByDistance(const TArray<FVoicePoint>& InPoints, TMap<int, TArray<FVoicePoint>>& GroupedPoints)
{
TArray<bool> Visited;
Visited.Init(false, InPoints.Num());
for (int32 i = 0; i < InPoints.Num(); ++i)
{
if (Visited[i]) continue; // Пропускаем уже обработанные точки
// Создаем новую группу для точки i
int32 GroupId = GroupedPoints.Num();
GroupedPoints.Add(GroupId);
GroupedPoints[GroupId].Add(InPoints[i]);
Visited[i] = true;
// Сравниваем с остальными точками
for (int32 j = i + 1; j < InPoints.Num(); ++j)
{
if (!Visited[j] && Distance(InPoints[i].Vector, InPoints[j].Vector) <= MaxDistance) // 1 метр = 100 см
{
GroupedPoints[GroupId].Add(InPoints[j]);
Visited[j] = true;
}
}
}
}
float UVoiceComponent::Distance(const FVector& P1, const FVector& P2)
{
return FVector::Distance(P1, P2);
}
bool UVoiceComponent::ParseString(const FString& Key, TSharedPtr<FJsonObject> JsonObject, FString& Value)
{
TSharedPtr<FJsonValue> Object = JsonObject->TryGetField(Key);
if (!Object) return false;
Value = Object ? Object->AsString() : FString();
return true;
}
bool UVoiceComponent::ParseArray(const FString& Key, TSharedPtr<FJsonObject> JsonObject, TArray<FString>& Value)
{
TSharedPtr<FJsonValue> Object = JsonObject->TryGetField(Key);
if (!Object) return false;
Value = TArray<FString>();
for (auto Item : Object->AsArray())
{
Value.Add(Item->AsString());
}
return true;
}
bool UVoiceComponent::ParseParticipants(TSharedPtr<FJsonObject> JsonObject, TArray<FRoomParticipant>& Participants)
{
TSharedPtr<FJsonValue> Object = JsonObject->TryGetField(TEXT("participants"));
if (!Object) return false;
Participants = TArray<FRoomParticipant>();
for (auto Item : Object->AsArray())
{
FString PuidString;
FString TokenString;
if (ParseString(TEXT("puid"), Item->AsObject(), PuidString) && ParseString(
TEXT("token"), Item->AsObject(), TokenString))
{
TSharedPtr<FJsonValue> ObjectHardMuted = JsonObject->TryGetField(TEXT("hardMuted"));
FRoomParticipant RoomParticipant;
RoomParticipant.puid = FCString::Atoi(*PuidString);
RoomParticipant.token = TokenString;
RoomParticipant.hardMuted = !ObjectHardMuted ? false : ObjectHardMuted->AsBool();
Participants.Add(RoomParticipant);
}
}
return true;
}
void UVoiceComponent::CreateSingleRoom(const int& OwnerId, const TArray<int> ArrayParticipants)
{
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetOwner());
if (!GalaxyGameMode) return;
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyGameMode->ServerMapPlayers.Contains(OwnerId)) return;
AGalaxyPlayerController* PlayerController = GalaxyGameMode->ServerMapPlayers[OwnerId];
if (!PlayerController) return;
if (PlayerController->VoiceChatComponent == nullptr) return;
PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus = true;
AStarshipPawn* StarshipPawn = Cast<AStarshipPawn>(PlayerController->GetPawn());
if (!StarshipPawn) return;
FServerStruct Server;
if (!GalaxyGameInstance->TableDataAsset->GetServer(GalaxyGameMode->ServerName, Server))
{
UE_LOG(LogTemp, Warning, TEXT("Dont Server %s"), *GalaxyGameMode->ServerName.ToString())
return;
}
FParticipantsRoom ParticipantsRoom;
FParticipant ParticipantOwner;
ParticipantOwner.puid = OwnerId;
ParticipantOwner.clientIp = Server.Ip;
ParticipantOwner.hardMuted = false;
ParticipantsRoom.participants.Add(ParticipantOwner);
for (const int& OverlapShip : ArrayParticipants)
{
if(GalaxyGameMode->ServerMapPlayers.Contains(OverlapShip))
{
if(GalaxyGameMode->ServerMapPlayers[OverlapShip])
{
if(GalaxyGameMode->ServerMapPlayers[OverlapShip]->GetPawn())
{
FParticipant Participant;
Participant.puid = OverlapShip;
Participant.clientIp = Server.Ip;
Participant.hardMuted = false;
ParticipantsRoom.participants.Add(Participant);
GalaxyGameMode->ServerMapPlayers[OverlapShip]->VoiceChatComponent->ServerVoiceChatDataPlayer.bStatus = true;
}
}
}
}
const FString& ChannelName = FString::FromInt(OwnerId);
UE_LOG(LogTemp, Warning, TEXT("participants %s %s"), *FString::FromInt(ParticipantsRoom.participants.Num()), *ChannelName)
FString StringParticipants;
FJsonObjectConverter::UStructToJsonObjectString<FParticipantsRoom>(ParticipantsRoom, StringParticipants);
FString ProductId;
FString SandboxId;
FString DeploymentId;
FString ClientId;
FString ClientSecret;
FString EncryptionKey;
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ProductId"), ProductId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("SandboxId"), SandboxId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("DeploymentId"), DeploymentId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientId"), ClientId, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientSecret"), ClientSecret, GEngineIni);
GConfig->GetString(TEXT("EOSVoiceChat"), TEXT("ClientEncryptionKey"), EncryptionKey, GEngineIni);
TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
HttpRequest->AppendToHeader(TEXT("Accept"), TEXT("application/json"));
HttpRequest->AppendToHeader(
TEXT("Authorization"), *FString::Printf(TEXT("Bearer %s"), *GalaxyGameMode->ServerAccessToken));
HttpRequest->SetContentAsString(StringParticipants);
HttpRequest->SetURL(
FString::Printf(
TEXT("https://api.epicgames.dev/rtc/v1/%s/room/%s"), *DeploymentId,
*ChannelName));
HttpRequest->SetVerb("POST");
HttpRequest->OnProcessRequestComplete().BindLambda(
[this, OwnerId, ChannelName, PlayerController, StarshipPawn](FHttpRequestPtr HttpRequest, FHttpResponsePtr HttpResponse,
bool bWasSuccessful)
{
if (!bWasSuccessful)
{
UE_LOG(LogTemp, Warning, TEXT("!bWasSuccessful CreateRoom"))
return;
}
UE_LOG(LogTemp, Warning, TEXT("Create Room content [%s]"), *HttpResponse->GetContentAsString());
TSharedPtr<FJsonObject> JsonObject;
if (!FJsonSerializer::Deserialize(
TJsonReaderFactory<>::Create(HttpResponse->GetContentAsString()), JsonObject) && JsonObject.IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("!Deserialize %s"), *HttpResponse->GetContentAsString());
return;
}
FString ErrorCodeString;
if (UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyErrorCode, JsonObject, ErrorCodeString))
{
TSharedPtr<FJsonValue> ErrorMessageObject = JsonObject->TryGetField(
UGalaxyGameInstance::ResponseKeyErrorMessage);
UE_LOG(LogTemp, Warning, TEXT("%s"), *ErrorMessageObject->AsString())
return;
}
FString RoomIdString;
if (!UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyRoomId, JsonObject, RoomIdString))
{
UE_LOG(LogTemp, Warning, TEXT("!RoomIdString"))
return;
}
FString DeploymentIdString;
if (UVoiceComponent::ParseString(TEXT("deploymentId"), JsonObject, DeploymentIdString))
{
UE_LOG(LogTemp, Warning, TEXT("DeploymentIdString %s"), *DeploymentIdString);
}
FString ClientBaseUrlString;
if (UVoiceComponent::ParseString(UGalaxyGameInstance::ResponseKeyClientBaseUrl, JsonObject,
ClientBaseUrlString))
{
UE_LOG(LogTemp, Warning, TEXT("ClientBaseUrlString %s"), *ClientBaseUrlString);
}
TArray<FRoomParticipant> ArrayRoomParticipant;
if (!UVoiceComponent::ParseParticipants(JsonObject, ArrayRoomParticipant))
{
UE_LOG(LogTemp, Warning, TEXT("!ArrayRoomParticipant"))
return;
}
if (ArrayRoomParticipant.Num() == 0)
{
UE_LOG(LogTemp, Warning, TEXT("ArrayRoomParticipant == 0"))
return;
}
TArray<FRoomParticipantData> ArrayParticipants = TArray<FRoomParticipantData>();
TMap<int, FString> MapToken = TMap<int, FString>();
for (const FRoomParticipant& RoomParticipant : ArrayRoomParticipant)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(RoomParticipant.puid))
{
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]) return;
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()) return;
if (AStarshipPawn* Starship = Cast<AStarshipPawn>(GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()))
{
FRoomParticipantData RoomParticipantData;
RoomParticipantData.UserId = Starship->StarshipData.UserId;
RoomParticipantData.UserEmail = Starship->StarshipData.UserEmail;
RoomParticipantData.UserName = Starship->StarshipData.UserName;
RoomParticipantData.UserIcon = Starship->StarshipData.UserIcon;
ArrayParticipants.Add(RoomParticipantData);
MapToken.Add(RoomParticipant.puid, RoomParticipant.token);
UE_LOG(LogTemp, Warning, TEXT("%s Token %s"), *FString::FromInt(RoomParticipant.puid), *RoomParticipant.token);
}
}
}
const int& IndexRoom = ArrayRoom.FindLastByPredicate(
[this, OwnerId](const FVoiceTestRoom& VoiceTestRoom)
{
return VoiceTestRoom.OwnerId == OwnerId;
});
const int& NewIndexRoom = ArrayRoom.Num();
for (const FRoomParticipant& RoomParticipant : ArrayRoomParticipant)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(RoomParticipant.puid))
{
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]) continue;
if (!GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->GetPawn()) continue;
UE_LOG(LogTemp, Warning, TEXT("Uid %s => %s"), *ChannelName, *FString::FromInt(RoomParticipant.puid));
GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer(
IndexRoom == INDEX_NONE ? NewIndexRoom : IndexRoom, EVoiceRoomRole::Participant);
GalaxyGameMode->ServerMapPlayers[RoomParticipant.puid]->VoiceChatComponent->ActionCreateRoom(
OwnerId,
ChannelName,
RoomIdString,
ClientBaseUrlString,
MapToken[RoomParticipant.puid],
ArrayParticipants
);
}
}
UE_LOG(LogTemp, Warning, TEXT("Create %s => %s"), *ChannelName, *FString::FromInt(ArrayParticipants.Num()));
if(IndexRoom == INDEX_NONE)
{
FVoiceTestRoom VoiceTestRoom;
VoiceTestRoom.OwnerId = OwnerId;
VoiceTestRoom.RoomId = NewIndexRoom;
VoiceTestRoom.RoomName = OwnerId;
VoiceTestRoom.ArrayPlayers.Empty();
VoiceTestRoom.ArrayPlayers = TArray<int>();
for (const FRoomParticipantData& RoomParticipant : ArrayParticipants)
{
VoiceTestRoom.ArrayPlayers.Add(RoomParticipant.UserId);
}
ArrayRoom.Add(VoiceTestRoom);
} else
{
ArrayRoom[IndexRoom].ArrayPlayers.Empty();
ArrayRoom[IndexRoom].ArrayPlayers = TArray<int>();
for (const FRoomParticipantData& RoomParticipant : ArrayParticipants)
{
ArrayRoom[IndexRoom].ArrayPlayers.Add(RoomParticipant.UserId);
}
}
PlayerController->VoiceChatComponent->ServerVoiceChatDataPlayer = FVoiceChatDataPlayer(IndexRoom == INDEX_NONE ? NewIndexRoom : IndexRoom, EVoiceRoomRole::Owner);
});
HttpRequest->ProcessRequest();
}
bool UVoiceComponent::BeginCollision(const int& A, const int& B, int& IndexCollision)
{
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetOwner());
if (!GalaxyGameMode) return false;
if (!GalaxyGameMode->HasAuthority()) return false;
if (GalaxyGameMode->ServerMapPlayers.Contains(A))
{
if (GalaxyGameMode->ServerMapPlayers[A])
{
if (GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent)
{
if (!GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent->bServerVoiceEnable)
return false;
}
}
}
if (GalaxyGameMode->ServerMapPlayers.Contains(B))
{
if (GalaxyGameMode->ServerMapPlayers[B])
{
if (GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent)
{
if (!GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent->bServerVoiceEnable)
return false;
}
}
}
int Index;
FindCollision(A, B, Index);
if (Index == INDEX_NONE)
{
IndexCollision = ArrayCollision.Num();
FCollision Collision;
Collision.CollisionId = IndexCollision;
Collision.Players.Add(A);
Collision.Players.Add(B);
ArrayCollision.Add(Collision);
if (GalaxyGameMode->ServerMapPlayers.Contains(A))
if (GalaxyGameMode->ServerMapPlayers[A])
if (GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent)
GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent->ServerAddCollision(IndexCollision);
if (GalaxyGameMode->ServerMapPlayers.Contains(B))
if (GalaxyGameMode->ServerMapPlayers[B])
if (GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent)
GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent->ServerAddCollision(IndexCollision);
return true;
}
return false;
}
bool UVoiceComponent::EndCollision(const int& A, const int& B, int& IndexCollision)
{
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetOwner());
if (!GalaxyGameMode) return false;
if (!GalaxyGameMode->HasAuthority()) return false;
if (GalaxyGameMode->ServerMapPlayers.Contains(A))
{
if (GalaxyGameMode->ServerMapPlayers[A])
{
if (GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent)
{
if (!GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent->bServerVoiceEnable)
return false;
}
}
}
if (GalaxyGameMode->ServerMapPlayers.Contains(B))
{
if (GalaxyGameMode->ServerMapPlayers[B])
{
if (GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent)
{
if (!GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent->bServerVoiceEnable)
return false;
}
}
}
FindCollision(A, B, IndexCollision);
if (IndexCollision != INDEX_NONE)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(A))
if (GalaxyGameMode->ServerMapPlayers[A])
if (GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent)
GalaxyGameMode->ServerMapPlayers[A]->VoiceChatComponent->ServerRemoveCollision(IndexCollision);
if (GalaxyGameMode->ServerMapPlayers.Contains(B))
if (GalaxyGameMode->ServerMapPlayers[B])
if (GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent)
GalaxyGameMode->ServerMapPlayers[B]->VoiceChatComponent->ServerRemoveCollision(IndexCollision);
ArrayCollision.RemoveAt(IndexCollision);
return true;
}
return false;
}
void UVoiceComponent::FindCollision(const int& A, const int& B, int& Index)
{
Index = ArrayCollision.FindLastByPredicate(
[this, A, B](const FCollision& Collision)
{
return Collision.Players.Contains(A) && Collision.Players.Contains(B);
});
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "Component/VoiceChatComponent.h"
#include "CurrentScreen.h"
#include "GalaxyGameInstance.h"
#include "JsonObjectConverter.h"
#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Component/VoiceComponent.h"
#include "Components/TextBlock.h"
#include "Components/VerticalBox.h"
#include "DataAsset/ItemDataAsset.h"
#include "DataAsset/TableDataAsset.h"
#include "Dialog/MenuDialog.h"
#include "GameFramework/GameStateBase.h"
#include "GameMode/GalaxyGameMode.h"
#include "HttpInstanceSubsystem/HttpEpicTokenSubsystem.h"
#include "HUD/GalaxyHUD.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Net/UnrealNetwork.h"
#include "Panel/AudioPanel.h"
#include "Pawn/StarshipPawn.h"
#include "PlayerController/GalaxyPlayerController.h"
#include "Screen/GalaxyScreen.h"
#include "Struct/RoomParticipant.h"
#include "Struct/ServerStruct.h"
#include "Struct/RoomParticipantData.h"
#include "Item/VoiceRoomItem.h"
#include "Item/VoiceUserItem.h"
#include "HttpModule.h"
#include "JsonObjectConverter.h"
#include "Component/PlayerInputComponent.h"
#include "Components/SphereComponent.h"
#include "DataAsset/TextDataAsset.h"
#include "Net/Core/PushModel/PushModel.h"
#include "Struct/VoiceGroup.h"
#include "Async/Async.h"
FName UVoiceChatComponent::Key_JoinRoom = FName("Key_JoinRoom");
UVoiceChatComponent::UVoiceChatComponent()
{
PrimaryComponentTick.bCanEverTick = false;
SetIsReplicatedByDefault(true);
}
void UVoiceChatComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
FDoRepLifetimeParams ParamsOwnerOnly;
ParamsOwnerOnly.Condition = ELifetimeCondition::COND_OwnerOnly;
ParamsOwnerOnly.bIsPushBased = true;
DOREPLIFETIME_WITH_PARAMS_FAST(UVoiceChatComponent, VoiceChatData, ParamsOwnerOnly);
}
void UVoiceChatComponent::OnRep_VoiceChatData()
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyHUD) return;
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
if (!GalaxyScreen) return;
if (VoiceChatData.Status == EVoiceChatStatus::DontCreate)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Dont")));
}
else if (VoiceChatData.Status == EVoiceChatStatus::Create || VoiceChatData.Status == EVoiceChatStatus::Update)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Connecting...")));
GalaxyScreen->UserVerticalBox->ClearChildren();
for (const FRoomParticipantData& RoomParticipantData : VoiceChatData.ArrayParticipants)
{
if (RoomParticipantData.UserId == StarshipPawn->StarshipData.UserId) continue;
UVoiceUserItem* VoiceUserItem = CreateWidget<UVoiceUserItem>(GalaxyPlayerController,
GalaxyGameInstance->ItemDataAsset->VoiceUserItemClass);
VoiceUserItem->PlayerName = FString::FromInt(RoomParticipantData.UserId);
VoiceUserItem->TextBlockUserName->SetText(FText::FromString(RoomParticipantData.UserName));
VoiceUserItem->TextBlockUserEmail->SetText(FText::FromString(RoomParticipantData.UserEmail));
VoiceUserItem->SetRenderOpacity(1.f);
GalaxyScreen->UserVerticalBox->AddChildToVerticalBox(VoiceUserItem);
}
if (VoiceChatData.Status == EVoiceChatStatus::Create && !VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE) && !VoiceChatData.Token.
Equals(EMPTY_STRING_VALUE))
{
AttemptConnectAndJoinChannel(VoiceChatData.Token, VoiceChatData.ClientBaseUrlString, VoiceChatData.RoomIdString);
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::ForceExit)
{
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::ForceExit"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionForceExit();
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionForceExit();
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Hangar)
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Hangar ") + VoiceChatData.RoomIdString, true, true, FColor::Red, 45.f);
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Hangar"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionEnterStarbase(VoiceChatData.HangarId);
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionEnterStarbase(VoiceChatData.HangarId);
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Die)
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("Die ") + VoiceChatData.RoomIdString, true, true, FColor::Red, 45.f);
if (!VoiceChatData.RoomIdString.Equals(EMPTY_STRING_VALUE))
{
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Die"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this](bool IsSuccess)
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionDie(VoiceChatData.HangarId);
}));
})
);
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
GalaxyPlayerController->ActionDie(VoiceChatData.HangarId);
}));
}
}
else if (VoiceChatData.Status == EVoiceChatStatus::Close)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Closing...")));
AttemptVoiceChatLogout(TEXT("VoiceChatData.Status == EVoiceChatStatus::Close"),
VoiceChatData.RoomIdString,
FOnCompleteLogout::CreateLambda([this, GalaxyScreen](bool IsSuccess)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyHUD) return;
if (IsSuccess)
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Close")));
}
else
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("Close !IsSuccess")));
}
GalaxyScreen->UserVerticalBox->ClearChildren();
}));
}
}
void UVoiceChatComponent::AttemptConnectAndJoinChannel(const FString& Token, const FString& ClientBaseUrlString, const FString& RoomIdString)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat)
return;
if (!VoiceChat->Initialize())
{
VoiceChat->Initialize(FOnVoiceChatInitializeCompleteDelegate::CreateLambda(
[this, VoiceChat, Token, ClientBaseUrlString, RoomIdString](const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
return;
if (!VoiceChat->IsConnected())
{
ToggleVoiceChatConnect(FOnCompleteToggleConnect::CreateLambda([this, Token, ClientBaseUrlString, RoomIdString](bool bConnect)
{
AttemptJoinChannel(Token, ClientBaseUrlString, RoomIdString); //
}));
}
else
{
AttemptJoinChannel(Token, ClientBaseUrlString, RoomIdString); //
}
}));
}
else
{
if (!VoiceChat->IsConnected())
{
ToggleVoiceChatConnect(FOnCompleteToggleConnect::CreateLambda([this, Token, ClientBaseUrlString, RoomIdString](bool bConnect)
{
AttemptJoinChannel(Token, ClientBaseUrlString, RoomIdString); //
}));
}
else
{
AttemptJoinChannel(Token, ClientBaseUrlString, RoomIdString); //
}
}
}
void UVoiceChatComponent::BeginPlay()
{
Super::BeginPlay();
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
}
EVoiceChatStatus UVoiceChatComponent::GetVoiceChatStatus()
{
return VoiceChatData.Status;
}
FString UVoiceChatComponent::GetVoiceChatRoom()
{
return VoiceChatData.RoomIdString;
}
bool UVoiceChatComponent::IsConnectedStatus(
FString& Token,
FString& ClientBaseUrlString,
FString& RoomIdString
)
{
if (VoiceChatData.Status == EVoiceChatStatus::Create || VoiceChatData.Status == EVoiceChatStatus::Update)
{
Token = VoiceChatData.Token;
ClientBaseUrlString = VoiceChatData.ClientBaseUrlString;
RoomIdString = VoiceChatData.RoomIdString;
return true;
}
return false;
}
void UVoiceChatComponent::AttemptJoinChannel(const FString& Token, const FString& ClientBaseUrlString, const FString& RoomIdString)
{
if (Token.IsEmpty())
{
return;
}
if (!VoiceChatUser)
{
return;
}
if (VoiceChatUser->IsLoggedIn())
{
AttemptVoiceChatLogout(TEXT("AttemptJoinChannel VoiceChatUser->IsLoggedIn()"), RoomIdString, FOnCompleteLogout::CreateLambda(
[this, RoomIdString, ClientBaseUrlString, Token](bool IsSuccess)
{
AttemptVoiceChatLogin(
TEXT("VoiceChatUser->IsLoggedIn() ") + IsSuccess ? TEXT("IsSuccess") : TEXT("!IsSuccess"), Token,
FOnCompleteLogin::CreateLambda([this, RoomIdString, ClientBaseUrlString, Token](const FString& Puid)
{
UE_LOG(LogTemp, Warning, TEXT("%s ClientBaseUrlString %s"), *Puid, *ClientBaseUrlString)
UE_LOG(LogTemp, Warning, TEXT("%s Token %s"), *Puid, *Token)
AttemptVoiceChatJoin(TEXT("VoiceChatUser->IsLoggedIn()"), RoomIdString, ClientBaseUrlString, Token, Puid);
}));
}));
}
else
{
AttemptVoiceChatLogin(TEXT("!VoiceChatUser->IsLoggedIn()"), Token, FOnCompleteLogin::CreateLambda(
[this, RoomIdString, ClientBaseUrlString, Token](const FString& Puid)
{
UE_LOG(LogTemp, Warning, TEXT("%s ClientBaseUrlString %s"), *Puid, *ClientBaseUrlString)
UE_LOG(LogTemp, Warning, TEXT("%s Token %s"), *Puid, *Token)
AttemptVoiceChatJoin(TEXT("!VoiceChatUser->IsLoggedIn() *"), RoomIdString, ClientBaseUrlString, Token, Puid);
}));
}
}
void UVoiceChatComponent::ActionCreateRoom(const int OwnerId, const FString& ChannelName, const FString& RoomIdString,
const FString& ClientBaseUrlString,
const FString& Token, const TArray<FRoomParticipantData>& ArrayParticipants)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
const EVoiceChatStatus& OldStatus = VoiceChatData.Status;
UE_LOG(LogTemp, Warning, TEXT("CreateRoom %s => %s"), *ChannelName, *FString::FromInt(OwnerId));
VoiceChatData.Owner = OwnerId;
VoiceChatData.ChannelName = ChannelName;
VoiceChatData.RoomIdString = RoomIdString;
VoiceChatData.ClientBaseUrlString = ClientBaseUrlString;
VoiceChatData.Token = Token;
VoiceChatData.ArrayParticipants = ArrayParticipants;
if (OldStatus == EVoiceChatStatus::Create)
{
VoiceChatData.Status = EVoiceChatStatus::Update;
}
else
{
VoiceChatData.Status = EVoiceChatStatus::Create;
}
VoiceChatData.HangarId = -1;
VoiceChatData.Text = TEXT("");
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::ActionCloseRoom()
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
VoiceChatData.RoomIdString = EMPTY_STRING_VALUE;
VoiceChatData.Status = EVoiceChatStatus::Close;
VoiceChatData.HangarId = -1;
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::OtherAction(const int& HangarId, const EVoiceChatStatus& VoiceChatStatus)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE) return;
VoiceChatData.Status = VoiceChatStatus;
VoiceChatData.HangarId = HangarId;
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::OnVoiceChatAvailableAudioDevicesChanged()
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
UMenuDialog* MenuDialog = Cast<UMenuDialog>(GalaxyHUD->MapDialog[ECurrentDialog::Menu]);
UAudioPanel* AudioPanel = Cast<UAudioPanel>(MenuDialog->MapPanel[ESettingsPanel::Audio]);
TArray<FVoiceChatDeviceData> ArrayInputDevice = TArray<FVoiceChatDeviceData>();
TArray<FVoiceChatDeviceData> ArrayOutputDevice = TArray<FVoiceChatDeviceData>();
FString InputDeviceInfoId;
FString OutputDeviceInfoId;
float AudioInputVolume = 0.f;
float AudioOutputVolume = 0.f;
GetAudioDevices(ArrayInputDevice,
ArrayOutputDevice,
InputDeviceInfoId,
OutputDeviceInfoId,
AudioInputVolume,
AudioOutputVolume);
AudioPanel->UpdateAudioDevice(ArrayInputDevice, ArrayOutputDevice, InputDeviceInfoId, OutputDeviceInfoId);
}
void UVoiceChatComponent::OnVoiceChatLoggedIn(const FString& PlayerName)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
const int& FindIndex = FindIndexVoiceUserItem(PlayerName);;
if (FindIndex != INDEX_NONE)
{
if (UVoiceUserItem* VoiceUserItem = Cast<UVoiceUserItem>(GalaxyScreen->UserVerticalBox->GetChildAt(FindIndex)))
{
VoiceUserItem->TextBlockLoggedStatus->SetVisibility(ESlateVisibility::Visible);
}
}
}
void UVoiceChatComponent::OnVoiceChatLoggedOut(const FString& PlayerName)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
const int& FindIndex = FindIndexVoiceUserItem(PlayerName);;
if (FindIndex != INDEX_NONE)
{
if (UVoiceUserItem* VoiceUserItem = Cast<UVoiceUserItem>(GalaxyScreen->UserVerticalBox->GetChildAt(FindIndex)))
{
VoiceUserItem->TextBlockLoggedStatus->SetVisibility(ESlateVisibility::Collapsed);
}
}
}
void UVoiceChatComponent::OnVoiceChatChannelJoined(const FString& ChannelName)
{
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatChannelJoined ") + ChannelName, true, true, FColor::Red, 10.f);
}
void UVoiceChatComponent::OnVoiceChatChannelExited(const FString& ChannelName, const FVoiceChatResult& VoiceChatResult)
{
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatChannelExited ") + ChannelName, true, true, FColor::Red, 10.f);
}
void UVoiceChatComponent::OnVoiceChatCallStatsUpdated(const FVoiceChatCallStats& VoiceChatCallStats)
{
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatCallStatsUpdated"), true, true, FColor::Red, 10.f);
}
void UVoiceChatComponent::OnVoiceChatPlayerAdded(const FString& ChannelName, const FString& PlayerName)
{
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatPlayerAdded ") + ChannelName, true, true, FColor::Red, 10.f);
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatPlayerAdded ") + PlayerName, true, true, FColor::Red, 10.f);
}
void UVoiceChatComponent::OnVoiceChatPlayerRemoved(const FString& ChannelName, const FString& PlayerName)
{
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatPlayerRemoved ") + ChannelName, true, true, FColor::Red, 10.f);
// UKismetSystemLibrary::PrintString(GetWorld(), TEXT("OnVoiceChatPlayerRemoved ") + PlayerName, true, true, FColor::Red, 10.f);
}
void UVoiceChatComponent::OnVoiceChatPlayerTalkingUpdated(const FString& ChannelName, const FString& PlayerName,
bool bIsTalking)
{
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (!GalaxyGameInstance)
GalaxyGameInstance = Cast<UGalaxyGameInstance>(GetWorld()->GetGameInstance());
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
const int& FindIndex = FindIndexVoiceUserItem(PlayerName);;
if (FindIndex != INDEX_NONE)
{
if (UVoiceUserItem* VoiceUserItem = Cast<UVoiceUserItem>(GalaxyScreen->UserVerticalBox->GetChildAt(FindIndex)))
{
if (VoiceUserItem->TextBlockLoggedStatus->GetVisibility() != ESlateVisibility::Visible)
VoiceUserItem->TextBlockLoggedStatus->SetVisibility(ESlateVisibility::Visible);
VoiceUserItem->TextBlockTalkingStatus->SetVisibility(bIsTalking ? ESlateVisibility::Visible : ESlateVisibility::Collapsed);
}
}
}
int UVoiceChatComponent::FindIndexVoiceUserItem(const FString& PlayerName)
{
int FindIndex = INDEX_NONE;
if (!GalaxyHUD) return FindIndex;
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
for (int i = 0; i < GalaxyScreen->UserVerticalBox->GetChildrenCount(); i++)
{
if (UVoiceUserItem* VoiceUserItem = Cast<UVoiceUserItem>(GalaxyScreen->UserVerticalBox->GetChildAt(i)))
{
if (VoiceUserItem->PlayerName.Equals(PlayerName))
{
FindIndex = i;
break;
}
}
}
return FindIndex;
}
void UVoiceChatComponent::ToggleEnableVoiceChat(bool bVoiceChat)
{
if (bVoiceChat)
{
AttemptVoiceChatConnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
Server_ToggleEnableVoiceChat(true);
}));
}
else
{
AttemptVoiceChatDisconnect(FOnCompleteToggleConnect::CreateLambda([this](bool bConnect)
{
Server_ToggleEnableVoiceChat(false);
}));
}
}
void UVoiceChatComponent::AttemptVoiceChatConnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat)
return;
if (!VoiceChat->Initialize())
{
VoiceChat->Initialize(FOnVoiceChatInitializeCompleteDelegate::CreateLambda(
[this, OnCompleteToggleConnect](const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
return;
ToggleVoiceChatConnect(OnCompleteToggleConnect);
}));
}
else
{
ToggleVoiceChatConnect(OnCompleteToggleConnect);
}
}
void UVoiceChatComponent::AttemptVoiceChatDisconnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat)
{
return;
}
if (!VoiceChat->Initialize())
{
VoiceChat->Initialize(FOnVoiceChatInitializeCompleteDelegate::CreateLambda(
[this, OnCompleteToggleConnect](const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
return;
}
ToggleVoiceChatDisconnect(OnCompleteToggleConnect);
}));
}
else
{
ToggleVoiceChatDisconnect(OnCompleteToggleConnect);
}
}
void UVoiceChatComponent::AttemptVoiceChatLogout(const FString& Cell, const FString& RoomIdString, FOnCompleteLogout OnCompleteLogout)
{
if (VoiceChatUser == nullptr)
{
return;
}
UE_LOG(LogTemp, Warning, TEXT("Attempt leave %s"), *Cell)
VoiceChatUser->LeaveChannel(RoomIdString,
FOnVoiceChatChannelLeaveCompleteDelegate::CreateLambda(
[this, OnCompleteLogout](
const FString& ChannelName, const FVoiceChatResult& Result)
{
// if (VoiceChatUser->IsLoggingIn())
// {
// UE_LOG(LogTemp, Warning, TEXT("AttemptVoiceChatLogout LeaveChannel IsLoggingIn %s"), *ChannelName)
// return;
// }
VoiceChatUser->Logout(FOnVoiceChatLogoutCompleteDelegate::CreateLambda(
[this, OnCompleteLogout](const FString& PlayerName, const FVoiceChatResult& Result)
{
OnCompleteLogout.ExecuteIfBound(Result.IsSuccess());
}));
}));
}
void UVoiceChatComponent::AttemptVoiceChatLogin(const FString& Cell, const FString& Token, FOnCompleteLogin OnCompleteLogin)
{
if (StarshipPawn->StarshipData.UserId == EMPTY_INT_VALUE)
{
GEngine->AddOnScreenDebugMessage(-1, 25.f, FColor::Red, TEXT("****AttemptVoiceChatLogin Error User Id"));
return;
}
const FString& Puid = FString::FromInt(StarshipPawn->StarshipData.UserId);
const FPlatformUserId& PlatformId = FPlatformMisc::GetPlatformUserForUserIndex(StarshipPawn->StarshipData.UserId);
UE_LOG(LogTemp, Warning, TEXT("Attempt login %s"), *Cell)
VoiceChatUser->Login(
PlatformId,
Puid, Token,
FOnVoiceChatLoginCompleteDelegate::CreateLambda(
[this, OnCompleteLogin, Puid](const FString& PlayerName, const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("VoiceChat->Login ") + Result.ErrorDesc, true, true, FColor::Red,
10.f);
return;
}
if (!VoiceChatUser->IsLoggedIn())
{
UKismetSystemLibrary::PrintString(GetWorld(), TEXT("(**************!VoiceChatUser->IsLoggedIn()*****************"), true, true,
FColor::Red, 10.f);
return;
}
OnCompleteLogin.ExecuteIfBound(Puid);
}));
}
void UVoiceChatComponent::AttemptVoiceChatJoin(const FString& Cell, const FString& RoomIdString, const FString& ClientBaseUrlString,
const FString& Token, const FString& Puid)
{
UGalaxyScreen* GalaxyScreen = Cast<UGalaxyScreen>(GalaxyHUD->MapScreen[ECurrentScreen::Galaxy]);
FRoomCredentials RoomCredentials;
RoomCredentials.override_userid = TEXT("");
RoomCredentials.client_base_url = ClientBaseUrlString;
RoomCredentials.participant_token = Token;
FString ChannelCredentials;
FVoiceChatChannel3dProperties Properties;
Properties.AttenuationModel = EVoiceChatAttenuationModel::InverseByDistance;
Properties.MaxDistance = 1000000.f;
Properties.MinDistance = 1000.f;
Properties.Rolloff = 0.5f;
FJsonObjectConverter::UStructToJsonObjectString<FRoomCredentials>(RoomCredentials, ChannelCredentials);
UE_LOG(LogTemp, Warning, TEXT("Attempt join %s"), *Cell)
if(VoiceChatUser == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("VoiceChatUser == nullptr"), *Cell)
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("VoiceChatUser == nullptr")));
return;
}
if(VoiceChatUser->IsLoggedIn())
{
VoiceChatUser->JoinChannel(RoomIdString, ChannelCredentials, EVoiceChatChannelType::NonPositional,
FOnVoiceChatChannelJoinCompleteDelegate::CreateLambda(
[this, Puid, RoomIdString, GalaxyScreen](
const FString& ChannelName, const FVoiceChatResult& Result)
{
UE_LOG(LogTemp, Warning, TEXT("On JoinChannel %s"), *ChannelName)
if (!Result.IsSuccess())
{
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorDesc %s"), *Result.ErrorDesc)
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorCode %s"), *Result.ErrorCode)
UE_LOG(LogTemp, Warning, TEXT("!JoinChannel ErrorNum %s"), *FString::FromInt(Result.ErrorNum))
switch (Result.ResultCode)
{
case EVoiceChatResult::Success:
UE_LOG(LogTemp, Warning, TEXT("Success JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::InvalidState:
UE_LOG(LogTemp, Warning, TEXT("InvalidState JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotInitialized:
UE_LOG(LogTemp, Warning, TEXT("NotInitialized JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotConnected:
UE_LOG(LogTemp, Warning, TEXT("NotConnected JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotLoggedIn:
UE_LOG(LogTemp, Warning, TEXT("NotLoggedIn JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::NotPermitted:
UE_LOG(LogTemp, Warning, TEXT("NotPermitted JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::Throttled:
UE_LOG(LogTemp, Warning, TEXT("Throttled JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::InvalidArgument:
UE_LOG(LogTemp, Warning, TEXT("InvalidArgument JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::CredentialsInvalid:
UE_LOG(LogTemp, Warning, TEXT("CredentialsInvalid JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::CredentialsExpired:
UE_LOG(LogTemp, Warning, TEXT("CredentialsExpired JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ClientTimeout:
UE_LOG(LogTemp, Warning, TEXT("ClientTimeout JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ServerTimeout:
UE_LOG(LogTemp, Warning, TEXT("ServerTimeout JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::DnsFailure:
UE_LOG(LogTemp, Warning, TEXT("DnsFailure JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ConnectionFailure:
UE_LOG(LogTemp, Warning, TEXT("ConnectionFailure JoinChannel %s"), *ChannelName)
break;
case EVoiceChatResult::ImplementationError:
UE_LOG(LogTemp, Warning, TEXT("ImplementationError JoinChannel %s"), *ChannelName)
break;
default: ;
}
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("!JoinChannel ") + Result.ErrorDesc));
return;
}
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(ChannelName));
UE_LOG(LogTemp, Warning, TEXT("[%s RoomIdString %s]"), *Puid, *RoomIdString)
}), Properties);
} else
{
GalaxyScreen->TextBlockVoiceRoomName->SetText(FText::FromString(TEXT("!VoiceChatUser->IsLoggedIn()")));
}
}
void UVoiceChatComponent::ToggleVoiceChatConnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
VoiceChat->Connect(FOnVoiceChatConnectCompleteDelegate::CreateLambda(
[this, VoiceChat, OnCompleteToggleConnect](
const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("VoiceChat->Connect !Result.IsSuccess()"));
return;
}
if (!VoiceChat->Initialize())
{
UE_LOG(LogTemp, Warning, TEXT("!VoiceChat->Initialize()"))
return;
}
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (GalaxyHUD)
{
if (GalaxyHUD->MapDialog.Contains(ECurrentDialog::Menu))
{
UMenuDialog* MenuDialog = Cast<UMenuDialog>(GalaxyHUD->MapDialog[ECurrentDialog::Menu]);
if (MenuDialog)
{
if (MenuDialog->MapPanel.Contains(ESettingsPanel::Audio))
{
UAudioPanel* AudioPanel = Cast<UAudioPanel>(MenuDialog->MapPanel[ESettingsPanel::Audio]);
TArray<FVoiceChatDeviceData> ArrayInputDevice = TArray<FVoiceChatDeviceData>();
TArray<FVoiceChatDeviceData> ArrayOutputDevice = TArray<FVoiceChatDeviceData>();
FString InputDeviceInfoId;
FString OutputDeviceInfoId;
float AudioInputVolume = 0.f;
float AudioOutputVolume = 0.f;
GetAudioDevices(ArrayInputDevice,
ArrayOutputDevice,
InputDeviceInfoId,
OutputDeviceInfoId,
AudioInputVolume,
AudioOutputVolume);
AudioPanel->ShowVoiceSettings(ArrayInputDevice, ArrayOutputDevice, InputDeviceInfoId, OutputDeviceInfoId);
}
}
}
}
VoiceChat->OnVoiceChatAvailableAudioDevicesChanged().AddUObject(
this, &UVoiceChatComponent::OnVoiceChatAvailableAudioDevicesChanged);
VoiceChatUser = VoiceChat->CreateUser();
if (VoiceChatUser != nullptr)
{
VoiceChatUser->OnVoiceChatLoggedIn().AddUObject(this, &UVoiceChatComponent::OnVoiceChatLoggedIn);
VoiceChatUser->OnVoiceChatLoggedOut().AddUObject(this, &UVoiceChatComponent::OnVoiceChatLoggedOut);
VoiceChatUser->OnVoiceChatChannelJoined().AddUObject(this, &UVoiceChatComponent::OnVoiceChatChannelJoined);
VoiceChatUser->OnVoiceChatChannelExited().AddUObject(this, &UVoiceChatComponent::OnVoiceChatChannelExited);
VoiceChatUser->OnVoiceChatCallStatsUpdated().AddUObject(
this, &UVoiceChatComponent::OnVoiceChatCallStatsUpdated);
VoiceChatUser->OnVoiceChatPlayerAdded().AddUObject(this, &UVoiceChatComponent::OnVoiceChatPlayerAdded);
VoiceChatUser->OnVoiceChatPlayerRemoved().AddUObject(this, &UVoiceChatComponent::OnVoiceChatPlayerRemoved);
VoiceChatUser->OnVoiceChatPlayerTalkingUpdated().AddUObject(
this, &UVoiceChatComponent::OnVoiceChatPlayerTalkingUpdated);
}
OnCompleteToggleConnect.ExecuteIfBound(true);
}));
}
void UVoiceChatComponent::ToggleVoiceChatDisconnect(FOnCompleteToggleConnect OnCompleteToggleConnect)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
VoiceChat->Disconnect(FOnVoiceChatConnectCompleteDelegate::CreateLambda(
[this, VoiceChat, OnCompleteToggleConnect](
const FVoiceChatResult& Result)
{
if (!Result.IsSuccess())
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("VoiceChat->Disconnect !Result.IsSuccess()"));
return;
}
if (VoiceChat)
VoiceChat->OnVoiceChatAvailableAudioDevicesChanged().RemoveAll(this);
if (VoiceChatUser != nullptr)
{
VoiceChatUser->OnVoiceChatLoggedIn().RemoveAll(this);
VoiceChatUser->OnVoiceChatLoggedOut().RemoveAll(this);
VoiceChatUser->OnVoiceChatChannelJoined().RemoveAll(this);
VoiceChatUser->OnVoiceChatChannelExited().RemoveAll(this);
VoiceChatUser->OnVoiceChatCallStatsUpdated().RemoveAll(this);
VoiceChatUser->OnVoiceChatPlayerAdded().RemoveAll(this);
VoiceChatUser->OnVoiceChatPlayerRemoved().RemoveAll(this);
VoiceChatUser->OnVoiceChatPlayerTalkingUpdated().RemoveAll(this);
VoiceChatUser = nullptr;
}
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
if (GalaxyHUD)
{
if (GalaxyHUD->MapDialog.Contains(ECurrentDialog::Menu))
{
UMenuDialog* MenuDialog = Cast<UMenuDialog>(GalaxyHUD->MapDialog[ECurrentDialog::Menu]);
if (MenuDialog)
{
if (MenuDialog->MapPanel.Contains(ESettingsPanel::Audio))
{
UAudioPanel* AudioPanel = Cast<UAudioPanel>(MenuDialog->MapPanel[ESettingsPanel::Audio]);
AudioPanel->HideVoiceSettings();
}
}
}
}
VoiceChat->Uninitialize(FOnVoiceChatUninitializeCompleteDelegate::CreateLambda(
[this, OnCompleteToggleConnect](const FVoiceChatResult& Result)
{
OnCompleteToggleConnect.ExecuteIfBound(false);
}));
}));
}
void UVoiceChatComponent::Server_ToggleEnableVoiceChat_Implementation(bool bVoiceChat)
{
UE_LOG(LogTemp, Warning, TEXT("***********************************Server_ToggleEnableVoiceChat*************************************"));
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
this->bServerVoiceEnable = bVoiceChat;
if (this->bServerVoiceEnable)
{
UE_LOG(LogTemp, Warning, TEXT("ServerVoiceChat"));
StarshipPawn->RoomSphere->SetSphereRadius(15000.f, true);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("!ServerVoiceChat"));
StarshipPawn->RoomSphere->SetSphereRadius(0.f, false);
}
UE_LOG(LogTemp, Warning, TEXT("***********************************Server_ToggleEnableVoiceChat*************************************"));
}
void UVoiceChatComponent::OnClickToInputDevice(const FString& Id)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat) return;
VoiceChat->SetInputDeviceId(Id);
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
UMenuDialog* MenuDialog = Cast<UMenuDialog>(GalaxyHUD->MapDialog[ECurrentDialog::Menu]);
UAudioPanel* AudioPanel = Cast<UAudioPanel>(MenuDialog->MapPanel[ESettingsPanel::Audio]);
AudioPanel->SetInputDevice(VoiceChat->GetInputDeviceInfo().DisplayName);
}
void UVoiceChatComponent::OnClickToOutputDevice(const FString& Id)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (!VoiceChat) return;
VoiceChat->SetOutputDeviceId(Id);
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyHUD)
GalaxyHUD = Cast<AGalaxyHUD>(GalaxyPlayerController->GetHUD());
UMenuDialog* MenuDialog = Cast<UMenuDialog>(GalaxyHUD->MapDialog[ECurrentDialog::Menu]);
UAudioPanel* AudioPanel = Cast<UAudioPanel>(MenuDialog->MapPanel[ESettingsPanel::Audio]);
AudioPanel->SetOutputDevice(VoiceChat->GetOutputDeviceInfo().DisplayName);
}
void UVoiceChatComponent::SetDontCreateStatus(const FString& Text)
{
VoiceChatData.Text = Text;
VoiceChatData.Status = EVoiceChatStatus::DontCreate;
MARK_PROPERTY_DIRTY_FROM_NAME(ThisClass, VoiceChatData, this);
}
void UVoiceChatComponent::ServerAttach(const int OwnerId, const int& UserId)
{
UE_LOG(LogTemp, Warning, TEXT("ServerAttach %s"), *FString::FromInt(OwnerId))
UE_LOG(LogTemp, Warning, TEXT("ServerAttach %s"), *FString::FromInt(UserId))
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
int FindIndex = GalaxyGameMode->VoiceComponent->ArrayRoom.FindLastByPredicate(
[this, OwnerId](const FVoiceTestRoom& VoiceTestRoom)
{
return VoiceTestRoom.OwnerId == OwnerId;
});
if (FindIndex != INDEX_NONE)
{
UE_LOG(LogTemp, Warning, TEXT("fin room %s"), *FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom[FindIndex].ArrayPlayers.Num()))
GalaxyGameMode->VoiceComponent->ArrayRoom[FindIndex].ArrayPlayers.Add(UserId);
GalaxyGameMode->VoiceComponent->CreateSingleRoom(OwnerId, GalaxyGameMode->VoiceComponent->ArrayRoom[FindIndex].ArrayPlayers);
UE_LOG(LogTemp, Warning, TEXT("fin room %s"), *FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom[FindIndex].ArrayPlayers.Num()))
}
}
void UVoiceChatComponent::ServerAddCollision(const int& Index)
{
ServerArrayCollision.Add(Index);
}
void UVoiceChatComponent::ServerRemoveCollision(const int& Index)
{
const int& FindA = ServerArrayCollision.FindLastByPredicate([this, Index](const int& Collision)
{
return Collision == Index;
});
if (FindA != INDEX_NONE)
{
ServerArrayCollision.RemoveAt(FindA);
}
}
bool UVoiceChatComponent::ServerAddOverlapShip(const int& OwnerId, const int& UserId)
{
const int& Index = ArrayOverlapShip.FindLastByPredicate(
[this, UserId](const int& OverlapShip)
{
return OverlapShip == UserId;
});
if (Index == INDEX_NONE)
{
UE_LOG(LogTemp, Warning, TEXT("%s Add OverlapShip %s"), *FString::FromInt(OwnerId), *FString::FromInt(ArrayOverlapShip.Num()));
ArrayOverlapShip.Add(UserId);
return true;
}
return false;
}
bool UVoiceChatComponent::ServerRemoveOverlapShip(const int& OwnerId, const int& UserId)
{
const int& Index = ArrayOverlapShip.FindLastByPredicate(
[this, UserId](const int& OverlapShip)
{
return OverlapShip == UserId;
});
if (Index != INDEX_NONE && Index < ArrayOverlapShip.Num())
{
UE_LOG(LogTemp, Warning, TEXT("%s Remove OverlapShip %s"), *FString::FromInt(OwnerId), *FString::FromInt(ArrayOverlapShip[Index]));
ArrayOverlapShip.RemoveAt(Index);
return true;
}
return false;
}
bool UVoiceChatComponent::IsServerRoleNull()
{
return ServerVoiceChatDataPlayer.Role == EVoiceRoomRole::Null;
}
bool UVoiceChatComponent::IsServerRoleOwner()
{
return ServerVoiceChatDataPlayer.Role == EVoiceRoomRole::Owner;
}
bool UVoiceChatComponent::IsServerRoleParticipant()
{
return ServerVoiceChatDataPlayer.Role == EVoiceRoomRole::Participant;
}
void UVoiceChatComponent::Server_ForceLogoutAction_Implementation(const int& NearestIndex, const EVoiceChatStatus& NewVoiceChatStatus)
{
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
ServerForceLogoutAction(NearestIndex, NewVoiceChatStatus);
}
void UVoiceChatComponent::ServerForceLogoutAction(const int& NearestIndex, const EVoiceChatStatus& NewVoiceChatStatus)
{
if (!GalaxyGameMode)
GalaxyGameMode = Cast<AGalaxyGameMode>(GetWorld()->GetAuthGameMode());
if (!GalaxyGameMode->HasAuthority()) return;
if (!GalaxyPlayerController)
GalaxyPlayerController = Cast<AGalaxyPlayerController>(GetOwner());
if (!GalaxyPlayerController) return;
if (!StarshipPawn)
StarshipPawn = Cast<AStarshipPawn>(GalaxyPlayerController->GetPawn());
if (!StarshipPawn) return;
StarshipPawn->RoomSphere->SetSphereRadius(0.f);
const int& IndexCollision = GalaxyGameMode->VoiceComponent->ArrayCollision.FindLastByPredicate(
[this](const FCollision& Collision)
{
return Collision.Players.Contains(StarshipPawn->StarshipData.UserId);
});
if (IndexCollision != INDEX_NONE)
{
GalaxyGameMode->VoiceComponent->ArrayCollision.RemoveAt(IndexCollision);
}
if (IsServerRoleNull())
{
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
}
else if (IsServerRoleParticipant() || IsServerRoleOwner())
{
if (ServerVoiceChatDataPlayer.Index < GalaxyGameMode->VoiceComponent->ArrayRoom.Num())
{
const int& RoomIndex = ServerVoiceChatDataPlayer.Index;
FVoiceTestRoom VoiceTestRoom = GalaxyGameMode->VoiceComponent->ArrayRoom[RoomIndex];
const int& FindIndexRemovedPlayer = VoiceTestRoom.ArrayPlayers.FindLastByPredicate(
[this](const int& Player)
{
return Player == StarshipPawn->StarshipData.UserId;
});
if (FindIndexRemovedPlayer != INDEX_NONE && FindIndexRemovedPlayer < VoiceTestRoom.ArrayPlayers.Num())
{
//Удаляем себя из списка участников
VoiceTestRoom.ArrayPlayers.RemoveAt(FindIndexRemovedPlayer);
if (VoiceTestRoom.ArrayPlayers.Num() == 1)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<
int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
if (GalaxyGameMode->ServerMapPlayers.Contains(VoiceTestRoom.ArrayPlayers[0]))
{
if (GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]])
{
if (GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->GetPawn())
{
const int& Index = GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->
ArrayOverlapShip.FindLastByPredicate(
[this](const int& OverlapShip)
{
return OverlapShip == StarshipPawn->StarshipData.UserId;
});
if (Index != INDEX_NONE && Index < GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent
->ArrayOverlapShip.Num())
{
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ArrayOverlapShip.RemoveAt(
Index);
}
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[VoiceTestRoom.ArrayPlayers[0]]->VoiceChatComponent->ActionCloseRoom();
}
}
}
}
else if (VoiceTestRoom.ArrayPlayers.Num() >= 2)
{
for (const int& Player : VoiceTestRoom.ArrayPlayers)
{
if (GalaxyGameMode->ServerMapPlayers.Contains(Player))
{
if (GalaxyGameMode->ServerMapPlayers[Player])
{
if (GalaxyGameMode->ServerMapPlayers[Player]->GetPawn())
{
const int& Index = GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.
FindLastByPredicate(
[this](const int& OverlapShip)
{
return OverlapShip == StarshipPawn->
StarshipData.UserId;
});
if (Index != INDEX_NONE && Index < GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.
Num())
{
GalaxyGameMode->ServerMapPlayers[Player]->VoiceChatComponent->ArrayOverlapShip.RemoveAt(Index);
}
}
}
}
}
GalaxyGameMode->VoiceComponent->CreateSingleRoom(VoiceTestRoom.OwnerId, VoiceTestRoom.ArrayPlayers);
if (GalaxyGameMode->ServerMapPlayers.Contains(StarshipPawn->StarshipData.UserId))
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId])
{
if (GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->GetPawn())
{
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip.Empty();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ArrayOverlapShip = TArray<
int>();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->ServerVoiceChatDataPlayer =
FVoiceChatDataPlayer();
GalaxyGameMode->ServerMapPlayers[StarshipPawn->StarshipData.UserId]->VoiceChatComponent->OtherAction(
NearestIndex, NewVoiceChatStatus);
}
}
}
}
UE_LOG(LogTemp, Warning, TEXT("RoomIndex %s"), *FString::FromInt(RoomIndex));
UE_LOG(LogTemp, Warning, TEXT("GalaxyGameMode->VoiceComponent->ArrayRoom %s"),
*FString::FromInt(GalaxyGameMode->VoiceComponent->ArrayRoom.Num()));
// GalaxyGameMode->VoiceComponent->ArrayRoom[RoomIndex] = VoiceTestRoom;
}
}
}
}
void UVoiceChatComponent::GetAudioDevices(TArray<FVoiceChatDeviceData>& ArrayInput, TArray<FVoiceChatDeviceData>& ArrayOutput,
FString& InputDeviceInfoId, FString& OutputDeviceInfoId, float& AudioInputVolume, float& AudioOutputVolume)
{
IVoiceChat* VoiceChat = IVoiceChat::Get();
for (FVoiceChatDeviceInfo VoiceChatDeviceInfo : VoiceChat->GetAvailableInputDeviceInfos())
{
ArrayInput.Add(FVoiceChatDeviceData(VoiceChatDeviceInfo.DisplayName, VoiceChatDeviceInfo.Id));
}
for (FVoiceChatDeviceInfo VoiceChatDeviceInfo : VoiceChat->GetAvailableOutputDeviceInfos())
{
ArrayOutput.Add(FVoiceChatDeviceData(VoiceChatDeviceInfo.DisplayName, VoiceChatDeviceInfo.Id));
}
InputDeviceInfoId = VoiceChat->GetInputDeviceInfo().Id;
OutputDeviceInfoId = VoiceChat->GetOutputDeviceInfo().Id;
AudioInputVolume = VoiceChat->GetAudioInputVolume();
AudioOutputVolume = VoiceChat->GetAudioOutputVolume();
}