| 1464 | } |
| 1465 | |
| 1466 | void NetworkBase::ServerSendMap(Connection* connection) |
| 1467 | { |
| 1468 | std::vector<const ObjectRepositoryItem*> objects; |
| 1469 | if (connection != nullptr) |
| 1470 | { |
| 1471 | objects = connection->requestedObjects; |
| 1472 | } |
| 1473 | else |
| 1474 | { |
| 1475 | // This will send all custom objects to connected clients |
| 1476 | // TODO: fix it so custom objects negotiation is performed even in this case. |
| 1477 | auto& context = GetContext(); |
| 1478 | auto& objManager = context.GetObjectManager(); |
| 1479 | objects = objManager.GetPackableObjects(); |
| 1480 | } |
| 1481 | |
| 1482 | auto mapContent = SaveForNetwork(objects); |
| 1483 | if (mapContent.empty()) |
| 1484 | { |
| 1485 | if (connection != nullptr) |
| 1486 | { |
| 1487 | connection->setLastDisconnectReason(STR_MULTIPLAYER_CONNECTION_CLOSED); |
| 1488 | connection->disconnect(); |
| 1489 | } |
| 1490 | return; |
| 1491 | } |
| 1492 | |
| 1493 | Packet packetBeginMap(Command::beginMap); |
| 1494 | |
| 1495 | Packet packetMap(Command::map); |
| 1496 | packetMap.write(mapContent.data(), mapContent.size()); |
| 1497 | |
| 1498 | if (connection != nullptr) |
| 1499 | { |
| 1500 | connection->queuePacket(std::move(packetBeginMap)); |
| 1501 | connection->queuePacket(std::move(packetMap)); |
| 1502 | } |
| 1503 | else |
| 1504 | { |
| 1505 | SendPacketToClients(packetBeginMap); |
| 1506 | SendPacketToClients(packetMap); |
| 1507 | } |
| 1508 | } |
| 1509 | |
| 1510 | std::vector<uint8_t> NetworkBase::SaveForNetwork(const std::vector<const ObjectRepositoryItem*>& objects) const |
| 1511 | { |
no test coverage detected