Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -29,16 +29,24 @@ namespace Client
|
||||
this.client = new TcpClient();
|
||||
this.connected = false;
|
||||
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
||||
|
||||
initEngine();
|
||||
}
|
||||
|
||||
private void initEngine()
|
||||
{
|
||||
engineConnection = EngineConnection.INSTANCE;
|
||||
engineConnection.OnNoTunnelId = retryEngineConnection;
|
||||
if (!engineConnection.Connected) engineConnection.Connect();
|
||||
}
|
||||
|
||||
private void retryEngineConnection()
|
||||
{
|
||||
Console.WriteLine("-- Could not connect to the VR engine. Please make sure you are running the simulation!");
|
||||
Console.WriteLine("-- Press any key to retry connecting to the VR engine.");
|
||||
Console.ReadKey();
|
||||
|
||||
engineConnection.CreateConnection();
|
||||
}
|
||||
|
||||
private void OnConnect(IAsyncResult ar)
|
||||
{
|
||||
this.client.EndConnect(ar);
|
||||
@@ -86,6 +94,7 @@ namespace Client
|
||||
if (responseStatus == "OK")
|
||||
{
|
||||
this.connected = true;
|
||||
initEngine();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -185,9 +194,12 @@ namespace Client
|
||||
Console.WriteLine("enter password");
|
||||
string password = Console.ReadLine();
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password));
|
||||
string hashUser = Hashing.Hasher.HashString(username);
|
||||
string hashPassword = Hashing.Hasher.HashString(password);
|
||||
|
||||
initEngine();
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
|
||||
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,4 +15,6 @@
|
||||
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,20 +7,22 @@ using System.Net.Sockets;
|
||||
namespace Client
|
||||
{
|
||||
public delegate void HandleSerial(string message);
|
||||
public delegate void HandleNoTunnelId();
|
||||
|
||||
public sealed class EngineConnection
|
||||
{
|
||||
private static EngineConnection instance = null;
|
||||
private static readonly object padlock = new object();
|
||||
public HandleNoTunnelId OnNoTunnelId;
|
||||
|
||||
|
||||
private static PC[] PCs = {
|
||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||
//new PC("T470S", "Shinichi"),
|
||||
//new PC("DESKTOP-DHS478C", "semme"),
|
||||
new PC("HP-ZBOOK-SEM", "Sem"),
|
||||
new PC("HP-ZBOOK-SEM", "Sem")
|
||||
//new PC("DESKTOP-TV73FKO", "Wouter"),
|
||||
new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
|
||||
//new PC("NA", "Bart")
|
||||
};
|
||||
|
||||
@@ -62,6 +64,7 @@ namespace Client
|
||||
{
|
||||
TcpClient client = new TcpClient("145.48.6.10", 6666);
|
||||
stream = client.GetStream();
|
||||
initReader();
|
||||
CreateConnection();
|
||||
}
|
||||
|
||||
@@ -69,9 +72,8 @@ namespace Client
|
||||
/// connects to the server and creates the tunnel
|
||||
/// </summary>
|
||||
/// <param name="stream">the network stream to use</param>
|
||||
private void CreateConnection()
|
||||
public void CreateConnection()
|
||||
{
|
||||
initReader();
|
||||
|
||||
WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
|
||||
|
||||
@@ -84,7 +86,10 @@ namespace Client
|
||||
|
||||
// wait until we have a tunnel id
|
||||
while (tunnelId == string.Empty) { }
|
||||
Write("got tunnel id! " + tunnelId);
|
||||
if (tunnelId != null)
|
||||
{
|
||||
Write("got tunnel id! " + tunnelId);
|
||||
}
|
||||
mainCommand = new Command(tunnelId);
|
||||
|
||||
}
|
||||
@@ -119,6 +124,8 @@ namespace Client
|
||||
if (tunnelId == null)
|
||||
{
|
||||
Write("could not find a valid tunnel id!");
|
||||
OnNoTunnelId?.Invoke();
|
||||
Connected = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +167,7 @@ namespace Client
|
||||
|
||||
stream.Write(res);
|
||||
|
||||
Write("sent message " + message);
|
||||
//Write("sent message " + message);
|
||||
}
|
||||
public void Write(string msg)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using Hardware;
|
||||
using Hardware.Simulators;
|
||||
using RH_Engine;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
@@ -11,7 +14,6 @@ namespace Client
|
||||
Console.WriteLine("Hello World!");
|
||||
//connect fiets?
|
||||
|
||||
|
||||
Client client = new Client();
|
||||
|
||||
|
||||
|
||||
27
Hashing/Hasher.cs
Normal file
27
Hashing/Hasher.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Hashing
|
||||
{
|
||||
class Hasher
|
||||
{
|
||||
public static byte[] GetHash(string input)
|
||||
{
|
||||
using (HashAlgorithm algorithm = SHA256.Create())
|
||||
{
|
||||
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
}
|
||||
}
|
||||
|
||||
public static string HashString(string input)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in GetHash(input)) {
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Hashing/Hashing.projitems
Normal file
14
Hashing/Hashing.projitems
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>70277749-d423-4871-b692-2efc5a6ed932</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>Hashing</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Hasher.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
Hashing/Hashing.shproj
Normal file
13
Hashing/Hashing.shproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>70277749-d423-4871-b692-2efc5a6ed932</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="Hashing.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -13,9 +13,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "..\Client\Client.
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DokterApp", "..\DokterApp\DokterApp.csproj", "{B150F08B-13DA-4D17-BD96-7E89F52727C6}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Hashing", "..\Hashing\Hashing.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\Hashing\Hashing.projitems*{5759dd20-7a4f-4d8d-b986-a70a7818c112}*SharedItemsImports = 5
|
||||
..\Hashing\Hashing.projitems*{70277749-d423-4871-b692-2efc5a6ed932}*SharedItemsImports = 13
|
||||
..\Hashing\Hashing.projitems*{b1ab6f51-a20d-4162-9a7f-b3350b7510fd}*SharedItemsImports = 5
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Client;
|
||||
using Newtonsoft.Json;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
@@ -19,6 +20,7 @@ namespace Server
|
||||
private SaveData saveData;
|
||||
private string username = null;
|
||||
private DateTime sessionStart;
|
||||
private const string fileName = "userInfo.dat";
|
||||
|
||||
|
||||
|
||||
@@ -132,6 +134,10 @@ namespace Server
|
||||
break;
|
||||
}
|
||||
saveData?.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
|
||||
|
||||
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
|
||||
|
||||
}
|
||||
else if (DataParser.isRawData(message))
|
||||
{
|
||||
@@ -160,9 +166,58 @@ namespace Server
|
||||
|
||||
private bool verifyLogin(string username, string password)
|
||||
{
|
||||
return username == password;
|
||||
Console.WriteLine("got hashes " + username + "\n" + password);
|
||||
|
||||
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
File.Create(fileName);
|
||||
Console.WriteLine("file doesnt exist");
|
||||
newUsers(username, password);
|
||||
Console.WriteLine("true");
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
Console.WriteLine("file exists, located at " + Path.GetFullPath(fileName));
|
||||
string[] usernamesPasswords = File.ReadAllLines(fileName);
|
||||
if (usernamesPasswords.Length == 0)
|
||||
{
|
||||
newUsers(username, password);
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (string s in usernamesPasswords)
|
||||
{
|
||||
string[] combo = s.Split(" ");
|
||||
if (combo[0] == username)
|
||||
{
|
||||
Console.WriteLine("correct info");
|
||||
return combo[1] == password;
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine("combo was not found in file");
|
||||
|
||||
}
|
||||
Console.WriteLine("false");
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private void newUsers(string username, string password)
|
||||
{
|
||||
|
||||
Console.WriteLine("creating new entry in file");
|
||||
using (StreamWriter sw = File.AppendText(fileName))
|
||||
{
|
||||
sw.WriteLine(username + " " + password);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||
|
||||
@@ -13,4 +13,6 @@
|
||||
<ProjectReference Include="..\Client\Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user