Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/PushkinStudio/PsWebServer
Civet web server integration plugin for Unreal Engine 4
https://github.com/PushkinStudio/PsWebServer
civet civetweb cpp mit-license network ue4 ue4-plugin unreal-engine unreal-engine-4 webserver
Last synced: about 1 month ago
JSON representation
Civet web server integration plugin for Unreal Engine 4
- Host: GitHub
- URL: https://github.com/PushkinStudio/PsWebServer
- Owner: PushkinStudio
- License: mit
- Created: 2019-02-05T05:35:09.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-20T13:54:11.000Z (almost 2 years ago)
- Last Synced: 2024-08-02T16:30:48.726Z (4 months ago)
- Topics: civet, civetweb, cpp, mit-license, network, ue4, ue4-plugin, unreal-engine, unreal-engine-4, webserver
- Language: C
- Size: 466 KB
- Stars: 32
- Watchers: 15
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-unreal - PsWebServer - Civet web server integration plugin for Unreal Engine 4 (Plugin)
README
# PsWebServer
Civet web server integration plugin for Unreal Engine 4
# HowTo
Web server usage (f.e. in AMyGameMode::BeginPlay()))
```cpp
// Launch web server
WebServer = NewObject(this);
WebServer->StartServer();// Create and register api handler
auto PingHandler = NewObject(this);
PingHandler->SetHeader(TEXT("Server"), TEXT("MyServer/") + MyGI->GetGameVersion()); // Optional header set
WebServer->AddHandler(PingHandler, TEXT("/api/ping"));
```If uses `UMyServerPingHandler` class that defined as:
```cpp
#pragma once#include "PsWebServerHandler.h"
#include "MyServerPingHandler.generated.h"
UCLASS()
class UMyServerPingHandler : public UPsWebServerHandler
{
GENERATED_BODY()public:
/** Override to implement your custom logic of request processing */
virtual void ProcessRequest_Implementation(const FGuid& RequestUniqueId, const FString& RequestData) override;
};```
And its definition:
```cpp
#include "MyServerPingHandler.h"#include "PsWebServerDefines.h"
#include "VaRestJsonObject.h"/*
* Check that request has valid json encoded body and return its copy in response
*/
void UMyServerPingHandler::ProcessRequest_Implementation(const FGuid& RequestUniqueId, const FString& RequestData)
{
// Validate json format with VaRest
UVaRestJsonObject* JsonTemp = UVaRestJsonObject::ConstructJsonObject(this);
if (JsonTemp->DecodeJson(RequestData))
{
ProcessRequestFinish(RequestUniqueId, FString::Printf(TEXT("{\"request_data\":%s}"), *RequestData));
return;
}UE_LOG(LogMyGame, Error, TEXT("%s: can't validate data as json one: %s"), *PS_FUNC_LINE, *RequestData);
const FString ErrorStr = TEXT(R"({"error":"1000","message":"Request data is not a valid json object"})");
ProcessRequestFinish(RequestUniqueId, ErrorStr);
}
```