| 2301 | } |
| 2302 | |
| 2303 | RpcPromise<Json> WorldClient::sendEntityMessage(Variant<EntityId, String> const& entityId, String const& message, JsonArray const& args) { |
| 2304 | if (!inWorld()) |
| 2305 | return RpcPromise<Json>::createFailed("Not currently in a world"); |
| 2306 | |
| 2307 | EntityPtr entity; |
| 2308 | if (entityId.is<EntityId>()) |
| 2309 | entity = m_entityMap->entity(entityId.get<EntityId>()); |
| 2310 | else |
| 2311 | entity = m_entityMap->uniqueEntity(entityId.get<String>()); |
| 2312 | |
| 2313 | // Only fail with "unknown entity" if we know this entity should exist on the |
| 2314 | // client, because it's entity id indicates it is master here. |
| 2315 | if (entityId.is<EntityId>() && !entity && m_clientId == connectionForEntity(entityId.get<EntityId>())) { |
| 2316 | return RpcPromise<Json>::createFailed("Unknown entity"); |
| 2317 | } else if (entity && entity->isMaster()) { |
| 2318 | if (auto resp = entity->receiveMessage(*m_clientId, message, args)) |
| 2319 | return RpcPromise<Json>::createFulfilled(resp.take()); |
| 2320 | else |
| 2321 | return RpcPromise<Json>::createFailed("Message not handled by entity"); |
| 2322 | } else { |
| 2323 | auto pair = RpcPromise<Json>::createPair(); |
| 2324 | Uuid uuid; |
| 2325 | m_entityMessageResponses[uuid] = pair.second; |
| 2326 | m_outgoingPackets.append(make_shared<EntityMessagePacket>(entityId, message, args, uuid)); |
| 2327 | return pair.first; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | List<ChatAction> WorldClient::pullPendingChatActions() { |
| 2332 | List<ChatAction> result; |
no test coverage detected