database-leveldb.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "config.h"
  18. #if USE_LEVELDB
  19. #include <string>
  20. #include "database.h"
  21. #include "leveldb/db.h"
  22. class Database_LevelDB : public MapDatabase
  23. {
  24. public:
  25. Database_LevelDB(const std::string &savedir);
  26. ~Database_LevelDB();
  27. bool saveBlock(const v3s16 &pos, const std::string &data);
  28. void loadBlock(const v3s16 &pos, std::string *block);
  29. bool deleteBlock(const v3s16 &pos);
  30. void listAllLoadableBlocks(std::vector<v3s16> &dst);
  31. void beginSave() {}
  32. void endSave() {}
  33. private:
  34. leveldb::DB *m_database;
  35. };
  36. class PlayerDatabaseLevelDB : public PlayerDatabase
  37. {
  38. public:
  39. PlayerDatabaseLevelDB(const std::string &savedir);
  40. ~PlayerDatabaseLevelDB();
  41. void savePlayer(RemotePlayer *player);
  42. bool loadPlayer(RemotePlayer *player, PlayerSAO *sao);
  43. bool removePlayer(const std::string &name);
  44. void listPlayers(std::vector<std::string> &res);
  45. private:
  46. leveldb::DB *m_database;
  47. };
  48. class AuthDatabaseLevelDB : public AuthDatabase
  49. {
  50. public:
  51. AuthDatabaseLevelDB(const std::string &savedir);
  52. virtual ~AuthDatabaseLevelDB();
  53. virtual bool getAuth(const std::string &name, AuthEntry &res);
  54. virtual bool saveAuth(const AuthEntry &authEntry);
  55. virtual bool createAuth(AuthEntry &authEntry);
  56. virtual bool deleteAuth(const std::string &name);
  57. virtual void listNames(std::vector<std::string> &res);
  58. virtual void reload();
  59. private:
  60. leveldb::DB *m_database;
  61. };
  62. #endif // USE_LEVELDB