Exemple #1
0
        private static async void AcceptAEClientAsync(TcpClient rawClient)
        {
            Console.WriteLine("Accepting AEClient");
            var client = new AERoutingClient(rawClient, MasterRouterServices.PacketHandler,
                                             MasterRouterServices.IncomingMiddlewareHandler,
                                             MasterRouterServices.OutgoingMiddlewareHandler,
                                             MasterRouterServices.ObjectRepository);

            try
            {
                await client.ListenForDataTask();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unhandled exception in {nameof(AcceptAEClientAsync)}: {ex}");
            }
            finally
            {
                if (client.ClientGuid != Guid.Empty)
                {
                    MasterRouterServices.ObjectRepository.RemoveObject(client.ClientGuid);
                    MasterRouterServices.RemoteClients.RemoveClient(client.ClientGuid);
                }
            }

            client.Disconnect();
        }
Exemple #2
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);
        }
        public static async Task ServerHandshakeResultHandler(ServerHandshakeResultPacket packet,
                                                              AERoutingClient context)
        {
            Console.WriteLine("Received AE# handshake result");
            if (packet.Result == ServerHandshakeResultPacket.SHRPResult.Failure)
            {
                Console.WriteLine($"Failed to authenticate with master router (reason: generic failure)");
                context.Disconnect();
                return;
            }

            if (packet.Result == ServerHandshakeResultPacket.SHRPResult.Success)
            {
                // Authenticated
                context.ComponentData = packet.OurComponent;

                foreach (var component in packet.OtherAvailableComponents)
                {
                    context.ObjectRepository.AddObject(component);
                }

                context.Authenticated = true;
                Console.WriteLine($"Authenticated successfully, we have guid: {context.ClientGuid}");

                context.ObjectRepository.AddObject(context.ComponentData);
            }
        }
Exemple #4
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);
        }
Exemple #5
0
 public static async Task HandleServerNewObjectAvailable(ServerObjectAvailabilityChanged packet,
                                                         AERoutingClient context)
 {
     if (packet.Available)
     {
         context.ObjectRepository.AddObject(packet.RoutingObject);
     }
     else
     {
         context.ObjectRepository.RemoveObject(packet.RoutingObject.Guid);
     }
 }
        /// <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());
        }
Exemple #7
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);
        }
Exemple #8
0
 private static bool SendToOtherComponentsPredicate(AERoutingClient context, AERoutingClient item)
 {
     // Only send if it's a real component (i.e. not a player etc)
     return(item.ComponentData.IsRealComponent);
 }