Merge remote-tracking branch 'origin/develop' into dataOnTabs
This commit is contained in:
@@ -34,7 +34,7 @@ namespace Server
|
||||
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead))
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
||||
return;
|
||||
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
@@ -65,6 +65,8 @@ namespace Server
|
||||
}
|
||||
}
|
||||
|
||||
if (ar == null || (!ar.IsCompleted) || (!this.stream.CanRead) || !this.tcpClient.Client.Connected)
|
||||
return;
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
@@ -117,11 +119,16 @@ namespace Server
|
||||
this.communication.StopSessionUser(DataParser.getUsernameFromJson(payloadbytes));
|
||||
break;
|
||||
case DataParser.SET_RESISTANCE:
|
||||
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
//bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
|
||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||
//set resistance on doctor GUI
|
||||
|
||||
break;
|
||||
case DataParser.DISCONNECT:
|
||||
communication.Disconnect(this);
|
||||
communication.LogOff(this);
|
||||
break;
|
||||
case DataParser.MESSAGE:
|
||||
communication.SendMessageToClient(DataParser.getUsernameFromJson(payloadbytes), message);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
|
||||
@@ -19,10 +19,12 @@ namespace Server
|
||||
set
|
||||
{
|
||||
this.mDoctor = value;
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
});
|
||||
if (this.mDoctor != null)
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
this.mDoctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
client.sendMessage(DataParser.getNewConnectionJson(this.mDoctor.username));
|
||||
});
|
||||
}
|
||||
}
|
||||
public Communication(TcpListener listener)
|
||||
@@ -49,24 +51,27 @@ namespace Server
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
internal void Disconnect(Client client)
|
||||
{
|
||||
clients.Remove(client);
|
||||
Doctor.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||
}
|
||||
|
||||
public void NewLogin(Client client)
|
||||
{
|
||||
this.clients.Add(client);
|
||||
Doctor?.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
if (this.Doctor != null)
|
||||
{
|
||||
Doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
|
||||
client.sendMessage(DataParser.getNewConnectionJson(Doctor.username));
|
||||
}
|
||||
}
|
||||
|
||||
public void LogOff(Client client)
|
||||
{
|
||||
if (this.Doctor == client)
|
||||
{
|
||||
this.clients.ForEach((client) =>
|
||||
{
|
||||
client.sendMessage(DataParser.getDisconnectJson(this.mDoctor.username));
|
||||
});
|
||||
this.Doctor = null;
|
||||
}
|
||||
Doctor?.sendMessage(DataParser.getDisconnectJson(client.username));
|
||||
this.clients.Remove(client);
|
||||
}
|
||||
|
||||
@@ -94,5 +99,16 @@ namespace Server
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SendMessageToClient(string user, byte[] message)
|
||||
{
|
||||
foreach (Client c in clients)
|
||||
{
|
||||
if (c.username == user)
|
||||
{
|
||||
c.sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user