Network total reforge. Team-List and Race-Data handled
This commit is contained in:
18
Source/DTFluxNetwork/Public/Clients/DTFluxHttpClient.h
Normal file
18
Source/DTFluxNetwork/Public/Clients/DTFluxHttpClient.h
Normal file
@ -0,0 +1,18 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "HttpModule.h"
|
||||
#include "Interfaces/IHttpRequest.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class DTFLUXNETWORK_API FDTFluxHttpClient: public TSharedFromThis<FDTFluxHttpClient>
|
||||
{
|
||||
public:
|
||||
FDTFluxHttpClient();
|
||||
~FDTFluxHttpClient();
|
||||
};
|
||||
188
Source/DTFluxNetwork/Public/Clients/DTFluxWebSocketClient.h
Normal file
188
Source/DTFluxNetwork/Public/Clients/DTFluxWebSocketClient.h
Normal file
@ -0,0 +1,188 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "IWebSocket.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "Utils/HttpStatusCode.h"
|
||||
#include "Utils/WebSocketStatusCode.h"
|
||||
#include "DTFluxWebSocketClient.generated.h"
|
||||
|
||||
|
||||
USTRUCT()
|
||||
struct FDTFluxWsClientError
|
||||
{
|
||||
GENERATED_BODY()
|
||||
FDTFluxWsClientError()
|
||||
:ClientId(FName("-1")),Reason(FString()), When(FDateTime::Now())
|
||||
{};
|
||||
FDTFluxWsClientError(const FName InName, EDTFluxProtocolError InCode = EDTFluxProtocolError::UnknownError ,
|
||||
FString InReason = FString(""))
|
||||
:ClientId(InName), Code(InCode), Reason(InReason), When(FDateTime::Now()){};
|
||||
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintInternalUseOnly)
|
||||
FName ClientId;
|
||||
|
||||
UPROPERTY()
|
||||
EDTFluxProtocolError Code = EDTFluxProtocolError::NoErrors;
|
||||
|
||||
UPROPERTY()
|
||||
FString Reason;
|
||||
|
||||
UPROPERTY()
|
||||
FDateTime When;
|
||||
|
||||
static FDTFluxWsClientError CreateNoError(FName InClientId)
|
||||
{
|
||||
return FDTFluxWsClientError(InClientId);
|
||||
|
||||
};
|
||||
static FDTFluxWsClientError CreateUnknownError(FName InClientId)
|
||||
{
|
||||
return FDTFluxWsClientError(InClientId, EDTFluxProtocolError::UnknownError);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
class DTFLUXNETWORK_API FDTFluxWebSocketClient : public TSharedFromThis<FDTFluxWebSocketClient>
|
||||
{
|
||||
public:
|
||||
|
||||
FDTFluxWebSocketClient();
|
||||
|
||||
static TSharedPtr<FDTFluxWebSocketClient> GetClient(const TArray<TSharedPtr<FDTFluxWebSocketClient>> InClients, const FName InName)
|
||||
{
|
||||
for(auto Client: InClients)
|
||||
{
|
||||
if(Client->ClientId == InName)
|
||||
{
|
||||
return Client;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Connect();
|
||||
void Reconnect();
|
||||
void Disconnect();
|
||||
FDTFluxWsClientError GetError();
|
||||
void ClearErrors();
|
||||
void AddError(const FDTFluxWsClientError Error);
|
||||
void Send(const FString& Message) const;
|
||||
void SetAddress(FString NewAddress)
|
||||
{
|
||||
WsAddress = NewAddress;
|
||||
}
|
||||
FString GetAddress()
|
||||
{
|
||||
return WsAddress;
|
||||
}
|
||||
|
||||
|
||||
DECLARE_EVENT(FDTFluxWebSocketClient, FWebSocketConnectedEvent);
|
||||
FWebSocketConnectedEvent DTFluxWsClientConnectedEvent;
|
||||
FWebSocketConnectedEvent& RegisterConnectedEvent()
|
||||
{
|
||||
return DTFluxWsClientConnectedEvent;
|
||||
}
|
||||
FWebSocketConnectedEvent& UnregisterConnectedEvent()
|
||||
{
|
||||
return DTFluxWsClientConnectedEvent;
|
||||
}
|
||||
|
||||
DECLARE_EVENT_OneParam(FDTFluxWebSocketClient, FDTFluxWsClientConnectionErrorEvent, const FString& /* Error */);
|
||||
FDTFluxWsClientConnectionErrorEvent DTFluxWsClientConnectionErrorEvent;
|
||||
FDTFluxWsClientConnectionErrorEvent& RegisterConnectionError()
|
||||
{
|
||||
return DTFluxWsClientConnectionErrorEvent;
|
||||
};
|
||||
FDTFluxWsClientConnectionErrorEvent& UnregisterConnectionError()
|
||||
{
|
||||
return DTFluxWsClientConnectionErrorEvent;
|
||||
};
|
||||
|
||||
DECLARE_EVENT_ThreeParams(FDTFluxWebSocketClient, FDTFluxWsClientClosedEvent, int32 /* StatusCode */, const FString& /* Reason */, bool /* bWasClean */);
|
||||
FDTFluxWsClientClosedEvent DTFluxWsClientClosedEvent;
|
||||
FDTFluxWsClientClosedEvent& RegisterClosedEvent()
|
||||
{
|
||||
return DTFluxWsClientClosedEvent;
|
||||
}
|
||||
FDTFluxWsClientClosedEvent& UnregisterClosedEvent()
|
||||
{
|
||||
return DTFluxWsClientClosedEvent;
|
||||
}
|
||||
|
||||
DECLARE_EVENT_OneParam(FDTFluxWebSocketClient, FDTFluxWsClientMessageEvent, const FString& /* MessageString */);
|
||||
FDTFluxWsClientMessageEvent DTFluxWsClientMessageEvent;
|
||||
FDTFluxWsClientMessageEvent& RegisterMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientMessageEvent;
|
||||
};
|
||||
FDTFluxWsClientMessageEvent& UnregisterMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientMessageEvent;
|
||||
};
|
||||
|
||||
DECLARE_EVENT_ThreeParams(FDTFluxWebSocketClient, FDTFluxWsClientBinaryMessageEvent, const void* /* Data */, SIZE_T /* Size */, bool /* bIsLastFragment */);
|
||||
FDTFluxWsClientBinaryMessageEvent DTFluxWsClientBinaryMessageEvent;
|
||||
FDTFluxWsClientBinaryMessageEvent& RegisterBinaryMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientBinaryMessageEvent;
|
||||
};
|
||||
FDTFluxWsClientBinaryMessageEvent& UnregisterBinaryMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientBinaryMessageEvent;
|
||||
};
|
||||
|
||||
DECLARE_EVENT_ThreeParams(FDTFluxWebSocketClient, FDTFluxWsClientRawMessageEvent, const void* /* Data */, SIZE_T /* Size */, SIZE_T /* BytesRemaining */);
|
||||
FDTFluxWsClientRawMessageEvent DTFluxWsClientRawMessageEvent;
|
||||
FDTFluxWsClientRawMessageEvent& RegisterRawMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientRawMessageEvent;
|
||||
};
|
||||
FDTFluxWsClientRawMessageEvent& UnregisterRawMessageEvent()
|
||||
{
|
||||
return DTFluxWsClientRawMessageEvent;
|
||||
};
|
||||
|
||||
DECLARE_EVENT_OneParam(FDTFluxWebSocketClient, FDTFluxWsClientMessageSentEvent, const FString& /* MessageString */);
|
||||
FDTFluxWsClientMessageSentEvent DTFluxWsClientMessageSentEvent;
|
||||
FDTFluxWsClientMessageSentEvent& RegisterMessageSentEvent()
|
||||
{
|
||||
return DTFluxWsClientMessageSentEvent;
|
||||
};
|
||||
FDTFluxWsClientMessageSentEvent& UnregisterMessageSentEvent()
|
||||
{
|
||||
return DTFluxWsClientMessageSentEvent;
|
||||
};
|
||||
|
||||
const FName GetClientId()
|
||||
{
|
||||
return ClientId;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
void Bind_Internal();
|
||||
void OnConnected_Internal();
|
||||
void OnClientClosed_Internal(int32 StatusCode, const FString& Reason, bool bWasClea);
|
||||
void OnClientError_Internal(const FString& ErrorMessage);
|
||||
void OnClientReceiveMessage_Internal(const FString& Message);
|
||||
void OnClientReceiveBinaryMessage_Internal(const void* Data, SIZE_T Size, bool bIsLastFragment);
|
||||
void OnClientReceiveRawMessage_Internal(const void* Data, SIZE_T Size, SIZE_T BytesRemaining);
|
||||
void OnMessageSent_Internal(const FString& MessageString);
|
||||
void SendMessage_internal(const FString& Message);
|
||||
// void SendBin_internal(void* Data);
|
||||
|
||||
TSharedPtr<IWebSocket> Ws;
|
||||
TArray<FDTFluxWsClientError> Errors;
|
||||
static int32 LastId;
|
||||
FName ClientId;
|
||||
FString WsAddress;
|
||||
static FName DefaultId;
|
||||
};
|
||||
|
||||
|
||||
25
Source/DTFluxNetwork/Public/DTFluxNetworkModule.h
Normal file
25
Source/DTFluxNetwork/Public/DTFluxNetworkModule.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
/**
|
||||
* @module DTFluxNetworkModule
|
||||
* @details DTFlux Project is a framework to integrate all kind of events data from
|
||||
* multiple API (stopwatch servers, etc...) or manually to unreal motion design platform
|
||||
* to create live audiovisual shows.
|
||||
* @brief This module provides all necessary basic class to set up your communication
|
||||
* between an external APIs and unreal engine.
|
||||
* @license See LICENSE.TXT at the of DTFluxAPI plugin folder or at
|
||||
* @see https://github.com/A2MSystemes/DTFluxAPI/blob/main/LICENSE
|
||||
* @author Ange-Marie MAURIN
|
||||
*/
|
||||
|
||||
DTFLUXNETWORK_API DECLARE_LOG_CATEGORY_EXTERN(logDTFluxNetwork, Log, All);
|
||||
|
||||
class FDTFluxNetworkModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
@ -0,0 +1,32 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxArchSelectServerResponse.generated.h"
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FDTFluxArchSelectResponseItem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "arch-select";
|
||||
UPROPERTY()
|
||||
int ContestId;
|
||||
UPROPERTY()
|
||||
int StageId;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxArchSelectResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
FString Type = "arch-select";
|
||||
UPROPERTY()
|
||||
TArray<FDTFluxArchSelectResponseItem> Datas;
|
||||
};
|
||||
@ -0,0 +1,93 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
// #include "DTFluxRaceDataServerResponse.generated.h"
|
||||
#include "DTFluxRaceDataServerResponse.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
* Struct that represent split Json data response from the server
|
||||
* Used to deserialize Split response data
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxSplitResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "split-response-data";
|
||||
UPROPERTY()
|
||||
int Id;
|
||||
UPROPERTY()
|
||||
FString Name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing Stage data response from the server
|
||||
* Used to deserialize Stage response data
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxStageResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "stage-response-data";
|
||||
UPROPERTY()
|
||||
int Id;
|
||||
UPROPERTY()
|
||||
FString Name;
|
||||
UPROPERTY()
|
||||
FString StartTime;
|
||||
UPROPERTY()
|
||||
FString EndTime;
|
||||
UPROPERTY()
|
||||
FString CutOff;
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing Contest data response from the server
|
||||
* Used to deserialize Contest Response
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxContestResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "contest";
|
||||
UPROPERTY()
|
||||
int Id;
|
||||
UPROPERTY()
|
||||
FString Name;
|
||||
UPROPERTY()
|
||||
FDateTime Date;
|
||||
UPROPERTY()
|
||||
TArray<FDTFluxStageResponse> Stages;
|
||||
UPROPERTY()
|
||||
TArray<FDTFluxSplitResponse> Splits;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Struct representing the race data globally
|
||||
* Used to exchange data between the system and the API
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxRaceDataResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
FString Type = "race-datas";
|
||||
UPROPERTY()
|
||||
TArray<FDTFluxContestResponse> Datas;
|
||||
};
|
||||
@ -0,0 +1,62 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Types/Struct/DTFluxRankingStructs.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxRankingServerResponse.generated.h"
|
||||
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxContestRankingResponseItem : public FDTFluxContestRanking
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "team-contest-ranking";
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxContestRankingResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "contest-ranking";
|
||||
UPROPERTY()
|
||||
int ContestID;
|
||||
UPROPERTY()
|
||||
TArray<FDTFluxContestRankingResponseItem> Datas;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxStageRankingResponseItem : public FDTFluxStageRanking
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "team-stage-ranking";
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxStageRankingResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "stage-ranking";
|
||||
UPROPERTY()
|
||||
int ContestID;
|
||||
UPROPERTY()
|
||||
int StageID;
|
||||
UPROPERTY()
|
||||
int SplitID = -1;
|
||||
UPROPERTY()
|
||||
// ReSharper disable once IdentifierTypo
|
||||
TArray<FDTFluxStageRankingResponseItem> Datas;
|
||||
};
|
||||
133
Source/DTFluxNetwork/Public/Struct/DTFluxRequestStructs.h
Normal file
133
Source/DTFluxNetwork/Public/Struct/DTFluxRequestStructs.h
Normal file
@ -0,0 +1,133 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxRequestStructs.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
* Struct representing a base json object request to the server
|
||||
* Used to request data to the server
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxRequestBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Path = "";
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing a RaceData json object request to the server
|
||||
* RaceData represents all data concerning the Race and its different Contests, Stages and Splits.
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxRaceDataRequest: public FDTFluxRequestBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
FDTFluxRaceDataRequest(){
|
||||
Path = "race-datas";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing a TeamList json object request to the server
|
||||
* TeamList is the list of participants of the events
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxTeamListRequest: public FDTFluxRequestBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
FDTFluxTeamListRequest(){
|
||||
Path = "team-list";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing a Ranking json request object for a specific to the server
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxContestRankingRequest: public FDTFluxRequestBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FDTFluxContestRankingRequest()
|
||||
{
|
||||
Path = "contest-ranking";
|
||||
ContestID = -1;
|
||||
}
|
||||
FDTFluxContestRankingRequest(int InContestID)
|
||||
{
|
||||
Path = "contest-ranking";
|
||||
ContestID = InContestID;
|
||||
}
|
||||
|
||||
UPROPERTY()
|
||||
int ContestID;
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing a Ranking json request object for a specific Stage to the server
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxStageRankingRequest: public FDTFluxRequestBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FDTFluxStageRankingRequest()
|
||||
{
|
||||
Path = "stage-ranking";
|
||||
ContestID = -1;
|
||||
StageID = -1;
|
||||
SplitID = -1;
|
||||
}
|
||||
FDTFluxStageRankingRequest(int InContestID, int InStageId)
|
||||
{
|
||||
Path = "stage-ranking";
|
||||
ContestID = InContestID;
|
||||
StageID = InStageId;
|
||||
SplitID = -1;
|
||||
}
|
||||
|
||||
UPROPERTY()
|
||||
int ContestID;
|
||||
UPROPERTY()
|
||||
int StageID;
|
||||
UPROPERTY()
|
||||
int SplitID;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Struct representing a Ranking json request object for a specific Split to the server
|
||||
*/
|
||||
USTRUCT()
|
||||
struct FDTFluxSplitRankingRequest: public FDTFluxStageRankingRequest
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FDTFluxSplitRankingRequest()
|
||||
{
|
||||
Path = "stage-ranking";
|
||||
ContestID = -1;
|
||||
StageID = -1;
|
||||
SplitID = -1;
|
||||
}
|
||||
FDTFluxSplitRankingRequest(int InContestID, int InStageId, int InSplitId)
|
||||
{
|
||||
Path = "stage-ranking";
|
||||
ContestID = InContestID;
|
||||
StageID = InStageId;
|
||||
SplitID = InSplitId;
|
||||
}
|
||||
|
||||
};
|
||||
@ -0,0 +1,54 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxServerResponseStruct.generated.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Struct representing a mixed root json server response
|
||||
*/
|
||||
USTRUCT()
|
||||
struct DTFLUXNETWORK_API FDTFluxServerResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "";
|
||||
UPROPERTY()
|
||||
int Code = -1;
|
||||
UPROPERTY()
|
||||
FString Message = "";
|
||||
UPROPERTY()
|
||||
FString Trigger = "";
|
||||
UPROPERTY()
|
||||
int ContestID = -1;
|
||||
UPROPERTY()
|
||||
int StageID = -1;
|
||||
UPROPERTY()
|
||||
int SplitID = -1;
|
||||
UPROPERTY()
|
||||
FDateTime ReceivedAt;
|
||||
UPROPERTY()
|
||||
FString RawMessage;
|
||||
UPROPERTY()
|
||||
FName RequestId = FName("");
|
||||
UPROPERTY()
|
||||
FText FailureReason;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxSplitSensorServerResponse.generated.h"
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxSplitSensorItemResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY()
|
||||
int Bib;
|
||||
UPROPERTY()
|
||||
FString Type = "split-sensor-item";
|
||||
UPROPERTY()
|
||||
int ContestID;
|
||||
UPROPERTY()
|
||||
int StageID;
|
||||
UPROPERTY()
|
||||
int SplitID;
|
||||
UPROPERTY()
|
||||
FString Time = "-";
|
||||
UPROPERTY()
|
||||
FString Gap = "-";
|
||||
UPROPERTY()
|
||||
int Rank;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxSplitSensorResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "split-sensor";
|
||||
UPROPERTY()
|
||||
// ReSharper disable once IdentifierTypo
|
||||
TArray<FDTFluxSplitSensorItemResponse> Datas;
|
||||
};
|
||||
@ -0,0 +1,66 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Types/Struct/DTFluxTeamListStruct.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "DTFluxTeamListServerResponse.generated.h"
|
||||
|
||||
/**
|
||||
* @struct FDTFluxTeamUpdateResponse
|
||||
* Struct representing the Participant List Update Response from the server
|
||||
* Used to exchange an update of a list of participant to the server
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxTeamUpdateResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "team-update";
|
||||
UPROPERTY()
|
||||
int Bib = -1;
|
||||
UPROPERTY()
|
||||
FString Status;
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct FDTFluxTeamListResponse
|
||||
* Struct representing the Participant List Response from the server
|
||||
* Used to exchange data between the system and the API
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxTeamListResponse : public FDTFluxTeamListDefinition
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "team-list";
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxStatusTeamUpdateResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
FString Type = "status-team-update";
|
||||
UPROPERTY()
|
||||
int Bib;
|
||||
UPROPERTY()
|
||||
int Status;
|
||||
};
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct DTFLUXNETWORK_API FDTFluxStatusUpdateResponse
|
||||
{
|
||||
GENERATED_BODY()
|
||||
UPROPERTY()
|
||||
FString Type = "status-update";
|
||||
UPROPERTY()
|
||||
// ReSharper disable once IdentifierTypo
|
||||
FDTFluxStatusTeamUpdateResponse Datas;
|
||||
|
||||
};
|
||||
110
Source/DTFluxNetwork/Public/Subsystems/DTFluxNetworkSubsystem.h
Normal file
110
Source/DTFluxNetwork/Public/Subsystems/DTFluxNetworkSubsystem.h
Normal file
@ -0,0 +1,110 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Struct/DTFluxServerResponseStruct.h"
|
||||
#include "Subsystems/EngineSubsystem.h"
|
||||
#include "Types/DTFluxNetworkSettingsTypes.h"
|
||||
#include "Types/Enum/DTfluxCoreEnum.h"
|
||||
#include "DTFluxNetworkSubsystem.generated.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class FDTFluxWebSocketClient;
|
||||
typedef TSharedPtr<FDTFluxWebSocketClient> FDTFluxWebSocketClientSP;
|
||||
class FDTFluxHttpClient;
|
||||
typedef TSharedPtr<FDTFluxHttpClient> FDTFluxHttpClientSP;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Blueprintable)
|
||||
class DTFLUXNETWORK_API UFDTFluxNetworkSubsystem : public UEngineSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
EDTFluxConnectionStatus WsStatus = EDTFluxConnectionStatus::Unset;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWebSocketConnected);
|
||||
UPROPERTY(BlueprintAssignable, Category="DTFlux|Network")
|
||||
FOnWebSocketConnected OnWebSocketConnected;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnRaceDataReceived, const FDTFluxRaceData&, RaceDataDefinition);
|
||||
FOnRaceDataReceived OnRaceDataReceived;
|
||||
FOnRaceDataReceived& OnReceivedRaceData()
|
||||
{
|
||||
return OnRaceDataReceived;
|
||||
};
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTeamListReceived, const FDTFluxTeamListDefinition&, TeamListDefinition);
|
||||
FOnTeamListReceived OnTeamListReceived;
|
||||
FOnTeamListReceived& OnReceivedTeamList()
|
||||
{
|
||||
return OnTeamListReceived;
|
||||
};
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Network")
|
||||
void Connect();
|
||||
//
|
||||
// UFUNCTION(BlueprintCallable, Category="DTFlux|Network")
|
||||
// void Reconnect();
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Core Subsystem")
|
||||
void SendRequest(const EDTFluxRequestType RequestType, int InContestId = -1, int InStageId = -1, int InSplitId = -1);
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="DTFlux|Network")
|
||||
void SendMessage(const FString& Message);
|
||||
|
||||
protected:
|
||||
// ~Subsystem Interface
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
virtual void Deinitialize() override;
|
||||
// ~Subsystem Interface
|
||||
|
||||
|
||||
private:
|
||||
FDTFluxWsSettings WsSettings;
|
||||
FDTFluxHttpSettings HttpSettings;
|
||||
|
||||
UFUNCTION()
|
||||
void WsSettingsChanged(const FDTFluxWsSettings& NewWsSettings);
|
||||
UFUNCTION()
|
||||
void HttpSettingsChanged(const FDTFluxHttpSettings& NewHttpSettings);
|
||||
void ReconnectWs(const FName WsClientId);
|
||||
void ReconnectHttp(const FName WsClientId);
|
||||
|
||||
void RegisterWebSocketEvents();
|
||||
void RegisterHttpEvents();
|
||||
void UnregisterWebSocketEvents();
|
||||
void UnregisterHttpEvents();
|
||||
|
||||
void OnWebSocketConnected_Subsystem();
|
||||
void OnWebSocketConnectionError_Subsystem(const FString& Error);
|
||||
void OnWebSocketClosedEvent_Subsystem(int32 StatusCode , const FString& Reason, bool bWasClean);
|
||||
void OnWebSocketMessageEvent_Subsystem(const FString& MessageString);
|
||||
void OnWebSocketMessageSentEvent_Subsystem(const FString& MessageSent);
|
||||
|
||||
// TODO : Allow multiple instances of network clients.
|
||||
// // For Future use of Multi-Connections
|
||||
// TArray<FDTFluxWebSocketClientSP> WsClients;
|
||||
// // For Future use of Multi-Connections
|
||||
// TArray<FDTFluxHttpClientSP> HttpClient;
|
||||
// Fo now we jest stick to only one client for each protocol
|
||||
|
||||
FDelegateHandle OnWsConnectedEventDelegateHandle;
|
||||
FDelegateHandle OnWsConnectionErrorEventDelegateHandle;
|
||||
FDelegateHandle OnWsClosedEventDelegateHandle;
|
||||
FDelegateHandle OnWsMessageEventDelegateHandle;
|
||||
FDelegateHandle OnWsMessageSentEventDelegateHandle;
|
||||
|
||||
FDTFluxWebSocketClientSP WsClient = nullptr;
|
||||
FDTFluxHttpClientSP HttpClient = nullptr;
|
||||
|
||||
|
||||
static FString ConstructWsAddress(const FString& Address, const FString& Path, const int& Port);
|
||||
};
|
||||
131
Source/DTFluxNetwork/Public/Utils/HttpStatusCode.h
Normal file
131
Source/DTFluxNetwork/Public/Utils/HttpStatusCode.h
Normal file
@ -0,0 +1,131 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "HttpStatusCode.generated.h"
|
||||
|
||||
UENUM()
|
||||
enum class EHttpResponseCode: int32
|
||||
{
|
||||
// status code not set yet
|
||||
Unknown = 0 UMETA(DisplayName="Unknown"),
|
||||
|
||||
// the request can be continued.
|
||||
Continue = 100 UMETA(DisplayName="Continue"),
|
||||
|
||||
// the server has switched protocols in an upgrade header.
|
||||
SwitchProtocol = 101 UMETA(DisplayName="Switching Protocols"),
|
||||
|
||||
// the request completed successfully.
|
||||
Ok = 200 UMETA(DisplayName="OK"),
|
||||
|
||||
// the request has been fulfilled and resulted in the creation of a new resource.
|
||||
Created = 201 UMETA(DisplayName="Created"),
|
||||
|
||||
// the request has been accepted for processing, but the processing has not been completed.
|
||||
Accepted = 202 UMETA(DisplayName="Accepted"),
|
||||
|
||||
// the returned meta information in the entity-header is not the definitive set available from the origin server.
|
||||
Partial = 203 UMETA(DisplayName="Non-Authoritative Information"),
|
||||
|
||||
// the server has fulfilled the request, but there is no new information to send back.
|
||||
NoContent = 204 UMETA(DisplayName="No Content"),
|
||||
|
||||
// the request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action.
|
||||
ResetContent = 205 UMETA(DisplayName="Reset Content"),
|
||||
|
||||
// the server has fulfilled the partial get request for the resource.
|
||||
PartialContent = 206 UMETA(DisplayName="Partial Content"),
|
||||
|
||||
// the server couldn't decide what to return.
|
||||
Ambiguous = 300 UMETA(DisplayName="Multiple Choices"),
|
||||
|
||||
// the requested resource has been assigned to a new permanent uri (uniform resource identifier), and any future references to this resource should be done using one of the returned uris.
|
||||
Moved = 301 UMETA(DisplayName="Moved Permanently"),
|
||||
|
||||
// the requested resource resides temporarily under a different uri (uniform resource identifier).
|
||||
Redirect = 302 UMETA(DisplayName="Found"),
|
||||
|
||||
// the response to the request can be found under a different uri (uniform resource identifier) and should be retrieved using a get http verb on that resource.
|
||||
RedirectMethod = 303 UMETA(DisplayName="See Other"),
|
||||
|
||||
// the requested resource has not been modified.
|
||||
NotModified = 304 UMETA(DisplayName="Not Modified"),
|
||||
|
||||
// the requested resource must be accessed through the proxy given by the location field.
|
||||
UseProxy = 305 UMETA(DisplayName="Use Proxy"),
|
||||
|
||||
// the redirected request keeps the same http verb. http/1.1 behavior.
|
||||
RedirectKeepVerb = 307 UMETA(DisplayName="Temporary Redirect"),
|
||||
|
||||
// the request could not be processed by the server due to invalid syntax.
|
||||
BadRequest = 400 UMETA(DisplayName="Bad Request"),
|
||||
|
||||
// the requested resource requires user authentication.
|
||||
Denied = 401 UMETA(DisplayName="Unauthorized"),
|
||||
|
||||
// not currently implemented in the http protocol.
|
||||
PaymentReq = 402 UMETA(DisplayName="Payment Required"),
|
||||
|
||||
// the server understood the request, but is refusing to fulfill it.
|
||||
Forbidden = 403 UMETA(DisplayName="Forbidden"),
|
||||
|
||||
// the server has not found anything matching the requested uri (uniform resource identifier).
|
||||
NotFound = 404 UMETA(DisplayName="Not Found"),
|
||||
|
||||
// the http verb used is not allowed.
|
||||
BadMethod = 405 UMETA(DisplayName="Method Not Allowed"),
|
||||
|
||||
// no responses acceptable to the client were found.
|
||||
NoneAcceptable = 406 UMETA(DisplayName="Not Acceptable"),
|
||||
|
||||
// proxy authentication required.
|
||||
ProxyAuthReq = 407 UMETA(DisplayName="Proxy Authentication Required"),
|
||||
|
||||
// the server timed out waiting for the request.
|
||||
RequestTimeout = 408 UMETA(DisplayName="Request Timeout"),
|
||||
|
||||
// the request could not be completed due to a conflict with the current state of the resource. the user should resubmit with more information.
|
||||
Conflict = 409 UMETA(DisplayName="Conflict"),
|
||||
|
||||
// the requested resource is no longer available at the server, and no forwarding address is known.
|
||||
Gone = 410 UMETA(DisplayName="Gone"),
|
||||
|
||||
// the server refuses to accept the request without a defined content length.
|
||||
LengthRequired = 411 UMETA(DisplayName="Length Required"),
|
||||
|
||||
// the precondition given in one or more of the request header fields evaluated to false when it was tested on the server.
|
||||
PrecondFailed = 412 UMETA(DisplayName="Precondition Failed"),
|
||||
|
||||
// the server is refusing to process a request because the request entity is larger than the server is willing or able to process.
|
||||
RequestTooLarge = 413 UMETA(DisplayName="Payload Too Large"),
|
||||
|
||||
// the server is refusing to service the request because the request uri (uniform resource identifier) is longer than the server is willing to interpret.
|
||||
UriTooLong = 414 UMETA(DisplayName="URI Too Long"),
|
||||
|
||||
// the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
|
||||
UnsupportedMedia = 415 UMETA(DisplayName="Unsupported Media Type"),
|
||||
|
||||
// too many requests, the server is throttling
|
||||
TooManyRequests = 429 UMETA(DisplayName="Too Many Requests"),
|
||||
|
||||
// the request should be retried after doing the appropriate action.
|
||||
RetryWith = 449 UMETA(DisplayName="Retry With"),
|
||||
|
||||
// the server encountered an unexpected condition that prevented it from fulfilling the request.
|
||||
ServerError = 500 UMETA(DisplayName="Internal Server Error"),
|
||||
|
||||
// the server does not support the functionality required to fulfill the request.
|
||||
NotSupported = 501 UMETA(DisplayName="Not Implemented"),
|
||||
|
||||
// the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.
|
||||
BadGateway = 502 UMETA(DisplayName="Bad Gateway"),
|
||||
|
||||
// the service is temporarily overloaded.
|
||||
ServiceUnavailable = 503 UMETA(DisplayName="Service Unavailable"),
|
||||
|
||||
// the request was timed out waiting for a gateway.
|
||||
GatewayTimeout = 504 UMETA(DisplayName="Gateway Timeout"),
|
||||
|
||||
// the server does not support, or refuses to support, the http protocol version that was used in the request message.
|
||||
VersionNotSup = 505 UMETA(DisplayName="HTTP Version Not Supported")
|
||||
};
|
||||
72
Source/DTFluxNetwork/Public/Utils/WebSocketStatusCode.h
Normal file
72
Source/DTFluxNetwork/Public/Utils/WebSocketStatusCode.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
UENUM()
|
||||
enum class EWebSocketCloseCode : int32
|
||||
{
|
||||
// No Error
|
||||
NoError = 0 UMETA(DisplayName="No Errors"),
|
||||
|
||||
// Normal Closure.
|
||||
Normal = 1000 UMETA(DisplayName="Normal Closure"),
|
||||
|
||||
// The endpoint is going away, either because of a server shutdown or because the browser is navigating away from the page that opened the connection.
|
||||
GoingAway = 1001 UMETA(DisplayName="Going Away"),
|
||||
|
||||
// A protocol error occurred.
|
||||
ProtocolError = 1002 UMETA(DisplayName="Protocol Error"),
|
||||
|
||||
// Unsupported data type received.
|
||||
UnsupportedData = 1003 UMETA(DisplayName="Unsupported Data"),
|
||||
|
||||
// Reserved for future use.
|
||||
Reserved = 1004 UMETA(DisplayName="Reserved"),
|
||||
|
||||
// Indicates no status code was provided (must not be sent over the wire).
|
||||
NoStatus = 1005 UMETA(DisplayName="No Status Received"),
|
||||
|
||||
// Connection closed abnormally without receiving a close code.
|
||||
Abnormal = 1006 UMETA(DisplayName="Abnormal Closure"),
|
||||
|
||||
// Invalid frame payload data (e.g., invalid UTF-8 text).
|
||||
InvalidPayload = 1007 UMETA(DisplayName="Invalid Frame Payload Data"),
|
||||
|
||||
// Message violates policy; rejected.
|
||||
PolicyViolation = 1008 UMETA(DisplayName="Policy Violation"),
|
||||
|
||||
// Message too big for processing.
|
||||
MessageTooBig = 1009 UMETA(DisplayName="Message Too Big"),
|
||||
|
||||
// Mandatory extension not supported by server.
|
||||
MandatoryExtension = 1010 UMETA(DisplayName="Mandatory Extension"),
|
||||
|
||||
// Internal server error while processing the connection.
|
||||
InternalServerError = 1011 UMETA(DisplayName="Internal Server Error"),
|
||||
|
||||
// Reserved for future use.
|
||||
ServiceRestart = 1012 UMETA(DisplayName="Service Restart"),
|
||||
|
||||
// Try again later.
|
||||
TryAgainLater = 1013 UMETA(DisplayName="Try Again Later"),
|
||||
|
||||
// TLS handshake failure.
|
||||
TlsHandshake = 1015 UMETA(DisplayName="TLS Handshake")
|
||||
};
|
||||
|
||||
/**
|
||||
* EDTFluxProtocolError
|
||||
* @brief Enum designed for Protocol link errors
|
||||
* @author Ange-Marie MAURIN
|
||||
*/
|
||||
UENUM()
|
||||
enum class EDTFluxProtocolError : uint8
|
||||
{
|
||||
NoErrors = 0,
|
||||
UnknownError = 1,
|
||||
ConnectionError = 2,
|
||||
MaxConnectionsError = 3,
|
||||
TimoutError=4,
|
||||
SerializationError = 5,
|
||||
DeserializationError=6
|
||||
};
|
||||
Reference in New Issue
Block a user