LobbyDatabase.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * LobbyDatabase.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "LobbyDefines.h"
  12. class SQLiteInstance;
  13. class SQLiteStatement;
  14. using SQLiteInstancePtr = std::unique_ptr<SQLiteInstance>;
  15. using SQLiteStatementPtr = std::unique_ptr<SQLiteStatement>;
  16. class LobbyDatabase
  17. {
  18. SQLiteInstancePtr database;
  19. SQLiteStatementPtr insertChatMessageStatement;
  20. SQLiteStatementPtr insertAccountStatement;
  21. SQLiteStatementPtr insertAccessCookieStatement;
  22. SQLiteStatementPtr insertGameRoomStatement;
  23. SQLiteStatementPtr insertGameRoomPlayersStatement;
  24. SQLiteStatementPtr insertGameRoomInvitesStatement;
  25. SQLiteStatementPtr deleteGameRoomPlayersStatement;
  26. SQLiteStatementPtr deleteGameRoomInvitesStatement;
  27. SQLiteStatementPtr setAccountOnlineStatement;
  28. SQLiteStatementPtr setGameRoomStatusStatement;
  29. SQLiteStatementPtr updateAccountLoginTimeStatement;
  30. SQLiteStatementPtr getRecentMessageHistoryStatement;
  31. SQLiteStatementPtr getIdleGameRoomStatement;
  32. SQLiteStatementPtr getGameRoomStatusStatement;
  33. SQLiteStatementPtr getActiveGameRoomsStatement;
  34. SQLiteStatementPtr getActiveAccountsStatement;
  35. SQLiteStatementPtr getAccountGameRoomStatement;
  36. SQLiteStatementPtr getAccountDisplayNameStatement;
  37. SQLiteStatementPtr countRoomUsedSlotsStatement;
  38. SQLiteStatementPtr countRoomTotalSlotsStatement;
  39. SQLiteStatementPtr isAccountCookieValidStatement;
  40. SQLiteStatementPtr isGameRoomCookieValidStatement;
  41. SQLiteStatementPtr isPlayerInGameRoomStatement;
  42. SQLiteStatementPtr isPlayerInAnyGameRoomStatement;
  43. SQLiteStatementPtr isAccountIDExistsStatement;
  44. SQLiteStatementPtr isAccountNameExistsStatement;
  45. void prepareStatements();
  46. void createTables();
  47. void clearOldData();
  48. public:
  49. explicit LobbyDatabase(const boost::filesystem::path & databasePath);
  50. ~LobbyDatabase();
  51. void setAccountOnline(const std::string & accountID, bool isOnline);
  52. void setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus);
  53. void insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID);
  54. void deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID);
  55. void deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  56. void insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  57. void insertGameRoom(const std::string & roomID, const std::string & hostAccountID);
  58. void insertAccount(const std::string & accountID, const std::string & displayName);
  59. void insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
  60. void insertChatMessage(const std::string & sender, const std::string & roomType, const std::string & roomID, const std::string & messageText);
  61. void updateAccountLoginTime(const std::string & accountID);
  62. std::vector<LobbyGameRoom> getActiveGameRooms();
  63. std::vector<LobbyAccount> getActiveAccounts();
  64. std::vector<LobbyChatMessage> getRecentMessageHistory();
  65. std::string getIdleGameRoom(const std::string & hostAccountID);
  66. std::string getAccountGameRoom(const std::string & accountID);
  67. std::string getAccountDisplayName(const std::string & accountID);
  68. LobbyCookieStatus getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID);
  69. LobbyInviteStatus getAccountInviteStatus(const std::string & accountID, const std::string & roomID);
  70. LobbyRoomState getGameRoomStatus(const std::string & roomID);
  71. uint32_t getGameRoomFreeSlots(const std::string & roomID);
  72. bool isPlayerInGameRoom(const std::string & accountID);
  73. bool isPlayerInGameRoom(const std::string & accountID, const std::string & roomID);
  74. bool isAccountNameExists(const std::string & displayName);
  75. bool isAccountIDExists(const std::string & accountID);
  76. };