Remove network component messages (#2659)

This commit is contained in:
mirrorcult
2022-03-30 16:24:27 -07:00
committed by GitHub
parent 4453a23069
commit 7e56f46f35
9 changed files with 2 additions and 258 deletions

View File

@@ -27,7 +27,6 @@ namespace Robust.Client.GameObjects
public override void Initialize()
{
SetupNetworking();
ReceivedComponentMessage += (_, compMsg) => DispatchComponentMessage(compMsg);
ReceivedSystemMessage += (_, systemMsg) => EventBus.RaiseEvent(EventSource.Network, systemMsg);
base.Initialize();
@@ -52,9 +51,6 @@ namespace Robust.Client.GameObjects
public override IEntityNetworkManager EntityNetManager => this;
/// <inheritdoc />
public event EventHandler<NetworkComponentMessage>? ReceivedComponentMessage;
/// <inheritdoc />
public event EventHandler<object>? ReceivedSystemMessage;
@@ -105,26 +101,6 @@ namespace Robust.Client.GameObjects
throw new NotSupportedException();
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendComponentNetworkMessage(INetChannel? channel, EntityUid entity, IComponent component, ComponentMessage message)
{
var componentType = component.GetType();
var netId = ComponentFactory.GetRegistration(componentType).NetID;
if (!netId.HasValue)
throw new ArgumentException($"Component {componentType} does not have a NetID.", nameof(component));
var msg = _networkManager.CreateNetMessage<MsgEntity>();
msg.Type = EntityMessageType.ComponentMessage;
msg.EntityUid = entity;
msg.NetId = netId.Value;
msg.ComponentMessage = message;
msg.SourceTick = _gameTiming.CurTick;
_networkManager.ClientSendMessage(msg);
}
private void HandleEntityNetworkMessage(MsgEntity message)
{
if (message.SourceTick <= _gameStateManager.CurServerTick)
@@ -143,10 +119,6 @@ namespace Robust.Client.GameObjects
{
switch (message.Type)
{
case EntityMessageType.ComponentMessage:
ReceivedComponentMessage?.Invoke(this, new NetworkComponentMessage(message));
return;
case EntityMessageType.SystemMessage:
var msg = message.SystemMessage;
var sessionType = typeof(EntitySessionMessage<>).MakeGenericType(msg.GetType());

View File

@@ -37,7 +37,6 @@ namespace Robust.Server.GameObjects
public override void Initialize()
{
SetupNetworking();
ReceivedComponentMessage += (_, compMsg) => DispatchComponentMessage(compMsg);
ReceivedSystemMessage += (_, systemMsg) => EventBus.RaiseEvent(EventSource.Network, systemMsg);
base.Initialize();
@@ -98,9 +97,6 @@ namespace Robust.Server.GameObjects
public override IEntityNetworkManager EntityNetManager => this;
/// <inheritdoc />
public event EventHandler<NetworkComponentMessage>? ReceivedComponentMessage;
/// <inheritdoc />
public event EventHandler<object>? ReceivedSystemMessage;
@@ -207,35 +203,6 @@ namespace Robust.Server.GameObjects
}
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public void SendComponentNetworkMessage(INetChannel? channel, EntityUid entity, IComponent component,
ComponentMessage message)
{
if (_networkManager.IsClient)
return;
var netId = ComponentFactory.GetRegistration(component.GetType()).NetID;
if (!netId.HasValue)
throw new ArgumentException($"Component {component.GetType()} does not have a NetID.", nameof(component));
var msg = _networkManager.CreateNetMessage<MsgEntity>();
msg.Type = EntityMessageType.ComponentMessage;
msg.EntityUid = entity;
msg.NetId = netId.Value;
msg.ComponentMessage = message;
msg.SourceTick = _gameTiming.CurTick;
// Logger.DebugS("net.ent", "Sending: {0}", msg);
//Send the message
if (channel == null)
_networkManager.ServerSendToAll(msg);
else
_networkManager.ServerSendMessage(msg, channel);
}
/// <inheritdoc />
public void SendSystemNetworkMessage(EntityEventArgs message)
{
@@ -302,10 +269,6 @@ namespace Robust.Server.GameObjects
{
switch (message.Type)
{
case EntityMessageType.ComponentMessage:
ReceivedComponentMessage?.Invoke(this, new NetworkComponentMessage(message, player));
return;
case EntityMessageType.SystemMessage:
var msg = message.SystemMessage;
var sessionType = typeof(EntitySessionMessage<>).MakeGenericType(msg.GetType());

View File

@@ -219,22 +219,6 @@ namespace Robust.Shared.GameObjects
entManager.Dirty(this);
}
/// <summary>
/// Sends a message over the network to all other components on the networked entity. This works both ways.
/// This is an alias of 'Owner.SendNetworkMessage(this, message);'
/// </summary>
/// <param name="message">Message to send.</param>
/// <param name="channel">Network channel to send the message over. If null, broadcast to all channels.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
protected void SendNetworkMessage(ComponentMessage message, INetChannel? channel = null)
{
IoCManager.Resolve<IEntityManager>().EntityNetManager?.SendComponentNetworkMessage(channel, Owner, this, message);
}
/// <inheritdoc />
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public virtual void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null) { }
private static readonly ComponentState DefaultComponentState = new();
/// <inheritdoc />

View File

@@ -1,24 +0,0 @@
using System;
using Robust.Shared.Serialization;
namespace Robust.Shared.GameObjects
{
/// <summary>
/// A message containing info to send through the component message system.
/// </summary>
[Serializable, NetSerializable]
[Obsolete("Component messages are deprecated. Use directed local events instead.")]
public abstract class ComponentMessage
{
/// <summary>
/// Was this message raised from a remote location over the network?
/// </summary>
public bool Remote { get; internal set; }
/// <summary>
/// If this is a remote message, will it only be sent to the corresponding component?
/// If this is not a remote message, this flag does nothing.
/// </summary>
public bool Directed { get; protected set; }
}
}

View File

@@ -478,31 +478,7 @@ namespace Robust.Shared.GameObjects
#endregion Entity Management
protected void DispatchComponentMessage(NetworkComponentMessage netMsg)
{
var compMsg = netMsg.Message;
var compChannel = netMsg.Channel;
var session = netMsg.Session;
compMsg.Remote = true;
#pragma warning disable 618
var uid = netMsg.EntityUid;
if (compMsg.Directed)
{
if (TryGetComponent(uid, (ushort) netMsg.NetId, out var component))
component.HandleNetworkMessage(compMsg, compChannel, session);
}
else
{
foreach (var component in GetComponents(uid))
{
component.HandleNetworkMessage(compMsg, compChannel, session);
}
}
#pragma warning restore 618
}
/// <summary>
/// <summary>
/// Factory for generating a new EntityUid for an entity currently being created.
/// </summary>
/// <inheritdoc />
@@ -515,7 +491,6 @@ namespace Robust.Shared.GameObjects
public enum EntityMessageType : byte
{
Error = 0,
ComponentMessage,
SystemMessage
}
}

View File

@@ -69,15 +69,6 @@ namespace Robust.Shared.GameObjects
/// </summary>
GameTick LastModifiedTick { get; }
/// <summary>
/// Handles an incoming component message from the server.
/// </summary>
/// <param name="message">Incoming event message.</param>
/// <param name="netChannel">The channel of the remote client that sent the message.</param>
/// <param name="session">The session data for the player who sent this message. Null if this is a client.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null);
/// <summary>
/// Get the component's state for replicating on the client.
/// </summary>

View File

@@ -9,12 +9,7 @@ namespace Robust.Shared.GameObjects
public interface IEntityNetworkManager
{
/// <summary>
/// This event is raised when a component message comes in from the network.
/// </summary>
event EventHandler<NetworkComponentMessage> ReceivedComponentMessage;
/// <summary>
/// This event is raised when a component message comes in from the network.
/// This event is raised when a system message comes in from the network.
/// </summary>
event EventHandler<object> ReceivedSystemMessage;
@@ -23,21 +18,6 @@ namespace Robust.Shared.GameObjects
/// </summary>
void SetupNetworking();
/// <summary>
/// Allows a component owned by this entity to send a message to a counterpart component on the
/// counterpart entities on clients.
/// </summary>
/// <param name="channel">
/// Intended recipient of the message. On Server, if this is null, broadcast the message to all clients.
/// On clients, this should always be null.
/// </param>
/// <param name="entity">Entity sending the message (also entity to send to).</param>
/// <param name="component">Component that sent the message.</param>
/// <param name="message">Message to send.</param>
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
void SendComponentNetworkMessage(INetChannel? channel, EntityUid entity, IComponent component,
ComponentMessage message);
/// <summary>
/// Sends an Entity System Message to relevant System(s).
/// Client: Sends the message to the relevant server side System(s).

View File

@@ -1,59 +0,0 @@
using Robust.Shared.Network;
using Robust.Shared.Network.Messages;
using Robust.Shared.Players;
using Robust.Shared.Utility;
namespace Robust.Shared.GameObjects
{
#nullable enable
/// <summary>
/// A container that holds a component message and network info.
/// </summary>
public readonly struct NetworkComponentMessage
{
/// <summary>
/// Network channel this message came from.
/// </summary>
public readonly INetChannel Channel;
/// <summary>
/// Entity Uid this message is associated with.
/// </summary>
public readonly EntityUid EntityUid;
/// <summary>
/// If the Message is Directed, Component net Uid this message is being sent to.
/// </summary>
public readonly uint NetId;
/// <summary>
/// The message payload.
/// </summary>
#pragma warning disable 618
public readonly ComponentMessage Message;
#pragma warning restore 618
/// <summary>
/// If the message is from the client, the client's session.
/// </summary>
public readonly ICommonSession? Session;
/// <summary>
/// Constructs a new instance of <see cref="NetworkComponentMessage"/>.
/// </summary>
/// <param name="netMsg">Raw network message containing the component message.</param>
public NetworkComponentMessage(MsgEntity netMsg, ICommonSession? session = null)
{
DebugTools.Assert(netMsg.Type == EntityMessageType.ComponentMessage);
Channel = netMsg.MsgChannel;
EntityUid = netMsg.EntityUid;
NetId = netMsg.NetId;
Message = netMsg.ComponentMessage;
Session = session;
}
}
#nullable restore
}

View File

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using Lidgren.Network;
using Robust.Shared.Enums;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
@@ -19,10 +17,6 @@ namespace Robust.Shared.Network.Messages
public EntityMessageType Type { get; set; }
public EntityEventArgs SystemMessage { get; set; }
#pragma warning disable 618
public ComponentMessage ComponentMessage { get; set; }
#pragma warning restore 618
public EntityUid EntityUid { get; set; }
public uint NetId { get; set; }
public uint Sequence { get; set; }
@@ -44,20 +38,6 @@ namespace Robust.Shared.Network.Messages
SystemMessage = serializer.Deserialize<EntityEventArgs>(stream);
}
break;
case EntityMessageType.ComponentMessage:
{
EntityUid = new EntityUid(buffer.ReadInt32());
NetId = buffer.ReadUInt32();
var serializer = IoCManager.Resolve<IRobustSerializer>();
int length = buffer.ReadVariableInt32();
using var stream = buffer.ReadAlignedMemory(length);
#pragma warning disable 618
ComponentMessage = serializer.Deserialize<ComponentMessage>(stream);
#pragma warning restore 618
}
break;
}
}
@@ -81,22 +61,6 @@ namespace Robust.Shared.Network.Messages
}
}
break;
case EntityMessageType.ComponentMessage:
{
buffer.Write((int)EntityUid);
buffer.Write(NetId);
var serializer = IoCManager.Resolve<IRobustSerializer>();
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, ComponentMessage);
buffer.WriteVariableInt32((int)stream.Length);
stream.TryGetBuffer(out var segment);
buffer.Write(segment);
}
}
break;
}
}
@@ -107,8 +71,6 @@ namespace Robust.Shared.Network.Messages
{
case EntityMessageType.Error:
return "MsgEntity Error";
case EntityMessageType.ComponentMessage:
return $"MsgEntity Comp, {timingData}, {EntityUid}/{NetId}: {ComponentMessage}";
case EntityMessageType.SystemMessage:
return $"MsgEntity Comp, {timingData}, {SystemMessage}";
default: