ConGroups are gone. Long live admin flags in content.

This commit is contained in:
Pieter-Jan Briers
2020-10-30 16:06:48 +01:00
parent f04818437d
commit ad58a056d7
62 changed files with 2673 additions and 289 deletions

View File

@@ -0,0 +1,52 @@
using Content.Server.GameObjects.Components.Observer;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public class AGhost : IClientCommand
{
public string Command => "aghost";
public string Description => "Makes you an admin ghost.";
public string Help => "aghost";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player == null)
{
shell.SendText((IPlayerSession) null, "Nah");
return;
}
var mind = player.ContentData().Mind;
if (mind == null)
{
shell.SendText(player, "You can't ghost here!");
return;
}
if (mind.VisitingEntity != null && mind.VisitingEntity.Prototype.ID == "AdminObserver")
{
var visiting = mind.VisitingEntity;
mind.UnVisit();
visiting.Delete();
}
else
{
var canReturn = mind.CurrentEntity != null && !mind.CurrentEntity.HasComponent<GhostComponent>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var ghost = entityManager.SpawnEntity("AdminObserver", player.AttachedEntity.Transform.MapPosition);
if(canReturn)
mind.Visit(ghost);
else
mind.TransferTo(ghost);
ghost.GetComponent<GhostComponent>().CanReturnToBody = canReturn;
}
}
}
}

View File

@@ -0,0 +1,58 @@
using System;
using Content.Server.Database;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
using Robust.Shared.Network;
#nullable enable
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Ban)]
public sealed class BanCommand : IClientCommand
{
public string Command => "ban";
public string Description => "Bans somebody";
public string Help => "Usage: <name or user ID> <reason> <duration in minutes, or 0 for permanent ban>";
public async void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
var plyMgr = IoCManager.Resolve<IPlayerManager>();
var dbMan = IoCManager.Resolve<IServerDbManager>();
var target = args[0];
var reason = args[1];
var duration = int.Parse(args[2]);
NetUserId targetUid;
if (plyMgr.TryGetSessionByUsername(target, out var targetSession))
{
targetUid = targetSession.UserId;
}
else if (Guid.TryParse(target, out var targetGuid))
{
targetUid = new NetUserId(targetGuid);
}
else
{
shell.SendText(player, "Unable to find user with that name.");
return;
}
DateTimeOffset? expires = null;
if (duration > 0)
{
expires = DateTimeOffset.Now + TimeSpan.FromMinutes(duration);
}
await dbMan.AddServerBanAsync(new ServerBanDef(targetUid, null, DateTimeOffset.Now, expires, reason, player?.UserId));
if (plyMgr.TryGetSessionById(targetUid, out var targetPlayer))
{
targetPlayer.ConnectedClient.Disconnect("You've been banned. Tough shit.");
}
}
}
}

View File

@@ -0,0 +1,70 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Observer;
using Content.Server.Players;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
class ControlMob : IClientCommand
{
public string Command => "controlmob";
public string Description => Loc.GetString("Transfers user mind to the specified entity.");
public string Help => Loc.GetString("Usage: controlmob <mobUid>.");
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player == null)
{
shell.SendText((IPlayerSession) null, "Server cannot do this.");
return;
}
if (args.Length != 1)
{
shell.SendText(player, Loc.GetString("Wrong number of arguments."));
return;
}
var mind = player.ContentData().Mind;
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!int.TryParse(args[0], out var targetId))
{
shell.SendText(player, Loc.GetString("Argument must be a number."));
return;
}
var eUid = new EntityUid(targetId);
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
{
shell.SendText(player, Loc.GetString("Invalid entity ID."));
return;
}
var target = entityManager.GetEntity(eUid);
if (!target.TryGetComponent(out MindComponent mindComponent))
{
shell.SendText(player, Loc.GetString("Target entity is not a mob!"));
return;
}
var oldEntity = mind.CurrentEntity;
mindComponent.Mind?.TransferTo(null);
mind.TransferTo(target);
if(oldEntity.HasComponent<GhostComponent>())
oldEntity.Delete();
}
}
}

View File

@@ -0,0 +1,31 @@
using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
#nullable enable
namespace Content.Server.Administration
{
[UsedImplicitly]
[AdminCommand(AdminFlags.None)]
public class DeAdminCommand : IClientCommand
{
public string Command => "deadmin";
public string Description => "Temporarily de-admins you so you can experience the round as a normal player.";
public string Help => "Usage: deadmin\nUse readmin to re-admin after using this.";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (player == null)
{
shell.SendText(player, "You cannot use this command from the server console.");
return;
}
var mgr = IoCManager.Resolve<IAdminManager>();
mgr.DeAdmin(player);
}
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
class DeleteEntitiesWithComponent : IClientCommand
{
public string Command => "deleteewc";
public string Description
{
get
{
return Loc.GetString("Deletes entities with the specified components.");
}
}
public string Help
{
get
{
return Loc.GetString("Usage: deleteewc <componentName_1> <componentName_2> ... <componentName_n>\nDeletes any entities with the components specified.");
}
}
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (args.Length < 1)
{
shell.SendText(player, Help);
return;
}
var factory = IoCManager.Resolve<IComponentFactory>();
var components = new List<Type>();
foreach (var arg in args)
{
components.Add(factory.GetRegistration(arg).Type);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var entities = entityManager.GetEntities(new MultipleTypeEntityQuery(components));
var count = 0;
foreach (var entity in entities)
{
entity.Delete();
count += 1;
}
shell.SendText(player, Loc.GetString("Deleted {0} entities", count));
}
}
}

View File

@@ -0,0 +1,41 @@
#nullable enable
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public class DeleteEntitiesWithId : IClientCommand
{
public string Command => "deleteewi";
public string Description => "Deletes entities with the specified prototype ID.";
public string Help => $"Usage: {Command} <prototypeID>";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, Help);
return;
}
var id = args[0].ToLower();
var entityManager = IoCManager.Resolve<IEntityManager>();
var query = new PredicateEntityQuery(e => e.Prototype?.ID.ToLower() == id);
var entities = entityManager.GetEntities(query);
var i = 0;
foreach (var entity in entities)
{
entity.Delete();
i++;
}
shell.SendText(player, $"Deleted all entities with id {id}. Occurrences: {i}");
}
}
}

View File

@@ -0,0 +1,35 @@
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
#nullable enable
namespace Content.Server.Administration
{
[AnyCommand]
public class ReAdminCommand : IClientCommand
{
public string Command => "readmin";
public string Description => "Re-admins you if you previously de-adminned.";
public string Help => "Usage: readmin";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
if (player == null)
{
shell.SendText(player, "You cannot use this command from the server console.");
return;
}
var mgr = IoCManager.Resolve<IAdminManager>();
if (mgr.GetAdminData(player, includeDeAdmin: true) == null)
{
shell.SendText(player, "You're not an admin.");
return;
}
mgr.ReAdmin(player);
}
}
}

View File

@@ -0,0 +1,42 @@
#nullable enable
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.IoC;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Server)]
public class ReadyAll : IClientCommand
{
public string Command => "readyall";
public string Description => "Readies up all players in the lobby.";
public string Help => $"{Command} | ̣{Command} <ready>";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
{
var ready = true;
if (args.Length > 0)
{
ready = bool.Parse(args[0]);
}
var gameTicker = IoCManager.Resolve<IGameTicker>();
var playerManager = IoCManager.Resolve<IPlayerManager>();
if (gameTicker.RunLevel != GameRunLevel.PreRoundLobby)
{
shell.SendText(player, "This command can only be ran while in the lobby!");
return;
}
foreach (var p in playerManager.GetAllPlayers())
{
gameTicker.ToggleReady(p, ready);
}
}
}
}

View File

@@ -0,0 +1,56 @@
using Content.Server.GlobalVerbs;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
class Rejuvenate : IClientCommand
{
public string Command => "rejuvenate";
public string Description
{
get
{
return Loc.GetString("Fully heals a mob.");
}
}
public string Help
{
get
{
return Loc.GetString("Usage: rejuvenate <mobUid_1> <mobUid_2> ... <mobUid_n>\nAttempts to heal the user's mob if no arguments are provided.");
}
}
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (args.Length < 1 && player != null) //Try to heal the users mob if applicable
{
shell.SendText(player, Loc.GetString("Healing the user's mob since no arguments were provided."));
if (player.AttachedEntity == null)
{
shell.SendText(player, Loc.GetString("There's no entity attached to the user."));
return;
}
RejuvenateVerb.PerformRejuvenate(player.AttachedEntity);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
foreach (var arg in args)
{
if(!EntityUid.TryParse(arg, out var uid) || !entityManager.TryGetEntity(uid, out var entity))
{
shell.SendText(player, Loc.GetString("Could not find entity {0}", arg));
continue;
}
RejuvenateVerb.PerformRejuvenate(entity);
}
}
}
}

View File

@@ -0,0 +1,129 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Markers;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public class WarpCommand : IClientCommand
{
public string Command => "warp";
public string Description => "Teleports you to predefined areas on the map.";
public string Help =>
"warp <location>\nLocations you can teleport to are predefined by the map. " +
"You can specify '?' as location to get a list of valid locations.";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
{
if (player == null)
{
shell.SendText((IPlayerSession) null, "Only players can use this command");
return;
}
if (args.Length != 1)
{
shell.SendText(player, "Expected a single argument.");
return;
}
var comp = IoCManager.Resolve<IComponentManager>();
var location = args[0];
if (location == "?")
{
var locations = string.Join(", ",
comp.EntityQuery<WarpPointComponent>()
.Select(p => p.Location)
.Where(p => p != null)
.OrderBy(p => p)
.Distinct());
shell.SendText(player, locations);
}
else
{
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
{
shell.SendText(player, "You are not in-game!");
return;
}
var mapManager = IoCManager.Resolve<IMapManager>();
var currentMap = player.AttachedEntity.Transform.MapID;
var currentGrid = player.AttachedEntity.Transform.GridID;
var entityManager = IoCManager.Resolve<IEntityManager>();
var found = comp.EntityQuery<WarpPointComponent>()
.Where(p => p.Location == location)
.Select(p => p.Owner.Transform.Coordinates)
.OrderBy(p => p, Comparer<EntityCoordinates>.Create((a, b) =>
{
// Sort so that warp points on the same grid/map are first.
// So if you have two maps loaded with the same warp points,
// it will prefer the warp points on the map you're currently on.
var aGrid = a.GetGridId(entityManager);
var bGrid = b.GetGridId(entityManager);
if (aGrid == bGrid)
{
return 0;
}
if (aGrid == currentGrid)
{
return -1;
}
if (bGrid == currentGrid)
{
return 1;
}
var mapA = mapManager.GetGrid(aGrid).ParentMapId;
var mapB = mapManager.GetGrid(bGrid).ParentMapId;
if (mapA == mapB)
{
return 0;
}
if (mapA == currentMap)
{
return -1;
}
if (mapB == currentMap)
{
return 1;
}
return 0;
}))
.FirstOrDefault();
if (found.GetGridId(entityManager) != GridId.Invalid)
{
player.AttachedEntity.Transform.Coordinates = found;
if (player.AttachedEntity.TryGetComponent(out IPhysicsComponent physics))
{
physics.Stop();
}
}
else
{
shell.SendText(player, "That location does not exist!");
}
}
}
}
}