using Unity.Collections; namespace Unity.Networking.Transport { namespace Error { /// /// DisconnectReason enumerates all disconnect reasons. /// public enum DisconnectReason : byte { /// Indicates a normal disconnection as a result of calling Disconnect on the connection. Default, // don't assign explicit values /// Indicates the connection timed out. Timeout, /// Indicates the connection failed to establish a connection after . MaxConnectionAttempts, /// Indicates the connection was closed remotely. ClosedByRemote, /// Used only for count. Keep last and don't assign explicit values Count } public enum StatusCode { Success = 0, NetworkIdMismatch = -1, NetworkVersionMismatch = -2, NetworkStateMismatch = -3, NetworkPacketOverflow = -4, NetworkSendQueueFull = -5, NetworkHeaderInvalid = -6, NetworkDriverParallelForErr = -7, NetworkSendHandleInvalid = -8, NetworkArgumentMismatch = -9, } } /// /// The NetworkConnection is a struct that hold all information needed by the driver to link it with a virtual /// connection. The NetworkConnection is a public representation of a connection. /// public struct NetworkConnection { internal int m_NetworkId; internal int m_NetworkVersion; /// /// ConnectionState enumerates available connection states a connection can have. /// public enum State { /// Indicates the connection is disconnected Disconnected, /// Indicates the connection is trying to connect. Connecting, /// Indicates the connection is waiting for a connection response. AwaitingResponse, /// Indicates the connection is connected.. Connected } /// /// Disconnects a virtual connection and marks it for deletion. This connection will be removed on next the next frame. /// /// The driver that owns the virtual connection. public int Disconnect(NetworkDriver driver) { return driver.Disconnect(this); } /// /// Receive an event for this specific connection. Should be called until it returns , even if the socket is disconnected. /// /// The driver that owns the virtual connection. /// A DataStreamReader, that will only be populated if a /// event was received. /// public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream) { return driver.PopEventForConnection(this, out stream); } public NetworkEvent.Type PopEvent(NetworkDriver driver, out DataStreamReader stream, out NetworkPipeline pipeline) { return driver.PopEventForConnection(this, out stream, out pipeline); } /// /// Close an active NetworkConnection, similar to . /// /// The driver that owns the virtual connection. public int Close(NetworkDriver driver) { if (m_NetworkId >= 0) return driver.Disconnect(this); return -1; } /// /// Check to see if a NetworkConnection is Created. /// /// `true` if the NetworkConnection has been correctly created by a call to /// or public bool IsCreated { get { return m_NetworkVersion != 0; } } public State GetState(NetworkDriver driver) { return driver.GetConnectionState(this); } public static bool operator ==(NetworkConnection lhs, NetworkConnection rhs) { return lhs.m_NetworkId == rhs.m_NetworkId && lhs.m_NetworkVersion == rhs.m_NetworkVersion; } public static bool operator !=(NetworkConnection lhs, NetworkConnection rhs) { return lhs.m_NetworkId != rhs.m_NetworkId || lhs.m_NetworkVersion != rhs.m_NetworkVersion; } public override bool Equals(object o) { return this == (NetworkConnection)o; } public bool Equals(NetworkConnection o) { return this == o; } public override int GetHashCode() { return (m_NetworkId << 8) ^ m_NetworkVersion; } public int InternalId => m_NetworkId; } }