void FTestFriendsInterface::OnQueryRecentPlayersComplete(const FUniqueNetId& UserId, const FString& Namespace, bool bWasSuccessful, const FString& ErrorStr) { UE_LOG(LogOnline, Log, TEXT("QueryRecentPlayers() for player (%s) was success=%d error=%s"), *UserId.ToDebugString(), bWasSuccessful, *ErrorStr); if (bWasSuccessful) { TArray< TSharedRef<FOnlineRecentPlayer> > Players; // Grab the friends data so we can print it out if (OnlineSub->GetFriendsInterface()->GetRecentPlayers(UserId, Namespace, Players)) { UE_LOG(LogOnline, Log, TEXT("GetRecentPlayers returned %d players"), Players.Num()); // Log each friend's data out for (auto RecentPlayer : Players) { UE_LOG(LogOnline, Log, TEXT("\t%s has unique id (%s)"), *RecentPlayer->GetDisplayName(), *RecentPlayer->GetUserId()->ToDebugString()); UE_LOG(LogOnline, Log, TEXT("\t LastSeen (%s)"), *RecentPlayer->GetLastSeen().ToString()); } } } // done with this part of the test bQueryRecentPlayers = false; // kick off next test StartNextTest(); }
bool FOnlineVoiceImpl::UnmuteRemoteTalker(uint8 LocalUserNum, const FUniqueNetId& PlayerId, bool bIsSystemWide) { uint32 Return = E_FAIL; if (LocalUserNum >= 0 && LocalUserNum < MAX_LOCAL_PLAYERS) { // Skip this if the session isn't active if (SessionInt && SessionInt->GetNumSessions() > 0 && // Or if voice is disabled VoiceEngine != NULL) { // Find the specified talker FRemoteTalker* Talker = FindRemoteTalker(PlayerId); if (Talker != NULL) { // Remove them from the mute list MuteList.RemoveSingleSwap((const FUniqueNetIdString&)PlayerId); UE_LOG(LogVoice, Log, TEXT("Unmuting remote talker (%s)"), *PlayerId.ToDebugString()); } else { UE_LOG(LogVoice, Warning, TEXT("Unknown remote talker (%s) specified to UnmuteRemoteTalker()"), *PlayerId.ToDebugString()); } } } else { UE_LOG(LogVoice, Warning, TEXT("Invalid user specified in UnmuteRemoteTalker(%d)"), LocalUserNum); } return Return == S_OK; }
bool FOnlineVoiceImpl::RegisterRemoteTalker(const FUniqueNetId& UniqueId) { uint32 Return = E_FAIL; if (OnlineSubsystem) { // Skip this if the session isn't active if (SessionInt && SessionInt->GetNumSessions() > 0 && // Or when voice is disabled VoiceEngine != NULL) { // See if this talker has already been registered or not FRemoteTalker* Talker = FindRemoteTalker(UniqueId); if (Talker == NULL) { // Add a new talker to our list int32 AddIndex = RemoteTalkers.AddZeroed(); Talker = &RemoteTalkers[AddIndex]; // Copy the UniqueId const FUniqueNetIdString& UniqueIdStr = (const FUniqueNetIdString&)UniqueId; Talker->TalkerId = MakeShareable(new FUniqueNetIdString(UniqueIdStr)); // Register the remote talker locally Return = VoiceEngine->RegisterRemoteTalker(UniqueId); UE_LOG(LogVoice, Log, TEXT("RegisterRemoteTalker(%s) returned 0x%08X"), *UniqueId.ToDebugString(), Return); } else { UE_LOG(LogVoice, Warning, TEXT("Remote talker %s is being re-registered"), *UniqueId.ToDebugString()); Return = S_OK; } // @todo ONLINE Mute List update // Now start processing the remote voices Return = VoiceEngine->StartRemoteVoiceProcessing(UniqueId); UE_LOG(LogVoice, Log, TEXT("StartRemoteVoiceProcessing(%s) returned 0x%08X"), *UniqueId.ToDebugString(), Return); } } return Return == S_OK; }
bool FOnlineVoiceSteam::RegisterRemoteTalker(const FUniqueNetId& UniqueId) { uint32 Return = E_FAIL; if (SteamSubsystem) { // Skip this if the session isn't active if (SessionInt && SessionInt->GetNumSessions() > 0 && // Or when voice is disabled VoiceEngine.IsValid()) { // See if this talker has already been registered or not FRemoteTalker* Talker = FindRemoteTalker(UniqueId); if (Talker == NULL) { // Add a new talker to our list int32 AddIndex = RemoteTalkers.AddZeroed(); Talker = &RemoteTalkers[AddIndex]; // Copy the UniqueId const FUniqueNetIdSteam& UniqueIdSteam = (const FUniqueNetIdSteam&)UniqueId; Talker->TalkerId = MakeShareable(new FUniqueNetIdSteam(UniqueIdSteam)); // Register the remote talker locally Return = VoiceEngine->RegisterRemoteTalker(UniqueId); UE_LOG(LogVoice, Log, TEXT("RegisterRemoteTalker(%s) returned 0x%08X"), *UniqueId.ToDebugString(), Return); } else { UE_LOG(LogVoice, Verbose, TEXT("Remote talker %s is being re-registered"), *UniqueId.ToDebugString()); Return = S_OK; } // Update muting all of the local talkers with this remote talker ProcessMuteChangeNotification(); // Now start processing the remote voices Return = VoiceEngine->StartRemoteVoiceProcessing(UniqueId); UE_LOG(LogVoice, Log, TEXT("StartRemoteVoiceProcessing(%s) returned 0x%08X"), *UniqueId.ToDebugString(), Return); } } return Return == S_OK; }
void FTestFriendsInterface::OnDeleteFriendComplete(int32 LocalPlayer, bool bWasSuccessful, const FUniqueNetId& FriendId, const FString& ListName, const FString& ErrorStr) { UE_LOG(LogOnline, Log, TEXT("DeleteFriend() for player (%d) to friend (%s) was success=%d. %s"), LocalPlayer, *FriendId.ToDebugString(), bWasSuccessful, *ErrorStr); // done with this part of the test if no more friends to delete FriendsToDelete.RemoveAt(0); if (bWasSuccessful && FriendsToDelete.Num() == 0) { bDeleteFriends = false; bReadFriendsList = true; } // kick off next test StartNextTest(); }
bool FOnlineVoiceSteam::UnregisterRemoteTalker(const FUniqueNetId& UniqueId) { uint32 Return = E_FAIL; if (SteamSubsystem) { // Skip this if the session isn't active if (SessionInt && SessionInt->GetNumSessions() > 0 && // Or when voice is disabled VoiceEngine.IsValid()) { // Make sure the talker is valid if (FindRemoteTalker(UniqueId) != NULL) { // Find them in the talkers array and remove them for (int32 Index = 0; Index < RemoteTalkers.Num(); Index++) { const FRemoteTalker& Talker = RemoteTalkers[Index]; // Is this the remote talker? if (*Talker.TalkerId == UniqueId) { // Going to remove the talker, so if they were talking recently make sure to indicate they've stopped if (OnPlayerTalkingStateChangedDelegates.IsBound() && (Talker.bIsTalking || Talker.bWasTalking)) { OnPlayerTalkingStateChangedDelegates.Broadcast(Talker.TalkerId.ToSharedRef(), false); } RemoteTalkers.RemoveAtSwap(Index); break; } } // Remove them from voice engine Return = VoiceEngine->UnregisterRemoteTalker(UniqueId); UE_LOG(LogVoice, Log, TEXT("UnregisterRemoteTalker(%s) returned 0x%08X"), *UniqueId.ToDebugString(), Return); } else { UE_LOG(LogVoice, Verbose, TEXT("Unknown remote talker (%s) specified to UnregisterRemoteTalker()"), *UniqueId.ToDebugString()); } } } return Return == S_OK; }
void FTestIdentityInterface::OnLoginComplete(int32 LocalUserNum, bool bWasSuccessful, const FUniqueNetId& UserId, const FString& Error) { if (bWasSuccessful) { UE_LOG(LogOnline, Log, TEXT("Successful authenticated user. UserId=[%s] "), *UserId.ToDebugString()); // update user info for newly registered user UserInfo = OnlineIdentity->GetUserAccount(UserId); } else { UE_LOG(LogOnline, Warning, TEXT("Failed to authenticate new user. Error=[%s]"), *Error); } // Mark test as done bRunLoginTest = false; // kick off next test StartNextTest(); }
void FTestEntitlementsInterface::OnQueryEntitlementsComplete(bool bWasSuccessful, const FUniqueNetId& InUserId, const FString& Namespace, const FString& Error) { UE_LOG(LogOnline, Log, TEXT("enumerated entitlements. UserId=%s Result=%s Error=[%s]"), *InUserId.ToDebugString(), bWasSuccessful ? TEXT("true") : TEXT("false"), *Error); // Now check em out TArray<TSharedRef<FOnlineEntitlement>> Entitlements; EntitlementsOSS->GetAllEntitlements(InUserId, FString(), Entitlements); for (auto It = Entitlements.CreateConstIterator(); It; ++It) { const TSharedRef<FOnlineEntitlement> Entry = *It; UE_LOG(LogOnline, Log, TEXT(" entitlement id=%s name=%s"), *Entry->Id, *Entry->Name); } // kick off next test bQueryEntitlements = false; StartNextTest(); }
bool FOnlineVoiceSteam::MuteRemoteTalker(uint8 LocalUserNum, const FUniqueNetId& PlayerId, bool bIsSystemWide) { uint32 Return = E_FAIL; if (LocalUserNum >= 0 && LocalUserNum < MAX_LOCAL_PLAYERS) { if (bIsSystemWide) { SystemMuteList.AddUnique((const FUniqueNetIdSteam&)PlayerId); ProcessMuteChangeNotification(); } else { // Skip this if the session isn't active if (SessionInt && SessionInt->GetNumSessions() > 0 && // Or if voice is disabled VoiceEngine.IsValid()) { // Find the specified talker FRemoteTalker* Talker = FindRemoteTalker(PlayerId); if (Talker != NULL) { MuteList.AddUnique((const FUniqueNetIdSteam&)PlayerId); Return = S_OK; UE_LOG(LogVoice, Log, TEXT("Muting remote talker (%s)"), *PlayerId.ToDebugString()); } else { UE_LOG(LogVoice, Verbose, TEXT("Unknown remote talker (%s) specified to MuteRemoteTalker()"), *PlayerId.ToDebugString()); } } } } else { UE_LOG(LogVoice, Warning, TEXT("Invalid user specified in MuteRemoteTalker(%d)"), LocalUserNum); } return Return == S_OK; }
void FTestCloudInterface::OnEnumerateUserFilesComplete(bool bWasSuccessful, const FUniqueNetId& InUserId) { UE_LOG(LogOnline, Log, TEXT("------------------------------------------------")); UE_LOG(LogOnline, Log, TEXT("OnEnumerateUserFilesComplete Success:%d UserId:%s"), bWasSuccessful, *InUserId.ToDebugString()); bOverallSuccess = bOverallSuccess && bWasSuccessful; TArray<FCloudFileHeader> UserFiles; UserCloud->GetUserFileList(InUserId, UserFiles); UserCloud->ClearOnEnumerateUserFilesCompleteDelegate(EnumerationDelegate); for (int32 Idx=0; Idx<UserFiles.Num(); Idx++) { UE_LOG(LogOnline, Log, TEXT("\t%d FileName:%s DLName:%s Hash:%s Size:%d"), Idx, *UserFiles[Idx].FileName, *UserFiles[Idx].DLName, *UserFiles[Idx].Hash, UserFiles[Idx].FileSize); } // Enumeration always advances the test phase TestPhase++; }
uint32 FVoiceEngineSteam::SubmitRemoteVoiceData(const FUniqueNetId& RemoteTalkerId, uint8* Data, uint32* Size) { UE_LOG(LogVoiceDecode, VeryVerbose, TEXT("SubmitRemoteVoiceData(%s) Size: %d received!"), *RemoteTalkerId.ToDebugString(), *Size); const FUniqueNetIdSteam& SteamId = (const FUniqueNetIdSteam&)RemoteTalkerId; FRemoteTalkerDataSteam* QueuedData = RemoteTalkerBuffers.Find(SteamId); if (QueuedData == NULL) { RemoteTalkerBuffers.Add(SteamId, FRemoteTalkerDataSteam()); QueuedData = RemoteTalkerBuffers.Find(SteamId); } check(QueuedData); // new voice packet. QueuedData->LastSeen = FPlatformTime::Seconds(); uint32 BytesWritten = 0; DecompressedVoiceBuffer.Empty(MAX_UNCOMPRESSED_VOICE_BUFFER_SIZE); DecompressedVoiceBuffer.AddUninitialized(MAX_UNCOMPRESSED_VOICE_BUFFER_SIZE); const EVoiceResult VoiceResult = SteamUserPtr->DecompressVoice(Data, *Size, DecompressedVoiceBuffer.GetData(), DecompressedVoiceBuffer.Num(), &BytesWritten, SteamUserPtr->GetVoiceOptimalSampleRate()); if (VoiceResult != k_EVoiceResultOK) { UE_LOG(LogVoiceDecode, Warning, TEXT("SubmitRemoteVoiceData: DecompressVoice failure: VoiceResult: %s"), *SteamVoiceResult(VoiceResult)); *Size = 0; return E_FAIL; } // If there is no data, return if (BytesWritten <= 0) { *Size = 0; return S_OK; } // Generate a streaming wave audio component for voice playback if (QueuedData->AudioComponent == NULL || QueuedData->AudioComponent->IsPendingKill()) { if (SerializeHelper == NULL) { SerializeHelper = new FVoiceSerializeHelper(this); } QueuedData->AudioComponent = CreateVoiceAudioComponent(SteamUserPtr->GetVoiceOptimalSampleRate()); if (QueuedData->AudioComponent) { QueuedData->AudioComponent->OnAudioFinishedNative.AddRaw(this, &FVoiceEngineSteam::OnAudioFinished); QueuedData->AudioComponent->Play(); } } if (QueuedData->AudioComponent != NULL) { USoundWaveProcedural* SoundStreaming = CastChecked<USoundWaveProcedural>(QueuedData->AudioComponent->Sound); if (SoundStreaming->GetAvailableAudioByteCount() == 0) { UE_LOG(LogVoiceDecode, Log, TEXT("VOIP audio component was starved!")); } SoundStreaming->QueueAudio(DecompressedVoiceBuffer.GetData(), BytesWritten); } return S_OK; }
void FTestCloudInterface::OnReadEnumeratedUserFilesComplete(bool bWasSuccessful, const FUniqueNetId& InUserId, const FString& FileName) { int32 FileSize = 0; if (bWasSuccessful) { TArray<uint8> FileContents; bWasSuccessful = UserCloud->GetFileContents(InUserId, FileName, FileContents); FileSize = FileContents.Num(); } UE_LOG(LogOnline, Log, TEXT("Read user file complete Success:%d UserId:%s FileName:%s Size:%d"), bWasSuccessful, *InUserId.ToDebugString(), *FileName, FileSize); bOverallSuccess = bOverallSuccess && bWasSuccessful; static int32 NumReadCount = 0; NumReadCount++; if (NumReadCount == ReadUserFileCount) { UE_LOG(LogOnline, Log, TEXT("Read %d User Files Complete!"), NumReadCount); UE_LOG(LogOnline, Log, TEXT("------------------------------------------------")); UserCloud->ClearOnReadUserFileCompleteDelegate(OnReadEnumeratedUserFilesCompleteDelegate); NumReadCount = 0; EnumerateUserFiles(); } }
void FTestCloudInterface::OnDeleteEnumeratedUserFilesComplete(bool bWasSuccessful, const FUniqueNetId& InUserId, const FString& FileName) { UE_LOG(LogOnline, Log, TEXT("Delete user file complete Success:%d UserId:%s FileName:%s"), bWasSuccessful, *InUserId.ToDebugString(), *FileName); bOverallSuccess = bOverallSuccess && bWasSuccessful; static int32 NumDeletedCount = 0; NumDeletedCount++; if (NumDeletedCount == DeleteUserFileCount) { UE_LOG(LogOnline, Log, TEXT("Delete %d User Files Complete!"), NumDeletedCount); UE_LOG(LogOnline, Log, TEXT("------------------------------------------------")); UserCloud->ClearOnDeleteUserFileCompleteDelegate(OnDeleteEnumeratedUserFilesCompleteDelegate); NumDeletedCount = 0; EnumerateUserFiles(); } }
void FTestCloudInterface::OnWriteSharedCloudFileComplete(bool bWasSuccessful, const FUniqueNetId& InUserId, const FString& FileName, const TSharedRef<FSharedContentHandle>& SharedHandle) { UE_LOG(LogOnline, Log, TEXT("Write shared file complete Success:%d UserId:%s FileName:%s SharedHandle:%s"), bWasSuccessful, *InUserId.ToDebugString(), *FileName, *SharedHandle->ToDebugString()); bOverallSuccess = bOverallSuccess && bWasSuccessful; CloudFileHandles.Add(SharedHandle); static int32 NumWrittenCount = 0; NumWrittenCount++; if (NumWrittenCount == WriteSharedCloudFileCount) { UE_LOG(LogOnline, Log, TEXT("Write %d Shared Files Complete!"), NumWrittenCount); UE_LOG(LogOnline, Log, TEXT("------------------------------------------------")); SharedCloud->ClearOnWriteSharedFileCompleteDelegate(OnWriteSharedCloudFileCompleteDelegate); NumWrittenCount = 0; // Enumeration will put the newly shared files into this user's list EnumerateUserFiles(); } }
/** Remove the player notification handler for a type */ void FOnlineNotificationHandler::RemovePlayerNotificationBinding(const FUniqueNetId& PlayerId, FString NotificationType, FDelegateHandle RemoveHandle) { int32 BindingsRemoved = 0; NotificationTypeBindingsMap* FoundPlayerBindings = PlayerBindingMap.Find(PlayerId.ToString()); if (FoundPlayerBindings) { TArray<FOnlineNotificationBinding>* FoundPlayerTypeBindings = FoundPlayerBindings->Find(NotificationType); if (FoundPlayerTypeBindings) { BindingsRemoved = FoundPlayerTypeBindings->RemoveAll([=](const FOnlineNotificationBinding& Binding) { return Binding.NotificationDelegate.GetHandle() == RemoveHandle; }); } } if (BindingsRemoved == 0) { UE_LOG_ONLINE(Error, TEXT("Attempted to remove binding that could not be found for player %s type %s"), *PlayerId.ToDebugString(), *NotificationType); } }
uint32 FVoiceEngineImpl::SubmitRemoteVoiceData(const FUniqueNetId& RemoteTalkerId, uint8* Data, uint32* Size) { UE_LOG(LogVoiceDecode, VeryVerbose, TEXT("SubmitRemoteVoiceData(%s) Size: %d received!"), *RemoteTalkerId.ToDebugString(), *Size); const FUniqueNetIdString& TalkerId = (const FUniqueNetIdString&)RemoteTalkerId; FRemoteTalkerDataImpl& QueuedData = RemoteTalkerBuffers.FindOrAdd(TalkerId); // new voice packet. QueuedData.LastSeen = FPlatformTime::Seconds(); uint32 BytesWritten = MAX_UNCOMPRESSED_VOICE_BUFFER_SIZE; DecompressedVoiceBuffer.Empty(MAX_UNCOMPRESSED_VOICE_BUFFER_SIZE); DecompressedVoiceBuffer.AddUninitialized(MAX_UNCOMPRESSED_VOICE_BUFFER_SIZE); QueuedData.VoiceDecoder->Decode(Data, *Size, DecompressedVoiceBuffer.GetData(), BytesWritten); // If there is no data, return if (BytesWritten <= 0) { *Size = 0; return S_OK; } bool bAudioComponentCreated = false; // Generate a streaming wave audio component for voice playback if (QueuedData.AudioComponent == nullptr || QueuedData.AudioComponent->IsPendingKill()) { if (SerializeHelper == nullptr) { SerializeHelper = new FVoiceSerializeHelper(this); } QueuedData.AudioComponent = CreateVoiceAudioComponent(VOICE_SAMPLE_RATE); if (QueuedData.AudioComponent) { QueuedData.AudioComponent->OnAudioFinishedNative.AddRaw(this, &FVoiceEngineImpl::OnAudioFinished); } } if (QueuedData.AudioComponent != nullptr) { if (!QueuedData.AudioComponent->IsActive()) { QueuedData.AudioComponent->Play(); } USoundWaveStreaming* SoundStreaming = CastChecked<USoundWaveStreaming>(QueuedData.AudioComponent->Sound); if (0) { if (!bAudioComponentCreated && SoundStreaming->GetAvailableAudioByteCount() == 0) { UE_LOG(LogVoiceDecode, Log, TEXT("VOIP audio component was starved!")); } } SoundStreaming->QueueAudio(DecompressedVoiceBuffer.GetData(), BytesWritten); } return S_OK; }
void FTestCloudInterface::WriteNSharedCloudFiles(const FUniqueNetId& InUserId, const FString& FileNameBase, int32 FileCount, FOnWriteSharedFileCompleteDelegate& Delegate) { UE_LOG(LogOnline, Log, TEXT("------------------------------------------------")); UE_LOG(LogOnline, Log, TEXT("Writing %d files to the cloud and sharing for user %s"), FileCount, *InUserId.ToDebugString()); FString FileName(FileNameBase); WriteSharedCloudFileCount = FileCount; SharedCloud->AddOnWriteSharedFileCompleteDelegate(Delegate); TArray<uint8> DummyData; for (int32 FileIdx=0; FileIdx<FileCount; FileIdx++) { WriteRandomFile(DummyData, FMath::Trunc(FMath::FRandRange(1024, 100*1024))); SharedCloud->WriteSharedFile(InUserId, FString::Printf(TEXT("%s%d.%s"), *FPaths::GetBaseFilename(FileName), FileIdx, *FPaths::GetExtension(FileName)), DummyData); } }