Windows support: portable local server launch + clean quit, %APPDATA% data dir, Win32 libs, MinGW/MSVC build docs

This commit is contained in:
Gabe
2026-10-02 15:44:12 -05:00
parent 238cd9c6c3
commit 34fa21139f
8 changed files with 326 additions and 53 deletions

41
client/LocalServer.h Normal file
View File

@@ -0,0 +1,41 @@
#pragma once
// Runs safari_server next to the client executable for "Host & Play".
// The child's stdin is a pipe: stop() sends the console command `quit` so the
// server saves and exits cleanly on every platform (Windows has no SIGTERM),
// and only kills it if it does not exit in time. Its output goes to a log file.
#include <cstdint>
#include <filesystem>
#include <string>
namespace bs {
// Per-user data folder: %APPDATA%\brandling-safari on Windows,
// $XDG_DATA_HOME/brandling-safari or ~/.local/share/brandling-safari elsewhere
// (the server uses the same folder for world.db). Created if missing.
std::filesystem::path userDataDir();
std::filesystem::path executableDir();
class LocalServer {
public:
LocalServer() = default;
LocalServer(const LocalServer&) = delete;
LocalServer& operator=(const LocalServer&) = delete;
~LocalServer() { stop(); }
// Starts `safari_server --port <port> --name <name>`; false + `error` on failure.
bool start(uint16_t port, const std::string& name, std::string& error);
void stop();
bool running() const;
private:
#if defined(_WIN32)
void* process_ = nullptr; // HANDLE
void* stdin_ = nullptr; // HANDLE (write end)
#else
int pid_ = -1;
int stdin_ = -1;
#endif
};
} // namespace bs