LobbyDatabase.h 4.7 KB

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