Update Game Instance to Start Game from Lobby
This commit is contained in:
parent
46d076c844
commit
8ac4588aed
@ -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
|
||||
|
@ -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"))
|
||||
|
||||
|
BIN
CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap
(Stored with Git LFS)
BIN
CorruptedMemory/Content/FirstPerson/Maps/FirstPersonMap.umap
(Stored with Git LFS)
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:44980cb55dcf0f576a61c7cb15800fc9b3fbe722500af8f796855a2a7befe79b
|
||||
size 120991
|
||||
oid sha256:89d525aa3d9c4633b4dfe12cf01e928844cbb8a21dcd92f7b008adecd7521828
|
||||
size 140796
|
||||
|
BIN
CorruptedMemory/Content/Server/BP_LobbyServer.uasset
(Stored with Git LFS)
BIN
CorruptedMemory/Content/Server/BP_LobbyServer.uasset
(Stored with Git LFS)
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:46876bb5c3c4d8cdb567cadf0b3034ac0d3df3fa804507323949398b9097432a
|
||||
size 1016257
|
||||
oid sha256:626aeae1e79975c59fdf35d793d2a62fbbb0bb0ed9f61829d0523238dc831158
|
||||
size 1198885
|
||||
|
Binary file not shown.
@ -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<FJsonObject> ReadyUp = MakeShareable(new FJsonObject);
|
||||
ReadyUp->SetStringField("lobbyID", JoinedLobbyID);
|
||||
ReadyUp->SetStringField("username", AccountUsername);
|
||||
Socket->Emit(TEXT("ready"), ReadyUp);
|
||||
}
|
||||
|
||||
void UCMGameInstance::UnReady()
|
||||
{
|
||||
const TSharedPtr<FJsonObject> 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<FJsonValue>& 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);
|
||||
}
|
||||
});
|
||||
|
||||
Socket->OnEvent("ready", [this](const FString& Event, const TSharedPtr<FJsonValue>& Message)
|
||||
{
|
||||
const auto JsonReader = TJsonReaderFactory<>::Create(USIOJConvert::ToJsonString(Message));
|
||||
if (TSharedPtr<FJsonObject> JsonObject; FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
const auto JsonUsername = JsonObject->GetStringField("username");
|
||||
OnPlayerReady.Broadcast(JsonUsername);
|
||||
}
|
||||
});
|
||||
|
||||
Socket->OnEvent("unready", [this](const FString& Event, const TSharedPtr<FJsonValue>& Message)
|
||||
{
|
||||
const auto JsonReader = TJsonReaderFactory<>::Create(USIOJConvert::ToJsonString(Message));
|
||||
if (TSharedPtr<FJsonObject> JsonObject; FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
const auto JsonUsername = JsonObject->GetStringField("username");
|
||||
OnPlayerUnReady.Broadcast(JsonUsername);
|
||||
}
|
||||
});
|
||||
|
||||
Socket->OnEvent("start", [this](const FString& Event, const TSharedPtr<FJsonValue>& 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user