Added some stuff

This commit is contained in:
Kingsmedia 2022-04-27 22:19:55 +02:00
parent 92f264a78f
commit c9f410adc1
8 changed files with 96 additions and 6 deletions

View File

@ -1,8 +1,8 @@
[/Script/EngineSettings.GameMapsSettings] [/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Engine/Maps/Templates/OpenWorld GameDefaultMap=/Game/Maps/GameStartupMap.GameStartupMap
EditorStartupMap=/Game/Maps/GameStartupMap.GameStartupMap
[/Script/HardwareTargeting.HardwareTargetingSettings] [/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop TargetedHardwareClass=Desktop
@ -41,3 +41,17 @@ ConnectionType=USBOnly
bUseManualIPAddress=False bUseManualIPAddress=False
ManualIPAddress= 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"

View File

@ -1,3 +1,11 @@
[/Script/EngineSettings.GeneralProjectSettings] [/Script/EngineSettings.GeneralProjectSettings]
ProjectID=DD573C214B328A1AEDE15DA9E4FBD4B4 ProjectID=DD573C214B328A1AEDE15DA9E4FBD4B4
[/Script/Engine.GameSession]
MaxPlayers=100
[/Script/UnrealEd.ProjectPackagingSettings]
+MapsToCook=(FilePath="/Game/Maps/Lobby")
+MapsToCook=(FilePath="/Game/Maps/GameStartupMap")

Binary file not shown.

BIN
Content/Maps/Lobby.umap Normal file

Binary file not shown.

View File

@ -7,10 +7,11 @@
#include "OnlineSessionSettings.h" #include "OnlineSessionSettings.h"
#include "OnlineSubsystem.h" #include "OnlineSubsystem.h"
void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch) void UMenu::MenuSetup(int32 NumberOfPublicConnections, FString TypeOfMatch, FString LobbyPath)
{ {
NumPublicConnections = NumberOfPublicConnections; NumPublicConnections = NumberOfPublicConnections;
MatchType = TypeOfMatch; MatchType = TypeOfMatch;
PathToLobby = FString::Printf(TEXT("%s?listen"), *LobbyPath);
AddToViewport(); AddToViewport();
SetVisibility(ESlateVisibility::Visible); SetVisibility(ESlateVisibility::Visible);
@ -89,7 +90,7 @@ void UMenu::OnCreateSession(bool bWasSuccessful)
UWorld* World = GetWorld(); UWorld* World = GetWorld();
if (World) if (World)
{ {
World->ServerTravel(FString("/Game/ThirdPerson/Maps/Lobby?listen")); World->ServerTravel(FString(PathToLobby));
} }
} }
else else
@ -102,6 +103,7 @@ void UMenu::OnCreateSession(bool bWasSuccessful)
FColor::Red, FColor::Red,
FString(TEXT("Failed to create session!"))); FString(TEXT("Failed to create session!")));
} }
HostButton->SetIsEnabled(true);
} }
} }
@ -122,6 +124,10 @@ void UMenu::OnFindSessions(const TArray<FOnlineSessionSearchResult>& SessionResu
return; return;
} }
} }
if (!bWasSuccessful || SessionResults.Num() == 0)
{
JoinButton->SetIsEnabled(true);
}
} }
void UMenu::OnJoinSession(EOnJoinSessionCompleteResult::Type Result) 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) void UMenu::OnDestroySession(bool bWasSuccessful)
@ -155,6 +166,8 @@ void UMenu::OnStartSession(bool bWasSuccessful)
void UMenu::HostButtonClicked() void UMenu::HostButtonClicked()
{ {
HostButton->SetIsEnabled(false);
if (MultiplayerSessionsSubsystem) if (MultiplayerSessionsSubsystem)
{ {
MultiplayerSessionsSubsystem->CreateSession(NumPublicConnections, MatchType); MultiplayerSessionsSubsystem->CreateSession(NumPublicConnections, MatchType);
@ -163,6 +176,8 @@ void UMenu::HostButtonClicked()
void UMenu::JoinButtonClicked() void UMenu::JoinButtonClicked()
{ {
JoinButton->SetIsEnabled(false);
if (MultiplayerSessionsSubsystem) if (MultiplayerSessionsSubsystem)
{ {
MultiplayerSessionsSubsystem->FindSessions(10000); MultiplayerSessionsSubsystem->FindSessions(10000);

View File

@ -31,7 +31,11 @@ void UMultiplayerSessionsSubsystem::CreateSession(int32 NumPublicConnections, FS
auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession); auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
if (ExistingSession != nullptr) 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 // 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() 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() 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) void UMultiplayerSessionsSubsystem::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
@ -146,8 +176,26 @@ void UMultiplayerSessionsSubsystem::OnJoinSessionComplete(FName SessionName, EOn
void UMultiplayerSessionsSubsystem::OnDestroySessionComplete(FName SessionName, bool bWasSuccessful) 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) void UMultiplayerSessionsSubsystem::OnStartSessionComplete(FName SessionNAme, bool bWasSuccessful)
{ {
if (SessionInterface)
{
SessionInterface->ClearOnStartSessionCompleteDelegate_Handle(StartSessionCompleteDelegateHandle);
}
MultiplayerOnStartSessionComplete.Broadcast(bWasSuccessful);
} }

View File

@ -18,7 +18,7 @@ class MULTIPLAYERSESSIONS_API UMenu : public UUserWidget
public: public:
UFUNCTION(BlueprintCallable) 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: protected:
@ -58,4 +58,5 @@ private:
int32 NumPublicConnections {4}; int32 NumPublicConnections {4};
FString MatchType {TEXT("FreeForAll")}; FString MatchType {TEXT("FreeForAll")};
FString PathToLobby { TEXT("")};
}; };

View File

@ -78,4 +78,8 @@ private:
FDelegateHandle DestroySessionCompleteDelegateHandle; FDelegateHandle DestroySessionCompleteDelegateHandle;
FOnStartSessionCompleteDelegate StartSessionCompleteDelegate; FOnStartSessionCompleteDelegate StartSessionCompleteDelegate;
FDelegateHandle StartSessionCompleteDelegateHandle; FDelegateHandle StartSessionCompleteDelegateHandle;
bool bCreateSessionOnDestroy { false };
int32 LastNumPublicConnections;
FString LastMatchType;
}; };