Files
RobustToolbox/Robust.Client/GameObjects/ClientEntityNetworkManager.cs
T
Pieter-Jan BriersandGitHub bb4a1eda8e Project file refactor (#819)
* Project file refactor

Move all the .csproj files to the new .NET Core style.
This doesn't make any difference for compiling for Framework,
but it does reduce a ton of useless boilerplate.

As an extension of this, killed a bunch of uncompiled & unmaintained .cs files.

Compiling for release (to profile) works now.
Removed AnyCPU targets from the solution file.

* Fix compiler warnings.
2019-05-28 00:16:01 +02:00

87 lines
3.1 KiB
C#

using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Network.Messages;
namespace Robust.Client.GameObjects
{
public class ClientEntityNetworkManager : IEntityNetworkManager
{
#pragma warning disable 649
[Dependency] private readonly IClientNetManager _network;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
/// <summary>
/// Sends a message to the relevant system(s) server side.
/// </summary>
public void SendSystemNetworkMessage(EntitySystemMessage message)
{
var msg = _network.CreateNetMessage<MsgEntity>();
msg.Type = EntityMessageType.SystemMessage;
msg.SystemMessage = message;
_network.ClientSendMessage(msg);
}
public void SendSystemNetworkMessage(EntitySystemMessage message, INetChannel channel)
{
throw new NotSupportedException();
}
/// <inheritdoc />
public void SendDirectedComponentNetworkMessage(INetChannel channel, IEntity entity, IComponent component, ComponentMessage message)
{
SendComponentNetworkMessage(entity, component, message);
}
/// <inheritdoc />
public void SendComponentNetworkMessage(IEntity entity, IComponent component, ComponentMessage message)
{
if (!component.NetID.HasValue)
throw new ArgumentException($"Component {component.Name} does not have a NetID.", nameof(component));
var msg = _network.CreateNetMessage<MsgEntity>();
msg.Type = EntityMessageType.ComponentMessage;
msg.EntityUid = entity.Uid;
msg.NetId = component.NetID.Value;
msg.ComponentMessage = message;
_network.ClientSendMessage(msg);
}
/// <inheritdoc />
public void SendEntityNetworkMessage(IEntity entity, EntityEventArgs message)
{
var msg = _network.CreateNetMessage<MsgEntity>();
msg.Type = EntityMessageType.EntityMessage;
msg.EntityUid = entity.Uid;
msg.EntityMessage = message;
_network.ClientSendMessage(msg);
}
/// <summary>
/// Converts a raw NetIncomingMessage to an IncomingEntityMessage object
/// </summary>
/// <param name="message">raw network message</param>
/// <returns>An IncomingEntityMessage object</returns>
public IncomingEntityMessage HandleEntityNetworkMessage(MsgEntity message)
{
switch (message.Type)
{
case EntityMessageType.ComponentMessage:
return new IncomingEntityMessage(message);
case EntityMessageType.EntityMessage:
// TODO: Handle this.
break;
case EntityMessageType.SystemMessage:
_entitySystemManager.HandleSystemMessage(message);
break;
}
return null;
}
}
}