默认的JoinSession 是没有传递参数功能的,不过我可以通过重写客户端的PlayerController的ClientTravelInternal_Implementation的函数 添加参数,然后在服务器GameMode的InitNewPlayer中获得改参数
CustomPlayerController
void ClientTravelInternal_Implementation(const FString& URL, enum ETravelType TravelType, bool bSeamless = false, FGuid MapPackageGuid = FGuid());
void AServerSession_PlayerController::ClientTravelInternal_Implementation(const FString& URL, ETravelType TravelType, bool bSeamless, FGuid MapPackageGuid)
{
//添加服务器参数
FString FinalURL = URL + TEXT("?bIsServer=true") ;
Super::ClientTravelInternal_Implementation(FinalURL, TravelType, bSeamless, MapPackageGuid);
}
CustomGameMode
virtual FString InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId, const FString& Options, const FString& Portal /* = TEXT("") */) override;
FString AVTTSGameModeBase::InitNewPlayer(APlayerController* NewPlayerController, const FUniqueNetIdRepl& UniqueId, const FString& Options, const FString& Portal)
{
//获得客户端传来的参数
FString IsServer = UGameplayStatics::ParseOption(Options, TEXT("bIsServer"));
Super::InitNewPlayer......
}