Arg parsing

This commit is contained in:
glax 2023-11-29 02:18:48 +01:00
parent e99974e754
commit cf3552a3ae

View File

@ -1,4 +1,5 @@
using BuildSoft.OscCore;
using System.Net;
using BuildSoft.OscCore;
namespace VRC_Console;
@ -7,7 +8,20 @@ public class OSCCollar
public static void Main(string[] args)
{
OSCCollar collar = new OSCCollar();
OSCCollar collar;
if (args.Length == 3)
{
string ip = args[0];
if(!IPAddress.TryParse(args[0], out IPAddress? test) ||
!int.TryParse(args[1], out var portReceive) ||
!int.TryParse(args[2], out var portSend))
{
Console.WriteLine("Invalid parameter.\n\rParameters <ip> <receivePort> <sendPort>");
return;
}
collar = new OSCCollar(ip, portReceive, portSend);
}else
collar = new OSCCollar();
}
private OscServer Server { get; init; }
@ -24,10 +38,10 @@ public class OSCCollar
private static readonly TimeSpan UpdateFieldsTimeout = TimeSpan.FromMilliseconds(1);
private static readonly TimeSpan NilMessageMaxTimeout = TimeSpan.FromMilliseconds(400);
private OSCCollar()
private OSCCollar(string ip = "127.0.0.1", int portReceive = 9001, int portSend = 9000)
{
this.Server = new OscServer(9001);
this.Client = new OscClient("127.0.0.1", 9000);
this.Server = new OscServer(portReceive);
this.Client = new OscClient(ip, portSend);
this._collarAngle = 0;
this._collarStretch = 0;
Server.TryAddMethod("/avatar/parameters/Collar_Angle", CollarAngleHandle);