Added Whisper system for talking with players 2 tiles away. (#5994)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -18,14 +18,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.");
|
||||
shell.WriteError("This command cannot be run from the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
|
||||
if (player.Status != SessionStatus.InGame)
|
||||
return;
|
||||
|
||||
if (args.Length < 1)
|
||||
@@ -35,22 +34,7 @@ namespace Content.Server.Chat.Commands
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
var mindComponent = player.ContentData()?.Mind;
|
||||
|
||||
if (mindComponent == null)
|
||||
{
|
||||
shell.WriteError("You don't have a mind!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mindComponent.OwnedEntity == null)
|
||||
{
|
||||
shell.WriteError("You don't have an entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
chat.EntityLOOC(mindComponent.OwnedEntity.Value, message);
|
||||
IoCManager.Resolve<IChatManager>().SendLOOC(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,9 @@ namespace Content.Server.Chat.Commands
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var player = (IPlayerSession?) shell.Player;
|
||||
|
||||
if (player == null)
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteError("You can't run this command locally.");
|
||||
shell.WriteError("This command cannot be run from the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,8 +29,7 @@ namespace Content.Server.Chat.Commands
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
chat.SendOOC(player, message);
|
||||
IoCManager.Resolve<IChatManager>().SendOOC(player, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Chat.Commands
|
||||
@@ -22,7 +18,7 @@ namespace Content.Server.Chat.Commands
|
||||
{
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteLine("This command cannot be run from the server.");
|
||||
shell.WriteError("This command cannot be run from the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,7 +27,7 @@ namespace Content.Server.Chat.Commands
|
||||
|
||||
if (player.AttachedEntity is not {} playerEntity)
|
||||
{
|
||||
shell.WriteLine("You don't have an entity!");
|
||||
shell.WriteError("You don't have an entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -42,34 +38,7 @@ namespace Content.Server.Chat.Commands
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var chat = IoCManager.Resolve<IChatManager>();
|
||||
var chatSanitizer = IoCManager.Resolve<IChatSanitizationManager>();
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().HasComponent<GhostComponent>(playerEntity))
|
||||
chat.SendDeadChat(player, message);
|
||||
else
|
||||
{
|
||||
var mindComponent = player.ContentData()?.Mind;
|
||||
|
||||
if (mindComponent == null)
|
||||
{
|
||||
shell.WriteError("You don't have a mind!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mindComponent.OwnedEntity is not {Valid: true} owned)
|
||||
{
|
||||
shell.WriteError("You don't have an entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
var emote = chatSanitizer.TrySanitizeOutSmilies(message, owned, out var sanitized, out var emoteStr);
|
||||
if (sanitized.Length != 0)
|
||||
chat.EntitySay(owned, sanitized);
|
||||
if (emote)
|
||||
chat.EntityMe(owned, emoteStr!);
|
||||
}
|
||||
|
||||
IoCManager.Resolve<IChatManager>().TrySpeak(playerEntity, message, false, shell, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
Content.Server/Chat/Commands/WhisperCommand.cs
Normal file
44
Content.Server/Chat/Commands/WhisperCommand.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Chat.Commands
|
||||
{
|
||||
[AnyCommand]
|
||||
internal class WhisperCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "whisper";
|
||||
public string Description => "Send chat messages to the local channel as a whisper";
|
||||
public string Help => "whisper <text>";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteError("This command cannot be run from the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.Status != SessionStatus.InGame)
|
||||
return;
|
||||
|
||||
if (player.AttachedEntity is not {} playerEntity)
|
||||
{
|
||||
shell.WriteError("You don't have an entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Length < 1)
|
||||
return;
|
||||
|
||||
var message = string.Join(" ", args).Trim();
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
IoCManager.Resolve<IChatManager>().TrySpeak(playerEntity, message, true, shell, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user