Files
RobustToolbox/Robust.Server/Prototypes/ServerPrototypeManager.cs
T
eada37378a Add YAML hot reloading (#1571)
* Implement hot reloading for entity prototypes

* Implement automatic prototype hot-reloading

* Merge fixes

* Add yaml hot reloading and a message to notify the client

* Add reloading only changed files, remove cooldown, add retries and remove IPrototype

* Remove reload command

* Make the client listen for reloads instead and only when focused

* Fix errors

* Only queue a reload when the queue has items in it

* Make fails after 10 retries log instead of throw if reloading

Co-authored-by: Jackson Lewis <inquisitivepenguin@protonmail.com>
2021-02-20 00:02:04 +01:00

51 lines
1.4 KiB
C#

using System;
using Robust.Server.Console;
using Robust.Server.Player;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Network.Messages;
using Robust.Shared.Prototypes;
namespace Robust.Server.Prototypes
{
public sealed class ServerPrototypeManager : PrototypeManager
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IConGroupController _conGroups = default!;
public ServerPrototypeManager() : base()
{
RegisterIgnore("shader");
}
public override void Initialize()
{
base.Initialize();
NetManager.RegisterNetMessage<MsgReloadPrototypes>(MsgReloadPrototypes.NAME, HandleReloadPrototypes, NetMessageAccept.Server);
}
private void HandleReloadPrototypes(MsgReloadPrototypes msg)
{
#if !FULL_RELEASE
if (!_playerManager.TryGetSessionByChannel(msg.MsgChannel, out var player) ||
!_conGroups.CanAdminReloadPrototypes(player))
{
return;
}
var then = DateTime.Now;
foreach (var path in msg.Paths)
{
ReloadPrototypes(path);
}
Logger.Info($"Reloaded prototypes in {(int) (DateTime.Now - then).TotalMilliseconds} ms");
#endif
}
}
}