MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / sendEntityMessage

Method sendEntityMessage

source/game/StarWorldClient.cpp:2303–2329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2301}
2302
2303RpcPromise<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
2331List<ChatAction> WorldClient::pullPendingChatActions() {
2332 List<ChatAction> result;

Callers 7

updateMethod · 0.45
validateEdgeMethod · 0.45
upgradeTableMethod · 0.45
teleportMethod · 0.45
dismissedMethod · 0.45
buyMethod · 0.45
sellMethod · 0.45

Calls 7

connectionForEntityFunction · 0.85
uniqueEntityMethod · 0.80
isMasterMethod · 0.80
entityMethod · 0.45
receiveMessageMethod · 0.45
takeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected