Files
DarkflameServer/dUgcServer/UgcStorage.h
Aaron Kimbrell 9d2ad053fd feat(ugc): icon light matched to the game, debounce, shared car icons, purge, icon editor
Brighter icons: a world light, a fill from the camera, a highlight, exposure
and contrast; with the defaults the icons' mean luminance matches the game's
own model icons (118 against 120 on a scratch set). Every icon parameter is
listed once (UgcIconParams: key, setting, range, default); the settings,
the dashboard's settings entries and the icon editor come from that list.
Presets per kind (player models, each car or rocket build type from
ModularBuildComponent) and overrides per model or module combination are in
ugc_icon_settings.

Saved models wait ugc_debounce_seconds (sharedconfig) after the owner's last
save before they're made (ugc.process_after); a client asking for one, the
owner leaving the world or a reset ends the wait.

Cars and rockets: one icon per combination of modules (sorted LOTs), shared
by every build of it; builds of a combination made already are marked made
right away, the client's per-blueprint downloads serve the shared files.

The dashboard can delete one item's files, purge by filter or all, preview
icons with any values on the UGC server (/admin routes, master password),
save presets and overrides, and draw a kind's icons again (icons only).

Migrations dlu/mysql/86 and dlu/sqlite/69. Not done yet: the dashboard
editor's lighting controls in the page script (routes are there), docs for
it, the empty-model state, /ugc?item= links, the shared fetch helper; the
storage size and property loading bugs are next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 14:56:45 -05:00

66 lines
2.2 KiB
C++

#pragma once
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
#include <string>
#include <vector>
#include "dCommonVars.h"
/**
* Where the UGC server keeps what it makes: <root>/models/<id % 1000>/<id>/ for player models and
* <root>/modular/<id % 1000>/<id>/ for modular builds. An item's files are written to a temporary folder and renamed
* into place, so a request never sees half of them. Plain file operations, safe from any thread for different items.
*/
class UgcStorage {
public:
enum class Kind { MODEL, MODULAR };
// The files an item has, by name (see FileName)
using Files = std::map<std::string, std::string>;
explicit UgcStorage(std::filesystem::path root);
const std::filesystem::path& GetRoot() const { return m_Root; }
std::filesystem::path Folder(Kind kind, LWOOBJID id) const;
// A file of an item, if it is there; `name` must be one of the names the server writes
std::optional<std::filesystem::path> File(Kind kind, LWOOBJID id, const std::string& name) const;
// Replaces an item's files with `files`; the bytes written, nullopt (and `error`) on failure
std::optional<uint64_t> Write(Kind kind, LWOOBJID id, const Files& files, std::string& error) const;
// Replaces some of an item's files in place (each written aside and renamed over the old one), keeping the others;
// the ones kept for comparing (icon.png...) are copied to previous.* first. The bytes written, nullopt when the item
// has no folder or a write fails.
std::optional<uint64_t> Update(Kind kind, LWOOBJID id, const Files& files, std::string& error) const;
// Deletes an item's files
void Remove(Kind kind, LWOOBJID id) const;
// Marks an item used now, for eviction
void Touch(Kind kind, LWOOBJID id) const;
struct Entry {
Kind kind{};
LWOOBJID id{};
uint64_t bytes{};
std::filesystem::file_time_type used{};
};
// Everything stored, with sizes and when it was last used
std::vector<Entry> List() const;
// Removes the least recently used items until the total is at most `maxBytes`; what was removed
std::vector<Entry> Evict(uint64_t maxBytes) const;
// Names the server writes (and serves); anything else is refused
static bool IsKnownFile(const std::string& name);
private:
std::filesystem::path m_Root;
};