Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/wizards/master' into upstr…
Browse files Browse the repository at this point in the history
…eam-sync
  • Loading branch information
Morb0 committed Aug 31, 2024
2 parents 85a4a7c + 8dbaca3 commit 0670981
Show file tree
Hide file tree
Showing 34 changed files with 573 additions and 194 deletions.
22 changes: 14 additions & 8 deletions Content.IntegrationTests/Tests/Actions/ActionPvsDetachTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ public async Task TestActionDetach()
// PVS-detach action entities
// We do this by just giving them the ghost layer
var visSys = server.System<VisibilitySystem>();
var enumerator = server.Transform(ent).ChildEnumerator;
while (enumerator.MoveNext(out var child))
server.Post(() =>
{
visSys.AddLayer(child, (int) VisibilityFlags.Ghost);
}
var enumerator = server.Transform(ent).ChildEnumerator;
while (enumerator.MoveNext(out var child))
{
visSys.AddLayer(child, (int) VisibilityFlags.Ghost);
}
});
await pair.RunTicksSync(5);

// Client's actions have left been detached / are out of view, but action comp state has not changed
Assert.That(sys.GetActions(ent).Count(), Is.EqualTo(initActions));
Assert.That(cSys.GetActions(cEnt).Count(), Is.EqualTo(initActions));

// Re-enter PVS view
enumerator = server.Transform(ent).ChildEnumerator;
while (enumerator.MoveNext(out var child))
server.Post(() =>
{
visSys.RemoveLayer(child, (int) VisibilityFlags.Ghost);
}
var enumerator = server.Transform(ent).ChildEnumerator;
while (enumerator.MoveNext(out var child))
{
visSys.RemoveLayer(child, (int) VisibilityFlags.Ghost);
}
});
await pair.RunTicksSync(5);
Assert.That(sys.GetActions(ent).Count(), Is.EqualTo(initActions));
Assert.That(cSys.GetActions(cEnt).Count(), Is.EqualTo(initActions));
Expand Down
6 changes: 5 additions & 1 deletion Content.IntegrationTests/Tests/Buckle/BuckleDragTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public async Task BucklePullTest()
Assert.That(pullable.BeingPulled, Is.False);

// Strap the human to the chair
Assert.That(Server.System<SharedBuckleSystem>().TryBuckle(sUrist, SPlayer, STarget.Value));
await Server.WaitAssertion(() =>
{
Assert.That(Server.System<SharedBuckleSystem>().TryBuckle(sUrist, SPlayer, STarget.Value));
});

await RunTicks(5);
Assert.That(buckle.Buckled, Is.True);
Assert.That(buckle.BuckledTo, Is.EqualTo(STarget));
Expand Down
13 changes: 8 additions & 5 deletions Content.IntegrationTests/Tests/CargoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,16 @@ public async Task StackPrice()
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;

var entManager = server.ResolveDependency<IEntityManager>();
var priceSystem = entManager.System<PricingSystem>();

var ent = entManager.SpawnEntity("StackEnt", MapCoordinates.Nullspace);
var price = priceSystem.GetPrice(ent);
Assert.That(price, Is.EqualTo(100.0));
await server.WaitAssertion(() =>
{
var priceSystem = entManager.System<PricingSystem>();
var ent = entManager.SpawnEntity("StackEnt", MapCoordinates.Nullspace);
var price = priceSystem.GetPrice(ent);
Assert.That(price, Is.EqualTo(100.0));
});

await pair.CleanReturnAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ await server.WaitPost(() =>
mobStateComp = entManager.GetComponent<MobStateComponent>(player);
mobThresholdsComp = entManager.GetComponent<MobThresholdsComponent>(player);
damageableComp = entManager.GetComponent<DamageableComponent>(player);
});
if (protoMan.TryIndex<DamageTypePrototype>("Slash", out var slashProto))
damageableSystem.TryChangeDamage(player, new DamageSpecifier(slashProto, FixedPoint2.New(46.5)));
if (protoMan.TryIndex<DamageTypePrototype>("Slash", out var slashProto))
damageableSystem.TryChangeDamage(player, new DamageSpecifier(slashProto, FixedPoint2.New(46.5)));
});

// Check that running the suicide command kills the player
// and properly ghosts them without them being able to return to their body
Expand Down
3 changes: 2 additions & 1 deletion Content.IntegrationTests/Tests/Shuttle/DockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ public async Task TestPlanetDock()
var entManager = server.ResolveDependency<IEntityManager>();
var dockingSystem = entManager.System<DockingSystem>();
var mapSystem = entManager.System<SharedMapSystem>();
MapGridComponent mapGrid = default!;

var mapGrid = entManager.AddComponent<MapGridComponent>(map.MapUid);
var shuttle = EntityUid.Invalid;

// Spawn shuttle and affirm no valid docks.
await server.WaitAssertion(() =>
{
mapGrid = entManager.AddComponent<MapGridComponent>(map.MapUid);
entManager.DeleteEntity(map.Grid);
Assert.That(entManager.System<MapLoaderSystem>().TryLoad(otherMap.MapId, "/Maps/Shuttles/emergency.yml", out var rootUids));
shuttle = rootUids[0];
Expand Down
5 changes: 2 additions & 3 deletions Content.Server/Administration/BanPanelEui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@ private async void BanPlayer(string? target, string? ipAddressString, bool useLa
}

if (erase &&
targetUid != null &&
_playerManager.TryGetSessionById(targetUid.Value, out var targetPlayer))
targetUid != null)
{
try
{
if (_entities.TrySystem(out AdminSystem? adminSystem))
adminSystem.Erase(targetPlayer);
adminSystem.Erase(targetUid.Value);
}
catch (Exception e)
{
Expand Down
47 changes: 47 additions & 0 deletions Content.Server/Administration/Commands/EraseCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Linq;
using Content.Server.Administration.Systems;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Console;

namespace Content.Server.Administration.Commands;

[AdminCommand(AdminFlags.Admin)]
public sealed class EraseCommand : LocalizedEntityCommands
{
[Dependency] private readonly IPlayerLocator _locator = default!;
[Dependency] private readonly IPlayerManager _players = default!;
[Dependency] private readonly AdminSystem _admin = default!;

public override string Command => "erase";

public override async void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("cmd-erase-invalid-args"));
shell.WriteLine(Help);
return;
}

var located = await _locator.LookupIdByNameOrIdAsync(args[0]);

if (located == null)
{
shell.WriteError(Loc.GetString("cmd-erase-player-not-found"));
return;
}

_admin.Erase(located.UserId);
}

public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length != 1)
return CompletionResult.Empty;

var options = _players.Sessions.OrderBy(c => c.Name).Select(c => c.Name).ToArray();

return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-erase-player-completion"));
}
}
56 changes: 30 additions & 26 deletions Content.Server/Administration/Systems/AdminSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.Mind;
using Content.Shared.PDA;
using Content.Shared.Players;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Popups;
using Content.Shared.Roles;
Expand Down Expand Up @@ -387,30 +389,32 @@ private void SendBabyJailStatusAll()
}
}

/// <summary>
/// Erases a player from the round.
/// This removes them and any trace of them from the round, deleting their
/// chat messages and showing a popup to other players.
/// Their items are dropped on the ground.
/// </summary>
public void Erase(ICommonSession player)
{
var entity = player.AttachedEntity;
_chat.DeleteMessagesBy(player);

if (entity != null && !TerminatingOrDeleted(entity.Value))
/// <summary>
/// Erases a player from the round.
/// This removes them and any trace of them from the round, deleting their
/// chat messages and showing a popup to other players.
/// Their items are dropped on the ground.
/// </summary>
public void Erase(NetUserId uid)
{
if (TryComp(entity.Value, out TransformComponent? transform))
_chat.DeleteMessagesBy(uid);

if (!_minds.TryGetMind(uid, out var mindId, out var mind) || mind.OwnedEntity == null || TerminatingOrDeleted(mind.OwnedEntity.Value))
return;

var entity = mind.OwnedEntity.Value;

if (TryComp(entity, out TransformComponent? transform))
{
var coordinates = _transform.GetMoverCoordinates(entity.Value, transform);
var name = Identity.Entity(entity.Value, EntityManager);
var coordinates = _transform.GetMoverCoordinates(entity, transform);
var name = Identity.Entity(entity, EntityManager);
_popup.PopupCoordinates(Loc.GetString("admin-erase-popup", ("user", name)), coordinates, PopupType.LargeCaution);
var filter = Filter.Pvs(coordinates, 1, EntityManager, _playerManager);
var audioParams = new AudioParams().WithVolume(3);
_audio.PlayStatic("/Audio/Effects/pop_high.ogg", filter, coordinates, true, audioParams);
}

foreach (var item in _inventory.GetHandOrInventoryEntities(entity.Value))
foreach (var item in _inventory.GetHandOrInventoryEntities(entity))
{
if (TryComp(item, out PdaComponent? pda) &&
TryComp(pda.ContainedId, out StationRecordKeyStorageComponent? keyStorage) &&
Expand All @@ -434,29 +438,29 @@ keyStorage.Key is { } key &&
}
}

if (_inventory.TryGetContainerSlotEnumerator(entity.Value, out var enumerator))
if (_inventory.TryGetContainerSlotEnumerator(entity, out var enumerator))
{
while (enumerator.NextItem(out var item, out var slot))
{
if (_inventory.TryUnequip(entity.Value, entity.Value, slot.Name, true, true))
if (_inventory.TryUnequip(entity, entity, slot.Name, true, true))
_physics.ApplyAngularImpulse(item, ThrowingSystem.ThrowAngularImpulse);
}
}

if (TryComp(entity.Value, out HandsComponent? hands))
if (TryComp(entity, out HandsComponent? hands))
{
foreach (var hand in _hands.EnumerateHands(entity.Value, hands))
foreach (var hand in _hands.EnumerateHands(entity, hands))
{
_hands.TryDrop(entity.Value, hand, checkActionBlocker: false, doDropInteraction: false, handsComp: hands);
_hands.TryDrop(entity, hand, checkActionBlocker: false, doDropInteraction: false, handsComp: hands);
}
}
}

_minds.WipeMind(player);
QueueDel(entity);
_minds.WipeMind(mindId, mind);
QueueDel(entity);

_gameTicker.SpawnObserver(player);
}
if (_playerManager.TryGetSessionById(uid, out var session))
_gameTicker.SpawnObserver(session);
}

private void OnSessionPlayTimeUpdated(ICommonSession session)
{
Expand Down
62 changes: 33 additions & 29 deletions Content.Server/Administration/Systems/AdminVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
using Robust.Shared.Toolshed;
using Robust.Shared.Utility;
using System.Linq;
using System.Numerics;
using Content.Server.Silicons.Laws;
using Content.Shared.Silicons.Laws;
using Content.Shared.Silicons.Laws.Components;
using Robust.Server.Player;
using Content.Shared.Mind;
using Robust.Shared.Physics.Components;
using static Content.Shared.Configurable.ConfigurationComponent;

Expand Down Expand Up @@ -137,34 +137,6 @@ private void AddAdminVerbs(GetVerbsEvent<Verb> args)
prayerVerb.Impact = LogImpact.Low;
args.Verbs.Add(prayerVerb);

// Erase
args.Verbs.Add(new Verb
{
Text = Loc.GetString("admin-verbs-erase"),
Message = Loc.GetString("admin-verbs-erase-description"),
Category = VerbCategory.Admin,
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png")),
Act = () =>
{
_adminSystem.Erase(targetActor.PlayerSession);
},
Impact = LogImpact.Extreme,
ConfirmationPopup = true
});

// Respawn
args.Verbs.Add(new Verb()
{
Text = Loc.GetString("admin-player-actions-respawn"),
Category = VerbCategory.Admin,
Act = () =>
{
_console.ExecuteCommand(player, $"respawn {targetActor.PlayerSession.Name}");
},
ConfirmationPopup = true,
// No logimpact as the command does it internally.
});

// Spawn - Like respawn but on the spot.
args.Verbs.Add(new Verb()
{
Expand Down Expand Up @@ -225,6 +197,38 @@ private void AddAdminVerbs(GetVerbsEvent<Verb> args)
});
}

if (_mindSystem.TryGetMind(args.Target, out _, out var mind) && mind.UserId != null)
{
// Erase
args.Verbs.Add(new Verb
{
Text = Loc.GetString("admin-verbs-erase"),
Message = Loc.GetString("admin-verbs-erase-description"),
Category = VerbCategory.Admin,
Icon = new SpriteSpecifier.Texture(
new("/Textures/Interface/VerbIcons/delete_transparent.svg.192dpi.png")),
Act = () =>
{
_adminSystem.Erase(mind.UserId.Value);
},
Impact = LogImpact.Extreme,
ConfirmationPopup = true
});

// Respawn
args.Verbs.Add(new Verb
{
Text = Loc.GetString("admin-player-actions-respawn"),
Category = VerbCategory.Admin,
Act = () =>
{
_console.ExecuteCommand(player, $"respawn \"{mind.UserId}\"");
},
ConfirmationPopup = true,
// No logimpact as the command does it internally.
});
}

// Freeze
var frozen = TryComp<AdminFrozenComponent>(args.Target, out var frozenComp);
var frozenAndMuted = frozenComp?.Muted ?? false;
Expand Down
8 changes: 4 additions & 4 deletions Content.Server/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private void OnAdminOocEnabledChanged(bool val)
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-admin-ooc-chat-enabled-message" : "chat-manager-admin-ooc-chat-disabled-message"));
}

public void DeleteMessagesBy(ICommonSession player)
{
if (!_players.TryGetValue(player.UserId, out var user))
return;
public void DeleteMessagesBy(NetUserId uid)
{
if (!_players.TryGetValue(uid, out var user))
return;

var msg = new MsgDeleteChatMessagesBy { Key = user.Key, Entities = user.Entities };
_netManager.ServerSendToAll(msg);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Chat/Managers/IChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessag

bool MessageCharacterLimit(ICommonSession player, string message);

void DeleteMessagesBy(ICommonSession player);
void DeleteMessagesBy(NetUserId uid);

[return: NotNullIfNotNull(nameof(author))]
ChatUser? EnsurePlayer(NetUserId? author);
Expand Down
Loading

0 comments on commit 0670981

Please sign in to comment.