Files
RobustToolbox/SS14.Shared/Network/NetChannel.cs
Acruid 3a5ea35c0b Raycasting + Turret AI (#532)
* Ray -> Box intersection works.

* Turret AI finished.

* Turret Works :D

* Light masks can now be rotated.

* Shoddy angle MoveTowards works.

* Shoddy Vector2 MoveTowards works.

* And pretty broken Quaternion version..

* Slept on it, rotation works good enough now.

* Fixed nuget dependencies.

* Moved AimShootLifeProcessor.cs to content.
2018-03-09 21:48:34 +01:00

64 lines
1.9 KiB
C#

using System;
using Lidgren.Network;
using SS14.Shared.Interfaces.Network;
namespace SS14.Shared.Network
{
/// <summary>
/// A network connection from this local peer to a remote peer.
/// </summary>
internal class NetChannel : INetChannel
{
private readonly NetManager _manager;
private readonly NetConnection _connection;
/// <inheritdoc />
public long ConnectionId => _connection.RemoteUniqueIdentifier;
/// <inheritdoc />
public INetManager NetPeer => _manager;
/// <inheritdoc />
public short Ping => (short) Math.Round(_connection.AverageRoundtripTime * 1000);
/// <inheritdoc />
public string RemoteAddress => _connection.RemoteEndPoint.Address.ToString();
/// <summary>
/// Exposes the lidgren connection.
/// </summary>
public NetConnection Connection => _connection;
/// <summary>
/// Creates a new instance of a NetChannel.
/// </summary>
/// <param name="manager">The server this channel belongs to.</param>
/// <param name="connection">The raw NetConnection to the remote peer.</param>
internal NetChannel(NetManager manager, NetConnection connection)
{
_manager = manager;
_connection = connection;
}
/// <inheritdoc />
public T CreateNetMessage<T>()
where T : NetMessage
{
return _manager.CreateNetMessage<T>();
}
/// <inheritdoc />
public void SendMessage(NetMessage message)
{
_manager.ServerSendMessage(message, this);
}
/// <inheritdoc />
public void Disconnect(string reason)
{
if (_connection.Status == NetConnectionStatus.Connected)
_connection.Disconnect(reason);
}
}
}