progress on improving responses
This commit is contained in:
@@ -264,6 +264,7 @@ namespace RH_Engine
|
|||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "route/add",
|
id = "route/add",
|
||||||
|
serial = "route",
|
||||||
data = new
|
data = new
|
||||||
{
|
{
|
||||||
nodes = new dynamic[]
|
nodes = new dynamic[]
|
||||||
@@ -354,7 +355,8 @@ namespace RH_Engine
|
|||||||
{
|
{
|
||||||
dynamic payload = new
|
dynamic payload = new
|
||||||
{
|
{
|
||||||
id = "scene/reset"
|
id = "scene/reset",
|
||||||
|
serial = "reset"
|
||||||
};
|
};
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(Payload(payload));
|
return JsonConvert.SerializeObject(Payload(payload));
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace RH_Engine
|
|||||||
public static string GetSerial(string json)
|
public static string GetSerial(string json)
|
||||||
{
|
{
|
||||||
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
||||||
return jsonData.serial;
|
return jsonData.data.data.serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetID(string json)
|
public static string GetID(string json)
|
||||||
@@ -73,7 +73,12 @@ namespace RH_Engine
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetRouteID(string json)
|
/// <summary>
|
||||||
|
/// method to get the uuid from requests for adding a node,route or road
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">the json response froo the server</param>
|
||||||
|
/// <returns>the uuid of the created object</returns>
|
||||||
|
public static string GetResponseUuid(string json)
|
||||||
{
|
{
|
||||||
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
dynamic jsonData = JsonConvert.DeserializeObject(json);
|
||||||
if (jsonData.data.status == "ok")
|
if (jsonData.data.status == "ok")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
@@ -13,6 +14,7 @@ using System.Threading;
|
|||||||
namespace RH_Engine
|
namespace RH_Engine
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public delegate void HandleSerial(string uuid);
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
private static PC[] PCs = {
|
private static PC[] PCs = {
|
||||||
@@ -28,13 +30,25 @@ namespace RH_Engine
|
|||||||
private static ServerResponseReader serverResponseReader;
|
private static ServerResponseReader serverResponseReader;
|
||||||
private static string sessionId = string.Empty;
|
private static string sessionId = string.Empty;
|
||||||
private static string tunnelId = string.Empty;
|
private static string tunnelId = string.Empty;
|
||||||
|
|
||||||
|
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
|
||||||
|
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
serialResponses.Add("route",handleRouteSerial);
|
||||||
|
|
||||||
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
||||||
|
|
||||||
CreateConnection(client.GetStream());
|
CreateConnection(client.GetStream());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleRouteSerial(string uuid)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static void initReader(NetworkStream stream)
|
private static void initReader(NetworkStream stream)
|
||||||
{
|
{
|
||||||
serverResponseReader = new ServerResponseReader(stream);
|
serverResponseReader = new ServerResponseReader(stream);
|
||||||
@@ -44,12 +58,11 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public static void HandleResponse(string message)
|
public static void HandleResponse(string message)
|
||||||
{
|
{
|
||||||
//Console.WriteLine("GOT MESSAGE FROM CALLBACK!!!!! " + message);
|
|
||||||
|
|
||||||
string id = JSONParser.GetID(message);
|
string id = JSONParser.GetID(message);
|
||||||
Console.WriteLine("got id : " + id);
|
|
||||||
|
|
||||||
// because the first messages don't have a serial, we need to check on the id
|
// because the first messages doesn't have a serial, we need to check on the id
|
||||||
|
|
||||||
if (id == "session/list")
|
if (id == "session/list")
|
||||||
{
|
{
|
||||||
sessionId = JSONParser.GetSessionID(message,PCs);
|
sessionId = JSONParser.GetSessionID(message,PCs);
|
||||||
@@ -62,6 +75,15 @@ namespace RH_Engine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.Contains("serial"))
|
||||||
|
{
|
||||||
|
string serial = JSONParser.GetSerial(message);
|
||||||
|
Console.WriteLine("Got serial " + serial);
|
||||||
|
serialResponses[serial].Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -82,35 +104,7 @@ namespace RH_Engine
|
|||||||
Console.WriteLine("sent message " + message);
|
Console.WriteLine("sent message " + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// reads a response from the server
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="stream">the network stream to use</param>
|
|
||||||
/// <returns>the returned message from the server</returns>
|
|
||||||
public static string ReadPrefMessage(NetworkStream stream)
|
|
||||||
{
|
|
||||||
byte[] lengthBytes = new byte[4];
|
|
||||||
|
|
||||||
stream.Read(lengthBytes, 0, 4);
|
|
||||||
Console.WriteLine("read message..");
|
|
||||||
|
|
||||||
int length = BitConverter.ToInt32(lengthBytes);
|
|
||||||
|
|
||||||
//Console.WriteLine("length is: " + length);
|
|
||||||
|
|
||||||
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);
|
|
||||||
totalRead += read;
|
|
||||||
//Console.WriteLine("ReadMessage: " + read);
|
|
||||||
} while (totalRead < length);
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString(buffer, 0, totalRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// connects to the server and creates the tunnel
|
/// connects to the server and creates the tunnel
|
||||||
@@ -132,7 +126,7 @@ namespace RH_Engine
|
|||||||
// wait until we have a tunnel id
|
// wait until we have a tunnel id
|
||||||
while (tunnelId == string.Empty) { }
|
while (tunnelId == string.Empty) { }
|
||||||
Console.WriteLine("got tunnel id! sending commands...");
|
Console.WriteLine("got tunnel id! sending commands...");
|
||||||
//sendCommands(stream, tunnelId);
|
sendCommands(stream, tunnelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -146,12 +140,10 @@ namespace RH_Engine
|
|||||||
|
|
||||||
|
|
||||||
WriteTextMessage(stream, mainCommand.ResetScene());
|
WriteTextMessage(stream, mainCommand.ResetScene());
|
||||||
ReadPrefMessage(stream);
|
|
||||||
string routeid = CreateRoute(stream, mainCommand);
|
string routeid = CreateRoute(stream, mainCommand);
|
||||||
|
|
||||||
WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
//WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
//string command;
|
||||||
string command;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -168,17 +160,17 @@ namespace RH_Engine
|
|||||||
//Console.WriteLine(ReadPrefMessage(stream));
|
//Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
|
||||||
|
|
||||||
command = mainCommand.addPanel();
|
//command = mainCommand.addPanel();
|
||||||
WriteTextMessage(stream, command);
|
//WriteTextMessage(stream, command);
|
||||||
string response = ReadPrefMessage(stream);
|
//string response = ReadPrefMessage(stream);
|
||||||
Console.WriteLine("add Panel response: \n\r" + response);
|
//Console.WriteLine("add Panel response: \n\r" + response);
|
||||||
string uuidPanel = JSONParser.getPanelID(response);
|
//string uuidPanel = JSONParser.getPanelID(response);
|
||||||
WriteTextMessage(stream, mainCommand.ClearPanel(uuidPanel));
|
//WriteTextMessage(stream, mainCommand.ClearPanel(uuidPanel));
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
//Console.WriteLine(ReadPrefMessage(stream));
|
||||||
WriteTextMessage(stream, mainCommand.bikeSpeed(uuidPanel));
|
//WriteTextMessage(stream, mainCommand.bikeSpeed(uuidPanel));
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
//Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
|
||||||
WriteTextMessage(stream, mainCommand.SwapPanelCommand(uuidPanel));
|
//WriteTextMessage(stream, mainCommand.SwapPanelCommand(uuidPanel));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -206,12 +198,14 @@ namespace RH_Engine
|
|||||||
|
|
||||||
public static string CreateRoute(NetworkStream stream, Command createGraphics)
|
public static string CreateRoute(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
|
//=============================================================================================================TODO change
|
||||||
WriteTextMessage(stream, createGraphics.RouteCommand());
|
WriteTextMessage(stream, createGraphics.RouteCommand());
|
||||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
//dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||||
if (response.data.data.id == "route/add")
|
//dynamic response = null;
|
||||||
{
|
//if (response.data.data.id == "route/add")
|
||||||
return response.data.data.data.uuid;
|
//{
|
||||||
}
|
// return response.data.data.data.uuid;
|
||||||
|
//}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -227,11 +221,12 @@ namespace RH_Engine
|
|||||||
x += 0.001f;
|
x += 0.001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=============================================================================================================TODO change
|
||||||
WriteTextMessage(stream, createGraphics.TerrainCommand(new int[] { 256, 256 }, height));
|
WriteTextMessage(stream, createGraphics.TerrainCommand(new int[] { 256, 256 }, height));
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
//Console.WriteLine(ReadPrefMessage(stream));
|
||||||
|
|
||||||
WriteTextMessage(stream, createGraphics.AddNodeCommand());
|
WriteTextMessage(stream, createGraphics.AddNodeCommand());
|
||||||
Console.WriteLine(ReadPrefMessage(stream));
|
//Console.WriteLine(ReadPrefMessage(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -243,8 +238,10 @@ namespace RH_Engine
|
|||||||
public static JArray GetChildren(NetworkStream stream, Command createGraphics)
|
public static JArray GetChildren(NetworkStream stream, Command createGraphics)
|
||||||
{
|
{
|
||||||
WriteTextMessage(stream, createGraphics.GetSceneInfoCommand());
|
WriteTextMessage(stream, createGraphics.GetSceneInfoCommand());
|
||||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
//dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||||
return response.data.data.data.children;
|
//return response.data.data.data.children;
|
||||||
|
//=============================================================================================================TODO change
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ namespace RH_Engine
|
|||||||
t.Start();
|
t.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// reads a response from the server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">the network stream to use</param>
|
||||||
|
/// <returns>the returned message from the server</returns>
|
||||||
public static string ReadPrefMessage(NetworkStream stream)
|
public static string ReadPrefMessage(NetworkStream stream)
|
||||||
{
|
{
|
||||||
byte[] lengthBytes = new byte[4];
|
byte[] lengthBytes = new byte[4];
|
||||||
|
|||||||
Reference in New Issue
Block a user