1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-22 03:39:45 +02:00

Replaced some of pointers to CPack's with references

This commit is contained in:
Ivan Savenko 2024-10-04 13:35:31 +00:00
parent cc6d6b0d63
commit c1c552d394
5 changed files with 13 additions and 15 deletions

View File

@ -853,7 +853,7 @@ void CServerHandler::onPacketReceived(const std::shared_ptr<INetworkConnection>
if(getState() == EClientState::DISCONNECTING)
return;
CPack * pack = logicConnection->retrievePack(message);
auto pack = logicConnection->retrievePack(message);
ServerHandlerCPackVisitor visitor(*this);
pack->visit(visitor);
}
@ -945,7 +945,7 @@ void CServerHandler::visitForClient(CPackForClient & clientPack)
void CServerHandler::sendLobbyPack(const CPackForLobby & pack) const
{
if(getState() != EClientState::STARTING)
logicConnection->sendPack(&pack);
logicConnection->sendPack(pack);
}
bool CServerHandler::inLobbyRoom() const

View File

@ -362,8 +362,6 @@ void CClient::handlePack(CPackForClient * pack)
logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name());
pack->visit(afterVisitor);
logNetwork->trace("\tMade second apply on cl: %s", typeid(*pack).name());
delete pack;
}
int CClient::sendRequest(const CPackForServer * request, PlayerColor player)
@ -376,7 +374,7 @@ int CClient::sendRequest(const CPackForServer * request, PlayerColor player)
waitingRequest.pushBack(requestID);
request->requestID = requestID;
request->player = player;
CSH->logicConnection->sendPack(request);
CSH->logicConnection->sendPack(*request);
if(vstd::contains(playerint, player))
playerint[player]->requestSent(request, requestID);

View File

@ -68,7 +68,7 @@ CConnection::CConnection(std::weak_ptr<INetworkConnection> networkConnection)
CConnection::~CConnection() = default;
void CConnection::sendPack(const CPack * pack)
void CConnection::sendPack(const CPack & pack)
{
boost::mutex::scoped_lock lock(writeMutex);
@ -78,18 +78,18 @@ void CConnection::sendPack(const CPack * pack)
throw std::runtime_error("Attempt to send packet on a closed connection!");
packWriter->buffer.clear();
*serializer & pack;
(*serializer) & (&pack);
logNetwork->trace("Sending a pack of type %s", typeid(*pack).name());
logNetwork->trace("Sending a pack of type %s", typeid(pack).name());
connectionPtr->sendPacket(packWriter->buffer);
packWriter->buffer.clear();
serializer->savedPointers.clear();
}
CPack * CConnection::retrievePack(const std::vector<std::byte> & data)
std::unique_ptr<CPack> CConnection::retrievePack(const std::vector<std::byte> & data)
{
CPack * result;
std::unique_ptr<CPack> result;
packReader->buffer = &data;
packReader->position = 0;
@ -102,7 +102,7 @@ CPack * CConnection::retrievePack(const std::vector<std::byte> & data)
if (packReader->position != data.size())
throw std::runtime_error("Failed to retrieve pack! Not all data has been read!");
logNetwork->trace("Received CPack of type %s", typeid(*result).name());
logNetwork->trace("Received CPack of type %s", typeid(result.get()).name());
deserializer->loadedPointers.clear();
deserializer->loadedSharedPointers.clear();
return result;

View File

@ -51,8 +51,8 @@ public:
explicit CConnection(std::weak_ptr<INetworkConnection> networkConnection);
~CConnection();
void sendPack(const CPack * pack);
CPack * retrievePack(const std::vector<std::byte> & data);
void sendPack(const CPack & pack);
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
void enterLobbyConnectionMode();
void setCallback(IGameCallback * cb);

View File

@ -467,7 +467,7 @@ void CGameHandler::handleReceivedPack(CPackForServer * pack)
applied.result = successfullyApplied;
applied.packType = CTypeList::getInstance().getTypeID(pack);
applied.requestID = pack->requestID;
pack->c->sendPack(&applied);
pack->c->sendPack(applied);
};
if(isBlockedByQueries(pack, pack->player))
@ -1438,7 +1438,7 @@ void CGameHandler::sendToAllClients(CPackForClient * pack)
{
logNetwork->trace("\tSending to all clients: %s", typeid(*pack).name());
for (auto c : lobby->activeConnections)
c->sendPack(pack);
c->sendPack(*pack);
}
void CGameHandler::sendAndApply(CPackForClient * pack)