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); }
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); }
/// <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()); }