private static void Main(string[] args) { // TODO: Arguments! Console.Title = "Xbox Live Machine Account Creation Server"; Resources.Start(); XServer server = new XServer(); server.Start(); Thread.Sleep(-1); //while (true) //{ // IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 88); // byte[] data = udpServer.Receive(ref remoteEP); // Console.WriteLine("Received " + data.Length + " bytes from " + remoteEP); // Console.WriteLine("Data: " + BitConverter.ToString(data).Replace("-", "")); // // First Request is AS_REQ // data = AsnIO.FindBER(data); // AsnElt AS_REQ = AsnElt.Decode(data); // AsnElt[] KDC_REQ = AS_REQ.Sub[0].Sub; // foreach (AsnElt s in KDC_REQ) // { // switch (s.TagValue) // { // case 1: // Console.WriteLine("PVNO: " + s.Sub[0].GetInteger()); // break; // case 2: // Console.WriteLine("MSG TYPE: " + s.Sub[0].GetInteger()); // break; // case 3: // Console.WriteLine("PA DATA"); // foreach (AsnElt pa in s.Sub[0].Sub) // { // Console.WriteLine(pa); // } // break; // case 4: // // break; // default: // throw new Exception("Invalid tag AS_REQ value: " + s.TagValue); // break; // } // } //} }
/// <summary> /// Starts listening for client connections on the specified network interface and port /// </summary> /// <param name="ipAddress">The IP address on which to bind and listen for clients</param> /// <param name="port">The port on which to listen. Must be a positive value.</param> public void Start(IPAddress ipAddress, int port) { if (port <= 0) { throw new ArgumentOutOfRangeException(nameof(port)); } Stop(); _mreIsListening = new ManualResetEventSlim(false); _host = new XServer <XClient <Message> >(); _host.IsListeningChanged += (isListening) => { IsListeningChanged?.Invoke(isListening); _mreIsListening?.Set(); }; _host.ClientConnected += (client) => { client.Socket.UseCompression = true; //Log.i("Client Connected: {0}", client.Name); client.Disconnected += (c, remoteEndPoint, exception) => { //var name = (c as GenericClient<Message>)?.Socket.Name ?? "Unknown"; Log.i($"Client Disconnected: {remoteEndPoint.ToString()}"); }; client.MessageReceived += (c, message) => { try { //call the appropriate RPC method OnMessageReceived(ref message); try { //Put this in a task to multi-thread the encryption and compression //Task.Run(() => //{ //send the result back to the client c.SerializationSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; c.SerializationSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; c.Send(message); //}); } catch (Exception e) { Log.e(e); } } catch (Exception e) { Log.e(e); } }; }; _host.Start(ipAddress, port); }