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 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
}
}
}
@@ -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);
@@ -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
}
};
}
}
}

View File

@@ -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,7 +23,6 @@ namespace RH_Engine
}
return res;
}
public static string GetSessionID(string msg, PC[] PCs)
@@ -60,7 +55,6 @@ namespace RH_Engine
{
dynamic d = JsonConvert.DeserializeObject(json);
return d.id;
}
public static string GetTunnelID(string json)

View File

@@ -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")
}
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);
}
}
@@ -120,8 +111,6 @@ namespace RH_Engine
Console.WriteLine("sent message " + message);
}
/// <summary>
/// connects to the server and creates the tunnel
/// </summary>
@@ -154,11 +143,9 @@ 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;
@@ -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)
@@ -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; }

View File

@@ -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;
}
public NetworkStream Stream { get; }
public ServerResponseReader(NetworkStream stream)