mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
WIP: Implemented joining public rooms
This commit is contained in:
parent
6d2ca070ea
commit
bed05eb52d
@ -51,23 +51,20 @@ void GlobalLobbyWindow::doSendChatMessage()
|
||||
void GlobalLobbyWindow::doCreateGameRoom()
|
||||
{
|
||||
GH.windows().createAndPushWindow<GlobalLobbyServerSetup>();
|
||||
// TODO:
|
||||
// start local server and supply our UUID / client credentials to it
|
||||
// server logs into lobby ( uuid = client, mode = server ). This creates 'room' in mode 'empty'
|
||||
// server starts accepting connections from players (including host)
|
||||
// client connects to local server
|
||||
// client sends createGameRoom query to lobby with own / server UUID and mode 'direct' (non-proxy)
|
||||
// client requests to change room status to private or public
|
||||
}
|
||||
|
||||
void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
|
||||
{
|
||||
|
||||
assert(0); // TODO
|
||||
}
|
||||
|
||||
void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
|
||||
{
|
||||
JsonNode toSend;
|
||||
toSend["type"].String() = "joinGameRoom";
|
||||
toSend["gameRoomID"].String() = roomID;
|
||||
|
||||
CSH->getGlobalLobby().sendMessage(toSend);
|
||||
}
|
||||
|
||||
void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
|
||||
|
@ -176,12 +176,18 @@ void LobbyDatabase::prepareStatements()
|
||||
WHERE status = 1
|
||||
)";
|
||||
|
||||
static const std::string countAccountsInRoomText = R"(
|
||||
static const std::string countRoomUsedSlotsText = R"(
|
||||
SELECT COUNT(accountID)
|
||||
FROM gameRoomPlayers
|
||||
WHERE roomID = ?
|
||||
)";
|
||||
|
||||
static const std::string countRoomTotalSlotsText = R"(
|
||||
SELECT playerLimit
|
||||
FROM gameRooms
|
||||
WHERE roomID = ?
|
||||
)";
|
||||
|
||||
static const std::string getAccountDisplayNameText = R"(
|
||||
SELECT displayName
|
||||
FROM accounts
|
||||
@ -245,7 +251,8 @@ void LobbyDatabase::prepareStatements()
|
||||
getActiveAccountsStatement = database->prepare(getActiveAccountsText);
|
||||
getActiveGameRoomsStatement = database->prepare(getActiveGameRoomsText);
|
||||
getAccountDisplayNameStatement = database->prepare(getAccountDisplayNameText);
|
||||
countAccountsInRoomStatement = database->prepare(countAccountsInRoomText);
|
||||
countRoomUsedSlotsStatement = database->prepare(countRoomUsedSlotsText);
|
||||
countRoomTotalSlotsStatement = database->prepare(countRoomTotalSlotsText);
|
||||
|
||||
isAccountCookieValidStatement = database->prepare(isAccountCookieValidText);
|
||||
isPlayerInGameRoomStatement = database->prepare(isPlayerInGameRoomText);
|
||||
@ -404,6 +411,22 @@ LobbyRoomState LobbyDatabase::getGameRoomStatus(const std::string & roomID)
|
||||
|
||||
uint32_t LobbyDatabase::getGameRoomFreeSlots(const std::string & roomID)
|
||||
{
|
||||
uint32_t usedSlots = 0;
|
||||
uint32_t totalSlots = 0;
|
||||
|
||||
countRoomUsedSlotsStatement->setBinds(roomID);
|
||||
if(countRoomUsedSlotsStatement->execute())
|
||||
countRoomUsedSlotsStatement->getColumns(usedSlots);
|
||||
countRoomUsedSlotsStatement->reset();
|
||||
|
||||
countRoomTotalSlotsStatement->setBinds(roomID);
|
||||
if(countRoomTotalSlotsStatement->execute())
|
||||
countRoomTotalSlotsStatement->getColumns(totalSlots);
|
||||
countRoomTotalSlotsStatement->reset();
|
||||
|
||||
|
||||
if (totalSlots > usedSlots)
|
||||
return totalSlots - usedSlots;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -443,10 +466,10 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
|
||||
|
||||
for (auto & room : result)
|
||||
{
|
||||
countAccountsInRoomStatement->setBinds(room.roomID);
|
||||
if(countAccountsInRoomStatement->execute())
|
||||
countAccountsInRoomStatement->getColumns(room.playersCount);
|
||||
countAccountsInRoomStatement->reset();
|
||||
countRoomUsedSlotsStatement->setBinds(room.roomID);
|
||||
if(countRoomUsedSlotsStatement->execute())
|
||||
countRoomUsedSlotsStatement->getColumns(room.playersCount);
|
||||
countRoomUsedSlotsStatement->reset();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ class LobbyDatabase
|
||||
SQLiteStatementPtr getActiveAccountsStatement;
|
||||
SQLiteStatementPtr getAccountGameRoomStatement;
|
||||
SQLiteStatementPtr getAccountDisplayNameStatement;
|
||||
SQLiteStatementPtr countAccountsInRoomStatement;
|
||||
SQLiteStatementPtr countRoomUsedSlotsStatement;
|
||||
SQLiteStatementPtr countRoomTotalSlotsStatement;
|
||||
|
||||
SQLiteStatementPtr isAccountCookieValidStatement;
|
||||
SQLiteStatementPtr isGameRoomCookieValidStatement;
|
||||
|
@ -485,6 +485,9 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
|
||||
|
||||
auto roomStatus = database->getGameRoomStatus(gameRoomID);
|
||||
|
||||
if(roomStatus != LobbyRoomState::PRIVATE && roomStatus != LobbyRoomState::PUBLIC)
|
||||
return;
|
||||
|
||||
if(roomStatus == LobbyRoomState::PRIVATE)
|
||||
{
|
||||
if(database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::INVITED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user