From 5bacfdc8cec1086f2e3b7e23976a601b9ebb8a10 Mon Sep 17 00:00:00 2001 From: shinichi Date: Fri, 16 Oct 2020 11:25:35 +0200 Subject: [PATCH] added so only one doctor can login to server --- Server/Client.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Server/Client.cs b/Server/Client.cs index 3843f52..2184dcf 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -100,9 +100,14 @@ namespace Server handleLogin(payloadbytes); break; case DataParser.LOGIN_DOCTOR: - handleLogin(payloadbytes); - communication.doctor = this; - Console.WriteLine("Set doctor to " + communication.doctor + " , this is " + this); + if (communication.doctor != null) + return; + + if (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")); @@ -150,7 +155,7 @@ namespace Server } - private void handleLogin(byte[] payloadbytes) + private bool handleLogin(byte[] payloadbytes) { string username; string password; @@ -164,6 +169,7 @@ namespace Server sendMessage(DataParser.getLoginResponse("OK")); sendMessage(DataParser.getStartSessionJson()); communication.NewLogin(this); + return true; } else { @@ -174,6 +180,7 @@ namespace Server { sendMessage(DataParser.getLoginResponse("invalid json")); } + return false; } public void sendMessage(byte[] message)