| 88 | } |
| 89 | |
| 90 | void SystemWorldServer::addClientShip(ConnectionId clientId, Uuid const& uuid, float shipSpeed, SystemLocation location) { |
| 91 | if (auto objectUuid = location.maybe<Uuid>()) { |
| 92 | if (getObject(*objectUuid) == nullptr) |
| 93 | location.reset(); |
| 94 | } |
| 95 | if (!location) |
| 96 | location = randomArrivalPosition(); |
| 97 | |
| 98 | SystemClientShipPtr ship = make_shared<SystemClientShip>(this, uuid, shipSpeed, location); |
| 99 | m_clientShips.set(clientId, ship->uuid()); |
| 100 | m_ships.set(ship->uuid(), ship); |
| 101 | m_clientNetVersions.set(clientId, {{}, {} }); |
| 102 | m_outgoingPackets.set(clientId, {}); |
| 103 | |
| 104 | List<ByteArray> objectStores = m_objects.values().transformed([](SystemObjectPtr const& o) { return o->netStore(); }); |
| 105 | List<ByteArray> shipStores = m_ships.values().filtered([uuid](SystemClientShipPtr const& s) { |
| 106 | return s->uuid() != uuid; |
| 107 | }).transformed([](SystemClientShipPtr const& s) { |
| 108 | return s->netStore(); |
| 109 | }); |
| 110 | pair<Uuid, SystemLocation> clientShip = {ship->uuid(), ship->systemLocation()}; |
| 111 | m_outgoingPackets[clientId].append(make_shared<SystemWorldStartPacket>(m_location, objectStores, shipStores, clientShip)); |
| 112 | |
| 113 | for (ConnectionId otherClient : m_clientShips.keys()) { |
| 114 | if (otherClient != clientId) |
| 115 | m_outgoingPackets[otherClient].append(make_shared<SystemShipCreatePacket>(ship->netStore())); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void SystemWorldServer::removeClientShip(ConnectionId clientId) { |
| 120 | m_shipDestroyQueue.append(m_clientShips.get(clientId)); |