Files
RobustToolbox/Robust.Server/Upload/GamePrototypeLoadManager.cs
T
83c2a1be11 [Dependency] source generator part 2 (#6550)
* [Dependency] source generator

No more reflection, no more codegen at runtime

Also various changes to Roslyn helpers to make this easier to write.

Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback.

No fallback is available for [field: Dependency] properties, due to a Roslyn bug.

Code Fixes exist. We love Roslyn

* Apply dependencies generator changes to all code

* Release notes

* Preprocessor got hands

* Handle nullable dependencies

These are bad but gotta deal with it.

* Apply suggestions from code review

Co-authored-by: Moony <moony@hellomouse.net>

* Fine, let's not use collection expressions

---------

Co-authored-by: Moony <moony@hellomouse.net>
2026-05-08 12:38:33 +02:00

64 lines
2.0 KiB
C#

using Robust.Server.Console;
using Robust.Server.Player;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Network;
using Robust.Shared.Upload;
namespace Robust.Server.Upload;
/// <summary>
/// Manages sending runtime-loaded prototypes from game staff to clients.
/// </summary>
public sealed partial class GamePrototypeLoadManager : SharedPrototypeLoadManager
{
[Dependency] private IServerNetManager _netManager = default!;
[Dependency] private IPlayerManager _playerManager = default!;
[Dependency] private IConGroupController _controller = default!;
[Dependency] private ILogManager _logManager = default!;
private ISawmill _sawmill = default!;
public override void Initialize()
{
base.Initialize();
_sawmill = _logManager.GetSawmill("adminbus");
}
public override void SendGamePrototype(string prototype)
{
var msg = new GamePrototypeLoadMessage { PrototypeData = prototype };
base.LoadPrototypeData(msg);
_netManager.ServerSendToAll(msg);
}
protected override void LoadPrototypeData(GamePrototypeLoadMessage message)
{
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
if (_controller.CanCommand(player, "loadprototype"))
{
base.LoadPrototypeData(message);
_netManager.ServerSendToAll(message); // everyone load it up!
_sawmill.Info($"Loaded adminbus prototype data from {player.Name}.");
}
else
{
message.MsgChannel.Disconnect("Sent prototype message without permission!");
}
}
internal void SendToNewUser(INetChannel channel)
{
if (LoadedPrototypes.Count == 0)
return;
// Just dump all the prototypes on connect, before them missing could be an issue.
var msg = new GamePrototypeLoadMessage
{
PrototypeData = string.Join("\n\n", LoadedPrototypes)
};
channel.SendMessage(msg);
}
}