Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Fix spectator having no way to contact server
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Pearson committed Apr 28, 2018
1 parent 77555f7 commit ef3191a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
#include "ParkourPlayerController.h"

#include "../MiniGame/MiniGameManager.h"
#include "../Utils/SingletonHelper.h"

bool AParkourPlayerController::StartGame_Validate(TSubclassOf<AMiniGameBase> GameClass)
{
return true;
}

void AParkourPlayerController::StartGame_Implementation(TSubclassOf<AMiniGameBase> GameClass)
{
AMiniGameManager* Mgr = FSingletonHelper::Static_GetSingletonObject<AMiniGameManager>(GetWorld());

if (!Mgr) return;

Mgr->CreateGame(GameClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@
#include "GameFramework/PlayerController.h"
#include "ParkourPlayerController.generated.h"

class AMiniGameBase;

UCLASS()
class AParkourPlayerController : public APlayerController
{
GENERATED_BODY()

public:

// Spectator Broadcast Functions
// (have to be here as spectators have no net role in a build)
UFUNCTION(Server, Unreliable, WithValidation)
void StartGame(TSubclassOf<AMiniGameBase> GameClass);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void AMiniGameManager::BeginPlay()
if(!HasAuthority())
OnGameOver.AddDynamic(this, &AMiniGameManager::OnGameEnded);

//SetNextGameTimer();
SetNextGameTimer();
}

void AMiniGameManager::CreateRandomGame()
Expand Down Expand Up @@ -138,7 +138,7 @@ void AMiniGameManager::SetNextGameTimer()
if (!HasAuthority())
return;

GetWorld()->GetTimerManager().SetTimer(NextGameTimer, this, &AMiniGameManager::CreateRandomGame, GameCreationInterval);
//GetWorld()->GetTimerManager().SetTimer(NextGameTimer, this, &AMiniGameManager::CreateRandomGame, GameCreationInterval);
}

void AMiniGameManager::OnGameEnded(AMiniGameBase* Game, EMiniGameEndReason Reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
static void cmd_OpenMenu(UWorld* World)
{
APlayerController* PlayerCtlr = World->GetFirstPlayerController();
AParkourSpectator* PlayerCharacter = PlayerCtlr ? Cast<AParkourSpectator>(PlayerCtlr->GetPawn()) : nullptr;

// If we have become a pawn using the console command then we use GetPawn, otherwise we need to use spectator pawn
AParkourSpectator* PlayerCharacter = PlayerCtlr ? Cast<AParkourSpectator>(PlayerCtlr->GetSpectatorPawn()) : nullptr;

#if WITH_EDITOR
if(!PlayerCharacter)
PlayerCharacter = Cast<AParkourSpectator>(PlayerCtlr->GetPawn());
#endif

if (!IsValid(PlayerCharacter))
return;
Expand Down Expand Up @@ -78,18 +85,12 @@ void AParkourSpectator::BeginAutoCam()
TargetRandomPlayer();
}

bool AParkourSpectator::StartGame_Validate(TSubclassOf<AMiniGameBase> GameClass)
{
return true;
}

void AParkourSpectator::StartGame_Implementation(TSubclassOf<AMiniGameBase> GameClass)
void AParkourSpectator::StartGame(TSubclassOf<AMiniGameBase> GameClass)
{
AMiniGameManager* Mgr = FSingletonHelper::Static_GetSingletonObject<AMiniGameManager>(GetWorld());

if (!Mgr) return;
AParkourPlayerController* Controller = Cast<AParkourPlayerController>(GetController());

Mgr->CreateGame(GameClass);
if (Controller)
Controller->StartGame(GameClass);
}

void AParkourSpectator::OpenControls()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AParkourSpectator : public ASpectatorPawn
UFUNCTION(BlueprintCallable, Category = "ParkourSpectator")
void BeginAutoCam();

UFUNCTION(BlueprintCallable, Category = "ParkourSpectator", Server, Unreliable, WithValidation)
UFUNCTION(BlueprintCallable, Category = "ParkourSpectator")
void StartGame(TSubclassOf<AMiniGameBase> GameClass);

void OpenControls();
Expand Down
4 changes: 2 additions & 2 deletions ParkourGame/Source/ParkourGame/Private/Utils/GameVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "GameVersion.generated.h"

#define GAME_VERSION_MAJOR 0
#define GAME_VERSION_MINOR 6
#define GAME_VERSION_PATCH 0
#define GAME_VERSION_MINOR 7
#define GAME_VERSION_PATCH 1

USTRUCT(BlueprintType)
struct FGameVersion
Expand Down

0 comments on commit ef3191a

Please sign in to comment.