LobbyDatabase.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 setGameRoomPlayerLimitStatement;
  30. SQLiteStatementPtr getRecentMessageHistoryStatement;
  31. SQLiteStatementPtr getIdleGameRoomStatement;
  32. SQLiteStatementPtr getActiveGameRoomsStatement;
  33. SQLiteStatementPtr getActiveAccountsStatement;
  34. SQLiteStatementPtr getAccountGameRoomStatement;
  35. SQLiteStatementPtr getAccountDisplayNameStatement;
  36. SQLiteStatementPtr countAccountsInRoomStatement;
  37. SQLiteStatementPtr isAccountCookieValidStatement;
  38. SQLiteStatementPtr isGameRoomCookieValidStatement;
  39. SQLiteStatementPtr isPlayerInGameRoomStatement;
  40. SQLiteStatementPtr isPlayerInAnyGameRoomStatement;
  41. SQLiteStatementPtr isAccountIDExistsStatement;
  42. SQLiteStatementPtr isAccountNameExistsStatement;
  43. void prepareStatements();
  44. void createTables();
  45. public:
  46. explicit LobbyDatabase(const boost::filesystem::path & databasePath);
  47. ~LobbyDatabase();
  48. void setAccountOnline(const std::string & accountID, bool isOnline);
  49. void setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus);
  50. void setGameRoomPlayerLimit(const std::string & roomID, uint32_t playerLimit);
  51. void insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID);
  52. void deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID);
  53. void deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  54. void insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  55. void insertGameRoom(const std::string & roomID, const std::string & hostAccountID);
  56. void insertAccount(const std::string & accountID, const std::string & displayName);
  57. void insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
  58. void insertChatMessage(const std::string & sender, const std::string & roomType, const std::string & roomID, const std::string & messageText);
  59. void updateAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
  60. void updateAccountLoginTime(const std::string & accountID);
  61. void updateActiveAccount(const std::string & accountID, bool isActive);
  62. std::vector<LobbyGameRoom> getActiveGameRooms();
  63. std::vector<LobbyAccount> getActiveAccounts();
  64. std::vector<LobbyAccount> getAccountsInRoom(const std::string & roomID);
  65. std::vector<LobbyChatMessage> getRecentMessageHistory();
  66. std::string getIdleGameRoom(const std::string & hostAccountID);
  67. std::string getAccountGameRoom(const std::string & accountID);
  68. std::string getAccountDisplayName(const std::string & accountID);
  69. LobbyCookieStatus getGameRoomCookieStatus(const std::string & accountID, const std::string & accessCookieUUID, std::chrono::seconds cookieLifetime);
  70. LobbyCookieStatus getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID, std::chrono::seconds cookieLifetime);
  71. LobbyInviteStatus getAccountInviteStatus(const std::string & accountID, const std::string & roomID);
  72. LobbyRoomState getGameRoomStatus(const std::string & roomID);
  73. uint32_t getGameRoomFreeSlots(const std::string & roomID);
  74. bool isPlayerInGameRoom(const std::string & accountID);
  75. bool isPlayerInGameRoom(const std::string & accountID, const std::string & roomID);
  76. bool isAccountNameExists(const std::string & displayName);
  77. bool isAccountIDExists(const std::string & accountID);
  78. };