Added some stuff
This commit is contained in:
parent
92f264a78f
commit
c9f410adc1
|
@ -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"
|
||||
|
||||
|
|
|
@ -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")
|
Binary file not shown.
Binary file not shown.
|
@ -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<FOnlineSessionSearchResult>& 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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("")};
|
||||
};
|
||||
|
|
|
@ -78,4 +78,8 @@ private:
|
|||
FDelegateHandle DestroySessionCompleteDelegateHandle;
|
||||
FOnStartSessionCompleteDelegate StartSessionCompleteDelegate;
|
||||
FDelegateHandle StartSessionCompleteDelegateHandle;
|
||||
|
||||
bool bCreateSessionOnDestroy { false };
|
||||
int32 LastNumPublicConnections;
|
||||
FString LastMatchType;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue