2023-12-29 13:09:56 +02:00
|
|
|
/*
|
|
|
|
* LobbyDatabase.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
#include "LobbyDefines.h"
|
|
|
|
|
2023-12-29 13:09:56 +02:00
|
|
|
class SQLiteInstance;
|
|
|
|
class SQLiteStatement;
|
|
|
|
|
|
|
|
using SQLiteInstancePtr = std::unique_ptr<SQLiteInstance>;
|
|
|
|
using SQLiteStatementPtr = std::unique_ptr<SQLiteStatement>;
|
|
|
|
|
|
|
|
class LobbyDatabase
|
|
|
|
{
|
|
|
|
SQLiteInstancePtr database;
|
|
|
|
|
|
|
|
SQLiteStatementPtr insertChatMessageStatement;
|
|
|
|
SQLiteStatementPtr insertAccountStatement;
|
|
|
|
SQLiteStatementPtr insertAccessCookieStatement;
|
|
|
|
SQLiteStatementPtr insertGameRoomStatement;
|
2023-12-30 00:41:16 +02:00
|
|
|
SQLiteStatementPtr insertGameRoomPlayersStatement;
|
|
|
|
SQLiteStatementPtr insertGameRoomInvitesStatement;
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
SQLiteStatementPtr deleteGameRoomPlayersStatement;
|
|
|
|
SQLiteStatementPtr deleteGameRoomInvitesStatement;
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
SQLiteStatementPtr setAccountOnlineStatement;
|
2023-12-29 13:09:56 +02:00
|
|
|
SQLiteStatementPtr setGameRoomStatusStatement;
|
2024-02-06 16:28:35 +02:00
|
|
|
SQLiteStatementPtr updateAccountLoginTimeStatement;
|
2024-03-11 19:47:35 +02:00
|
|
|
SQLiteStatementPtr updateRoomDescriptionStatement;
|
2024-03-11 20:03:33 +02:00
|
|
|
SQLiteStatementPtr updateRoomPlayerLimitStatement;
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
SQLiteStatementPtr getRecentMessageHistoryStatement;
|
2024-03-13 23:02:53 +02:00
|
|
|
SQLiteStatementPtr getFullMessageHistoryStatement;
|
2023-12-30 00:41:16 +02:00
|
|
|
SQLiteStatementPtr getIdleGameRoomStatement;
|
2024-01-29 22:05:11 +02:00
|
|
|
SQLiteStatementPtr getGameRoomStatusStatement;
|
2024-03-20 18:40:37 +02:00
|
|
|
SQLiteStatementPtr getAccountGameHistoryStatement;
|
2024-01-21 16:48:36 +02:00
|
|
|
SQLiteStatementPtr getActiveGameRoomsStatement;
|
2023-12-30 00:41:16 +02:00
|
|
|
SQLiteStatementPtr getActiveAccountsStatement;
|
2024-03-25 18:04:44 +02:00
|
|
|
SQLiteStatementPtr getAccountInviteStatusStatement;
|
2024-01-21 16:48:36 +02:00
|
|
|
SQLiteStatementPtr getAccountGameRoomStatement;
|
2024-01-08 20:50:43 +02:00
|
|
|
SQLiteStatementPtr getAccountDisplayNameStatement;
|
2024-01-28 00:04:54 +02:00
|
|
|
SQLiteStatementPtr countRoomUsedSlotsStatement;
|
|
|
|
SQLiteStatementPtr countRoomTotalSlotsStatement;
|
2023-12-30 00:41:16 +02:00
|
|
|
|
|
|
|
SQLiteStatementPtr isAccountCookieValidStatement;
|
|
|
|
SQLiteStatementPtr isGameRoomCookieValidStatement;
|
|
|
|
SQLiteStatementPtr isPlayerInGameRoomStatement;
|
|
|
|
SQLiteStatementPtr isPlayerInAnyGameRoomStatement;
|
2024-01-08 20:50:43 +02:00
|
|
|
SQLiteStatementPtr isAccountIDExistsStatement;
|
|
|
|
SQLiteStatementPtr isAccountNameExistsStatement;
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
void prepareStatements();
|
|
|
|
void createTables();
|
2024-04-15 12:34:16 +02:00
|
|
|
void upgradeDatabase();
|
2024-02-02 00:12:30 +02:00
|
|
|
void clearOldData();
|
2023-12-29 13:09:56 +02:00
|
|
|
|
|
|
|
public:
|
2023-12-30 00:41:16 +02:00
|
|
|
explicit LobbyDatabase(const boost::filesystem::path & databasePath);
|
2023-12-29 13:09:56 +02:00
|
|
|
~LobbyDatabase();
|
|
|
|
|
2024-01-21 16:48:36 +02:00
|
|
|
void setAccountOnline(const std::string & accountID, bool isOnline);
|
2023-12-30 00:41:16 +02:00
|
|
|
void setGameRoomStatus(const std::string & roomID, LobbyRoomState roomStatus);
|
|
|
|
|
|
|
|
void insertPlayerIntoGameRoom(const std::string & accountID, const std::string & roomID);
|
|
|
|
void deletePlayerFromGameRoom(const std::string & accountID, const std::string & roomID);
|
|
|
|
|
|
|
|
void deleteGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
|
|
|
|
void insertGameRoomInvite(const std::string & targetAccountID, const std::string & roomID);
|
|
|
|
|
2024-04-15 12:34:16 +02:00
|
|
|
void insertGameRoom(const std::string & roomID, const std::string & hostAccountID, const std::string & serverVersion, const std::string & modListJson);
|
2023-12-30 00:41:16 +02:00
|
|
|
void insertAccount(const std::string & accountID, const std::string & displayName);
|
|
|
|
void insertAccessCookie(const std::string & accountID, const std::string & accessCookieUUID);
|
2024-03-13 23:02:53 +02:00
|
|
|
void insertChatMessage(const std::string & sender, const std::string & channelType, const std::string & roomID, const std::string & messageText);
|
2023-12-30 00:41:16 +02:00
|
|
|
|
|
|
|
void updateAccountLoginTime(const std::string & accountID);
|
2024-03-11 20:03:33 +02:00
|
|
|
void updateRoomPlayerLimit(const std::string & gameRoomID, int playerLimit);
|
2024-03-11 19:47:35 +02:00
|
|
|
void updateRoomDescription(const std::string & gameRoomID, const std::string & description);
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2024-03-20 18:40:37 +02:00
|
|
|
std::vector<LobbyGameRoom> getAccountGameHistory(const std::string & accountID);
|
2023-12-30 00:41:16 +02:00
|
|
|
std::vector<LobbyGameRoom> getActiveGameRooms();
|
|
|
|
std::vector<LobbyAccount> getActiveAccounts();
|
2024-03-13 23:02:53 +02:00
|
|
|
std::vector<LobbyChatMessage> getRecentMessageHistory(const std::string & channelType, const std::string & channelName);
|
|
|
|
std::vector<LobbyChatMessage> getFullMessageHistory(const std::string & channelType, const std::string & channelName);
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
std::string getIdleGameRoom(const std::string & hostAccountID);
|
|
|
|
std::string getAccountGameRoom(const std::string & accountID);
|
|
|
|
std::string getAccountDisplayName(const std::string & accountID);
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2024-02-02 15:32:06 +02:00
|
|
|
LobbyCookieStatus getAccountCookieStatus(const std::string & accountID, const std::string & accessCookieUUID);
|
2023-12-30 00:41:16 +02:00
|
|
|
LobbyInviteStatus getAccountInviteStatus(const std::string & accountID, const std::string & roomID);
|
|
|
|
LobbyRoomState getGameRoomStatus(const std::string & roomID);
|
|
|
|
uint32_t getGameRoomFreeSlots(const std::string & roomID);
|
2023-12-29 13:09:56 +02:00
|
|
|
|
2023-12-30 00:41:16 +02:00
|
|
|
bool isPlayerInGameRoom(const std::string & accountID);
|
|
|
|
bool isPlayerInGameRoom(const std::string & accountID, const std::string & roomID);
|
2024-01-08 20:50:43 +02:00
|
|
|
bool isAccountNameExists(const std::string & displayName);
|
|
|
|
bool isAccountIDExists(const std::string & accountID);
|
2023-12-29 13:09:56 +02:00
|
|
|
};
|