diff --git a/RH-Engine/JSONParser.cs b/RH-Engine/JSONParser.cs index d42adb6..3f880fd 100644 --- a/RH-Engine/JSONParser.cs +++ b/RH-Engine/JSONParser.cs @@ -33,10 +33,11 @@ namespace RH_Engine Newtonsoft.Json.Linq.JArray data = jsonData.data; foreach (dynamic d in data) { - foreach(PC pc in PCs) + foreach (PC pc in PCs) { if (d.clientinfo.host == pc.host && d.clientinfo.user == pc.user) { + Console.WriteLine("connecting to {0}, on {1} with id {2}", pc.user, pc.host, d.id); return d.id; } } @@ -45,6 +46,16 @@ namespace RH_Engine return null; } + public static string GetTunnelID(string json) + { + dynamic jsonData = JsonConvert.DeserializeObject(json); + if (jsonData.data.status == "ok") + { + return jsonData.data.id; + } + return null; + } + } } diff --git a/RH-Engine/Program.cs b/RH-Engine/Program.cs index 89d5beb..6f9e1ae 100644 --- a/RH-Engine/Program.cs +++ b/RH-Engine/Program.cs @@ -10,7 +10,7 @@ namespace RH_Engine internal class Program { private static PC[] PCs = { - new PC("DESKTOP-M2CIH87", "Fabian"), + new PC("DESKTOP-M2CIH87", "F@bian"), new PC("T470S", "Shinichi"), new PC("NA", "Sem"), new PC("NA", "Wouter"), @@ -34,7 +34,7 @@ namespace RH_Engine stream.Write(res); - Console.WriteLine("sent message " + message); + //Console.WriteLine("sent message " + message); } public static string ReadPrefMessage(NetworkStream stream) @@ -50,7 +50,6 @@ namespace RH_Engine byte[] buffer = new byte[length]; int totalRead = 0; - //read bytes until stream indicates there are no more do { int read = stream.Read(buffer, totalRead, buffer.Length - totalRead); @@ -63,16 +62,26 @@ namespace RH_Engine private static void CreateConnection(NetworkStream stream) { - //WriteTextMessage(stream, "{\r\n\"id\" : \"session/list\"\r\n}"); - //string msg = ReadPrefMessage(stream); - //Console.WriteLine(msg); - //string id = JSONParser.GetSessionID(msg, PCs); - - //Console.WriteLine(id); WriteTextMessage(stream, "{\r\n\"id\" : \"session/list\"\r\n}"); - string result = ReadPrefMessage(stream); - Console.WriteLine(result); - //JSONParser.Parse(result); + string id = JSONParser.GetSessionID(ReadPrefMessage(stream), PCs); + + string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + id + "\"}}"; + + WriteTextMessage(stream, tunnelCreate); + + string tunnelResponse = ReadPrefMessage(stream); + + Console.WriteLine(tunnelResponse); + + string tunnelID = JSONParser.GetTunnelID(tunnelResponse); + Console.WriteLine("tunnelID is: " + tunnelID); + + string sceneReset = "{\"id\" : \"tunnel/send\", \"data\" : {\"dest\" : \"" + tunnelID + "\",\"data\" :{\"id\" : \"scene/reset\",\"data\" : { }}}}}"; + //string sceneReset = "{\"id\" : \"scene/reset\"}"; + + WriteTextMessage(stream, sceneReset); + + Console.WriteLine(ReadPrefMessage(stream)); } } @@ -87,4 +96,5 @@ namespace RH_Engine public string host { get; } public string user { get; } } -} \ No newline at end of file +} +