Skip to content

Commit e4b0f0c

Browse files
oblmImprobableMatthewwangxinErnest Oppetit
authored
0.8.1 preview rc > preview (#118)
* [UNR-1715][MS] Fix for error messages being deisplayed when character is killed. (#89) Essentially there is a race on death between the health component being updated and the player controller unpossessing it's character actor. I have just added a delay as a quick hacky fix so that both updates are recieved. * Decrementing player count when player disconnects. (#98) * [UNR-2425][MS] Fixing bug with sim players not moving. * [UNR-2608][MS] Decrementing player count when player disconnects. * Revert "[UNR-2425][MS] Fixing bug with sim players not moving." This reverts commit 3c662ca. * Fixing none component on Player character. (#100) The Nameplate component had "Owner no see" enabled which means that the component will not exist for the owner of the actor. The fix is simply to check the Nameplate component before using it. # Conflicts: # Game/Content/Characters/BP_FPS_Character.uasset * Merge of MBL-19 (#108) * MBL-19 Remove some hard coded logics in ADeploymentsPlayerController. (#94) * MBL-19 Remove some hard coded thing in ADeploymentsPlayerController and keep existing features. * Update to player controller. * Removing tryloadfromcommandline as it is unecessary for release. Co-authored-by: wangxin <[email protected]> * [CHINF-886][MS] Fixing a crash caused by the merge into release related to the jira issue. (#111) * [UNR-3041][MS] Addin 14.3 into release (#112) * Crash fix when hitting cancel button. (#114) * [UNR-3071][MS] Updating Worker SDK version to 14.5 (#116) * Readme update: new docs site + maturity guidelines * More docs links updates * Update DefaultSpatialGDKSettings.ini Co-authored-by: MatthewSandfordImprobable <[email protected]> Co-authored-by: wangxin <[email protected]> Co-authored-by: Ernest Oppetit <[email protected]>
1 parent fdbfd33 commit e4b0f0c

File tree

12 files changed

+57
-95
lines changed

12 files changed

+57
-95
lines changed

Game/Config/DefaultSpatialGDKSettings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ DefaultWorkerType=(WorkerTypeName="UnrealWorker")
2929
bEnableOffloading=False
3030
ActorGroups=()
3131
ServerWorkerTypes=("UnrealWorker")
32-
32+
ServicesRegion=Default
19.7 KB
Binary file not shown.
6.74 KB
Binary file not shown.
34.5 KB
Binary file not shown.

Game/Source/GDKShooter/Private/Controllers/GDKPlayerController.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ AGDKPlayerController::AGDKPlayerController()
4343

4444
}
4545

46-
void AGDKPlayerController::BeginPlay()
47-
{
48-
Super::BeginPlay();
49-
50-
if (PlayerState)
51-
{
52-
if (UPlayerPublisher* PlayerPublisher = Cast<UPlayerPublisher>(GetWorld()->GetGameState()->GetComponentByClass(UPlayerPublisher::StaticClass())))
53-
{
54-
PlayerPublisher->PublishPlayer(PlayerState, EPlayerProgress::Connected);
55-
}
56-
}
57-
}
58-
5946
void AGDKPlayerController::Tick(float DeltaTime)
6047
{
6148
Super::Tick(DeltaTime);

Game/Source/GDKShooter/Private/Deployments/DeploymentsPlayerController.cpp

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "SpatialGameInstance.h"
66
#include "TimerManager.h"
7+
#include "SpatialGDKSettings.h"
78
#include "SpatialWorkerConnection.h"
89

910
#include "GDKLogging.h"
@@ -15,79 +16,36 @@ void ADeploymentsPlayerController::BeginPlay()
1516

1617
bShowMouseCursor = true;
1718

18-
QueryPIT();
19-
}
19+
USpatialGameInstance* SpatialGameInstance = GetGameInstance<USpatialGameInstance>();
20+
SpatialWorkerConnection = SpatialGameInstance->GetSpatialWorkerConnection();
2021

21-
void ADeploymentsPlayerController::EndPlay(const EEndPlayReason::Type Reason)
22-
{
23-
GetWorld()->GetTimerManager().ClearAllTimersForObject(this);
24-
}
25-
26-
void OnLoginTokens(void* UserData, const Worker_Alpha_LoginTokensResponse* LoginTokens)
27-
{
28-
ADeploymentsPlayerController* contoller = static_cast<ADeploymentsPlayerController*>(UserData);
29-
if (LoginTokens->status.code == WORKER_CONNECTION_STATUS_CODE_SUCCESS)
30-
{
31-
UE_LOG(LogGDK, Log, TEXT("Success: Login Token Count %d"), LoginTokens->login_token_count);
32-
contoller->Populate(LoginTokens);
33-
}
34-
else
22+
if (SpatialWorkerConnection == nullptr)
3523
{
36-
UE_LOG(LogGDK, Log, TEXT("Failure: Error %s"), UTF8_TO_TCHAR(LoginTokens->status.detail));
24+
// We might not be using spatial networking in which case SpatialWorkerConnection will not exist so we should just return
25+
return;
3726
}
38-
}
3927

40-
void OnPlayerIdentityToken(void* UserData, const Worker_Alpha_PlayerIdentityTokenResponse* PIToken)
41-
{
42-
if (PIToken->status.code == WORKER_CONNECTION_STATUS_CODE_SUCCESS)
43-
{
44-
UE_LOG(LogGDK, Log, TEXT("Success: Received PIToken: %s"), UTF8_TO_TCHAR(PIToken->player_identity_token));
45-
ADeploymentsPlayerController* controller = static_cast<ADeploymentsPlayerController*>(UserData);
46-
controller->LatestPITokenData = PIToken->player_identity_token;
47-
controller->LatestPIToken = UTF8_TO_TCHAR(PIToken->player_identity_token);
48-
49-
if (!controller->GetWorld()->GetTimerManager().IsTimerActive(controller->QueryDeploymentsTimer))
28+
FString SpatialWorkerType = SpatialGameInstance->GetSpatialWorkerType().ToString();
29+
SpatialWorkerConnection->RegisterOnLoginTokensCallback([this](const Worker_Alpha_LoginTokensResponse* Deployments){
30+
Populate(Deployments);
31+
if (!GetWorld()->GetTimerManager().IsTimerActive(QueryDeploymentsTimer))
5032
{
51-
controller->GetWorld()->GetTimerManager().SetTimer(controller->QueryDeploymentsTimer, controller, &ADeploymentsPlayerController::QueryDeployments, 5.0f, true, 0.0f);
33+
GetWorld()->GetTimerManager().SetTimer(QueryDeploymentsTimer, this, &ADeploymentsPlayerController::ScheduleRefreshDeployments, 10.0f, true, 0.0f);
5234
}
53-
}
54-
else
35+
return true;
36+
});
37+
38+
if (GetDefault<USpatialGDKSettings>()->bUseDevelopmentAuthenticationFlow)
5539
{
56-
UE_LOG(LogGDK, Log, TEXT("Failure: Error %s"), UTF8_TO_TCHAR(PIToken->status.detail));
57-
ADeploymentsPlayerController* controller = static_cast<ADeploymentsPlayerController*>(UserData);
58-
59-
if (controller->GetWorld()->GetTimerManager().IsTimerActive(controller->QueryDeploymentsTimer))
60-
{
61-
controller->GetWorld()->GetTimerManager().ClearTimer(controller->QueryDeploymentsTimer);
62-
}
40+
SpatialWorkerConnection->Connect(true, 0);
6341
}
6442
}
6543

66-
void ADeploymentsPlayerController::QueryDeployments()
67-
{
68-
Worker_Alpha_LoginTokensRequest* LTParams = new Worker_Alpha_LoginTokensRequest();
69-
LTParams->player_identity_token = LatestPITokenData;
70-
LTParams->worker_type = "UnrealClient";
71-
Worker_Alpha_LoginTokensResponseFuture* LTFuture = Worker_Alpha_CreateDevelopmentLoginTokensAsync("locator.improbable.io", 444, LTParams);
72-
Worker_Alpha_LoginTokensResponseFuture_Get(LTFuture, nullptr, this, OnLoginTokens);
73-
}
74-
75-
void ADeploymentsPlayerController::QueryPIT()
44+
void ADeploymentsPlayerController::EndPlay(const EEndPlayReason::Type Reason)
7645
{
77-
Worker_Alpha_PlayerIdentityTokenRequest* PITParams = new Worker_Alpha_PlayerIdentityTokenRequest();
78-
// Replace this string with a dev auth token, see docs for information on how to generate one of these
79-
PITParams->development_authentication_token = "REPLACE ME";
80-
PITParams->player_id = "Player Id";
81-
PITParams->display_name = "";
82-
PITParams->metadata = "";
83-
PITParams->use_insecure_connection = false;
84-
85-
Worker_Alpha_PlayerIdentityTokenResponseFuture* PITFuture = Worker_Alpha_CreateDevelopmentPlayerIdentityTokenAsync("locator.improbable.io", 444, PITParams);
86-
87-
if (PITFuture != nullptr)
88-
{
89-
Worker_Alpha_PlayerIdentityTokenResponseFuture_Get(PITFuture, nullptr, this, OnPlayerIdentityToken);
90-
}
46+
if (SpatialWorkerConnection != nullptr)
47+
SpatialWorkerConnection->RegisterOnLoginTokensCallback([](const Worker_Alpha_LoginTokensResponse* Deployments){return false;});
48+
GetWorld()->GetTimerManager().ClearAllTimersForObject(this);
9149
}
9250

9351
FDeploymentInfo Parse(const Worker_Alpha_LoginTokenDetails LoginToken)
@@ -137,12 +95,19 @@ void ADeploymentsPlayerController::Populate(const Worker_Alpha_LoginTokensRespon
13795

13896
void ADeploymentsPlayerController::JoinDeployment(const FString& LoginToken)
13997
{
98+
if (SpatialWorkerConnection == nullptr)
99+
{
100+
UE_LOG(LogGDK, Error, TEXT("Failure: failed to Join Deployment caused by SpatialWorkerConnection is nullptr"));
101+
return;
102+
}
103+
104+
const FLocatorConfig& LocatorConfig = SpatialWorkerConnection->LocatorConfig;
140105
FURL TravelURL;
141-
TravelURL.Host = TEXT("locator.improbable.io");
106+
TravelURL.Host = LocatorConfig.LocatorHost;
142107
TravelURL.AddOption(TEXT("locator"));
143-
TravelURL.AddOption(*FString::Printf(TEXT("playeridentity=%s"), *LatestPIToken));
108+
TravelURL.AddOption(*FString::Printf(TEXT("playeridentity=%s"), *LocatorConfig.PlayerIdentityToken));
144109
TravelURL.AddOption(*FString::Printf(TEXT("login=%s"), *LoginToken));
145-
110+
146111
OnLoadingStarted.Broadcast();
147112

148113
ClientTravel(TravelURL.ToString(), TRAVEL_Absolute, false);
@@ -152,3 +117,9 @@ void ADeploymentsPlayerController::SetLoadingScreen(UUserWidget* LoadingScreen)
152117
{
153118
GetGameInstance()->GetGameViewportClient()->AddViewportWidgetContent(LoadingScreen->TakeWidget());
154119
}
120+
121+
void ADeploymentsPlayerController::ScheduleRefreshDeployments()
122+
{
123+
if (SpatialWorkerConnection != nullptr)
124+
SpatialWorkerConnection->RequestDeploymentLoginTokens();
125+
}

Game/Source/GDKShooter/Private/UI/GDKWidget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "Components/ControllerEventsComponent.h"
55
#include "Components/GDKMovementComponent.h"
66
#include "Components/HealthComponent.h"
7+
#include "EngineClasses/SpatialGameInstance.h"
78
#include "Game/Components/LobbyTimerComponent.h"
89
#include "Game/Components/MatchTimerComponent.h"
910
#include "Game/Components/PlayerCountingComponent.h"
@@ -106,6 +107,11 @@ void UGDKWidget::LeaveGame(const FString& TargetMap)
106107
FURL TravelURL;
107108
TravelURL.Map = *TargetMap;
108109

110+
if (USpatialGameInstance* GameInstance = Cast<USpatialGameInstance>(GetGameInstance()))
111+
{
112+
GameInstance->GetSpatialWorkerConnection()->DestroyConnection();
113+
}
114+
109115
GetOwningPlayer()->ClientTravel(TravelURL.ToString(), TRAVEL_Absolute, false /*bSeamless*/);
110116

111117
}

Game/Source/GDKShooter/Public/Controllers/GDKPlayerController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class GDKSHOOTER_API AGDKPlayerController : public APlayerController
1919
public:
2020
AGDKPlayerController();
2121

22-
virtual void BeginPlay() override;
2322
virtual void Tick(float DeltaTime) override;
2423

2524
FPawnEvent& OnPawn() { return PawnEvent; }

Game/Source/GDKShooter/Public/Deployments/DeploymentsPlayerController.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "DeploymentsPlayerController.generated.h"
1111

12+
class USpatialWorkerConnection;
13+
1214
USTRUCT(BlueprintType)
1315
struct FDeploymentInfo {
1416
GENERATED_BODY()
@@ -51,19 +53,15 @@ class GDKSHOOTER_API ADeploymentsPlayerController : public APlayerController
5153
FString LatestPIToken;
5254
const char * LatestPITokenData;
5355

54-
void QueryDeployments();
55-
5656
FTimerHandle QueryDeploymentsTimer;
57+
USpatialWorkerConnection* SpatialWorkerConnection = nullptr;
5758

5859
UFUNCTION(BlueprintCallable)
5960
void JoinDeployment(const FString& LoginToken);
6061

6162
UFUNCTION(BlueprintCallable)
6263
void SetLoadingScreen(UUserWidget* LoadingScreen);
63-
64-
private:
65-
66-
void QueryPIT();
67-
6864

65+
private:
66+
void ScheduleRefreshDeployments();
6967
};

Game/Source/GDKShooter/Public/Game/Components/PlayerPublisher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class GDKSHOOTER_API UPlayerPublisher : public UActorComponent
2424
GENERATED_BODY()
2525

2626
public:
27+
UFUNCTION(BlueprintCallable)
2728
void PublishPlayer(APlayerState* PlayerState, EPlayerProgress Progress) { PlayerEvent.Broadcast(PlayerState, Progress); }
2829

2930
UPROPERTY(BlueprintAssignable)

0 commit comments

Comments
 (0)