/// <summary> /// 解析加密后的数据包得到原始数据包 /// </summary> /// <param name="dataCache"></param> public static byte[] DeMakeData(byte[] buffer) { // 拆包得到数据包 byte[] bufferNew = new byte[buffer.Length - 3]; bool IsComPressLen = false; ushort crc = 0; using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { //是否压缩 IsComPressLen = ms.ReadBool(); crc = ms.ReadUShort(); ms.Read(bufferNew, 0, bufferNew.Length); } //1、crc校验 ushort newCrc = CRC16.CalculateCrc16(bufferNew); if (newCrc == crc) { //2、异或后的原始数据包 bufferNew = SecurityUtil.Xor(bufferNew); if (IsComPressLen) { //3、解压缩 bufferNew是真实数据 bufferNew = ZlibHelper.deCompressBytes(bufferNew); } } return(bufferNew); }
public static MailProto GetProto(byte[] buffer) { MailProto proto = new MailProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.Count = ms.ReadInt(); proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.SuccMsg = ms.ReadUTF8String(); proto.SuccCode = ms.ReadUTF8String(); } else { proto.ErrorCode = ms.ReadInt(); } proto.ItemCount = ms.ReadInt(); proto.ItemIdList = new List <int>(); proto.ItemNameList = new List <int>(); for (int i = 0; i < proto.ItemCount; i++) { int _ItemId = ms.ReadInt(); //道具编号 proto.ItemIdList.Add(_ItemId); int _ItemName = ms.ReadInt(); //道具名称 proto.ItemNameList.Add(_ItemName); } } return(proto); }
public static Goods_UseItemReturnProto GetProto(byte[] buffer, bool isChild = false) { Goods_UseItemReturnProto proto = new Goods_UseItemReturnProto(); MMO_MemoryStream ms = null; if (!isChild) { ms = GameEntry.Socket.SocketSendMS; } else { ms = GameEntry.Pool.DequeueClassObject <MMO_MemoryStream>(); } ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.GoodsId = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } if (isChild) { GameEntry.Pool.EnqueueClassObject(ms); } return(proto); }
public static System_GameServerConfigReturnProto GetProto(byte[] buffer, bool isChild = false) { System_GameServerConfigReturnProto proto = new System_GameServerConfigReturnProto(); MMO_MemoryStream ms = null; if (!isChild) { ms = GameEntry.Socket.SocketSendMS; } else { ms = GameEntry.Pool.DequeueClassObject <MMO_MemoryStream>(); } ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.ConfigCount = ms.ReadInt(); proto.ServerConfigList = new List <ConfigItem>(); for (int i = 0; i < proto.ConfigCount; i++) { ConfigItem _ServerConfig = new ConfigItem(); _ServerConfig.ConfigCode = ms.ReadUTF8String(); _ServerConfig.IsOpen = ms.ReadBool(); _ServerConfig.Param = ms.ReadUTF8String(); proto.ServerConfigList.Add(_ServerConfig); } if (isChild) { GameEntry.Pool.EnqueueClassObject(ms); } return(proto); }
public static RoleOperation_SelectRoleInfoReturnProto ToProto(byte[] buffer) { using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { RoleOperation_SelectRoleInfoReturnProto proto = new RoleOperation_SelectRoleInfoReturnProto(); proto.IsSucess = ms.ReadBool(); if (proto.IsSucess) { proto.RoleNickName = ms.ReadUTF8String(); proto.Level = ms.ReadInt(); proto.RoleId = ms.ReadInt(); proto.JobId = ms.ReadInt(); proto.Money = ms.ReadInt(); proto.Gold = ms.ReadInt(); proto.Exp = ms.ReadInt(); proto.MaxHP = ms.ReadInt(); proto.CurrentHP = ms.ReadInt(); proto.MaxMP = ms.ReadInt(); proto.CurrentMP = ms.ReadInt(); proto.Attack = ms.ReadInt(); proto.Defense = ms.ReadInt(); proto.Hit = ms.ReadInt(); proto.Dodge = ms.ReadInt(); proto.Cri = ms.ReadInt(); proto.Fighting = ms.ReadInt(); proto.Res = ms.ReadInt(); proto.LastSceneId = ms.ReadInt(); } else { proto.MessageId = ms.ReadInt(); } return(proto); } }
public static RoleOperation_SelectRoleInfoReturnProto GetProto(MMO_MemoryStream ms, byte[] buffer) { RoleOperation_SelectRoleInfoReturnProto proto = new RoleOperation_SelectRoleInfoReturnProto(); ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.RoldId = ms.ReadInt(); proto.RoleNickName = ms.ReadUTF8String(); proto.JobId = (byte)ms.ReadByte(); proto.Level = ms.ReadInt(); proto.TotalRechargeMoney = ms.ReadInt(); proto.Money = ms.ReadInt(); proto.Gold = ms.ReadInt(); proto.Exp = ms.ReadInt(); proto.MaxHP = ms.ReadInt(); proto.MaxMP = ms.ReadInt(); proto.CurrHP = ms.ReadInt(); proto.CurrMP = ms.ReadInt(); proto.ToSpeed = ms.ReadInt(); proto.WeaponDamageMin = ms.ReadInt(); proto.WeaponDamageMax = ms.ReadInt(); proto.AttackNumber = ms.ReadInt(); proto.StrikePower = ms.ReadInt(); proto.PiercingPower = ms.ReadInt(); proto.MagicPower = 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(); proto.ChoppingDefense = ms.ReadInt(); proto.PuncturDefense = ms.ReadInt(); proto.MagicDefense = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } return(proto); }
protected override void OnUpdate() { base.OnUpdate(); while (true) { if (m_ReceiveCount <= 5) { m_ReceiveCount++; lock (m_ReceiveQueue) { if (m_ReceiveQueue.Count > 0) { byte[] buffer = m_ReceiveQueue.Dequeue(); bool isCompress; ushort crc; byte[] crcBuffer = new byte[buffer.Length - 3]; using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { isCompress = ms.ReadBool(); crc = ms.ReadUShort(); ms.Read(crcBuffer, 0, crcBuffer.Length); } if (crc == Crc16.CalculateCrc16(crcBuffer)) { crcBuffer = SecurityUtil.Xor(crcBuffer); if (isCompress) { crcBuffer = ZlibHelper.DeCompressBytes(crcBuffer); } ushort protoCode; byte[] protoContent = new byte[buffer.Length - 2]; using (MMO_MemoryStream ms = new MMO_MemoryStream(crcBuffer)) { protoCode = ms.ReadUShort(); ms.Read(protoContent, 0, protoContent.Length); } EnventDispather.Instance.Dispach(protoCode, protoContent); } else { break; } } else { break; } } } else { m_ReceiveCount = 0; break; } } }
public static GameLevel_FailReturnProto ToProto(byte[] buffer) { using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { GameLevel_FailReturnProto proto = new GameLevel_FailReturnProto(); proto.IsSucess = ms.ReadBool(); return(proto); } }
public static RoleOperation_SelectRoleInfoReturnProto GetProto(byte[] buffer) { RoleOperation_SelectRoleInfoReturnProto proto = new RoleOperation_SelectRoleInfoReturnProto(); MMO_MemoryStream ms = GameEntry.Socket.SocketReceiveMS; ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.RoldId = ms.ReadInt(); proto.RoleNickName = ms.ReadUTF8String(); proto.JobId = (byte)ms.ReadByte(); proto.Level = ms.ReadInt(); proto.TotalRechargeMoney = ms.ReadInt(); proto.Money = ms.ReadInt(); proto.Gold = 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.Fighting = 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); }
public static RoleOperation_EnterGameReturnProto ToProto(byte[] buffer) { using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { RoleOperation_EnterGameReturnProto proto = new RoleOperation_EnterGameReturnProto(); proto.IsSucess = ms.ReadBool(); return(proto); } }
public static RoleOperation_CreateRoleReturnProto ToProto(byte[] buffer) { using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { RoleOperation_CreateRoleReturnProto proto = new RoleOperation_CreateRoleReturnProto(); proto.IsSucess = ms.ReadBool(); if (!proto.IsSucess) { proto.MessageID = ms.ReadInt(); } return(proto); } }
public static WorldMap_RoleEnterReturnProto GetProto(byte[] buffer) { WorldMap_RoleEnterReturnProto proto = new WorldMap_RoleEnterReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static GameLevelSuccessResponseProto GetProto(byte[] buffer) { GameLevelSuccessResponseProto proto = new GameLevelSuccessResponseProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static RoleOperation_CreateRoleReturnProto GetProto(byte[] buffer) { RoleOperation_CreateRoleReturnProto proto = new RoleOperation_CreateRoleReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static RoleOperation_DeleteRoleReturnProto GetProto(byte[] buffer) { RoleOperation_DeleteRoleReturnProto proto = new RoleOperation_DeleteRoleReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MessageId = ms.ReadShort(); } } return(proto); }
public static Goods_SellToSysReturnProto GetProto(byte[] buffer) { Goods_SellToSysReturnProto proto = new Goods_SellToSysReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { } proto.MsgCode = ms.ReadInt(); } return(proto); }
public static GameLevel_FailReturnProto GetProto(byte[] buffer) { GameLevel_FailReturnProto proto = new GameLevel_FailReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MessageId = ms.ReadShort(); } } return(proto); }
public static Shop_BuyProductReturnProto GetProto(byte[] buffer) { Shop_BuyProductReturnProto proto = new Shop_BuyProductReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { } proto.MsgCode = ms.ReadInt(); } return(proto); }
public static GameServerOnePageResponseProto GetProto(byte[] buffer) { GameServerOnePageResponseProto proto = new GameServerOnePageResponseProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.ItemCount = ms.ReadInt(); proto.ServerOnePageItemList = new List <GameServerOnePageItem>(); for (int i = 0; i < proto.ItemCount; i++) { GameServerOnePageItem _ServerOnePageItem = new GameServerOnePageItem(); _ServerOnePageItem.ServerId = ms.ReadInt(); _ServerOnePageItem.Status = ms.ReadInt(); _ServerOnePageItem.RunState = ms.ReadInt(); _ServerOnePageItem.IsCommand = ms.ReadBool(); _ServerOnePageItem.IsNew = ms.ReadBool(); _ServerOnePageItem.Name = ms.ReadUTF8String(); _ServerOnePageItem.Ip = ms.ReadUTF8String(); _ServerOnePageItem.Port = ms.ReadInt(); proto.ServerOnePageItemList.Add(_ServerOnePageItem); } } return(proto); }
public static GameLevel_ResurgenceReturnProto GetProto(MMO_MemoryStream ms, byte[] buffer) { GameLevel_ResurgenceReturnProto proto = new GameLevel_ResurgenceReturnProto(); ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } return(proto); }
public static Shop_BuyProductReturnProto GetProto(MMO_MemoryStream ms, byte[] buffer) { Shop_BuyProductReturnProto proto = new Shop_BuyProductReturnProto(); ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { } proto.MsgCode = ms.ReadInt(); return(proto); }
public static RoleOperation_DeleteRoleReturnProto GetProto(MMO_MemoryStream ms, byte[] buffer) { RoleOperation_DeleteRoleReturnProto proto = new RoleOperation_DeleteRoleReturnProto(); ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } return(proto); }
public static WorldMap_RoleEnterReturnProto GetProto(MMO_MemoryStream ms, byte[] buffer) { WorldMap_RoleEnterReturnProto proto = new WorldMap_RoleEnterReturnProto(); ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } return(proto); }
/// <summary> /// 根据字节数组转换成结构体 /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static Mail_Get_DerarilProto GetProto(byte[] buffer) { Mail_Get_DerarilProto proto = new Mail_Get_DerarilProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.Name = ms.ReadUTF8String(); } else { proto.ErrorCode = ms.ReadUShort(); } } return proto; }
public static Goods_SellToSysReturnProto GetProto(byte[] buffer) { Goods_SellToSysReturnProto proto = new Goods_SellToSysReturnProto(); MMO_MemoryStream ms = GameEntry.Socket.SocketReceiveMS; ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { } proto.MsgCode = ms.ReadInt(); return(proto); }
public static RoleOperation_EnterGameReturnProto GetProto(byte[] buffer) { RoleOperation_EnterGameReturnProto proto = new RoleOperation_EnterGameReturnProto(); MMO_MemoryStream ms = GameEntry.Socket.SocketReceiveMS; ms.SetLength(0); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; proto.IsSuccess = ms.ReadBool(); if (!proto.IsSuccess) { proto.MsgCode = ms.ReadInt(); } return(proto); }
public static Goods_UseItemReturnProto GetProto(byte[] buffer) { Goods_UseItemReturnProto proto = new Goods_UseItemReturnProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.GoodsId = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static AccountRegisterResponseProto GetProto(byte[] buffer) { AccountRegisterResponseProto proto = new AccountRegisterResponseProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.UserId = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static RoleInfoResponseProto GetProto(byte[] buffer) { RoleInfoResponseProto proto = new RoleInfoResponseProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.IsSuccess = ms.ReadBool(); if (proto.IsSuccess) { proto.RoleId = ms.ReadInt(); proto.JobId = ms.ReadInt(); proto.NickName = ms.ReadUTF8String(); proto.Sex = ms.ReadInt(); proto.Level = ms.ReadInt(); proto.Money = ms.ReadInt(); proto.Gold = ms.ReadInt(); proto.Exp = ms.ReadInt(); proto.MaxHP = ms.ReadInt(); proto.CurrHP = ms.ReadInt(); proto.MaxMP = ms.ReadInt(); proto.CurrMP = ms.ReadInt(); proto.Attack = ms.ReadInt(); proto.AttackAddition = ms.ReadInt(); proto.Defense = ms.ReadInt(); proto.DefenseAddition = ms.ReadInt(); proto.Res = ms.ReadInt(); proto.ResAddition = ms.ReadInt(); proto.Hit = ms.ReadInt(); proto.HitAddition = ms.ReadInt(); proto.Dodge = ms.ReadInt(); proto.DodgeAddition = ms.ReadInt(); proto.Cri = ms.ReadInt(); proto.CriAddition = ms.ReadInt(); proto.Fighting = ms.ReadInt(); proto.FightingAddition = ms.ReadInt(); proto.LastInWorldMapId = ms.ReadInt(); } else { proto.MsgCode = ms.ReadInt(); } } return(proto); }
public static MailResponseProto GetProto(byte[] buffer) { MailResponseProto proto = new MailResponseProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.MailCount = ms.ReadInt(); proto.MailList = new List <MailItem>(); for (int i = 0; i < proto.MailCount; i++) { MailItem _Mail = new MailItem(); _Mail.Id = ms.ReadInt(); _Mail.Content = ms.ReadUTF8String(); _Mail.IsRead = ms.ReadBool(); proto.MailList.Add(_Mail); } } return(proto); }