Re-organize all projects (#4166)
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using Content.Shared.Notification;
|
||||
|
||||
namespace Content.Server.Notification.Managers
|
||||
{
|
||||
public interface IServerNotifyManager : ISharedNotifyManager
|
||||
{
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
69
Content.Server/Notification/Managers/ServerNotifyManager.cs
Normal file
69
Content.Server/Notification/Managers/ServerNotifyManager.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Content.Shared;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Notification.Managers
|
||||
{
|
||||
public class ServerNotifyManager : SharedNotifyManager, IServerNotifyManager
|
||||
{
|
||||
[Dependency] private readonly IServerNetManager _netManager = default!;
|
||||
|
||||
private bool _initialized;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
DebugTools.Assert(!_initialized);
|
||||
|
||||
_netManager.RegisterNetMessage<MsgDoNotifyCursor>(nameof(MsgDoNotifyCursor));
|
||||
_netManager.RegisterNetMessage<MsgDoNotifyCoordinates>(nameof(MsgDoNotifyCoordinates));
|
||||
_netManager.RegisterNetMessage<MsgDoNotifyEntity>(nameof(MsgDoNotifyEntity));
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
public override void PopupMessage(IEntity source, IEntity viewer, string message)
|
||||
{
|
||||
if (!viewer.TryGetComponent(out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var netMessage = _netManager.CreateNetMessage<MsgDoNotifyEntity>();
|
||||
netMessage.Entity = source.Uid;
|
||||
netMessage.Message = message;
|
||||
|
||||
_netManager.ServerSendMessage(netMessage, actor.PlayerSession.ConnectedClient);
|
||||
}
|
||||
|
||||
public override void PopupMessage(EntityCoordinates coordinates, IEntity viewer, string message)
|
||||
{
|
||||
if (!viewer.TryGetComponent(out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var netMessage = _netManager.CreateNetMessage<MsgDoNotifyCoordinates>();
|
||||
netMessage.Coordinates = coordinates;
|
||||
netMessage.Message = message;
|
||||
|
||||
_netManager.ServerSendMessage(netMessage, actor.PlayerSession.ConnectedClient);
|
||||
}
|
||||
|
||||
public override void PopupMessageCursor(IEntity viewer, string message)
|
||||
{
|
||||
if (!viewer.TryGetComponent(out ActorComponent? actor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var netMessage = _netManager.CreateNetMessage<MsgDoNotifyCursor>();
|
||||
netMessage.Message = message;
|
||||
|
||||
_netManager.ServerSendMessage(netMessage, actor.PlayerSession.ConnectedClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Content.Server/Notification/NotifyExtensions.cs
Normal file
61
Content.Server/Notification/NotifyExtensions.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Notification
|
||||
{
|
||||
public static class NotifyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Pops up a message for every player around <see cref="source"/> to see,
|
||||
/// except for <see cref="source"/> itself.
|
||||
/// </summary>
|
||||
/// <param name="source">The entity on which to popup the message.</param>
|
||||
/// <param name="message">The message to show.</param>
|
||||
/// <param name="playerManager">
|
||||
/// The instance of player manager to use, will be resolved automatically
|
||||
/// if null.
|
||||
/// </param>
|
||||
/// <param name="range">
|
||||
/// The range in which to search for players, defaulting to one screen.
|
||||
/// </param>
|
||||
public static void PopupMessageOtherClients(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
|
||||
{
|
||||
playerManager ??= IoCManager.Resolve<IPlayerManager>();
|
||||
|
||||
var viewers = playerManager.GetPlayersInRange(source.Transform.Coordinates, range);
|
||||
|
||||
foreach (var viewer in viewers)
|
||||
{
|
||||
var viewerEntity = viewer.AttachedEntity;
|
||||
|
||||
if (viewerEntity == null || source == viewerEntity || viewer.AttachedEntity == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
source.PopupMessage(viewer.AttachedEntity, message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pops up a message at the given entity's location for everyone,
|
||||
/// including itself, to see.
|
||||
/// </summary>
|
||||
/// <param name="source">The entity above which to show the message.</param>
|
||||
/// <param name="message">The message to be seen.</param>
|
||||
/// <param name="playerManager">
|
||||
/// The instance of player manager to use, will be resolved automatically
|
||||
/// if null.
|
||||
/// </param>
|
||||
/// <param name="range">
|
||||
/// The range in which to search for players, defaulting to one screen.
|
||||
/// </param>
|
||||
public static void PopupMessageEveryone(this IEntity source, string message, IPlayerManager? playerManager = null, int range = 15)
|
||||
{
|
||||
source.PopupMessage(message);
|
||||
source.PopupMessageOtherClients(message, playerManager, range);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
Content.Server/Notification/PopupMsgCommand.cs
Normal file
28
Content.Server/Notification/PopupMsgCommand.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Notification
|
||||
{
|
||||
[AdminCommand(AdminFlags.Debug)]
|
||||
public class PopupMsgCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "srvpopupmsg";
|
||||
public string Description => "";
|
||||
public string Help => "";
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
var entityMgr = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var source = EntityUid.Parse(args[0]);
|
||||
var viewer = EntityUid.Parse(args[1]);
|
||||
var msg = args[2];
|
||||
|
||||
entityMgr.GetEntity(source).PopupMessage(entityMgr.GetEntity(viewer), msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user