コード例 #1
0
ファイル: UDPServer.cs プロジェクト: buraktaban0/RUDP
        private void OnConnectionRequestReceived(Packet packet)
        {
            Monitor.Enter(clients);

            IPEndPoint remoteEP = Address.DuplicateEndPoint(packet.IPEndPoint);
            int        id       = clients.GetFirstAvailableId();

            if (id < 0 || clients.ContainsEndPoint(remoteEP))
            {
                Packet rejectedPacket = PacketFactory.GetConnectionRejected();
                trafficHandler.SendReliable(rejectedPacket, remoteEP);
            }

            ushort serverKey = Utility.GetRandomUShort();

            UDPClientHandler client =
                new UDPClientHandler(id, serverKey, packet.Key, remoteEP, this, trafficHandler);

            clients.AddTo(client, id);

            Monitor.Exit(clients);

            Packet challengePacket = PacketFactory.GetChallenge(id, serverKey);

            trafficHandler.SendReliable(challengePacket, remoteEP);
        }