Move upload commands to engine (#16582)

This commit is contained in:
Leon Friedrich
2023-05-20 13:53:09 +12:00
committed by GitHub
parent 8422e51678
commit be0d22ad5e
20 changed files with 43 additions and 590 deletions

View File

@@ -1,22 +0,0 @@
using Lidgren.Network;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
namespace Content.Shared.Administration;
public sealed class GamePrototypeLoadMessage : NetMessage
{
public override MsgGroups MsgGroup => MsgGroups.String;
public string PrototypeData { get; set; } = string.Empty;
public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer)
{
PrototypeData = buffer.ReadString();
}
public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
{
buffer.Write(PrototypeData);
}
}

View File

@@ -1,19 +0,0 @@
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Administration;
public interface IGamePrototypeLoadManager
{
public void Initialize();
public void SendGamePrototype(string prototype);
}
// TODO REPLAYS
// Figure out a way to just directly save NetMessage objects to replays. This just uses IRobustSerializer as a crutch.
[Serializable, NetSerializable]
public sealed class ReplayPrototypeUploadMsg
{
public string PrototypeData = default!;
}

View File

@@ -1,41 +0,0 @@
using Lidgren.Network;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
namespace Content.Shared.Administration;
public sealed class NetworkResourceUploadMessage : NetMessage
{
public override NetDeliveryMethod DeliveryMethod => NetDeliveryMethod.ReliableUnordered;
public override MsgGroups MsgGroup => MsgGroups.Command;
public byte[] Data { get; set; } = Array.Empty<byte>();
public ResPath RelativePath { get; set; } = ResPath.Self;
public NetworkResourceUploadMessage()
{
}
public NetworkResourceUploadMessage(byte[] data, ResPath relativePath)
{
Data = data;
RelativePath = relativePath;
}
public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer)
{
var dataLength = buffer.ReadVariableInt32();
Data = buffer.ReadBytes(dataLength);
// What is the second argument here?
RelativePath = new ResPath(buffer.ReadString());
}
public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
{
buffer.WriteVariableInt32(Data.Length);
buffer.Write(Data);
buffer.Write(RelativePath.ToString());
buffer.Write(ResPath.Separator);
}
}

View File

@@ -1,52 +0,0 @@
using Robust.Shared.ContentPack;
using Robust.Shared.Network;
using Robust.Shared.Serialization;
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 ResPath Prefix = ResPath.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();
}
// TODO REPLAYS
// Figure out a way to just directly save NetMessage objects to replays. This just uses IRobustSerializer as a crutch.
[Serializable, NetSerializable]
public sealed class ReplayResourceUploadMsg
{
public byte[] Data = default!;
public ResPath RelativePath = default!;
}
}