示例#1
0
        public UdpServerReceiver(UInt64 _serverId, UdpVerfiyReqDele _dele, uint _convCapacity, IUdpMsgHandler _handler, long _maxHeartBeatTime)
        {
            serverId   = _serverId;
            verifyDele = _dele;
            sessionMgr = new UdpServerSessionMgr(_serverId, _convCapacity, _handler, _maxHeartBeatTime);

            kcpVerifyReqBytes    = System.Text.Encoding.Default.GetBytes(KcpDef.KcpVerifyReq);
            kcpVerifyReqTotalLen = kcpVerifyReqBytes.Length + KcpDef.KcpVerifyTokenLen;
        }
示例#2
0
        private void ProcessVerifyReqMsg(IUdpEvent evt)
        {
            UdpServerReceiver serverReceiver = evt.GetUdpReceiver() as UdpServerReceiver;

            if (serverReceiver == null)
            {
                return;
            }

            int iepHashCode         = evt.GetIPEndPoint().GetHashCode();
            UdpServerSessionMgr mgr = serverReceiver.GetUdpSessionMgr();

            UdpServerSession session = mgr.FindSession(iepHashCode);

            if (session == null)
            {
                session = mgr.CreateSession(serverReceiver.GetSocket(), evt.GetIPEndPoint());
            }
            else
            {
                if (!session.IsRepeatedVerify(iepHashCode))
                {
                    mgr.DelSession(iepHashCode);
                    session = mgr.CreateSession(serverReceiver.GetSocket(), evt.GetIPEndPoint());
                }
            }

            if (session == null)
            {
                Log.ErrorAf("[Udp] Verify Ok And Create Session Error");
                return;
            }

            byte[]       resKey       = System.Text.Encoding.Default.GetBytes(KcpDef.KcpVerifyRes);
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter writer       = new BinaryWriter(memoryStream);

            writer.Write(resKey);
            writer.Write(session.GetConv());
            serverReceiver.GetUdpSender().SendUdpMsg(serverReceiver.GetSocket(), evt.GetIPEndPoint(), memoryStream.ToArray());
        }