protected void OnSendCustomClick(object sender, EventArgs e) { // build a gamemessage from the provided messagetype and body byte[] body = txtMessageBody.GetBinaryValue(); byte[] msgbytes = new byte[MessageHeader.Tcp.HEADERLENGTH + body.Length]; Array.Copy(BitConverter.GetBytes(Convert.ToUInt16(body.Length)), 0, msgbytes, 0, 2); Array.Copy(BitConverter.GetBytes(Convert.ToUInt16(body.Length)), 0, msgbytes, 4, 2); Array.Copy(body, 0, msgbytes, MessageHeader.Tcp.HEADERLENGTH, body.Length); // create generic instance from raw bytes GenericGameMessage message = new GenericGameMessage(msgbytes); // send it by raising event if (PacketSend != null) { PacketSend(this, new GameMessageEventArgs(message)); } }
private void btnSend_Click(object sender, EventArgs e) { try { byte[] packetbody = txtSendPacket.Value; byte[] packetdata = new byte[GameMessage.HEADERLENGTH + packetbody.Length]; Array.Copy(BitConverter.GetBytes(Convert.ToUInt16(packetbody.Length)), 0, packetdata, 0, 2); Array.Copy(BitConverter.GetBytes(Convert.ToUInt16(packetbody.Length)), 0, packetdata, 4, 2); Array.Copy(packetbody, 0, packetdata, GameMessage.HEADERLENGTH, packetbody.Length); GenericGameMessage packet = new GenericGameMessage(packetdata); if (PacketSend != null) { PacketSend(this, new GameMessageEventArgs(packet)); } } catch (Exception) { } }