Skip to content

Commit

Permalink
Harden scripting wrapper (#104)
Browse files Browse the repository at this point in the history
* Update vehicle.h

* Update player.h
  • Loading branch information
zpl-zak authored Aug 27, 2024
1 parent 6d936b4 commit 431b041
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions code/server/src/core/builtins/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
#include <sol/sol.hpp>

#include "integrations/server/scripting/builtins/node/entity.h"
#include "shared/modules/human_sync.hpp"
#include "scripting/server_engine.h"

namespace MafiaMP::Scripting {
class Vehicle;
class Human final: public Framework::Integrations::Scripting::Entity {
public:
Human(flecs::entity_t ent): Entity(ent) {}
Human(flecs::entity ent): Entity(ent) {}
Human(flecs::entity_t ent): Entity(ent) {
const auto humanData = _ent.get<Shared::Modules::HumanSync::UpdateData>();

if (!humanData) {
throw std::runtime_error(fmt::format("Entity handle '{}' is not a Human!", ent));
}
}

Human(flecs::entity ent): Human(ent.id()) {}

static void EventPlayerDied(flecs::entity e);
static void EventPlayerConnected(flecs::entity e);
Expand Down
11 changes: 9 additions & 2 deletions code/server/src/core/builtins/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@
namespace MafiaMP::Scripting {
class Vehicle final: public Framework::Integrations::Scripting::Entity {
public:
Vehicle(flecs::entity_t ent): Entity(ent) {}
Vehicle(flecs::entity ent): Entity(ent) {}
Vehicle(flecs::entity_t ent) : Entity(ent) {
const auto vehData = _ent.get<Shared::Modules::VehicleSync::UpdateData>();

if (!vehData) {
throw std::runtime_error(fmt::format("Entity handle '{}' is not a Vehicle!", ent));
}
}

Vehicle(flecs::entity ent): Vehicle(ent.id()) {}

static void EventVehiclePlayerEnter(flecs::entity vehicle, flecs::entity player, int seatIndex);
static void EventVehiclePlayerLeave(flecs::entity vehicle, flecs::entity player);
Expand Down

0 comments on commit 431b041

Please sign in to comment.