Players can host or join via Steam or LAN, pick maps, and connect by address; dedicated servers expose an HTTP panel for port and game rules. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
// Copyright VocationLife Project. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Subsystems/GameInstanceSubsystem.h"
|
|
#include "VocationServerSettings.h"
|
|
#include "VocationWebAdminSubsystem.generated.h"
|
|
|
|
class FSocket;
|
|
class FTcpListener;
|
|
class FInternetAddr;
|
|
|
|
/**
|
|
* Lightweight HTTP admin panel for dedicated / headless servers.
|
|
* Default: http://<server-ip>:8080
|
|
*/
|
|
UCLASS()
|
|
class VOCATIONLIFE_API UVocationWebAdminSubsystem : public UGameInstanceSubsystem, public FTickableGameObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
|
virtual void Deinitialize() override;
|
|
|
|
virtual void Tick(float DeltaTime) override;
|
|
virtual TStatId GetStatId() const override;
|
|
virtual bool IsTickable() const override;
|
|
virtual bool IsTickableInEditor() const override { return false; }
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "VocationLife|WebAdmin")
|
|
bool StartAdminServer(int32 Port = 8080);
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "VocationLife|WebAdmin")
|
|
void StopAdminServer();
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "VocationLife|WebAdmin")
|
|
bool IsAdminRunning() const { return bIsRunning; }
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "VocationLife|WebAdmin")
|
|
UVocationServerSettings* GetServerSettings() const { return ServerSettings; }
|
|
|
|
protected:
|
|
void AcceptConnections();
|
|
void HandleClient(FSocket* ClientSocket);
|
|
FString BuildHtmlPage() const;
|
|
FString BuildJsonStatus() const;
|
|
bool ApplyFormBody(const FString& Body, FString& OutMessage);
|
|
static bool ParseHttpRequest(const FString& Raw, FString& OutMethod, FString& OutPath, FString& OutBody);
|
|
static FString UrlDecode(const FString& Encoded);
|
|
|
|
UPROPERTY()
|
|
TObjectPtr<UVocationServerSettings> ServerSettings;
|
|
|
|
TSharedPtr<FSocket> ListenSocket;
|
|
bool bIsRunning = false;
|
|
int32 BoundPort = 8080;
|
|
bool bPendingPortRestartNotice = false;
|
|
};
|