Files
mapo-core/MP.RIOC/Services/LuaScriptProvider.cs
Samuele Locatelli facd8c0856 Fix solution MP.RIOC
2026-05-08 12:13:12 +02:00

43 lines
1.2 KiB
C#

using Microsoft.Extensions.Options;
using MP.Core.Conf;
namespace MP.RIOC.Services
{
public sealed class LuaScriptProvider
{
private readonly Dictionary<string, string> _scripts;
public IReadOnlyDictionary<string, string> Scripts => _scripts;
public LuaScriptProvider(
IOptions<RedisScriptsConfig> cfg,
IWebHostEnvironment env)
{
_scripts = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var kv in cfg.Value.Scripts)
{
var name = kv.Key;
var relativePath = kv.Value;
var fullPath = Path.Combine(env.ContentRootPath, relativePath);
if (!File.Exists(fullPath))
throw new FileNotFoundException($"Script Lua non trovato: {fullPath}");
var content = File.ReadAllText(fullPath);
_scripts[name] = content;
}
}
public string Get(string name)
{
if (!_scripts.TryGetValue(name, out var script))
throw new KeyNotFoundException($"Script Lua '{name}' non trovato.");
return script;
}
}
}