13 Commits

Author SHA1 Message Date
Sem van der Hoeven
cb2435bf53 weird fix 2020-10-02 11:48:03 +02:00
Sem van der Hoeven
fedf8c0e5b added client server login with hashed passwords and usernames 2020-10-02 11:43:07 +02:00
Sem van der Hoeven
3e5f6e46c4 progress on validation 2020-09-30 16:22:57 +02:00
Sem van der Hoeven
97f9d863aa fix 2020-09-30 15:10:47 +02:00
Sem van der Hoeven
d6b938668f added reconnecting to the vr server when no tunnel id is found 2020-09-30 14:33:15 +02:00
Sem van der Hoeven
341723d1d1 added maincommand to engineconnection 2020-09-30 12:59:04 +02:00
Sem van der Hoeven
0cd3753b76 properly added engineconnection to client 2020-09-30 12:30:40 +02:00
Sem van der Hoeven
4388b39be5 only connects when username and password are entered 2020-09-30 12:27:31 +02:00
Sem van der Hoeven
0dc4bb6fad connected engine to client 2020-09-30 12:23:53 +02:00
Sem van der Hoeven
3ca3c1ad78 added engineconnection to client 2020-09-30 12:17:57 +02:00
Sem van der Hoeven
d06d621b13 added necessary methods and added method sig to cw of engineconnect 2020-09-30 12:13:59 +02:00
Sem van der Hoeven
7b05fcc898 added engineconnect as singleton 2020-09-30 12:01:53 +02:00
Sem van der Hoeven
c5b9a7ec09 made rh engine classes public 2020-09-30 11:44:00 +02:00
23 changed files with 335 additions and 287 deletions

View File

@@ -14,6 +14,7 @@ namespace Client
private bool connected; private bool connected;
private byte[] totalBuffer = new byte[1024]; private byte[] totalBuffer = new byte[1024];
private int totalBufferReceived = 0; private int totalBufferReceived = 0;
private EngineConnection engineConnection;
public Client() : this("localhost", 5555) public Client() : this("localhost", 5555)
@@ -28,6 +29,22 @@ namespace Client
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null); client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
} }
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) private void OnConnect(IAsyncResult ar)
{ {
this.client.EndConnect(ar); this.client.EndConnect(ar);
@@ -75,6 +92,7 @@ namespace Client
if (responseStatus == "OK") if (responseStatus == "OK")
{ {
this.connected = true; this.connected = true;
initEngine();
} }
else else
{ {
@@ -141,8 +159,12 @@ namespace Client
Console.WriteLine("enter password"); Console.WriteLine("enter password");
string password = Console.ReadLine(); string password = Console.ReadLine();
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password)); string hashUser = Hashing.Hasher.HashString(username);
string hashPassword = Hashing.Hasher.HashString(password);
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(hashUser, hashPassword));
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
} }

View File

@@ -12,6 +12,9 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Message\Message.csproj" /> <ProjectReference Include="..\Message\Message.csproj" />
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" /> <ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
<ProjectReference Include="..\RH-Engine\RH-Engine.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project> </Project>

180
Client/EngineConnection.cs Normal file
View File

@@ -0,0 +1,180 @@
using System;
using System.Collections.Generic;
using System.Text;
using RH_Engine;
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("DESKTOP-TV73FKO", "Wouter"),
//new PC("DESKTOP-SINMKT1", "Ralf van Aert"),
//new PC("NA", "Bart")
};
private static ServerResponseReader serverResponseReader;
private static string sessionId = string.Empty;
private static string tunnelId = string.Empty;
private static string routeId = string.Empty;
private static string panelId = string.Empty;
private static string bikeId = string.Empty;
private static NetworkStream stream;
private static Dictionary<string, HandleSerial> serialResponses = new Dictionary<string, HandleSerial>();
private Command mainCommand;
public bool Connected = false;
EngineConnection()
{
}
public static EngineConnection INSTANCE
{
get
{
lock (padlock)
{
if (instance == null)
{
instance = new EngineConnection();
}
}
return instance;
}
}
public void Connect()
{
TcpClient client = new TcpClient("145.48.6.10", 6666);
stream = client.GetStream();
initReader();
CreateConnection();
}
/// <summary>
/// connects to the server and creates the tunnel
/// </summary>
/// <param name="stream">the network stream to use</param>
public void CreateConnection()
{
WriteTextMessage( "{\r\n\"id\" : \"session/list\",\r\n\"serial\" : \"list\"\r\n}");
// wait until we have got a sessionId
while (sessionId == string.Empty) { }
string tunnelCreate = "{\"id\" : \"tunnel/create\", \"data\" : {\"session\" : \"" + sessionId + "\"}}";
WriteTextMessage(tunnelCreate);
// wait until we have a tunnel id
while (tunnelId == string.Empty) { }
if (tunnelId != null)
{
Write("got tunnel id! " + tunnelId);
}
mainCommand = new Command(tunnelId);
}
/// <summary>
/// initializes and starts the reading of the responses from the vr server
/// </summary>
/// <param name="stream">the networkstream</param>
private void initReader()
{
serverResponseReader = new ServerResponseReader(stream);
serverResponseReader.callback = HandleResponse;
serverResponseReader.StartRead();
Connected = true;
}
/// <summary>
/// callback method that handles responses from the server
/// </summary>
/// <param name="message">the response message from the server</param>
public 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")
{
tunnelId = JSONParser.GetTunnelID(message);
if (tunnelId == null)
{
Write("could not find a valid tunnel id!");
OnNoTunnelId?.Invoke();
Connected = false;
return;
}
}
if (message.Contains("serial"))
{
//Console.WriteLine("GOT MESSAGE WITH SERIAL: " + message + "\n\n\n");
string serial = JSONParser.GetSerial(message);
//Console.WriteLine("Got serial " + serial);
if (serialResponses.ContainsKey(serial)) serialResponses[serial].Invoke(message);
}
}
/// <summary>
/// method that sends the speciefied message with the specified serial, and executes the given action upon receivind a reply from the server with this serial.
/// </summary>
/// <param name="stream">the networkstream to use</param>
/// <param name="message">the message to send</param>
/// <param name="serial">the serial to check for</param>
/// <param name="action">the code to be executed upon reveiving a reply from the server with the specified serial</param>
public void SendMessageAndOnResponse(string message, string serial, HandleSerial action)
{
serialResponses.Add(serial, action);
WriteTextMessage(message);
}
/// <summary>
/// writes a message to the server
/// </summary>
/// <param name="stream">the network stream to use</param>
/// <param name="message">the message to send</param>
public void WriteTextMessage(string message)
{
byte[] msg = Encoding.ASCII.GetBytes(message);
byte[] res = new byte[msg.Length + 4];
Array.Copy(BitConverter.GetBytes(msg.Length), 0, res, 0, 4);
Array.Copy(msg, 0, res, 4, msg.Length);
stream.Write(res);
//Write("sent message " + message);
}
public void Write(string msg)
{
Console.WriteLine( "[ENGINECONNECT] " + msg);
}
}
}

View File

@@ -1,6 +1,9 @@
using System; using System;
using Hardware; using Hardware;
using Hardware.Simulators; using Hardware.Simulators;
using RH_Engine;
using System.Security.Cryptography;
using System.Text;
namespace Client namespace Client
{ {
@@ -11,7 +14,6 @@ namespace Client
Console.WriteLine("Hello World!"); Console.WriteLine("Hello World!");
//connect fiets? //connect fiets?
Client client = new Client(); Client client = new Client();

View File

@@ -1,28 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Input;
namespace DokterApp
{
public interface ITab
{
string Name { get; set; }
ICommand CloseCommand { get; }
event EventHandler CloseRequested;
}
public abstract class Tab : ITab
{
public string Name { get; set; }
public ICommand CloseCommand { get; }
public event EventHandler CloseRequested;
public Tab()
{
//CloseCommand =
}
}
}

View File

@@ -5,25 +5,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DokterApp" xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d" mc:Ignorable="d"
WindowState="Maximized" Title="MainWindow" Height="450" Width="800">
Title="Dokter App" > <Grid>
<Grid RenderTransformOrigin="0.499,0.49">
<Grid.RowDefinitions>
<RowDefinition Height="23*"/>
<RowDefinition Height="31*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.ColumnSpan="2" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Orientation="Vertical">
<Label Content="Sensei" Margin="0,0,0,20" HorizontalAlignment="Center"/>
<Label Content="Username" HorizontalContentAlignment="Center"/>
<TextBox x:Name="Username" TextWrapping="Wrap" Width="120"/>
<Label Content="Password" HorizontalContentAlignment="Center"/>
<TextBox x:Name="Password" TextWrapping="Wrap" Width="120"/>
<Button x:Name="Login" Content="Login" Margin="0,20,0,0" Click="Login_Click_1" />
</StackPanel>
</Grid> </Grid>
</Window> </Window>

View File

@@ -24,17 +24,5 @@ namespace DokterApp
{ {
InitializeComponent(); InitializeComponent();
} }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void Login_Click_1(object sender, RoutedEventArgs e)
{
WindowTabs windowTabs = new WindowTabs();
windowTabs.Show();
this.Close();
}
} }
} }

View File

@@ -1,67 +0,0 @@
<UserControl x:Class="DokterApp.UserControlForTab"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Margin="15,5,15,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="43*"/>
<RowDefinition Height="47*"/>
<RowDefinition Height="180*"/>
<RowDefinition Height="180*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.RowSpan="2" Margin="0,0,0,22">
<StackPanel.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="Margin" Value="0,0,20,0"/>
</Style>
</StackPanel.Resources>
<Label Content="UserName" Name="Username_Label"/>
<Label Content="Status: " Name="Status_Label"/>
</StackPanel>
<StackPanel Margin="0,10,0,0" Grid.RowSpan="2" Grid.Row="1">
<StackPanel.Resources>
<Style TargetType="{x:Type DockPanel}">
<Setter Property="Margin" Value="0,20,0,0"/>
</Style>
</StackPanel.Resources>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<Label Content="Resistance" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Speed" Width="110" DockPanel.Dock="Left"/>
<Label Content="Current BPM" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False" HorizontalAlignment="Stretch">
<TextBox Name="textBox_Resistance" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentSpeed" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentBPM" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<Label Content="Distance Covered" Width="110" DockPanel.Dock="Right"/>
<Label Content="Current Power" Width="110" DockPanel.Dock="Left"/>
<Label Content="Acc. Power" Width="110" DockPanel.Dock="Top"/>
</DockPanel>
<DockPanel Height="26" LastChildFill="False">
<TextBox Name="textBox_DistanceCovered" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Right" IsReadOnly="true"/>
<TextBox Name="textBox_CurrentPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Left" IsReadOnly="true"/>
<TextBox Name="textBox_AccPower" Text="" TextWrapping="Wrap" Width="110" DockPanel.Dock="Top" Height="26" IsReadOnly="true"/>
</DockPanel>
</StackPanel>
<ListBox Name="ChatBox" Grid.Column="1" Margin="59,41,0,0" SelectionChanged="ListBox_SelectionChanged" Grid.RowSpan="3"/>
<TextBox Name="textBox_Chat" Grid.Column="1" HorizontalAlignment="Left" Margin="59,10,0,0" Grid.Row="3" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="235"/>
<Button Content="Button" Grid.Column="1" HorizontalAlignment="Left" Margin="59,33,0,0" Grid.Row="3" VerticalAlignment="Top" Click="Button_Click"/>
<Button Content="Start Session" Grid.Column="1" HorizontalAlignment="Left" Margin="69,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StartSession_Click"/>
<Button Content="Stop Session" Grid.Column="1" HorizontalAlignment="Left" Margin="187,86,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Click="StopSession_Click"/>
<TextBox x:Name="textBox_SetResistance" Grid.Column="1" HorizontalAlignment="Left" Margin="69,128,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="97"/>
<Button Content="Set Resistance" Grid.Column="1" HorizontalAlignment="Left" Margin="187,128,0,0" Grid.Row="3" VerticalAlignment="Top" Width="97" Height="18" Click="SetResistance_Click"/>
<Canvas Grid.Row="3" Background="White" Margin="0,33,0,0"/>
<ComboBox Name="DropBox" HorizontalAlignment="Left" Margin="0,6,0,0" Grid.Row="3" VerticalAlignment="Top" Width="190"/>
<Button Content="Client Info" Grid.Column="1" HorizontalAlignment="Left" Margin="207,6,0,0" VerticalAlignment="Top" Height="26" Width="82" Click="ClientInfo_Click"/>
</Grid>
</UserControl>

View File

@@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DokterApp
{
/// <summary>
/// Interaction logic for UserControlForTab.xaml
/// </summary>
public partial class UserControlForTab : UserControl
{
public UserControlForTab()
{
InitializeComponent();
Username_Label.Content = "Bob";
Status_Label.Content = "Status: Dead";
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ChatBox.Items.Add(textBox_Chat.Text);
}
private void StartSession_Click(object sender, RoutedEventArgs e)
{
}
private void StopSession_Click(object sender, RoutedEventArgs e)
{
}
private void SetResistance_Click(object sender, RoutedEventArgs e)
{
}
private void ClientInfo_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("firstname:\tBob\n" +
"surname:\t\tde Bouwer");
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DokterApp
{
class UserTab : Tab
{
public UserTab()
{
Name = "Piet";
}
}
}

View File

@@ -1,16 +0,0 @@
<Window x:Class="DokterApp.WindowTabs"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DokterApp"
mc:Ignorable="d"
WindowState="Maximized"
Title="WindowTabs" Height="450" Width="800">
<Grid>
<TabControl x:Name="tabControl" Loaded="tabControl_Load" TabStripPlacement="Left" Margin="0,23,0,0" />
<Button Content="Button" HorizontalAlignment="Left" Margin="578,125,0,0" VerticalAlignment="Top" Click="Button_Click"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>

View File

@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace DokterApp
{
/// <summary>
/// Interaction logic for WindowTabs.xaml
/// </summary>
public partial class WindowTabs : Window
{
public TabControl tbControl;
public WindowTabs()
{
InitializeComponent();
}
private void tabControl_Load(object sender, RoutedEventArgs e)
{
this.tbControl = (sender as TabControl);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TabItem newTabItem = new TabItem
{
Header = "Test",
Width = 110,
Height = 40
};
newTabItem.Content = new UserControlForTab();
this.tbControl.Items.Add(newTabItem);
}
}
}

27
Hashing/Hasher.cs Normal file
View 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
View 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
View 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>

View File

@@ -15,7 +15,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Message", "..\Message\Messa
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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 EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Hashing", "..\Hashing\Hashing.shproj", "{70277749-D423-4871-B692-2EFC5A6ED932}"
EndProject
Global 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 GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU

View File

@@ -4,7 +4,7 @@ using System;
namespace RH_Engine namespace RH_Engine
{ {
class Command public 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";

View File

@@ -3,7 +3,7 @@ using System;
namespace RH_Engine namespace RH_Engine
{ {
class JSONParser public class JSONParser
{ {
/// <summary> /// <summary>
/// returns all the users from the given response /// returns all the users from the given response
@@ -36,7 +36,7 @@ namespace RH_Engine
{ {
if (d.clientinfo.host == pc.host && d.clientinfo.user == pc.user) if (d.clientinfo.host == pc.host && d.clientinfo.user == pc.user)
{ {
Console.WriteLine("connecting to {0}, on {1} with id {2}", pc.user, pc.host, d.id); Console.WriteLine("[JSONPARSER] connecting to {0}, on {1} with id {2}", pc.user, pc.host, d.id);
return d.id; return d.id;
} }
} }

View File

@@ -10,7 +10,7 @@ namespace RH_Engine
{ {
public delegate void HandleSerial(string message); public delegate void HandleSerial(string message);
class Program public class Program
{ {
private static PC[] PCs = { private static PC[] PCs = {
//new PC("DESKTOP-M2CIH87", "Fabian"), //new PC("DESKTOP-M2CIH87", "Fabian"),
@@ -161,23 +161,6 @@ namespace RH_Engine
}); });
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);
//command = mainCommand.addPanel();
// WriteTextMessage(stream, command);
// string response = ReadPrefMessage(stream);
// Console.WriteLine("add Panel response: \n\r" + response);
// string uuidPanel = JSONParser.getPanelID(response);
// WriteTextMessage(stream, mainCommand.ClearPanel(uuidPanel));
// Console.WriteLine(ReadPrefMessage(stream));
// WriteTextMessage(stream, mainCommand.bikeSpeed(uuidPanel, 2.42));
// Console.WriteLine(ReadPrefMessage(stream));
// WriteTextMessage(stream, mainCommand.ColorPanel(uuidPanel));
// Console.WriteLine("Color panel: " + ReadPrefMessage(stream));
// WriteTextMessage(stream, mainCommand.SwapPanel(uuidPanel));
// Console.WriteLine("Swap panel: " + ReadPrefMessage(stream));
} }
/// <summary> /// <summary>

View File

@@ -7,7 +7,7 @@ namespace RH_Engine
{ {
public delegate void OnResponse(string response); public delegate void OnResponse(string response);
class ServerResponseReader public class ServerResponseReader
{ {
public OnResponse callback public OnResponse callback
{ {
@@ -31,7 +31,7 @@ namespace RH_Engine
} }
else else
{ {
Console.WriteLine("Starting loop for reading"); Console.WriteLine("[SERVERRESPONSEREADER] Starting loop for reading");
while (true) while (true)
{ {
string res = ReadPrefMessage(Stream); string res = ReadPrefMessage(Stream);

View File

@@ -5,6 +5,7 @@ using System.Net.Sockets;
using System.Text; using System.Text;
using Client; using Client;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Security.Cryptography;
namespace Server namespace Server
{ {
@@ -19,6 +20,7 @@ namespace Server
private SaveData saveData; private SaveData saveData;
private string username = null; private string username = null;
private DateTime sessionStart; private DateTime sessionStart;
private const string fileName = "userInfo.dat";
@@ -125,7 +127,8 @@ namespace Server
} }
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5); Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes)); dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
//saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
} }
else if (DataParser.isRawData(message)) else if (DataParser.isRawData(message))
@@ -139,9 +142,58 @@ namespace Server
private bool verifyLogin(string username, string password) 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) public static string ByteArrayToString(byte[] ba)
{ {
StringBuilder hex = new StringBuilder(ba.Length * 2); StringBuilder hex = new StringBuilder(ba.Length * 2);

View File

@@ -33,7 +33,7 @@ namespace Server
public void WriteDataRAW(string data) public void WriteDataRAW(string data)
{ {
using (StreamWriter sw = File.AppendText(this.path + "/rawFiets" + filename + ".txt")) using (StreamWriter sw = File.AppendText(this.path + "/raw" + filename + ".txt"))
{ {
sw.WriteLine(data); sw.WriteLine(data);
} }

View File

@@ -13,4 +13,6 @@
<ProjectReference Include="..\Client\Client.csproj" /> <ProjectReference Include="..\Client\Client.csproj" />
</ItemGroup> </ItemGroup>
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
</Project> </Project>