Skip to content

Commit

Permalink
Merge branch 'dev' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
emcifuntik committed Aug 21, 2023
2 parents bd52e16 + 9df6cd5 commit 8ebe3cf
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 57 deletions.
20 changes: 16 additions & 4 deletions client/src/IImportHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::deque<std::string> IImportHandler::GetModuleKeys(const std::string& name)
std::deque<std::string> keys;

alt::MValueDict _exports = resource->GetExports();
for(auto it = _exports->Begin(); it; it = _exports->Next()) keys.push_back(it->GetKey());
for(auto it = _exports->Begin(); it != _exports->End(); ++it) keys.push_back(it->first);

return keys;
}
Expand Down Expand Up @@ -296,15 +296,27 @@ v8::MaybeLocal<v8::Module> IImportHandler::ResolveBytecode(const std::string& na
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();

// Copy source code size
int sourceCodeSize = 0;
memcpy(&sourceCodeSize, buffer + sizeof(bytecodeMagic), sizeof(int));
// Copy bytecode buffer
size_t bytecodeSize = size - sizeof(bytecodeMagic);
size_t bytecodeSize = size - sizeof(bytecodeMagic) - sizeof(int);
uint8_t* bytecode = new uint8_t[bytecodeSize];
memcpy(bytecode, buffer + sizeof(bytecodeMagic), bytecodeSize);
memcpy(bytecode, buffer + sizeof(bytecodeMagic) + sizeof(int), bytecodeSize);

v8::ScriptCompiler::CachedData* cachedData = new v8::ScriptCompiler::CachedData(bytecode, bytecodeSize, v8::ScriptCompiler::CachedData::BufferOwned);
v8::ScriptOrigin origin(isolate, V8Helpers::JSValue(name), 0, 0, false, -1, v8::Local<v8::Value>(), false, false, true, v8::Local<v8::PrimitiveArray>());

v8::ScriptCompiler::Source source{ V8Helpers::JSValue(" "), origin, cachedData };
// Create source string
std::string sourceString;
sourceString.reserve(sourceCodeSize + 2);
sourceString += "'";
for(size_t i = 0; i < sourceCodeSize; i++)
{
sourceString += "a";
}
sourceString += "'";
v8::ScriptCompiler::Source source{ V8Helpers::JSValue(sourceString), origin, cachedData };
v8::MaybeLocal<v8::Module> module = v8::ScriptCompiler::CompileModule(isolate, &source, v8::ScriptCompiler::kConsumeCodeCache);
if(cachedData->rejected)
{
Expand Down
6 changes: 2 additions & 4 deletions client/src/bindings/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ static void ConstructorAttached(const v8::FunctionCallbackInfo<v8::Value>& info)
static void AllAudioOutputGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
auto objects = alt::ICore::Instance().GetBaseObjects(alt::IBaseObject::Type::AUDIO_OUTPUT);
v8::Local<v8::Array> jsArr = v8::Array::New(isolate, objects.size());
for(size_t i = 0; i < objects.size(); ++i) jsArr->Set(ctx, i, resource->GetBaseObjectOrNull(objects[i]));
V8_RETURN(jsArr);

V8_RETURN(resource->GetAllAudioOutputs()->Clone());
}

static void AudioOutputCountGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
Expand Down
40 changes: 20 additions & 20 deletions client/src/bindings/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo<v8::Value>& info)

auto dict = client->GetExtraHeaders();
V8_NEW_OBJECT(headers);
for(auto it = dict->Begin(); it; it = dict->Next())
for(auto it = dict->Begin(); it != dict->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}

V8_RETURN(headers);
Expand Down Expand Up @@ -69,9 +69,9 @@ static void Get(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -112,9 +112,9 @@ static void Head(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -156,9 +156,9 @@ static void Post(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -200,9 +200,9 @@ static void Put(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -244,9 +244,9 @@ static void Delete(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -288,9 +288,9 @@ static void Connect(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -332,9 +332,9 @@ static void Options(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -376,9 +376,9 @@ static void Trace(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down Expand Up @@ -420,9 +420,9 @@ static void Patch(const v8::FunctionCallbackInfo<v8::Value>& info)
V8_OBJECT_SET_INT(responseObj, "statusCode", response.statusCode);
V8_OBJECT_SET_STRING(responseObj, "body", response.body);
V8_NEW_OBJECT(headers);
for(auto it = response.headers->Begin(); it; it = response.headers->Next())
for(auto it = response.headers->Begin(); it != response.headers->End(); ++it)
{
headers->Set(ctx, V8Helpers::JSValue(it->GetKey().c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->GetValue())->Value().c_str()));
headers->Set(ctx, V8Helpers::JSValue(it->first.c_str()), V8Helpers::JSValue(std::dynamic_pointer_cast<const alt::IMValueString>(it->second)->Value().c_str()));
}
responseObj->Set(ctx, V8Helpers::JSValue("headers"), headers);
resolver->Resolve(resolver->GetCreationContext().ToLocalChecked(), responseObj);
Expand Down
1 change: 1 addition & 0 deletions client/src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ extern V8Class v8Player("Player",
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsOnLadder>(isolate, tpl, "isOnLadder");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsInMelee>(isolate, tpl, "isInMelee");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsInCover>(isolate, tpl, "isInCover");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsParachuting>(isolate, tpl, "isParachuting");

// V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsSuperJumpEnabled>(isolate, tpl, "isSuperJumpEnabled");
// V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsCrouching>(isolate, tpl, "isCrouching");
Expand Down
4 changes: 2 additions & 2 deletions client/src/bindings/WebSocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ static void GetExtraHeaders(const v8::FunctionCallbackInfo<v8::Value>& info)
auto extraHeaders = webSocket->GetExtraHeaders();
V8_NEW_OBJECT(headersObject);

for(auto it = extraHeaders->Begin(); it; it = extraHeaders->Next())
for(auto it = extraHeaders->Begin(); it != extraHeaders->End(); ++it)
{
std::string key = it->GetKey();
std::string key = it->first;
V8_OBJECT_SET_STRING(headersObject, key.c_str(), std::dynamic_pointer_cast<alt::IMValueString>(extraHeaders->Get(key))->Value());
}

Expand Down
18 changes: 18 additions & 0 deletions server/src/bindings/ConnectionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ static void StaticGetByID(const v8::FunctionCallbackInfo<v8::Value>& info)
}
}

static void GetText(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
{
V8_GET_ISOLATE_CONTEXT_RESOURCE();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);

V8_RETURN_STRING(con->GetText());
}

static void SetText(v8::Local<v8::String>, v8::Local<v8::Value> val, const v8::PropertyCallbackInfo<void>& info)
{
V8_GET_ISOLATE_CONTEXT();
V8_GET_THIS_BASE_OBJECT(con, alt::IConnectionInfo);
V8_TO_STRING(val, text);

con->SetText(text);
}

extern V8Class v8BaseObject;
extern V8Class v8ConnectionInfo("ConnectionInfo",
v8BaseObject,
Expand Down Expand Up @@ -197,4 +214,5 @@ extern V8Class v8ConnectionInfo("ConnectionInfo",
V8Helpers::SetAccessor(isolate, tpl, "socialClubName", &SocialClubNameGetter);
V8Helpers::SetAccessor(isolate, tpl, "id", &ConnectionIDGetter);
V8Helpers::SetAccessor(isolate, tpl, "cloudAuthHash", &CloudAuthHashGetter);
V8Helpers::SetAccessor(isolate, tpl, "text", &GetText, &SetText);
});
2 changes: 0 additions & 2 deletions server/src/bindings/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,4 @@ extern V8Module
V8Helpers::RegisterFunc(exports, "setVoiceExternal", &SetVoiceExternal);

V8_OBJECT_SET_STRING(exports, "rootDir", alt::ICore::Instance().GetRootDirectory());
V8_OBJECT_SET_INT(exports, "defaultDimension", alt::DEFAULT_DIMENSION);
V8_OBJECT_SET_INT(exports, "globalDimension", alt::GLOBAL_DIMENSION);
});
42 changes: 22 additions & 20 deletions server/src/bindings/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,26 +856,27 @@ static void RequestCloudID(const v8::FunctionCallbackInfo<v8::Value>& info)

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, &resource]()
{
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);
});
});
player->RequestCloudID(
[&persistent, resource](bool ok, const std::string& result)
{
resource->RunOnNextTick(
[=, &persistent, &resource]()
{
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());
}
Expand Down Expand Up @@ -1437,6 +1438,7 @@ extern V8Class v8Player("Player",
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsOnLadder>(isolate, tpl, "isOnLadder");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsInMelee>(isolate, tpl, "isInMelee");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsInCover>(isolate, tpl, "isInCover");
V8Helpers::SetAccessor<IPlayer, bool, &IPlayer::IsParachuting>(isolate, tpl, "isParachuting");

V8Helpers::SetAccessor<IPlayer, uint32_t, &IPlayer::GetCurrentAnimationDict>(isolate, tpl, "currentAnimationDict");
V8Helpers::SetAccessor<IPlayer, uint32_t, &IPlayer::GetCurrentAnimationName>(isolate, tpl, "currentAnimationName");
Expand Down
Loading

0 comments on commit 8ebe3cf

Please sign in to comment.