yuanshen/Yuanshen.Kcp/KcpConversationReceiveResult.cs
wisedev fc2ac1050f First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:10:50 +03:00

61 lines
2.5 KiB
C#

using System.Globalization;
namespace Yuanshen.Kcp
{
/// <summary>
/// The result of a receive or peek operation.
/// </summary>
public readonly struct KcpConversationReceiveResult : IEquatable<KcpConversationReceiveResult>
{
private readonly int _bytesReceived;
private readonly bool _connectionAlive;
/// <summary>
/// The number of bytes received.
/// </summary>
public int BytesReceived => _bytesReceived;
/// <summary>
/// Whether the underlying transport is marked as closed.
/// </summary>
public bool TransportClosed => !_connectionAlive;
/// <summary>
/// Construct a <see cref="KcpConversationReceiveResult"/> with the specified number of bytes received.
/// </summary>
/// <param name="bytesReceived">The number of bytes received.</param>
public KcpConversationReceiveResult(int bytesReceived)
{
_bytesReceived = bytesReceived;
_connectionAlive = true;
}
/// <summary>
/// Checks whether the two instance is equal.
/// </summary>
/// <param name="left">The one instance.</param>
/// <param name="right">The other instance.</param>
/// <returns>Whether the two instance is equal</returns>
public static bool operator ==(KcpConversationReceiveResult left, KcpConversationReceiveResult right) => left.Equals(right);
/// <summary>
/// Checks whether the two instance is not equal.
/// </summary>
/// <param name="left">The one instance.</param>
/// <param name="right">The other instance.</param>
/// <returns>Whether the two instance is not equal</returns>
public static bool operator !=(KcpConversationReceiveResult left, KcpConversationReceiveResult right) => !left.Equals(right);
/// <inheritdoc />
public bool Equals(KcpConversationReceiveResult other) => BytesReceived == other.BytesReceived && TransportClosed == other.TransportClosed;
/// <inheritdoc />
public override bool Equals(object obj) => obj is KcpConversationReceiveResult other && Equals(other);
/// <inheritdoc />
public override int GetHashCode() => HashCode.Combine(BytesReceived, TransportClosed);
/// <inheritdoc />
public override string ToString() => _connectionAlive ? _bytesReceived.ToString(CultureInfo.InvariantCulture) : "Transport is closed.";
}
}