Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ endif()


# MinHook Pfad relativ zum CMake-Projektverzeichnis
set(MINHOOK_DIR ${CMAKE_SOURCE_DIR}/MinHook)
set(MINHOOK_DIR ${CMAKE_SOURCE_DIR}/common/lib/MinHook)

# Suche alle .cpp-Dateien im aktuellen Verzeichnis
file(GLOB SOURCES "src/*.cpp")
file(GLOB MODELS_SOURCES "src/Models/*.cpp")
file(GLOB LOGIC_SOURCES "src/Logic/*.cpp")
file(GLOB WRAPPER_SOURCES "src/Wrapper/*.cpp")
file(GLOB NETWORK_SOURCES "src/Network/*.cpp")
file(GLOB PACKET_SOURCES "server/src/PackagingSystem.cpp") # Single file from server
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE COMMON_SOURCES "common/src/*.cpp")

list(APPEND SOURCES ${COMMON_SOURCES})
include_directories("common/src/")


# Dear ImGui Quellen und Header definieren
set(IMGUI_DIR ${CMAKE_SOURCE_DIR}/imgui)
set(IMGUI_DIR ${CMAKE_SOURCE_DIR}/common/lib/imgui)
set(IMGUI_BACKENDS_DIR ${IMGUI_DIR}/backends)

set(IMGUI_SOURCES
Expand All @@ -72,6 +72,11 @@ set(IMGUI_SOURCES
${IMGUI_BACKENDS_DIR}/imgui_impl_win32.cpp
)

# inih
set(INIH_SOURCES
${CMAKE_SOURCE_DIR}/common/lib/inih/ini.c
)

# MinHook Quellen und Bibliotheken
set(MINHOOK_LIB ${MINHOOK_DIR}/libMinHook.x86.lib)

Expand All @@ -91,7 +96,7 @@ set(MINHOOK_LIB ${MINHOOK_DIR}/libMinHook.x86.lib)
#endif()

# Bibliothek erstellen (DLL)
add_library(MyDLL SHARED ${SOURCES} ${IMGUI_SOURCES} ${MODELS_SOURCES} ${LOGIC_SOURCES} ${WRAPPER_SOURCES} ${NETWORK_SOURCES} ${PACKET_SOURCES})
add_library(MyDLL SHARED ${SOURCES} ${IMGUI_SOURCES} ${INIH_SOURCES})

# Include-Verzeichnisse hinzufügen
target_include_directories(MyDLL PUBLIC
Expand Down
Binary file removed MinHook/libMinHook.x86.lib
Binary file not shown.
Binary file removed MinHook/oldlibMinHook.x86.lib
Binary file not shown.
55 changes: 55 additions & 0 deletions MonitoringServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.15)
project(MonitoringServer)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(WIN32)
# Windows 10
add_definitions(-D_WIN32_WINNT=0x0A00)

# ASIO-path
set(ASIO_INCLUDE_DIR "C:/Program Files (x86)/asio-1.34.2/include")

# Crow-path
set(CMAKE_PREFIX_PATH "C:/Program Files (x86)/crow-install")
endif()


find_package(Crow REQUIRED)

# Optional
# find_package(OpenSSL REQUIRED)
# find_package(ZLIB REQUIRED)


file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
src/*.cpp
src/*.h
src/*.hpp
)

# inih
set(INIH_SOURCES
${CMAKE_SOURCE_DIR}/../common/lib/inih/ini.c
)

# Automatisch alle .cpp-Dateien aus ../common/ einbinden
file(GLOB_RECURSE COMMON_SOURCES "../common/src/*.cpp")
list(APPEND SOURCES ${COMMON_SOURCES})
include_directories("../common/src/")

# --- Executable ---
add_executable(MonitoringServer ${SOURCES} ${INIH_SOURCES})
target_include_directories(MonitoringServer PRIVATE src)

# --- link Libraries ---
target_link_libraries(MonitoringServer
PRIVATE
Crow::Crow
# OpenSSL::SSL
# OpenSSL::Crypto
# ZLIB::ZLIB
)

# install(TARGETS MonitoringServer DESTINATION bin)
59 changes: 59 additions & 0 deletions MonitoringServer/src/IniData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <iostream>
#include <filesystem>
#include <fstream>
#include <string>
#include "../../common/src/IniManager.h"

class IniData {
public:

struct Ini {
std::string serverIp = "127.0.0.1";
int serverPort = 18080;
std::string secret = "my_secret_key";
};
static constexpr const char * CONFIG_FILE = "config.ini";

class Item
{
public:
static constexpr const char * GENERAL_SERVER_IP = "General.server_ip";
static constexpr const char * GENERAL_SERVER_PORT = "General.server_port";
static constexpr const char * GENERAL_SERVER_HEADER_SECRET = "General.header_secret";
};

static Ini LoadIni()
{
Ini retIni;
retIni.serverIp = IniManager::GetItem(CONFIG_FILE, Item::GENERAL_SERVER_IP);
retIni.serverPort = std::stoi(IniManager::GetItem(IniData::CONFIG_FILE, Item::GENERAL_SERVER_PORT));
retIni.secret = IniManager::GetItem(CONFIG_FILE, Item::GENERAL_SERVER_HEADER_SECRET);
return retIni;
}
static bool CreateConfigIfMissing(const std::string& path) // STATIC
{
writeConfig(path);

if (std::filesystem::exists(path))
return true;

return false;
}

private:
static void writeConfig(const std::string& path)
{
if (std::filesystem::exists(path))
return;

Ini tempIni;
std::ofstream out(path);
out << "[General]\n";
out << "server_ip =" << tempIni.serverIp << "\n";
out << "server_port = " << std::to_string(tempIni.serverPort).c_str() << "\n";
out << "header_secret = " << tempIni.secret << "\n\n";
}

};
92 changes: 92 additions & 0 deletions MonitoringServer/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <mutex>

#include "IniData.h"

#include "crow.h"
//#include "crow_all.h"

std::string ascii = R"(
____ _____ ____ _____ __ __ _ _
| _ \| ____/ ___|_ _| | \/ | ___ _ __ (_) |_ ___ _ __
| |_) | _| \___ \ | | | |\/| |/ _ \| '_ \| | __/ _ \| '__|
| _ <| |___ ___) || | | | | | (_) | | | | | || (_) | |
|_| \_\_____|____/ |_| |_| |_|\___/|_| |_|_|\__\___/|_|
)";

std::mutex mtx_serverData;

IniData::Ini config;

struct GothicServerData {
std::string status = "offline";
int playerCount = 0;

} serverData;

IniData::Ini getConfigData();


/*This RestAPI receives every 5 Seconds a Message from the GothicServer, if there is no answer for more than 7 Seconds,
this RestAPI-Sever answers with an Offline-Status.
*/
int main()
{
std::cout << ascii << "\n\n";
config = getConfigData();

crow::SimpleApp app; //define your crow application

auto lastResponse = std::chrono::high_resolution_clock::now();

// GET /status
CROW_ROUTE(app, "/status").methods("GET"_method)([&lastResponse] {
auto currentTime = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = currentTime - lastResponse;
int durrationInSec = static_cast<int>(elapsed.count()/1000);

crow::json::wvalue res;
if(durrationInSec > 7) {
res["status"] = "offline";
res["playerCount"] = "0";
} else {
std::lock_guard<std::mutex> lock(mtx_serverData);

res["status"] = serverData.status;
res["playerCount"] = std::to_string(serverData.playerCount);
}
return res;
});

// PUT /status
CROW_ROUTE(app, "/status").methods("PUT"_method)([&lastResponse](const crow::request& req) {
if (req.get_header_value("X-Auth-Token") != config.secret){
return crow::response(403, "Forbidden");
}

auto body = crow::json::load(req.body);
if (!body || !body.has("status")) {
return crow::response(400, "Missing 'status' field");
}
lastResponse = std::chrono::high_resolution_clock::now();
std::lock_guard<std::mutex> lock(mtx_serverData);
serverData.status = body["status"].s();
serverData.playerCount = body["playerCount"].i();

return crow::response(200, "Updated");
});

app.bindaddr(config.serverIp).port(config.serverPort).multithreaded().run();
}

IniData::Ini getConfigData() {
IniData::Ini ret;

// #### LOADIN INI ####
if(!IniData::CreateConfigIfMissing(IniData::CONFIG_FILE))
return ret;

ret = IniData::LoadIni();
std::cout << "-- Config loaded --" << "\n";
return ret;
}
File renamed without changes.
1 change: 1 addition & 0 deletions common/lib/cpp-httplib/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/yhirose/cpp-httplib
Loading