Sandbox panel
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Server.GameTicking;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Sandbox;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.ContentPack;
|
||||
@@ -48,6 +49,7 @@ namespace Content.Server
|
||||
IoCManager.Register<IGameTicker, GameTicker>();
|
||||
IoCManager.Register<IChatManager, ChatManager>();
|
||||
IoCManager.Register<IMoMMILink, MoMMILink>();
|
||||
IoCManager.Register<ISandboxManager, SandboxManager>();
|
||||
if (TestingCallbacks != null)
|
||||
{
|
||||
var cast = (ServerModuleTestingCallbacks) TestingCallbacks;
|
||||
@@ -73,6 +75,7 @@ namespace Content.Server
|
||||
base.PostInit();
|
||||
|
||||
_gameTicker.Initialize();
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
}
|
||||
|
||||
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Sandbox;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.GameTicking.GamePresets
|
||||
{
|
||||
public sealed class PresetSandbox : GamePreset
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly ISandboxManager _sandboxManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
// Nothing yet.
|
||||
_sandboxManager.IsSandboxEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,8 +156,7 @@ namespace Content.Server.GameTicking
|
||||
|
||||
RunLevel = GameRunLevel.InRound;
|
||||
|
||||
// TODO: Allow other presets to be selected.
|
||||
var preset = (GamePreset)_dynamicTypeFactory.CreateInstance(_presetType ?? typeof(PresetSandbox));
|
||||
var preset = _dynamicTypeFactory.CreateInstance<GamePreset>(_presetType ?? typeof(PresetSandbox));
|
||||
preset.Start();
|
||||
|
||||
foreach (var (playerSession, ready) in _playersInLobby.ToList())
|
||||
|
||||
8
Content.Server/Sandbox/ISandboxManager.cs
Normal file
8
Content.Server/Sandbox/ISandboxManager.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Content.Server.Sandbox
|
||||
{
|
||||
public interface ISandboxManager
|
||||
{
|
||||
bool IsSandboxEnabled { get; set; }
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
80
Content.Server/Sandbox/SandboxManager.cs
Normal file
80
Content.Server/Sandbox/SandboxManager.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Shared.Sandbox;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Sandbox
|
||||
{
|
||||
internal sealed class SandboxManager : SharedSandboxManager, ISandboxManager
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IPlayerManager _playerManager;
|
||||
[Dependency] private readonly IServerNetManager _netManager;
|
||||
[Dependency] private readonly IGameTicker _gameTicker;
|
||||
#pragma warning restore 649
|
||||
|
||||
private bool _isSandboxEnabled;
|
||||
|
||||
public bool IsSandboxEnabled
|
||||
{
|
||||
get => _isSandboxEnabled;
|
||||
set
|
||||
{
|
||||
_isSandboxEnabled = value;
|
||||
UpdateSandboxStatusForAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus));
|
||||
_netManager.RegisterNetMessage<MsgSandboxRespawn>(nameof(MsgSandboxRespawn), SandboxRespawnReceived);
|
||||
|
||||
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
||||
_gameTicker.OnRunLevelChanged += GameTickerOnOnRunLevelChanged;
|
||||
}
|
||||
|
||||
private void GameTickerOnOnRunLevelChanged(GameRunLevelChangedEventArgs obj)
|
||||
{
|
||||
// Automatically clear sandbox state when round resets.
|
||||
if (obj.NewRunLevel == GameRunLevel.PreRoundLobby)
|
||||
{
|
||||
IsSandboxEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerStatusChanged(object sender, SessionStatusEventArgs e)
|
||||
{
|
||||
if (e.NewStatus != SessionStatus.Connected || e.OldStatus != SessionStatus.Connecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||
msg.SandboxAllowed = IsSandboxEnabled;
|
||||
_netManager.ServerSendMessage(msg, e.Session.ConnectedClient);
|
||||
}
|
||||
|
||||
private void SandboxRespawnReceived(MsgSandboxRespawn message)
|
||||
{
|
||||
if (!IsSandboxEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
||||
_gameTicker.Respawn(player);
|
||||
}
|
||||
|
||||
private void UpdateSandboxStatusForAll()
|
||||
{
|
||||
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
||||
msg.SandboxAllowed = IsSandboxEnabled;
|
||||
_netManager.ServerSendToAll(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user