feature/move-to-svelte #1
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -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}",
|
||||
|
||||
9
.vscode/tasks.json
vendored
9
.vscode/tasks.json
vendored
@@ -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",
|
||||
|
||||
@@ -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
|
||||
$<$<CONFIG:Release>:-O3>
|
||||
$<$<CONFIG:Release>:-flto=auto>
|
||||
)
|
||||
|
||||
target_link_libraries(${TARGET_NAME} pthread sodium)
|
||||
# relase linker options
|
||||
target_link_options(${TARGET_NAME} PRIVATE
|
||||
$<$<CONFIG:Release>:-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}")
|
||||
@@ -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
|
||||
Submodule modules/cpp-libraries updated: 70b723bfc1...238108b69a
13
shadowrun-server.service
Normal file
13
shadowrun-server.service
Normal file
@@ -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
|
||||
@@ -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__
|
||||
@@ -1,12 +1,17 @@
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#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<decltype(make_database())>(make_database());
|
||||
db->sync_schema();
|
||||
|
||||
@@ -48,7 +48,7 @@ std::optional<std::string> 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) {
|
||||
|
||||
@@ -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<login::User>()) {
|
||||
if (u.username == username){
|
||||
std::cout << "WTF" << std::endl;
|
||||
id = u.id;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
auto user = db->get_optional<login::User>(
|
||||
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);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "ShadowrunApi.hpp"
|
||||
#include "ShadowrunDb.hpp"
|
||||
#include "login.hpp"
|
||||
#include <format>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// Created by lukas on 5/11/25.
|
||||
//
|
||||
|
||||
#ifndef SYSTEMD_H
|
||||
#define SYSTEMD_H
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
@@ -1,75 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<title>Service Status</title>
|
||||
<style>
|
||||
.active-button {
|
||||
background-color: #4CAF50; /* Green */
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.inactive-button {
|
||||
background-color: #f44336; /* Red */
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
height: 100vh; /* Full screen height */
|
||||
display: flex;
|
||||
justify-content: center; /* Horizontal centering */
|
||||
align-items: center; /* Vertical centering */
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center; /* Optional: center items within the column */
|
||||
gap: 1rem; /* Space between elements */
|
||||
}
|
||||
|
||||
.app-panel {
|
||||
display: inline-block;
|
||||
width: 200px;
|
||||
height: 120px;
|
||||
margin: 10px;
|
||||
padding: 20px;
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 10px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s ease;
|
||||
}
|
||||
.app-panel:hover {
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="app-panel"
|
||||
hx-get="/redirect?file=shadowrun.html"
|
||||
hx-trigger="click"
|
||||
hx-target="this"
|
||||
hx-swap="none">
|
||||
<h3>Shadowrun</h3>
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
<h1>Service Status</h1>
|
||||
|
||||
<div id="services" hx-get="/status" hx-trigger="load, every 5s" hx-swap="innerHTML">
|
||||
Loading services...
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,55 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<title>Login</title>
|
||||
<style>
|
||||
.active-button {
|
||||
background-color: #4CAF50; /* Green */
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.inactive-button {
|
||||
background-color: #f44336; /* Red */
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
border-radius: 5px;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
height: 100vh; /* Full screen height */
|
||||
display: flex;
|
||||
justify-content: center; /* Horizontal centering */
|
||||
align-items: center; /* Vertical centering */
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center; /* Optional: center items within the column */
|
||||
gap: 1rem; /* Space between elements */
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="column">
|
||||
<h1>Login</h1>
|
||||
|
||||
<div id="login" hx-get="/login"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,138 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Shadowrun Character Sheet</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Segoe UI', sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
background-color: white;
|
||||
padding: 2em;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #ccc;
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.grid_at {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 1em;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
|
||||
.grid-2 {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.grid-3 {
|
||||
grid-template-columns: 2fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.grid-4 {
|
||||
grid-template-columns: 2fr 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.grid-6 {
|
||||
grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr;
|
||||
}
|
||||
|
||||
.skill-row {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr 1fr;
|
||||
gap: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
input[type="text"], input[type="number"] {
|
||||
padding: 0.4em;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
margin-top: 2em;
|
||||
padding: 0.75em 2em;
|
||||
background-color: #222;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #444;
|
||||
}
|
||||
|
||||
.monitor-track {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, auto);
|
||||
gap: 0.25em;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.monitor-box input[type="checkbox"] {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.monitor-number {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-weight: bold;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<h1>Shadowrun Character Sheet</h1>
|
||||
|
||||
<div id="character-selector"
|
||||
hx-get="/api/shadowrun/character-list"
|
||||
hx-trigger="load"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML">
|
||||
</div>
|
||||
<div id="form-container"></div>
|
||||
|
||||
<div id="form-response"></div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user