diff --git a/.vscode/launch.json b/.vscode/launch.json index cb0bcb3..9b87958 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,10 +2,10 @@ "version": "0.2.0", "configurations": [ { - "name": "Debug Server Admin Panel", + "name": "Debug Shadowrun Server", "type": "lldb", "request": "launch", - "program": "${workspaceFolder}/build/lf-server-admin-panel", + "program": "${workspaceFolder}/build/shadowrun-server", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 0bbd935..2c7326f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -9,6 +9,15 @@ "problemMatcher": [ "$gcc" ] + }, + { + "label": "build release", + "type": "shell", + "command": "cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build", + "group": "build", + "problemMatcher": [ + "$gcc" + ] }, { "label": "build Frontend", diff --git a/CMakeLists.txt b/CMakeLists.txt index d502bb6..d61b64f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project(CrowHTMX) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(TARGET_NAME lf-server-admin-panel ) +set(TARGET_NAME shadowrun-server ) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -20,15 +20,15 @@ if(NOT CMAKE_BUILD_TYPE IN_LIST SUPPORTED_BUILD_TYPES) endif() # Copy 'static' and 'templates' directories to build directory -file(GLOB_RECURSE STATIC_FILES "${CMAKE_SOURCE_DIR}/static/*") -file(GLOB_RECURSE TEMPLATE_FILES "${CMAKE_SOURCE_DIR}/templates/*") +file(GLOB_RECURSE ASSETS_FILES "${CMAKE_SOURCE_DIR}/assets/*") +file(GLOB_RECURSE FRONTEND_FILES "${CMAKE_SOURCE_DIR}/frontend/build/*") foreach(file IN LISTS STATIC_FILES) file(RELATIVE_PATH rel_path "${CMAKE_SOURCE_DIR}" "${file}") configure_file("${file}" "${CMAKE_BINARY_DIR}/${rel_path}" COPYONLY) endforeach() -foreach(file IN LISTS TEMPLATE_FILES) +foreach(file IN LISTS FRONTEND_FILES) file(RELATIVE_PATH rel_path "${CMAKE_SOURCE_DIR}" "${file}") configure_file("${file}" "${CMAKE_BINARY_DIR}/${rel_path}" COPYONLY) endforeach() @@ -36,22 +36,18 @@ endforeach() include_directories( modules/cpp-libraries/include/ src - src/htmx src/shadowrun src/database src/login ) add_executable(${TARGET_NAME} - # sqlite3 modules/cpp-libraries/src/sqlite3.c modules/cpp-libraries/src/monocypher.c src/main.cpp src/utils.hpp src/utils.cpp - src/systemd.cpp - src/systemd.h src/json_settings.cpp src/json_settings.h @@ -80,9 +76,23 @@ target_compile_options(${TARGET_NAME} PRIVATE > ) -target_compile_definitions(${TARGET_NAME} PRIVATE APPLICATION_NAME="${TARGET_NAME}") +# relase compiler options +target_compile_options(${TARGET_NAME} PRIVATE + $<$:-O3> + $<$:-flto=auto> +) -target_link_libraries(${TARGET_NAME} pthread sodium) +# relase linker options +target_link_options(${TARGET_NAME} PRIVATE + $<$:-flto=auto> +) + +target_compile_definitions(${TARGET_NAME} PRIVATE + APPLICATION_NAME="${TARGET_NAME}" + SQLITE_THREADSAFE=1 +) + +target_link_libraries(${TARGET_NAME} pthread) # Optional: Print build type at configuration time message(STATUS "Configuring build type: ${CMAKE_BUILD_TYPE}") \ No newline at end of file diff --git a/lf-server-admin-panel.service b/lf-server-admin-panel.service deleted file mode 100644 index c96049d..0000000 --- a/lf-server-admin-panel.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=lf-server-admin-panel Service -After=network.target - -[Service] -Type=simple -WorkingDirectory=/usr/share/lf-server-admin-panel -ExecStart=/usr/bin/lf-server-admin-panel -Restart=on-failure -RestartSec=5 - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/modules/cpp-libraries b/modules/cpp-libraries index 70b723b..238108b 160000 --- a/modules/cpp-libraries +++ b/modules/cpp-libraries @@ -1 +1 @@ -Subproject commit 70b723bfc10ae6988725ea55cc97ba508ba00892 +Subproject commit 238108b69a88c225694d5024e991e133d0a72759 diff --git a/shadowrun-server.service b/shadowrun-server.service new file mode 100644 index 0000000..72b6fa4 --- /dev/null +++ b/shadowrun-server.service @@ -0,0 +1,13 @@ +[Unit] +Description=shadowrun server Service +After=network.target + +[Service] +Type=simple +WorkingDirectory=/usr/share/shadowrun-server +ExecStart=/usr/bin/shadowrun-server +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/src/database/database.hpp b/src/database/database.hpp index bfc284a..94bce4b 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -7,7 +7,7 @@ #include "loginDb.hpp" namespace Database { - static constexpr std::string dbFile = "test.db"; + static constexpr std::string dbFile = "shadowrun.db"; } inline auto make_database() { @@ -33,7 +33,8 @@ inline auto make_database() { sqlite_orm::make_column("updated_at", &shadowrun::ShadowrunCharacterData::updated_at, sqlite_orm::default_value("CURRENT_TIMESTAMP")), sqlite_orm::foreign_key(&shadowrun::ShadowrunCharacterData::character_id).references(&shadowrun::ShadowrunCharacter::id).on_delete.cascade() )); - return storage; + + return storage; } #endif // __DATABASE_H__ \ No newline at end of file diff --git a/src/database/databasepool.h b/src/database/databasepool.h index 87a1108..0b34b47 100644 --- a/src/database/databasepool.h +++ b/src/database/databasepool.h @@ -1,12 +1,17 @@ #include #include #include +#include #include #include "database.hpp" class DatabasePool { public: DatabasePool(size_t size) { + // allow multithreaded access to database + assert(sqlite3_config(SQLITE_CONFIG_MULTITHREAD) == SQLITE_OK); + assert(sqlite3_initialize() == SQLITE_OK); + for (size_t i = 0; i < size; ++i){ auto db = std::make_shared(make_database()); db->sync_schema(); diff --git a/src/login/login.cpp b/src/login/login.cpp index 7a9e611..49e52c1 100644 --- a/src/login/login.cpp +++ b/src/login/login.cpp @@ -48,7 +48,7 @@ std::optional loginUser(const std::string& username, const std::str void initLogin(crow::SimpleApp& app) { - //createUser("lukas", "Trollar4928"); + createUser("lukas", "Trollar4928"); CROW_ROUTE(app, "/login").methods("POST"_method) ([](const crow::request& req) { diff --git a/src/login/loginDb.cpp b/src/login/loginDb.cpp index 48bbf29..4367885 100644 --- a/src/login/loginDb.cpp +++ b/src/login/loginDb.cpp @@ -59,22 +59,17 @@ int createUser(const std::string& username, const std::string& password){ if (username.empty() || password.empty()) return -1; - int64_t id; + int64_t id = -1; auto db = dbpool.acquire(); for (auto &u : db->get_all()) { if (u.username == username){ - std::cout << "WTF" << std::endl; + id = u.id; + break; }; } - auto user = db->get_optional( - where(c(&login::User::username) == username) - ); - - if (user.has_value()) { - id = user.value().id; - } else { + if (id < 0){ User usr = newUser(username); createPasswordHash(usr, password); id = db->insert(usr); diff --git a/src/shadowrun/ShadowrunApi.cpp b/src/shadowrun/ShadowrunApi.cpp index 331cd32..b8eb143 100644 --- a/src/shadowrun/ShadowrunApi.cpp +++ b/src/shadowrun/ShadowrunApi.cpp @@ -3,7 +3,6 @@ #include "ShadowrunApi.hpp" #include "ShadowrunDb.hpp" #include "login.hpp" -#include #include using namespace std; diff --git a/src/systemd.cpp b/src/systemd.cpp deleted file mode 100644 index 74a3e85..0000000 --- a/src/systemd.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// -// Created by lukas on 5/11/25. -// - -#include "format" -#include "systemd.h" - -using namespace std; - -namespace systemd { - bool is_service_active(string_view service_name) { - const string cmd = format("systemctl is-active --quiet {}", service_name); - return system(cmd.c_str()) == 0; - } - - bool is_service_enabled(string_view service_name) { - const string cmd = format("systemctl is-enabled --quiet {}", service_name); - return system(cmd.c_str()) == 0; - } - - void toggle_service(string_view serviceName){ - string_view toggle = is_service_active(serviceName) ? "stop" : "start"; - const string cmd = format("systemctl {} {}", toggle, serviceName); - // TODO: add error handling - (void)system(cmd.c_str()); - } -} \ No newline at end of file diff --git a/src/systemd.h b/src/systemd.h deleted file mode 100644 index fcea2d2..0000000 --- a/src/systemd.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by lukas on 5/11/25. -// - -#ifndef SYSTEMD_H -#define SYSTEMD_H - -#include - -namespace systemd { - /** - * Check if a service is active - * @param service_name name of the systemd service - * @return - */ - bool is_service_active(std::string_view service_name); - - /** - * Check if a service is enabled - * @param service_name name of the systemd service - * @return - */ - bool is_service_enabled(std::string_view service_name); - - /** - * Toggle the service on or off dependent on its current state - * @param service_name name of the systemd service - */ - void toggle_service(std::string_view service_name); -} - - - -#endif //SYSTEMD_H diff --git a/templates/dashboard.html b/templates/dashboard.html deleted file mode 100644 index eefaabc..0000000 --- a/templates/dashboard.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - Service Status - - - - -
-

Shadowrun

-
- -
-

Service Status

- -
- Loading services... -
-
- - diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index 3f9c775..0000000 --- a/templates/index.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - Login - - - - -
-

Login

- -
-
-
- - - diff --git a/templates/shadowrun.html b/templates/shadowrun.html deleted file mode 100644 index 314b483..0000000 --- a/templates/shadowrun.html +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - Shadowrun Character Sheet - - - - -
-

Shadowrun Character Sheet

- -
-
-
- -
- -
- -