| 277 | } |
| 278 | |
| 279 | List<PacketPtr> WorldServer::removeClient(ConnectionId clientId) { |
| 280 | auto const& info = m_clientInfo.get(clientId); |
| 281 | |
| 282 | for (auto const& entityId : m_entityMap->entityIds()) { |
| 283 | if (connectionForEntity(entityId) == clientId) |
| 284 | removeEntity(entityId, false); |
| 285 | } |
| 286 | |
| 287 | for (auto const& uuid : m_entityMessageResponses.keys()) { |
| 288 | if (m_entityMessageResponses[uuid].first == clientId) { |
| 289 | auto response = m_entityMessageResponses[uuid].second; |
| 290 | if (response.is<ConnectionId>()) { |
| 291 | if (auto clientInfo = m_clientInfo.value(response.get<ConnectionId>())) |
| 292 | clientInfo->outgoingPackets.append(make_shared<EntityMessageResponsePacket>(makeLeft("Client disconnected"), uuid)); |
| 293 | } else { |
| 294 | response.get<RpcPromiseKeeper<Json>>().fail("Client disconnected"); |
| 295 | } |
| 296 | m_entityMessageResponses.remove(uuid); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | auto packets = std::move(info->outgoingPackets); |
| 301 | m_clientInfo.remove(clientId); |
| 302 | |
| 303 | packets.append(make_shared<WorldStopPacket>("Removed")); |
| 304 | |
| 305 | for (auto& p : m_scriptContexts) |
| 306 | p.second->invoke("removeClient", clientId); |
| 307 | |
| 308 | return packets; |
| 309 | } |
| 310 | |
| 311 | List<ConnectionId> WorldServer::clientIds() const { |
| 312 | return m_clientInfo.keys(); |