Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
database-files.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
4
5#pragma once
6
7// !!! WARNING !!!
8// This backend is intended to be used on Minetest 0.4.16 only for the transition backend
9// for player files
10
11#include "database.h"
12#include <unordered_map>
13#include <unordered_set>
14#include <json/json.h> // for Json::Value
15
17{
18public:
19 PlayerDatabaseFiles(const std::string &savedir);
20 virtual ~PlayerDatabaseFiles() = default;
21
22 void savePlayer(RemotePlayer *player);
23 bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
24 bool removePlayer(const std::string &name);
25 void listPlayers(std::vector<std::string> &res);
26
27private:
28 void deSerialize(RemotePlayer *p, std::istream &is, const std::string &playername,
29 PlayerSAO *sao);
30 /*
31 serialize() writes a bunch of text that can contain
32 any characters except a '\0', and such an ending that
33 deSerialize stops reading exactly at the right point.
34 */
35 void serialize(RemotePlayer *p, std::ostream &os);
36
37 std::string m_savedir;
38};
39
41{
42public:
43 AuthDatabaseFiles(const std::string &savedir);
44 virtual ~AuthDatabaseFiles() = default;
45
46 virtual bool getAuth(const std::string &name, AuthEntry &res);
47 virtual bool saveAuth(const AuthEntry &authEntry);
48 virtual bool createAuth(AuthEntry &authEntry);
49 virtual bool deleteAuth(const std::string &name);
50 virtual void listNames(std::vector<std::string> &res);
51 virtual void reload();
52
53private:
54 std::unordered_map<std::string, AuthEntry> m_auth_list;
55 std::string m_savedir;
56 bool readAuthFile();
57 bool writeAuthFile();
58};
59
61{
62public:
63 ModStorageDatabaseFiles(const std::string &savedir);
64 virtual ~ModStorageDatabaseFiles() = default;
65
66 virtual void getModEntries(const std::string &modname, StringMap *storage);
67 virtual void getModKeys(const std::string &modname, std::vector<std::string> *storage);
68 virtual bool getModEntry(const std::string &modname,
69 const std::string &key, std::string *value);
70 virtual bool hasModEntry(const std::string &modname, const std::string &key);
71 virtual bool setModEntry(const std::string &modname,
72 const std::string &key, std::string_view value);
73 virtual bool removeModEntry(const std::string &modname, const std::string &key);
74 virtual bool removeModEntries(const std::string &modname);
75 virtual void listMods(std::vector<std::string> *res);
76
77 virtual void beginSave();
78 virtual void endSave();
79
80private:
81 Json::Value *getOrCreateJson(const std::string &modname);
82
83 std::string m_storage_dir;
84 std::unordered_map<std::string, Json::Value> m_mod_storage;
85 std::unordered_set<std::string> m_modified;
86};
Definition database-files.h:41
virtual bool deleteAuth(const std::string &name)
Definition database-files.cpp:291
std::unordered_map< std::string, AuthEntry > m_auth_list
Definition database-files.h:54
bool readAuthFile()
Definition database-files.cpp:314
virtual bool createAuth(AuthEntry &authEntry)
Definition database-files.cpp:283
virtual ~AuthDatabaseFiles()=default
virtual void listNames(std::vector< std::string > &res)
Definition database-files.cpp:300
virtual bool saveAuth(const AuthEntry &authEntry)
Definition database-files.cpp:275
AuthDatabaseFiles(const std::string &savedir)
Definition database-files.cpp:260
virtual bool getAuth(const std::string &name, AuthEntry &res)
Definition database-files.cpp:265
bool writeAuthFile()
Definition database-files.cpp:344
std::string m_savedir
Definition database-files.h:55
virtual void reload()
Definition database-files.cpp:309
Definition database.h:61
Definition database-files.h:61
virtual ~ModStorageDatabaseFiles()=default
virtual bool getModEntry(const std::string &modname, const std::string &key, std::string *value)
Definition database-files.cpp:393
Json::Value * getOrCreateJson(const std::string &modname)
Definition database-files.cpp:503
virtual bool hasModEntry(const std::string &modname, const std::string &key)
Definition database-files.cpp:407
virtual void beginSave()
Definition database-files.cpp:453
virtual void endSave()
Definition database-files.cpp:457
virtual void getModEntries(const std::string &modname, StringMap *storage)
Definition database-files.cpp:367
virtual void listMods(std::vector< std::string > *res)
Definition database-files.cpp:489
std::unordered_set< std::string > m_modified
Definition database-files.h:85
std::string m_storage_dir
Definition database-files.h:83
virtual bool removeModEntries(const std::string &modname)
Definition database-files.cpp:442
ModStorageDatabaseFiles(const std::string &savedir)
Definition database-files.cpp:362
virtual bool removeModEntry(const std::string &modname, const std::string &key)
Definition database-files.cpp:427
virtual void getModKeys(const std::string &modname, std::vector< std::string > *storage)
Definition database-files.cpp:380
virtual bool setModEntry(const std::string &modname, const std::string &key, std::string_view value)
Definition database-files.cpp:413
std::unordered_map< std::string, Json::Value > m_mod_storage
Definition database-files.h:84
Definition database.h:74
Definition database-files.h:17
virtual ~PlayerDatabaseFiles()=default
void listPlayers(std::vector< std::string > &res)
Definition database-files.cpp:233
void deSerialize(RemotePlayer *p, std::istream &is, const std::string &playername, PlayerSAO *sao)
Definition database-files.cpp:25
bool removePlayer(const std::string &name)
Definition database-files.cpp:182
void serialize(RemotePlayer *p, std::ostream &os)
Definition database-files.cpp:101
std::string m_savedir
Definition database-files.h:37
bool loadPlayer(RemotePlayer *player, PlayerSAO *sao)
Definition database-files.cpp:208
void savePlayer(RemotePlayer *player)
Definition database-files.cpp:136
PlayerDatabaseFiles(const std::string &savedir)
Definition database-files.cpp:20
Definition database.h:41
Definition player_sao.h:56
Definition remoteplayer.h:26
std::unordered_map< std::string, std::string > StringMap
Definition string.h:65
Definition database.h:52
static std::string p(std::string path)
Definition test_filesys.cpp:53