private bool IsHandshake(byte[] buffer, int offset, int size, out uint index, out uint key) { if (HandshakeUtility.IsHandshakeDataRight(buffer, offset, size, out index, out key)) { return(IsClientKeyCorrect(index, (int)key)); } else { return(false); } }
void process_recv_queue() { m_RecvQueue.Switch(); while (!m_RecvQueue.Empty()) { if (m_Kcp == null) {//退出 return; } var buf = m_RecvQueue.Pop(); if (this.Status == ClientSessionStatus.InConnect) { //服务端将返回和握手请求相同的响应数据 uint _index = 0, _key = 0; if (HandshakeUtility.IsHandshakeDataRight(buf, 0, buf.Length, out _index, out _key)) { if (_index == m_NetIndex && _key == m_Key) { #if DEBUG Console.WriteLine("连接握手成功"); #endif this.Status = ClientSessionStatus.Connected; var e = Event; if (e != null) { m_LastSendTimestamp = UnityEngine.Time.time; m_LastRecvTimestamp = UnityEngine.Time.time; e(UdpClientEvents.Connected, null); } continue; } } } m_Kcp.Input(buf); m_NeedUpdateFlag = true; for (var size = m_Kcp.PeekSize(); size > 0; size = m_Kcp.PeekSize()) { var buffer = new byte[size]; if (m_Kcp.Recv(buffer) > 0) { m_LastRecvTimestamp = UnityEngine.Time.time; var e = Event; if (e != null) { e(UdpClientEvents.Recv, buffer); } } } } }