LobbyDatabase.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 updateRoomDescriptionStatement;
  31. SQLiteStatementPtr updateRoomPlayerLimitStatement;
  32. SQLiteStatementPtr getRecentMessageHistoryStatement;
  33. SQLiteStatementPtr getFullMessageHistoryStatement;
  34. SQLiteStatementPtr getIdleGameRoomStatement;
  35. SQLiteStatementPtr getGameRoomStatusStatement;
  36. SQLiteStatementPtr getAccountGameHistoryStatement;
  37. SQLiteStatementPtr getActiveGameRoomsStatement;
  38. SQLiteStatementPtr getActiveAccountsStatement;
  39. SQLiteStatementPtr getAccountInviteStatusStatement;
  40. SQLiteStatementPtr getAccountGameRoomStatement;
  41. SQLiteStatementPtr getAccountDisplayNameStatement;
  42. SQLiteStatementPtr getGameRoomPlayersStatement;
  43. SQLiteStatementPtr countRoomUsedSlotsStatement;
  44. SQLiteStatementPtr countRoomTotalSlotsStatement;
  45. SQLiteStatementPtr isAccountCookieValidStatement;
  46. SQLiteStatementPtr isGameRoomCookieValidStatement;
  47. SQLiteStatementPtr isPlayerInGameRoomStatement;
  48. SQLiteStatementPtr isPlayerInAnyGameRoomStatement;
  49. SQLiteStatementPtr isAccountIDExistsStatement;
  50. SQLiteStatementPtr isAccountNameExistsStatement;
  51. void prepareStatements();
  52. void createTables();
  53. void upgradeDatabase();
  54. void clearOldData();
  55. public:
  56. explicit LobbyDatabase(const boost::filesystem::path & databasePath);
  57. ~LobbyDatabase();
  58. void setAccountOnline(const std::string & accountID, bool isOnline);
  59. void setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus);
  60. void insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID);
  61. void deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID);
  62. void deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  63. void insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  64. void insertGameRoom(const std::string & roomID, const std::string & hostAccountID, const std::string & serverVersion, const std::string & modListJson);
  65. void insertAccount(const std::string & accountID, const std::string & displayName);
  66. void insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
  67. void insertChatMessage(const std::string & sender, const std::string & channelType, const std::string & roomID, const std::string & messageText);
  68. void updateAccountLoginTime(const std::string & accountID);
  69. void updateRoomPlayerLimit(const std::string & gameRoomID, int playerLimit);
  70. void updateRoomDescription(const std::string & gameRoomID, const std::string & description);
  71. std::vector<LobbyGameRoom> getAccountGameHistory(const std::string & accountID);
  72. std::vector<LobbyGameRoom> getActiveGameRooms();
  73. std::vector<LobbyAccount> getActiveAccounts();
  74. std::vector<LobbyChatMessage> getRecentMessageHistory(const std::string & channelType, const std::string & channelName);
  75. std::vector<LobbyChatMessage> getFullMessageHistory(const std::string & channelType, const std::string & channelName);
  76. std::string getIdleGameRoom(const std::string & hostAccountID);
  77. std::string getAccountGameRoom(const std::string & accountID);
  78. std::string getAccountDisplayName(const std::string & accountID);
  79. LobbyCookieStatus getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID);
  80. LobbyInviteStatus getAccountInviteStatus(const std::string & accountID, const std::string & roomID);
  81. LobbyRoomState getGameRoomStatus(const std::string & roomID);
  82. uint32_t getGameRoomFreeSlots(const std::string & roomID);
  83. bool isPlayerInGameRoom(const std::string & accountID);
  84. bool isPlayerInGameRoom(const std::string & accountID, const std::string & roomID);
  85. bool isAccountNameExists(const std::string & displayName);
  86. bool isAccountIDExists(const std::string & accountID);
  87. };