diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 520fc7e29b8..f0316a8742f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -43,7 +43,7 @@ END TEMPLATE--> ### Bugfixes -*None yet* +* Clients connecting to a server now always load prototype uploads after resource uploads, fixing ordering bugs that could cause various errors. ### Other diff --git a/Robust.Server/ServerIoC.cs b/Robust.Server/ServerIoC.cs index 016e8271ee1..d69eb0f6eb5 100644 --- a/Robust.Server/ServerIoC.cs +++ b/Robust.Server/ServerIoC.cs @@ -93,8 +93,10 @@ internal static void RegisterIoC(IDependencyCollection deps) deps.Register(); deps.Register(); deps.Register(); + deps.Register(); deps.Register(); deps.Register(); + deps.Register(); } } } diff --git a/Robust.Server/Upload/GamePrototypeLoadManager.cs b/Robust.Server/Upload/GamePrototypeLoadManager.cs index 3cc11c17a87..e1daf963a20 100644 --- a/Robust.Server/Upload/GamePrototypeLoadManager.cs +++ b/Robust.Server/Upload/GamePrototypeLoadManager.cs @@ -24,8 +24,6 @@ public override void Initialize() base.Initialize(); _sawmill = _logManager.GetSawmill("adminbus"); - - _netManager.Connected += NetManagerOnConnected; } public override void SendGamePrototype(string prototype) @@ -50,7 +48,7 @@ protected override void LoadPrototypeData(GamePrototypeLoadMessage message) } } - private void NetManagerOnConnected(object? sender, NetChannelArgs e) + internal void SendToNewUser(INetChannel channel) { // Just dump all the prototypes on connect, before them missing could be an issue. foreach (var prototype in LoadedPrototypes) @@ -59,7 +57,7 @@ private void NetManagerOnConnected(object? sender, NetChannelArgs e) { PrototypeData = prototype }; - e.Channel.SendMessage(msg); + channel.SendMessage(msg); } } } diff --git a/Robust.Server/Upload/NetworkResourceManager.cs b/Robust.Server/Upload/NetworkResourceManager.cs index 8e324a1854f..e3fbe382412 100644 --- a/Robust.Server/Upload/NetworkResourceManager.cs +++ b/Robust.Server/Upload/NetworkResourceManager.cs @@ -27,7 +27,6 @@ public override void Initialize() { base.Initialize(); - _serverNetManager.Connected += ServerNetManagerOnConnected; _cfgManager.OnValueChanged(CVars.ResourceUploadingEnabled, value => Enabled = value, true); _cfgManager.OnValueChanged(CVars.ResourceUploadingLimitMb, value => SizeLimit = value, true); } @@ -65,14 +64,14 @@ protected override void ResourceUploadMsg(NetworkResourceUploadMessage msg) OnResourceUploaded?.Invoke(session, msg); } - private void ServerNetManagerOnConnected(object? sender, NetChannelArgs e) + internal void SendToNewUser(INetChannel channel) { foreach (var (path, data) in ContentRoot.GetAllFiles()) { var msg = new NetworkResourceUploadMessage(); msg.RelativePath = path; msg.Data = data; - e.Channel.SendMessage(msg); + channel.SendMessage(msg); } } } diff --git a/Robust.Server/Upload/UploadedContentManager.cs b/Robust.Server/Upload/UploadedContentManager.cs new file mode 100644 index 00000000000..3bea743a71d --- /dev/null +++ b/Robust.Server/Upload/UploadedContentManager.cs @@ -0,0 +1,28 @@ +using Robust.Shared.IoC; +using Robust.Shared.Network; + +namespace Robust.Server.Upload; + +/// +/// Responsible for sending uploaded content to clients when they connect. +/// +internal sealed class UploadedContentManager +{ + [Dependency] private readonly IServerNetManager _netManager = default!; + [Dependency] private readonly GamePrototypeLoadManager _prototypeLoadManager = default!; + [Dependency] private readonly NetworkResourceManager _networkResourceManager = default!; + + public void Initialize() + { + _netManager.Connected += NetManagerOnConnected; + } + + private void NetManagerOnConnected(object? sender, NetChannelArgs e) + { + // This just shells out to the other managers, ensuring they are ordered properly. + // Resources must be done before prototypes. + // Note: both net messages sent here are on the same group and are therefore ordered. + _networkResourceManager.SendToNewUser(e.Channel); + _prototypeLoadManager.SendToNewUser(e.Channel); + } +} diff --git a/Robust.Shared/Upload/NetworkResourceUploadMessage.cs b/Robust.Shared/Upload/NetworkResourceUploadMessage.cs index 7b7021b0820..0e7c62ff30f 100644 --- a/Robust.Shared/Upload/NetworkResourceUploadMessage.cs +++ b/Robust.Shared/Upload/NetworkResourceUploadMessage.cs @@ -8,8 +8,7 @@ namespace Robust.Shared.Upload; public sealed class NetworkResourceUploadMessage : NetMessage { - public override NetDeliveryMethod DeliveryMethod => NetDeliveryMethod.ReliableUnordered; - public override MsgGroups MsgGroup => MsgGroups.Command; + public override MsgGroups MsgGroup => MsgGroups.String; public byte[] Data { get; set; } = Array.Empty(); public ResPath RelativePath { get; set; } = ResPath.Self;