private bool ReadPacket() { bool flag = false; try { net.minecraft.src.Packet packet = net.minecraft.src.Packet.ReadPacket(socketInputStream, netHandler.IsServerHandler()); if (packet != null) { field_28141_d[packet.GetPacketId()] += packet.GetPacketSize() + 1; readPackets.Enqueue(packet); flag = true; } else { NetworkShutdown("disconnect.endOfStream", new object[0]); } } catch (System.Exception exception) { if (!isTerminating) { OnNetworkError(exception); } return(false); } return(flag); }
public virtual void AddToSendQueue(net.minecraft.src.Packet packet) { if (isServerTerminating) { return; } lock (sendQueueLock) { sendQueueByteLength += packet.GetPacketSize() + 1; if (packet.isChunkDataPacket) { chunkDataPackets.Enqueue(packet); } else { dataPackets.Enqueue(packet); } } }
/// <exception cref="System.IO.IOException"/> public static net.minecraft.src.Packet ReadPacket(java.io.DataInputStream datainputstream, bool flag) { int i = 0; net.minecraft.src.Packet packet = null; try { i = datainputstream.Read(); if (i == -1) { return(null); } if (flag && !serverPacketIdList.Contains(i) || !flag && !clientPacketIdList.Contains(i)) { throw new System.IO.IOException((new java.lang.StringBuilder()).Append("Bad packet id ").Append(i).ToString()); } packet = GetNewPacket(i); if (packet == null) { throw new System.IO.IOException((new java.lang.StringBuilder()).Append("Bad packet id ").Append(i).ToString()); } packet.ReadPacketData(datainputstream); } catch (System.IO.EndOfStreamException e) { System.Console.Out.WriteLine("Reached end of stream"); return(null); } net.minecraft.src.PacketCounter packetcounter = (net.minecraft.src.PacketCounter) packetStats[i]; if (packetcounter == null) { packetcounter = new net.minecraft.src.PacketCounter(null); packetStats[i] = packetcounter; } packetcounter.AddPacket(packet.GetPacketSize()); totalPacketsCount++; if (totalPacketsCount % 1000 != 0) { } return(packet); }
private bool SendPacket() { bool flag = false; try { Packet ppeek; bool peek; bool t = false; peek = dataPackets.TryPeek(out ppeek); if (dataPackets.Count > 0 && peek && (chunkDataSendCounter == 0 || Sharpen.Runtime.CurrentTimeMillis() - ((net.minecraft.src.Packet)ppeek).creationTimeMillis >= (long)chunkDataSendCounter)) { net.minecraft.src.Packet packet = null; try { lock (sendQueueLock) { t = dataPackets.TryDequeue(out packet); //packet = (net.minecraft.src.Packet)dataPackets.(0); if (t) { sendQueueByteLength -= packet.GetPacketSize() + 1; } } if (t) { net.minecraft.src.Packet.WritePacket(packet, socketOutputStream); field_28140_e[packet.GetPacketId()] += packet.GetPacketSize() + 1; flag = true; } } finally { if (t && packet != null && packet is IDisposable) { ((IDisposable)packet).Dispose(); } } } peek = chunkDataPackets.TryPeek(out ppeek); if (field_20175_w-- <= 0 && chunkDataPackets.Count > 0 && peek && (chunkDataSendCounter == 0 || Sharpen.Runtime.CurrentTimeMillis() - ((net.minecraft.src.Packet)ppeek).creationTimeMillis >= (long)chunkDataSendCounter)) { net.minecraft.src.Packet packet1 = null; try { lock (sendQueueLock) { t = chunkDataPackets.TryDequeue(out packet1); //packet1 = (net.minecraft.src.Packet) if (t) { sendQueueByteLength -= packet1.GetPacketSize() + 1; } } if (t) { net.minecraft.src.Packet.WritePacket(packet1, socketOutputStream); field_28140_e[packet1.GetPacketId()] += packet1.GetPacketSize() + 1; field_20175_w = 0; flag = true; } } finally { if (t && packet1 != null && packet1 is IDisposable) { ((IDisposable)packet1).Dispose(); } } } } catch (System.Exception exception) { if (exception is ThreadInterruptedException) { throw; //SHARP: Not sure if this 'fixes' ThreadInterruptedExceptions, just allows it to be ignored by the thread (as it's being caught in NetworkWriterThread). } if (!isTerminating) { OnNetworkError(exception); } return(false); } return(flag); }