yichael 4 anos atrás
pai
commit
6470f5888f

+ 79 - 0
Source/Communication_Org/Private/HttpReqActor.cpp

@@ -0,0 +1,79 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+
+#include "HttpReqActor.h"
+
+// Sets default values
+UHttpReqActor::UHttpReqActor()
+{
+ 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
+}
+
+// Called when the game starts or when spawned
+void UHttpReqActor::BeginPlay()
+{
+	Super::BeginPlay();
+	
+}
+
+/*Http call*/
+bool UHttpReqActor::Post(FString URL,FString ContentString)
+{
+	//TSharedRef<IHttpRequest> Request = Http->CreateRequest();
+	//Request->OnProcessRequestComplete().BindUObject(this, &UHttpReqActor::OnResponseReceived);
+	////This is the url on which to process the request
+	//Request->SetURL(URL);
+	//Request->SetVerb("POST");
+	//Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
+	//Request->SetContentAsString(ContentString);
+	//Request->SetHeader("Content-Type", "text/javascript;charset=utf-8");
+	//Request->ProcessRequest();
+
+	//UE_LOG(LogTemp, Log, TEXT("aaaaaaaaaaaaaa======%s"));
+
+	// 创建Http 请求
+	TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
+	// 设置请求头
+	Request->SetHeader("Content-Type", "text/javascript;charset=utf-8");
+	// 设置请求方式
+	Request->SetVerb("POST");
+	// 请求的链接
+	Request->SetURL(URL); // 服务端预留的测试接口
+	// 内容包
+	Request->SetContentAsString(ContentString);
+	// 设置回调函数
+	Request->OnProcessRequestComplete().BindUObject(this, &UHttpReqActor::OnResponseReceived);
+	// 发送请求
+	Request->ProcessRequest();
+
+	return 0;
+}
+
+/*Assigned function on successfull http call*/
+void UHttpReqActor::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
+{
+	//GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, Response->GetContentAsString());
+	//UE_LOG(LogTemp, Log, TEXT("FHttpResponsePtr======%s"), *Response->GetContentAsString());
+	////Create a pointer to hold the json serialized data
+	//TSharedPtr<FJsonObject> JsonObject;
+
+	////Create a reader pointer to read the json data
+	//TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
+
+	////Deserialize the json data given Reader and the actual object to deserialize
+	//if (FJsonSerializer::Deserialize(Reader, JsonObject))
+	//{
+	//	TSharedPtr<FJsonObject> recievedObject = JsonObject->GetObjectField("Exam");
+	//	//Get the value of the json object by field name
+	//	FString recievedStr = recievedObject->GetStringField("ScoreStep");
+
+	//	//Output it to the engine
+	//	GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, recievedStr);
+
+		if (OnPostResponseReceived.IsBound())//检查是否存在有效绑定
+		{
+			OnPostResponseReceived.Broadcast(Response->GetContentAsString());
+		}
+	//}
+}
+

Diferenças do arquivo suprimidas por serem muito extensas
+ 48 - 0
Source/Communication_Org/Private/MyBlueprintFunctionLibrary.cpp


+ 5 - 0
Source/Communication_Org/Private/MyGameModeBase.cpp

@@ -0,0 +1,5 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+
+#include "MyGameModeBase.h"
+

+ 38 - 0
Source/Communication_Org/Public/HttpReqActor.h

@@ -0,0 +1,38 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "GameFramework/Actor.h"
+#include "Runtime/Online/HTTP/Public/Http.h"
+#include "HttpReqActor.generated.h"
+
+
+DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FResponseDelegate, FString, Response);
+
+UCLASS(ClassGroup = (HttpReq), meta = (BlueprintSpawnableComponent))
+class COMMUNICATION_ORG_API UHttpReqActor : public UActorComponent
+{
+	GENERATED_BODY()
+	
+public:	
+	// Sets default values for this actor's properties
+	UHttpReqActor();
+
+protected:
+	// Called when the game starts or when spawned
+	virtual void BeginPlay() override;
+
+	UPROPERTY(BlueprintAssignable)
+		FResponseDelegate OnPostResponseReceived;
+
+	FHttpModule* Http;
+
+	/* The actual HTTP call */
+	//UFUNCTION(BlueprintPure, Category = "HttpReq")
+	UFUNCTION(BlueprintCallable, Category = "HttpReq")
+		bool Post(FString URL,FString ContentString);
+
+	/*Assign this function to call when the GET request processes sucessfully*/
+	void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
+};

+ 92 - 0
Source/Communication_Org/Public/MyBlueprintFunctionLibrary.h

@@ -0,0 +1,92 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "Kismet/BlueprintFunctionLibrary.h"
+#include "Dom/JsonObject.h"
+#include "MyBlueprintFunctionLibrary.generated.h"
+//#include <Runtime/Engine/Classes/GameFramework/GameState.h>
+
+
+typedef TSharedPtr<FJsonObject> JsonObjectPtr;
+/**
+ * 
+ */
+UCLASS()
+class COMMUNICATION_ORG_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
+{
+	GENERATED_BODY()
+
+public:	
+	
+	UFUNCTION(BlueprintPure, Category = "UnixTimestamp")
+		static FDateTime UnixTimestampToDateTime(int64 UnixTime);
+
+	UFUNCTION(BlueprintPure, Category = "UnixTimestamp")
+		static int64 DateTimeToUnixTimestamp(FDateTime DateTime);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString GetTempScoresStr(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString CreateExamJson(FString UserID, FString ExamId, FString DataJsonStr);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString ParseExamIdFromCreateExam(FString RawDataJson);
+	
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString GetExamUsingId(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString GetScoresStr(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static TArray<int32> GetScores(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static int64 GetStartTimestamp(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString ParseAndGetScores(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static int32 GetScore(FString RawDataJson, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString SetScoreJson(FString RawDataJson, FString ExamId, FString UserID, int32 Score, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString SetOtherScoreJson(FString UserID, FString ExamId, FString ScoresStr, TArray<int32> Scores);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FDateTime GetStartTime(FString RawDataJson, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FDateTime GetExpectTime(FString RawDataJson, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static bool IsOverTime(FString RawDataJson, int32 ScoreIndex);
+
+	
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString SetStartTimeJson(FString ScoresStr, FString ExamId, FString UserID, FDateTime StartTime, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString SetEndTimeJson(FString ScoresStr, FString ExamId, FString UserID, FDateTime EndTime, int32 ScoreIndex);
+
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString SetScoreAndEndTimeJson(FString ScoresStr, FString ExamId, FString UserID, FDateTime EndTime, int32 Score, int32 ScoreIndex);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static bool IsSubmit(FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString GetSubmitJsonString(FString UserID, FString ProjectName, FString RawDataJson);
+
+	UFUNCTION(BlueprintPure, Category = "Json")
+		static FString GetRestartJsonString(FString UserID,FString RawDataJson);
+
+};

+ 17 - 0
Source/Communication_Org/Public/MyGameModeBase.h

@@ -0,0 +1,17 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "GameFramework/GameModeBase.h"
+#include "MyGameModeBase.generated.h"
+
+/**
+ * 
+ */
+UCLASS()
+class COMMUNICATION_ORG_API AMyGameModeBase : public AGameModeBase
+{
+	GENERATED_BODY()
+	
+};

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff