Update Server Menu for Server Lobbies Functionality
This commit is contained in:
parent
7bc06a8c8b
commit
46d076c844
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:1ecbae613ae890fe4829b40837aba118bfa07457b23ed2e4268f1a5b88a87f92
|
||||
size 118927
|
||||
oid sha256:def06648264e990a4f43b936545f16ba808b5db19770d83e8dde10467d3b4445
|
||||
size 140875
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:9f2fbfa898429dd167f6a358fa9a4f40007b5bf0ebfd941183221a1cdaa332e6
|
||||
size 908820
|
||||
oid sha256:46876bb5c3c4d8cdb567cadf0b3034ac0d3df3fa804507323949398b9097432a
|
||||
size 1016257
|
||||
|
@ -97,6 +97,17 @@ void UCMGameInstance::GetPlayerLobbyList()
|
||||
Request->ProcessRequest();
|
||||
}
|
||||
|
||||
void UCMGameInstance::GetServerLobbyList()
|
||||
{
|
||||
const auto Request = FHttpModule::Get().CreateRequest();
|
||||
Request->SetURL(LobbyAPI + "/lobbies" + JoinedLobbyID);
|
||||
Request->SetVerb("GET");
|
||||
Request->SetHeader("Authorization", "Bearer " + JwtToken);
|
||||
Request->SetHeader("Accept", "application/json");
|
||||
Request->OnProcessRequestComplete().BindUObject(this, &UCMGameInstance::OnRequestToGetServerLobbyListComplete);
|
||||
Request->ProcessRequest();
|
||||
}
|
||||
|
||||
void UCMGameInstance::Init()
|
||||
{
|
||||
Super::Init();
|
||||
@ -194,6 +205,7 @@ void UCMGameInstance::OnRequestToLoginComplete(FHttpRequestPtr Request, FHttpRes
|
||||
const auto JsonUsername = JsonObject->GetStringField("user");
|
||||
JwtToken = JsonToken;
|
||||
AccountUsername = JsonUsername;
|
||||
Socket->Emit(TEXT("login"), JsonUsername);
|
||||
OnLoginComplete.Broadcast(true);
|
||||
}
|
||||
else
|
||||
@ -326,3 +338,32 @@ void UCMGameInstance::OnRequestToGetLobbyPlayersComplete(FHttpRequestPtr Request
|
||||
OnGetPlayersInLobbyComplete.Broadcast(false);
|
||||
}
|
||||
}
|
||||
|
||||
void UCMGameInstance::OnRequestToGetServerLobbyListComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||
{
|
||||
if (bWasSuccessful)
|
||||
{
|
||||
const auto JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
|
||||
if (TArray<TSharedPtr<FJsonValue>> JsonObject; FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
ServerLobbies.Empty();
|
||||
for (const auto& Server : JsonObject)
|
||||
{
|
||||
const auto JsonLobbyID = Server->AsObject()->GetStringField("id");
|
||||
const auto JsonStatus = Server->AsObject()->GetStringField("status");
|
||||
const auto JsonOnlinePlayers = Server->AsObject()->GetIntegerField("online");
|
||||
const auto JsonMaxPlayers = Server->AsObject()->GetIntegerField("maxPlayers");
|
||||
ServerLobbies.Add(FServerLobby(JsonLobbyID, JsonStatus, JsonOnlinePlayers, JsonMaxPlayers));
|
||||
}
|
||||
OnServerLobbyListComplete.Broadcast(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnServerLobbyListComplete.Broadcast(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnServerLobbyListComplete.Broadcast(false);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGetPlayersInLobbyComplete, const bool, bWasSuccessful);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnServerLobbyListComplete, const bool, bWasSuccessful);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerJoin, const FString, PlayerName);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerLeave, const FString, PlayerName);
|
||||
@ -51,6 +53,8 @@ public:
|
||||
UPROPERTY(BlueprintAssignable, Category = "Lobby")
|
||||
FOnGetPlayersInLobbyComplete OnGetPlayersInLobbyComplete;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Lobby")
|
||||
FOnServerLobbyListComplete OnServerLobbyListComplete;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Lobby")
|
||||
FOnPlayerJoin OnPlayerJoin;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Lobby")
|
||||
FOnPlayerLeave OnPlayerLeave;
|
||||
@ -70,6 +74,8 @@ public:
|
||||
int ServerPort;
|
||||
UPROPERTY(BlueprintReadOnly, Category = "Lobby")
|
||||
TArray<FPlayerInLobby> PlayersInLobby;
|
||||
UPROPERTY(BlueprintReadOnly, Category = "Lobby")
|
||||
TArray<FServerLobby> ServerLobbies;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Account")
|
||||
void Login(const FString& Username, const FString& Password);
|
||||
@ -85,6 +91,8 @@ public:
|
||||
void LeaveLobby();
|
||||
UFUNCTION(BlueprintCallable, Category = "Lobby")
|
||||
void GetPlayerLobbyList();
|
||||
UFUNCTION(BlueprintCallable, Category = "Lobby")
|
||||
void GetServerLobbyList();
|
||||
|
||||
|
||||
virtual void Init() override;
|
||||
@ -100,4 +108,5 @@ private:
|
||||
void OnRequestToJoinLobbyComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
void OnRequestToLeaveLobbyComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
void OnRequestToGetLobbyPlayersComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
void OnRequestToGetServerLobbyListComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||
};
|
||||
|
@ -26,3 +26,37 @@ struct FPlayerInLobby
|
||||
this->bIsOwner = false;
|
||||
}
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FServerLobby
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
FString LobbyName;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
FString Status;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
int32 OnlinePlayers;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
|
||||
int32 MaxPlayers;
|
||||
|
||||
FServerLobby(FString LobbyName, FString Status, int32 OnlinePlayers, int32 MaxPlayers)
|
||||
{
|
||||
this->LobbyName = LobbyName;
|
||||
this->Status = Status;
|
||||
this->OnlinePlayers = OnlinePlayers;
|
||||
this->MaxPlayers = MaxPlayers;
|
||||
}
|
||||
|
||||
FServerLobby()
|
||||
{
|
||||
this->LobbyName = "";
|
||||
this->Status = "";
|
||||
this->OnlinePlayers = 0;
|
||||
this->MaxPlayers = 0;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user