From 8ac4588aed2bebab8b3651c3f9f14c066190c295 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Fri, 8 Dec 2023 05:44:20 +0000 Subject: [PATCH] Update Game Instance to Start Game from Lobby --- CorruptedMemory/Config/DefaultEngine.ini | 4 +- CorruptedMemory/Config/DefaultGame.ini | 5 +- .../FirstPerson/Maps/FirstPersonMap.umap | 4 +- .../Content/Server/BP_LobbyPlayer.uasset | 4 +- .../Content/Server/BP_LobbyServer.uasset | 4 +- .../Content/Server/BP_ServerMenu.uasset | 4 +- .../8/Z7/W1SXRCM1KAKBJOIZDLHZ47.uasset | 4 +- .../Source/CorruptedMemory/CMGameInstance.cpp | 67 ++++++++++++++++--- .../Source/CorruptedMemory/CMGameInstance.h | 14 ++++ .../Source/CorruptedMemory/GenericStructs.h | 8 ++- 10 files changed, 95 insertions(+), 23 deletions(-) diff --git a/CorruptedMemory/Config/DefaultEngine.ini b/CorruptedMemory/Config/DefaultEngine.ini index c2a307f..1e26153 100644 --- a/CorruptedMemory/Config/DefaultEngine.ini +++ b/CorruptedMemory/Config/DefaultEngine.ini @@ -6,10 +6,12 @@ [/Script/EngineSettings.GameMapsSettings] EditorStartupMap=/Game/FirstPerson/Maps/FirstPersonMap.FirstPersonMap LocalMapOptions= -TransitionMap= +TransitionMap=None bUseSplitscreen=True TwoPlayerSplitscreenLayout=Horizontal ThreePlayerSplitscreenLayout=FavorTop +FourPlayerSplitscreenLayout=Grid +bOffsetPlayerGamepadIds=False GameInstanceClass=/Script/CorruptedMemory.CMGameInstance GameDefaultMap=/Game/Levels/ClientEntry.ClientEntry ServerDefaultMap=/Game/FirstPerson/Maps/FirstPersonMap.FirstPersonMap diff --git a/CorruptedMemory/Config/DefaultGame.ini b/CorruptedMemory/Config/DefaultGame.ini index fc95a88..f741aa7 100644 --- a/CorruptedMemory/Config/DefaultGame.ini +++ b/CorruptedMemory/Config/DefaultGame.ini @@ -14,7 +14,7 @@ Build=IfProjectHasCode BuildConfiguration=PPBC_Development BuildTarget=CorruptedMemory LaunchOnTarget= -StagingDirectory=(Path="C:/Users/Phro/Downloads/TestLobbies") +StagingDirectory=(Path="C:/Users/Phro/Downloads/ServerArm64") FullRebuild=False ForDistribution=False IncludeDebugFiles=False @@ -100,12 +100,13 @@ bSkipMovies=False +IniSectionDenylist=HordeStorageServers +IniSectionDenylist=StorageServers +MapsToCook=(FilePath="/Game/FirstPerson/Maps/FirstPersonMap") ++MapsToCook=(FilePath="/Game/Levels/ClientEntry") +DirectoriesToAlwaysCook=(Path="/Interchange/Functions") +DirectoriesToAlwaysCook=(Path="/Interchange/gltf") +DirectoriesToAlwaysCook=(Path="/Interchange/Materials") +DirectoriesToAlwaysCook=(Path="/Interchange/Pipelines") +DirectoriesToAlwaysCook=(Path="/Interchange/Utilities") -PerPlatformBuildConfig=(("LinuxArm64", PPBC_Development)) +PerPlatformBuildConfig=(("LinuxArm64", PPBC_Shipping)) PerPlatformTargetFlavorName=() PerPlatformBuildTarget=(("LinuxArm64", "CorruptedMemoryServer")) diff --git a/CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap b/CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap index a84d83a..aafbf3b 100644 --- a/CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap +++ b/CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:67d471229c8f9c6511984ba2f8fadede38d36e8f16b0cf6cea340345f95cd7d0 -size 38952 +oid sha256:19af0badb2efa7269b7336ba4f44d39966ccb5bf94b8aaafee26a968ffac09f5 +size 41799 diff --git a/CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset b/CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset index 938ab1e..e8e0760 100644 --- a/CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset +++ b/CorruptedMemory/Content/Server/BP_LobbyPlayer.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:44980cb55dcf0f576a61c7cb15800fc9b3fbe722500af8f796855a2a7befe79b -size 120991 +oid sha256:89d525aa3d9c4633b4dfe12cf01e928844cbb8a21dcd92f7b008adecd7521828 +size 140796 diff --git a/CorruptedMemory/Content/Server/BP_LobbyServer.uasset b/CorruptedMemory/Content/Server/BP_LobbyServer.uasset index f0915ef..c15d53e 100644 --- a/CorruptedMemory/Content/Server/BP_LobbyServer.uasset +++ b/CorruptedMemory/Content/Server/BP_LobbyServer.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:def06648264e990a4f43b936545f16ba808b5db19770d83e8dde10467d3b4445 -size 140875 +oid sha256:3dc58a45ec688cee19f901f4c0220cb6660109ec9b27e2c1d135e4592a35eed0 +size 154229 diff --git a/CorruptedMemory/Content/Server/BP_ServerMenu.uasset b/CorruptedMemory/Content/Server/BP_ServerMenu.uasset index aaa0011..fed5639 100644 --- a/CorruptedMemory/Content/Server/BP_ServerMenu.uasset +++ b/CorruptedMemory/Content/Server/BP_ServerMenu.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:46876bb5c3c4d8cdb567cadf0b3034ac0d3df3fa804507323949398b9097432a -size 1016257 +oid sha256:626aeae1e79975c59fdf35d793d2a62fbbb0bb0ed9f61829d0523238dc831158 +size 1198885 diff --git a/CorruptedMemory/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/8/Z7/W1SXRCM1KAKBJOIZDLHZ47.uasset b/CorruptedMemory/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/8/Z7/W1SXRCM1KAKBJOIZDLHZ47.uasset index 37429cd..e89fb6a 100644 --- a/CorruptedMemory/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/8/Z7/W1SXRCM1KAKBJOIZDLHZ47.uasset +++ b/CorruptedMemory/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/8/Z7/W1SXRCM1KAKBJOIZDLHZ47.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:496bdbd13cd2e8c56c46e772f1e836982c9d351ffed82308cda322805d54d07d -size 4064 +oid sha256:1e67416956667dfaa3abdfb23eada561e169c9e05ed77cfa5f0931bd8ba1d38f +size 4448 diff --git a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp index 0cb1bb1..5e0a761 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp +++ b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.cpp @@ -51,11 +51,6 @@ void UCMGameInstance::CreateLobby(const int MaxPlayers) void UCMGameInstance::JoinLobby(const FString LobbyID) { - // if (APlayerController* PC = GetWorld()->GetFirstPlayerController()) - // { - // PC->ConsoleCommand("open " + ServerFQDN + ":" + FString::FromInt(Port)); - // } - const auto Request = FHttpModule::Get().CreateRequest(); Request->SetURL(LobbyAPI + "/join"); Request->SetVerb("POST"); @@ -100,7 +95,7 @@ void UCMGameInstance::GetPlayerLobbyList() void UCMGameInstance::GetServerLobbyList() { const auto Request = FHttpModule::Get().CreateRequest(); - Request->SetURL(LobbyAPI + "/lobbies" + JoinedLobbyID); + Request->SetURL(LobbyAPI + "/lobbies"); Request->SetVerb("GET"); Request->SetHeader("Authorization", "Bearer " + JwtToken); Request->SetHeader("Accept", "application/json"); @@ -108,6 +103,31 @@ void UCMGameInstance::GetServerLobbyList() Request->ProcessRequest(); } +void UCMGameInstance::ReadyUp() +{ + const TSharedPtr ReadyUp = MakeShareable(new FJsonObject); + ReadyUp->SetStringField("lobbyID", JoinedLobbyID); + ReadyUp->SetStringField("username", AccountUsername); + Socket->Emit(TEXT("ready"), ReadyUp); +} + +void UCMGameInstance::UnReady() +{ + const TSharedPtr UnReady = MakeShareable(new FJsonObject); + UnReady->SetStringField("lobbyID", JoinedLobbyID); + UnReady->SetStringField("username", AccountUsername); + Socket->Emit(TEXT("unready"), UnReady); +} + +void UCMGameInstance::StartGame() +{ + Socket->Emit(TEXT("start"), JoinedLobbyID); + if (APlayerController* PC = GetWorld()->GetFirstPlayerController()) + { + PC->ConsoleCommand("open " + ServerFQDN + ":" + FString::FromInt(ServerPort)); + } +} + void UCMGameInstance::Init() { Super::Init(); @@ -148,7 +168,6 @@ void UCMGameInstance::Init() } }); - Socket->OnEvent("join", [this](const FString& Event, const TSharedPtr& Message) { const auto JsonReader = TJsonReaderFactory<>::Create(USIOJConvert::ToJsonString(Message)); @@ -178,8 +197,37 @@ void UCMGameInstance::Init() if (GetWorld()->GetName() != "ClientEntry") { UGameplayStatics::OpenLevel(GetWorld(), "ClientEntry"); - OnServerClose.Broadcast(JsonMessage); } + OnServerClose.Broadcast(JsonMessage); + } + }); + + Socket->OnEvent("ready", [this](const FString& Event, const TSharedPtr& Message) + { + const auto JsonReader = TJsonReaderFactory<>::Create(USIOJConvert::ToJsonString(Message)); + if (TSharedPtr JsonObject; FJsonSerializer::Deserialize(JsonReader, JsonObject)) + { + const auto JsonUsername = JsonObject->GetStringField("username"); + OnPlayerReady.Broadcast(JsonUsername); + } + }); + + Socket->OnEvent("unready", [this](const FString& Event, const TSharedPtr& Message) + { + const auto JsonReader = TJsonReaderFactory<>::Create(USIOJConvert::ToJsonString(Message)); + if (TSharedPtr JsonObject; FJsonSerializer::Deserialize(JsonReader, JsonObject)) + { + const auto JsonUsername = JsonObject->GetStringField("username"); + OnPlayerUnReady.Broadcast(JsonUsername); + } + }); + + Socket->OnEvent("start", [this](const FString& Event, const TSharedPtr& Message) + { + if (GetWorld()->GetName() != "ClientEntry") return; + if (APlayerController* PC = GetWorld()->GetFirstPlayerController()) + { + PC->ConsoleCommand("open " + ServerFQDN + ":" + FString::FromInt(ServerPort)); } }); } @@ -324,7 +372,8 @@ void UCMGameInstance::OnRequestToGetLobbyPlayersComplete(FHttpRequestPtr Request { const auto JsonUsername = Player->AsObject()->GetStringField("user"); const auto JsonIsOwner = Player->AsObject()->GetBoolField("isOwner"); - PlayersInLobby.Add(FPlayerInLobby(JsonUsername, JsonIsOwner)); + const auto JsonIsReady = Player->AsObject()->GetBoolField("isReady"); + PlayersInLobby.Add(FPlayerInLobby(JsonUsername, JsonIsOwner, JsonIsReady)); } OnGetPlayersInLobbyComplete.Broadcast(true); } diff --git a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h index 9448cc6..655efcb 100644 --- a/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h +++ b/CorruptedMemory/Source/CorruptedMemory/CMGameInstance.h @@ -36,6 +36,10 @@ public: DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerLeave, const FString, PlayerName); + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerReady, const FString, PlayerName); + + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerUnReady, const FString, PlayerName); + DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnServerClose, const FString, Message); UPROPERTY(BlueprintAssignable, Category = "Account") @@ -59,6 +63,10 @@ public: UPROPERTY(BlueprintAssignable, Category = "Lobby") FOnPlayerLeave OnPlayerLeave; UPROPERTY(BlueprintAssignable, Category = "Lobby") + FOnPlayerReady OnPlayerReady; + UPROPERTY(BlueprintAssignable, Category = "Lobby") + FOnPlayerUnReady OnPlayerUnReady; + UPROPERTY(BlueprintAssignable, Category = "Lobby") FOnServerClose OnServerClose; UPROPERTY(BlueprintReadOnly, Category = "Account") @@ -93,6 +101,12 @@ public: void GetPlayerLobbyList(); UFUNCTION(BlueprintCallable, Category = "Lobby") void GetServerLobbyList(); + UFUNCTION(BlueprintCallable, Category = "Lobby") + void ReadyUp(); + UFUNCTION(BlueprintCallable, Category = "Lobby") + void UnReady(); + UFUNCTION(BlueprintCallable, Category = "Lobby") + void StartGame(); virtual void Init() override; diff --git a/CorruptedMemory/Source/CorruptedMemory/GenericStructs.h b/CorruptedMemory/Source/CorruptedMemory/GenericStructs.h index 2b77c8e..fb4fe1e 100644 --- a/CorruptedMemory/Source/CorruptedMemory/GenericStructs.h +++ b/CorruptedMemory/Source/CorruptedMemory/GenericStructs.h @@ -14,16 +14,22 @@ struct FPlayerInLobby UPROPERTY(VisibleAnywhere, BlueprintReadOnly) bool bIsOwner; - FPlayerInLobby(FString Username, const bool bIsOwner) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + bool bIsReady; + + + FPlayerInLobby(FString Username, const bool bIsOwner, const bool bIsReady) { this->Username = Username; this->bIsOwner = bIsOwner; + this->bIsReady = bIsReady; } FPlayerInLobby() { this->Username = ""; this->bIsOwner = false; + this->bIsReady = false; } };