LobbyDatabase.h 4.4 KB

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