mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Formatting
This commit is contained in:
@@ -11,15 +11,15 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "GlobalLobbyClient.h"
|
#include "GlobalLobbyClient.h"
|
||||||
|
|
||||||
#include "GlobalLobbyWindow.h"
|
|
||||||
#include "GlobalLobbyLoginWindow.h"
|
#include "GlobalLobbyLoginWindow.h"
|
||||||
|
#include "GlobalLobbyWindow.h"
|
||||||
|
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/WindowHandler.h"
|
#include "../gui/WindowHandler.h"
|
||||||
#include "../windows/InfoWindows.h"
|
#include "../windows/InfoWindows.h"
|
||||||
|
|
||||||
#include "../../lib/MetaString.h"
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
#include "../../lib/MetaString.h"
|
||||||
#include "../../lib/TextOperations.h"
|
#include "../../lib/TextOperations.h"
|
||||||
#include "../../lib/network/NetworkClient.h"
|
#include "../../lib/network/NetworkClient.h"
|
||||||
|
|
||||||
@@ -52,32 +52,32 @@ void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<NetworkConnection
|
|||||||
|
|
||||||
JsonNode json(message.data(), message.size());
|
JsonNode json(message.data(), message.size());
|
||||||
|
|
||||||
if (json["type"].String() == "accountCreated")
|
if(json["type"].String() == "accountCreated")
|
||||||
return receiveAccountCreated(json);
|
return receiveAccountCreated(json);
|
||||||
|
|
||||||
if (json["type"].String() == "loginFailed")
|
if(json["type"].String() == "loginFailed")
|
||||||
return receiveLoginFailed(json);
|
return receiveLoginFailed(json);
|
||||||
|
|
||||||
if (json["type"].String() == "loginSuccess")
|
if(json["type"].String() == "loginSuccess")
|
||||||
return receiveLoginSuccess(json);
|
return receiveLoginSuccess(json);
|
||||||
|
|
||||||
if (json["type"].String() == "chatHistory")
|
if(json["type"].String() == "chatHistory")
|
||||||
return receiveChatHistory(json);
|
return receiveChatHistory(json);
|
||||||
|
|
||||||
if (json["type"].String() == "chatMessage")
|
if(json["type"].String() == "chatMessage")
|
||||||
return receiveChatMessage(json);
|
return receiveChatMessage(json);
|
||||||
|
|
||||||
if (json["type"].String() == "activeAccounts")
|
if(json["type"].String() == "activeAccounts")
|
||||||
return receiveActiveAccounts(json);
|
return receiveActiveAccounts(json);
|
||||||
|
|
||||||
throw std::runtime_error("Received unexpected message from lobby server: " + json["type"].String() );
|
throw std::runtime_error("Received unexpected message from lobby server: " + json["type"].String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlobalLobbyClient::receiveAccountCreated(const JsonNode & json)
|
void GlobalLobbyClient::receiveAccountCreated(const JsonNode & json)
|
||||||
{
|
{
|
||||||
auto loginWindowPtr = loginWindow.lock();
|
auto loginWindowPtr = loginWindow.lock();
|
||||||
|
|
||||||
if (!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
||||||
throw std::runtime_error("lobby connection finished without active login window!");
|
throw std::runtime_error("lobby connection finished without active login window!");
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -98,7 +98,7 @@ void GlobalLobbyClient::receiveLoginFailed(const JsonNode & json)
|
|||||||
{
|
{
|
||||||
auto loginWindowPtr = loginWindow.lock();
|
auto loginWindowPtr = loginWindow.lock();
|
||||||
|
|
||||||
if (!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
||||||
throw std::runtime_error("lobby connection finished without active login window!");
|
throw std::runtime_error("lobby connection finished without active login window!");
|
||||||
|
|
||||||
loginWindowPtr->onConnectionFailed(json["reason"].String());
|
loginWindowPtr->onConnectionFailed(json["reason"].String());
|
||||||
@@ -116,7 +116,7 @@ void GlobalLobbyClient::receiveLoginSuccess(const JsonNode & json)
|
|||||||
|
|
||||||
auto loginWindowPtr = loginWindow.lock();
|
auto loginWindowPtr = loginWindow.lock();
|
||||||
|
|
||||||
if (!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
||||||
throw std::runtime_error("lobby connection finished without active login window!");
|
throw std::runtime_error("lobby connection finished without active login window!");
|
||||||
|
|
||||||
loginWindowPtr->onConnectionSuccess();
|
loginWindowPtr->onConnectionSuccess();
|
||||||
@@ -124,7 +124,7 @@ void GlobalLobbyClient::receiveLoginSuccess(const JsonNode & json)
|
|||||||
|
|
||||||
void GlobalLobbyClient::receiveChatHistory(const JsonNode & json)
|
void GlobalLobbyClient::receiveChatHistory(const JsonNode & json)
|
||||||
{
|
{
|
||||||
for (auto const & entry : json["messages"].Vector())
|
for(const auto & entry : json["messages"].Vector())
|
||||||
{
|
{
|
||||||
std::string accountID = entry["accountID"].String();
|
std::string accountID = entry["accountID"].String();
|
||||||
std::string displayName = entry["displayName"].String();
|
std::string displayName = entry["displayName"].String();
|
||||||
@@ -164,7 +164,7 @@ void GlobalLobbyClient::onConnectionEstablished(const std::shared_ptr<NetworkCon
|
|||||||
|
|
||||||
std::string accountID = settings["lobby"]["accountID"].String();
|
std::string accountID = settings["lobby"]["accountID"].String();
|
||||||
|
|
||||||
if (accountID.empty())
|
if(accountID.empty())
|
||||||
sendClientRegister();
|
sendClientRegister();
|
||||||
else
|
else
|
||||||
sendClientLogin();
|
sendClientLogin();
|
||||||
@@ -191,7 +191,7 @@ void GlobalLobbyClient::onConnectionFailed(const std::string & errorMessage)
|
|||||||
{
|
{
|
||||||
auto loginWindowPtr = loginWindow.lock();
|
auto loginWindowPtr = loginWindow.lock();
|
||||||
|
|
||||||
if (!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
if(!loginWindowPtr || !GH.windows().topWindow<GlobalLobbyLoginWindow>())
|
||||||
throw std::runtime_error("lobby connection failed without active login window!");
|
throw std::runtime_error("lobby connection failed without active login window!");
|
||||||
|
|
||||||
logGlobal->warn("Connection to game lobby failed! Reason: %s", errorMessage);
|
logGlobal->warn("Connection to game lobby failed! Reason: %s", errorMessage);
|
||||||
@@ -214,7 +214,7 @@ void GlobalLobbyClient::sendMessage(const JsonNode & data)
|
|||||||
std::string payloadString = data.toJson(true);
|
std::string payloadString = data.toJson(true);
|
||||||
|
|
||||||
// FIXME: find better approach
|
// FIXME: find better approach
|
||||||
uint8_t * payloadBegin = reinterpret_cast<uint8_t*>(payloadString.data());
|
uint8_t * payloadBegin = reinterpret_cast<uint8_t *>(payloadString.data());
|
||||||
uint8_t * payloadEnd = payloadBegin + payloadString.size();
|
uint8_t * payloadEnd = payloadBegin + payloadString.size();
|
||||||
|
|
||||||
std::vector<uint8_t> payloadBuffer(payloadBegin, payloadEnd);
|
std::vector<uint8_t> payloadBuffer(payloadBegin, payloadEnd);
|
||||||
@@ -237,7 +237,7 @@ bool GlobalLobbyClient::isConnected()
|
|||||||
std::shared_ptr<GlobalLobbyLoginWindow> GlobalLobbyClient::createLoginWindow()
|
std::shared_ptr<GlobalLobbyLoginWindow> GlobalLobbyClient::createLoginWindow()
|
||||||
{
|
{
|
||||||
auto loginWindowPtr = loginWindow.lock();
|
auto loginWindowPtr = loginWindow.lock();
|
||||||
if (loginWindowPtr)
|
if(loginWindowPtr)
|
||||||
return loginWindowPtr;
|
return loginWindowPtr;
|
||||||
|
|
||||||
auto loginWindowNew = std::make_shared<GlobalLobbyLoginWindow>();
|
auto loginWindowNew = std::make_shared<GlobalLobbyLoginWindow>();
|
||||||
@@ -249,7 +249,7 @@ std::shared_ptr<GlobalLobbyLoginWindow> GlobalLobbyClient::createLoginWindow()
|
|||||||
std::shared_ptr<GlobalLobbyWindow> GlobalLobbyClient::createLobbyWindow()
|
std::shared_ptr<GlobalLobbyWindow> GlobalLobbyClient::createLobbyWindow()
|
||||||
{
|
{
|
||||||
auto lobbyWindowPtr = lobbyWindow.lock();
|
auto lobbyWindowPtr = lobbyWindow.lock();
|
||||||
if (lobbyWindowPtr)
|
if(lobbyWindowPtr)
|
||||||
return lobbyWindowPtr;
|
return lobbyWindowPtr;
|
||||||
|
|
||||||
lobbyWindowPtr = std::make_shared<GlobalLobbyWindow>();
|
lobbyWindowPtr = std::make_shared<GlobalLobbyWindow>();
|
||||||
@@ -257,4 +257,3 @@ std::shared_ptr<GlobalLobbyWindow> GlobalLobbyClient::createLobbyWindow()
|
|||||||
lobbyWindowLock = lobbyWindowPtr;
|
lobbyWindowLock = lobbyWindowPtr;
|
||||||
return lobbyWindowPtr;
|
return lobbyWindowPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class GlobalLobbyClient : public INetworkClientListener, boost::noncopyable
|
|||||||
void receiveChatHistory(const JsonNode & json);
|
void receiveChatHistory(const JsonNode & json);
|
||||||
void receiveChatMessage(const JsonNode & json);
|
void receiveChatMessage(const JsonNode & json);
|
||||||
void receiveActiveAccounts(const JsonNode & json);
|
void receiveActiveAccounts(const JsonNode & json);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GlobalLobbyClient();
|
explicit GlobalLobbyClient();
|
||||||
~GlobalLobbyClient();
|
~GlobalLobbyClient();
|
||||||
|
|||||||
@@ -14,18 +14,18 @@
|
|||||||
#include "GlobalLobbyClient.h"
|
#include "GlobalLobbyClient.h"
|
||||||
#include "GlobalLobbyWindow.h"
|
#include "GlobalLobbyWindow.h"
|
||||||
|
|
||||||
#include "../gui/CGuiHandler.h"
|
|
||||||
#include "../gui/WindowHandler.h"
|
|
||||||
#include "../widgets/TextControls.h"
|
|
||||||
#include "../widgets/Images.h"
|
|
||||||
#include "../widgets/Buttons.h"
|
|
||||||
#include "../widgets/MiscWidgets.h"
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CServerHandler.h"
|
#include "../CServerHandler.h"
|
||||||
|
#include "../gui/CGuiHandler.h"
|
||||||
|
#include "../gui/WindowHandler.h"
|
||||||
|
#include "../widgets/Buttons.h"
|
||||||
|
#include "../widgets/Images.h"
|
||||||
|
#include "../widgets/MiscWidgets.h"
|
||||||
|
#include "../widgets/TextControls.h"
|
||||||
|
|
||||||
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/MetaString.h"
|
#include "../../lib/MetaString.h"
|
||||||
#include "../../lib/CConfigHandler.h"
|
|
||||||
|
|
||||||
GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
|
GlobalLobbyLoginWindow::GlobalLobbyLoginWindow()
|
||||||
: CWindowObject(BORDERED)
|
: CWindowObject(BORDERED)
|
||||||
@@ -66,7 +66,7 @@ void GlobalLobbyLoginWindow::onLogin()
|
|||||||
config->String() = inputUsername->getText();
|
config->String() = inputUsername->getText();
|
||||||
|
|
||||||
labelStatus->setText(CGI->generaltexth->translate("vcmi.lobby.login.connecting"));
|
labelStatus->setText(CGI->generaltexth->translate("vcmi.lobby.login.connecting"));
|
||||||
if (!CSH->getGlobalLobby().isConnected())
|
if(!CSH->getGlobalLobby().isConnected())
|
||||||
CSH->getGlobalLobby().connect();
|
CSH->getGlobalLobby().connect();
|
||||||
buttonClose->block(true);
|
buttonClose->block(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,17 +11,17 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "GlobalLobbyServerSetup.h"
|
#include "GlobalLobbyServerSetup.h"
|
||||||
|
|
||||||
#include "../gui/CGuiHandler.h"
|
|
||||||
#include "../widgets/TextControls.h"
|
|
||||||
#include "../widgets/Images.h"
|
|
||||||
#include "../widgets/Buttons.h"
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
#include "../CServerHandler.h"
|
#include "../CServerHandler.h"
|
||||||
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../mainmenu/CMainMenu.h"
|
#include "../mainmenu/CMainMenu.h"
|
||||||
|
#include "../widgets/Buttons.h"
|
||||||
|
#include "../widgets/Images.h"
|
||||||
|
#include "../widgets/TextControls.h"
|
||||||
|
|
||||||
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/MetaString.h"
|
#include "../../lib/MetaString.h"
|
||||||
#include "../../lib/CConfigHandler.h"
|
|
||||||
|
|
||||||
GlobalLobbyServerSetup::GlobalLobbyServerSetup()
|
GlobalLobbyServerSetup::GlobalLobbyServerSetup()
|
||||||
: CWindowObject(BORDERED)
|
: CWindowObject(BORDERED)
|
||||||
@@ -85,12 +85,12 @@ void GlobalLobbyServerSetup::updateDescription()
|
|||||||
{
|
{
|
||||||
MetaString description;
|
MetaString description;
|
||||||
description.appendRawString("%s %s %s");
|
description.appendRawString("%s %s %s");
|
||||||
if (toggleRoomType->getSelected() == 0)
|
if(toggleRoomType->getSelected() == 0)
|
||||||
description.replaceTextID("vcmi.lobby.room.description.public");
|
description.replaceTextID("vcmi.lobby.room.description.public");
|
||||||
else
|
else
|
||||||
description.replaceTextID("vcmi.lobby.room.description.private");
|
description.replaceTextID("vcmi.lobby.room.description.private");
|
||||||
|
|
||||||
if (toggleGameMode->getSelected() == 0)
|
if(toggleGameMode->getSelected() == 0)
|
||||||
description.replaceTextID("vcmi.lobby.room.description.new");
|
description.replaceTextID("vcmi.lobby.room.description.new");
|
||||||
else
|
else
|
||||||
description.replaceTextID("vcmi.lobby.room.description.load");
|
description.replaceTextID("vcmi.lobby.room.description.load");
|
||||||
@@ -124,7 +124,7 @@ void GlobalLobbyServerSetup::onGameModeChanged(int value)
|
|||||||
|
|
||||||
void GlobalLobbyServerSetup::onCreate()
|
void GlobalLobbyServerSetup::onCreate()
|
||||||
{
|
{
|
||||||
if (toggleGameMode->getSelected() == 0)
|
if(toggleGameMode->getSelected() == 0)
|
||||||
{
|
{
|
||||||
CSH->resetStateForLobby(StartInfo::NEW_GAME, nullptr);
|
CSH->resetStateForLobby(StartInfo::NEW_GAME, nullptr);
|
||||||
CSH->screenType = ESelectionScreen::newGame;
|
CSH->screenType = ESelectionScreen::newGame;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class GlobalLobbyWindow;
|
|||||||
class GlobalLobbyWidget : public InterfaceObjectConfigurable
|
class GlobalLobbyWidget : public InterfaceObjectConfigurable
|
||||||
{
|
{
|
||||||
GlobalLobbyWindow * window;
|
GlobalLobbyWindow * window;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GlobalLobbyWidget(GlobalLobbyWindow * window);
|
GlobalLobbyWidget(GlobalLobbyWindow * window);
|
||||||
|
|
||||||
|
|||||||
@@ -11,20 +11,20 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "GlobalLobbyWindow.h"
|
#include "GlobalLobbyWindow.h"
|
||||||
|
|
||||||
#include "GlobalLobbyWidget.h"
|
|
||||||
#include "GlobalLobbyClient.h"
|
#include "GlobalLobbyClient.h"
|
||||||
#include "GlobalLobbyServerSetup.h"
|
#include "GlobalLobbyServerSetup.h"
|
||||||
|
#include "GlobalLobbyWidget.h"
|
||||||
|
|
||||||
|
#include "../CServerHandler.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/WindowHandler.h"
|
#include "../gui/WindowHandler.h"
|
||||||
#include "../widgets/TextControls.h"
|
#include "../widgets/TextControls.h"
|
||||||
#include "../CServerHandler.h"
|
|
||||||
|
|
||||||
#include "../../lib/MetaString.h"
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
|
#include "../../lib/MetaString.h"
|
||||||
|
|
||||||
GlobalLobbyWindow::GlobalLobbyWindow():
|
GlobalLobbyWindow::GlobalLobbyWindow()
|
||||||
CWindowObject(BORDERED)
|
: CWindowObject(BORDERED)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
widget = std::make_shared<GlobalLobbyWidget>(this);
|
widget = std::make_shared<GlobalLobbyWidget>(this);
|
||||||
|
|||||||
@@ -26,5 +26,4 @@ public:
|
|||||||
void doCreateGameRoom();
|
void doCreateGameRoom();
|
||||||
|
|
||||||
void onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when);
|
void onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ bool LobbyDatabase::isPlayerInGameRoom(const std::string & accountID)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
isPlayerInAnyGameRoomStatement->setBinds(accountID);
|
isPlayerInAnyGameRoomStatement->setBinds(accountID);
|
||||||
if (isPlayerInAnyGameRoomStatement->execute())
|
if(isPlayerInAnyGameRoomStatement->execute())
|
||||||
isPlayerInAnyGameRoomStatement->getColumns(result);
|
isPlayerInAnyGameRoomStatement->getColumns(result);
|
||||||
isPlayerInAnyGameRoomStatement->reset();
|
isPlayerInAnyGameRoomStatement->reset();
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ bool LobbyDatabase::isPlayerInGameRoom(const std::string & accountID, const std:
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
isPlayerInGameRoomStatement->setBinds(accountID, roomID);
|
isPlayerInGameRoomStatement->setBinds(accountID, roomID);
|
||||||
if (isPlayerInGameRoomStatement->execute())
|
if(isPlayerInGameRoomStatement->execute())
|
||||||
isPlayerInGameRoomStatement->getColumns(result);
|
isPlayerInGameRoomStatement->getColumns(result);
|
||||||
isPlayerInGameRoomStatement->reset();
|
isPlayerInGameRoomStatement->reset();
|
||||||
|
|
||||||
@@ -330,27 +330,18 @@ void LobbyDatabase::insertAccessCookie(const std::string & accountID, const std:
|
|||||||
insertAccessCookieStatement->executeOnce(accountID, accessCookieUUID);
|
insertAccessCookieStatement->executeOnce(accountID, accessCookieUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyDatabase::updateAccessCookie(const std::string & accountID, const std::string & accessCookieUUID)
|
void LobbyDatabase::updateAccessCookie(const std::string & accountID, const std::string & accessCookieUUID) {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
void LobbyDatabase::updateAccountLoginTime(const std::string & accountID) {}
|
||||||
|
|
||||||
void LobbyDatabase::updateAccountLoginTime(const std::string & accountID)
|
void LobbyDatabase::updateActiveAccount(const std::string & accountID, bool isActive) {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void LobbyDatabase::updateActiveAccount(const std::string & accountID, bool isActive)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string LobbyDatabase::getAccountDisplayName(const std::string & accountID)
|
std::string LobbyDatabase::getAccountDisplayName(const std::string & accountID)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
getAccountDisplayNameStatement->setBinds(accountID);
|
getAccountDisplayNameStatement->setBinds(accountID);
|
||||||
if (getAccountDisplayNameStatement->execute())
|
if(getAccountDisplayNameStatement->execute())
|
||||||
getAccountDisplayNameStatement->getColumns(result);
|
getAccountDisplayNameStatement->getColumns(result);
|
||||||
getAccountDisplayNameStatement->reset();
|
getAccountDisplayNameStatement->reset();
|
||||||
|
|
||||||
@@ -367,7 +358,7 @@ LobbyCookieStatus LobbyDatabase::getAccountCookieStatus(const std::string & acco
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
isAccountCookieValidStatement->setBinds(accountID, accessCookieUUID, cookieLifetime.count());
|
isAccountCookieValidStatement->setBinds(accountID, accessCookieUUID, cookieLifetime.count());
|
||||||
if (isAccountCookieValidStatement->execute())
|
if(isAccountCookieValidStatement->execute())
|
||||||
isAccountCookieValidStatement->getColumns(result);
|
isAccountCookieValidStatement->getColumns(result);
|
||||||
isAccountCookieValidStatement->reset();
|
isAccountCookieValidStatement->reset();
|
||||||
|
|
||||||
@@ -394,7 +385,7 @@ bool LobbyDatabase::isAccountNameExists(const std::string & displayName)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
isAccountNameExistsStatement->setBinds(displayName);
|
isAccountNameExistsStatement->setBinds(displayName);
|
||||||
if (isAccountNameExistsStatement->execute())
|
if(isAccountNameExistsStatement->execute())
|
||||||
isAccountNameExistsStatement->getColumns(result);
|
isAccountNameExistsStatement->getColumns(result);
|
||||||
isAccountNameExistsStatement->reset();
|
isAccountNameExistsStatement->reset();
|
||||||
return result;
|
return result;
|
||||||
@@ -405,7 +396,7 @@ bool LobbyDatabase::isAccountIDExists(const std::string & accountID)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
isAccountIDExistsStatement->setBinds(accountID);
|
isAccountIDExistsStatement->setBinds(accountID);
|
||||||
if (isAccountIDExistsStatement->execute())
|
if(isAccountIDExistsStatement->execute())
|
||||||
isAccountIDExistsStatement->getColumns(result);
|
isAccountIDExistsStatement->getColumns(result);
|
||||||
isAccountIDExistsStatement->reset();
|
isAccountIDExistsStatement->reset();
|
||||||
return result;
|
return result;
|
||||||
@@ -434,7 +425,7 @@ std::string LobbyDatabase::getIdleGameRoom(const std::string & hostAccountID)
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
if (getIdleGameRoomStatement->execute())
|
if(getIdleGameRoomStatement->execute())
|
||||||
getIdleGameRoomStatement->getColumns(result);
|
getIdleGameRoomStatement->getColumns(result);
|
||||||
|
|
||||||
getIdleGameRoomStatement->reset();
|
getIdleGameRoomStatement->reset();
|
||||||
@@ -445,7 +436,7 @@ std::string LobbyDatabase::getAccountGameRoom(const std::string & accountID)
|
|||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
if (getAccountGameRoomStatement->execute())
|
if(getAccountGameRoomStatement->execute())
|
||||||
getAccountGameRoomStatement->getColumns(result);
|
getAccountGameRoomStatement->getColumns(result);
|
||||||
|
|
||||||
getAccountGameRoomStatement->reset();
|
getAccountGameRoomStatement->reset();
|
||||||
|
|||||||
@@ -48,9 +48,9 @@ enum class LobbyInviteStatus : int32_t
|
|||||||
|
|
||||||
enum class LobbyRoomState : int32_t
|
enum class LobbyRoomState : int32_t
|
||||||
{
|
{
|
||||||
IDLE, // server is ready but no players are in the room
|
IDLE, // server is ready but no players are in the room
|
||||||
PUBLIC, // host has joined and allows anybody to join
|
PUBLIC, // host has joined and allows anybody to join
|
||||||
PRIVATE, // host has joined but only allows those he invited to join
|
PRIVATE, // host has joined but only allows those he invited to join
|
||||||
//BUSY, // match is ongoing
|
//BUSY, // match is ongoing
|
||||||
//CANCELLED, // game room was cancelled without starting the game
|
//CANCELLED, // game room was cancelled without starting the game
|
||||||
//CLOSED, // game room was closed after playing for some time
|
//CLOSED, // game room was closed after playing for some time
|
||||||
|
|||||||
@@ -13,24 +13,24 @@
|
|||||||
#include "LobbyDatabase.h"
|
#include "LobbyDatabase.h"
|
||||||
|
|
||||||
#include "../lib/JsonNode.h"
|
#include "../lib/JsonNode.h"
|
||||||
#include "../lib/network/NetworkServer.h"
|
|
||||||
#include "../lib/network/NetworkConnection.h"
|
#include "../lib/network/NetworkConnection.h"
|
||||||
|
#include "../lib/network/NetworkServer.h"
|
||||||
|
|
||||||
#include <boost/uuid/uuid_io.hpp>
|
|
||||||
#include <boost/uuid/uuid_generators.hpp>
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
static const auto accountCookieLifetime = std::chrono::hours(24*7);
|
static const auto accountCookieLifetime = std::chrono::hours(24 * 7);
|
||||||
|
|
||||||
bool LobbyServer::isAccountNameValid(const std::string & accountName)
|
bool LobbyServer::isAccountNameValid(const std::string & accountName)
|
||||||
{
|
{
|
||||||
if (accountName.size() < 4)
|
if(accountName.size() < 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (accountName.size() < 20)
|
if(accountName.size() < 20)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (auto const & c : accountName)
|
for(const auto & c : accountName)
|
||||||
if (!std::isalnum(c))
|
if(!std::isalnum(c))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -44,8 +44,8 @@ std::string LobbyServer::sanitizeChatMessage(const std::string & inputString) co
|
|||||||
|
|
||||||
NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID)
|
NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID)
|
||||||
{
|
{
|
||||||
for (auto const & account : activeAccounts)
|
for(const auto & account : activeAccounts)
|
||||||
if (account.second.accountID == accountID)
|
if(account.second.accountID == accountID)
|
||||||
return account.first;
|
return account.first;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -53,8 +53,8 @@ NetworkConnectionPtr LobbyServer::findAccount(const std::string & accountID)
|
|||||||
|
|
||||||
NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID)
|
NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID)
|
||||||
{
|
{
|
||||||
for (auto const & account : activeGameRooms)
|
for(const auto & account : activeGameRooms)
|
||||||
if (account.second.roomID == gameRoomID)
|
if(account.second.roomID == gameRoomID)
|
||||||
return account.first;
|
return account.first;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -105,7 +105,7 @@ void LobbyServer::sendLoginSuccess(const NetworkConnectionPtr & target, const st
|
|||||||
JsonNode reply;
|
JsonNode reply;
|
||||||
reply["type"].String() = "loginSuccess";
|
reply["type"].String() = "loginSuccess";
|
||||||
reply["accountCookie"].String() = accountCookie;
|
reply["accountCookie"].String() = accountCookie;
|
||||||
if (!displayName.empty())
|
if(!displayName.empty())
|
||||||
reply["displayName"].String() = displayName;
|
reply["displayName"].String() = displayName;
|
||||||
sendMessage(target, reply);
|
sendMessage(target, reply);
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ void LobbyServer::broadcastActiveAccounts()
|
|||||||
JsonNode jsonEntry;
|
JsonNode jsonEntry;
|
||||||
jsonEntry["accountID"].String() = account.accountID;
|
jsonEntry["accountID"].String() = account.accountID;
|
||||||
jsonEntry["displayName"].String() = account.displayName;
|
jsonEntry["displayName"].String() = account.displayName;
|
||||||
// jsonEntry["status"].String() = account.status;
|
// jsonEntry["status"].String() = account.status;
|
||||||
reply["accounts"].Vector().push_back(jsonEntry);
|
reply["accounts"].Vector().push_back(jsonEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,10 +224,10 @@ void LobbyServer::onDisconnected(const NetworkConnectionPtr & connection)
|
|||||||
void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, const std::vector<uint8_t> & message)
|
void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, const std::vector<uint8_t> & message)
|
||||||
{
|
{
|
||||||
// proxy connection - no processing, only redirect
|
// proxy connection - no processing, only redirect
|
||||||
if (activeProxies.count(connection))
|
if(activeProxies.count(connection))
|
||||||
{
|
{
|
||||||
auto lockedPtr = activeProxies.at(connection).lock();
|
auto lockedPtr = activeProxies.at(connection).lock();
|
||||||
if (lockedPtr)
|
if(lockedPtr)
|
||||||
lockedPtr->sendPacket(message);
|
lockedPtr->sendPacket(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -238,7 +238,7 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
|
|||||||
// TODO: validate json based on received message type
|
// TODO: validate json based on received message type
|
||||||
|
|
||||||
// communication messages from vcmiclient
|
// communication messages from vcmiclient
|
||||||
if (activeAccounts.count(connection))
|
if(activeAccounts.count(connection))
|
||||||
{
|
{
|
||||||
if(json["type"].String() == "sendChatMessage")
|
if(json["type"].String() == "sendChatMessage")
|
||||||
return receiveSendChatMessage(connection, json);
|
return receiveSendChatMessage(connection, json);
|
||||||
@@ -259,7 +259,7 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// communication messages from vcmiserver
|
// communication messages from vcmiserver
|
||||||
if (activeGameRooms.count(connection))
|
if(activeGameRooms.count(connection))
|
||||||
{
|
{
|
||||||
if(json["type"].String() == "leaveGameRoom")
|
if(json["type"].String() == "leaveGameRoom")
|
||||||
return receiveLeaveGameRoom(connection, json);
|
return receiveLeaveGameRoom(connection, json);
|
||||||
@@ -294,7 +294,7 @@ void LobbyServer::receiveSendChatMessage(const NetworkConnectionPtr & connection
|
|||||||
std::string messageTextClean = sanitizeChatMessage(messageText);
|
std::string messageTextClean = sanitizeChatMessage(messageText);
|
||||||
std::string displayName = database->getAccountDisplayName(accountID);
|
std::string displayName = database->getAccountDisplayName(accountID);
|
||||||
|
|
||||||
if (messageTextClean.empty())
|
if(messageTextClean.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
database->insertChatMessage(accountID, "global", "english", messageText);
|
database->insertChatMessage(accountID, "global", "english", messageText);
|
||||||
@@ -308,10 +308,10 @@ void LobbyServer::receiveClientRegister(const NetworkConnectionPtr & connection,
|
|||||||
std::string displayName = json["displayName"].String();
|
std::string displayName = json["displayName"].String();
|
||||||
std::string language = json["language"].String();
|
std::string language = json["language"].String();
|
||||||
|
|
||||||
if (isAccountNameValid(displayName))
|
if(isAccountNameValid(displayName))
|
||||||
return sendLoginFailed(connection, "Illegal account name");
|
return sendLoginFailed(connection, "Illegal account name");
|
||||||
|
|
||||||
if (database->isAccountNameExists(displayName))
|
if(database->isAccountNameExists(displayName))
|
||||||
return sendLoginFailed(connection, "Account name already in use");
|
return sendLoginFailed(connection, "Account name already in use");
|
||||||
|
|
||||||
std::string accountCookie = boost::uuids::to_string(boost::uuids::random_generator()());
|
std::string accountCookie = boost::uuids::to_string(boost::uuids::random_generator()());
|
||||||
@@ -330,12 +330,12 @@ void LobbyServer::receiveClientLogin(const NetworkConnectionPtr & connection, co
|
|||||||
std::string language = json["language"].String();
|
std::string language = json["language"].String();
|
||||||
std::string version = json["version"].String();
|
std::string version = json["version"].String();
|
||||||
|
|
||||||
if (!database->isAccountIDExists(accountID))
|
if(!database->isAccountIDExists(accountID))
|
||||||
return sendLoginFailed(connection, "Account not found");
|
return sendLoginFailed(connection, "Account not found");
|
||||||
|
|
||||||
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
||||||
|
|
||||||
if (clientCookieStatus == LobbyCookieStatus::INVALID)
|
if(clientCookieStatus == LobbyCookieStatus::INVALID)
|
||||||
return sendLoginFailed(connection, "Authentification failure");
|
return sendLoginFailed(connection, "Authentification failure");
|
||||||
|
|
||||||
// prolong existing cookie
|
// prolong existing cookie
|
||||||
@@ -366,7 +366,7 @@ void LobbyServer::receiveServerLogin(const NetworkConnectionPtr & connection, co
|
|||||||
|
|
||||||
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
||||||
|
|
||||||
if (clientCookieStatus == LobbyCookieStatus::INVALID)
|
if(clientCookieStatus == LobbyCookieStatus::INVALID)
|
||||||
{
|
{
|
||||||
sendLoginFailed(connection, "Invalid credentials");
|
sendLoginFailed(connection, "Invalid credentials");
|
||||||
}
|
}
|
||||||
@@ -386,20 +386,20 @@ void LobbyServer::receiveClientProxyLogin(const NetworkConnectionPtr & connectio
|
|||||||
|
|
||||||
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
auto clientCookieStatus = database->getAccountCookieStatus(accountID, accountCookie, accountCookieLifetime);
|
||||||
|
|
||||||
if (clientCookieStatus != LobbyCookieStatus::INVALID)
|
if(clientCookieStatus != LobbyCookieStatus::INVALID)
|
||||||
{
|
{
|
||||||
for (auto & proxyEntry : awaitingProxies)
|
for(auto & proxyEntry : awaitingProxies)
|
||||||
{
|
{
|
||||||
if (proxyEntry.accountID != accountID)
|
if(proxyEntry.accountID != accountID)
|
||||||
continue;
|
continue;
|
||||||
if (proxyEntry.roomID != gameRoomID)
|
if(proxyEntry.roomID != gameRoomID)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
proxyEntry.accountConnection = connection;
|
proxyEntry.accountConnection = connection;
|
||||||
|
|
||||||
auto gameRoomConnection = proxyEntry.roomConnection.lock();
|
auto gameRoomConnection = proxyEntry.roomConnection.lock();
|
||||||
|
|
||||||
if (gameRoomConnection)
|
if(gameRoomConnection)
|
||||||
{
|
{
|
||||||
activeProxies[gameRoomConnection] = connection;
|
activeProxies[gameRoomConnection] = connection;
|
||||||
activeProxies[connection] = gameRoomConnection;
|
activeProxies[connection] = gameRoomConnection;
|
||||||
@@ -419,11 +419,11 @@ void LobbyServer::receiveServerProxyLogin(const NetworkConnectionPtr & connectio
|
|||||||
|
|
||||||
auto clientCookieStatus = database->getGameRoomCookieStatus(gameRoomID, hostCookie, accountCookieLifetime);
|
auto clientCookieStatus = database->getGameRoomCookieStatus(gameRoomID, hostCookie, accountCookieLifetime);
|
||||||
|
|
||||||
if (clientCookieStatus != LobbyCookieStatus::INVALID)
|
if(clientCookieStatus != LobbyCookieStatus::INVALID)
|
||||||
{
|
{
|
||||||
NetworkConnectionPtr targetAccount = findAccount(guestAccountID);
|
NetworkConnectionPtr targetAccount = findAccount(guestAccountID);
|
||||||
|
|
||||||
if (targetAccount == nullptr)
|
if(targetAccount == nullptr)
|
||||||
return; // unknown / disconnected account
|
return; // unknown / disconnected account
|
||||||
|
|
||||||
sendJoinRoomSuccess(targetAccount, gameRoomID);
|
sendJoinRoomSuccess(targetAccount, gameRoomID);
|
||||||
@@ -448,13 +448,13 @@ void LobbyServer::receiveOpenGameRoom(const NetworkConnectionPtr & connection, c
|
|||||||
return; // only 1 room per player allowed
|
return; // only 1 room per player allowed
|
||||||
|
|
||||||
std::string gameRoomID = database->getIdleGameRoom(hostAccountID);
|
std::string gameRoomID = database->getIdleGameRoom(hostAccountID);
|
||||||
if (gameRoomID.empty())
|
if(gameRoomID.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string roomType = json["roomType"].String();
|
std::string roomType = json["roomType"].String();
|
||||||
if (roomType == "public")
|
if(roomType == "public")
|
||||||
database->setGameRoomStatus(gameRoomID, LobbyRoomState::PUBLIC);
|
database->setGameRoomStatus(gameRoomID, LobbyRoomState::PUBLIC);
|
||||||
if (roomType == "private")
|
if(roomType == "private")
|
||||||
database->setGameRoomStatus(gameRoomID, LobbyRoomState::PRIVATE);
|
database->setGameRoomStatus(gameRoomID, LobbyRoomState::PRIVATE);
|
||||||
|
|
||||||
// TODO: additional flags / initial settings, e.g. allowCheats
|
// TODO: additional flags / initial settings, e.g. allowCheats
|
||||||
@@ -474,18 +474,18 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
|
|||||||
|
|
||||||
NetworkConnectionPtr targetRoom = findGameRoom(gameRoomID);
|
NetworkConnectionPtr targetRoom = findGameRoom(gameRoomID);
|
||||||
|
|
||||||
if (targetRoom == nullptr)
|
if(targetRoom == nullptr)
|
||||||
return; // unknown / disconnected room
|
return; // unknown / disconnected room
|
||||||
|
|
||||||
auto roomStatus = database->getGameRoomStatus(gameRoomID);
|
auto roomStatus = database->getGameRoomStatus(gameRoomID);
|
||||||
|
|
||||||
if (roomStatus == LobbyRoomState::PRIVATE)
|
if(roomStatus == LobbyRoomState::PRIVATE)
|
||||||
{
|
{
|
||||||
if (database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::INVITED)
|
if(database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::INVITED)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (database->getGameRoomFreeSlots(gameRoomID) == 0)
|
if(database->getGameRoomFreeSlots(gameRoomID) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sendAccountJoinsRoom(targetRoom, accountID);
|
sendAccountJoinsRoom(targetRoom, accountID);
|
||||||
@@ -513,7 +513,7 @@ void LobbyServer::receiveSendInvite(const NetworkConnectionPtr & connection, con
|
|||||||
|
|
||||||
auto targetAccount = findAccount(accountID);
|
auto targetAccount = findAccount(accountID);
|
||||||
|
|
||||||
if (!targetAccount)
|
if(!targetAccount)
|
||||||
return; // target player does not exists or offline
|
return; // target player does not exists or offline
|
||||||
|
|
||||||
if(!database->isPlayerInGameRoom(senderName))
|
if(!database->isPlayerInGameRoom(senderName))
|
||||||
@@ -522,7 +522,7 @@ void LobbyServer::receiveSendInvite(const NetworkConnectionPtr & connection, con
|
|||||||
if(database->isPlayerInGameRoom(accountID))
|
if(database->isPlayerInGameRoom(accountID))
|
||||||
return; // target player is busy
|
return; // target player is busy
|
||||||
|
|
||||||
if (database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::NOT_INVITED)
|
if(database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::NOT_INVITED)
|
||||||
return; // already has invite
|
return; // already has invite
|
||||||
|
|
||||||
database->insertGameRoomInvite(accountID, gameRoomID);
|
database->insertGameRoomInvite(accountID, gameRoomID);
|
||||||
@@ -534,7 +534,7 @@ void LobbyServer::receiveDeclineInvite(const NetworkConnectionPtr & connection,
|
|||||||
std::string accountID = activeAccounts[connection].accountID;
|
std::string accountID = activeAccounts[connection].accountID;
|
||||||
std::string gameRoomID = json["gameRoomID"].String();
|
std::string gameRoomID = json["gameRoomID"].String();
|
||||||
|
|
||||||
if (database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::INVITED)
|
if(database->getAccountInviteStatus(accountID, gameRoomID) != LobbyInviteStatus::INVITED)
|
||||||
return; // already has invite
|
return; // already has invite
|
||||||
|
|
||||||
database->deleteGameRoomInvite(accountID, gameRoomID);
|
database->deleteGameRoomInvite(accountID, gameRoomID);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "LobbyDefines.h"
|
|
||||||
#include "../lib/network/NetworkListener.h"
|
#include "../lib/network/NetworkListener.h"
|
||||||
|
#include "LobbyDefines.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
class JsonNode;
|
class JsonNode;
|
||||||
|
|||||||
Reference in New Issue
Block a user