forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lidgren NetTime.Now is now synchronized to IGameTiming.RealTime. NetChannel is now a nested class of NetManager. Add IGameTiming.ServerTime, INetChannel.RemoteTimeOffset, INetChannel.RemoteTime
- Loading branch information
Showing
9 changed files
with
160 additions
and
89 deletions.
There are no files selected for viewing
Submodule Lidgren.Network
updated
from 4a5ced to 73554e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Net; | ||
using Lidgren.Network; | ||
using Robust.Shared.Interfaces.Network; | ||
|
||
namespace Robust.Shared.Network | ||
{ | ||
public partial class NetManager | ||
{ | ||
private class NetChannel : INetChannel | ||
{ | ||
private readonly NetManager _manager; | ||
private readonly NetConnection _connection; | ||
|
||
/// <inheritdoc /> | ||
public long ConnectionId => _connection.RemoteUniqueIdentifier; | ||
|
||
/// <inheritdoc /> | ||
public INetManager NetPeer => _manager; | ||
|
||
public string UserName { get; } | ||
public LoginType AuthType { get; } | ||
public TimeSpan RemoteTimeOffset => TimeSpan.FromSeconds(_connection.RemoteTimeOffset); | ||
public TimeSpan RemoteTime => _manager._timing.RealTime + RemoteTimeOffset; | ||
|
||
/// <inheritdoc /> | ||
public short Ping => (short) Math.Round(_connection.AverageRoundtripTime * 1000); | ||
|
||
/// <inheritdoc /> | ||
public bool IsConnected => _connection.Status == NetConnectionStatus.Connected; | ||
|
||
/// <inheritdoc /> | ||
public IPEndPoint RemoteEndPoint => _connection.RemoteEndPoint; | ||
|
||
/// <summary> | ||
/// Exposes the lidgren connection. | ||
/// </summary> | ||
public NetConnection Connection => _connection; | ||
|
||
public NetUserId UserId { get; } | ||
|
||
// Only used on server, contains the encryption to use for this channel. | ||
public NetEncryption? Encryption { get; set; } | ||
|
||
/// <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, NetUserId userId, string userName, | ||
LoginType loginType) | ||
{ | ||
_manager = manager; | ||
_connection = connection; | ||
UserId = userId; | ||
UserName = userName; | ||
AuthType = loginType; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public T CreateNetMessage<T>() | ||
where T : NetMessage | ||
{ | ||
return _manager.CreateNetMessage<T>(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void SendMessage(NetMessage message) | ||
{ | ||
if (_manager.IsClient) | ||
{ | ||
_manager.ClientSendMessage(message); | ||
return; | ||
} | ||
|
||
_manager.ServerSendMessage(message, this); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void Disconnect(string reason) | ||
{ | ||
if (_connection.Status == NetConnectionStatus.Connected) | ||
_connection.Disconnect(reason); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters