From 9b6d7f421b82e9a23e8067bd36eb81e956239774 Mon Sep 17 00:00:00 2001 From: Blue Date: Sat, 8 Jan 2022 12:05:05 +0100 Subject: [PATCH] server: fix build Former-commit-id: e6d434cd053a53246bb61787c84d799edb76eb7d --- server/src/bindings/Main.cpp | 7 +- server/src/bindings/Player.cpp | 232 +++++++++++++++++---------------- server/src/events/Player.cpp | 167 ++++++++++++++---------- shared/bindings/Entity.cpp | 71 +++++----- 4 files changed, 254 insertions(+), 223 deletions(-) diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index 5dea1eb3..86a6b072 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -202,7 +202,7 @@ static void SetSyncedMeta(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_ARG_TO_MVALUE(2, value); alt::ICore::Instance().SetSyncedMetaData(key, value); @@ -213,7 +213,7 @@ static void DeleteSyncedMeta(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); alt::ICore::Instance().DeleteSyncedMetaData(key); } @@ -387,7 +387,8 @@ extern V8Module v8Alt("alt", v8ColshapeCircle, v8ColshapeCuboid, v8ColshapeRectangle }, - [](v8::Local ctx, v8::Local exports) { + [](v8::Local ctx, v8::Local exports) + { v8::Isolate* isolate = ctx->GetIsolate(); V8Helpers::RegisterFunc(exports, "getResourceMain", &GetResourceMain); diff --git a/server/src/bindings/Player.cpp b/server/src/bindings/Player.cpp index 82219f7e..5d18e92b 100644 --- a/server/src/bindings/Player.cpp +++ b/server/src/bindings/Player.cpp @@ -692,7 +692,7 @@ static void HasLocalMeta(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN_MIN(1); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_RETURN(player->HasLocalMetaData(key)); } @@ -703,7 +703,7 @@ static void SetLocalMeta(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN_MIN(1); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_ARG_TO_MVALUE(2, value); player->SetLocalMetaData(key, value); } @@ -714,7 +714,7 @@ static void GetLocalMeta(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN_MIN(1); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_RETURN_MVALUE(player->GetLocalMetaData(key)); } @@ -725,119 +725,123 @@ static void DeleteLocalMeta(const v8::FunctionCallbackInfo& info) V8_CHECK_ARGS_LEN_MIN(1); V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); player->DeleteLocalMetaData(key); } extern V8Class v8Entity; -extern V8Class v8Player("Player", v8Entity, nullptr, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); - - v8::Local proto = tpl->PrototypeTemplate(); - - V8Helpers::SetStaticMethod(isolate, tpl, "getByID", &StaticGetByID); - V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter); - - V8Helpers::SetMethod(isolate, tpl, "emit", &Emit); - V8Helpers::SetMethod(isolate, tpl, "emitRaw", &EmitRaw); - - V8Helpers::SetMethod(isolate, tpl, "hasLocalMeta", &HasLocalMeta); - V8Helpers::SetMethod(isolate, tpl, "setLocalMeta", &SetLocalMeta); - V8Helpers::SetMethod(isolate, tpl, "getLocalMeta", &GetLocalMeta); - V8Helpers::SetMethod(isolate, tpl, "deleteLocalMeta", &DeleteLocalMeta); - - V8Helpers::SetAccessor(isolate, tpl, "ping"); - V8Helpers::SetAccessor(isolate, tpl, "ip"); - V8Helpers::SetAccessor(isolate, tpl, "name"); - V8Helpers::SetAccessor, &IPlayer::GetVehicle>(isolate, tpl, "vehicle"); - V8Helpers::SetAccessor(isolate, tpl, "seat"); - V8Helpers::SetAccessor(isolate, tpl, "health"); - V8Helpers::SetAccessor(isolate, tpl, "maxHealth"); - V8Helpers::SetAccessor(isolate, tpl, "armour"); - V8Helpers::SetAccessor(isolate, tpl, "maxArmour"); - V8Helpers::SetAccessor(isolate, tpl, "weapons", &GetWeapons); - V8Helpers::SetAccessor(isolate, tpl, "isDead"); - V8Helpers::SetAccessor(isolate, tpl, "isInRagdoll"); - V8Helpers::SetAccessor(isolate, tpl, "isAiming"); - // V8Helpers::SetAccessor(isolate, tpl, "isJumping"); - // V8Helpers::SetAccessor(isolate, tpl, "isShooting"); - V8Helpers::SetAccessor(isolate, tpl, "isReloading"); - V8Helpers::SetAccessor(isolate, tpl, "aimPos"); - V8Helpers::SetAccessor(isolate, tpl, "headRot"); - - V8Helpers::SetAccessor(isolate, tpl, "isSuperJumpEnabled"); - V8Helpers::SetAccessor(isolate, tpl, "isCrouching"); - V8Helpers::SetAccessor(isolate, tpl, "isStealthy"); - - V8Helpers::SetAccessor, &IPlayer::GetEntityAimingAt>(isolate, tpl, "entityAimingAt"); - V8Helpers::SetAccessor(isolate, tpl, "entityAimOffset"); - - V8Helpers::SetAccessor(isolate, tpl, "currentWeapon"); - V8Helpers::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); - V8Helpers::SetAccessor(isolate, tpl, "currentWeaponTintIndex"); - - V8Helpers::SetAccessor(isolate, tpl, "socialID", &SocialIDGetter); - V8Helpers::SetAccessor(isolate, tpl, "hwidHash", &HwidHashGetter); - V8Helpers::SetAccessor(isolate, tpl, "hwidExHash", &HwidExHashGetter); - - V8Helpers::SetAccessor(isolate, tpl, "authToken"); - - V8Helpers::SetAccessor(isolate, tpl, "flashlightActive"); - - V8Helpers::SetAccessor(isolate, tpl, "moveSpeed"); - - V8Helpers::SetAccessor(isolate, tpl, "invincible"); - - V8Helpers::SetMethod(isolate, tpl, "spawn", &Spawn); - V8Helpers::SetMethod(isolate, tpl, "setDateTime", &SetDateTime); - V8Helpers::SetMethod(isolate, tpl, "setWeather", &SetWeather); - - V8Helpers::SetMethod(isolate, tpl, "clearBloodDamage"); - V8Helpers::SetMethod(isolate, tpl, "giveWeapon", &GiveWeapon); - V8Helpers::SetMethod(isolate, tpl, "removeWeapon", &RemoveWeapon); - V8Helpers::SetMethod(isolate, tpl, "removeAllWeapons"); - - V8Helpers::SetMethod(isolate, tpl, "addWeaponComponent", &AddWeaponComponent); - V8Helpers::SetMethod(isolate, tpl, "removeWeaponComponent", &RemoveWeaponComponent); - - V8Helpers::SetMethod(isolate, tpl, "setWeaponTintIndex", &SetWeaponTintIndex); - - V8Helpers::SetMethod(isolate, tpl, "kick", &Kick); - - V8Helpers::SetMethod(isolate, tpl, "isEntityInStreamRange", &IsEntityInStreamRange); - - V8Helpers::SetMethod(isolate, tpl, "setClothes", &SetClothes); - V8Helpers::SetMethod(isolate, tpl, "setDlcClothes", &SetDlcClothes); - V8Helpers::SetMethod(isolate, tpl, "getClothes", &GetClothes); - V8Helpers::SetMethod(isolate, tpl, "getDlcClothes", &GetDlcClothes); - - V8Helpers::SetMethod(isolate, tpl, "setProp", &SetProps); - V8Helpers::SetMethod(isolate, tpl, "setDlcProp", &SetDlcProps); - V8Helpers::SetMethod(isolate, tpl, "getProp", &GetProps); - V8Helpers::SetMethod(isolate, tpl, "getDlcProp", &GetDlcProps); - V8Helpers::SetMethod(isolate, tpl, "clearProp", &ClearProps); - - V8Helpers::SetMethod(isolate, tpl, "setIntoVehicle", &SetIntoVehicle); - - V8Helpers::SetMethod(isolate, tpl, "playAmbientSpeech", &PlayAmbientSpeech); - - // Appearance getter & setter - V8Helpers::SetMethod(isolate, tpl, "setHeadOverlay", &SetHeadOverlay); - V8Helpers::SetMethod(isolate, tpl, "removeHeadOverlay", &RemoveHeadOverlay); - V8Helpers::SetMethod(isolate, tpl, "setHeadOverlayColor", &SetHeadOverlayColor); - V8Helpers::SetMethod(isolate, tpl, "getHeadOverlay", &GetHeadOverlay); - V8Helpers::SetMethod(isolate, tpl, "setFaceFeature", &SetFaceFeature); - V8Helpers::SetMethod(isolate, tpl, "getFaceFeatureScale", &GetFaceFeatureScale); - V8Helpers::SetMethod(isolate, tpl, "removeFaceFeature", &RemoveFaceFeature); - V8Helpers::SetMethod(isolate, tpl, "setHeadBlendPaletteColor", &SetHeadBlendPaletteColor); - V8Helpers::SetMethod(isolate, tpl, "getHeadBlendPaletteColor", &GetHeadBlendPaletteColor); - V8Helpers::SetMethod(isolate, tpl, "setHeadBlendData", &SetHeadBlendData); - V8Helpers::SetMethod(isolate, tpl, "getHeadBlendData", &GetHeadBlendData); - V8Helpers::SetMethod(isolate, tpl, "setEyeColor", &SetEyeColor); - V8Helpers::SetMethod(isolate, tpl, "getEyeColor", &GetEyeColor); - V8Helpers::SetMethod(isolate, tpl, "setHairColor", &SetHairColor); - V8Helpers::SetMethod(isolate, tpl, "getHairColor", &GetHairColor); - V8Helpers::SetMethod(isolate, tpl, "setHairHighlightColor", &SetHairHighlightColor); - V8Helpers::SetMethod(isolate, tpl, "getHairHighlightColor", &GetHairHighlightColor); -}); +extern V8Class v8Player("Player", + v8Entity, + nullptr, + [](v8::Local tpl) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + + v8::Local proto = tpl->PrototypeTemplate(); + + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", &StaticGetByID); + V8Helpers::SetStaticAccessor(isolate, tpl, "all", &AllGetter); + + V8Helpers::SetMethod(isolate, tpl, "emit", &Emit); + V8Helpers::SetMethod(isolate, tpl, "emitRaw", &EmitRaw); + + V8Helpers::SetMethod(isolate, tpl, "hasLocalMeta", &HasLocalMeta); + V8Helpers::SetMethod(isolate, tpl, "setLocalMeta", &SetLocalMeta); + V8Helpers::SetMethod(isolate, tpl, "getLocalMeta", &GetLocalMeta); + V8Helpers::SetMethod(isolate, tpl, "deleteLocalMeta", &DeleteLocalMeta); + + V8Helpers::SetAccessor(isolate, tpl, "ping"); + V8Helpers::SetAccessor(isolate, tpl, "ip"); + V8Helpers::SetAccessor(isolate, tpl, "name"); + V8Helpers::SetAccessor, &IPlayer::GetVehicle>(isolate, tpl, "vehicle"); + V8Helpers::SetAccessor(isolate, tpl, "seat"); + V8Helpers::SetAccessor(isolate, tpl, "health"); + V8Helpers::SetAccessor(isolate, tpl, "maxHealth"); + V8Helpers::SetAccessor(isolate, tpl, "armour"); + V8Helpers::SetAccessor(isolate, tpl, "maxArmour"); + V8Helpers::SetAccessor(isolate, tpl, "weapons", &GetWeapons); + V8Helpers::SetAccessor(isolate, tpl, "isDead"); + V8Helpers::SetAccessor(isolate, tpl, "isInRagdoll"); + V8Helpers::SetAccessor(isolate, tpl, "isAiming"); + // V8Helpers::SetAccessor(isolate, tpl, "isJumping"); + // V8Helpers::SetAccessor(isolate, tpl, "isShooting"); + V8Helpers::SetAccessor(isolate, tpl, "isReloading"); + V8Helpers::SetAccessor(isolate, tpl, "aimPos"); + V8Helpers::SetAccessor(isolate, tpl, "headRot"); + + V8Helpers::SetAccessor(isolate, tpl, "isSuperJumpEnabled"); + V8Helpers::SetAccessor(isolate, tpl, "isCrouching"); + V8Helpers::SetAccessor(isolate, tpl, "isStealthy"); + + V8Helpers::SetAccessor, &IPlayer::GetEntityAimingAt>(isolate, tpl, "entityAimingAt"); + V8Helpers::SetAccessor(isolate, tpl, "entityAimOffset"); + + V8Helpers::SetAccessor(isolate, tpl, "currentWeapon"); + V8Helpers::SetAccessor(isolate, tpl, "currentWeaponComponents", &CurrentWeaponComponentsGetter); + V8Helpers::SetAccessor(isolate, tpl, "currentWeaponTintIndex"); + + V8Helpers::SetAccessor(isolate, tpl, "socialID", &SocialIDGetter); + V8Helpers::SetAccessor(isolate, tpl, "hwidHash", &HwidHashGetter); + V8Helpers::SetAccessor(isolate, tpl, "hwidExHash", &HwidExHashGetter); + + V8Helpers::SetAccessor(isolate, tpl, "authToken"); + + V8Helpers::SetAccessor(isolate, tpl, "flashlightActive"); + + V8Helpers::SetAccessor(isolate, tpl, "moveSpeed"); + + V8Helpers::SetAccessor(isolate, tpl, "invincible"); + + V8Helpers::SetMethod(isolate, tpl, "spawn", &Spawn); + V8Helpers::SetMethod(isolate, tpl, "setDateTime", &SetDateTime); + V8Helpers::SetMethod(isolate, tpl, "setWeather", &SetWeather); + + V8Helpers::SetMethod(isolate, tpl, "clearBloodDamage"); + V8Helpers::SetMethod(isolate, tpl, "giveWeapon", &GiveWeapon); + V8Helpers::SetMethod(isolate, tpl, "removeWeapon", &RemoveWeapon); + V8Helpers::SetMethod(isolate, tpl, "removeAllWeapons"); + + V8Helpers::SetMethod(isolate, tpl, "addWeaponComponent", &AddWeaponComponent); + V8Helpers::SetMethod(isolate, tpl, "removeWeaponComponent", &RemoveWeaponComponent); + + V8Helpers::SetMethod(isolate, tpl, "setWeaponTintIndex", &SetWeaponTintIndex); + + V8Helpers::SetMethod(isolate, tpl, "kick", &Kick); + + V8Helpers::SetMethod(isolate, tpl, "isEntityInStreamRange", &IsEntityInStreamRange); + + V8Helpers::SetMethod(isolate, tpl, "setClothes", &SetClothes); + V8Helpers::SetMethod(isolate, tpl, "setDlcClothes", &SetDlcClothes); + V8Helpers::SetMethod(isolate, tpl, "getClothes", &GetClothes); + V8Helpers::SetMethod(isolate, tpl, "getDlcClothes", &GetDlcClothes); + + V8Helpers::SetMethod(isolate, tpl, "setProp", &SetProps); + V8Helpers::SetMethod(isolate, tpl, "setDlcProp", &SetDlcProps); + V8Helpers::SetMethod(isolate, tpl, "getProp", &GetProps); + V8Helpers::SetMethod(isolate, tpl, "getDlcProp", &GetDlcProps); + V8Helpers::SetMethod(isolate, tpl, "clearProp", &ClearProps); + + V8Helpers::SetMethod(isolate, tpl, "setIntoVehicle", &SetIntoVehicle); + + V8Helpers::SetMethod(isolate, tpl, "playAmbientSpeech", &PlayAmbientSpeech); + + // Appearance getter & setter + V8Helpers::SetMethod(isolate, tpl, "setHeadOverlay", &SetHeadOverlay); + V8Helpers::SetMethod(isolate, tpl, "removeHeadOverlay", &RemoveHeadOverlay); + V8Helpers::SetMethod(isolate, tpl, "setHeadOverlayColor", &SetHeadOverlayColor); + V8Helpers::SetMethod(isolate, tpl, "getHeadOverlay", &GetHeadOverlay); + V8Helpers::SetMethod(isolate, tpl, "setFaceFeature", &SetFaceFeature); + V8Helpers::SetMethod(isolate, tpl, "getFaceFeatureScale", &GetFaceFeatureScale); + V8Helpers::SetMethod(isolate, tpl, "removeFaceFeature", &RemoveFaceFeature); + V8Helpers::SetMethod(isolate, tpl, "setHeadBlendPaletteColor", &SetHeadBlendPaletteColor); + V8Helpers::SetMethod(isolate, tpl, "getHeadBlendPaletteColor", &GetHeadBlendPaletteColor); + V8Helpers::SetMethod(isolate, tpl, "setHeadBlendData", &SetHeadBlendData); + V8Helpers::SetMethod(isolate, tpl, "getHeadBlendData", &GetHeadBlendData); + V8Helpers::SetMethod(isolate, tpl, "setEyeColor", &SetEyeColor); + V8Helpers::SetMethod(isolate, tpl, "getEyeColor", &GetEyeColor); + V8Helpers::SetMethod(isolate, tpl, "setHairColor", &SetHairColor); + V8Helpers::SetMethod(isolate, tpl, "getHairColor", &GetHairColor); + V8Helpers::SetMethod(isolate, tpl, "setHairHighlightColor", &SetHairHighlightColor); + V8Helpers::SetMethod(isolate, tpl, "getHairHighlightColor", &GetHairHighlightColor); + }); diff --git a/server/src/events/Player.cpp b/server/src/events/Player.cpp index fc4561d3..d8b61abe 100644 --- a/server/src/events/Player.cpp +++ b/server/src/events/Player.cpp @@ -18,62 +18,77 @@ using alt::CEvent; using EventType = CEvent::Type; -V8Helpers::LocalEventHandler playerConnect(EventType::PLAYER_CONNECT, "playerConnect", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); -}); - -V8Helpers::LocalEventHandler - beforePlayerConnect(EventType::PLAYER_BEFORE_CONNECT, "beforePlayerConnect", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - const alt::ConnectionInfo& info = ev->GetConnectionInfo(); - v8::Isolate* isolate = resource->GetIsolate(); - v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); - V8_NEW_OBJECT(infoObj); - V8_OBJECT_SET_STD_STRING(infoObj, "name", info.name); - V8_OBJECT_SET_STD_STRING(infoObj, "socialID", std::to_string(info.socialId)); - V8_OBJECT_SET_STD_STRING(infoObj, "hwidHash", std::to_string(info.hwidHash)); - V8_OBJECT_SET_STD_STRING(infoObj, "hwidExHash", std::to_string(info.hwidExHash)); - V8_OBJECT_SET_STD_STRING(infoObj, "authToken", info.authToken); - V8_OBJECT_SET_BOOLEAN(infoObj, "isDebug", info.isDebug); - V8_OBJECT_SET_STD_STRING(infoObj, "branch", info.branch); - V8_OBJECT_SET_UINT(infoObj, "build", info.build); - V8_OBJECT_SET_STD_STRING(infoObj, "cdnUrl", info.cdnUrl); - V8_OBJECT_SET_BIGUINT(infoObj, "passwordHash", info.passwordHash); - args.push_back(infoObj); - args.push_back(V8Helpers::JSValue(ev->GetReason())); - }); - -V8Helpers::LocalEventHandler playerDisconnect(EventType::PLAYER_DISCONNECT, "playerDisconnect", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(V8Helpers::JSValue(ev->GetReason())); -}); - -V8Helpers::LocalEventHandler playerDamage(EventType::PLAYER_DAMAGE, "playerDamage", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); - - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(resource->GetBaseObjectOrNull(ev->GetAttacker())); - args.push_back(V8Helpers::JSValue(ev->GetHealthDamage())); - args.push_back(V8Helpers::JSValue(ev->GetArmourDamage())); - args.push_back(V8Helpers::JSValue(ev->GetWeapon())); -}); - -V8Helpers::LocalEventHandler playerDeath(EventType::PLAYER_DEATH, "playerDeath", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); - - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(resource->GetBaseObjectOrNull(ev->GetKiller())); - args.push_back(V8Helpers::JSValue(ev->GetWeapon())); -}); +V8Helpers::LocalEventHandler playerConnect(EventType::PLAYER_CONNECT, + "playerConnect", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + }); + +V8Helpers::LocalEventHandler beforePlayerConnect(EventType::PLAYER_BEFORE_CONNECT, + "beforePlayerConnect", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + const alt::ConnectionInfo& info = ev->GetConnectionInfo(); + v8::Isolate* isolate = resource->GetIsolate(); + v8::Local ctx = isolate->GetEnteredOrMicrotaskContext(); + V8_NEW_OBJECT(infoObj); + V8_OBJECT_SET_STD_STRING(infoObj, "name", info.name); + V8_OBJECT_SET_STD_STRING(infoObj, "socialID", std::to_string(info.socialId)); + V8_OBJECT_SET_STD_STRING(infoObj, "hwidHash", std::to_string(info.hwidHash)); + V8_OBJECT_SET_STD_STRING(infoObj, "hwidExHash", std::to_string(info.hwidExHash)); + V8_OBJECT_SET_STD_STRING(infoObj, "authToken", info.authToken); + V8_OBJECT_SET_BOOLEAN(infoObj, "isDebug", info.isDebug); + V8_OBJECT_SET_STD_STRING(infoObj, "branch", info.branch); + V8_OBJECT_SET_UINT(infoObj, "build", info.build); + V8_OBJECT_SET_STD_STRING(infoObj, "cdnUrl", info.cdnUrl); + V8_OBJECT_SET_BIGUINT(infoObj, "passwordHash", info.passwordHash); + args.push_back(infoObj); + args.push_back(V8Helpers::JSValue(ev->GetReason())); + }); + +V8Helpers::LocalEventHandler playerDisconnect(EventType::PLAYER_DISCONNECT, + "playerDisconnect", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(V8Helpers::JSValue(ev->GetReason())); + }); + +V8Helpers::LocalEventHandler playerDamage(EventType::PLAYER_DAMAGE, + "playerDamage", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetAttacker())); + args.push_back(V8Helpers::JSValue(ev->GetHealthDamage())); + args.push_back(V8Helpers::JSValue(ev->GetArmourDamage())); + args.push_back(V8Helpers::JSValue(ev->GetWeapon())); + }); + +V8Helpers::LocalEventHandler playerDeath(EventType::PLAYER_DEATH, + "playerDeath", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(resource->GetBaseObjectOrNull(ev->GetKiller())); + args.push_back(V8Helpers::JSValue(ev->GetWeapon())); + }); V8Helpers::LocalEventHandler playerEnterVehicle(EventType::PLAYER_ENTER_VEHICLE, "playerEnteredVehicle", // TODO: change name for consistency - [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); @@ -83,7 +98,8 @@ V8Helpers::LocalEventHandler playerEnterVehicle(EventType::PLAYER_ENTER_VEHICLE, V8Helpers::LocalEventHandler playerEnteringVehicle(EventType::PLAYER_ENTERING_VEHICLE, "playerEnteringVehicle", // TODO: don't change names, it's okay - [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); @@ -93,7 +109,8 @@ V8Helpers::LocalEventHandler playerEnteringVehicle(EventType::PLAYER_ENTERING_VE V8Helpers::LocalEventHandler playerLeaveVehicle(EventType::PLAYER_LEAVE_VEHICLE, "playerLeftVehicle", // TODO: change name for consistency - [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); @@ -103,7 +120,8 @@ V8Helpers::LocalEventHandler playerLeaveVehicle(EventType::PLAYER_LEAVE_VEHICLE, V8Helpers::LocalEventHandler playerChangeVehicleSeat(EventType::PLAYER_CHANGE_VEHICLE_SEAT, "playerChangedVehicleSeat", // TODO: change name for consistency - [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { auto ev = static_cast(e); args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer())); @@ -112,21 +130,26 @@ V8Helpers::LocalEventHandler playerChangeVehicleSeat(EventType::PLAYER_CHANGE_VE args.push_back(V8Helpers::JSValue(ev->GetNewSeat())); }); -V8Helpers::LocalEventHandler - playerWeaponChange(EventType::PLAYER_WEAPON_CHANGE, "playerWeaponChange", [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) { - auto ev = static_cast(e); +V8Helpers::LocalEventHandler playerWeaponChange(EventType::PLAYER_WEAPON_CHANGE, + "playerWeaponChange", + [](V8ResourceImpl* resource, const CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(V8Helpers::JSValue(ev->GetOldWeapon())); - args.push_back(V8Helpers::JSValue(ev->GetNewWeapon())); - }); - -V8_LOCAL_EVENT_HANDLER localMetaChange(EventType::LOCAL_SYNCED_META_CHANGE, "localMetaChange", [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) { - auto ev = static_cast(e); - v8::Isolate* isolate = resource->GetIsolate(); + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(V8Helpers::JSValue(ev->GetOldWeapon())); + args.push_back(V8Helpers::JSValue(ev->GetNewWeapon())); + }); - args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); - args.push_back(V8Helpers::JSValue(ev->GetKey().CStr())); - args.push_back(V8Helpers::MValueToV8(ev->GetVal())); - args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); -}); +V8_LOCAL_EVENT_HANDLER localMetaChange(EventType::LOCAL_SYNCED_META_CHANGE, + "localMetaChange", + [](V8ResourceImpl* resource, const alt::CEvent* e, std::vector>& args) + { + auto ev = static_cast(e); + v8::Isolate* isolate = resource->GetIsolate(); + + args.push_back(resource->GetBaseObjectOrNull(ev->GetTarget())); + args.push_back(V8Helpers::JSValue(ev->GetKey())); + args.push_back(V8Helpers::MValueToV8(ev->GetVal())); + args.push_back(V8Helpers::MValueToV8(ev->GetOldVal())); + }); diff --git a/shared/bindings/Entity.cpp b/shared/bindings/Entity.cpp index d4169e07..7240e965 100644 --- a/shared/bindings/Entity.cpp +++ b/shared/bindings/Entity.cpp @@ -87,7 +87,7 @@ static void SetSyncedMeta(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_ARG_TO_MVALUE(2, value); V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); @@ -100,7 +100,7 @@ static void DeleteSyncedMeta(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); @@ -112,7 +112,7 @@ static void SetStreamSyncedMeta(const v8::FunctionCallbackInfo& info) V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(2); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_ARG_TO_MVALUE(2, value); V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); @@ -125,7 +125,7 @@ static void DeleteStreamSyncedMeta(const v8::FunctionCallbackInfo& in V8_GET_ISOLATE_CONTEXT(); V8_CHECK_ARGS_LEN(1); - V8_ARG_TO_STRING(1, key); + V8_ARG_TO_STD_STRING(1, key); V8_GET_THIS_BASE_OBJECT(ent, alt::IEntity); @@ -216,49 +216,52 @@ static void StaticAllGetter(v8::Local, const v8::PropertyCallbackInf } extern V8Class v8WorldObject; -extern V8Class v8Entity("Entity", v8WorldObject, [](v8::Local tpl) { - v8::Isolate* isolate = v8::Isolate::GetCurrent(); +extern V8Class v8Entity("Entity", + v8WorldObject, + [](v8::Local tpl) + { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); - V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); - V8Helpers::SetStaticAccessor(isolate, tpl, "all", StaticAllGetter); + V8Helpers::SetStaticMethod(isolate, tpl, "getByID", StaticGetByID); + V8Helpers::SetStaticAccessor(isolate, tpl, "all", StaticAllGetter); - V8Helpers::SetAccessor(isolate, tpl, "id"); - V8Helpers::SetAccessor, &IEntity::GetNetworkOwner>(isolate, tpl, "netOwner"); + V8Helpers::SetAccessor(isolate, tpl, "id"); + V8Helpers::SetAccessor, &IEntity::GetNetworkOwner>(isolate, tpl, "netOwner"); - V8Helpers::SetMethod(isolate, tpl, "hasSyncedMeta", HasSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "getSyncedMeta", GetSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "hasSyncedMeta", HasSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "getSyncedMeta", GetSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "hasStreamSyncedMeta", HasStreamSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "getStreamSyncedMeta", GetStreamSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "hasStreamSyncedMeta", HasStreamSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "getStreamSyncedMeta", GetStreamSyncedMeta); #ifdef ALT_SERVER_API - V8Helpers::SetAccessor(isolate, tpl, "rot"); - V8Helpers::SetAccessor(isolate, tpl, "model", &ModelGetter, &ModelSetter); - V8Helpers::SetAccessor(isolate, tpl, "visible"); - V8Helpers::SetAccessor(isolate, tpl, "streamed"); + V8Helpers::SetAccessor(isolate, tpl, "rot"); + V8Helpers::SetAccessor(isolate, tpl, "model", &ModelGetter, &ModelSetter); + V8Helpers::SetAccessor(isolate, tpl, "visible"); + V8Helpers::SetAccessor(isolate, tpl, "streamed"); - V8Helpers::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "deleteSyncedMeta", DeleteSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "setSyncedMeta", SetSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "deleteSyncedMeta", DeleteSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "setStreamSyncedMeta", SetStreamSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "deleteStreamSyncedMeta", DeleteStreamSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "setStreamSyncedMeta", SetStreamSyncedMeta); + V8Helpers::SetMethod(isolate, tpl, "deleteStreamSyncedMeta", DeleteStreamSyncedMeta); - V8Helpers::SetMethod(isolate, tpl, "setNetOwner", SetNetOwner); - V8Helpers::SetMethod(isolate, tpl, "resetNetOwner", ResetNetOwner); + V8Helpers::SetMethod(isolate, tpl, "setNetOwner", SetNetOwner); + V8Helpers::SetMethod(isolate, tpl, "resetNetOwner", ResetNetOwner); - V8Helpers::SetMethod(isolate, tpl, "attachTo", AttachTo); - V8Helpers::SetMethod(isolate, tpl, "detach"); + V8Helpers::SetMethod(isolate, tpl, "attachTo", AttachTo); + V8Helpers::SetMethod(isolate, tpl, "detach"); #endif // ALT_SERVER_API #ifdef ALT_CLIENT_API - V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); + V8Helpers::SetStaticMethod(isolate, tpl, "getByScriptID", StaticGetByScriptID); - V8Helpers::SetAccessor(isolate, tpl, "pos"); - V8Helpers::SetAccessor(isolate, tpl, "rot"); - V8Helpers::SetAccessor(isolate, tpl, "model"); - V8Helpers::SetAccessor(isolate, tpl, "scriptID"); - V8Helpers::SetAccessor(isolate, tpl, "visible"); + V8Helpers::SetAccessor(isolate, tpl, "pos"); + V8Helpers::SetAccessor(isolate, tpl, "rot"); + V8Helpers::SetAccessor(isolate, tpl, "model"); + V8Helpers::SetAccessor(isolate, tpl, "scriptID"); + V8Helpers::SetAccessor(isolate, tpl, "visible"); - V8Helpers::SetAccessor(isolate, tpl, "isSpawned", &IsSpawnedGetter); + V8Helpers::SetAccessor(isolate, tpl, "isSpawned", &IsSpawnedGetter); #endif // ALT_CLIENT_API -}); + });