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
499 changes: 499 additions & 0 deletions src/Prima.Core.Server/Collections/ValueLinkList.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Prima.Core.Server/Data/PrimaServerContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Orion.Core.Server.Data.Directories;
using Orion.Core.Server.Interfaces.Services.System;
using Prima.Core.Server.Data.Session;
using Prima.Core.Server.Data.Uo;
Expand All @@ -10,6 +11,8 @@ public static class PrimaServerContext
{
public static IServiceProvider ServiceProvider { get; set; }

public static DirectoriesConfig DirectoriesConfig => ServiceProvider.GetRequiredService<DirectoriesConfig>();

public static IEventLoopService EventLoopService => ServiceProvider.GetRequiredService<IEventLoopService>();

public static INetworkSessionService<NetworkSession> NetworkSessionService => ServiceProvider.GetRequiredService<INetworkSessionService<NetworkSession>>();
Expand Down
1 change: 0 additions & 1 deletion src/Prima.Core.Server/Data/Session/NetworkSession.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Orion.Core.Server.Interfaces.Sessions;
using Prima.Core.Server.Data.Uo;
using Prima.Network.Interfaces.Packets;
using Prima.Network.Packets;

namespace Prima.Core.Server.Data.Session;

Expand Down
16 changes: 16 additions & 0 deletions src/Prima.Core.Server/Handlers/Base/BasePacketListenerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;
using Orion.Core.Server.Interfaces.Services.Base;
using Orion.Core.Server.Interfaces.Services.System;
using Orion.Core.Server.Listeners.EventBus;
using Prima.Core.Server.Data.Session;
using Prima.Core.Server.Interfaces.Listeners;
using Prima.Core.Server.Interfaces.Services;
Expand Down Expand Up @@ -79,4 +80,19 @@ public Task OnPacketReceived(string sessionId, IUoNetworkPacket packet)
{
return _serviceProvider.GetRequiredService<INetworkSessionService<NetworkSession>>().GetSession(sessionId);
}

protected Task PublishEvent<TEvent>(TEvent eventArgs) where TEvent : class
{
return _serviceProvider.GetRequiredService<IEventBusService>().PublishAsync(eventArgs);
}

protected void SubscribeEvent<TEvent>(Func<TEvent, Task> handler) where TEvent : class
{
_serviceProvider.GetRequiredService<IEventBusService>().Subscribe(handler);
}

protected void SubscribeEvent<TEvent>(IEventBusListener<TEvent> listener) where TEvent : class
{
_serviceProvider.GetRequiredService<IEventBusService>().Subscribe(listener);
}
}
28 changes: 28 additions & 0 deletions src/Prima.JavaScript.Engine/Services/ScriptEngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,41 @@ public Task StartAsync(CancellationToken cancellationToken = default)

File.WriteAllText(Path.Combine(_directoriesConfig["Scripts"], "index.d.ts"), documentation);

GenerateEnumDefinitions(TypeScriptDocumentationGenerator.FoundEnums);

ExecuteBootstrap();


return Task.CompletedTask;
}

private void GenerateEnumDefinitions(List<Type> enumTypes)
{
foreach (var enumType in enumTypes)
{
var enumName = enumType.Name;
var enumDictionary = ConvertEnumToDictionary(enumType);

_jsEngine.SetValue(enumName, enumDictionary);
}
}


public static Dictionary<string, object> ConvertEnumToDictionary(Type enumType)
{
if (!enumType.IsEnum)
{
throw new ArgumentException($"Type {enumType.Name} is not an enum", nameof(enumType));
}


return Enum.GetNames(enumType)
.ToDictionary(
name => name.ToSnakeCaseUpper(),
name => (object)Enum.Parse(enumType, name)
);
}

public Task StopAsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public static class TypeScriptDocumentationGenerator
private static readonly StringBuilder _enumsBuilder = new();
private static readonly List<Type> _interfaceTypesToGenerate = [];

public static List<Type> FoundEnums { get; } = [];

private static Func<string, string> _nameResolver = name => name.ToSnakeCase();

public static string GenerateDocumentation(
Expand Down Expand Up @@ -499,6 +501,8 @@ private static void GenerateEnumInterface(Type enumType)
return;
}

FoundEnums.Add(enumType);

_enumsBuilder.AppendLine();
_enumsBuilder.AppendLine($"/**");
_enumsBuilder.AppendLine($" * Generated enum for {enumType.FullName}");
Expand All @@ -509,8 +513,20 @@ private static void GenerateEnumInterface(Type enumType)

foreach (var value in enumValues)
{
var numericValue = (int)Enum.Parse(enumType, value);
_enumsBuilder.AppendLine($" {value} = {numericValue},");
var numericValue = -1;
try
{
numericValue = Convert.ToInt32(Enum.Parse(enumType, value));
}
catch (InvalidCastException)
{
// Handle the case where the enum value is not an integer
// This can happen if the enum is defined with a different underlying type
numericValue = (int)Enum.Parse(enumType, value);
}


_enumsBuilder.AppendLine($" {value.ToSnakeCaseUpper()} = {numericValue},");
}

_enumsBuilder.AppendLine("}");
Expand Down
2 changes: 1 addition & 1 deletion src/Prima.Network/Packets/Base/BaseUoNetworkPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class BaseUoNetworkPacket : IUoNetworkPacket
/// <summary>
/// Gets the length of the packet data.
/// </summary>
public int Length { get; }
public int Length { get; set; }

/// <summary>
/// Initializes a new instance of the BaseUoNetworkPacket class with the specified operation code.
Expand Down
Loading
Loading