Lots of crap
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
class FLogCaptureOutputDevice : public FOutputDevice
|
||||
{
|
||||
public:
|
||||
TArray<FString> CapturedErrors;
|
||||
bool bEnabled = true;
|
||||
|
||||
void Install() { GLog->AddOutputDevice(this); }
|
||||
void Uninstall() { GLog->RemoveOutputDevice(this); }
|
||||
|
||||
// If the device is marked 'CanBeUsedOnMultipleThreads,'
|
||||
// then UE_LOG will call Serialize from the current
|
||||
// thread, otherwise, it will call Serialize from the
|
||||
// logging thread. Without this, we wouldn't be able to
|
||||
// tell whether an error is coming from the game thread.
|
||||
virtual bool CanBeUsedOnMultipleThreads() const override { return true; }
|
||||
|
||||
virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category) override
|
||||
{
|
||||
// Only capture messages from the game thread.
|
||||
// Other threads generate noise we don't care about.
|
||||
if (!IsInGameThread() || !bEnabled) return;
|
||||
|
||||
if (Verbosity == ELogVerbosity::Warning ||
|
||||
Verbosity == ELogVerbosity::Error ||
|
||||
Verbosity == ELogVerbosity::Fatal)
|
||||
{
|
||||
CapturedErrors.Add(FString(V));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "MCPProperty.h"
|
||||
#include "MCPUtils.h"
|
||||
|
||||
MCPProperty::MCPProperty(FProperty* InProp, void* Container)
|
||||
: Prop(InProp), ValuePtr(InProp ? InProp->ContainerPtrToValuePtr<void>(Container) : nullptr) {}
|
||||
|
||||
FString MCPProperty::GetText() const
|
||||
{
|
||||
FString Result;
|
||||
Prop->ExportTextItem_Direct(Result, ValuePtr, nullptr, nullptr, PPF_None);
|
||||
return Result;
|
||||
}
|
||||
|
||||
bool MCPProperty::SetText(const FString& Value, MCPErrorCallback Error)
|
||||
{
|
||||
const TCHAR* ImportResult = Prop->ImportText_Direct(*Value, ValuePtr, nullptr, PPF_None);
|
||||
if (!ImportResult)
|
||||
{
|
||||
Error.SetError(FString::Printf(TEXT("Failed to parse '%s' for property '%s' (type: %s)"),
|
||||
*Value, *MCPUtils::FormatName(Prop), *Prop->GetCPPType()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "MCPServer.h"
|
||||
#include "MCPHandler.h"
|
||||
#include "LogCapture.h"
|
||||
#include "MCPUtils.h"
|
||||
#include "MCPAssetFinder.h"
|
||||
#include "UObject/StrongObjectPtr.h"
|
||||
@@ -151,6 +152,8 @@ void UMCPServer::Initialize(FSubsystemCollectionBase& Collection)
|
||||
}
|
||||
|
||||
BuildMCPHandlerRegistry();
|
||||
LogCapture.bEnabled = false;
|
||||
LogCapture.Install();
|
||||
bRunning = true;
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: MCP server listening on tcp://localhost:%d"), Port);
|
||||
}
|
||||
@@ -204,6 +207,7 @@ void UMCPServer::Deinitialize()
|
||||
ListenSocket = nullptr;
|
||||
}
|
||||
|
||||
LogCapture.Uninstall();
|
||||
bRunning = false;
|
||||
bShuttingDown = false;
|
||||
UE_LOG(LogTemp, Display, TEXT("BlueprintMCP: Server stopped."));
|
||||
@@ -294,9 +298,19 @@ FString UMCPServer::HandleRequest(const FString& Line)
|
||||
return PopulateError.ToString();
|
||||
}
|
||||
|
||||
// Invoke the handler.
|
||||
// Invoke the handler with log capture.
|
||||
LogCapture.CapturedErrors.Empty();
|
||||
LogCapture.bEnabled = true;
|
||||
TStringBuilder<32768> TextResult;
|
||||
Handler->Handle(TextResult);
|
||||
LogCapture.bEnabled = false;
|
||||
for (const FString& Msg : LogCapture.CapturedErrors)
|
||||
{
|
||||
TextResult.Append(TEXT("LOG: "));
|
||||
TextResult.Append(Msg);
|
||||
TextResult.Append(TEXT("\n"));
|
||||
}
|
||||
LogCapture.CapturedErrors.Empty();
|
||||
FString Result = TextResult.ToString();
|
||||
for (int32 i = 0; i < Result.Len(); ++i)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user