It works (kinda) now to actually implement things

This commit is contained in:
Aaron Kimbrell
2025-10-11 00:02:31 -05:00
parent 5453d163a3
commit d532a9b063
11 changed files with 3125 additions and 19 deletions

View File

@@ -89,6 +89,7 @@ elseif(MSVC)
add_compile_options("/wd4267" "/utf-8" "/volatile:iso" "/Zc:inline") add_compile_options("/wd4267" "/utf-8" "/volatile:iso" "/Zc:inline")
elseif(WIN32) elseif(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS) add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(NOMINMAX)
endif() endif()
# Our output dir # Our output dir
@@ -253,6 +254,7 @@ include_directories(
"thirdparty/MD5" "thirdparty/MD5"
"thirdparty/nlohmann" "thirdparty/nlohmann"
"thirdparty/mongoose" "thirdparty/mongoose"
"thirdparty/inja"
) )
# Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux) # Add system specfic includes for Apple, Windows and Other Unix OS' (including Linux)

View File

@@ -3,6 +3,6 @@ set(DDASHBOARDSERVER_SOURCES
) )
add_executable(DashboardServer "DashboardServer.cpp" "DashboardWeb.cpp") add_executable(DashboardServer "DashboardServer.cpp" "DashboardWeb.cpp")
target_link_libraries(DashboardServer ${COMMON_LIBRARIES} dServer dWeb inja) target_link_libraries(DashboardServer ${COMMON_LIBRARIES} dServer dWeb)
target_include_directories(DashboardServer PRIVATE ${PROJECT_SOURCE_DIR}/dServer ${PROJECT_SOURCE_DIR}/dWeb) target_include_directories(DashboardServer PRIVATE ${PROJECT_SOURCE_DIR}/dServer ${PROJECT_SOURCE_DIR}/dWeb)
add_compile_definitions(DashboardServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"") add_compile_definitions(DashboardServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION}\"")

View File

@@ -42,7 +42,7 @@ int main(int argc, char** argv) {
std::signal(SIGINT, Game::OnSignal); std::signal(SIGINT, Game::OnSignal);
std::signal(SIGTERM, Game::OnSignal); std::signal(SIGTERM, Game::OnSignal);
Game::config = new dConfig("dashboardconfig.ini"); Game::config = new dConfig("dashboardconfig.ini");
//Create all the objects we need to run our service: //Create all the objects we need to run our service:
@@ -131,7 +131,7 @@ int main(int argc, char** argv) {
Game::logger->Flush(); // once immediately before main loop Game::logger->Flush(); // once immediately before main loop
while (!Game::ShouldShutdown()) { while (!Game::ShouldShutdown()) {
//Check if we're still connected to master: // Check if we're still connected to master:
if (!Game::server->GetIsConnectedToMaster()) { if (!Game::server->GetIsConnectedToMaster()) {
framesSinceMasterDisconnect++; framesSinceMasterDisconnect++;

View File

@@ -1,11 +1,59 @@
#include "DashboardWeb.h" #include "DashboardWeb.h"
#include <inja/inja.hpp> // thanks bill gates
#ifdef _WIN32
#undef min
#undef max
#endif
#include "inja.hpp"
// default home page #include "eHTTPMethod.h"
// simple home page with inja
void HandleHTTPHomeRequest(HTTPReply& reply, std::string body) {
try {
inja::Environment env;
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
nlohmann::json data;
data["title"] = "Darkflame Universe Dashboard";
data["header"] = "Welcome to the Darkflame Universe Dashboard";
data["message"] = "This is a simple dashboard page served using Inja templating engine.";
const std::string template_str = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>{{ header }}</h1>
<p>{{ message }}</p>
</body>
</html>
)";
std::string rendered = env.render(template_str, data);
reply.message = rendered;
reply.status = eHTTPStatusCode::OK;
reply.contentType = ContentType::HTML;
} catch (const std::exception& e) {
reply.status = eHTTPStatusCode::INTERNAL_SERVER_ERROR;
reply.message = "Internal Server Error";
reply.contentType = ContentType::PLAIN;
}
}
namespace DashboardWeb { namespace DashboardWeb {
void RegisterRoutes() { void RegisterRoutes() {
Game::web.RegisterHTTPRoute({
.path = "/",
.method = eHTTPMethod::GET,
.handle = HandleHTTPHomeRequest
});
} }
} }

View File

@@ -1,9 +1,6 @@
#ifndef __DASHBOARDWEB_H__ #ifndef __DASHBOARDWEB_H__
#define __DASHBOARDWEB_H__ #define __DASHBOARDWEB_H__
#include <string>
#include <functional>
#include "Web.h" #include "Web.h"
namespace DashboardWeb { namespace DashboardWeb {

View File

@@ -379,6 +379,7 @@ int main(int argc, char** argv) {
Game::im->GetInstance(0, false, 0); Game::im->GetInstance(0, false, 0);
Game::im->GetInstance(1000, false, 0); Game::im->GetInstance(1000, false, 0);
StartAuthServer(); StartAuthServer();
StartDashboardServer();
} }
auto t = std::chrono::high_resolution_clock::now(); auto t = std::chrono::high_resolution_clock::now();

View File

@@ -147,3 +147,39 @@ uint32_t StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInsta
LOG("WorldServer PID is %d", world_pid); LOG("WorldServer PID is %d", world_pid);
return world_pid; return world_pid;
} }
uint32_t StartDashboardServer() {
if (Game::ShouldShutdown()) {
LOG("Currently shutting down. dashboard will not be restarted.");
return 0;
}
auto dashboard_path = BinaryPathFinder::GetBinaryDir() / "DashboardServer";
#ifdef _WIN32
dashboard_path.replace_extension(".exe");
auto dashboard_startup = startup;
auto dashboard_info = PROCESS_INFORMATION{};
if (!CreateProcessW(dashboard_path.wstring().data(), dashboard_path.wstring().data(),
nullptr, nullptr, false, 0, nullptr, nullptr,
&dashboard_startup, &dashboard_info))
{
LOG("Failed to launch DashboardServer");
return 0;
}
// get pid and close unused handles
auto dashboard_pid = dashboard_info.dwProcessId;
CloseHandle(dashboard_info.hProcess);
CloseHandle(dashboard_info.hThread);
#else // *nix systems
const auto dashboard_pid = fork();
if (dashboard_pid < 0) {
LOG("Failed to launch DashboardServer");
return 0;
} else if (dashboard_pid == 0) {
// We are the child process
execl(dashboard_path.string().c_str(), dashboard_path.string().c_str(), nullptr);
}
#endif
LOG("DashboardServer PID is %d", dashboard_pid);
return dashboard_pid;
}

View File

@@ -4,3 +4,4 @@
uint32_t StartAuthServer(); uint32_t StartAuthServer();
uint32_t StartChatServer(); uint32_t StartChatServer();
uint32_t StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID); uint32_t StartWorldServer(LWOMAPID mapID, uint16_t port, LWOINSTANCEID lastInstanceID, int maxPlayers, LWOCLONEID cloneID);
uint32_t StartDashboardServer();

View File

View File

@@ -77,16 +77,6 @@ FetchContent_Declare(
FetchContent_MakeAvailable(glm) FetchContent_MakeAvailable(glm)
FetchContent_Declare(
inja
GIT_REPOSITORY https://github.com/pantor/inja.git
GIT_TAG b2276440be8334aeba9cd5d628c2731d0f6a5809 #refs/tags/v3.4.0
GIT_PROGRESS TRUE
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(inja)
add_subdirectory(MD5) add_subdirectory(MD5)
add_subdirectory(mongoose) add_subdirectory(mongoose)

3031
thirdparty/inja/inja.hpp vendored Normal file

File diff suppressed because it is too large Load Diff