cleanup files
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
using LibNoise.Primitive;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace RH_Engine
|
||||
{
|
||||
class Command
|
||||
internal class Command
|
||||
{
|
||||
public const string STANDARD_HEAD = "Head";
|
||||
public const string STANDARD_GROUND = "GroundPlane";
|
||||
@@ -16,9 +12,7 @@ namespace RH_Engine
|
||||
public const string STANDARD_LEFTHAND = "LeftHand";
|
||||
public const string STANDARD_RIGHTHAND = "RightHand";
|
||||
|
||||
|
||||
|
||||
string tunnelID;
|
||||
private string tunnelID;
|
||||
|
||||
public Command(string tunnelID)
|
||||
{
|
||||
@@ -35,10 +29,10 @@ namespace RH_Engine
|
||||
size = sizeArray,
|
||||
heights = heightsArray
|
||||
}
|
||||
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
public string AddLayer(string uid, string texture)
|
||||
{
|
||||
dynamic payload = new
|
||||
@@ -56,6 +50,7 @@ namespace RH_Engine
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
public string UpdateTerrain()
|
||||
{
|
||||
dynamic payload = new
|
||||
@@ -63,7 +58,6 @@ namespace RH_Engine
|
||||
id = "scene/terrain/update",
|
||||
data = new
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
@@ -91,19 +85,15 @@ namespace RH_Engine
|
||||
|
||||
public string DeleteNode(string uuid)
|
||||
{
|
||||
|
||||
dynamic payload = new
|
||||
{
|
||||
id = "scene/node/delete",
|
||||
data = new
|
||||
{
|
||||
id = uuid,
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
|
||||
}
|
||||
|
||||
public string addPanel(string serialToSend)
|
||||
@@ -123,7 +113,6 @@ namespace RH_Engine
|
||||
resolution = new int[] { 512, 512 },
|
||||
background = new int[] { 1, 0, 0, 0 },
|
||||
castShadow = false
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,20 +199,20 @@ namespace RH_Engine
|
||||
|
||||
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;
|
||||
bool animatedBool = false;
|
||||
@@ -246,7 +235,6 @@ namespace RH_Engine
|
||||
position = positionVector,
|
||||
scale = scalar,
|
||||
rotation = rotationVector
|
||||
|
||||
},
|
||||
model = new
|
||||
{
|
||||
@@ -257,7 +245,6 @@ namespace RH_Engine
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
@@ -287,7 +274,6 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
|
||||
public string RouteCommand(string serialToSend)
|
||||
{
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
|
||||
@@ -345,7 +331,7 @@ namespace RH_Engine
|
||||
private int[] GetDir()
|
||||
{
|
||||
Random rng = new Random();
|
||||
int[] dir = {rng.Next(50), 0, rng.Next(50)};
|
||||
int[] dir = { rng.Next(50), 0, rng.Next(50) };
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -401,7 +387,6 @@ namespace RH_Engine
|
||||
throw new Exception("The time must be between 0 and 24!");
|
||||
}
|
||||
|
||||
|
||||
dynamic payload = new
|
||||
{
|
||||
id = "scene/skybox/settime",
|
||||
@@ -409,13 +394,10 @@ namespace RH_Engine
|
||||
{
|
||||
time = timeToSet
|
||||
}
|
||||
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
|
||||
}
|
||||
|
||||
|
||||
private object Payload(dynamic message)
|
||||
{
|
||||
return new
|
||||
@@ -428,8 +410,5 @@ namespace RH_Engine
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace RH_Engine
|
||||
{
|
||||
@@ -27,14 +23,13 @@ namespace RH_Engine
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
public static string GetSessionID(string msg, PC[] PCs)
|
||||
{
|
||||
dynamic jsonData = JsonConvert.DeserializeObject(msg);
|
||||
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];
|
||||
foreach (PC pc in PCs)
|
||||
@@ -60,7 +55,6 @@ namespace RH_Engine
|
||||
{
|
||||
dynamic d = JsonConvert.DeserializeObject(json);
|
||||
return d.id;
|
||||
|
||||
}
|
||||
|
||||
public static string GetTunnelID(string json)
|
||||
|
||||
@@ -3,19 +3,13 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace RH_Engine
|
||||
{
|
||||
|
||||
public delegate void HandleSerial(string message);
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static PC[] PCs = {
|
||||
@@ -36,10 +30,8 @@ namespace RH_Engine
|
||||
|
||||
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
|
||||
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
||||
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
||||
|
||||
CreateConnection(client.GetStream());
|
||||
@@ -62,14 +54,14 @@ namespace RH_Engine
|
||||
/// <param name="message">the response message from the server</param>
|
||||
public static void HandleResponse(string message)
|
||||
{
|
||||
|
||||
string id = JSONParser.GetID(message);
|
||||
|
||||
// because the first messages don't have a serial, we need to check on the id
|
||||
if (id == "session/list")
|
||||
{
|
||||
sessionId = JSONParser.GetSessionID(message,PCs);
|
||||
} else if (id == "tunnel/create")
|
||||
sessionId = JSONParser.GetSessionID(message, PCs);
|
||||
}
|
||||
else if (id == "tunnel/create")
|
||||
{
|
||||
tunnelId = JSONParser.GetTunnelID(message);
|
||||
if (tunnelId == null)
|
||||
@@ -85,7 +77,6 @@ namespace RH_Engine
|
||||
string serial = JSONParser.GetSerial(message);
|
||||
//Console.WriteLine("Got serial " + serial);
|
||||
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>
|
||||
public static void SendMessageAndOnResponse(NetworkStream stream, string message, string serial, HandleSerial action)
|
||||
{
|
||||
serialResponses.Add(serial,action);
|
||||
serialResponses.Add(serial, action);
|
||||
WriteTextMessage(stream, message);
|
||||
}
|
||||
|
||||
@@ -120,8 +111,6 @@ namespace RH_Engine
|
||||
Console.WriteLine("sent message " + message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// connects to the server and creates the tunnel
|
||||
/// </summary>
|
||||
@@ -154,17 +143,15 @@ namespace RH_Engine
|
||||
{
|
||||
Command mainCommand = new Command(tunnelID);
|
||||
|
||||
|
||||
WriteTextMessage(stream, mainCommand.ResetScene());
|
||||
SendMessageAndOnResponse(stream, mainCommand.RouteCommand("routeID"), "routeID", (message) => routeId = JSONParser.GetResponseUuid(message));
|
||||
|
||||
|
||||
//WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
||||
//string command;
|
||||
|
||||
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");
|
||||
//WriteTextMessage(stream, command);
|
||||
@@ -182,7 +169,6 @@ namespace RH_Engine
|
||||
// Console.WriteLine("Color panel: " + ReadPrefMessage(stream));
|
||||
// WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel));
|
||||
// Console.WriteLine("Swap panel: " + ReadPrefMessage(stream));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -205,7 +191,6 @@ namespace RH_Engine
|
||||
}
|
||||
Console.WriteLine("Could not find id of " + name);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static void CreateTerrain(NetworkStream stream, Command createGraphics)
|
||||
@@ -232,7 +217,7 @@ namespace RH_Engine
|
||||
public static JArray GetChildren(NetworkStream stream, Command createGraphics)
|
||||
{
|
||||
JArray res = null;
|
||||
SendMessageAndOnResponse(stream, createGraphics.GetSceneInfoCommand("getChildren"),"getChildren",(message) =>
|
||||
SendMessageAndOnResponse(stream, createGraphics.GetSceneInfoCommand("getChildren"), "getChildren", (message) =>
|
||||
{
|
||||
dynamic response = JsonConvert.DeserializeObject(message);
|
||||
res = response.data.data.data.children;
|
||||
@@ -260,9 +245,7 @@ namespace RH_Engine
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -275,6 +258,7 @@ namespace RH_Engine
|
||||
this.host = host;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public string host { get; }
|
||||
public string user { get; }
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -7,12 +6,14 @@ using System.Threading;
|
||||
namespace RH_Engine
|
||||
{
|
||||
public delegate void OnResponse(string response);
|
||||
|
||||
class ServerResponseReader
|
||||
{
|
||||
public OnResponse callback
|
||||
{
|
||||
get;set;
|
||||
get; set;
|
||||
}
|
||||
|
||||
public NetworkStream Stream { get; }
|
||||
|
||||
public ServerResponseReader(NetworkStream stream)
|
||||
|
||||
Reference in New Issue
Block a user