diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index b5ff937..e7739b4 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,8 +1,8 @@ [/Script/EngineSettings.GameMapsSettings] -GameDefaultMap=/Engine/Maps/Templates/OpenWorld - +GameDefaultMap=/Game/Maps/GameStartupMap.GameStartupMap +EditorStartupMap=/Game/Maps/GameStartupMap.GameStartupMap [/Script/HardwareTargeting.HardwareTargetingSettings] TargetedHardwareClass=Desktop @@ -41,3 +41,17 @@ ConnectionType=USBOnly bUseManualIPAddress=False ManualIPAddress= +[/Script/Engine.GameEngine] ++NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver") + +[OnlineSubsystem] +DefaultPlatformService=Steam + +[OnlineSubsystemSteam] +bEnabled=true +SteamDevAppId=480 +bInitServerOnClient=true + +[/Script/OnlineSubsystemSteam.SteamNetDriver] +NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection" + diff --git a/Config/DefaultGame.ini b/Config/DefaultGame.ini index 866291b..b767302 100644 --- a/Config/DefaultGame.ini +++ b/Config/DefaultGame.ini @@ -1,3 +1,11 @@ + [/Script/EngineSettings.GeneralProjectSettings] ProjectID=DD573C214B328A1AEDE15DA9E4FBD4B4 + +[/Script/Engine.GameSession] +MaxPlayers=100 + +[/Script/UnrealEd.ProjectPackagingSettings] ++MapsToCook=(FilePath="/Game/Maps/Lobby") ++MapsToCook=(FilePath="/Game/Maps/GameStartupMap") \ No newline at end of file diff --git a/Content/Maps/GameStartupMap.umap b/Content/Maps/GameStartupMap.umap new file mode 100644 index 0000000..1580559 Binary files /dev/null and b/Content/Maps/GameStartupMap.umap differ diff --git a/Content/Maps/Lobby.umap b/Content/Maps/Lobby.umap new file mode 100644 index 0000000..46d4476 Binary files /dev/null and b/Content/Maps/Lobby.umap differ diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp index 0c7fd94..bef43c3 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/Menu.cpp @@ -7,10 +7,11 @@ #include "OnlineSessionSettings.h" #include "OnlineSubsystem.h" -void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch) +void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FString LobbyPath) { NumPublicConnections = NumberOfPublicConnections; MatchType = TypeOfMatch; + PathToLobby = FString::Printf(TEXT("%s?listen"), *LobbyPath); AddToViewport(); SetVisibility(ESlateVisibility::Visible); @@ -89,7 +90,7 @@ void UMenu::OnCreateSession(bool bWasSuccessful) UWorld* World = GetWorld(); if (World) { - World->ServerTravel(FString("/Game/ThirdPerson/Maps/Lobby?listen")); + World->ServerTravel(FString(PathToLobby)); } } else @@ -102,6 +103,7 @@ void UMenu::OnCreateSession(bool bWasSuccessful) FColor::Red, FString(TEXT("Failed to create session!"))); } + HostButton->SetIsEnabled(true); } } @@ -122,6 +124,10 @@ void UMenu::OnFindSessions(const TArray& SessionResu return; } } + if (!bWasSuccessful || SessionResults.Num() == 0) + { + JoinButton->SetIsEnabled(true); + } } void UMenu::OnJoinSession(EOnJoinSessionCompleteResult::Type Result) @@ -143,6 +149,11 @@ void UMenu::OnJoinSession(EOnJoinSessionCompleteResult::Type Result) } } } + + if (Result != EOnJoinSessionCompleteResult::Success) + { + JoinButton->SetIsEnabled(true); + } } void UMenu::OnDestroySession(bool bWasSuccessful) @@ -155,6 +166,8 @@ void UMenu::OnStartSession(bool bWasSuccessful) void UMenu::HostButtonClicked() { + HostButton->SetIsEnabled(false); + if (MultiplayerSessionsSubsystem) { MultiplayerSessionsSubsystem->CreateSession(NumPublicConnections, MatchType); @@ -163,6 +176,8 @@ void UMenu::HostButtonClicked() void UMenu::JoinButtonClicked() { + JoinButton->SetIsEnabled(false); + if (MultiplayerSessionsSubsystem) { MultiplayerSessionsSubsystem->FindSessions(10000); diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp index 30561ca..f366c88 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Private/MultiplayerSessionsSubsystem.cpp @@ -31,7 +31,11 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession); if (ExistingSession != nullptr) { - SessionInterface->DestroySession(NAME_GameSession); + bCreateSessionOnDestroy = true; + LastNumPublicConnections = NumPublicConnections; + LastMatchType = MatchType; + + DestroySession(); } // Store the delegate in a FDelegateHandle so we can later remove it from the delegate list @@ -102,10 +106,36 @@ void UMultiplayerSessionsSubsystem::JoinSession(const FOnlineSessionSearchResult void UMultiplayerSessionsSubsystem::DestroySession() { + if (!SessionInterface.IsValid()) + { + MultiplayerOnDestroySessionComplete.Broadcast(false); + return; + } + + DestroySessionCompleteDelegateHandle = SessionInterface->AddOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegate); + + if (!SessionInterface->DestroySession(NAME_GameSession)) + { + SessionInterface->ClearOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegateHandle); + MultiplayerOnDestroySessionComplete.Broadcast(false); + } } void UMultiplayerSessionsSubsystem::StartSession() { + if (!SessionInterface.IsValid()) + { + return; + } + + StartSessionCompleteDelegateHandle = SessionInterface->AddOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegate); + + if (!SessionInterface->StartSession(NAME_GameSession)) + { + SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); + + MultiplayerOnStartSessionComplete.Broadcast(false); + } } void UMultiplayerSessionsSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful) @@ -146,8 +176,26 @@ void UMultiplayerSessionsSubsystem::OnJoinSessionComplete(FName SessionName, EOn void UMultiplayerSessionsSubsystem::OnDestroySessionComplete(FName SessionName, bool bWasSuccessful) { + if (SessionInterface) + { + SessionInterface->ClearOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegateHandle); + } + + if (bWasSuccessful && bCreateSessionOnDestroy) + { + bCreateSessionOnDestroy = false; + CreateSession(LastNumPublicConnections, LastMatchType); + } + + MultiplayerOnDestroySessionComplete.Broadcast(bWasSuccessful); } void UMultiplayerSessionsSubsystem::OnStartSessionComplete(FName SessionNAme, bool bWasSuccessful) { + if (SessionInterface) + { + SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle); + } + + MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful); } diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h index a53cbd5..93359b7 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/Menu.h @@ -18,7 +18,7 @@ class MULTIPLAYERSESSIONS_API UMenu : public UUserWidget public: UFUNCTION(BlueprintCallable) - void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll"))); + void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll")), FString LobbyPath = FString(TEXT("/Game/ThirdPerson/Maps/Lobby"))); protected: @@ -58,4 +58,5 @@ private: int32 NumPublicConnections {4}; FString MatchType {TEXT("FreeForAll")}; + FString PathToLobby { TEXT("")}; }; diff --git a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h index 7db1c11..c975cae 100644 --- a/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h +++ b/Plugins/MultiplayerSessions/Source/MultiplayerSessions/Public/MultiplayerSessionsSubsystem.h @@ -78,4 +78,8 @@ private: FDelegateHandle DestroySessionCompleteDelegateHandle; FOnStartSessionCompleteDelegate StartSessionCompleteDelegate; FDelegateHandle StartSessionCompleteDelegateHandle; + + bool bCreateSessionOnDestroy { false }; + int32 LastNumPublicConnections; + FString LastMatchType; };