Merge branch 'plz-help-fix' into develop

This commit is contained in:
shinichi
2020-09-16 13:39:42 +02:00
2 changed files with 43 additions and 13 deletions

View File

@@ -27,6 +27,24 @@ namespace RH_Engine
} }
public static string GetSessionID(string msg, PC[] PCs)
{
dynamic jsonData = JsonConvert.DeserializeObject(msg);
Newtonsoft.Json.Linq.JArray data = jsonData.data;
foreach (dynamic d in data)
{
foreach(PC pc in PCs)
{
if (d.clientinfo.host == pc.host && d.clientinfo.user == pc.user)
{
return d.id;
}
}
}
return null;
}
} }
} }

View File

@@ -9,7 +9,7 @@ namespace RH_Engine
internal class Program internal class Program
{ {
private static PC[] PCs = { private static PC[] PCs = {
new PC("DESKTOP-M2CIH87", "Fabian"), new PC("DESKTOP-M2CIH87", "Fabian"),
new PC("T470S", "Shinichi"), new PC("T470S", "Shinichi"),
new PC("NA", "Sem"), new PC("NA", "Sem"),
@@ -20,13 +20,11 @@ namespace RH_Engine
{ {
TcpClient client = new TcpClient("145.48.6.10", 6666); TcpClient client = new TcpClient("145.48.6.10", 6666);
WriteTextMessage(client, "{\r\n\"id\" : \"session/list\"\r\n}"); CreateConnection(client.GetStream());
string result = ReadPrefMessage(client.GetStream());
JSONParser.Parse(result);
} }
public static void WriteTextMessage(TcpClient client, string message) public static void WriteTextMessage(NetworkStream stream, string message)
{ {
byte[] msg = Encoding.ASCII.GetBytes(message); byte[] msg = Encoding.ASCII.GetBytes(message);
byte[] res = new byte[msg.Length + 4]; byte[] res = new byte[msg.Length + 4];
@@ -34,7 +32,7 @@ namespace RH_Engine
Array.Copy(BitConverter.GetBytes(msg.Length), 0, res, 0, 4); Array.Copy(BitConverter.GetBytes(msg.Length), 0, res, 0, 4);
Array.Copy(msg, 0, res, 4, msg.Length); Array.Copy(msg, 0, res, 4, msg.Length);
client.GetStream().Write(res); stream.Write(res);
Console.WriteLine("sent message " + message); Console.WriteLine("sent message " + message);
} }
@@ -47,20 +45,34 @@ namespace RH_Engine
int length = BitConverter.ToInt32(lengthBytes); int length = BitConverter.ToInt32(lengthBytes);
Console.WriteLine("length is: " + length);
byte[] buffer = new byte[length]; byte[] buffer = new byte[length];
int totalRead = 0; int totalRead = 0;
int read = stream.Read(buffer, totalRead, buffer.Length - totalRead); //read bytes until stream indicates there are no more
totalRead += read; do
//Console.WriteLine("ReadMessage: " + read); {
//Console.WriteLine(Encoding.UTF8.GetString(buffer)); int read = stream.Read(buffer, totalRead, buffer.Length - totalRead);
totalRead += read;
Console.WriteLine("ReadMessage: " + read);
} while (totalRead < length);
return Encoding.UTF8.GetString(buffer); return Encoding.UTF8.GetString(buffer, 0, totalRead);
} }
private static void CreateTunnel() 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);
} }
} }