| 747 | } |
| 748 | |
| 749 | String CommandProcessor::entityEval(ConnectionId connectionId, String const& lua) { |
| 750 | if (auto errorMsg = localCheck(connectionId, "execute server entity script")) |
| 751 | return *errorMsg; |
| 752 | |
| 753 | if (auto errorMsg = adminCheck(connectionId, "execute server entity script")) |
| 754 | return *errorMsg; |
| 755 | |
| 756 | String message; |
| 757 | bool done = m_universe->executeForClient(connectionId, |
| 758 | [&lua, &message](WorldServer* world, PlayerPtr const& player) { |
| 759 | auto queryRect = RectF::withCenter(player->aimPosition(), Vec2F{2, 2}); |
| 760 | auto entities = world->query<ScriptedEntity>(queryRect); |
| 761 | if (entities.empty()) { |
| 762 | message = "Could not find scripted entity at cursor"; |
| 763 | return; |
| 764 | } |
| 765 | |
| 766 | ScriptedEntityPtr targetEntity; |
| 767 | for (auto const& entity : entities) { |
| 768 | if (!targetEntity |
| 769 | || vmagSquared(entity->position() - player->aimPosition()) |
| 770 | < vmagSquared(targetEntity->position() - player->aimPosition())) |
| 771 | targetEntity = entity; |
| 772 | } |
| 773 | |
| 774 | if (auto res = targetEntity->evalScript(lua)) |
| 775 | message = toString(*res); |
| 776 | else |
| 777 | message = "Error evaluating script in entity context, check log"; |
| 778 | }); |
| 779 | |
| 780 | return done ? message : "failed to do entity eval"; |
| 781 | } |
| 782 | |
| 783 | String CommandProcessor::enableSpawning(ConnectionId connectionId, String const&) { |
| 784 | if (auto errorMsg = adminCheck(connectionId, "enable world spawning")) |
nothing calls this directly
no test coverage detected