本文整理汇总了C++中IOnlineSessionPtr::IsValid方法的典型用法代码示例。如果您正苦于以下问题:C++ IOnlineSessionPtr::IsValid方法的具体用法?C++ IOnlineSessionPtr::IsValid怎么用?C++ IOnlineSessionPtr::IsValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOnlineSessionPtr
的用法示例。
在下文中一共展示了IOnlineSessionPtr::IsValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnFindSessionsComplete
void UtrnetDemoGameInstance::OnFindSessionsComplete(bool bWasSuccessful)
{
isLoading_ = false;
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OFindSessionsComplete bSuccess: %d"), bWasSuccessful));
// Get SessionInterface of the OnlineSubsystem
IOnlineSessionPtr Sessions = GetSession();
if (!Sessions.IsValid())
{
return;
}
// Clear the Delegate handle, since we finished this call
Sessions->ClearOnFindSessionsCompleteDelegate_Handle(OnFindSessionsCompleteDelegateHandle);
// Just debugging the Number of Search results. Can be displayed in UMG or something later on
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Num Search Results: %d"), SessionSearch->SearchResults.Num()));
// If we have found at least 1 session, we just going to debug them. You could add them to a list of UMG Widgets, like it is done in the BP version!
if (SessionSearch->SearchResults.Num() > 0)
{
// "SessionSearch->SearchResults" is an Array that contains all the information. You can access the Session in this and get a lot of information.
// This can be customized later on with your own classes to add more information that can be set and displayed
for (int32 SearchIdx = 0; SearchIdx < SessionSearch->SearchResults.Num(); SearchIdx++)
{
// OwningUserName is just the SessionName for now. I guess you can create your own Host Settings class and GameSession Class and add a proper GameServer Name here.
// This is something you can't do in Blueprint for example!
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("Session Number: %d | Sessionname: %s "), SearchIdx + 1, *(SessionSearch->SearchResults[SearchIdx].Session.OwningUserName)));
}
}
}
示例2: GetSessionSettings
void UAdvancedSessionsLibrary::GetSessionSettings(int32 &NumConnections, bool &bIsLAN, bool &bIsDedicated, bool &bIsAnticheatEnabled, int32 &BuildUniqueID, TArray<FSessionPropertyKeyPair> &ExtraSettings, TEnumAsByte<EBlueprintResultSwitch::Type> &Result)
{
IOnlineSessionPtr SessionInterface = Online::GetSessionInterface();
if (!SessionInterface.IsValid())
{
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetSessionSettings couldn't get the session interface!"));
Result = EBlueprintResultSwitch::Type::OnFailure;
return;
}
FOnlineSessionSettings* settings = SessionInterface->GetSessionSettings(GameSessionName);
if (!settings)
{
UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetSessionSettings couldn't get the session settings!"));
Result = EBlueprintResultSwitch::Type::OnFailure;
return;
}
BuildUniqueID = settings->BuildUniqueId;
NumConnections = settings->NumPublicConnections;
bIsLAN = settings->bIsLANMatch;
bIsDedicated = settings->bIsDedicated;
bIsAnticheatEnabled = settings->bAntiCheatProtected;
FSessionPropertyKeyPair NewSetting;
for (auto& Elem : settings->Settings)
{
NewSetting.Key = Elem.Key;
NewSetting.Data = Elem.Value.Data;
ExtraSettings.Add(NewSetting);
}
Result = EBlueprintResultSwitch::Type::OnSuccess;
}
示例3: RequestReservation
bool APartyBeaconClient::RequestReservation(const FOnlineSessionSearchResult& DesiredHost, const FUniqueNetIdRepl& RequestingPartyLeader, const TArray<FPlayerReservation>& PartyMembers)
{
bool bSuccess = false;
if (DesiredHost.IsValid())
{
UWorld* World = GetWorld();
IOnlineSubsystem* OnlineSub = Online::GetSubsystem(World);
if (OnlineSub)
{
IOnlineSessionPtr SessionInt = OnlineSub->GetSessionInterface();
if (SessionInt.IsValid())
{
FString ConnectInfo;
if (SessionInt->GetResolvedConnectString(DesiredHost, BeaconPort, ConnectInfo))
{
FString SessionId = DesiredHost.Session.SessionInfo->GetSessionId().ToString();
return RequestReservation(ConnectInfo, SessionId, RequestingPartyLeader, PartyMembers);
}
}
}
}
if (!bSuccess)
{
OnFailure();
}
return bSuccess;
}
示例4: OnJoinSessionComplete
void UtrnetDemoGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
isLoading_ = false;
GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OnJoinSessionComplete %s, %d"), *SessionName.ToString(), static_cast<int32>(Result)));
// Get SessionInterface from the OnlineSubsystem
IOnlineSessionPtr Sessions = GetSession();
if (!Sessions.IsValid())
{
return;
}
// Clear the Delegate again
Sessions->ClearOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegateHandle);
// Get the first local PlayerController, so we can call "ClientTravel" to get to the Server Map
// This is something the Blueprint Node "Join Session" does automatically!
APlayerController * const PlayerController = GetFirstLocalPlayerController();
// We need a FString to use ClientTravel and we can let the SessionInterface contruct such a
// String for us by giving him the SessionName and an empty String. We want to do this, because
// Every OnlineSubsystem uses different TravelURLs
FString TravelURL;
if (PlayerController && Sessions->GetResolvedConnectString(SessionName, TravelURL))
{
// Finally call the ClienTravel. If you want, you could print the TravelURL to see
// how it really looks like
PlayerController->ClientTravel(TravelURL, ETravelType::TRAVEL_Absolute);
}
}
示例5: OnStartOnlineGameComplete
/**
* Delegate fired when a session start request has completed
*
* @param SessionName the name of the session this callback is for
* @param bWasSuccessful true if the async action completed without error, false if there was an error
*/
void URadeGameInstance::OnStartOnlineGameComplete(FName SessionName, bool bWasSuccessful)
{
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OnStartSessionComplete %s, %d"), *SessionName.ToString(), bWasSuccessful));
// Get the Online Subsystem so we can get the Session Interface
IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
if (OnlineSub)
{
// Get the Session Interface to clear the Delegate
IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
{
// Clear the delegate, since we are done with this call
Sessions->ClearOnStartSessionCompleteDelegate_Handle(OnStartSessionCompleteDelegateHandle);
}
}
// If the start was successful, we can open a NewMap if we want. Make sure to use "listen" as a parameter!
if (bWasSuccessful)
{
//BattleArena
UGameplayStatics::OpenLevel(GetWorld(), *TheMapName, true, "listen");
}
}
示例6: OnCreateSessionComplete
/**
* Delegate fired when a session create request has completed
*
* @param SessionName the name of the session this callback is for
* @param bWasSuccessful true if the async action completed without error, false if there was an error
*/
void URadeGameInstance::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
{
//GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Red, FString::Printf(TEXT("OnCreateSessionComplete %s, %d"), *SessionName.ToString(), bWasSuccessful));
// Get the OnlineSubsystem so we can get the Session Interface
IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
if (OnlineSub)
{
// Get the Session Interface to call the StartSession function
IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
{
// Clear the SessionComplete delegate handle, since we finished this call
Sessions->ClearOnCreateSessionCompleteDelegate_Handle(OnCreateSessionCompleteDelegateHandle);
if (bWasSuccessful)
{
// Set the StartSession delegate handle
OnStartSessionCompleteDelegateHandle = Sessions->AddOnStartSessionCompleteDelegate_Handle(OnStartSessionCompleteDelegate);
//printr(SessionName.ToString());
// Our StartSessionComplete delegate should get called after this
Sessions->StartSession(SessionName);
}
}
}
}
示例7: JoinSession
// Join Session
bool URadeGameInstance::JoinSession(TSharedPtr<const FUniqueNetId> UserId, FName SessionName, const FOnlineSessionSearchResult& SearchResult)
{
// Return bool
bool bSuccessful = false;
// Get OnlineSubsystem we want to work with
IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
if (OnlineSub)
{
// Get SessionInterface from the OnlineSubsystem
IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
if (Sessions.IsValid() && UserId.IsValid())
{
// Set the Handle again
OnJoinSessionCompleteDelegateHandle = Sessions->AddOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegate);
// Call the "JoinSession" Function with the passed "SearchResult". The "SessionSearch->SearchResults" can be used to get such a
// "FOnlineSessionSearchResult" and pass it. Pretty straight forward!
bSuccessful = Sessions->JoinSession(*UserId, SessionName, SearchResult);
}
}
return bSuccessful;
}
示例8: ClientStartOnlineGame_Implementation
/** Starts the online game using the session name in the PlayerState */
void AShooterPlayerController::ClientStartOnlineGame_Implementation()
{
if (!IsPrimaryPlayer())
return;
AShooterPlayerState* ShooterPlayerState = Cast<AShooterPlayerState>(PlayerState);
if (ShooterPlayerState)
{
IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
if (OnlineSub)
{
IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
{
UE_LOG(LogOnline, Log, TEXT("Starting session %s on client"), *ShooterPlayerState->SessionName.ToString() );
Sessions->StartSession(ShooterPlayerState->SessionName);
}
}
}
else
{
// Keep retrying until player state is replicated
GetWorld()->GetTimerManager().SetTimer(FTimerDelegate::CreateUObject(this, &AShooterPlayerController::ClientStartOnlineGame_Implementation), 0.2f, false);
}
}
示例9: OnJoinSessionComplete
void URadeGameInstance::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
// Get the OnlineSubsystem we want to work with
IOnlineSubsystem* OnlineSub = IOnlineSubsystem::Get();
if (OnlineSub)
{
// Get SessionInterface from the OnlineSubsystem
IOnlineSessionPtr Sessions = OnlineSub->GetSessionInterface();
if (Sessions.IsValid())
{
// Clear the Delegate again
Sessions->ClearOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegateHandle);
// Get the first local PlayerController, so we can call "ClientTravel" to get to the Server Map
// This is something the Blueprint Node "Join Session" does automatically!
APlayerController * const PlayerController = GetFirstLocalPlayerController();
// We need a FString to use ClientTravel and we can let the SessionInterface contruct such a
// String for us by giving him the SessionName and an empty String. We want to do this, because
// Every OnlineSubsystem uses different TravelURLs
FString TravelURL;
if (PlayerController && Sessions->GetResolvedConnectString(SessionName, TravelURL))
{
// Finally call the ClienTravel. If you want, you could print the TravelURL to see
// how it really looks like
PlayerController->ClientTravel(TravelURL, ETravelType::TRAVEL_Absolute);
}
}
}
}
示例10: JoinGame
bool UUModGameInstance::JoinGame(FString ip, int32 port)
{
IOnlineSubsystem* const OnlineSub = IOnlineSubsystem::Get();
IOnlineSessionPtr Sessions = NULL;
if (OnlineSub == NULL) {
return false;
}
Sessions = OnlineSub->GetSessionInterface();
if (!Sessions.IsValid()) {
return false;
}
if (!CurSessionName.IsEmpty()){
DestroyCurSession(Sessions);
return false;
}
ULocalPlayer* const Player = GetFirstGamePlayer();
FString str = ip + FString(":");
str.AppendInt(port);
ConnectIP = str;
Player->PlayerController->ClientTravel("LoadScreen", ETravelType::TRAVEL_Absolute);
DelayedServerConnect = true;
return false;
}
示例11: onClickEndGame
void AFPSGPlayerController::onClickEndGame() const
{
//Make sure it is the server calling the function
if (Role < ROLE_Authority && GetNetMode() == NM_Client) return;
//GEngine->AddOnScreenDebugMessage(-1, 40.0f, FColor::Cyan, "AFPSGPlayerController::onClickEndGame");
IOnlineSubsystem* onlineSubsystem = IOnlineSubsystem::Get();
IOnlineSessionPtr sessions = onlineSubsystem != NULL ? onlineSubsystem->GetSessionInterface() : NULL;
if (sessions.IsValid())
{
UWorld* world = GetWorld();
AFPSGGameState* gameState = world != NULL ? world->GetGameState<AFPSGGameState>() : NULL;
if (gameState != NULL)
{
//Retrieve the session state and match state
EOnlineSessionState::Type sessionState = sessions->GetSessionState(GameSessionName);
FName matchState = gameState->GetMatchState();
//Only attempt to end the game if both the session and match are in progress
if (sessionState == EOnlineSessionState::Type::InProgress && matchState == MatchState::InProgress)
{
gameState->onClickEndGame();
}
}
}
}
示例12: OnJoinSessionComplete
void UOnlineSessionClient::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result)
{
UE_LOG(LogOnline, Verbose, TEXT("OnJoinSessionComplete %s bSuccess: %d"), *SessionName.ToString(), static_cast<int32>(Result));
IOnlineSessionPtr SessionInt = GetSessionInt();
if (SessionInt.IsValid())
{
SessionInt->ClearOnJoinSessionCompleteDelegate_Handle(OnJoinSessionCompleteDelegateHandle);
if (Result == EOnJoinSessionCompleteResult::Success)
{
FString URL;
if (SessionInt->GetResolvedConnectString(SessionName, URL))
{
APlayerController* PC = GetGameInstance()->GetFirstLocalPlayerController(GetWorld());
if (PC)
{
if (bIsFromInvite)
{
URL += TEXT("?bIsFromInvite");
bIsFromInvite = false;
}
PC->ClientTravel(URL, TRAVEL_Absolute);
}
}
else
{
UE_LOG(LogOnline, Warning, TEXT("Failed to join session %s"), *SessionName.ToString());
}
}
}
}
示例13: ClearOnlineDelegates
void UOnlineSessionClient::ClearOnlineDelegates()
{
IOnlineSessionPtr SessionInt = GetSessionInt();
if (SessionInt.IsValid())
{
SessionInt->ClearOnSessionUserInviteAcceptedDelegate_Handle(OnSessionUserInviteAcceptedDelegateHandle);
}
}
示例14: TriggerDelegates
/**
* Async task is given a chance to trigger it's delegates
*/
virtual void TriggerDelegates() override
{
IOnlineSessionPtr SessionInt = Subsystem->GetSessionInterface();
if (SessionInt.IsValid())
{
SessionInt->TriggerOnDestroySessionCompleteDelegates(SessionName, bWasSuccessful);
}
}
示例15: DumpOnlineSessionState
void UCheatManager::DumpOnlineSessionState()
{
IOnlineSessionPtr SessionInt = Online::GetSessionInterface(GetWorld());
if (SessionInt.IsValid())
{
SessionInt->DumpSessionState();
}
}