Esempio n. 1
0
 public void DelSession(int iepHashCode)
 {
     if (dict.ContainsKey(iepHashCode))
     {
         UdpServerSession session = dict[iepHashCode];
         usedConvList.Remove(session.GetConv());
         freeConvQueue.Enqueue(session.GetConv());
         Log.InfoAf("[Udp] UdpServer Del UdpSession ServerId={0} IepHashCode={1}  Conv = {2}  RemoteIp ={3} RemotePort = {4}", serverId, session.GetIepHashCode(), session.GetConv(), session.GetRemoteIp(), session.GetRemotePort());
         dict.Remove(iepHashCode);
     }
 }
Esempio n. 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());
        }
Esempio n. 3
0
        private void ProcessServerKcpMsg(IUdpEvent evt)
        {
            int iepHashCode            = evt.GetIPEndPoint().GetHashCode();
            UdpServerReceiver receiver = evt.GetUdpReceiver() as UdpServerReceiver;

            if (receiver == null)
            {
                return;
            }

            UdpServerSession session = receiver.GetUdpSessionMgr().FindSession(iepHashCode);

            if (session == null)
            {
                Log.WarnAf("[Udp] UdpServerReceiver ServerId = {0} Conv = {1}", receiver.GetServerId(), evt.GetConv());
            }
            else if (evt.GetConv() == session.GetConv())
            {
                session.KcpInput(evt.GetMessage());
            }
        }
Esempio n. 4
0
        public UdpServerSession CreateSession(Socket sendSocket, IPEndPoint remoteIEP)
        {
            uint conv = PopFreeConv();

            if (conv == 0)
            {
                return(null);
            }

            usedConvList.Add(conv);
            UdpServerSession session = new UdpServerSession(serverId, conv, sendSocket, remoteIEP, handler, maxHeartBeatTime);

            dict[session.GetIepHashCode()] = session;
            Log.InfoAf("[Udp] UdpServer Add UdpSession ServerId={0} IepHashCode={1}  Conv = {2}  RemoteIp ={3} RemotePort = {4}", serverId, session.GetIepHashCode(), session.GetConv(), session.GetRemoteIp(), session.GetRemotePort());
            return(session);
        }