Fix erase verb not removing chat messages in some cases (#21355)
* Fix erase verb not removing chat messages in some cases * Admin changelog * Fix deleting messages with entity id 0
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Content.Server.Administration.Logs;
|
||||
@@ -49,8 +50,7 @@ namespace Content.Server.Chat.Managers
|
||||
private bool _oocEnabled = true;
|
||||
private bool _adminOocEnabled = true;
|
||||
|
||||
public Dictionary<ICommonSession, int> SenderKeys { get; } = new();
|
||||
public Dictionary<ICommonSession, HashSet<NetEntity>> SenderEntities { get; } = new();
|
||||
private readonly Dictionary<NetUserId, ChatUser> _players = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -79,13 +79,26 @@ namespace Content.Server.Chat.Managers
|
||||
|
||||
public void DeleteMessagesBy(ICommonSession player)
|
||||
{
|
||||
var key = SenderKeys.GetValueOrDefault(player);
|
||||
var entities = SenderEntities.GetValueOrDefault(player) ?? new HashSet<NetEntity>();
|
||||
var msg = new MsgDeleteChatMessagesBy { Key = key, Entities = entities };
|
||||
if (!_players.TryGetValue(player.UserId, out var user))
|
||||
return;
|
||||
|
||||
var msg = new MsgDeleteChatMessagesBy { Key = user.Key, Entities = user.Entities };
|
||||
_netManager.ServerSendToAll(msg);
|
||||
}
|
||||
|
||||
[return: NotNullIfNotNull(nameof(author))]
|
||||
public ChatUser? EnsurePlayer(NetUserId? author)
|
||||
{
|
||||
if (author == null)
|
||||
return null;
|
||||
|
||||
ref var user = ref CollectionsMarshal.GetValueRefOrAddDefault(_players, author.Value, out var exists);
|
||||
if (!exists || user == null)
|
||||
user = new ChatUser(_players.Count);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
#region Server Announcements
|
||||
|
||||
public void DispatchServerAnnouncement(string message, Color? colorOverride = null)
|
||||
@@ -214,12 +227,8 @@ namespace Content.Server.Chat.Managers
|
||||
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
||||
}
|
||||
|
||||
ref var key = ref CollectionsMarshal.GetValueRefOrAddDefault(SenderKeys, player, out var exists);
|
||||
if (!exists)
|
||||
key = SenderKeys.Count;
|
||||
|
||||
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
|
||||
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, senderKey: key);
|
||||
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, author: player.UserId);
|
||||
_mommiLink.SendOOCMessage(player.Name, message);
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"OOC from {player:Player}: {message}");
|
||||
}
|
||||
@@ -237,10 +246,6 @@ namespace Content.Server.Chat.Managers
|
||||
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
|
||||
("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
||||
|
||||
ref var key = ref CollectionsMarshal.GetValueRefOrAddDefault(SenderKeys, player, out var exists);
|
||||
if (!exists)
|
||||
key = SenderKeys.Count;
|
||||
|
||||
foreach (var client in clients)
|
||||
{
|
||||
var isSource = client != player.ConnectedClient;
|
||||
@@ -251,7 +256,8 @@ namespace Content.Server.Chat.Managers
|
||||
false,
|
||||
client,
|
||||
audioPath: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath) : default,
|
||||
audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default, senderKey: key);
|
||||
audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default,
|
||||
author: player.UserId);
|
||||
}
|
||||
|
||||
_adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}");
|
||||
@@ -261,9 +267,13 @@ namespace Content.Server.Chat.Managers
|
||||
|
||||
#region Utility
|
||||
|
||||
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, int? senderKey = null)
|
||||
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
||||
{
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, _entityManager.GetNetEntity(source), senderKey, hideChat, colorOverride, audioPath, audioVolume);
|
||||
var user = author == null ? null : EnsurePlayer(author);
|
||||
var netSource = _entityManager.GetNetEntity(source);
|
||||
user?.AddEntity(netSource);
|
||||
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
||||
_netManager.ServerSendMessage(new MsgChatMessage() { Message = msg }, client);
|
||||
|
||||
if (!recordReplay)
|
||||
@@ -276,12 +286,16 @@ namespace Content.Server.Chat.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
|
||||
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume);
|
||||
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
||||
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume, author);
|
||||
|
||||
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
|
||||
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
||||
{
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, _entityManager.GetNetEntity(source), null, hideChat, colorOverride, audioPath, audioVolume);
|
||||
var user = author == null ? null : EnsurePlayer(author);
|
||||
var netSource = _entityManager.GetNetEntity(source);
|
||||
user?.AddEntity(netSource);
|
||||
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
||||
_netManager.ServerSendToMany(new MsgChatMessage() { Message = msg }, clients);
|
||||
|
||||
if (!recordReplay)
|
||||
@@ -309,9 +323,13 @@ namespace Content.Server.Chat.Managers
|
||||
ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride, audioPath, audioVolume);
|
||||
}
|
||||
|
||||
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, int? senderKey = null)
|
||||
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
||||
{
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, _entityManager.GetNetEntity(source), senderKey, hideChat, colorOverride, audioPath, audioVolume);
|
||||
var user = author == null ? null : EnsurePlayer(author);
|
||||
var netSource = _entityManager.GetNetEntity(source);
|
||||
user?.AddEntity(netSource);
|
||||
|
||||
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
||||
_netManager.ServerSendToAll(new MsgChatMessage() { Message = msg });
|
||||
|
||||
if (!recordReplay)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Chat;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
@@ -6,17 +7,6 @@ namespace Content.Server.Chat.Managers
|
||||
{
|
||||
public interface IChatManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Keys identifying messages sent by a specific player, used when sending
|
||||
/// <see cref="MsgChatMessage"/>
|
||||
/// </summary>
|
||||
Dictionary<ICommonSession, int> SenderKeys { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tracks which entities a player was attached to while sending messages.
|
||||
/// </summary>
|
||||
Dictionary<ICommonSession, HashSet<NetEntity>> SenderEntities { get; }
|
||||
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
@@ -36,17 +26,20 @@ namespace Content.Server.Chat.Managers
|
||||
void SendAdminAlert(EntityUid player, string message);
|
||||
|
||||
void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat,
|
||||
INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, int? senderKey = null);
|
||||
INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, NetUserId? author = null);
|
||||
|
||||
void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay,
|
||||
IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0);
|
||||
IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null);
|
||||
|
||||
void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride, string? audioPath = null, float audioVolume = 0);
|
||||
|
||||
void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, int? senderKey = null);
|
||||
void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null);
|
||||
|
||||
bool MessageCharacterLimit(ICommonSession player, string message);
|
||||
|
||||
void DeleteMessagesBy(ICommonSession player);
|
||||
|
||||
[return: NotNullIfNotNull(nameof(author))]
|
||||
ChatUser? EnsurePlayer(NetUserId? author);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user