mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Some stuff for auth * Holy crap auth works * Enable encryption even if no auth token is provided. It's still possible that the public key was retrieved over HTTPS via the status API, in which case it will be secure. * Fix integration test compile. * Secure CVar API. * Literally rewrite the auth protocol to be minecraft's. * Better exception tolerance in server handshake. * Auth works from launcher. * Fix some usages of UserID instead of UserName * Fix auth.server CVar * Kick existing connection if same account connects twice. * Username assignment, guest session distinguishing. * Necessary work to make bans work. * Expose LoginType to OnConnecting. * Fixing tests and warnings.
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using System;
|
|
using System.Net;
|
|
using Lidgren.Network;
|
|
using Robust.Shared.Interfaces.Network;
|
|
|
|
namespace Robust.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;
|
|
|
|
public string UserName { get; }
|
|
public LoginType AuthType { get; }
|
|
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|