LobbyDatabase.h 4.5 KB

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