| 2342 | } |
| 2343 | |
| 2344 | RpcPromise<Json> WorldServer::sendEntityMessage(Variant<EntityId, String> const& entityId, String const& message, JsonArray const& args) { |
| 2345 | EntityPtr entity; |
| 2346 | if (entityId.is<EntityId>()) |
| 2347 | entity = m_entityMap->entity(entityId.get<EntityId>()); |
| 2348 | else |
| 2349 | entity = m_entityMap->entity(loadUniqueEntity(entityId.get<String>())); |
| 2350 | |
| 2351 | if (!entity) { |
| 2352 | return RpcPromise<Json>::createFailed("Unknown entity"); |
| 2353 | } else if (entity->isMaster()) { |
| 2354 | if (auto resp = entity->receiveMessage(ServerConnectionId, message, args)) |
| 2355 | return RpcPromise<Json>::createFulfilled(resp.take()); |
| 2356 | else |
| 2357 | return RpcPromise<Json>::createFailed("Message not handled by entity"); |
| 2358 | } else { |
| 2359 | auto pair = RpcPromise<Json>::createPair(); |
| 2360 | auto clientInfo = m_clientInfo.get(connectionForEntity(entity->entityId())); |
| 2361 | Uuid uuid; |
| 2362 | m_entityMessageResponses[uuid] = {clientInfo->clientId, pair.second}; |
| 2363 | clientInfo->outgoingPackets.append(make_shared<EntityMessagePacket>(entity->entityId(), message, args, uuid)); |
| 2364 | return pair.first; |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | void WorldServer::setPlayerStart(Vec2F const& startPosition, bool respawnInWorld) { |
| 2369 | m_playerStart = startPosition; |
nothing calls this directly
no test coverage detected