Skip to content

Commit

Permalink
Rename socket to connectionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
TheVeryStarlk committed Aug 22, 2023
1 parent 283244d commit 1680aac
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Obsidian/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Obsidian.Net.Packets.Login;
using Obsidian.Net.Packets.Play;
using Obsidian.Net.Packets.Play.Clientbound;
using Obsidian.Net.Packets.Play.Serverbound;
using Obsidian.Net.Packets.Status;
using Obsidian.Registries;
using Obsidian.Utilities.Mojang;
Expand Down Expand Up @@ -112,9 +111,9 @@ public sealed class Client : IDisposable
private readonly PacketCryptography packetCryptography;

/// <summary>
/// The socket associated with the <see cref="networkStream"/>.
/// The connection context associated with the <see cref="networkStream"/>.
/// </summary>
private readonly ConnectionContext socket;
private readonly ConnectionContext connectionContext;

/// <summary>
/// The current server configuration.
Expand All @@ -139,7 +138,7 @@ public sealed class Client : IDisposable
/// <summary>
/// The client's ip and port used to establish this connection.
/// </summary>
public EndPoint? RemoteEndPoint => socket.RemoteEndPoint;
public EndPoint? RemoteEndPoint => connectionContext.RemoteEndPoint;

/// <summary>
/// Executed when the client disconnects.
Expand All @@ -166,25 +165,25 @@ public sealed class Client : IDisposable
/// </summary>
public string? Brand { get; set; }

public Client(ConnectionContext socket, ServerConfiguration config, int playerId, Server originServer)
public Client(ConnectionContext connectionContext, ServerConfiguration config, int playerId, Server originServer)
{
this.socket = socket;
this.connectionContext = connectionContext;
this.config = config;
id = playerId;
Server = originServer;

LoadedChunks = new();
packetCryptography = new();
handler = new(config);
networkStream = new(socket.Transport);
networkStream = new(connectionContext.Transport);
minecraftStream = new(networkStream);

missedKeepAlives = new List<long>();
var linkOptions = new DataflowLinkOptions { PropagateCompletion = true };
var blockOptions = new ExecutionDataflowBlockOptions { CancellationToken = cancellationSource.Token, EnsureOrdered = true };
var sendPacketBlock = new ActionBlock<IClientboundPacket>(packet =>
{
if (socket.IsConnected())
if (connectionContext.IsConnected())
SendPacket(packet);
}, blockOptions);

Expand Down Expand Up @@ -228,7 +227,7 @@ public Client(ConnectionContext socket, ServerConfiguration config, int playerId

public async Task StartConnectionAsync()
{
while (!cancellationSource.IsCancellationRequested && socket.IsConnected())
while (!cancellationSource.IsCancellationRequested && connectionContext.IsConnected())
{
(var id, var data) = await GetNextPacketAsync();

Expand Down Expand Up @@ -266,7 +265,7 @@ public async Task StartConnectionAsync()
{
if (this.Server.Config.CanThrottle)
{
string ip = ((IPEndPoint)socket.RemoteEndPoint!).Address.ToString();
string ip = ((IPEndPoint)connectionContext.RemoteEndPoint!).Address.ToString();

if (Server.throttler.TryGetValue(ip, out var timeLeft))
{
Expand Down Expand Up @@ -713,7 +712,7 @@ internal void SendPacket(IClientboundPacket packet)
catch (SocketException)
{
// Clients can disconnect at any point, causing exception to be raised
if (!socket.IsConnected())
if (!connectionContext.IsConnected())
{
Disconnect();
}
Expand Down Expand Up @@ -779,7 +778,7 @@ public void Dispose()
disposed = true;

minecraftStream.Dispose();
socket.Abort();
connectionContext.Abort();
cancellationSource?.Dispose();

GC.SuppressFinalize(this);
Expand Down

0 comments on commit 1680aac

Please sign in to comment.