コード例 #1
0
        private static async Task ConnectToMasterRouterAsync(IPAddress address, int port)
        {
            TcpClient routerClient = null;

            LogonServices.InteropConnectionManager.Connect(tcpClient => routerClient = tcpClient);

            var routingClient = new AERoutingClient(routerClient, LogonServices.InteropPacketHandler,
                                                    LogonServices.IncomingRoutingMiddlewareHandler,
                                                    LogonServices.OutgoingRoutingMiddlewareHandler,
                                                    LogonServices.ObjectRepository);

            var chbp = new ClientHandshakeBeginPacket
            {
                Protocol  = Constants.LatestAEProtocolVersion,
                Password  = "******",
                Component = new RoutingComponent
                {
                    Type = ComponentType.UniversalAuthServer
                }
            };

            await routingClient.SendDataAsync(chbp.FinalizePacket());

            await routingClient.ListenForDataTask();

            LogonServices.ObjectRepository.RemoveObject(routingClient.ClientGuid);
        }
コード例 #2
0
        private static async Task ConnectToMasterRouterAsync(IPAddress address, int port)
        {
            var client = new TcpClient();
            await client.ConnectAsync(address, port);

            var routingClient = new AERoutingClient(client, DatabaseServices.InteropPacketHandler,
                                                    DatabaseServices.IncomingRoutingMiddlewareHandler,
                                                    DatabaseServices.OutgoingRoutingMiddlewareHandler,
                                                    DatabaseServices.ObjectRepository);

            var chbp = new ClientHandshakeBeginPacket
            {
                Protocol  = Constants.LatestAEProtocolVersion,
                Password  = "******",
                Component = new RoutingComponent
                {
                    Type = ComponentType.DatabaseComponent
                }
            };

            await routingClient.SendDataAsync(chbp.FinalizePacket());

            await routingClient.ListenForDataTask();

            DatabaseServices.ObjectRepository.RemoveObject(routingClient.ClientGuid);
        }
コード例 #3
0
        /// <summary>
        ///     Default handler called when a ClientHandshakeBegin packet is received
        /// </summary>
        /// <param name="packet">Packet received</param>
        /// <param name="context">Context object</param>
        /// <returns>Task</returns>
        public static async Task ClientHandshakeBeginHandler(ClientHandshakeBeginPacket packet,
                                                             AERoutingClient context)
        {
            Console.WriteLine("Received AE# handshake");
            if (!ValidateHandshakeProtocol(packet))
            {
                throw new InvalidPacketException(
                          $"Received handshake with protocol version {packet.Protocol} but version {Constants.LatestAEProtocolVersion} is required");
            }

            var response = new ServerHandshakeResultPacket();

            if (!ValidateHandshakeAuthentication(packet))
            {
                Console.WriteLine(
                    $"Password does not match (expected: {Constants._TEMP_RouterAuthPassword}) (got: {packet.Password})");
                response.Result = ServerHandshakeResultPacket.SHRPResult.Failure;
                await context.SendDataAsync(response.FinalizePacket());

                context.Disconnect();

                return;
            }

            context.Authenticated = true;
            context.ComponentData = packet.Component;

            // Overwrite any existing guid - master router should dictate this
            context.ComponentData.Guid = Guid.NewGuid();

            Console.WriteLine($"Password matched, allocating guid: {context.ComponentData.Guid}");
            Console.WriteLine($"Got component of type {context.ComponentData.Type}");
            Console.WriteLine($"Component owns {context.ComponentData.OwnedObjects.Count} objects");

            response.Result                   = ServerHandshakeResultPacket.SHRPResult.Success;
            response.OurComponent             = context.ComponentData;
            response.OtherAvailableComponents = context.ObjectRepository.GetAllObjects();

            context.ObjectRepository.AddObject(context.ComponentData);

            await context.SendDataAsync(response.FinalizePacket());
        }
コード例 #4
0
        public static async Task HandleClientHandshakeBegin(ClientHandshakeBeginPacket packet,
                                                            AERoutingClient context)
        {
            //await HandshakeHandlers.ClientHandshakeBeginHandler( packet, context );

            if (!HandshakeHandlers.ValidateHandshakeProtocol(packet))
            {
                Console.WriteLine(
                    $"Invalid protocol (got: {packet.Protocol}) (exp: {Constants.LatestAEProtocolVersion})");
                context.Disconnect();
                return;
            }

            if (!HandshakeHandlers.ValidateHandshakeAuthentication(packet))
            {
                Console.WriteLine(
                    $"Authentication failure (got: {packet.Password}) (exp: {Constants._TEMP_RouterAuthPassword})");
                context.Disconnect();
                return;
            }

            context.Authenticated      = true;
            context.ComponentData      = packet.Component;
            context.ComponentData.Guid = Guid.NewGuid();

            Console.WriteLine($"Successfully authenticated {context.ComponentData.Guid}");

            var clients =
                MasterRouterServices.RemoteClients.GetClients(
                    item =>
                    SendToOtherComponentsPredicate(context,
                                                   item));

            var snoap = new ServerObjectAvailabilityChanged
            {
                RoutingObject = context.ComponentData,
                Available     = true
            };

            await context.SendPayloadToComponents(clients, snoap.PacketId, snoap.FinalizePacket().Payload);
        }
コード例 #5
0
 public static bool ValidateHandshakeAuthentication(ClientHandshakeBeginPacket packet)
 {
     return(packet.Password == Constants._TEMP_RouterAuthPassword);
 }
コード例 #6
0
 public static bool ValidateHandshakeProtocol(ClientHandshakeBeginPacket packet)
 {
     return(packet.Protocol == Constants.LatestAEProtocolVersion);
 }