/// <summary> /// Sends a HeapItem to the connected client. The HeapItem must be a valid /// Terraria packet. /// </summary> /// <remarks> /// Heap item must point to a valid packet. /// </remarks> protected void SendHeapItem(HeapItem item) { if (item.Heap == null) { return; } try { int length = BitConverter.ToInt16(item.Heap, item.Offset); PacketTypes type = (PacketTypes)item.Heap[item.Offset + 2]; TcpClient tcpClient = (client.Socket as TcpSocket)._connection; tcpClient.GetStream().Write(item.Heap, item.Offset, length); if (type == PacketTypes.Disconnect) { Netplay.Clients[client.Id].PendingTermination = true; } } catch { Netplay.Clients[client.Id].PendingTermination = true; } finally { Free(item.Block, item.HeapType); } }
public void Enqueue(HeapItem item) { if (item.Block == -1) { return; } lock (_syncRoot) { sendQueue.Enqueue(item); Monitor.Pulse(_syncRoot); } }
/// <summary> /// Enqueues a heap item into the send queue. Packets enqued will be sent to the client. /// </summary> public void Enqueue(HeapItem item) { if (item.Block == -1 || item.Heap == null) { return; } lock (_syncRoot) { sendQueue.Enqueue(item); Monitor.Pulse(_syncRoot); } //Trace.WriteLine($"Enqueue on {client.Id}"); }