2020-08-14 09:09:58 -07:00
|
|
|
using Content.Server.GameObjects.Components;
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2019-10-02 10:45:06 +02:00
|
|
|
using Content.Server.GameTicking;
|
|
|
|
|
using Content.Server.Interfaces.GameTicking;
|
|
|
|
|
using Content.Shared.Sandbox;
|
2020-08-14 09:09:58 -07:00
|
|
|
using Robust.Server.Interfaces.Console;
|
2020-02-08 20:45:02 +01:00
|
|
|
using Robust.Server.Console;
|
|
|
|
|
using Robust.Server.Interfaces.Placement;
|
2019-10-02 10:45:06 +02:00
|
|
|
using Robust.Server.Interfaces.Player;
|
|
|
|
|
using Robust.Server.Player;
|
|
|
|
|
using Robust.Shared.Enums;
|
2020-07-17 03:38:58 -05:00
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
2019-10-02 10:45:06 +02:00
|
|
|
using Robust.Shared.Interfaces.Network;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-02-08 21:23:37 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
2019-10-02 10:45:06 +02:00
|
|
|
|
|
|
|
|
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;
|
2020-02-08 20:45:02 +01:00
|
|
|
[Dependency] private readonly IPlacementManager _placementManager;
|
|
|
|
|
[Dependency] private readonly IConGroupController _conGroupController;
|
2020-07-17 03:38:58 -05:00
|
|
|
[Dependency] private readonly IEntityManager _entityManager;
|
2020-08-14 09:09:58 -07:00
|
|
|
[Dependency] private readonly IConsoleShell _shell;
|
2019-10-02 10:45:06 +02:00
|
|
|
#pragma warning restore 649
|
|
|
|
|
|
|
|
|
|
private bool _isSandboxEnabled;
|
|
|
|
|
|
2020-02-08 21:23:37 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2019-10-02 10:45:06 +02:00
|
|
|
public bool IsSandboxEnabled
|
|
|
|
|
{
|
|
|
|
|
get => _isSandboxEnabled;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isSandboxEnabled = value;
|
|
|
|
|
UpdateSandboxStatusForAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
|
|
|
|
_netManager.RegisterNetMessage<MsgSandboxStatus>(nameof(MsgSandboxStatus));
|
|
|
|
|
_netManager.RegisterNetMessage<MsgSandboxRespawn>(nameof(MsgSandboxRespawn), SandboxRespawnReceived);
|
2020-07-17 03:38:58 -05:00
|
|
|
_netManager.RegisterNetMessage<MsgSandboxGiveAccess>(nameof(MsgSandboxGiveAccess), SandboxGiveAccessReceived);
|
2020-08-14 09:09:58 -07:00
|
|
|
_netManager.RegisterNetMessage<MsgSandboxGiveAghost>(nameof(MsgSandboxGiveAghost), SandboxGiveAghostReceived);
|
|
|
|
|
_netManager.RegisterNetMessage<MsgSandboxSuicide>(nameof(MsgSandboxSuicide), SandboxSuicideReceived);
|
2019-10-02 10:45:06 +02:00
|
|
|
|
|
|
|
|
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
|
|
|
|
|
_gameTicker.OnRunLevelChanged += GameTickerOnOnRunLevelChanged;
|
2020-02-08 20:45:02 +01:00
|
|
|
|
|
|
|
|
_placementManager.AllowPlacementFunc = placement =>
|
|
|
|
|
{
|
|
|
|
|
if (IsSandboxEnabled)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var channel = placement.MsgChannel;
|
|
|
|
|
var player = _playerManager.GetSessionByChannel(channel);
|
|
|
|
|
|
|
|
|
|
if (_conGroupController.CanAdminPlace(player))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
2019-10-02 10:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-17 03:38:58 -05:00
|
|
|
private void SandboxGiveAccessReceived(MsgSandboxGiveAccess message)
|
|
|
|
|
{
|
|
|
|
|
if(!IsSandboxEnabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
|
|
|
|
if(player.AttachedEntity.TryGetComponent<HandsComponent>(out var hands))
|
|
|
|
|
{
|
|
|
|
|
;
|
|
|
|
|
hands.PutInHandOrDrop(
|
|
|
|
|
_entityManager.SpawnEntity("CaptainIDCard",
|
|
|
|
|
player.AttachedEntity.Transform.GridPosition).GetComponent<ItemComponent>());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-14 09:09:58 -07:00
|
|
|
private void SandboxGiveAghostReceived(MsgSandboxGiveAghost message)
|
|
|
|
|
{
|
|
|
|
|
if (!IsSandboxEnabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
2020-08-14 21:55:39 +02:00
|
|
|
|
|
|
|
|
_shell.ExecuteCommand(player, _conGroupController.CanCommand(player, "aghost") ? "aghost" : "ghost");
|
2020-08-14 09:09:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SandboxSuicideReceived(MsgSandboxSuicide message)
|
|
|
|
|
{
|
|
|
|
|
if (!IsSandboxEnabled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var player = _playerManager.GetSessionByChannel(message.MsgChannel);
|
|
|
|
|
_shell.ExecuteCommand(player, $"suicide");
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 10:45:06 +02:00
|
|
|
private void UpdateSandboxStatusForAll()
|
|
|
|
|
{
|
|
|
|
|
var msg = _netManager.CreateNetMessage<MsgSandboxStatus>();
|
|
|
|
|
msg.SandboxAllowed = IsSandboxEnabled;
|
|
|
|
|
_netManager.ServerSendToAll(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|