From be0d22ad5e52cc845c5bca869984764ada313031 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 20 May 2023 13:53:09 +1200 Subject: [PATCH] Move upload commands to engine (#16582) --- .../Commands/LoadPrototypeCommand.cs | 33 ------ .../Administration/Commands/UploadFile.cs | 64 ----------- .../Administration/Commands/UploadFolder.cs | 76 ------------- .../Managers/GamePrototypeLoadManager.cs | 36 ------ .../Managers/NetworkResourceManager.cs | 15 --- .../UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs | 5 +- Content.Client/Entry/EntryPoint.cs | 5 - Content.Client/IoC/ClientContentIoC.cs | 2 - .../ContentNetworkResourceManager.cs | 36 ++++++ .../GamePrototypeLoadManager.cs | 91 --------------- .../Administration/NetworkResourceManager.cs | 105 ------------------ Content.Server/Entry/EntryPoint.cs | 3 +- Content.Server/IoC/ServerContentIoC.cs | 4 +- .../GamePrototypeLoadMessage.cs | 22 ---- .../IGamePrototypeLoadManager.cs | 19 ---- .../NetworkResourceUploadMessage.cs | 41 ------- .../SharedNetworkResourceManager.cs | 52 --------- Content.Shared/CCVar/CCVars.cs | 14 --- .../administration/commands/uploadfolder.ftl | 7 -- Resources/engineCommandPerms.yml | 3 + 20 files changed, 43 insertions(+), 590 deletions(-) delete mode 100644 Content.Client/Administration/Commands/LoadPrototypeCommand.cs delete mode 100644 Content.Client/Administration/Commands/UploadFile.cs delete mode 100644 Content.Client/Administration/Commands/UploadFolder.cs delete mode 100644 Content.Client/Administration/Managers/GamePrototypeLoadManager.cs delete mode 100644 Content.Client/Administration/Managers/NetworkResourceManager.cs create mode 100644 Content.Server/Administration/ContentNetworkResourceManager.cs delete mode 100644 Content.Server/Administration/GamePrototypeLoadManager.cs delete mode 100644 Content.Server/Administration/NetworkResourceManager.cs delete mode 100644 Content.Shared/Administration/GamePrototypeLoadMessage.cs delete mode 100644 Content.Shared/Administration/IGamePrototypeLoadManager.cs delete mode 100644 Content.Shared/Administration/NetworkResourceUploadMessage.cs delete mode 100644 Content.Shared/Administration/SharedNetworkResourceManager.cs delete mode 100644 Resources/Locale/en-US/administration/commands/uploadfolder.ftl diff --git a/Content.Client/Administration/Commands/LoadPrototypeCommand.cs b/Content.Client/Administration/Commands/LoadPrototypeCommand.cs deleted file mode 100644 index 9a962f9b76..0000000000 --- a/Content.Client/Administration/Commands/LoadPrototypeCommand.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.IO; -using Content.Shared.Administration; -using Robust.Client.UserInterface; -using Robust.Shared.Console; - -namespace Content.Client.Administration.Commands; - -public sealed class LoadPrototypeCommand : IConsoleCommand -{ - public string Command { get; } = "loadprototype"; - public string Description { get; } = "Load a prototype file into the server."; - public string Help => Command; - - public void Execute(IConsoleShell shell, string argStr, string[] args) - { - LoadPrototype(); - } - - public static async void LoadPrototype() - { - var dialogManager = IoCManager.Resolve(); - var loadManager = IoCManager.Resolve(); - - var stream = await dialogManager.OpenFile(); - if (stream is null) - return; - - // ew oop - var reader = new StreamReader(stream); - var proto = await reader.ReadToEndAsync(); - loadManager.SendGamePrototype(proto); - } -} diff --git a/Content.Client/Administration/Commands/UploadFile.cs b/Content.Client/Administration/Commands/UploadFile.cs deleted file mode 100644 index db501c8fb1..0000000000 --- a/Content.Client/Administration/Commands/UploadFile.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Content.Shared.Administration; -using Content.Shared.CCVar; -using Robust.Client.UserInterface; -using Robust.Shared.Configuration; -using Robust.Shared.Console; -using Robust.Shared.Network; -using Robust.Shared.Utility; - -namespace Content.Client.Administration.Commands; - -public sealed class UploadFile : IConsoleCommand -{ - public string Command => "uploadfile"; - public string Description => "Uploads a resource to the server."; - public string Help => $"{Command} [relative path for the resource]"; - - public async void Execute(IConsoleShell shell, string argStr, string[] args) - { - var cfgMan = IoCManager.Resolve(); - - if (!cfgMan.GetCVar(CCVars.ResourceUploadingEnabled)) - { - shell.WriteError("Network Resource Uploading is currently disabled by the server."); - return; - } - - if (args.Length != 1) - { - shell.WriteError("Wrong number of arguments!"); - return; - } - - var path = new ResPath(args[0]).ToRelativePath(); - - var dialog = IoCManager.Resolve(); - - var filters = new FileDialogFilters(new FileDialogFilters.Group(path.Extension)); - await using var file = await dialog.OpenFile(filters); - - if (file == null) - { - shell.WriteError("Error picking file!"); - return; - } - - var sizeLimit = cfgMan.GetCVar(CCVars.ResourceUploadingLimitMb); - - if (sizeLimit > 0f && file.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit) - { - shell.WriteError($"File above the current size limit! It must be smaller than {sizeLimit} MB."); - return; - } - - var data = file.CopyToArray(); - - var netManager = IoCManager.Resolve(); - var msg = netManager.CreateNetMessage(); - - msg.RelativePath = path; - msg.Data = data; - - netManager.ClientSendMessage(msg); - } -} diff --git a/Content.Client/Administration/Commands/UploadFolder.cs b/Content.Client/Administration/Commands/UploadFolder.cs deleted file mode 100644 index 128da57577..0000000000 --- a/Content.Client/Administration/Commands/UploadFolder.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System.IO; -using Content.Shared.Administration; -using Content.Shared.CCVar; -using Robust.Shared.Configuration; -using Robust.Shared.Console; -using Robust.Shared.ContentPack; -using Robust.Shared.Network; -using Robust.Shared.Utility; - -namespace Content.Client.Administration.Commands; - -public sealed class UploadFolder : IConsoleCommand -{ - public string Command => "uploadfolder"; - public string Description => Loc.GetString("uploadfolder-command-description"); - public string Help => Loc.GetString("uploadfolder-command-help"); - - private static readonly ResPath BaseUploadFolderPath = new("/UploadFolder"); - - [Dependency] private IResourceManager _resourceManager = default!; - [Dependency] private IConfigurationManager _configManager = default!; - - public async void Execute(IConsoleShell shell, string argStr, string[] args) - { - var fileCount = 0; - - - if (!_configManager.GetCVar(CCVars.ResourceUploadingEnabled)) - { - shell.WriteError( Loc.GetString("uploadfolder-command-resource-upload-disabled")); - return; - } - - if (args.Length != 1) - { - shell.WriteError( Loc.GetString("uploadfolder-command-wrong-args")); - shell.WriteLine( Loc.GetString("uploadfolder-command-help")); - return; - } - var folderPath = new ResPath(BaseUploadFolderPath + $"/{args[0]}"); - - if (!_resourceManager.UserData.Exists(folderPath.ToRootedPath())) - { - shell.WriteError( Loc.GetString("uploadfolder-command-folder-not-found",("folder", folderPath))); - return; // bomb out if the folder doesnt exist in /UploadFolder - } - - //Grab all files in specified folder and upload them - foreach (var filepath in _resourceManager.UserData.Find($"{folderPath.ToRelativePath()}/").files ) - { - - await using var filestream = _resourceManager.UserData.Open(filepath,FileMode.Open); - { - var sizeLimit = _configManager.GetCVar(CCVars.ResourceUploadingLimitMb); - if (sizeLimit > 0f && filestream.Length * SharedNetworkResourceManager.BytesToMegabytes > sizeLimit) - { - shell.WriteError( Loc.GetString("uploadfolder-command-file-too-big", ("filename",filepath), ("sizeLimit",sizeLimit))); - return; - } - - var data = filestream.CopyToArray(); - - var netManager = IoCManager.Resolve(); - var msg = netManager.CreateNetMessage(); - - msg.RelativePath = new ResPath($"{filepath.ToString().Remove(0,14)}"); //removes /UploadFolder/ from path - msg.Data = data; - - netManager.ClientSendMessage(msg); - fileCount++; - } - } - - shell.WriteLine( Loc.GetString("uploadfolder-command-success",("fileCount",fileCount))); - } -} diff --git a/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs b/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs deleted file mode 100644 index 504b35cad2..0000000000 --- a/Content.Client/Administration/Managers/GamePrototypeLoadManager.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Content.Shared.Administration; -using Robust.Shared.Network; -using Robust.Shared.Prototypes; - -namespace Content.Client.Administration.Managers; - -public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager -{ - [Dependency] private readonly IClientNetManager _netManager = default!; - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly ILocalizationManager _localizationManager = default!; - - public void Initialize() - { - _netManager.RegisterNetMessage(LoadGamePrototype); - } - - private void LoadGamePrototype(GamePrototypeLoadMessage message) - { - var changed = new Dictionary>(); - _prototypeManager.LoadString(message.PrototypeData, true, changed); - _prototypeManager.ResolveResults(); - _prototypeManager.ReloadPrototypes(changed); - _localizationManager.ReloadLocalizations(); - Logger.InfoS("adminbus", "Loaded adminbus prototype data."); - } - - public void SendGamePrototype(string prototype) - { - var msg = new GamePrototypeLoadMessage - { - PrototypeData = prototype - }; - _netManager.ClientSendMessage(msg); - } -} diff --git a/Content.Client/Administration/Managers/NetworkResourceManager.cs b/Content.Client/Administration/Managers/NetworkResourceManager.cs deleted file mode 100644 index 2fc5456901..0000000000 --- a/Content.Client/Administration/Managers/NetworkResourceManager.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Content.Shared.Administration; - -namespace Content.Client.Administration.Managers; - -public sealed class NetworkResourceManager : SharedNetworkResourceManager -{ - /// - /// Callback for when the server sends a new resource. - /// - /// The network message containing the data. - protected override void ResourceUploadMsg(NetworkResourceUploadMessage msg) - { - ContentRoot.AddOrUpdateFile(msg.RelativePath, msg.Data); - } -} diff --git a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs index e002b4a923..43439748d8 100644 --- a/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/AdminbusTab/AdminbusTab.xaml.cs @@ -1,9 +1,8 @@ -using System.IO; -using Content.Client.Administration.Commands; -using Content.Client.Administration.Managers; +using Content.Client.Administration.Managers; using Content.Client.UserInterface.Systems.DecalPlacer; using Content.Shared.Administration; using Robust.Client.AutoGenerated; +using Robust.Client.Upload.Commands; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controllers.Implementations; using Robust.Client.UserInterface.Controls; diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 4b30700524..4e6035d17a 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -52,14 +52,11 @@ namespace Content.Client.Entry [Dependency] private readonly ViewportManager _viewportManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IInputManager _inputManager = default!; - [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IOverlayManager _overlayManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; [Dependency] private readonly IClientPreferencesManager _clientPreferencesManager = default!; [Dependency] private readonly EuiManager _euiManager = default!; [Dependency] private readonly IVoteManager _voteManager = default!; - [Dependency] private readonly IGamePrototypeLoadManager _gamePrototypeLoadManager = default!; - [Dependency] private readonly NetworkResourceManager _networkResources = default!; [Dependency] private readonly DocumentParsingManager _documentParsingManager = default!; [Dependency] private readonly GhostKickManager _ghostKick = default!; [Dependency] private readonly ExtendedDisconnectInformationManager _extendedDisconnectInformation = default!; @@ -162,8 +159,6 @@ namespace Content.Client.Entry _clientPreferencesManager.Initialize(); _euiManager.Initialize(); _voteManager.Initialize(); - _gamePrototypeLoadManager.Initialize(); - _networkResources.Initialize(); _userInterfaceManager.SetDefaultTheme("SS14DefaultTheme"); _documentParsingManager.Initialize(); diff --git a/Content.Client/IoC/ClientContentIoC.cs b/Content.Client/IoC/ClientContentIoC.cs index bea60fc3f3..e8c22ad028 100644 --- a/Content.Client/IoC/ClientContentIoC.cs +++ b/Content.Client/IoC/ClientContentIoC.cs @@ -39,8 +39,6 @@ namespace Content.Client.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); - IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Server/Administration/ContentNetworkResourceManager.cs b/Content.Server/Administration/ContentNetworkResourceManager.cs new file mode 100644 index 0000000000..0d3f3291e6 --- /dev/null +++ b/Content.Server/Administration/ContentNetworkResourceManager.cs @@ -0,0 +1,36 @@ +using Content.Server.Database; +using Content.Shared.CCVar; +using Robust.Server.Player; +using Robust.Server.Upload; +using Robust.Shared.Configuration; +using Robust.Shared.Upload; + +namespace Content.Server.Administration; + +public sealed class ContentNetworkResourceManager +{ + [Dependency] private readonly IServerDbManager _serverDb = default!; + [Dependency] private readonly NetworkResourceManager _netRes = default!; + [Dependency] private readonly IConfigurationManager _cfgManager = default!; + + [ViewVariables] public bool StoreUploaded { get; set; } = true; + + public void Initialize() + { + _cfgManager.OnValueChanged(CCVars.ResourceUploadingStoreEnabled, value => StoreUploaded = value, true); + AutoDelete(_cfgManager.GetCVar(CCVars.ResourceUploadingStoreDeletionDays)); + _netRes.OnResourceUploaded += OnUploadResource; + } + + private async void OnUploadResource(IPlayerSession session, NetworkResourceUploadMessage msg) + { + if (StoreUploaded) + await _serverDb.AddUploadedResourceLogAsync(session.UserId, DateTime.Now, msg.RelativePath.ToString(), msg.Data); + } + + private async void AutoDelete(int days) + { + if (days > 0) + await _serverDb.PurgeUploadedResourceLogAsync(days); + } +} diff --git a/Content.Server/Administration/GamePrototypeLoadManager.cs b/Content.Server/Administration/GamePrototypeLoadManager.cs deleted file mode 100644 index b8ed602f61..0000000000 --- a/Content.Server/Administration/GamePrototypeLoadManager.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Content.Server.Administration.Managers; -using Content.Shared.Administration; -using Robust.Server.Player; -using Robust.Shared.Network; -using Robust.Shared.Prototypes; -using Robust.Shared.Replays; -using Robust.Shared.Serialization.Markdown.Mapping; - -namespace Content.Server.Administration; - -/// -/// Manages sending runtime-loaded prototypes from game staff to clients. -/// -public sealed class GamePrototypeLoadManager : IGamePrototypeLoadManager -{ - [Dependency] private readonly IReplayRecordingManager _replay = default!; - [Dependency] private readonly IServerNetManager _netManager = default!; - [Dependency] private readonly IAdminManager _adminManager = default!; - [Dependency] private readonly IPlayerManager _playerManager = default!; - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly ILocalizationManager _localizationManager = default!; - - private readonly List _loadedPrototypes = new(); - public IReadOnlyList LoadedPrototypes => _loadedPrototypes; - - public void Initialize() - { - _netManager.RegisterNetMessage(ClientLoadsPrototype); - _netManager.Connected += NetManagerOnConnected; - _replay.OnRecordingStarted += OnStartReplayRecording; - } - - private void OnStartReplayRecording((MappingDataNode, List) initReplayData) - { - // replays will need information about currently loaded prototypes - foreach (var prototype in _loadedPrototypes) - { - initReplayData.Item2.Add(new ReplayPrototypeUploadMsg { PrototypeData = prototype }); - } - } - - public void SendGamePrototype(string prototype) - { - - } - - private void ClientLoadsPrototype(GamePrototypeLoadMessage message) - { - var player = _playerManager.GetSessionByChannel(message.MsgChannel); - if (_adminManager.IsAdmin(player) && _adminManager.HasAdminFlag(player, AdminFlags.Query)) - { - LoadPrototypeData(message.PrototypeData); - Logger.InfoS("adminbus", $"Loaded adminbus prototype data from {player.Name}."); - } - else - { - message.MsgChannel.Disconnect("Sent prototype message without permission!"); - } - } - - private void LoadPrototypeData(string prototypeData) - { - _loadedPrototypes.Add(prototypeData); - - _replay.QueueReplayMessage(new ReplayPrototypeUploadMsg { PrototypeData = prototypeData }); - - var msg = new GamePrototypeLoadMessage - { - PrototypeData = prototypeData - }; - _netManager.ServerSendToAll(msg); // everyone load it up! - var changed = new Dictionary>(); - _prototypeManager.LoadString(prototypeData, true, changed); // server needs it too. - _prototypeManager.ResolveResults(); - _prototypeManager.ReloadPrototypes(changed); - _localizationManager.ReloadLocalizations(); - } - - private void NetManagerOnConnected(object? sender, NetChannelArgs e) - { - // Just dump all the prototypes on connect, before them missing could be an issue. - foreach (var prototype in _loadedPrototypes) - { - var msg = new GamePrototypeLoadMessage - { - PrototypeData = prototype - }; - e.Channel.SendMessage(msg); - } - } -} diff --git a/Content.Server/Administration/NetworkResourceManager.cs b/Content.Server/Administration/NetworkResourceManager.cs deleted file mode 100644 index 93a6955965..0000000000 --- a/Content.Server/Administration/NetworkResourceManager.cs +++ /dev/null @@ -1,105 +0,0 @@ -using Content.Server.Administration.Managers; -using Content.Server.Database; -using Content.Shared.Administration; -using Content.Shared.CCVar; -using Robust.Server.Player; -using Robust.Shared.Configuration; -using Robust.Shared.Network; -using Robust.Shared.Replays; -using Robust.Shared.Serialization.Markdown.Mapping; - -namespace Content.Server.Administration; - -public sealed class NetworkResourceManager : SharedNetworkResourceManager -{ - [Dependency] private readonly IPlayerManager _playerManager = default!; - [Dependency] private readonly IAdminManager _adminManager = default!; - [Dependency] private readonly IServerNetManager _serverNetManager = default!; - [Dependency] private readonly IConfigurationManager _cfgManager = default!; - [Dependency] private readonly IServerDbManager _serverDb = default!; - [Dependency] private readonly IReplayRecordingManager _replay = default!; - - [ViewVariables] public bool Enabled { get; private set; } = true; - [ViewVariables] public float SizeLimit { get; private set; } = 0f; - [ViewVariables] public bool StoreUploaded { get; set; } = true; - - public override void Initialize() - { - base.Initialize(); - - _serverNetManager.Connected += ServerNetManagerOnConnected; - _cfgManager.OnValueChanged(CCVars.ResourceUploadingEnabled, value => Enabled = value, true); - _cfgManager.OnValueChanged(CCVars.ResourceUploadingLimitMb, value => SizeLimit = value, true); - _cfgManager.OnValueChanged(CCVars.ResourceUploadingStoreEnabled, value => StoreUploaded = value, true); - - AutoDelete(_cfgManager.GetCVar(CCVars.ResourceUploadingStoreDeletionDays)); - _replay.OnRecordingStarted += OnStartReplayRecording; - } - - private void OnStartReplayRecording((MappingDataNode, List) initReplayData) - { - // replays will need information about currently loaded extra resources - foreach (var (path, data) in ContentRoot.GetAllFiles()) - { - initReplayData.Item2.Add(new ReplayResourceUploadMsg { RelativePath = path, Data = data }); - } - } - - /// - /// Callback for when a client attempts to upload a resource. - /// - /// - /// - protected override async void ResourceUploadMsg(NetworkResourceUploadMessage msg) - { - // Do not allow uploading any new resources if it has been disabled. - // Note: Any resources uploaded before being disabled will still be kept and sent. - if (!Enabled) - return; - - if (!_playerManager.TryGetSessionByChannel(msg.MsgChannel, out var session)) - return; - - // +QUERY only for now. - if (!_adminManager.HasAdminFlag(session, AdminFlags.Query)) - return; - - // Ensure the data is under the current size limit, if it's currently enabled. - if (SizeLimit > 0f && msg.Data.Length * BytesToMegabytes > SizeLimit) - return; - - ContentRoot.AddOrUpdateFile(msg.RelativePath, msg.Data); - - // Now we broadcast the message! - foreach (var channel in _serverNetManager.Channels) - { - channel.SendMessage(msg); - } - - _replay.QueueReplayMessage(new ReplayResourceUploadMsg { RelativePath = msg.RelativePath, Data = msg.Data }); - - if (!StoreUploaded) - return; - - await _serverDb.AddUploadedResourceLogAsync(session.UserId, DateTime.Now, msg.RelativePath.ToString(), msg.Data); - } - - private void ServerNetManagerOnConnected(object? sender, NetChannelArgs e) - { - foreach (var (path, data) in ContentRoot.GetAllFiles()) - { - var msg = new NetworkResourceUploadMessage(); - msg.RelativePath = path; - msg.Data = data; - e.Channel.SendMessage(msg); - } - } - - private async void AutoDelete(int days) - { - if (days <= 0) - return; // auto-deletion disabled... - - await _serverDb.PurgeUploadedResourceLogAsync(days); - } -} diff --git a/Content.Server/Entry/EntryPoint.cs b/Content.Server/Entry/EntryPoint.cs index 147e0b4f94..f287265882 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -105,8 +105,7 @@ namespace Content.Server.Entry _dbManager.Init(); IoCManager.Resolve().Init(); IoCManager.Resolve().Initialize(); - IoCManager.Resolve().Initialize(); - IoCManager.Resolve().Initialize(); + IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); diff --git a/Content.Server/IoC/ServerContentIoC.cs b/Content.Server/IoC/ServerContentIoC.cs index 106c995d44..68865ca1c4 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -20,7 +20,6 @@ using Content.Server.ServerInfo; using Content.Server.ServerUpdates; using Content.Server.Voting.Managers; using Content.Server.Worldgen.Tools; -using Content.Shared.Administration; using Content.Shared.Administration.Logs; using Content.Shared.Administration.Managers; using Content.Shared.Kitchen; @@ -48,10 +47,9 @@ namespace Content.Server.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Shared/Administration/GamePrototypeLoadMessage.cs b/Content.Shared/Administration/GamePrototypeLoadMessage.cs deleted file mode 100644 index fdb44de234..0000000000 --- a/Content.Shared/Administration/GamePrototypeLoadMessage.cs +++ /dev/null @@ -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); - } -} diff --git a/Content.Shared/Administration/IGamePrototypeLoadManager.cs b/Content.Shared/Administration/IGamePrototypeLoadManager.cs deleted file mode 100644 index b02ad69ced..0000000000 --- a/Content.Shared/Administration/IGamePrototypeLoadManager.cs +++ /dev/null @@ -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!; -} diff --git a/Content.Shared/Administration/NetworkResourceUploadMessage.cs b/Content.Shared/Administration/NetworkResourceUploadMessage.cs deleted file mode 100644 index 9f5f64213b..0000000000 --- a/Content.Shared/Administration/NetworkResourceUploadMessage.cs +++ /dev/null @@ -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(); - 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); - } -} diff --git a/Content.Shared/Administration/SharedNetworkResourceManager.cs b/Content.Shared/Administration/SharedNetworkResourceManager.cs deleted file mode 100644 index 3ed35eb691..0000000000 --- a/Content.Shared/Administration/SharedNetworkResourceManager.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Robust.Shared.ContentPack; -using Robust.Shared.Network; -using Robust.Shared.Serialization; -using Robust.Shared.Utility; - -namespace Content.Shared.Administration; - -/// -/// Manager that allows resources to be added at runtime by admins. -/// They will be sent to all clients automatically. -/// -public abstract class SharedNetworkResourceManager : IDisposable -{ - [Dependency] private readonly INetManager _netManager = default!; - [Dependency] protected readonly IResourceManager ResourceManager = default!; - - public const double BytesToMegabytes = 0.000001d; - - /// - /// The prefix for any and all downloaded network resources. - /// - private static readonly ResPath Prefix = ResPath.Root / "Uploaded"; - - protected readonly MemoryContentRoot ContentRoot = new(); - - public virtual void Initialize() - { - _netManager.RegisterNetMessage(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!; - } -} diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index bd7954ee08..7d40e21f0d 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1425,20 +1425,6 @@ namespace Content.Shared.CCVar * Network Resource Manager */ - /// - /// Controls whether new resources can be uploaded by admins. - /// Does not prevent already uploaded resources from being sent. - /// - public static readonly CVarDef ResourceUploadingEnabled = - CVarDef.Create("netres.enabled", true, CVar.REPLICATED | CVar.SERVER); - - /// - /// Controls the data size limit in megabytes for uploaded resources. If they're too big, they will be dropped. - /// Set to zero or a negative value to disable limit. - /// - public static readonly CVarDef ResourceUploadingLimitMb = - CVarDef.Create("netres.limit", 3f, CVar.REPLICATED | CVar.SERVER); - /// /// Whether uploaded files will be stored in the server's database. /// This is useful to keep "logs" on what files admins have uploaded in the past. diff --git a/Resources/Locale/en-US/administration/commands/uploadfolder.ftl b/Resources/Locale/en-US/administration/commands/uploadfolder.ftl deleted file mode 100644 index 9d2ec1b542..0000000000 --- a/Resources/Locale/en-US/administration/commands/uploadfolder.ftl +++ /dev/null @@ -1,7 +0,0 @@ -uploadfolder-command-description = Uploads a folder from your UserData folder recursively to the server contentDB. -uploadfolder-command-help = uploadfolder [folder you want to upload in userdata/UploadFolder] -uploadfolder-command-wrong-args = Wrong number of arguments! -uploadfolder-command-folder-not-found = Folder {$folder} not found! -uploadfolder-command-resource-upload-disabled = Network Resource Uploading is currently disabled. check Server CVars. -uploadfolder-command-file-too-big = File {$filename} above the current size limit! It must be smaller than {$sizeLimit} MB. skipping. -uploadfolder-command-success = Uploaded {$fileCount} files diff --git a/Resources/engineCommandPerms.yml b/Resources/engineCommandPerms.yml index 05793d11e9..a2aafdff78 100644 --- a/Resources/engineCommandPerms.yml +++ b/Resources/engineCommandPerms.yml @@ -124,3 +124,6 @@ - Flags: QUERY Commands: - forall + - uploadfile + - loadprototype + - uploadfolder