Add GameInstance for Global Session ID

This commit is contained in:
Philip W 2023-11-28 03:36:27 +00:00
parent 61018a044d
commit d34b52f972
12 changed files with 67 additions and 71 deletions

View File

@ -67,7 +67,7 @@ TwoPlayerSplitscreenLayout=Horizontal
ThreePlayerSplitscreenLayout=FavorTop
FourPlayerSplitscreenLayout=Grid
bOffsetPlayerGamepadIds=False
GameInstanceClass=/Script/Engine.GameInstance
GameInstanceClass=/Script/EndlessVendetta.EVGameInstance
GameDefaultMap=/Game/Levels/TrainingFacility.TrainingFacility
ServerDefaultMap=/Engine/Maps/Entry.Entry
GlobalDefaultGameMode=/Script/EndlessVendetta.EndlessVendettaGameMode

Binary file not shown.

View File

@ -9,7 +9,6 @@
#include "Perception/AIPerceptionStimuliSourceComponent.h"
#include "Perception/AISense_Sight.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "../Telemetry.h"
#include <EndlessVendetta/EndlessVendettaGameMode.h>

View File

@ -5,7 +5,6 @@
#include "CoreMinimal.h"
#include "WaypointActor.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/Telemetry.h"
#include "GameFramework/Actor.h"
#include <EndlessVendetta/EndlessVendettaGameMode.h>
#include "CheckpointClass.generated.h"

View File

@ -0,0 +1,32 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "EVGameInstance.h"
void UEVGameInstance::OnStart()
{
Super::OnStart();
GlobalSessionID = FGuid::NewGuid().ToString().Left(5).ToUpper();
IsValidSessionID(GlobalSessionID);
}
void UEVGameInstance::IsValidSessionID(const FString& SessionID)
{
const auto Request = FHttpModule::Get().CreateRequest();
Request->SetURL("https://ev.api.philipwhite.dev/api/session/" + SessionID);
Request->SetVerb("GET");
Request->OnProcessRequestComplete().BindUObject(this, &UEVGameInstance::OnResponseReceived);
Request->ProcessRequest();
}
void UEVGameInstance::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully)
{
if (Response->GetResponseCode() == 200)
{
GLog->Log("Session ID Exists Regenerating");
GlobalSessionID = FGuid::NewGuid().ToString().Left(5).ToUpper();
IsValidSessionID(GlobalSessionID);
return;
}
GLog->Log("Session ID is Valid");
}

View File

@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "Http.h"
#include "EVGameInstance.generated.h"
/**
*
*/
UCLASS()
class ENDLESSVENDETTA_API UEVGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString GlobalSessionID = "AAAAA";
protected:
virtual void OnStart() override;
private:
void IsValidSessionID(const FString& SessionID);
void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bConnectedSuccessfully);
};

View File

@ -7,7 +7,6 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InteractionInterface.h"
#include "Telemetry.h"
#include "AI/EnemyCharacter.h"
#include "Engine/DamageEvents.h"
#include "GameFramework/CharacterMovementComponent.h"

View File

@ -2,6 +2,7 @@
#include "EndlessVendettaGameMode.h"
#include "EndlessVendettaCharacter.h"
#include "EVGameInstance.h"
#include "UObject/ConstructorHelpers.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"
#include "EndlessVendetta/AI/AIControlHub.h"
@ -60,5 +61,5 @@ void AEndlessVendettaGameMode::SendEvent(FString EventKey, FString EventData)
void AEndlessVendettaGameMode::BeginPlay()
{
Super::BeginPlay();
SessionID = FGuid::NewGuid().ToString().Left(5).ToUpper();
SessionID = Cast<UEVGameInstance>(GetGameInstance())->GlobalSessionID;
}

View File

@ -25,7 +25,7 @@ public:
FString TelemetryURLEvents = "https://ev.api.philipwhite.dev/api/event";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString TelemetryURLUsers = "https://ev.api.philipwhite.dev/api/user";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Instanced, Category = "Telemetry")
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString SessionID = "AAAAA";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString PlayerGUID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";

View File

@ -1,28 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Telemetry.h"
#include "Misc/Guid.h"
void ATelemetry::SendEvent(FString EventKey, FString EventData)
{
const FString EventID = FGuid::NewGuid().ToString();
const FString EventTime = FDateTime::Now().ToString();
const auto Request = FHttpModule::Get().CreateRequest();
Request->SetURL(TelemetryURLEvents);
Request->SetVerb("POST");
Request->SetHeader("Content-Type", "application/json");
Request->SetHeader("Accept", "application/json");
Request->SetContentAsString( "{\"SessionID\":\"" + SessionID + "\",\"PlayerGUID\":\"" + PlayerGUID + "\",\"EventID\":\"" + EventID + "\",\"Timestamp\":\"" + EventTime + "\",\"EventKey\":\"" + EventKey + "\",\"EventData\":\"" + EventData + "\"}" );
Request->OnProcessRequestComplete().BindLambda([](FHttpRequestPtr request, FHttpResponsePtr response, bool success)
{
GLog->Log("Telemetry Event Response: " + response->GetContentAsString());
});
Request->ProcessRequest();
}
void ATelemetry::BeginPlay()
{
Super::BeginPlay();
SessionID = FGuid::NewGuid().ToString().Left(5).ToUpper();
}

View File

@ -1,33 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameState.h"
#include "Http.h"
#include "Telemetry.generated.h"
/**
*
*/
UCLASS()
class ENDLESSVENDETTA_API ATelemetry : public AGameState
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString TelemetryURLEvents = "https://ev.api.philipwhite.dev/api/event";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString TelemetryURLUsers = "https://ev.api.philipwhite.dev/api/user";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString SessionID = "AAAAA";
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Telemetry")
FString PlayerGUID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
UFUNCTION(BlueprintCallable, Category = "Telemetry")
void SendEvent(FString EventKey, FString EventData);
protected:
virtual void BeginPlay() override;
};

View File

@ -7,7 +7,6 @@
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "Kismet/KismetMathLibrary.h"
#include "Components/CapsuleComponent.h"
#include "EndlessVendetta/Telemetry.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/DamageEvents.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"