public void OnUpdate() { while (true) { if (m_ReceiveCount < 5) { ++m_ReceiveCount; lock (m_ReceiveQueue) { if (m_ReceiveQueue.Count > 0) { byte[] buffer = m_ReceiveQueue.Dequeue(); byte[] protocodeBuffer = new byte[4]; byte[] protoContent = new byte[buffer.Length - 5]; bool isCompress = false; using (MemoryStreamExt ms = new MemoryStreamExt(buffer)) { isCompress = ms.ReadBool(); ms.Read(protocodeBuffer, 0, protocodeBuffer.Length); Array.Reverse(protocodeBuffer); int protoCode = BitConverter.ToInt32(protocodeBuffer, 0); LogSystem.Log("=============================================================收到消息" + protoCode); ms.Read(protoContent, 0, protoContent.Length); if (isCompress) { protoContent = GZipCompress.DeCompress(protoContent); } if (protoCode == OP_PLAYER_CLOSE.CODE) { LogSystem.LogSpecial("服务器返回关闭消息,网络连接断开"); Close(true); } else if (protoCode == OP_SYS_HEART.CODE) { lastHeart = OP_SYS_HEART.decode(protoContent); } else { //return; NetDispatcher.Instance.Dispatch(protoCode, protoContent); } } } else { break; } } } else { m_ReceiveCount = 0; break; } } m_SocketStateDic[m_CurrentState].OnUpdate(); }
/// <summary> /// 播放外部音频 /// </summary> /// <param name="bytes"></param> public void PlayExternalAudio(byte[] bytes) { bytes = GZipCompress.DeCompress(bytes); float[] fl = new float[bytes.Length / 4]; using (MemoryStreamExt ms = new MemoryStreamExt(bytes)) { for (int i = 0; i < fl.Length; ++i) { fl[i] = ms.ReadFloat(); } } AudioClip clip = AudioClip.Create("MicroAudio", fl.Length, 1, FREQUENCY, false); clip.SetData(fl, 0); m_MicroQueue.Enqueue(clip); }
// byte[] = byte[] /// <summary> /// 3DES解密后GZip解压缩,密钥长度必需是24字节 /// </summary> /// <param name="hexStringKey">密钥串</param> /// <param name="encryptSource"></param> /// <returns></returns> public static byte[] Un3DesAndUnGZip(string hexStringKey, byte[] encryptSource) { byte[] desResult = Cryptography.TripleDesDecrypt(hexStringKey, encryptSource); return(GZipCompress.DeCompress(desResult)); }