1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Split CConnection into GameConnection and IGameConnection classes

This commit is contained in:
Ivan Savenko
2025-06-26 17:15:36 +03:00
parent 790c5cb455
commit 58de180083
21 changed files with 133 additions and 93 deletions

View File

@@ -48,8 +48,7 @@
#include "../lib/mapObjects/MiscObjects.h"
#include "../lib/modding/ModIncompatibility.h"
#include "../lib/rmg/CMapGenOptions.h"
#include "../lib/serializer/Connection.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/serializer/GameConnection.h"
#include "../lib/UnlockGuard.h"
#include <boost/uuid/uuid.hpp>
@@ -269,7 +268,7 @@ void CServerHandler::onConnectionEstablished(const NetworkConnectionPtr & netCon
getGlobalLobby().sendProxyConnectionLogin(netConnection);
}
logicConnection = std::make_shared<CConnection>(netConnection);
logicConnection = std::make_shared<GameConnection>(netConnection);
logicConnection->uuid = uuid;
logicConnection->enterLobbyConnectionMode();
sendClientConnecting();

View File

@@ -17,7 +17,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CConnection;
class GameConnection;
class PlayerColor;
struct StartInfo;
struct TurnTimerInfo;
@@ -125,7 +125,7 @@ class CServerHandler final : public IServerAPI, public LobbyInfo, public INetwor
public:
/// High-level connection overlay that is capable of (de)serializing network data
std::shared_ptr<CConnection> logicConnection;
std::shared_ptr<GameConnection> logicConnection;
////////////////////
// FIXME: Bunch of crutches to glue it all together

View File

@@ -30,16 +30,16 @@
#include "../lib/callback/CDynLibHandler.h"
#include "../lib/callback/CGlobalAI.h"
#include "../lib/callback/IGameInfoCallback.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/gameState/CGameState.h"
#include "../lib/CPlayerState.h"
#include "../lib/CThreadHelper.h"
#include "../lib/VCMIDirs.h"
#include "../lib/UnlockGuard.h"
#include "../lib/serializer/Connection.h"
#include "../lib/mapObjects/army/CArmedInstance.h"
#include "../lib/mapping/CMapService.h"
#include "../lib/pathfinder/CGPathNode.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/serializer/GameConnection.h"
#include <memory>
#include <vcmi/events/EventBus.h>
@@ -125,7 +125,6 @@ events::EventBus * CClient::eventBus() const
void CClient::newGame(std::shared_ptr<CGameState> initializedGameState)
{
GAME->server().th->update();
CMapService mapService;
assert(initializedGameState);
gamestate = initializedGameState;
gamestate->preInit(LIBRARY);
@@ -148,9 +147,7 @@ void CClient::loadGame(std::shared_ptr<CGameState> initializedGameState)
logNetwork->info("Game loaded, initialize interfaces.");
initMapHandler();
reinitScripting();
initPlayerEnvironments();
initPlayerInterfaces();
}

View File

@@ -38,9 +38,9 @@
#include "../lib/modding/CModHandler.h"
#include "../lib/modding/ContentTypeHandler.h"
#include "../lib/modding/ModUtility.h"
#include "../lib/serializer/GameConnection.h"
#include "../lib/VCMIDirs.h"
#include "../lib/logging/VisualLogger.h"
#include "../lib/serializer/Connection.h"
#ifdef SCRIPTING_ENABLED
#include "../lib/ScriptHandler.h"

View File

@@ -31,7 +31,6 @@
#include "../lib/callback/CCallback.h"
#include "../lib/filesystem/Filesystem.h"
#include "../lib/filesystem/FileInfo.h"
#include "../lib/serializer/Connection.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/GameLibrary.h"
#include "../lib/mapping/CMap.h"
@@ -44,6 +43,7 @@
#include "../lib/mapObjects/CGMarket.h"
#include "../lib/mapObjects/CGTownInstance.h"
#include "../lib/gameState/CGameState.h"
#include "../lib/serializer/GameConnection.h"
#include "../lib/CStack.h"
#include "../lib/battle/BattleInfo.h"
#include "../lib/GameConstants.h"

View File

@@ -36,9 +36,9 @@
#include "windows/GUIClasses.h"
#include "../lib/CConfigHandler.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include "../lib/serializer/Connection.h"
#include "../lib/campaign/CampaignState.h"
#include "../lib/serializer/GameConnection.h"
#include "../lib/texts/CGeneralTextHandler.h"
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientConnected & pack)
{

View File

@@ -246,7 +246,7 @@ set(lib_MAIN_SRCS
serializer/CLoadFile.cpp
serializer/CMemorySerializer.cpp
serializer/Connection.cpp
serializer/GameConnection.cpp
serializer/CSaveFile.cpp
serializer/CTypeList.cpp
serializer/JsonDeserializer.cpp
@@ -705,10 +705,11 @@ set(lib_MAIN_HEADERS
serializer/BinarySerializer.h
serializer/CLoadFile.h
serializer/CMemorySerializer.h
serializer/Connection.h
serializer/GameConnection.h
serializer/CSaveFile.h
serializer/CSerializer.h
serializer/CTypeList.h
serializer/IGameConnection.h
serializer/JsonDeserializer.h
serializer/JsonSerializeFormat.h
serializer/JsonSerializer.h

View File

@@ -15,8 +15,6 @@
VCMI_LIB_NAMESPACE_BEGIN
class CGameState;
class CConnection;
class ICPackVisitor;
struct DLL_LINKAGE CPack : public Serializeable

View File

@@ -1,5 +1,5 @@
/*
* Connection.cpp, part of VCMI engine
* GameConnection.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@@ -8,7 +8,7 @@
*
*/
#include "StdInc.h"
#include "Connection.h"
#include "GameConnection.h"
#include "BinaryDeserializer.h"
#include "BinarySerializer.h"
@@ -52,7 +52,7 @@ int ConnectionPackReader::read(std::byte * data, unsigned size)
return size;
}
CConnection::CConnection(std::weak_ptr<INetworkConnection> networkConnection)
GameConnection::GameConnection(std::weak_ptr<INetworkConnection> networkConnection)
: networkConnection(networkConnection)
, packReader(std::make_unique<ConnectionPackReader>())
, packWriter(std::make_unique<ConnectionPackWriter>())
@@ -66,9 +66,14 @@ CConnection::CConnection(std::weak_ptr<INetworkConnection> networkConnection)
deserializer->version = ESerializationVersion::CURRENT;
}
CConnection::~CConnection() = default;
GameConnection::~GameConnection() = default;
void CConnection::sendPack(const CPack & pack)
int GameConnection::getConnectionID() const
{
return connectionID;
}
void GameConnection::sendPack(const CPack & pack)
{
std::scoped_lock lock(writeMutex);
@@ -87,7 +92,7 @@ void CConnection::sendPack(const CPack & pack)
serializer->clear();
}
std::unique_ptr<CPack> CConnection::retrievePack(const std::vector<std::byte> & data)
std::unique_ptr<CPack> GameConnection::retrievePack(const std::vector<std::byte> & data)
{
std::unique_ptr<CPack> result;
@@ -108,28 +113,28 @@ std::unique_ptr<CPack> CConnection::retrievePack(const std::vector<std::byte> &
return result;
}
bool CConnection::isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const
bool GameConnection::isMyConnection(const std::shared_ptr<INetworkConnection> & otherConnection) const
{
return otherConnection != nullptr && networkConnection.lock() == otherConnection;
}
std::shared_ptr<INetworkConnection> CConnection::getConnection()
std::shared_ptr<INetworkConnection> GameConnection::getConnection()
{
return networkConnection.lock();
}
void CConnection::enterLobbyConnectionMode()
void GameConnection::enterLobbyConnectionMode()
{
deserializer->clear();
serializer->clear();
}
void CConnection::setCallback(IGameInfoCallback & cb)
void GameConnection::setCallback(IGameInfoCallback & cb)
{
deserializer->cb = &cb;
}
void CConnection::setSerializationVersion(ESerializationVersion version)
void GameConnection::setSerializationVersion(ESerializationVersion version)
{
deserializer->version = version;
serializer->version = version;

View File

@@ -1,5 +1,5 @@
/*
* Connection.h, part of VCMI engine
* GameConnection.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
@@ -9,6 +9,8 @@
*/
#pragma once
#include "IGameConnection.h"
enum class ESerializationVersion : int32_t;
VCMI_LIB_NAMESPACE_BEGIN
@@ -24,7 +26,7 @@ class IGameInfoCallback;
/// Wrapper class for game connection
/// Handles serialization and deserialization of data received from network
class DLL_LINKAGE CConnection : boost::noncopyable
class DLL_LINKAGE GameConnection final : public IGameConnection
{
/// Non-owning pointer to underlying connection
std::weak_ptr<INetworkConnection> networkConnection;
@@ -43,10 +45,11 @@ public:
std::string uuid;
int connectionID;
explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
~CConnection();
explicit GameConnection(std::weak_ptr<INetworkConnection> networkConnection);
~GameConnection();
void sendPack(const CPack & pack);
void sendPack(const CPack & pack) override;
int getConnectionID() const override;
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
void enterLobbyConnectionMode();

View File

@@ -0,0 +1,23 @@
/*
* IConnection.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
VCMI_LIB_NAMESPACE_BEGIN
struct CPack;
class DLL_LINKAGE IGameConnection : boost::noncopyable
{
public:
virtual void sendPack(const CPack & pack) = 0;
virtual int getConnectionID() const = 0;
};
VCMI_LIB_NAMESPACE_END

View File

@@ -75,7 +75,7 @@
#include "../lib/serializer/CSaveFile.h"
#include "../lib/serializer/CLoadFile.h"
#include "../lib/serializer/Connection.h"
#include "../lib/serializer/IGameConnection.h"
#include "../lib/spells/CSpellHandler.h"
@@ -437,7 +437,7 @@ void CGameHandler::changeSecSkill(const CGHeroInstance * hero, SecondarySkill wh
}
void CGameHandler::handleClientDisconnection(const std::shared_ptr<CConnection> & c)
void CGameHandler::handleClientDisconnection(const std::shared_ptr<IGameConnection> & c)
{
if(gameServer().getState() == EServerState::SHUTDOWN || !gameState().getStartInfo())
{
@@ -474,7 +474,7 @@ void CGameHandler::handleClientDisconnection(const std::shared_ptr<CConnection>
}
}
void CGameHandler::handleReceivedPack(std::shared_ptr<CConnection> connection, CPackForServer & pack)
void CGameHandler::handleReceivedPack(std::shared_ptr<IGameConnection> connection, CPackForServer & pack)
{
//prepare struct informing that action was applied
auto sendPackageResponse = [&](bool successfullyApplied)
@@ -524,6 +524,13 @@ void CGameHandler::handleReceivedPack(std::shared_ptr<CConnection> connection, C
}
}
CGameHandler::CGameHandler(IGameServer & server, const std::shared_ptr<CGameState> & initialGamestate)
:CGameHandler(server)
{
gs = initialGamestate;
randomizer = std::make_unique<GameRandomizer>(*gs);
}
CGameHandler::CGameHandler(IGameServer & server)
: server(server)
, heroPool(std::make_unique<HeroPoolProcessor>(this))
@@ -1529,12 +1536,12 @@ void CGameHandler::sendAndApply(NewStructures & pack)
checkVictoryLossConditionsForPlayer(gameInfo().getTown(pack.tid)->tempOwner);
}
bool CGameHandler::isPlayerOwns(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, ObjectInstanceID id)
bool CGameHandler::isPlayerOwns(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, ObjectInstanceID id)
{
return pack->player == gameState().getOwner(id) && hasPlayerAt(gameState().getOwner(id), connection);
}
void CGameHandler::throwNotAllowedAction(const std::shared_ptr<CConnection> & connection)
void CGameHandler::throwNotAllowedAction(const std::shared_ptr<IGameConnection> & connection)
{
playerMessages->sendSystemMessage(connection, MetaString::createFromTextID("vcmi.server.errors.notAllowed"));
@@ -1542,7 +1549,7 @@ void CGameHandler::throwNotAllowedAction(const std::shared_ptr<CConnection> & co
throw ExceptionNotAllowedAction();
}
void CGameHandler::wrongPlayerMessage(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, PlayerColor expectedplayer)
void CGameHandler::wrongPlayerMessage(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, PlayerColor expectedplayer)
{
auto str = MetaString::createFromTextID("vcmi.server.errors.wrongIdentified");
str.replaceName(pack->player);
@@ -1552,7 +1559,7 @@ void CGameHandler::wrongPlayerMessage(const std::shared_ptr<CConnection> & conne
playerMessages->sendSystemMessage(connection, str);
}
void CGameHandler::throwIfWrongOwner(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, ObjectInstanceID id)
void CGameHandler::throwIfWrongOwner(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, ObjectInstanceID id)
{
if(!isPlayerOwns(connection, pack, id))
{
@@ -1561,18 +1568,18 @@ void CGameHandler::throwIfWrongOwner(const std::shared_ptr<CConnection> & connec
}
}
void CGameHandler::throwIfPlayerNotActive(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack)
void CGameHandler::throwIfPlayerNotActive(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack)
{
if (!turnOrder->isPlayerMakingTurn(pack->player))
throwNotAllowedAction(connection);
}
void CGameHandler::throwIfWrongPlayer(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack)
void CGameHandler::throwIfWrongPlayer(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack)
{
throwIfWrongPlayer(connection, pack, pack->player);
}
void CGameHandler::throwIfWrongPlayer(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, PlayerColor player)
void CGameHandler::throwIfWrongPlayer(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, PlayerColor player)
{
if(!hasPlayerAt(player, connection) || pack->player != player)
{
@@ -1581,7 +1588,7 @@ void CGameHandler::throwIfWrongPlayer(const std::shared_ptr<CConnection> & conne
}
}
void CGameHandler::throwAndComplain(const std::shared_ptr<CConnection> & connection, const std::string & txt)
void CGameHandler::throwAndComplain(const std::shared_ptr<IGameConnection> & connection, const std::string & txt)
{
complain(txt);
throwNotAllowedAction(connection);
@@ -2038,7 +2045,7 @@ bool CGameHandler::arrangeStacks(ObjectInstanceID id1, ObjectInstanceID id2, ui8
return true;
}
bool CGameHandler::hasPlayerAt(PlayerColor player, const std::shared_ptr<CConnection> & c) const
bool CGameHandler::hasPlayerAt(PlayerColor player, const std::shared_ptr<IGameConnection> & c) const
{
return gameServer().hasPlayerAt(player, c);
}

View File

@@ -22,7 +22,7 @@ VCMI_LIB_NAMESPACE_BEGIN
struct SideInBattle;
class IMarket;
class SpellCastEnvironment;
class CConnection;
class IGameConnection;
class CCommanderInstance;
class EVictoryLossCheckResult;
class CRandomGenerator;
@@ -110,6 +110,7 @@ public:
void newObject(std::shared_ptr<CGObjectInstance> object, PlayerColor initiator);
explicit CGameHandler(IGameServer & server);
CGameHandler(IGameServer & server, const std::shared_ptr<CGameState> & gamestate);
~CGameHandler();
//////////////////////////////////////////////////////////////////////////
@@ -203,9 +204,9 @@ public:
//////////////////////////////////////////////////////////////////////////
void init(StartInfo *si, Load::ProgressAccumulator & progressTracking);
void handleClientDisconnection(const std::shared_ptr<CConnection> & c);
void handleReceivedPack(std::shared_ptr<CConnection> c, CPackForServer & pack);
bool hasPlayerAt(PlayerColor player, const std::shared_ptr<CConnection> & c) const;
void handleClientDisconnection(const std::shared_ptr<IGameConnection> & c);
void handleReceivedPack(std::shared_ptr<IGameConnection> c, CPackForServer & pack);
bool hasPlayerAt(PlayerColor player, const std::shared_ptr<IGameConnection> & c) const;
bool hasBothPlayersAtSameConnection(PlayerColor left, PlayerColor right) const;
bool queryReply( QueryID qid, std::optional<int32_t> reply, PlayerColor player );
@@ -281,19 +282,19 @@ public:
void sendAndApply(SetResources & pack);
void sendAndApply(NewStructures & pack);
void wrongPlayerMessage(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, PlayerColor expectedplayer);
void wrongPlayerMessage(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, PlayerColor expectedplayer);
/// Unconditionally throws with "Action not allowed" message
[[noreturn]] void throwNotAllowedAction(const std::shared_ptr<CConnection> & connection);
[[noreturn]] void throwNotAllowedAction(const std::shared_ptr<IGameConnection> & connection);
/// Throws if player stated in pack is not making turn right now
void throwIfPlayerNotActive(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack);
void throwIfPlayerNotActive(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack);
/// Throws if object is not owned by pack sender
void throwIfWrongOwner(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, ObjectInstanceID id);
void throwIfWrongOwner(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, ObjectInstanceID id);
/// Throws if player is not present on connection of this pack
void throwIfWrongPlayer(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, PlayerColor player);
void throwIfWrongPlayer(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack);
[[noreturn]] void throwAndComplain(const std::shared_ptr<CConnection> & connection, const std::string & txt);
void throwIfWrongPlayer(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, PlayerColor player);
void throwIfWrongPlayer(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack);
[[noreturn]] void throwAndComplain(const std::shared_ptr<IGameConnection> & connection, const std::string & txt);
bool isPlayerOwns(const std::shared_ptr<CConnection> & connection, const CPackForServer * pack, ObjectInstanceID id);
bool isPlayerOwns(const std::shared_ptr<IGameConnection> & connection, const CPackForServer * pack, ObjectInstanceID id);
void start(bool resume);
void tick(int millisecondsPassed);

View File

@@ -26,7 +26,7 @@
#include "../lib/modding/ModIncompatibility.h"
#include "../lib/rmg/CMapGenOptions.h"
#include "../lib/serializer/CMemorySerializer.h"
#include "../lib/serializer/Connection.h"
#include "../lib/serializer/GameConnection.h"
#include "../lib/texts/CGeneralTextHandler.h"
// UUID generation
@@ -40,10 +40,10 @@ class CVCMIServerPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
private:
CVCMIServer & handler;
std::shared_ptr<CGameHandler> gh;
std::shared_ptr<CConnection> connection;
std::shared_ptr<GameConnection> connection;
public:
CVCMIServerPackVisitor(CVCMIServer & handler, const std::shared_ptr<CGameHandler> & gh, const std::shared_ptr<CConnection> & connection)
CVCMIServerPackVisitor(CVCMIServer & handler, const std::shared_ptr<CGameHandler> & gh, const std::shared_ptr<GameConnection> & connection)
: handler(handler)
, gh(gh)
, connection(connection)
@@ -117,7 +117,7 @@ void CVCMIServer::onNewConnection(const std::shared_ptr<INetworkConnection> & co
{
if(getState() == EServerState::LOBBY)
{
activeConnections.push_back(std::make_shared<CConnection>(connection));
activeConnections.push_back(std::make_shared<GameConnection>(connection));
activeConnections.back()->enterLobbyConnectionMode();
}
else
@@ -129,7 +129,7 @@ void CVCMIServer::onNewConnection(const std::shared_ptr<INetworkConnection> & co
void CVCMIServer::onPacketReceived(const std::shared_ptr<INetworkConnection> & connection, const std::vector<std::byte> & message)
{
std::shared_ptr<CConnection> c = findConnection(connection);
std::shared_ptr<GameConnection> c = findConnection(connection);
if (c == nullptr)
throw std::out_of_range("Unknown connection received in CVCMIServer::findConnection");
@@ -156,7 +156,7 @@ EServerState CVCMIServer::getState() const
return state;
}
std::shared_ptr<CConnection> CVCMIServer::findConnection(const std::shared_ptr<INetworkConnection> & netConnection)
std::shared_ptr<GameConnection> CVCMIServer::findConnection(const std::shared_ptr<INetworkConnection> & netConnection)
{
for(const auto & gameConnection : activeConnections)
{
@@ -319,7 +319,7 @@ void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & con
{
logNetwork->error("Network error receiving a pack. Connection has been closed");
std::shared_ptr<CConnection> c = findConnection(connection);
std::shared_ptr<GameConnection> c = findConnection(connection);
// player may have already disconnected via clientDisconnected call
if (c)
@@ -330,7 +330,7 @@ void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & con
}
}
void CVCMIServer::handleReceivedPack(std::shared_ptr<CConnection> connection, CPackForLobby & pack)
void CVCMIServer::handleReceivedPack(std::shared_ptr<GameConnection> connection, CPackForLobby & pack)
{
ClientPermissionsCheckerNetPackVisitor checker(*this, connection);
pack.visit(checker);
@@ -406,7 +406,7 @@ bool CVCMIServer::passHost(int toConnectionId)
return false;
}
void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode)
void CVCMIServer::clientConnected(std::shared_ptr<GameConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode)
{
assert(getState() == EServerState::LOBBY);
@@ -444,7 +444,7 @@ void CVCMIServer::clientConnected(std::shared_ptr<CConnection> c, std::vector<st
}
}
void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> connection)
void CVCMIServer::clientDisconnected(std::shared_ptr<GameConnection> connection)
{
assert(vstd::contains(activeConnections, connection));
logGlobal->trace("Received disconnection request");
@@ -1142,9 +1142,9 @@ bool CVCMIServer::isPlayerHost(const PlayerColor & color) const
return LobbyInfo::isPlayerHost(color);
}
bool CVCMIServer::hasPlayerAt(PlayerColor player, const std::shared_ptr<CConnection> & c) const
bool CVCMIServer::hasPlayerAt(PlayerColor player, const std::shared_ptr<IGameConnection> & c) const
{
return vstd::contains(getAllClientPlayers(c->connectionID), player);
return vstd::contains(getAllClientPlayers(c->getConnectionID()), player);
}
bool CVCMIServer::hasBothPlayersAtSameConnection(PlayerColor left, PlayerColor right) const

View File

@@ -20,7 +20,7 @@ class CMapInfo;
struct CPackForLobby;
class CConnection;
class GameConnection;
struct StartInfo;
struct LobbyInfo;
struct PlayerSettings;
@@ -47,7 +47,7 @@ class CVCMIServer : public LobbyInfo, public INetworkServerListener, public INet
EServerState state = EServerState::LOBBY;
std::shared_ptr<CConnection> findConnection(const std::shared_ptr<INetworkConnection> &);
std::shared_ptr<GameConnection> findConnection(const std::shared_ptr<INetworkConnection> &);
int currentClientId;
ui8 currentPlayerId;
@@ -62,12 +62,12 @@ public:
void setState(EServerState value) override;
EServerState getState() const override;
bool isPlayerHost(const PlayerColor & color) const override;
bool hasPlayerAt(PlayerColor player, const std::shared_ptr<CConnection> & c) const override;
bool hasPlayerAt(PlayerColor player, const std::shared_ptr<IGameConnection> & c) const override;
bool hasBothPlayersAtSameConnection(PlayerColor left, PlayerColor right) const override;
void broadcastPack(const CPackForClient & pack) override;
/// List of all active connections
std::vector<std::shared_ptr<CConnection>> activeConnections;
std::vector<std::shared_ptr<GameConnection>> activeConnections;
uint16_t prepare(bool connectToLobby, bool listenForConnections);
@@ -90,7 +90,7 @@ public:
void startGameImmediately();
uint16_t startAcceptingIncomingConnections(bool listenForConnections);
void threadHandleClient(std::shared_ptr<CConnection> c);
void threadHandleClient(std::shared_ptr<GameConnection> c);
void announcePack(CPackForLobby & pack);
bool passHost(int toConnectionId);
@@ -101,14 +101,14 @@ public:
void setPlayerConnectedId(PlayerSettings & pset, ui8 player) const;
void updateStartInfoOnMapChange(std::shared_ptr<CMapInfo> mapInfo, std::shared_ptr<CMapGenOptions> mapGenOpt = {});
void clientConnected(std::shared_ptr<CConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode);
void clientDisconnected(std::shared_ptr<CConnection> c);
void clientConnected(std::shared_ptr<GameConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode);
void clientDisconnected(std::shared_ptr<GameConnection> c);
void reconnectPlayer(int connId);
void announceMessage(const MetaString & txt);
void announceMessage(const std::string & txt);
void handleReceivedPack(std::shared_ptr<CConnection> connection, CPackForLobby & pack);
void handleReceivedPack(std::shared_ptr<GameConnection> connection, CPackForLobby & pack);
void updateAndPropagateLobbyState();

View File

@@ -11,7 +11,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class PlayerColor;
class CConnection;
class IGameConnection;
struct CPackForClient;
VCMI_LIB_NAMESPACE_END
@@ -31,7 +31,7 @@ public:
virtual void setState(EServerState value) = 0;
virtual EServerState getState() const = 0;
virtual bool isPlayerHost(const PlayerColor & color) const = 0;
virtual bool hasPlayerAt(PlayerColor player, const std::shared_ptr<CConnection> & c) const = 0;
virtual bool hasPlayerAt(PlayerColor player, const std::shared_ptr<IGameConnection> & c) const = 0;
virtual bool hasBothPlayersAtSameConnection(PlayerColor left, PlayerColor right) const = 0;
virtual void broadcastPack(const CPackForClient & pack) = 0;
};

View File

@@ -11,15 +11,19 @@
#include "../lib/networkPacks/NetPackVisitor.h"
VCMI_LIB_NAMESPACE_BEGIN
class GameConnection;
VCMI_LIB_NAMESPACE_END
class ClientPermissionsCheckerNetPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
{
private:
std::shared_ptr<CConnection> connection;
std::shared_ptr<GameConnection> connection;
CVCMIServer & srv;
bool result;
public:
ClientPermissionsCheckerNetPackVisitor(CVCMIServer & srv, const std::shared_ptr<CConnection> & connection)
ClientPermissionsCheckerNetPackVisitor(CVCMIServer & srv, const std::shared_ptr<GameConnection> & connection)
: connection(connection)
, srv(srv)
, result(false)
@@ -67,12 +71,12 @@ public:
class ApplyOnServerNetPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
{
private:
std::shared_ptr<CConnection> connection;
std::shared_ptr<GameConnection> connection;
CVCMIServer & srv;
bool result;
public:
ApplyOnServerNetPackVisitor(CVCMIServer & srv, const std::shared_ptr<CConnection> & connection)
ApplyOnServerNetPackVisitor(CVCMIServer & srv, const std::shared_ptr<GameConnection> & connection)
: connection(connection)
, srv(srv)
, result(true)

View File

@@ -22,7 +22,7 @@
#include "../lib/filesystem/Filesystem.h"
#include "../lib/gameState/CGameState.h"
#include "../lib/mapping/CMapInfo.h"
#include "../lib/serializer/Connection.h"
#include "../lib/serializer/GameConnection.h"
void ClientPermissionsCheckerNetPackVisitor::visitForLobby(CPackForLobby & pack)
{

View File

@@ -11,15 +11,17 @@
#include "../lib/networkPacks/NetPackVisitor.h"
class IGameConnection;
class ApplyGhNetPackVisitor : public VCMI_LIB_WRAP_NAMESPACE(ICPackVisitor)
{
private:
std::shared_ptr<CConnection> connection;
std::shared_ptr<IGameConnection> connection;
CGameHandler & gh;
bool result;
public:
ApplyGhNetPackVisitor(CGameHandler & gh, const std::shared_ptr<CConnection> & connection)
ApplyGhNetPackVisitor(CGameHandler & gh, const std::shared_ptr<IGameConnection> & connection)
: connection(connection)
, gh(gh)
, result(false)

View File

@@ -32,7 +32,7 @@
#include "../../lib/mapping/CMap.h"
#include "../../lib/networkPacks/PacksForClient.h"
#include "../../lib/networkPacks/StackLocation.h"
#include "../../lib/serializer/Connection.h"
#include "../../lib/serializer/IGameConnection.h"
#include "../../lib/spells/CSpellHandler.h"
#include "../lib/VCMIDirs.h"
@@ -964,14 +964,14 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla
callbacks.at(cheatName)();
}
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message)
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<IGameConnection> connection, const MetaString & message)
{
SystemMessage sm;
sm.text = message;
connection->sendPack(sm);
}
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message)
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<IGameConnection> connection, const std::string & message)
{
MetaString str;
str.appendRawString(message);

View File

@@ -14,7 +14,7 @@
VCMI_LIB_NAMESPACE_BEGIN
class CGHeroInstance;
class CGTownInstance;
class CConnection;
class IGameConnection;
class MetaString;
VCMI_LIB_NAMESPACE_END
@@ -80,8 +80,8 @@ public:
void playerMessage(PlayerColor player, const std::string & message, ObjectInstanceID currObj);
/// Send message to specific client with "System" as sender
void sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message);
void sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message);
void sendSystemMessage(std::shared_ptr<IGameConnection> connection, const MetaString & message);
void sendSystemMessage(std::shared_ptr<IGameConnection> connection, const std::string & message);
/// Send message to all players with "System" as sender
void broadcastSystemMessage(MetaString message);