database.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include <set>
  18. #include <string>
  19. #include <vector>
  20. #include "irr_v3d.h"
  21. #include "irrlichttypes.h"
  22. #include "util/basic_macros.h"
  23. class Database
  24. {
  25. public:
  26. virtual void beginSave() = 0;
  27. virtual void endSave() = 0;
  28. virtual bool initialized() const { return true; }
  29. };
  30. class MapDatabase : public Database
  31. {
  32. public:
  33. virtual ~MapDatabase() = default;
  34. virtual bool saveBlock(const v3s16 &pos, const std::string &data) = 0;
  35. virtual void loadBlock(const v3s16 &pos, std::string *block) = 0;
  36. virtual bool deleteBlock(const v3s16 &pos) = 0;
  37. static s64 getBlockAsInteger(const v3s16 &pos);
  38. static v3s16 getIntegerAsBlock(s64 i);
  39. virtual void listAllLoadableBlocks(std::vector<v3s16> &dst) = 0;
  40. };
  41. class PlayerSAO;
  42. class RemotePlayer;
  43. class PlayerDatabase
  44. {
  45. public:
  46. virtual ~PlayerDatabase() = default;
  47. virtual void savePlayer(RemotePlayer *player) = 0;
  48. virtual bool loadPlayer(RemotePlayer *player, PlayerSAO *sao) = 0;
  49. virtual bool removePlayer(const std::string &name) = 0;
  50. virtual void listPlayers(std::vector<std::string> &res) = 0;
  51. };
  52. struct AuthEntry
  53. {
  54. u64 id;
  55. std::string name;
  56. std::string password;
  57. std::vector<std::string> privileges;
  58. s64 last_login;
  59. };
  60. class AuthDatabase
  61. {
  62. public:
  63. virtual ~AuthDatabase() = default;
  64. virtual bool getAuth(const std::string &name, AuthEntry &res) = 0;
  65. virtual bool saveAuth(const AuthEntry &authEntry) = 0;
  66. virtual bool createAuth(AuthEntry &authEntry) = 0;
  67. virtual bool deleteAuth(const std::string &name) = 0;
  68. virtual void listNames(std::vector<std::string> &res) = 0;
  69. virtual void reload() = 0;
  70. };