Skip to content

Commit

Permalink
Merge branch 'dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
C0kkie committed Oct 13, 2023
2 parents abccf72 + d75b218 commit fab6971
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 74 deletions.
2 changes: 1 addition & 1 deletion client/src/bindings/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_CHECK_CONSTRUCTOR();
V8_CHECK_ARGS_LEN_MIN_MAX(1, 3);
V8_CHECK_ARGS_LEN_MIN_MAX(1, 4);

V8_ARG_TO_STRING(1, source);
V8_ARG_TO_NUMBER_OPT(2, volume, 1.f);
Expand Down
8 changes: 4 additions & 4 deletions server/src/bindings/Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_ARG_TO_NUMBER(3, radiusVal);
V8_ARG_TO_NUMBER(4, heightVal);
V8_ARG_TO_RGBA(5, colorVal);
V8_ARG_TO_UINT(6, streamingDistance)
V8_ARG_TO_UINT(6, _streamingDistance)

pos = posVal;
color = colorVal;
radius = radiusVal;
height = heightVal;
streamingDistance = streamingDistance;
streamingDistance = _streamingDistance;
}
else
{
Expand All @@ -43,13 +43,13 @@ static void Constructor(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_ARG_TO_INT(8, g);
V8_ARG_TO_INT(9, b);
V8_ARG_TO_INT(10, a);
V8_ARG_TO_UINT(11, streamingDistance)
V8_ARG_TO_UINT(11, _streamingDistance)

pos = { x, y, z };
color = { (uint8_t)r, (uint8_t)g, (uint8_t)b, (uint8_t)a };
radius = radiusVal;
height = heightVal;
streamingDistance = streamingDistance;
streamingDistance = _streamingDistance;
}

ICheckpoint* cp = ICore::Instance().CreateCheckpoint(type, pos, radius, height, color, streamingDistance);
Expand Down
33 changes: 3 additions & 30 deletions server/src/bindings/ConnectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,38 +175,11 @@ static void SetText(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::P
con->SetText(text);
}

static void RequestCloudID(const v8::FunctionCallbackInfo<v8::Value>& info)
static void GetCloudIDGetter(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
static std::list<v8::Global<v8::Promise::Resolver>> promises;

V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);

auto& persistent = promises.emplace_back(v8::Global<v8::Promise::Resolver>(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked()));

con->RequestCloudID(
[&persistent, resource](bool ok, const std::string& result)
{
resource->RunOnNextTick(
[=, &persistent]()
{
if(!resource->GetResource()->IsStarted())
{
promises.remove(persistent);
return;
}

auto isolate = resource->GetIsolate();
auto context = resource->GetContext();

if(ok) persistent.Get(isolate)->Resolve(context, V8Helpers::JSValue(result));
else
persistent.Get(isolate)->Reject(context, v8::Exception::Error(V8Helpers::JSValue(result)));
promises.remove(persistent);
});
});

V8_RETURN(persistent.Get(isolate)->GetPromise());
V8_RETURN_STRING(con->GetCloudID());
}

extern V8Class v8BaseObject;
Expand All @@ -224,7 +197,6 @@ extern V8Class v8ConnectionInfo("ConnectionInfo",

V8Helpers::SetMethod(isolate, tpl, "accept", &Accept);
V8Helpers::SetMethod(isolate, tpl, "decline", &Decline);
V8Helpers::SetMethod(isolate, tpl, "requestCloudID", &RequestCloudID);
V8Helpers::SetAccessor(isolate, tpl, "isAccepted", &IsAcceptedGetter);

V8Helpers::SetAccessor(isolate, tpl, "name", &NameGetter);
Expand All @@ -241,5 +213,6 @@ extern V8Class v8ConnectionInfo("ConnectionInfo",
V8Helpers::SetAccessor(isolate, tpl, "discordUserID", &DiscordUserIDGetter);
V8Helpers::SetAccessor(isolate, tpl, "socialClubName", &SocialClubNameGetter);
V8Helpers::SetAccessor(isolate, tpl, "id", &ConnectionIDGetter);
V8Helpers::SetAccessor(isolate, tpl, "cloudID", &GetCloudIDGetter);
V8Helpers::SetAccessor(isolate, tpl, "text", &GetText, &SetText);
});
11 changes: 11 additions & 0 deletions server/src/bindings/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,16 @@ static void SetMigrationDistance(const v8::FunctionCallbackInfo<v8::Value>& info
alt::ICore::Instance().SetMigrationDistance(tickrate);
}

static void GetLoadedVehicleModels(const v8::FunctionCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT();

std::vector<uint32_t> list = alt::ICore::Instance().GetLoadedVehicleModels();
v8::Local<v8::Array> modelArray = V8Helpers::JSValue(list);

V8_RETURN(modelArray);
}

extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle,
v8ColshapeCuboid, v8ColshapeRectangle, v8ColshapePolygon, v8Ped, v8Object, v8VirtualEntity, v8VirtualEntityGroup, v8Marker, v8ConnectionInfo;

Expand Down Expand Up @@ -852,6 +862,7 @@ extern V8Module
V8Helpers::RegisterFunc(exports, "stopServer", &StopServer);

V8Helpers::RegisterFunc(exports, "getVehicleModelInfoByHash", &GetVehicleModelByHash);
V8Helpers::RegisterFunc(exports, "getLoadedVehicleModels", &GetLoadedVehicleModels);
V8Helpers::RegisterFunc(exports, "getPedModelInfoByHash", &GetPedModelByHash);
V8Helpers::RegisterFunc(exports, "getWeaponModelInfoByHash", &GetWeaponModelByHash);
V8Helpers::RegisterFunc(exports, "getAmmoHashForWeaponHash", &GetAmmoHashForWeaponHash);
Expand Down
48 changes: 9 additions & 39 deletions server/src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,40 +866,6 @@ static void GetLocalMetaDataKeys(const v8::FunctionCallbackInfo<v8::Value>& info
V8_RETURN(arr);
}

static void RequestCloudID(const v8::FunctionCallbackInfo<v8::Value>& info)
{
static std::list<v8::Global<v8::Promise::Resolver>> promises;

V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(player, alt::IPlayer);

auto& persistent = promises.emplace_back(v8::Global<v8::Promise::Resolver>(isolate, v8::Promise::Resolver::New(ctx).ToLocalChecked()));

player->RequestCloudID(
[&persistent, resource](bool ok, const std::string& result)
{
resource->RunOnNextTick(
[=, &persistent]()
{
if(!resource->GetResource()->IsStarted())
{
promises.remove(persistent);
return;
}

auto isolate = resource->GetIsolate();
auto context = resource->GetContext();

if(ok) persistent.Get(isolate)->Resolve(context, V8Helpers::JSValue(result));
else
persistent.Get(isolate)->Reject(context, v8::Exception::Error(V8Helpers::JSValue(result)));
promises.remove(persistent);
});
});

V8_RETURN(persistent.Get(isolate)->GetPromise());
}

static void DiscordIDGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE();
Expand Down Expand Up @@ -1322,7 +1288,8 @@ static void AddDecoration(const v8::FunctionCallbackInfo<v8::Value>& info)
uint32_t overlayHash;
if(info[0]->IsNumber())
{
V8_ARG_TO_UINT(1, collectionHash);
V8_ARG_TO_UINT(1, collection);
collectionHash = collection;
}
else
{
Expand All @@ -1332,7 +1299,8 @@ static void AddDecoration(const v8::FunctionCallbackInfo<v8::Value>& info)

if(info[1]->IsNumber())
{
V8_ARG_TO_UINT(2, overlayHash);
V8_ARG_TO_UINT(2, overlay);
overlayHash = overlay;
}
else
{
Expand All @@ -1353,7 +1321,8 @@ static void RemoveDecoration(const v8::FunctionCallbackInfo<v8::Value>& info)
uint32_t overlayHash;
if(info[0]->IsNumber())
{
V8_ARG_TO_UINT(1, collectionHash);
V8_ARG_TO_UINT(1, collection);
collectionHash = collection;
}
else
{
Expand All @@ -1363,7 +1332,8 @@ static void RemoveDecoration(const v8::FunctionCallbackInfo<v8::Value>& info)

if(info[1]->IsNumber())
{
V8_ARG_TO_UINT(2, overlayHash);
V8_ARG_TO_UINT(2, overlay);
overlayHash = overlay;
}
else
{
Expand Down Expand Up @@ -1427,9 +1397,9 @@ extern V8Class v8Player("Player",
V8Helpers::SetMethod(isolate, tpl, "getLocalMeta", &GetLocalMeta);
V8Helpers::SetMethod(isolate, tpl, "deleteLocalMeta", &DeleteLocalMeta);
V8Helpers::SetMethod(isolate, tpl, "getLocalMetaKeys", &GetLocalMetaDataKeys);
V8Helpers::SetMethod(isolate, tpl, "requestCloudID", &RequestCloudID);

V8Helpers::SetAccessor<IPlayer, uint32_t, &IPlayer::GetPing>(isolate, tpl, "ping");
V8Helpers::SetAccessor<IPlayer, std::string, &IPlayer::GetCloudID>(isolate, tpl, "cloudID");
V8Helpers::SetAccessor<IPlayer, std::string, &IPlayer::GetIP>(isolate, tpl, "ip");
V8Helpers::SetAccessor<IPlayer, std::string, &IPlayer::GetName>(isolate, tpl, "name");
V8Helpers::SetAccessor<IPlayer, IVehicle*, &IPlayer::GetVehicle>(isolate, tpl, "vehicle");
Expand Down

0 comments on commit fab6971

Please sign in to comment.