public static String EncodeHashlink(Redirect room) { List <byte> list = new List <byte>(); list.AddRange(new byte[20]); list.AddRange(Encoding.UTF8.GetBytes("CHATCHANNEL")); list.Add(0); list.AddRange(room.IP.GetAddressBytes()); list.AddRange(BitConverter.GetBytes(room.Port)); list.AddRange(room.IP.GetAddressBytes()); list.AddRange(Encoding.UTF8.GetBytes(room.Name)); list.Add(0); list.Add(0); byte[] buf = list.ToArray(); buf = Zip.Compress(buf); buf = e67(buf, 28435); return(Convert.ToBase64String(buf)); }
public static byte[][] GetPackets(VoiceRecorderSendMethod m, byte len) { List <byte[]> packets = new List <byte[]>(); byte[] org_data = RecordBytes(); uint ident = Settings.Time; byte clip_len = (byte)(len + 2); uint uncompressed_size = (uint)org_data.Length; uint compressed_size = uncompressed_size; List <uint> compress_results = new List <uint>(); if (m == VoiceRecorderSendMethod.Opus) { org_data = Opus.Encode(org_data); uncompressed_size = (uint)org_data.Length; List <byte> data_to_send = new List <byte>(org_data); if (data_to_send.Count < MAX_CHUNK_SIZE) { packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, 0, uncompressed_size, data_to_send.ToArray())); } else { packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, 0, uncompressed_size, data_to_send.ToArray())); data_to_send.RemoveRange(0, MAX_CHUNK_SIZE); while (data_to_send.Count >= MAX_CHUNK_SIZE) { packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.GetRange(0, MAX_CHUNK_SIZE).ToArray())); data_to_send.RemoveRange(0, MAX_CHUNK_SIZE); } if (data_to_send.Count > 0) { packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.ToArray())); } } } else { while (true) { byte[] tmp = Zip.Compress(org_data); if (tmp.Length < org_data.Length) { compress_results.Add((uint)tmp.Length); compressed_size = (uint)tmp.Length; org_data = tmp; } else { break; } } List <byte> data_to_send = new List <byte>(org_data); List <byte> compress_results_data = new List <byte>(); for (int i = 0; i < compress_results.Count; i++) { compress_results_data.AddRange(BitConverter.GetBytes(compress_results[i])); } if (data_to_send.Count < MAX_CHUNK_SIZE) { packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, (byte)compress_results.Count, uncompressed_size, compress_results_data.ToArray().Concat(data_to_send).ToArray())); } else { packets.Add(TCPOutbound.VoiceFirst(ident, clip_len, (byte)compress_results.Count, uncompressed_size, compress_results_data.ToArray().Concat(data_to_send.GetRange(0, MAX_CHUNK_SIZE)).ToArray())); data_to_send.RemoveRange(0, MAX_CHUNK_SIZE); while (data_to_send.Count >= MAX_CHUNK_SIZE) { packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.GetRange(0, MAX_CHUNK_SIZE).ToArray())); data_to_send.RemoveRange(0, MAX_CHUNK_SIZE); } if (data_to_send.Count > 0) { packets.Add(TCPOutbound.VoiceChunk(ident, data_to_send.ToArray())); } } } return(packets.ToArray()); }