Fix 3000 errors

This commit is contained in:
DrSmugleaf
2021-12-05 18:09:01 +01:00
parent 2bfec7ec62
commit 2a3b7d809d
569 changed files with 2979 additions and 3280 deletions

View File

@@ -24,7 +24,7 @@ namespace Content.Server.Chat.Commands
return;
}
if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
if (player.Status != SessionStatus.InGame || !player.AttachedEntity.HasValue)
return;
if (args.Length < 1)

View File

@@ -19,14 +19,13 @@ namespace Content.Server.Chat.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
if (shell.Player is not IPlayerSession player)
{
shell.WriteLine("This command cannot be run from the server.");
return;
}
if (player.Status != SessionStatus.InGame || !player.AttachedEntityUid.HasValue)
if (player.Status != SessionStatus.InGame || !player.AttachedEntity.HasValue)
return;
if (args.Length < 1)
@@ -38,9 +37,8 @@ namespace Content.Server.Chat.Commands
var chat = IoCManager.Resolve<IChatManager>();
var chatSanitizer = IoCManager.Resolve<IChatSanitizationManager>();
var playerEntity = player.AttachedEntity;
if (playerEntity == null)
if (player.AttachedEntity is not {Valid: true} playerEntity)
{
shell.WriteLine("You don't have an entity!");
return;
@@ -58,7 +56,7 @@ namespace Content.Server.Chat.Commands
return;
}
if (mindComponent.OwnedEntity == null)
if (mindComponent.OwnedEntity == default)
{
shell.WriteError("You don't have an entity!");
return;

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.Act;
using Content.Server.Administration;
@@ -9,7 +8,6 @@ using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Players;
using Content.Server.Popups;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
@@ -27,13 +25,15 @@ namespace Content.Server.Chat.Commands
[AnyCommand]
internal class SuicideCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entities = default!;
public string Command => "suicide";
public string Description => Loc.GetString("suicide-command-description");
public string Help => Loc.GetString("suicide-command-help-text");
private void DealDamage(ISuicideAct suicide, IChatManager chat, IEntity target)
private void DealDamage(ISuicideAct suicide, IChatManager chat, EntityUid target)
{
var kind = suicide.Suicide(target, chat);
if (kind != SuicideKind.Special)
@@ -73,10 +73,9 @@ namespace Content.Server.Chat.Commands
var chat = IoCManager.Resolve<IChatManager>();
var mind = player.ContentData()?.Mind;
var owner = mind?.OwnedComponent?.Owner;
// This check also proves mind not-null for at the end when the mob is ghosted.
if (owner == null)
if (mind?.OwnedComponent?.Owner is not {Valid: true} owner)
{
shell.WriteLine("You don't have a mind!");
return;
@@ -88,11 +87,11 @@ namespace Content.Server.Chat.Commands
EntitySystem.Get<AdminLogSystem>().Add(LogType.Suicide, $"{player.AttachedEntity} is committing suicide");
// Held item suicide
var handsComponent = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(owner);
var handsComponent = _entities.GetComponent<HandsComponent>(owner);
var itemComponent = handsComponent.GetActiveHand;
if (itemComponent != null)
{
var suicide = IoCManager.Resolve<IEntityManager>().GetComponents<ISuicideAct>(itemComponent.Owner).FirstOrDefault();
var suicide = _entities.GetComponents<ISuicideAct>(itemComponent.Owner).FirstOrDefault();
if (suicide != null)
{
@@ -107,9 +106,9 @@ namespace Content.Server.Chat.Commands
{
foreach (var entity in entities)
{
if (IoCManager.Resolve<IEntityManager>().HasComponent<ItemComponent>(entity))
if (_entities.HasComponent<ItemComponent>(entity))
continue;
var suicide = IoCManager.Resolve<IEntityManager>().GetComponents<ISuicideAct>(entity).FirstOrDefault();
var suicide = _entities.GetComponents<ISuicideAct>(entity).FirstOrDefault();
if (suicide != null)
{
DealDamage(suicide, chat, owner);

View File

@@ -114,7 +114,7 @@ namespace Content.Server.Chat.Managers
_netManager.ServerSendMessage(msg, player.ConnectedClient);
}
public void EntitySay(IEntity source, string message, bool hideChat=false)
public void EntitySay(EntityUid source, string message, bool hideChat=false)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanSpeak(source))
{
@@ -122,7 +122,7 @@ namespace Content.Server.Chat.Managers
}
// Check if message exceeds the character limit if the sender is a player
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(source, out ActorComponent? actor) &&
if (_entManager.TryGetComponent(source, out ActorComponent? actor) &&
message.Length > MaxMessageLength)
{
var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength));
@@ -142,19 +142,22 @@ namespace Content.Server.Chat.Managers
// We'll try to avoid using MapPosition as EntityCoordinates can early-out and potentially be faster for common use cases
// Downside is it may potentially convert to MapPosition unnecessarily.
var sourceMapId = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(source).MapID;
var sourceCoords = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(source).Coordinates;
var sourceMapId = _entManager.GetComponent<TransformComponent>(source).MapID;
var sourceCoords = _entManager.GetComponent<TransformComponent>(source).Coordinates;
var clients = new List<INetChannel>();
foreach (var player in _playerManager.Sessions)
{
if (player.AttachedEntity == null) continue;
var transform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(player.AttachedEntity);
if (player.AttachedEntity is not {Valid: true} playerEntity)
continue;
var transform = _entManager.GetComponent<TransformComponent>(playerEntity);
if (transform.MapID != sourceMapId ||
!IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(player.AttachedEntity) &&
!sourceCoords.InRange(_entManager, transform.Coordinates, VoiceRange)) continue;
!_entManager.HasComponent<GhostComponent>(playerEntity) &&
!sourceCoords.InRange(_entManager, transform.Coordinates, VoiceRange))
continue;
clients.Add(player.ConnectedClient);
}
@@ -168,9 +171,9 @@ namespace Content.Server.Chat.Managers
message = message[0].ToString().ToUpper() +
message.Remove(0, 1);
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(source, out InventoryComponent? inventory) &&
if (_entManager.TryGetComponent(source, out InventoryComponent? inventory) &&
inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.EARS, out ItemComponent? item) &&
IoCManager.Resolve<IEntityManager>().TryGetComponent(item.Owner, out HeadsetComponent? headset))
_entManager.TryGetComponent(item.Owner, out HeadsetComponent? headset))
{
headset.RadioRequested = true;
}
@@ -194,13 +197,13 @@ namespace Content.Server.Chat.Managers
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Local;
msg.Message = message;
msg.MessageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",("entityName", Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(source).EntityName));
msg.MessageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",("entityName", Name: _entManager.GetComponent<MetaDataComponent>(source).EntityName));
msg.SenderEntity = source;
msg.HideChat = hideChat;
_netManager.ServerSendToMany(msg, clients);
}
public void EntityMe(IEntity source, string action)
public void EntityMe(EntityUid source, string action)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanEmote(source))
{
@@ -208,7 +211,7 @@ namespace Content.Server.Chat.Managers
}
// Check if entity is a player
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(source, out ActorComponent? actor))
if (!_entManager.TryGetComponent(source, out ActorComponent? actor))
{
return;
}
@@ -223,7 +226,7 @@ namespace Content.Server.Chat.Managers
action = FormattedMessage.EscapeText(action);
var clients = Filter.Empty()
.AddInRange(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(source).MapPosition, VoiceRange)
.AddInRange(_entManager.GetComponent<TransformComponent>(source).MapPosition, VoiceRange)
.Recipients
.Select(p => p.ConnectedClient)
.ToList();
@@ -231,7 +234,7 @@ namespace Content.Server.Chat.Managers
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Emotes;
msg.Message = action;
msg.MessageWrap = Loc.GetString("chat-manager-entity-me-wrap-message", ("entityName",Name: IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(source).EntityName));
msg.MessageWrap = Loc.GetString("chat-manager-entity-me-wrap-message", ("entityName",Name: _entManager.GetComponent<MetaDataComponent>(source).EntityName));
msg.SenderEntity = source;
_netManager.ServerSendToMany(msg, clients);
}
@@ -296,11 +299,14 @@ namespace Content.Server.Chat.Managers
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Dead;
msg.Message = message;
IEntity? tempQualifier = player.AttachedEntity;
var playerName = player.AttachedEntity is {Valid: true} playerEntity
? _entManager.GetComponent<MetaDataComponent>(playerEntity).EntityName
: "???";
msg.MessageWrap = Loc.GetString("chat-manager-send-dead-chat-wrap-message",
("deadChannelName", Loc.GetString("chat-manager-dead-channel-name")),
("playerName", (tempQualifier != null ? IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(tempQualifier).EntityName : null) ?? "???"));
msg.SenderEntity = player.AttachedEntityUid.GetValueOrDefault();
("playerName", (playerName)));
msg.SenderEntity = player.AttachedEntity.GetValueOrDefault();
_netManager.ServerSendToMany(msg, clients.ToList());
}

View File

@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
@@ -69,7 +68,7 @@ public class ChatSanitizationManager : IChatSanitizationManager
_configurationManager.OnValueChanged(CCVars.ChatSanitizerEnabled, x => doSanitize = x, true);
}
public bool TrySanitizeOutSmilies(string input, IEntity speaker, out string sanitized, [NotNullWhen(true)] out string? emote)
public bool TrySanitizeOutSmilies(string input, EntityUid speaker, out string sanitized, [NotNullWhen(true)] out string? emote)
{
if (!doSanitize)
{

View File

@@ -23,8 +23,8 @@ namespace Content.Server.Chat.Managers
void DispatchServerMessage(IPlayerSession player, string message);
/// <param name="hideChat">If true, message will not be logged to chat boxes but will still produce a speech bubble.</param>
void EntitySay(IEntity source, string message, bool hideChat=false);
void EntityMe(IEntity source, string action);
void EntitySay(EntityUid source, string message, bool hideChat=false);
void EntityMe(EntityUid source, string action);
void SendOOC(IPlayerSession player, string message);
void SendAdminChat(IPlayerSession player, string message);

View File

@@ -7,5 +7,5 @@ public interface IChatSanitizationManager
{
public void Initialize();
public bool TrySanitizeOutSmilies(string input, IEntity speaker, out string sanitized, [NotNullWhen(true)] out string? emote);
public bool TrySanitizeOutSmilies(string input, EntityUid speaker, out string sanitized, [NotNullWhen(true)] out string? emote);
}