CPacketHeader GetHeaderFromBuffer(Byte[] arr_bBuffer) { try { String strBuffer = UnicodeEncoding.Unicode.GetString(arr_bBuffer, 2, arr_bBuffer.Length - 2); if (String.IsNullOrEmpty(strBuffer)) { return(null); } String[] arr_strData = strBuffer.Split('|'); if (arr_strData.Length != Header_Length) { return(null); } CPacketHeader PacketHeader = new CPacketHeader(); PacketHeader.Packet_Ident = arr_strData[0]; PacketHeader.Packet = arr_bBuffer[1]; if (!Int32.TryParse(arr_strData[1], out PacketHeader.Block_Amount)) { return(null); } return(PacketHeader); } catch { } return(null); }
public CPacket CreatePacket(Byte Packet, Byte[] arr_bArguments) { try { //Split Buffer to 128-byte long Blocks List <Byte[]> lstBlockBuffers = CUtils.SplitBytes(arr_bArguments, 512); List <CPacketBlock> lstBlocks = new List <CPacketBlock>(); //Create Blocks foreach (Byte[] arr_bBuffer in lstBlockBuffers.ToArray()) { CPacketBlock Block = new CPacketBlock(); Block.Block_ID = lstBlocks.Count + 1; string strBuffer = UnicodeEncoding.Unicode.GetString(arr_bBuffer); Block.Block_Buffer = arr_bBuffer; lstBlocks.Add(Block); } //Create Packet Header CPacketHeader Header = CPacketHeader.CreateHeader(Packet, lstBlocks.Count); //Create Packet CPacket SendPacket = new CPacket(Header); SendPacket.Data_Blocks = lstBlocks; return(SendPacket); } catch { } return(null); }
void m_Protocol_OnHeaderReceived(CPacketHeader Header) { if (this.OnHeaderReceived != null) { this.OnHeaderReceived.Invoke(Header); } }
public CPacket(CPacketHeader Header) { this.PacketHeader = Header; if (Header.Block_Amount > 0) { Data_Blocks = new List <CPacketBlock>(); } }
public static CPacketHeader CreateHeader(Byte Packet, Int32 iBlockAmount) { try { CPacketHeader Header = new CPacketHeader(); Header.Packet_Ident = CUtils.RandomString(8); Header.Packet = Packet; Header.Block_Amount = iBlockAmount; return(Header); } catch { } return(null); }
void ProcessHeader(Byte[] arr_bBuffer) { CPacketHeader Header = this.GetHeaderFromBuffer(arr_bBuffer); if (Header == null) { return; } CPacket Packet = new CPacket(Header); for (int i = 0; i < Packet.PacketHeader.Block_Amount; i++) { CPacketBlock Block = new CPacketBlock(); Block.Block_ID = Packet.Data_Blocks.Count + 1; Packet.Data_Blocks.Add(Block); } if (!Packet.IsFinished()) { lock (m_lstQueueRecvPacket) { m_lstQueueRecvPacket.Add(Packet); if (this.OnHeaderReceived != null) { this.OnHeaderReceived.Invoke(Packet.PacketHeader); } } } else { if (this.OnPacketReceived != null) { this.OnPacketReceived.Invoke(Packet); } } }