public void DealMsg(ReceiveMsgData _data) { if (_data == null) { return; } byte[] _dataBytes = _data.receiveBytes; IPEndPoint receivePoint = _data.receivePoint; ByteBuffer _buff = new ByteBuffer(_dataBytes); int length = _buff.ReadInt32(); //真实长度 byte[] _bytes = _buff.ReadBytes(length); MessageData data = ProtoBufTools.DeSerialize <MessageData>(_bytes); data.receivePoint = receivePoint; DealMsgSwitch(data); }
public static void SendMsg(int cmd, int scmd, ByteBuffer buffer) { MessageData sendMsg = new MessageData(); HeadMsg head = new HeadMsg(); head.cmd = cmd; head.scmd = scmd; sendMsg.head = head; sendMsg.data = buffer.ToBytes(); byte[] bytes = ProtoBufTools.Serialize(sendMsg); ByteBuffer sendBuffer = new ByteBuffer(); sendBuffer.WriteInt32(bytes.Length); sendBuffer.WriteBytes(bytes); bytes = sendBuffer.ToBytes(); socket.Send(bytes); }
public void DealMsg(MessageReceiveData _data) { if (_data == null) { return; } byte[] _dataBytes = _data.receiveBytes; IPEndPoint receivePoint = _data.receivePoint; ByteBuffer _buff = new ByteBuffer(_dataBytes); int length = _buff.ReadInt32(); byte[] _bytes = _buff.ReadBytes(length); MessageData <BaseMessageData> data = ProtoBufTools.DeSerialize <MessageData <BaseMessageData> > (_bytes); if (data.body.dealFlg == 0) { if (Main.Self.clientType == ClientType.server) { if (data.head.cmd == 1 && data.head.scmd == 1) { Main.Self.server.AddPlayer(receivePoint); } else if (data.head.cmd == 1 && data.head.scmd == 2) { Main.Self.server.RemovePlayer(receivePoint); } byte[] _serverDealBytes = ServerDealMsg(data, receivePoint); ByteBuffer _serverDealBuff = new ByteBuffer(); _serverDealBuff.WriteInt32(_serverDealBytes.Length); _serverDealBuff.WriteBytes(_serverDealBytes); Main.Self.server.AddSendQueue(_serverDealBuff.ToBytes()); } } else { if (Main.Self.clientType == ClientType.server) { } else { } SwitchMsg(data); } }