LobbyDatabase.h 4.0 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 getGameRoomStatusStatement;
  33. SQLiteStatementPtr getActiveGameRoomsStatement;
  34. SQLiteStatementPtr getActiveAccountsStatement;
  35. SQLiteStatementPtr getAccountGameRoomStatement;
  36. SQLiteStatementPtr getAccountDisplayNameStatement;
  37. SQLiteStatementPtr countRoomUsedSlotsStatement;
  38. SQLiteStatementPtr countRoomTotalSlotsStatement;
  39. SQLiteStatementPtr isAccountCookieValidStatement;
  40. SQLiteStatementPtr isGameRoomCookieValidStatement;
  41. SQLiteStatementPtr isPlayerInGameRoomStatement;
  42. SQLiteStatementPtr isPlayerInAnyGameRoomStatement;
  43. SQLiteStatementPtr isAccountIDExistsStatement;
  44. SQLiteStatementPtr isAccountNameExistsStatement;
  45. void prepareStatements();
  46. void createTables();
  47. void clearOldData();
  48. public:
  49. explicit LobbyDatabase(const boost::filesystem::path & databasePath);
  50. ~LobbyDatabase();
  51. void setAccountOnline(const std::string & accountID, bool isOnline);
  52. void setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus);
  53. void insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID);
  54. void deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID);
  55. void deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  56. void insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
  57. void insertGameRoom(const std::string & roomID, const std::string & hostAccountID);
  58. void insertAccount(const std::string & accountID, const std::string & displayName);
  59. void insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
  60. void insertChatMessage(const std::string & sender, const std::string & roomType, const std::string & roomID, const std::string & messageText);
  61. void updateAccountLoginTime(const std::string & accountID);
  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);
  70. LobbyCookieStatus getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID);
  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. };