private void EGMI_ACK_MOVE_IMMUNE(MsgHead head, MemoryStream stream) { AFMsg.ReqAckPlayerMove xData = ReceiveMsg(stream, ReqAckPlayerMove.Parser) as ReqAckPlayerMove; if (xData.TargetPos.Count <= 0) { return; } //其实就是jump float fSpeed = AFCKernel.Instance.QueryPropertyInt(PBToAF(xData.Mover), "MOVE_SPEED") / 10000.0f; fSpeed *= 1.5f; AFCDataList varList = new AFCDataList(); varList.AddObject(PBToAF(xData.Mover)); varList.AddFloat(xData.TargetPos[0].X); varList.AddFloat(xData.TargetPos[0].Y); varList.AddFloat(xData.TargetPos[0].Z); varList.AddFloat(fSpeed); AFCLogicEvent.Instance.DoEvent((int)ClientEventDefine.EVENTDEFINE_MOVE_IMMUNE, varList); //AFCRenderInterface.Instance.MoveImmuneBySpeed(PBToAF(xData.mover), new Vector3(xData.target_pos[0].x, xData.target_pos[0].y, xData.target_pos[0].z), fSpeed, true); }
public void RequireMoveImmune(NFCoreEx.NFIDENTID objectID, float fX, float fZ) { NFMsg.ReqAckPlayerMove xData = new NFMsg.ReqAckPlayerMove(); xData.mover = NFToPB(objectID); xData.moveType = 0; NFMsg.Position xTargetPos = new NFMsg.Position(); xTargetPos.x = fX; xTargetPos.z = fZ; xData.target_pos.Add(xTargetPos); MemoryStream stream = new MemoryStream(); Serializer.Serialize <NFMsg.ReqAckPlayerMove>(stream, xData); SendMsg(objectID, NFMsg.EGameMsgID.EGMI_REQ_MOVE_IMMUNE, stream); if (NFStart.Instance.bDebugMode) { NFMsg.MsgBase xAckData = new NFMsg.MsgBase(); xAckData.player_id = xData.mover; xAckData.msg_data = stream.ToArray(); MemoryStream xAckBody = new MemoryStream(); Serializer.Serialize <NFMsg.MsgBase>(xAckBody, xAckData); MsgHead head = new MsgHead(); head.unMsgID = (UInt16)NFMsg.EGameMsgID.EGMI_ACK_MOVE_IMMUNE; head.unDataLen = (UInt32)xAckBody.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE; xNet.mxBinMsgEvent.OnMessageEvent(head, xAckBody.ToArray()); } }
private void EGMI_ACK_OBJECT_PROPERTY_ENTRY(MsgHead head, MemoryStream stream) { AFMsg.MultiEntityDataNodeList xMultiObjectPropertyList = MultiEntityDataNodeList.Parser.ParseFrom(stream); // ReceiveMsg(stream, ref xMultiObjectPropertyList); for (int i = 0; i < xMultiObjectPropertyList.MultiEntityDataNodeList_.Count; i++) { AFMsg.EntityDataNodeList xPropertyData = xMultiObjectPropertyList.MultiEntityDataNodeList_[i]; AFIObject go = AFCKernel.Instance.GetObject(PBToAF(xPropertyData.EntityId)); AFIPropertyManager xPropertyManager = go.GetPropertyManager(); for (int j = 0; j < xPropertyData.DataNodeList.Count; j++) { string strPropertyName = xPropertyData.DataNodeList[j].NodeName; AFCoreEx.AFIDataList.Var_Data xPropertyValue = PBPropertyToData(xPropertyData.DataNodeList[j]); AFIProperty xProperty = xPropertyManager.GetProperty(strPropertyName); if (null == xProperty) { AFIDataList varList = new AFCDataList(); varList.AddDataObject(ref xPropertyValue); xProperty = xPropertyManager.AddProperty(strPropertyName, varList); } xProperty.SetDataObject(ref xPropertyValue); } } }
/// <summary> /// 执行对应消息的事件 /// </summary> /// <param name="headData">msgHead数据</param> private void Dispatch(MsgHead headData) { if (headData == null) { Debug.LogError("消息头为空."); return; } var msgId = headData.msgId; if (msgDispatchActionList.ContainsKey(msgId)) { var dic = msgDispatchActionList[msgId]; if (dic.ContainsKey(true)) { var actionList = dic[true]; // 执行并删除 foreach (var action in actionList.Where(action => action != null)) { action(headData); } // 清空 actionList.Clear(); } if (dic.ContainsKey(false)) { // 执行 var actionList = dic[false]; // 执行并删除 foreach (var action in actionList.Where(action => action != null)) { action(headData); } } } }
public void Analysis(Client pClient) { int Count = pClient.bufferCount; try { pClient.msgLength = pClient.readBuffer.Length; object cmdmsgs = ProtocolByt.ByteToStruct(pClient.readBuffer, typeof(MsgHead)); MsgHead head = (MsgHead)cmdmsgs; pClient.bufferCount -= Marshal.SizeOf(head); string msg = ""; if (pClient.bufferCount > 0) { msg = System.Text.Encoding.UTF8.GetString(pClient.readBuffer, Count - pClient.bufferCount, head.len); bufferCount = 0; } EDebug.LogFormat("Analysis {0} {1}", head.cmd_id, msg); ServerMsgObj serverMsgPair = new ServerMsgObj { MsgId = (int)head.cmd_id, SubId = (int)head.sub_id, Msg = msg }; _msgReceived.AddLast(serverMsgPair); } catch (Exception e) { EDebug.Log(e.ToString()); OnDisconnect(); //throw; } }
private void EGMI_ACK_CHAT(MsgHead head, MemoryStream stream) { AFMsg.ReqAckPlayerChat xReqAckChat = ReqAckPlayerChat.Parser.ParseFrom(stream);// new AFMsg.ReqAckPlayerChat(); //ReceiveMsg(stream, ref xReqAckChat); mxPlayerNet.aChatMsgList.Add(PBToAF(xReqAckChat.ChatId).ToString() + ":" + xReqAckChat.ChatInfo); }
/// <summary> /// 接收到消息 /// </summary> void OnReceive(byte[] bytes, int length) { memStream.Seek(0, SeekOrigin.End); memStream.Write(bytes, 0, length); //Reset to beginning memStream.Seek(0, SeekOrigin.Begin); while (RemainingBytes() >= ConstDefine.NF_PACKET_HEAD_SIZE) { object structType = new MsgHead(); byte[] headBytes = new byte[Marshal.SizeOf(structType)]; Int32 msgheeadlen = Marshal.SizeOf(structType); Array.Copy(reader.ReadBytes(msgheeadlen), 0, headBytes, 0, msgheeadlen); StructureTransform.ByteArrayToStructureEndian(headBytes, ref structType, 0); MsgHead head = (MsgHead)structType; int datalen = (int)head.unDataLen - ConstDefine.NF_PACKET_HEAD_SIZE; if (RemainingBytes() >= datalen) { MemoryStream ms = new MemoryStream(); BinaryWriter writer = new BinaryWriter(ms); writer.Write(datalen); writer.Write(reader.ReadBytes(datalen)); ms.Seek(0, SeekOrigin.Begin); OnReceivedMessage(head.unMsgID, ms); } } //Create a new stream with any leftover bytes byte[] leftover = reader.ReadBytes((int)RemainingBytes()); memStream.SetLength(0); //Clear memStream.Write(leftover, 0, leftover.Length); }
/// <summary> /// 注册和登录都走这里,根据AutoLoginOrRegister区分 /// </summary> public void Login() { if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_passWd)) { return; } EDebug.LogFormat("Login {0} {1} Login Or Regist {2}", _userName, _passWd, AutoLoginOrRegist); MsgHead head = new MsgHead { cmd_id = AutoLoginOrRegist ? (short)ServerMsgId.CCMD_ROLE_AUTH : (short)ServerMsgId.CCMD_ROLE_REG }; LoginMsg loginMsg = new LoginMsg { type = 0, name = _userName, passwd = _passWd }; string loginInfo = JsonUtility.ToJson(loginMsg); byte[] bMsg = System.Text.Encoding.UTF8.GetBytes(loginInfo); head.len = bMsg.Length; byte[] bHead = ProtocolByt.StructToBytes(head, 16); byte[] buffer = new byte[bHead.Length + bMsg.Length]; System.Array.Copy(bHead, buffer, bHead.Length); System.Array.Copy(bMsg, 0, buffer, bHead.Length, bMsg.Length); try { client.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, null, null); } catch (Exception e) { EDebug.LogErrorFormat("Client.Login Socket Exception {0}", e.ToString()); OnDisconnect(); } }
public void SendMsg(NFrame.NFGUID xID, NFMsg.EGameMsgID unMsgID, MemoryStream stream) { if (NFStart.Instance.bDebugMode) { return; } NFMsg.MsgBase xData = new NFMsg.MsgBase(); xData.player_id = NFToPB(xID); xData.msg_data = stream.ToArray(); MemoryStream body = new MemoryStream(); Serializer.Serialize <NFMsg.MsgBase>(body, xData); MsgHead head = new MsgHead(); head.unMsgID = (UInt16)unMsgID; 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); xNet.mxClient.SendBytes(sendBytes); string strTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; string strData = "S***:" + strTime + " MsgID:" + head.unMsgID + " Len:" + head.unDataLen; xNet.mxListener.aMsgList.Add(strData); }
int ConnectGateServer(Message _msg) { Debug.Log("connect gate server start"); GameManager.Instance.GamePause(); m_Net.DisConnect(); ServerInfo gateserver = ServerInfo.Parser.ParseFrom(_msg.m_data); if (m_Net.ConnectServer(gateserver.MIp, gateserver.MPort) < 0) { return(-1); } MsgHead msg_head = new MsgHead { m_usrid = _msg.m_usrid }; byte[] data = new byte[16]; msg_head.EnCode(data, 0); m_Net.Send(data, 16); UIManager.Instance.ClosePanel("LoginPanel"); UIManager.Instance.ShowPanel("PanelMain"); GameManager.Instance.GameStart(); Debug.Log("connect gate server end"); return(0); }
/// <summary> /// 请求战斗回复事件 /// </summary> /// <param name="headData"></param> private void MsgAskBattleResponseAction(MsgHead headData) { var msgAskBattleResponseData = (byte[])headData.body.Clone(); msgAskBattleResponseData = ReadMsg(msgAskBattleResponseData); // 反序列化战斗请求回复消息 var msgAskBattleResponse = SocketManager.DeSerialize <MsgAskBattleResponse>(msgAskBattleResponseData); // 读取数据准备战斗 // 匹配成功 // 设置唯一Id起始值 MsgFactory.UniqueIdStart = msgAskBattleResponse.UniqueIdStart; // 将数据放入全局 GlobalData.FightData.SetData(msgAskBattleResponse.BaseLevel, msgAskBattleResponse.TurretLevel, msgAskBattleResponse.Race, msgAskBattleResponse.EnemyBaseLevel, msgAskBattleResponse.EnemyTurretLevel, msgAskBattleResponse.EnemyRace, msgAskBattleResponse.MapId); // TODO Debug.Log("匹配成功."); }
/// <summary> /// 字符串消息事件 /// </summary> /// <param name="headData"></param> private void MsgStringAction(MsgHead headData) { var subData = (byte[])headData.body.Clone(); subData = ReadMsg(subData); // 字符串 Debug.Log("收到字符数据:" + Encoding.UTF8.GetString(subData)); }
public void RequireCreateRole(string strAccount, string strRoleName, int byCareer, int bySex, int nGameID) { if (strRoleName.Length >= 20 || strRoleName.Length < 1) { return; } NFMsg.ReqCreateRole xData = new NFMsg.ReqCreateRole(); xData.career = byCareer; xData.sex = bySex; xData.noob_name = UnicodeEncoding.Default.GetBytes(strRoleName); xData.account = UnicodeEncoding.Default.GetBytes(strAccount); xData.race = 0; xData.game_id = nGameID; MemoryStream stream = new MemoryStream(); Serializer.Serialize <NFMsg.ReqCreateRole>(stream, xData); SendMsg(new NFCoreEx.NFIDENTID(), NFMsg.EGameMsgID.EGMI_REQ_CREATE_ROLE, stream); if (NFStart.Instance.bDebugMode) { NFMsg.AckRoleLiteInfoList xAckBodyData = new NFMsg.AckRoleLiteInfoList(); NFMsg.RoleLiteInfo info = new NFMsg.RoleLiteInfo(); info.career = byCareer; info.sex = bySex; info.noob_name = xData.noob_name; info.race = xData.race; info.noob_name = xData.noob_name; info.id = new NFMsg.Ident(); info.game_id = 1; info.role_level = 1; info.view_record = xData.account = UnicodeEncoding.Default.GetBytes(""); info.delete_time = 1; info.reg_time = 1; info.last_offline_time = 1; info.last_offline_ip = 1; xAckBodyData.char_data.Add(info); MemoryStream xAckBodyStream = new MemoryStream(); Serializer.Serialize <NFMsg.AckRoleLiteInfoList>(xAckBodyStream, xAckBodyData); NFMsg.MsgBase xAckData = new NFMsg.MsgBase(); xAckData.player_id = info.id; xAckData.msg_data = xAckBodyStream.ToArray(); MemoryStream xAckAllStream = new MemoryStream(); Serializer.Serialize <NFMsg.MsgBase>(xAckAllStream, xAckData); MsgHead head = new MsgHead(); head.unMsgID = (UInt16)NFMsg.EGameMsgID.EGMI_ACK_ROLE_LIST; head.unDataLen = (UInt32)xAckAllStream.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE; xNet.mxBinMsgEvent.OnMessageEvent(head, xAckAllStream.ToArray()); } }
private void SendMsg(AFCoreEx.AFIDENTID xID, AFMsg.EGameMsgID unMsgID, MemoryStream stream) { MsgHead head = new MsgHead(); head.unMsgID = (UInt16)unMsgID; head.nHead64 = xID.nHead64; head.nData64 = xID.nData64; mxPlayerNet.mxNet.SendMsg(head, stream.ToArray()); }
//private IMessage ReceiveMsg2<TParser, TMessage>(MemoryStream stream, TParser xData) // where TMessage : IMessage<TMessage> // where TParser : MessageParser //{ // TMessage msg = xData.ParseFrom(stream) as TMessage; // return msg; //} private void EGMI_EVENT_RESULT(MsgHead head, MemoryStream stream) { //OnResultMsg AFMsg.AckEventResult xResultCode = new AFMsg.AckEventResult(); xResultCode = AFMsg.AckEventResult.Parser.ParseFrom(stream); //ReceiveMsg(stream, ref xResultCode); AFMsg.EGameEventCode eEvent = xResultCode.EventCode; mxPlayerNet.mxNet.DoResultCodeDelegation((int)eEvent); }
private void EGMI_ACK_OBJECT_LEAVE(MsgHead head, MemoryStream stream) { AFMsg.AckEntityLeaveList xData = new AFMsg.AckEntityLeaveList(); xData = AFMsg.AckEntityLeaveList.Parser.ParseFrom(stream); //ReceiveMsg(stream, ref xData); for (int i = 0; i < xData.EntityList.Count; ++i) { AFCKernel.Instance.DestroyObject(PBToAF(xData.EntityList[i])); } }
public Client() { readBuffer = new byte[MAX_BUFFER]; MsgHead keepaliveHead = new MsgHead { cmd_id = (int)ServerMsgId.CCMD_KEEP_ALIVE }; keepalive = ProtocolByt.StructToBytes(keepaliveHead, 16); ProcessCtrl.Instance.AddUpdate(this); }
private void EGMI_ACK_LOGIN(MsgHead head, MemoryStream stream) { AFMsg.AckEventResult xData = new AFMsg.AckEventResult(); xData = AFMsg.AckEventResult.Parser.ParseFrom(stream); //ReceiveMsg(stream, ref xData); if (EGameEventCode.EgecAccountSuccess == xData.EventCode) { mxPlayerNet.ChangePlayerState(PlayerNet.PLAYER_STATE.E_PLAYER_LOGIN_SUCCESSFUL); } }
/// <summary> /// 数据压入缓冲 /// </summary> private void PushReceivedData(MsgHead head) { if (head == null) { return; } lock (dataList) { dataList.Add(head); } }
public bool DoDelegation(int eMsg, MsgHead head, MemoryStream stream) { if (mhtMsgDelegation.ContainsKey(eMsg)) { MsgDelegation myDelegationHandler = (MsgDelegation)mhtMsgDelegation[eMsg]; myDelegationHandler(head, stream); return(true); } return(false); }
private void EGMI_ACK_ADD_ROW(MsgHead head, MemoryStream stream) { AFMsg.EntityDataTableAddRow recordData = ReceiveMsg(stream, EntityDataTableAddRow.Parser) as EntityDataTableAddRow; AFIObject go = AFCKernel.Instance.GetObject(PBToAF(recordData.EntityId)); AFIRecordManager recordManager = go.GetRecordManager(); for (int i = 0; i < recordData.RowData.Count; i++) { ADD_ROW(PBToAF(recordData.EntityId), recordData.TableName, recordData.RowData[i]); } }
private void EGMI_ACK_SWAP_ROW(MsgHead head, MemoryStream stream) { AFMsg.EntityDataTableSwap recordData = ReceiveMsg(stream, EntityDataTableSwap.Parser) as EntityDataTableSwap; AFIObject go = AFCKernel.Instance.GetObject(PBToAF(recordData.EntityId)); AFIRecordManager recordManager = go.GetRecordManager(); AFIRecord record = recordManager.GetRecord(recordData.OriginTableName); //目前认为在同一张表中交换吧 record.SwapRow(recordData.RowOrigin, recordData.RowTarget); }
/// <summary> /// 获取数据头消息 /// </summary> /// <param name="data"></param> /// <param name="dataLength"></param> /// <returns></returns> private MsgHead GetHead(byte[] data, int dataLength) { MsgHead result = null; using (var stream = new MemoryStream(ByteUtils.GetSubBytes(data, 0, dataLength))) { // 解析为类 result = ProtoBuf.Serializer.Deserialize <MsgHead>(stream); } return(result); }
/// <summary> /// 操作消息 /// </summary> /// <param name="headData"></param> private void MsgOptionalAction(MsgHead headData) { var opData = (byte[])headData.body.Clone(); opData = ReadMsg(opData); // 操作数据 var msgOp = SocketManager.DeSerialize <MsgOptional>(opData); Debug.Log("收到操作数据" + " opType:" + msgOp.OpType + "opPosX:" + msgOp.OpPosX + "opPosY:" + msgOp.OpPosY + ", opPosZ:" + msgOp.OpPosZ + ", opParams:" + msgOp.OpParams); // TODO 操作转化到本地行为 switch (msgOp.OpType) { case 1: // 唯一Id // 来自于对方的唯一ID 位移加标记 var opUniqueId = msgOp.OpUniqueNum; // 保存数据, 等待确认数据 PushBeComfirmData(msgOp); // 设置超时 var killTimer = new Timer(OperationTimeOut).OnCompleteCallback(() => { // 超时失败删除操作 opMsgBufferSend.Remove(opUniqueId); // 发送取消请求 Debug.LogError("操作超时,操作内容:" + opUniqueId + ", "); }).Start(); // 操作结束停止计时 opSendCallbackDic.Add(opUniqueId, () => { killTimer.Kill(); }); // TODO 如果是基地则不创建 var kvDic = GetParams(msgOp.OpParams); var sourceUserId = Convert.ToInt32(kvDic["UserId"]); // 创建确认发送消息 var cOpMsg = MsgFactory.GetMsgComfirmOperation(opUniqueId, sourceUserId, ""); var unitType = Convert.ToInt32(kvDic["UnitType"]); if (unitType != 1 && unitType != 2) { // 缓存发送确认操作 PushtBeSendData(cOpMsg, (int)MsgId.MsgComfirmOperation); } break; //couldDispatch = true; } }
/// <summary> /// 操作确认事件 /// </summary> /// <param name="headData"></param> private void MsgComfirmOperationAction(MsgHead headData) { var cOpData = (byte[])headData.body.Clone(); // 读取消息 cOpData = ReadMsg(cOpData); // 操作确认数据 var msgCmOp = SocketManager.DeSerialize <MsgComfirmOperation>(cOpData); // 激活本地下兵 // 获得本地缓存操作 ComfirmOp(msgCmOp); }
private void EGMI_ACK_CONNECT_WORLD(MsgHead head, MemoryStream stream) { mxPlayerNet.mxNet.Disconnect(); AFMsg.AckConnectWorldResult xData = new AFMsg.AckConnectWorldResult(); xData = AFMsg.AckConnectWorldResult.Parser.ParseFrom(stream); //ReceiveMsg(stream, ref xData); mxPlayerNet.strKey = xData.WorldKey; mxPlayerNet.strWorldIP = xData.WorldIp; mxPlayerNet.nWorldPort = xData.WorldPort; mxPlayerNet.ChangePlayerState(PlayerNet.PLAYER_STATE.E_PLAYER_GET_WORLD_KEY_SUCCESSFUL); }
/// <summary> /// 随机种子消息事件 /// </summary> /// <param name="headData"></param> private void MsgRandomSeedResponseAction(MsgHead headData) { var msgRandomSeedData = (byte[])headData.body.Clone(); msgRandomSeedData = ReadMsg(msgRandomSeedData); // 数据反序列化 var msgRandomSeed = SocketManager.DeSerialize <MsgRandomSeedRequest>(msgRandomSeedData); // 设置随机种子 RandomPacker.Single.SetSeed(msgRandomSeed.RandomSeed); // 输出log Debug.Log("收到随机种子消息:" + msgRandomSeed.RandomSeed); }
/// <summary> /// 创建数据头消息 /// </summary> /// <param name="userId"></param> /// <param name="msgId"></param> /// <param name="msgBody"></param> /// <returns></returns> public static MsgHead GetMsgHead(int userId, int msgId, byte[] msgBody) { MsgHead result = null; result = new MsgHead() { userId = userId, msgId = msgId, body = msgBody }; return(result); }
private void EGMI_ACK_REMOVE_ROW(MsgHead head, MemoryStream stream) { AFMsg.EntityDataTableRemove recordData = EntityDataTableRemove.Parser.ParseFrom(stream); //new AFMsg.ObjectRecordRemove(); // ReceiveMsg(stream, ref recordData); AFIObject go = AFCKernel.Instance.GetObject(PBToAF(recordData.EntityId)); AFIRecordManager recordManager = go.GetRecordManager(); AFIRecord record = recordManager.GetRecord(recordData.TableName); for (int i = 0; i < recordData.RemoveRow.Count; i++) { record.Remove(recordData.RemoveRow[i]); } }
void Start() { buf = new byte[50]; msg = new MsgHead(); m_opNew = GameManager.Instance.mainPlayer.m_protoInfo.Op; m_opOld = new Operation(); msg.setId(GameManager.Instance.mainPlayer.m_protoInfo.Id); msg.setType(EventType.UPDATE); m_opNew.H = 0; m_opNew.V = 0; m_opOld.H = 0; m_opOld.V = 0; }
/// <summary> /// 添加包头 /// </summary> /// <param name="type">package type</param> /// <param name="content">package content with byte array</param> /// <returns></returns> public static byte[] ContentAddHead(HeadType type, byte[] content) { MsgHead head = new MsgHead(); head.MsgType = (UInt32)IPAddress.HostToNetworkOrder((int)type); int contentLenght = content.Length; int size = Marshal.SizeOf(head); head.MsgLen = (UInt32)IPAddress.HostToNetworkOrder(contentLenght); byte[] bytes_head = new byte[size]; IntPtr buffer = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(head, buffer, false); Marshal.Copy(buffer, bytes_head, 0, size); Marshal.FreeHGlobal(buffer); byte[] package = new byte[content.Length + bytes_head.Length]; Array.Copy(bytes_head, 0, package, 0, bytes_head.Length); Array.Copy(content, 0, package, bytes_head.Length, content.Length); return package; }
public static byte[] ContentRemoveHead(byte[] content) { MsgHead head = new MsgHead(); int size = Marshal.SizeOf(head); byte[] dd = new byte[size]; Array.Copy(content, 0, dd, 0, dd.Length); IntPtr intPtr = Marshal.AllocHGlobal(dd.Length); try { Marshal.Copy(dd, 0, intPtr, dd.Length); head = (MsgHead)Marshal.PtrToStructure(intPtr, head.GetType()); } catch { } byte[] packet = new byte[IPAddress.NetworkToHostOrder((int)head.MsgLen)]; Array.Copy(content,size, packet, 0, packet.Length); return packet; }