From 4cf6ce5c415a673ae4f83104db4039cc353812bc Mon Sep 17 00:00:00 2001 From: vadzz Date: Thu, 26 Dec 2024 17:01:00 +0300 Subject: [PATCH] ALTV-614 Add invokeConsoleCommand --- server/src/bindings/Main.cpp | 25 +++++++++++++++++++++++++ shared/deps/cpp-sdk | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/server/src/bindings/Main.cpp b/server/src/bindings/Main.cpp index b17295fb..2efd37e4 100644 --- a/server/src/bindings/Main.cpp +++ b/server/src/bindings/Main.cpp @@ -847,6 +847,30 @@ static void PrintHealth(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); resource->PrintHealth(); +} + +static void InvokeConsoleCommand(const v8::FunctionCallbackInfo& info) +{ + V8_GET_ISOLATE_CONTEXT(); + V8_CHECK_ARGS_LEN(2); + + V8_ARG_TO_STRING(1, cmd); + V8_ARG_TO_ARRAY(2, jsArgs); + + std::vector args; + uint32_t argsLen = jsArgs->Length(); + for(uint32_t i = 0; i < argsLen; ++i) + { + v8::MaybeLocal maybeVal = jsArgs->Get(ctx, i); + if(maybeVal.IsEmpty()) continue; + + v8::Local jsArg = maybeVal.ToLocalChecked(); + V8_TO_STRING(jsArg, arg); + + args.push_back(arg); + } + + alt::ICore::Instance().InvokeCommand(cmd, args); } extern V8Class v8Player, v8Vehicle, v8Blip, v8AreaBlip, v8RadiusBlip, v8PointBlip, v8Checkpoint, v8VoiceChannel, v8Colshape, v8ColshapeCylinder, v8ColshapeSphere, v8ColshapeCircle, @@ -944,6 +968,7 @@ extern V8Module V8Helpers::RegisterFunc(exports, "hasBenefit", &HasBenefit); V8Helpers::RegisterFunc(exports, "printHealth", &PrintHealth); + V8Helpers::RegisterFunc(exports, "invokeConsoleCommand", &InvokeConsoleCommand); V8_OBJECT_SET_STRING(exports, "rootDir", alt::ICore::Instance().GetRootDirectory()); }); diff --git a/shared/deps/cpp-sdk b/shared/deps/cpp-sdk index 55077272..96573a12 160000 --- a/shared/deps/cpp-sdk +++ b/shared/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 5507727239d5665e75828a7bec3f44bff245f3c8 +Subproject commit 96573a12f204e03e7a187c0c20b1bc03b2716ca0