public static Account_RoleInfoRespProto GetProto(byte[] buffer) { Account_RoleInfoRespProto proto = new Account_RoleInfoRespProto(); using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.RoldId = ms.ReadInt(); proto.RoleNickName = ms.ReadUTF8String(); proto.ClassId = (byte)ms.ReadByte(); proto.Level = ms.ReadInt(); proto.VIPLevel = ms.ReadInt(); proto.TotalRechargeGem = ms.ReadInt(); proto.Gem = ms.ReadInt(); proto.Gold = ms.ReadInt(); proto.CurrEnergy = ms.ReadInt(); proto.MaxEnergy = ms.ReadInt(); proto.Exp = ms.ReadInt(); proto.MaxHP = ms.ReadInt(); proto.MaxMP = ms.ReadInt(); proto.CurrHP = ms.ReadInt(); proto.CurrMP = ms.ReadInt(); proto.Attack = ms.ReadInt(); proto.Defense = ms.ReadInt(); proto.Hit = ms.ReadInt(); proto.Dodge = ms.ReadInt(); proto.Cri = ms.ReadInt(); proto.Res = ms.ReadInt(); proto.SumDPS = ms.ReadInt(); proto.LastPassGameQuestId = ms.ReadInt(); proto.LastInWorldMapId = ms.ReadInt(); proto.LastInWorldMapPos = ms.ReadUTF8String(); proto.Equip_Weapon = ms.ReadInt(); proto.Equip_Pants = ms.ReadInt(); proto.Equip_Clothes = ms.ReadInt(); proto.Equip_Belt = ms.ReadInt(); proto.Equip_Cuff = ms.ReadInt(); proto.Equip_Necklace = ms.ReadInt(); proto.Equip_Shoe = ms.ReadInt(); proto.Equip_Ring = ms.ReadInt(); proto.Equip_WeaponTableId = ms.ReadInt(); proto.Equip_PantsTableId = ms.ReadInt(); proto.Equip_ClothesTableId = ms.ReadInt(); proto.Equip_BeltTableId = ms.ReadInt(); proto.Equip_CuffTableId = ms.ReadInt(); proto.Equip_NecklaceTableId = ms.ReadInt(); proto.Equip_ShoeTableId = ms.ReadInt(); proto.Equip_RingTableId = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } } return(proto); }
/// <summary> /// 构造函数 /// </summary> /// <param name="path"></param> public GameDataTableParser(string path) { m_FieldNameDic = new Dictionary <string, int>(); //------------------ //第1步:读取文件 //------------------ /* 48课以后读取AB资源时使用新写法 * using (FileStream fs = new FileStream(path, FileMode.Open)) * { * buffer = new byte[fs.Length]; * fs.Read(buffer, 0, buffer.Length); * } */ byte[] buffer = LocalFileManager.Instance.GetBuffer(path); //------------------ //第2步:解压缩 //------------------ buffer = ZlibHelper.DeCompressBytes(buffer); //------------------ //第3步:xor解密 //43课以后将其移动到Leo_SecurityUtil中 //------------------ buffer = SecurityUtil.XorAlgorithm(buffer); //------------------ //第4步:解析数据到数组 //------------------ using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { m_Row = ms.ReadInt(); m_Column = ms.ReadInt(); m_GameData = new String[m_Row, m_Column]; m_FieldName = new string[m_Column]; for (int i = 0; i < m_Row; i++) { for (int j = 0; j < m_Column; j++) { string str = ms.ReadUTF8String(); if (i == 0) { //表示读取的是字段 m_FieldName[j] = str; m_FieldNameDic[str] = j; } else if (i > 2) { //表示读取的是内容 m_GameData[i, j] = str; } } } } }
public static Account_AddRoleReqProto GetProto(byte[] buffer) { Account_AddRoleReqProto proto = new Account_AddRoleReqProto(); using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { proto.ClassId = (byte)ms.ReadByte(); proto.RoleNickName = ms.ReadUTF8String(); proto.GameServerId = ms.ReadInt(); } return(proto); }
public static Account_LoginGameServerRespProto GetProto(byte[] buffer) { Account_LoginGameServerRespProto proto = new Account_LoginGameServerRespProto(); using (MemoryStreamUtil ms = new MemoryStreamUtil(buffer)) { proto.RoleCount = ms.ReadInt(); proto.RoleList = new List <RoleItem>(); for (int i = 0; i < proto.RoleCount; i++) { RoleItem _Role = new RoleItem(); _Role.RoleId = ms.ReadInt(); _Role.RoleNickName = ms.ReadUTF8String(); _Role.RoleClass = (byte)ms.ReadByte(); _Role.RoleLevel = ms.ReadInt(); proto.RoleList.Add(_Role); } } return(proto); }
private void ReceiveCallback(IAsyncResult result) { try { int len = client.EndReceive(result); if (len > 0) //接收到数据了 { mReceiveStream.Position = mReceiveStream.Length; mReceiveStream.Write(mReceiveBuffer, 0, mReceiveBuffer.Length); //数据写进内存,等待操作 //根据我们自定义数据包的格式,大于2字节代表有一个包传过来了 if (mReceiveStream.Length > 2) { while (true) { mReceiveStream.Position = 0; int currentMsgLen = mReceiveStream.ReadUShort(); //包体长度 int currentFullLen = 2 + currentMsgLen; //包头+包体长度 if (mReceiveStream.Length >= currentFullLen) //接收的数据包大于一个完整包的长度,表示至少有一个完整包传过来了 { byte[] buffer = new byte[currentMsgLen]; //此buffer为真实数据 mReceiveStream.Position = 2; //根据我们自定义的数据包格式,刨除前2位,后面的是真实数据 mReceiveStream.Read(buffer, 0, currentMsgLen); lock (mReceiveQueue) { mReceiveQueue.Enqueue(buffer); //加入接收队列中 } using (MemoryStreamUtil stream = new MemoryStreamUtil()) { string data = stream.ReadUTF8String(); // Debug.Log("data:" + data); } //上面是一个完整数据包处理过程,下面是本次接收多余的数据进行处理 int remainLen = (int)mReceiveStream.Length - currentFullLen; if (remainLen > 0) //本次接收的数据大于一个完整包时 { mReceiveStream.Position = currentFullLen; byte[] remainBuffer = new byte[remainLen]; mReceiveStream.Read(remainBuffer, 0, remainLen); //把剩余所有数据读进内存 //把流中数据清空 mReceiveStream.Position = 0; mReceiveStream.SetLength(0); mReceiveStream.Write(remainBuffer, 0, remainBuffer.Length); remainBuffer = null; } else { //把流中数据清空 mReceiveStream.Position = 0; mReceiveStream.SetLength(0); break; } } else { //还没收到完整包 break; } } } ReceiveMessage(); } else { Debug.Log("断开连接else"); } } catch (Exception e) { Debug.Log(e.Message); Debug.Log("断开连接catch"); } }