<commit_before>#include "UT4WebAdmin.h"
#include "Base64.h"


#define UT4WA_PLUGIN_FOLDER "UT4WebAdmin"
#define UT4WA_HTML_FOLDER "www"
#define LISTENING_PORT "8080"

int
WelcomeHandler(struct mg_connection *conn, void *cbdata)
{
	mg_printf(conn,
		"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
		"close\r\n\r\n");
	mg_printf(conn, "<html><body>");
	mg_printf(conn, "<h2>Welcome to UT4 Web Admin !</h2>");
	mg_printf(conn, "</body></html>\n");

	return 1;
}

UUT4WebAdmin::UUT4WebAdmin(const FObjectInitializer& ObjectInitializer) 
	: Super(ObjectInitializer)
{
	#if defined(USE_CIVETWEB)
		ctx = nullptr;
	#endif
	GameMode = nullptr;
}


void UUT4WebAdmin::Init()
{

	// Don't garbage collect me
	SetFlags(RF_MarkAsRootSet);

	if (Port == 0)
	{
		Port = 8080;
	}

	// Set the document root
	FString DocumentRoot = FPaths::GamePluginsDir() / UT4WA_PLUGIN_FOLDER / UT4WA_HTML_FOLDER;

	// Set listening port 
	FString PortStr = FString::FromInt(Port);

	#if defined(USE_CIVETWEB)
		StartCivetWeb(DocumentRoot, PortStr);
	#endif
}

#if defined(USE_CIVETWEB)
void UUT4WebAdmin::StartCivetWeb(FString &DocumentRoot, FString &PortStr)
{
	/* Initialize the library */
	mg_init_library(0);

	const char *options[] = {
		"document_root", TCHAR_TO_ANSI(*DocumentRoot),
		"listening_ports", TCHAR_TO_ANSI(*PortStr),
		0
	};

	/* Start the server */
	ctx = mg_start(NULL, 0, options);

	if (ctx) {
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));
		UE_LOG(UT4WebAdmin, Log, TEXT("UT4WebAdmin Started:"));
		UE_LOG(UT4WebAdmin, Log, TEXT(" * Port           : %i"), Port);
		UE_LOG(UT4WebAdmin, Log, TEXT(" * Root Web Folder: %s"), *DocumentRoot);
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));

		/* Add some handler */
		mg_set_request_handler(ctx, "/", WelcomeHandler, "Hello world");
	}
	else {
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));
		UE_LOG(UT4WebAdmin, Log, TEXT("UT4WebAdmin could not be started"));
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));
	}<commit_msg>Warning log if http server could not be started<commit_after>#include "UT4WebAdmin.h"
#include "Base64.h"


#define UT4WA_PLUGIN_FOLDER "UT4WebAdmin"
#define UT4WA_HTML_FOLDER "www"
#define LISTENING_PORT "8080"

int
WelcomeHandler(struct mg_connection *conn, void *cbdata)
{
	mg_printf(conn,
		"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
		"close\r\n\r\n");
	mg_printf(conn, "<html><body>");
	mg_printf(conn, "<h2>Welcome to UT4 Web Admin !</h2>");
	mg_printf(conn, "</body></html>\n");

	return 1;
}

UUT4WebAdmin::UUT4WebAdmin(const FObjectInitializer& ObjectInitializer) 
	: Super(ObjectInitializer)
{
	#if defined(USE_CIVETWEB)
		ctx = nullptr;
	#endif
	GameMode = nullptr;
}


void UUT4WebAdmin::Init()
{

	// Don't garbage collect me
	SetFlags(RF_MarkAsRootSet);

	if (Port == 0)
	{
		Port = 8080;
	}

	// Set the document root
	FString DocumentRoot = FPaths::GamePluginsDir() / UT4WA_PLUGIN_FOLDER / UT4WA_HTML_FOLDER;

	// Set listening port 
	FString PortStr = FString::FromInt(Port);

	#if defined(USE_CIVETWEB)
		StartCivetWeb(DocumentRoot, PortStr);
	#endif
}

#if defined(USE_CIVETWEB)
void UUT4WebAdmin::StartCivetWeb(FString &DocumentRoot, FString &PortStr)
{
	/* Initialize the library */
	mg_init_library(0);

	const char *options[] = {
		"document_root", TCHAR_TO_ANSI(*DocumentRoot),
		"listening_ports", TCHAR_TO_ANSI(*PortStr),
		0
	};

	/* Start the server */
	ctx = mg_start(NULL, 0, options);

	if (ctx) {
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));
		UE_LOG(UT4WebAdmin, Log, TEXT("UT4WebAdmin Started:"));
		UE_LOG(UT4WebAdmin, Log, TEXT(" * Port           : %i"), Port);
		UE_LOG(UT4WebAdmin, Log, TEXT(" * Root Web Folder: %s"), *DocumentRoot);
		UE_LOG(UT4WebAdmin, Log, TEXT("=================="));

		/* Add some handler */
		mg_set_request_handler(ctx, "/", WelcomeHandler, "Hello world");
	}
	else {
		UE_LOG(UT4WebAdmin, Warning, TEXT("=================="));
		UE_LOG(UT4WebAdmin, Warning, TEXT("UT4WebAdmin could not be started"));
		UE_LOG(UT4WebAdmin, Warning, TEXT("=================="));
	}
{'fraction_non_alphanumeric': 0.1832023575638507, 'fraction_numerical': 0.02111984282907662, 'mean_word_length': 5.256528417818741, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2464381', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1545, 'n_words': 316}