public void Send(int id, string name, LuaTable tb) { if (SocketClient.State == SocketClient.ConnectState.DisConnect) { return; } var msg = ProtocolGroup.GetMsg(name); if (msg == null) { Debug.Log(String.Format("protocol {0} not exist", name)); return } m_messageIndex++; ByteBuffer protoBuff = new ByteBuffer(); ProtocolReadWriter.Req(msg.Id, buff, tb, ProtocolGroup); byteBuffer buff = new ByteBuffer(); buff.WriteUshort(msg.Id); buff.WriteBytes(protoBuff.ToBytes()); protoBuff.Close(); byte[] buffBytes = buff.ToBytes(); ByteBuffer contentBuff = new ByteBuffer(); contentBuff.WriteVchar((uint)buffBytes.Length); contentBuff.WriteBytes(buffBytes); ByteBuffer sendBuff = new ByteBuffer(); sendBuff.WriteUint(Convert.ToUInt32(buffBytes.Length) + 16); //CRC uint crc = CRC.GetCrc32(buffBytes); sendBuffer.WriteUint(crc); //Time uint timeUint = TimeSpanUtils.ConvertDateTimeToUInt(DateTime.Now); ByteBuffer desBuff = new ByteBuffer(); desBuff.WriteBytes(BitConverter.GetBytes(timeUint)); desBuff.WriteBytes(BitConverter.GetBytes(m_messageIndex)); //DES ulong des = BitConverter.ToUInt64(desBuff.ToBytes(), 0); byte[] desBytes = DES.Encrypt(bitConverter.GetBytes(des)); sendBuff.WriteUlong(BitConverter.ToUInt64(desBytes, 0)); sendBuff.WriteBytes(buffBytes); client.SendMessage(sendBuff); contentBuff.Close(); desBuff.Close(); buff.Close(); }
static int Close(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); LuaFramework.ByteBuffer obj = (LuaFramework.ByteBuffer)ToLua.CheckObject <LuaFramework.ByteBuffer>(L, 1); obj.Close(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 发送SOCKET消息 /// </summary> public void SendMsg(int uMsgID, ByteBuffer buffer) { NFMsg.MsgBase xData = new NFMsg.MsgBase(); xData.player_id = Util.NFToPB(mMainID); ByteBuffer newbuffer = new ByteBuffer(buffer.ToBytes()); xData.msg_data = newbuffer.ReadBytes(); MemoryStream body = new MemoryStream(); Serializer.Serialize <NFMsg.MsgBase>(body, xData); MsgHead head = new MsgHead(); head.unMsgID = (UInt16)uMsgID; head.unDataLen = (UInt32)body.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE; byte[] bodyByte = body.ToArray(); byte[] headByte = StructureTransform.StructureToByteArrayEndian(head); byte[] sendBytes = new byte[head.unDataLen]; headByte.CopyTo(sendBytes, 0); bodyByte.CopyTo(sendBytes, headByte.Length); SocketClient.SendMessage(sendBytes); buffer.Close(); newbuffer.Close(); }
IEnumerator OnExtractResource() { Util.Log("------> extract start <------"); string dataPath = Util.DataPath; //数据目录 string resPath = Util.AppContentPath(); //游戏包资源目录 if (!Directory.Exists(dataPath)) { Directory.CreateDirectory(dataPath); } yield return(null); //md5对比 //包内 string aplicationFileMD5 = resPath + AppConst.FinalSingleFileInfoMD5; //包外 string persistentFileMD5 = dataPath + AppConst.FinalSingleFileInfoMD5; string aplicationMd5String = null; string persistentMd5String = null; // 读取文件列表 // string aplicationFileListName = resPath + AppConst.FinalSingleFileInfo; //获取md5? //获取包外 if (File.Exists(persistentFileMD5)) { persistentMd5String = File.ReadAllText(persistentFileMD5); } //包内 WWW www = new WWW(aplicationFileMD5); yield return(www); aplicationMd5String = www.text; www.Dispose(); // md5验证相同,跳过解压 if (persistentMd5String != null && persistentMd5String.Equals(aplicationMd5String)) { StartCoroutine(OnUpdateResource()); yield break; } //md5验证不同或者data目录不存在MD5文件 //读取整个单文件 string inFile = resPath + AppConst.FinalSingleFile; www = new WWW(inFile); yield return(www); //解析文件 ByteBuffer buffer = new ByteBuffer(www.bytes); int idx = 0; int curIndex = 0; int totalCount = buffer.ReadInt(); byte[] wwwByte = www.bytes; NotiConst.MsgProgress msgProgress; for (int i = 0; i < totalCount; i++) { //开始写吧 string outFile = dataPath + buffer.ReadString(); string dir = Path.GetDirectoryName(outFile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } File.WriteAllBytes(outFile, buffer.ReadBytes()); curIndex++; if (idx++ > 10) // 限制每帧加载4个文件 { idx = 0; msgProgress.progress = (float)curIndex / (float)totalCount; msgProgress.notice = string.Format("正在解压:({0}%)", (int)(msgProgress.progress * 100)); facade.SendMessageCommand(NotiConst.LOADING_PROGRESS, msgProgress); yield return(null); } } buffer.Close(); www.Dispose(); //facade.SendMessageCommand( NotiConst.UPDATE_EXTRACT, "解压完毕(100%)" ); //加载完之后 将包内的md5信息写到包外 File.WriteAllText(persistentFileMD5, aplicationMd5String); //Debug.Log("OnExtractResource Done"); StartCoroutine(OnUpdateResource()); }
/// <summary> /// 发送消息 /// </summary> public void SendMessage(LuaFramework.ByteBuffer buffer) { SessionSend(buffer.ToBytes()); buffer.Close(); }