/// <summary> /// Updates a peer that has been closed. /// </summary> private void UpdateClosed(NetPeer peer) { // The peer must have been closed by the main thread, because if // we closed it on this thread it would have been removed immediately NetDebug.Assert(peer.ClosedByUser); peers.Remove(peer.EndPoint); }
/// <summary> /// Closes the peer's network connection for a given reason byte. /// </summary> public void Close( byte userReason = NetConfig.DEFAULT_USER_REASON) { NetDebug.Assert(core != null); if (IsOpen) { ClosedByUser = true; Disconnected(); if (userReason != NetConfig.DONT_NOTIFY_PEER) { core.SendKick(this, userReason); } } }
private void HandleConnectAccept( NetPeer peer, byte[] buffer, int length) { NetDebug.Assert(peer.IsClient == false, "Ignoring accept from client"); if (peer.IsConnected || peer.IsClient) { return; } peer.OnReceiveOther(Time); peer.Connected(); eventOut.Enqueue( CreateEvent(NetEventType.PeerConnected, peer)); }
/// <summary> /// Packs a connect request with version and token strings. /// </summary> internal static int PackConnectRequest(byte[] buffer, string version, string token) { int versionBytes = Encoding.UTF8.GetByteCount(version); int tokenBytes = Encoding.UTF8.GetByteCount(token); NetDebug.Assert((byte)versionBytes == versionBytes); NetDebug.Assert((byte)tokenBytes == tokenBytes); // Pack header info buffer[0] = (byte)NetPacketType.Connect; buffer[1] = (byte)versionBytes; buffer[2] = (byte)tokenBytes; int position = CONNECT_HEADER_SIZE; Encoding.UTF8.GetBytes(version, 0, version.Length, buffer, position); position += versionBytes; Encoding.UTF8.GetBytes(token, 0, token.Length, buffer, position); position += tokenBytes; return(position); }