From d34b52f972c50f983cadb6dc7df54b23279e98f1 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Tue, 28 Nov 2023 03:36:27 +0000 Subject: [PATCH] Add GameInstance for Global Session ID --- EndlessVendetta/Config/DefaultEngine.ini | 2 +- .../Content/Levels/TrainingFacility.umap | 4 +-- .../Source/EndlessVendetta/AI/AICharacter.cpp | 1 - .../BountySystem/CheckpointClass.h | 1 - .../Source/EndlessVendetta/EVGameInstance.cpp | 32 ++++++++++++++++++ .../Source/EndlessVendetta/EVGameInstance.h | 28 ++++++++++++++++ .../EndlessVendettaCharacter.cpp | 1 - .../EndlessVendettaGameMode.cpp | 3 +- .../EndlessVendetta/EndlessVendettaGameMode.h | 4 +-- .../Source/EndlessVendetta/Telemetry.cpp | 28 ---------------- .../Source/EndlessVendetta/Telemetry.h | 33 ------------------- .../WeaponSystem/BaseWeaponClass.cpp | 1 - 12 files changed, 67 insertions(+), 71 deletions(-) create mode 100644 EndlessVendetta/Source/EndlessVendetta/EVGameInstance.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/EVGameInstance.h delete mode 100644 EndlessVendetta/Source/EndlessVendetta/Telemetry.cpp delete mode 100644 EndlessVendetta/Source/EndlessVendetta/Telemetry.h diff --git a/EndlessVendetta/Config/DefaultEngine.ini b/EndlessVendetta/Config/DefaultEngine.ini index a3178012..18ee5e14 100644 --- a/EndlessVendetta/Config/DefaultEngine.ini +++ b/EndlessVendetta/Config/DefaultEngine.ini @@ -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 diff --git a/EndlessVendetta/Content/Levels/TrainingFacility.umap b/EndlessVendetta/Content/Levels/TrainingFacility.umap index cbe7aa20..19053416 100644 --- a/EndlessVendetta/Content/Levels/TrainingFacility.umap +++ b/EndlessVendetta/Content/Levels/TrainingFacility.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:87523c2b8607590648fb1ad88b98e94617e34faa25375af04116b01388bdbda2 -size 679514 +oid sha256:9085d76489c04f7d273f580154acee8bbe53b285514f36e2770d3be3e9407730 +size 679662 diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp index c95a5e7e..fb600020 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp @@ -9,7 +9,6 @@ #include "Perception/AIPerceptionStimuliSourceComponent.h" #include "Perception/AISense_Sight.h" #include "BehaviorTree/BlackboardComponent.h" -#include "../Telemetry.h" #include diff --git a/EndlessVendetta/Source/EndlessVendetta/BountySystem/CheckpointClass.h b/EndlessVendetta/Source/EndlessVendetta/BountySystem/CheckpointClass.h index 854d8588..a414a61d 100644 --- a/EndlessVendetta/Source/EndlessVendetta/BountySystem/CheckpointClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/BountySystem/CheckpointClass.h @@ -5,7 +5,6 @@ #include "CoreMinimal.h" #include "WaypointActor.h" #include "EndlessVendetta/EndlessVendettaCharacter.h" -#include "EndlessVendetta/Telemetry.h" #include "GameFramework/Actor.h" #include #include "CheckpointClass.generated.h" diff --git a/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.cpp b/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.cpp new file mode 100644 index 00000000..bdaaddab --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.cpp @@ -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"); +} diff --git a/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.h b/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.h new file mode 100644 index 00000000..ec749839 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/EVGameInstance.h @@ -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); +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 30287f35..04a8f415 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -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" diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.cpp index 9390d136..744fe187 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.cpp @@ -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(GetGameInstance())->GlobalSessionID; } diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.h index a5fb31f5..5d015623 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaGameMode.h @@ -14,7 +14,7 @@ class AEndlessVendettaGameMode : public AGameModeBase public: AEndlessVendettaGameMode(); - + UFUNCTION(Exec, Category = ExecFunctions) void KillAllEnemies(); @@ -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"; diff --git a/EndlessVendetta/Source/EndlessVendetta/Telemetry.cpp b/EndlessVendetta/Source/EndlessVendetta/Telemetry.cpp deleted file mode 100644 index 196fcc0c..00000000 --- a/EndlessVendetta/Source/EndlessVendetta/Telemetry.cpp +++ /dev/null @@ -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(); -} diff --git a/EndlessVendetta/Source/EndlessVendetta/Telemetry.h b/EndlessVendetta/Source/EndlessVendetta/Telemetry.h deleted file mode 100644 index 15cbdc69..00000000 --- a/EndlessVendetta/Source/EndlessVendetta/Telemetry.h +++ /dev/null @@ -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; -}; diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index d5069806..6ebc5b94 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -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"