2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2013-09-10 15:49:43 +02:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2012-10-23 01:18:44 +04:00
|
|
|
|
2014-07-08 20:04:37 +02:00
|
|
|
#include <string>
|
2024-02-17 15:35:33 +01:00
|
|
|
#include <string_view>
|
2017-04-01 14:48:16 +02:00
|
|
|
#include <vector>
|
2013-09-10 15:49:43 +02:00
|
|
|
#include "irr_v3d.h"
|
2014-03-12 19:37:19 -04:00
|
|
|
#include "irrlichttypes.h"
|
2022-01-07 13:28:49 -05:00
|
|
|
#include "util/string.h"
|
2014-07-07 01:20:25 -04:00
|
|
|
|
2012-10-23 01:18:44 +04:00
|
|
|
class Database
|
|
|
|
{
|
|
|
|
public:
|
2017-04-23 14:35:08 +02:00
|
|
|
virtual void beginSave() = 0;
|
|
|
|
virtual void endSave() = 0;
|
|
|
|
virtual bool initialized() const { return true; }
|
|
|
|
};
|
2014-11-16 15:31:57 -05:00
|
|
|
|
2017-04-23 14:35:08 +02:00
|
|
|
class MapDatabase : public Database
|
|
|
|
{
|
|
|
|
public:
|
2017-08-17 23:02:50 +02:00
|
|
|
virtual ~MapDatabase() = default;
|
2014-11-16 15:31:57 -05:00
|
|
|
|
2024-02-17 15:35:33 +01:00
|
|
|
virtual bool saveBlock(const v3s16 &pos, std::string_view data) = 0;
|
2016-05-14 12:23:15 +02:00
|
|
|
virtual void loadBlock(const v3s16 &pos, std::string *block) = 0;
|
2014-11-16 15:31:57 -05:00
|
|
|
virtual bool deleteBlock(const v3s16 &pos) = 0;
|
|
|
|
|
|
|
|
static s64 getBlockAsInteger(const v3s16 &pos);
|
|
|
|
static v3s16 getIntegerAsBlock(s64 i);
|
|
|
|
|
2015-02-17 14:30:32 +01:00
|
|
|
virtual void listAllLoadableBlocks(std::vector<v3s16> &dst) = 0;
|
2017-04-23 14:35:08 +02:00
|
|
|
};
|
2014-11-16 15:31:57 -05:00
|
|
|
|
2017-04-23 14:35:08 +02:00
|
|
|
class PlayerSAO;
|
|
|
|
class RemotePlayer;
|
|
|
|
|
|
|
|
class PlayerDatabase
|
|
|
|
{
|
|
|
|
public:
|
2017-08-17 23:02:50 +02:00
|
|
|
virtual ~PlayerDatabase() = default;
|
|
|
|
|
2017-04-23 14:35:08 +02:00
|
|
|
virtual void savePlayer(RemotePlayer *player) = 0;
|
|
|
|
virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0;
|
|
|
|
virtual bool removePlayer(const std::string &name) = 0;
|
|
|
|
virtual void listPlayers(std::vector<std::string> &res) = 0;
|
2012-10-23 01:18:44 +04:00
|
|
|
};
|
2018-08-05 13:13:38 +02:00
|
|
|
|
|
|
|
struct AuthEntry
|
|
|
|
{
|
|
|
|
u64 id;
|
|
|
|
std::string name;
|
|
|
|
std::string password;
|
|
|
|
std::vector<std::string> privileges;
|
|
|
|
s64 last_login;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AuthDatabase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~AuthDatabase() = default;
|
|
|
|
|
|
|
|
virtual bool getAuth(const std::string &name, AuthEntry &res) = 0;
|
|
|
|
virtual bool saveAuth(const AuthEntry &authEntry) = 0;
|
|
|
|
virtual bool createAuth(AuthEntry &authEntry) = 0;
|
|
|
|
virtual bool deleteAuth(const std::string &name) = 0;
|
|
|
|
virtual void listNames(std::vector<std::string> &res) = 0;
|
|
|
|
virtual void reload() = 0;
|
|
|
|
};
|
2022-01-07 13:28:49 -05:00
|
|
|
|
2022-11-23 17:25:34 -05:00
|
|
|
class ModStorageDatabase : public Database
|
2022-01-07 13:28:49 -05:00
|
|
|
{
|
|
|
|
public:
|
2022-11-23 17:25:34 -05:00
|
|
|
virtual ~ModStorageDatabase() = default;
|
2022-01-07 13:28:49 -05:00
|
|
|
|
2022-11-23 17:46:20 -05:00
|
|
|
virtual void getModEntries(const std::string &modname, StringMap *storage) = 0;
|
|
|
|
virtual void getModKeys(const std::string &modname, std::vector<std::string> *storage) = 0;
|
2022-09-26 17:03:43 -04:00
|
|
|
virtual bool hasModEntry(const std::string &modname, const std::string &key) = 0;
|
|
|
|
virtual bool getModEntry(const std::string &modname,
|
|
|
|
const std::string &key, std::string *value) = 0;
|
2022-01-07 13:28:49 -05:00
|
|
|
virtual bool setModEntry(const std::string &modname,
|
2024-02-17 15:35:33 +01:00
|
|
|
const std::string &key, std::string_view value) = 0;
|
2022-01-07 13:28:49 -05:00
|
|
|
virtual bool removeModEntry(const std::string &modname, const std::string &key) = 0;
|
2022-09-26 17:03:43 -04:00
|
|
|
virtual bool removeModEntries(const std::string &modname) = 0;
|
2022-01-07 13:28:49 -05:00
|
|
|
virtual void listMods(std::vector<std::string> *res) = 0;
|
|
|
|
};
|