This commit is contained in:
Sem van der Hoeven
2020-10-02 11:44:26 +02:00
parent 341723d1d1
commit 32ef17365e

View File

@@ -27,16 +27,24 @@ namespace Client
this.client = new TcpClient(); this.client = new TcpClient();
this.connected = false; this.connected = false;
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null); client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
initEngine();
} }
private void initEngine() private void initEngine()
{ {
engineConnection = EngineConnection.INSTANCE; engineConnection = EngineConnection.INSTANCE;
engineConnection.OnNoTunnelId = retryEngineConnection;
if (!engineConnection.Connected) engineConnection.Connect(); 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);
@@ -84,6 +92,7 @@ namespace Client
if (responseStatus == "OK") if (responseStatus == "OK")
{ {
this.connected = true; this.connected = true;
initEngine();
} }
else else
{ {
@@ -150,9 +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));
initEngine();
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null); this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
} }
} }