2015-05-12 16:48:58 -06:00
|
|
|
|
using System;
|
2015-05-12 17:30:56 -06:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Sockets;
|
2015-05-30 16:45:43 -06:00
|
|
|
|
using TrueCraft.Core;
|
2015-05-12 16:48:58 -06:00
|
|
|
|
|
2015-05-16 21:50:10 -06:00
|
|
|
|
namespace TrueCraft.Client
|
2015-05-12 16:48:58 -06:00
|
|
|
|
{
|
|
|
|
|
public static class Program
|
|
|
|
|
{
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main(string[] args)
|
|
|
|
|
{
|
2015-05-30 16:45:43 -06:00
|
|
|
|
var user = new TrueCraftUser { Username = args[1] };
|
|
|
|
|
var client = new MultiplayerClient(user);
|
2015-05-13 14:20:35 -06:00
|
|
|
|
var game = new TrueCraftGame(client, ParseEndPoint(args[0]));
|
2015-05-12 16:48:58 -06:00
|
|
|
|
game.Run();
|
2015-05-13 16:26:23 -06:00
|
|
|
|
client.Disconnect();
|
2015-05-12 16:48:58 -06:00
|
|
|
|
}
|
2015-05-12 17:30:56 -06:00
|
|
|
|
|
|
|
|
|
private static IPEndPoint ParseEndPoint(string arg)
|
|
|
|
|
{
|
|
|
|
|
IPAddress address;
|
|
|
|
|
int port;
|
|
|
|
|
if (arg.Contains(':'))
|
|
|
|
|
{
|
|
|
|
|
// Both IP and port are specified
|
|
|
|
|
var parts = arg.Split(':');
|
|
|
|
|
if (!IPAddress.TryParse(parts[0], out address))
|
|
|
|
|
address = Resolve(parts[0]);
|
|
|
|
|
return new IPEndPoint(address, int.Parse(parts[1]));
|
|
|
|
|
}
|
|
|
|
|
if (IPAddress.TryParse(arg, out address))
|
|
|
|
|
return new IPEndPoint(address, 25565);
|
|
|
|
|
if (int.TryParse(arg, out port))
|
|
|
|
|
return new IPEndPoint(IPAddress.Loopback, port);
|
|
|
|
|
return new IPEndPoint(Resolve(arg), 25565);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IPAddress Resolve(string arg)
|
|
|
|
|
{
|
|
|
|
|
return Dns.GetHostEntry(arg).AddressList.FirstOrDefault(item => item.AddressFamily == AddressFamily.InterNetwork);
|
|
|
|
|
}
|
2015-05-12 16:48:58 -06:00
|
|
|
|
}
|
|
|
|
|
}
|