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); }
public void SendMsg(NFrame.NFGUID xID, NFMsg.EGameMsgID unMsgID, MemoryStream stream) { mxData.player_id = NFNetController.NFToPB(xID); mxData.msg_data = stream.ToArray(); mxBody.SetLength(0); mxSerializer.Serialize(mxBody, mxData); mxHead.unMsgID = (UInt16)unMsgID; mxHead.unDataLen = (UInt32)mxBody.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE; byte[] bodyByte = mxBody.ToArray(); byte[] headByte = mxHead.EnCode(); byte[] sendBytes = new byte[mxHead.unDataLen]; headByte.CopyTo(sendBytes, 0); bodyByte.CopyTo(sendBytes, headByte.Length); mxNetController.mxNetClient.SendBytes(sendBytes); ///////////////////////////////////////////////////////////////// NFLog.Instance.Log(NFLog.LOG_LEVEL.INFO, "SendMsg:" + unMsgID); }
public bool DoDelegation(NFMsg.EGameMsgID eMsg, MsgHead head, MemoryStream stream) { if (mhtMsgDelegation.ContainsKey(eMsg)) { MsgDelegation myDelegationHandler = (MsgDelegation)mhtMsgDelegation[eMsg]; myDelegationHandler(head, stream); return(true); } return(false); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public bool RegisteredDelegation(NFMsg.EGameMsgID eMsg, MsgDelegation msgDelegate) { if (!mhtMsgDelegation.ContainsKey(eMsg)) { MsgDelegation myDelegationHandler = new MsgDelegation(msgDelegate); mhtMsgDelegation.Add(eMsg, myDelegationHandler); } else { MsgDelegation myDelegationHandler = (MsgDelegation)mhtMsgDelegation[eMsg]; myDelegationHandler += new MsgDelegation(msgDelegate); } return(true); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void OnMessageEvent(MsgHead head, byte[] bytes) { if (head.unDataLen != bytes.Length + ConstDefine.NF_PACKET_HEAD_SIZE) { return; } NFMsg.EGameMsgID eMsg = (NFMsg.EGameMsgID)head.unMsgID; string strTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second; string strData = "R:" + strTime + " MsgID:" + head.unMsgID + " Len:" + head.unDataLen; net.mxListener.aMsgList.Add(strData); DoDelegation(eMsg, head, new MemoryStream(bytes)); }