Adds Network Resource Uploading for admins. (#6904)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
committed by
GitHub
parent
5954b7668c
commit
eb54f4b224
@@ -0,0 +1,41 @@
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Administration;
|
||||
|
||||
/// <summary>
|
||||
/// Manager that allows resources to be added at runtime by admins.
|
||||
/// They will be sent to all clients automatically.
|
||||
/// </summary>
|
||||
public abstract class SharedNetworkResourceManager : IDisposable
|
||||
{
|
||||
[Dependency] private readonly INetManager _netManager = default!;
|
||||
[Dependency] protected readonly IResourceManager ResourceManager = default!;
|
||||
|
||||
public const double BytesToMegabytes = 0.000001d;
|
||||
|
||||
/// <summary>
|
||||
/// The prefix for any and all downloaded network resources.
|
||||
/// </summary>
|
||||
private static readonly ResourcePath Prefix = ResourcePath.Root / "Uploaded";
|
||||
|
||||
protected readonly MemoryContentRoot ContentRoot = new();
|
||||
|
||||
public virtual void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<NetworkResourceUploadMessage>(ResourceUploadMsg);
|
||||
|
||||
// Add our content root to the resource manager.
|
||||
ResourceManager.AddRoot(Prefix, ContentRoot);
|
||||
}
|
||||
|
||||
protected abstract void ResourceUploadMsg(NetworkResourceUploadMessage msg);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// This is called automatically when the IoCManager's dependency collection is cleared.
|
||||
// MemoryContentRoot uses a ReaderWriterLockSlim, which we need to dispose of.
|
||||
ContentRoot.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user