cleanup files

This commit is contained in:
Sem van der Hoeven
2020-09-25 15:56:26 +02:00
parent aa5f58e752
commit 13d99eb107
4 changed files with 33 additions and 75 deletions

View File

@@ -1,14 +1,10 @@
using LibNoise.Primitive; using LibNoise.Primitive;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
namespace RH_Engine namespace RH_Engine
{ {
class Command internal class Command
{ {
public const string STANDARD_HEAD = "Head"; public const string STANDARD_HEAD = "Head";
public const string STANDARD_GROUND = "GroundPlane"; public const string STANDARD_GROUND = "GroundPlane";
@@ -16,9 +12,7 @@ namespace RH_Engine
public const string STANDARD_LEFTHAND = "LeftHand"; public const string STANDARD_LEFTHAND = "LeftHand";
public const string STANDARD_RIGHTHAND = "RightHand"; public const string STANDARD_RIGHTHAND = "RightHand";
private string tunnelID;
string tunnelID;
public Command(string tunnelID) public Command(string tunnelID)
{ {
@@ -35,10 +29,10 @@ namespace RH_Engine
size = sizeArray, size = sizeArray,
heights = heightsArray heights = heightsArray
} }
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
public string AddLayer(string uid, string texture) public string AddLayer(string uid, string texture)
{ {
dynamic payload = new dynamic payload = new
@@ -56,6 +50,7 @@ namespace RH_Engine
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
public string UpdateTerrain() public string UpdateTerrain()
{ {
dynamic payload = new dynamic payload = new
@@ -63,7 +58,6 @@ namespace RH_Engine
id = "scene/terrain/update", id = "scene/terrain/update",
data = new data = new
{ {
} }
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
@@ -91,19 +85,15 @@ namespace RH_Engine
public string DeleteNode(string uuid) public string DeleteNode(string uuid)
{ {
dynamic payload = new dynamic payload = new
{ {
id = "scene/node/delete", id = "scene/node/delete",
data = new data = new
{ {
id = uuid, id = uuid,
} }
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
public string addPanel(string serialToSend) public string addPanel(string serialToSend)
@@ -123,7 +113,6 @@ namespace RH_Engine
resolution = new int[] { 512, 512 }, resolution = new int[] { 512, 512 },
background = new int[] { 1, 0, 0, 0 }, background = new int[] { 1, 0, 0, 0 },
castShadow = false castShadow = false
} }
} }
} }
@@ -210,20 +199,20 @@ namespace RH_Engine
public string AddBikeModel() public string AddBikeModel()
{ {
return AddModel("bike","addbike", "data\\NetworkEngine\\models\\bike\\bike.fbx"); return AddModel("bike", "addbike", "data\\NetworkEngine\\models\\bike\\bike.fbx");
} }
public string AddModel(string nodeName,string serial, string fileLocation) public string AddModel(string nodeName, string serial, string fileLocation)
{ {
return AddModel(nodeName,serial, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 }); return AddModel(nodeName, serial, fileLocation, null, new float[] { 0, 0, 0 }, 1, new float[] { 0, 0, 0 });
} }
public string AddModel(string nodeName,string serial, string fileLocation, float[] positionVector, float scalar, float[] rotationVector) public string AddModel(string nodeName, string serial, string fileLocation, float[] positionVector, float scalar, float[] rotationVector)
{ {
return AddModel(nodeName,serial, fileLocation, null, positionVector, scalar, rotationVector); return AddModel(nodeName, serial, fileLocation, null, positionVector, scalar, rotationVector);
} }
public string AddModel(string nodeName,string serialToSend, string fileLocation, string animationLocation, float[] positionVector, float scalar, float[] rotationVector) public string AddModel(string nodeName, string serialToSend, string fileLocation, string animationLocation, float[] positionVector, float scalar, float[] rotationVector)
{ {
string namename = nodeName; string namename = nodeName;
bool animatedBool = false; bool animatedBool = false;
@@ -246,7 +235,6 @@ namespace RH_Engine
position = positionVector, position = positionVector,
scale = scalar, scale = scalar,
rotation = rotationVector rotation = rotationVector
}, },
model = new model = new
{ {
@@ -257,7 +245,6 @@ namespace RH_Engine
}, },
} }
} }
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
@@ -287,7 +274,6 @@ namespace RH_Engine
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
public string RouteCommand(string serialToSend) public string RouteCommand(string serialToSend)
{ {
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best); ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
@@ -345,7 +331,7 @@ namespace RH_Engine
private int[] GetDir() private int[] GetDir()
{ {
Random rng = new Random(); Random rng = new Random();
int[] dir = {rng.Next(50), 0, rng.Next(50)}; int[] dir = { rng.Next(50), 0, rng.Next(50) };
return dir; return dir;
} }
@@ -401,7 +387,6 @@ namespace RH_Engine
throw new Exception("The time must be between 0 and 24!"); throw new Exception("The time must be between 0 and 24!");
} }
dynamic payload = new dynamic payload = new
{ {
id = "scene/skybox/settime", id = "scene/skybox/settime",
@@ -409,13 +394,10 @@ namespace RH_Engine
{ {
time = timeToSet time = timeToSet
} }
}; };
return JsonConvert.SerializeObject(Payload(payload)); return JsonConvert.SerializeObject(Payload(payload));
} }
private object Payload(dynamic message) private object Payload(dynamic message)
{ {
return new return new
@@ -428,8 +410,5 @@ namespace RH_Engine
} }
}; };
} }
} }
} }

View File

@@ -1,9 +1,5 @@
using System; using Newtonsoft.Json;
using System.Collections.Generic; using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
using Newtonsoft.Json;
namespace RH_Engine namespace RH_Engine
{ {
@@ -27,14 +23,13 @@ namespace RH_Engine
} }
return res; return res;
} }
public static string GetSessionID(string msg, PC[] PCs) public static string GetSessionID(string msg, PC[] PCs)
{ {
dynamic jsonData = JsonConvert.DeserializeObject(msg); dynamic jsonData = JsonConvert.DeserializeObject(msg);
Newtonsoft.Json.Linq.JArray data = jsonData.data; Newtonsoft.Json.Linq.JArray data = jsonData.data;
for (int i = data.Count-1; i >= 0; i--) for (int i = data.Count - 1; i >= 0; i--)
{ {
dynamic d = data[i]; dynamic d = data[i];
foreach (PC pc in PCs) foreach (PC pc in PCs)
@@ -60,7 +55,6 @@ namespace RH_Engine
{ {
dynamic d = JsonConvert.DeserializeObject(json); dynamic d = JsonConvert.DeserializeObject(json);
return d.id; return d.id;
} }
public static string GetTunnelID(string json) public static string GetTunnelID(string json)

View File

@@ -3,19 +3,13 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.Intrinsics.X86;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading;
namespace RH_Engine namespace RH_Engine
{ {
public delegate void HandleSerial(string message); public delegate void HandleSerial(string message);
internal class Program internal class Program
{ {
private static PC[] PCs = { private static PC[] PCs = {
@@ -36,10 +30,8 @@ namespace RH_Engine
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>(); private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
private static void Main(string[] args) private static void Main(string[] args)
{ {
TcpClient client = new TcpClient("145.48.6.10", 6666); TcpClient client = new TcpClient("145.48.6.10", 6666);
CreateConnection(client.GetStream()); CreateConnection(client.GetStream());
@@ -62,14 +54,14 @@ namespace RH_Engine
/// <param name="message">the response message from the server</param> /// <param name="message">the response message from the server</param>
public static void HandleResponse(string message) public static void HandleResponse(string message)
{ {
string id = JSONParser.GetID(message); string id = JSONParser.GetID(message);
// because the first messages don't have a serial, we need to check on the id // because the first messages don'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);
} else if (id == "tunnel/create") }
else if (id == "tunnel/create")
{ {
tunnelId = JSONParser.GetTunnelID(message); tunnelId = JSONParser.GetTunnelID(message);
if (tunnelId == null) if (tunnelId == null)
@@ -85,7 +77,6 @@ namespace RH_Engine
string serial = JSONParser.GetSerial(message); string serial = JSONParser.GetSerial(message);
//Console.WriteLine("Got serial " + serial); //Console.WriteLine("Got serial " + serial);
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message); if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
} }
} }
@@ -98,7 +89,7 @@ namespace RH_Engine
/// <param name="action">the code to be executed upon reveiving a reply from the server with the specified serial</param> /// <param name="action">the code to be executed upon reveiving a reply from the server with the specified serial</param>
public static void SendMessageAndOnResponse(NetworkStream stream, string message, string serial, HandleSerial action) public static void SendMessageAndOnResponse(NetworkStream stream, string message, string serial, HandleSerial action)
{ {
serialResponses.Add(serial,action); serialResponses.Add(serial, action);
WriteTextMessage(stream, message); WriteTextMessage(stream, message);
} }
@@ -120,8 +111,6 @@ namespace RH_Engine
Console.WriteLine("sent message " + message); Console.WriteLine("sent message " + message);
} }
/// <summary> /// <summary>
/// connects to the server and creates the tunnel /// connects to the server and creates the tunnel
/// </summary> /// </summary>
@@ -154,17 +143,15 @@ namespace RH_Engine
{ {
Command mainCommand = new Command(tunnelID); Command mainCommand = new Command(tunnelID);
WriteTextMessage(stream, mainCommand.ResetScene()); WriteTextMessage(stream, mainCommand.ResetScene());
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message)); SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
//WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null)); //WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
//string command; //string command;
SendMessageAndOnResponse(stream, mainCommand.addPanel("panelID"), "panelID", (message) => panelId = JSONParser.GetResponseUuid(message)); SendMessageAndOnResponse(stream, mainCommand.addPanel("panelID"), "panelID", (message) => panelId = JSONParser.GetResponseUuid(message));
Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD,stream,mainCommand)); Console.WriteLine("id of head " + GetId(Command.STANDARD_HEAD, stream, mainCommand));
//command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx"); //command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
//WriteTextMessage(stream, command); //WriteTextMessage(stream, command);
@@ -182,7 +169,6 @@ namespace RH_Engine
// Console.WriteLine("Color panel: " + ReadPrefMessage(stream)); // Console.WriteLine("Color panel: " + ReadPrefMessage(stream));
// WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel)); // WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel));
// Console.WriteLine("Swap panel: " + ReadPrefMessage(stream)); // Console.WriteLine("Swap panel: " + ReadPrefMessage(stream));
} }
/// <summary> /// <summary>
@@ -205,7 +191,6 @@ namespace RH_Engine
} }
Console.WriteLine("Could not find id of " + name); Console.WriteLine("Could not find id of " + name);
return null; return null;
} }
public static void CreateTerrain(NetworkStream stream, Command createGraphics) public static void CreateTerrain(NetworkStream stream, Command createGraphics)
@@ -232,11 +217,11 @@ namespace RH_Engine
public static JArray GetChildren(NetworkStream stream, Command createGraphics) public static JArray GetChildren(NetworkStream stream, Command createGraphics)
{ {
JArray res = null; JArray res = null;
SendMessageAndOnResponse(stream, createGraphics.GetSceneInfoCommand("getChildren"),"getChildren",(message) => SendMessageAndOnResponse(stream, createGraphics.GetSceneInfoCommand("getChildren"), "getChildren", (message) =>
{ {
dynamic response = JsonConvert.DeserializeObject(message); dynamic response = JsonConvert.DeserializeObject(message);
res = response.data.data.data.children; res = response.data.data.data.children;
}); });
while (res == null) { } while (res == null) { }
return res; return res;
} }
@@ -260,9 +245,7 @@ namespace RH_Engine
} }
return res; return res;
} }
} }
/// <summary> /// <summary>
@@ -275,6 +258,7 @@ namespace RH_Engine
this.host = host; this.host = host;
this.user = user; this.user = user;
} }
public string host { get; } public string host { get; }
public string user { get; } public string user { get; }

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@@ -7,12 +6,14 @@ using System.Threading;
namespace RH_Engine namespace RH_Engine
{ {
public delegate void OnResponse(string response); public delegate void OnResponse(string response);
class ServerResponseReader class ServerResponseReader
{ {
public OnResponse callback public OnResponse callback
{ {
get;set; get; set;
} }
public NetworkStream Stream { get; } public NetworkStream Stream { get; }
public ServerResponseReader(NetworkStream stream) public ServerResponseReader(NetworkStream stream)