Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Prima.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prima.Tcp.Test", "src\Prima
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prima.UOData", "src\Prima.UOData\Prima.UOData.csproj", "{174F3943-CC41-419F-9599-BFD6DF5B756F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prima.JavaScript.Engine", "src\Prima.JavaScript.Engine\Prima.JavaScript.Engine.csproj", "{7728B06A-6F5E-4B4C-AABB-55E71239BD09}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -99,6 +101,18 @@ Global
{174F3943-CC41-419F-9599-BFD6DF5B756F}.Release|x64.Build.0 = Release|Any CPU
{174F3943-CC41-419F-9599-BFD6DF5B756F}.Release|x86.ActiveCfg = Release|Any CPU
{174F3943-CC41-419F-9599-BFD6DF5B756F}.Release|x86.Build.0 = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|x64.ActiveCfg = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|x64.Build.0 = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|x86.ActiveCfg = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Debug|x86.Build.0 = Debug|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|Any CPU.Build.0 = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|x64.ActiveCfg = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|x64.Build.0 = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|x86.ActiveCfg = Release|Any CPU
{7728B06A-6F5E-4B4C-AABB-55E71239BD09}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Prima.Core.Server.Attributes.Scripts;

[AttributeUsage(AttributeTargets.Method)]
public class ScriptFunctionAttribute : Attribute
{
public string? HelpText { get; }

public ScriptFunctionAttribute(string? helpText = null)
{
HelpText = helpText;
}
}
12 changes: 12 additions & 0 deletions src/Prima.Core.Server/Attributes/Scripts/ScriptModuleAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Prima.Core.Server.Attributes.Scripts;

[AttributeUsage(AttributeTargets.Class)]
public class ScriptModuleAttribute : Attribute
{
public string Name { get; }

public ScriptModuleAttribute(string name)
{
Name = name;
}
}
4 changes: 2 additions & 2 deletions src/Prima.Core.Server/Data/Config/Sections/ShardConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class ShardConfig

public string Url { get; set; } = "https://github.com/tgiachi/prima";

public int TimeZone { get; set; } = 0;
public int TimeZone { get; set; } = (int)TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow).TotalHours;

public string Language { get; set; } = "en";
public string Language { get; set; } = "eng";

public AutosaveConfig Autosave { get; set; } = new();
}
13 changes: 13 additions & 0 deletions src/Prima.Core.Server/Interfaces/Services/IScriptEngineService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Orion.Core.Server.Interfaces.Services.Base;

namespace Prima.Core.Server.Interfaces.Services;

public interface IScriptEngineService : IOrionStartService
{
void AddInitScript(string script);
void ExecuteScript(string script);
void ExecuteScriptFile(string scriptFile);
void AddCallback(string name, Action<object[]> callback);
void AddConstant(string name, object value);
void ExecuteCallback(string name, params object[] args);
}
3 changes: 2 additions & 1 deletion src/Prima.Core.Server/Prima.Core.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.21" />
<PackageReference Include="Orion.Core.Server" Version="0.29.0" />
<PackageReference Include="Orion.Core.Server" Version="0.30.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -25,6 +25,7 @@


<ItemGroup>
<Folder Include="Modules\Scripts\" />
<Folder Include="Services\" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Prima.Core.Server/Types/DirectoryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum DirectoryType
WorldSaves,
Templates,
Configs,
Dictionaries,
Data
}
15 changes: 15 additions & 0 deletions src/Prima.JavaScript.Engine/Data/Configs/ScriptEngineConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Prima.JavaScript.Engine.Data.Configs;

public class ScriptEngineConfig
{
public List<string> InitScriptsFileNames { get; set; } = new() { "bootstrap.js", "index.js" };

public ScriptNameConversion NamingConvention { get; set; } = ScriptNameConversion.PascalCase;
}

public enum ScriptNameConversion
{
CamelCase,
PascalCase,
SnakeCase,
}
3 changes: 3 additions & 0 deletions src/Prima.JavaScript.Engine/Data/Internal/ScriptModuleData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Orion.JavaScript.Engine.Data.Internal;

public record ScriptModuleData(Type ModuleType);
20 changes: 20 additions & 0 deletions src/Prima.JavaScript.Engine/Extensions/AddScriptModuleExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.Extensions.DependencyInjection;
using Orion.Core.Server.Extensions;
using Orion.JavaScript.Engine.Data.Internal;

namespace Orion.JavaScript.Engine.Extensions;

public static class AddScriptModuleExtension
{
public static IServiceCollection AddScriptModule<T>(this IServiceCollection services)
where T : class
{
return services.AddScriptModule(typeof(T));
}

public static IServiceCollection AddScriptModule(this IServiceCollection services, Type type)
{
services.AddSingleton(type);
return services.AddToRegisterTypedList(new ScriptModuleData(type));
}
}
19 changes: 19 additions & 0 deletions src/Prima.JavaScript.Engine/Extensions/ServicesCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.Extensions.DependencyInjection;
using Orion.Core.Server.Extensions;
using Prima.Core.Server.Interfaces.Services;
using Prima.JavaScript.Engine.Data.Configs;
using Prima.JavaScript.Engine.Services;

namespace Prima.JavaScript.Engine.Extensions;

public static class ServicesCollection
{
public static IServiceCollection AddJsScriptEngineService(
this IServiceCollection services, ScriptEngineConfig? config = null
)
{
config ??= new ScriptEngineConfig();
services.AddSingleton(config);
return services.AddService<IScriptEngineService, ScriptEngineService>();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Orion.Core.Server.Attributes.Scripts;
using Orion.Core.Server.Data.Directories;
using Orion.Core.Server.Interfaces.Services.System;
using Prima.Core.Server.Attributes.Scripts;
using Prima.Core.Server.Interfaces.Services;

namespace Prima.Core.Server.Modules.Scripts;
namespace Prima.JavaScript.Engine.Modules.Scripts;

[ScriptModule("files")]
public class FileScriptModule
Expand Down
45 changes: 45 additions & 0 deletions src/Prima.JavaScript.Engine/Modules/Scripts/JsLoggerModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Extensions.Logging;
using Prima.Core.Server.Attributes.Scripts;

namespace Prima.JavaScript.Engine.Modules.Scripts;

[ScriptModule("logger")]
public class JsLoggerModule
{
private readonly ILogger _logger;

public JsLoggerModule(ILogger<JsLoggerModule> logger)
{
_logger = logger;
}

[ScriptFunction("Log an informational message")]
public void Info(string message, params object[]? args)
{
_logger.LogInformation("[JS] " + message, args);
}

[ScriptFunction("Log a warning message")]
public void Warn(string message, params object[]? args)
{
_logger.LogWarning("[JS] " + message, args);
}

[ScriptFunction("Log an error message")]
public void Error(string message, params object[]? args)
{
_logger.LogError("[JS] " + message, args);
}

[ScriptFunction("Log a critical message")]
public void Critical(string message, params object[]? args)
{
_logger.LogCritical("[JS] " + message, args);
}

[ScriptFunction("Log a debug message")]
public void Debug(string message, params object[]? args)
{
_logger.LogDebug("[JS] " + message, args);
}
}
23 changes: 23 additions & 0 deletions src/Prima.JavaScript.Engine/Prima.JavaScript.Engine.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>



<ItemGroup>
<Folder Include="Attributes\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Prima.Core.Server\Prima.Core.Server.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Jint" Version="4.2.2" />
</ItemGroup>

</Project>
Loading