From cf3552a3aef2ef12e4c83c9a775393e5046b40ae Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 29 Nov 2023 02:18:48 +0100 Subject: [PATCH] Arg parsing --- OSCCollar/OSCCollar.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/OSCCollar/OSCCollar.cs b/OSCCollar/OSCCollar.cs index 8239d49..e17a5ba 100644 --- a/OSCCollar/OSCCollar.cs +++ b/OSCCollar/OSCCollar.cs @@ -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 "); + 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);