Merge branch 'develop' into newDoctor

This commit is contained in:
fabjuuuh
2020-10-14 15:21:03 +02:00
20 changed files with 74 additions and 270 deletions

View File

@@ -4,6 +4,8 @@ using System.Net.Sockets;
using System.Text;
using Newtonsoft.Json;
using ClientApp.Utils;
using System.Diagnostics;
using Util;
namespace Server
{
@@ -93,28 +95,12 @@ namespace Server
switch (identifier)
{
case DataParser.LOGIN:
string username;
string password;
bool worked = DataParser.GetUsernamePassword(payloadbytes, out username, out password);
if (worked)
{
if (verifyLogin(username, password))
{
Console.WriteLine("Log in");
this.username = username;
sendMessage(DataParser.getLoginResponse("OK"));
sendMessage(DataParser.getStartSessionJson());
communication.NewLogin(this);
}
else
{
sendMessage(DataParser.getLoginResponse("wrong username or password"));
}
}
else
{
sendMessage(DataParser.getLoginResponse("invalid json"));
}
handleLogin(payloadbytes);
break;
case DataParser.LOGIN_DOCTOR:
handleLogin(payloadbytes);
communication.doctor = this;
Console.WriteLine("Set doctor to " + communication.doctor + " , this is " + this);
break;
case DataParser.START_SESSION:
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
@@ -123,7 +109,7 @@ namespace Server
this.saveData = null;
break;
case DataParser.SET_RESISTANCE:
worked = DataParser.getResistanceFromResponseJson(payloadbytes);
bool worked = DataParser.getResistanceFromResponseJson(payloadbytes);
Console.WriteLine($"set resistance worked is " + worked);
//set resistance on doctor GUI
break;
@@ -162,6 +148,32 @@ namespace Server
}
private void handleLogin(byte[] payloadbytes)
{
string username;
string password;
bool worked = DataParser.GetUsernamePassword(payloadbytes, out username, out password);
if (worked)
{
if (verifyLogin(username, password))
{
Console.WriteLine("Log in");
this.username = username;
sendMessage(DataParser.getLoginResponse("OK"));
sendMessage(DataParser.getStartSessionJson());
communication.NewLogin(this);
}
else
{
sendMessage(DataParser.getLoginResponse("wrong username or password"));
}
}
else
{
sendMessage(DataParser.getLoginResponse("invalid json"));
}
}
public void sendMessage(byte[] message)
{
stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Net.Sockets;
using System.Text;
using DoctorApp.Utils;
using Util;
namespace Server
{
@@ -12,7 +13,7 @@ namespace Server
{
private TcpListener listener;
private List<Client> clients;
private Client doctor;
public Client doctor;
public Communication(TcpListener listener)
{
this.listener = listener;