Develop #10
@@ -300,6 +300,7 @@ namespace ClientApp.Utils
|
|||||||
this.stream.Dispose();
|
this.stream.Dispose();
|
||||||
this.client.Dispose();
|
this.client.Dispose();
|
||||||
this.handler.stop();
|
this.handler.stop();
|
||||||
|
this.engineConnection.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ namespace ClientApp.Utils
|
|||||||
Console.WriteLine("set tunnel id to " + tunnelId);
|
Console.WriteLine("set tunnel id to " + tunnelId);
|
||||||
if (tunnelId == null)
|
if (tunnelId == null)
|
||||||
{
|
{
|
||||||
Write("could not find a valid tunnel id!");
|
//Write("could not find a valid tunnel id!");
|
||||||
OnNoTunnelId?.Invoke();
|
OnNoTunnelId?.Invoke();
|
||||||
Connected = false;
|
Connected = false;
|
||||||
FollowingRoute = false;
|
FollowingRoute = false;
|
||||||
@@ -256,9 +256,9 @@ namespace ClientApp.Utils
|
|||||||
WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false));
|
WriteTextMessage(mainCommand.ShowRoute("showRouteFalse", false));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
setEnvironment();
|
setEnvironment();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEnvironment()
|
private void setEnvironment()
|
||||||
@@ -348,7 +348,7 @@ namespace ClientApp.Utils
|
|||||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||||
for (int i = 0; i < 256 * 256; i++)
|
for (int i = 0; i < 256 * 256; i++)
|
||||||
{
|
{
|
||||||
height[i] = improvedPerlin.GetValue(x /10, x / 10, x * 100) / 3.5f + 1;
|
height[i] = improvedPerlin.GetValue(x / 10, x / 10, x * 100) / 3.5f + 1;
|
||||||
|
|
||||||
//if (height[i] > 1.1f)
|
//if (height[i] > 1.1f)
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -225,6 +225,8 @@ namespace Util
|
|||||||
|
|
||||||
public static byte[] getNewConnectionJson(string user)
|
public static byte[] getNewConnectionJson(string user)
|
||||||
{
|
{
|
||||||
|
if (user == null)
|
||||||
|
throw new ArgumentNullException("user null");
|
||||||
dynamic data = new
|
dynamic data = new
|
||||||
{
|
{
|
||||||
username = user
|
username = user
|
||||||
|
|||||||
@@ -97,16 +97,17 @@ namespace Server
|
|||||||
switch (identifier)
|
switch (identifier)
|
||||||
{
|
{
|
||||||
case DataParser.LOGIN:
|
case DataParser.LOGIN:
|
||||||
handleLogin(payloadbytes);
|
if (handleLogin(payloadbytes))
|
||||||
|
communication.NewLogin(this);
|
||||||
break;
|
break;
|
||||||
case DataParser.LOGIN_DOCTOR:
|
case DataParser.LOGIN_DOCTOR:
|
||||||
if (communication.doctor != null)
|
if (communication.Doctor != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (handleLogin(payloadbytes))
|
if (handleLogin(payloadbytes))
|
||||||
{
|
{
|
||||||
communication.doctor = this;
|
communication.Doctor = this;
|
||||||
Console.WriteLine("Set doctor to " + communication.doctor + " , this is " + this);
|
Console.WriteLine("Set doctor to " + communication.Doctor + " , this is " + this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DataParser.START_SESSION:
|
case DataParser.START_SESSION:
|
||||||
@@ -136,7 +137,7 @@ namespace Server
|
|||||||
else if (DataParser.isRawData(message))
|
else if (DataParser.isRawData(message))
|
||||||
{
|
{
|
||||||
// print the raw data
|
// print the raw data
|
||||||
Console.WriteLine(BitConverter.ToString(payloadbytes));
|
//Console.WriteLine(BitConverter.ToString(payloadbytes));
|
||||||
// TODO change, checking for length is not that safe
|
// TODO change, checking for length is not that safe
|
||||||
if (payloadbytes.Length == 8)
|
if (payloadbytes.Length == 8)
|
||||||
{
|
{
|
||||||
@@ -168,7 +169,6 @@ namespace Server
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
sendMessage(DataParser.getLoginResponse("OK"));
|
sendMessage(DataParser.getLoginResponse("OK"));
|
||||||
sendMessage(DataParser.getStartSessionJson());
|
sendMessage(DataParser.getStartSessionJson());
|
||||||
communication.NewLogin(this);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO.Pipes;
|
using System.IO.Pipes;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
@@ -13,7 +14,24 @@ namespace Server
|
|||||||
{
|
{
|
||||||
private TcpListener listener;
|
private TcpListener listener;
|
||||||
private List<Client> clients;
|
private List<Client> clients;
|
||||||
public Client doctor;
|
private Client mDoctor;
|
||||||
|
public Client Doctor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.mDoctor;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.mDoctor = value;
|
||||||
|
this.clients.ForEach((client) =>
|
||||||
|
{
|
||||||
|
var dinges = DataParser.getNewConnectionJson(client.username);
|
||||||
|
Debug.WriteLine("foreach " + Encoding.ASCII.GetString(dinges));
|
||||||
|
this.mDoctor.sendMessage(dinges);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
public Communication(TcpListener listener)
|
public Communication(TcpListener listener)
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
@@ -34,7 +52,7 @@ namespace Server
|
|||||||
|
|
||||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||||
clients.Add(new Client(this, tcpClient));
|
new Client(this, tcpClient);
|
||||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,15 +63,19 @@ namespace Server
|
|||||||
|
|
||||||
public void NewLogin(Client client)
|
public void NewLogin(Client client)
|
||||||
{
|
{
|
||||||
if (doctor == null)
|
clients.Add(client);
|
||||||
|
var dinges = DataParser.getNewConnectionJson(client.username);
|
||||||
|
Debug.WriteLine("new login" + Encoding.ASCII.GetString(dinges));
|
||||||
|
Doctor?.sendMessage(dinges);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LogOff(Client client)
|
||||||
|
{
|
||||||
|
if (this.Doctor == client)
|
||||||
{
|
{
|
||||||
doctor = client;
|
this.Doctor = null;
|
||||||
}
|
}
|
||||||
else
|
this.clients.Remove(client);
|
||||||
{
|
|
||||||
doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user