| 11 | namespace Star { |
| 12 | |
| 13 | ServerClientContext::ServerClientContext(ConnectionId clientId, Maybe<HostAddress> remoteAddress, NetCompatibilityRules netRules, Uuid playerUuid, |
| 14 | String playerName, String playerSpecies, bool canBecomeAdmin, WorldChunks initialShipChunks) |
| 15 | : m_clientId(clientId), |
| 16 | m_remoteAddress(remoteAddress), |
| 17 | m_netRules(netRules), |
| 18 | m_playerUuid(playerUuid), |
| 19 | m_playerName(playerName), |
| 20 | m_playerSpecies(playerSpecies), |
| 21 | m_canBecomeAdmin(canBecomeAdmin), |
| 22 | m_shipChunks(std::move(initialShipChunks)) { |
| 23 | m_rpc.registerHandler("ship.applyShipUpgrades", [this](Json const& args) -> Json { |
| 24 | RecursiveMutexLocker locker(m_mutex); |
| 25 | setShipUpgrades(shipUpgrades().apply(args)); |
| 26 | return true; |
| 27 | }); |
| 28 | |
| 29 | m_rpc.registerHandler("world.containerPutItems", [this](Json const& args) -> Json { |
| 30 | List<ItemDescriptor> overflow = args.getArray("items").transformed(construct<ItemDescriptor>()); |
| 31 | RecursiveMutexLocker locker(m_mutex); |
| 32 | if (m_worldThread) { |
| 33 | m_worldThread->executeAction([args, &overflow](WorldServerThread*, WorldServer* server) { |
| 34 | EntityId entityId = args.getInt("entityId"); |
| 35 | Json items = args.get("items"); |
| 36 | auto itemDatabase = Root::singleton().itemDatabase(); |
| 37 | if (auto containerEntity = as<ContainerEntity>(server->entity(entityId))) { |
| 38 | overflow.clear(); |
| 39 | for (auto const& itemDescriptor : items.iterateArray()) { |
| 40 | if (auto left = containerEntity->addItems(itemDatabase->item(ItemDescriptor(itemDescriptor))).result().value()) |
| 41 | overflow.append(left->descriptor()); |
| 42 | } |
| 43 | } |
| 44 | }); |
| 45 | } |
| 46 | return overflow.transformed(mem_fn(&ItemDescriptor::toJson)); |
| 47 | }); |
| 48 | |
| 49 | m_rpc.registerHandler("universe.setFlag", [this](Json const& args) -> Json { |
| 50 | auto flagName = args.toString(); |
| 51 | RecursiveMutexLocker locker(m_mutex); |
| 52 | if (m_worldThread) { |
| 53 | m_worldThread->executeAction([flagName](WorldServerThread*, WorldServer* server) { |
| 54 | server->universeSettings()->setFlag(flagName); |
| 55 | }); |
| 56 | } |
| 57 | return Json(); |
| 58 | }); |
| 59 | |
| 60 | m_netGroup.addNetElement(&m_orbitWarpActionNetState); |
| 61 | m_netGroup.addNetElement(&m_playerWorldIdNetState); |
| 62 | m_netGroup.addNetElement(&m_isAdminNetState); |
| 63 | m_netGroup.addNetElement(&m_teamNetState); |
| 64 | m_netGroup.addNetElement(&m_shipUpgrades); |
| 65 | m_netGroup.addNetElement(&m_shipCoordinate); |
| 66 | |
| 67 | m_creationTime = Time::monotonicMilliseconds(); |
| 68 | } |
| 69 | |
| 70 | ConnectionId ServerClientContext::clientId() const { |
nothing calls this directly
no test coverage detected