From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/CNetSender.cs | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/CNetSender.cs (limited to 'Client/Assets/Scripts/XMainClient/CNetSender.cs') diff --git a/Client/Assets/Scripts/XMainClient/CNetSender.cs b/Client/Assets/Scripts/XMainClient/CNetSender.cs new file mode 100644 index 00000000..3f53cd71 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/CNetSender.cs @@ -0,0 +1,93 @@ +using System; +using System.IO; +using XUtliPoolLib; + +namespace XMainClient +{ + public class CNetSender : INetSender, ILuaNetSender + { + private CNetwork m_oNetwork; + + private MemoryStream m_oSendStream; + + public CNetSender(CNetwork network) + { + this.m_oNetwork = network; + this.m_oSendStream = new MemoryStream(); + } + + public bool Send(Protocol protocol) + { + this.m_oSendStream.SetLength(0L); + this.m_oSendStream.Position = 0L; + protocol.SerializeWithHead(this.m_oSendStream); + bool flag = XSingleton.singleton.EnableRecord(); + if (flag) + { + XSingleton.singleton.AddPoint(protocol.GetProtoType(), protocol.GetType().Name, (float)this.m_oSendStream.Length, 1, XDebug.RecordChannel.ENetwork); + } + bool flag2 = this.m_oSendStream.Length > 1024L; + if (flag2) + { + XSingleton.singleton.AddWarningLog2("Send Ptc:{0} to long:{1}b", new object[] + { + protocol.GetProtoType(), + this.m_oSendStream.Length + }); + } + return this.m_oNetwork.Send(this.m_oSendStream.GetBuffer(), 0, (int)this.m_oSendStream.Length); + } + + public bool Send(uint _type, bool isRpc, uint tagID, byte[] _reqBuff) + { + this.m_oSendStream.SetLength(0L); + this.m_oSendStream.Position = 0L; + long num = 0L; + ProtocolHead sharedHead = ProtocolHead.SharedHead; + sharedHead.Reset(); + sharedHead.tagID = tagID; + sharedHead.type = _type; + sharedHead.flag = (isRpc ? 3u : 0u); + sharedHead.Serialize(this.m_oSendStream); + this.m_oSendStream.Write(_reqBuff, 0, _reqBuff.Length); + long position = this.m_oSendStream.Position; + uint value = (uint)(position - num - 4L); + this.m_oSendStream.Position = num; + this.m_oSendStream.Write(BitConverter.GetBytes(value), 0, 4); + this.m_oSendStream.Position = position; + byte[] buffer = this.m_oSendStream.GetBuffer(); + int num2 = (int)this.m_oSendStream.Length; + return this.m_oNetwork.Send(this.m_oSendStream.GetBuffer(), 0, (int)this.m_oSendStream.Length); + } + + public bool Send(Rpc rpc) + { + rpc.SocketID = this.m_oNetwork.GetSocketID(); + rpc.BeforeSend(); + this.m_oSendStream.SetLength(0L); + this.m_oSendStream.Position = 0L; + rpc.SerializeWithHead(this.m_oSendStream); + bool flag = XSingleton.singleton.EnableRecord(); + if (flag) + { + XSingleton.singleton.AddPoint(rpc.GetRpcType(), rpc.GetType().Name, (float)this.m_oSendStream.Length, 1, XDebug.RecordChannel.ENetwork); + } + bool flag2 = this.m_oSendStream.Length > 1024L; + if (flag2) + { + XSingleton.singleton.AddWarningLog2("Send Rpc:{0} to long:{1}b", new object[] + { + rpc.GetRpcType(), + this.m_oSendStream.Length + }); + } + bool flag3 = this.m_oNetwork.Send(this.m_oSendStream.GetBuffer(), 0, (int)this.m_oSendStream.Length); + bool flag4 = flag3; + if (flag4) + { + rpc.AfterSend(); + } + return flag3; + } + } +} -- cgit v1.1-26-g67d0