protected override void OnReceive(byte[] Packet) { lock (this) { PacketIn packet = new PacketIn(Packet, 0, Packet.Length); long byteLeft = packet.Length; while (byteLeft > 0) { if (!m_expectData) { long StartPos = packet.Position; m_expectSize = packet.DecodeMythicSize(); long EndPos = packet.Position; long Diff = EndPos - StartPos; byteLeft -= Diff; if (m_expectSize <= 0) { return; } if (byteLeft <= 0) { return; } Opcode = packet.GetUint8(); byteLeft -= 1; m_expectData = true; } else { m_expectData = false; if (byteLeft >= m_expectSize) { long Pos = packet.Position; packet.Opcode = Opcode; packet.Size = (ulong)m_expectSize; _srvr.HandlePacket(this, packet); byteLeft -= m_expectSize; packet.Position = Pos; packet.Skip(m_expectSize); } else { Log.Error("OnReceive", "Data count incorrect :" + byteLeft + " != " + m_expectSize); } } } packet.Dispose(); } }
protected override void OnReceive(byte[] packetBuffer) { lock (this) { PacketIn packet = new PacketIn(packetBuffer, 0, packetBuffer.Length); long bytesLeft = packet.Length; Log.Debug("OnReceive", $"Packet Received : Size {bytesLeft}, OpCode {packet.Opcode}"); while (bytesLeft > 0) { if (!_expectData) { long startPos = packet.Position; _expectedSize = packet.DecodeMythicSize(); long endPos = packet.Position; long diff = endPos - startPos; bytesLeft -= diff; if (_expectedSize <= 0) { packet.Opcode = packet.GetUint8(); packet.Size = (ulong)_expectedSize; Server.HandlePacket(this, packet); return; } if (bytesLeft <= 0) { return; } _opcode = packet.GetUint8(); bytesLeft -= 1; _expectData = true; } else { _expectData = false; if (bytesLeft >= _expectedSize) { long pos = packet.Position; packet.Opcode = _opcode; packet.Size = (ulong)_expectedSize; Server.HandlePacket(this, packet); bytesLeft -= _expectedSize; packet.Position = pos; packet.Skip(_expectedSize); } else { Log.Error("OnReceive", "Data count incorrect :" + bytesLeft + " != " + _expectedSize); } } } packet.Dispose(); } }