From 18dc45d604094f8bc190264117b99bd13bd43448 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Mon, 19 Oct 2015 22:25:57 +0200 Subject: [PATCH] Better connection handling --- ErgometerServer/ClientThread.cs | 13 +- ErgometerServer/DoctorThread.cs | 6 + ErgometerServer/ErgometerServer.csproj | 6 + ErgometerServer/FileHandler.cs | 165 +++++++++++++++++++++++++ ErgometerServer/Server.cs | 6 - ErgometerServer/packages.config | 4 + 6 files changed, 191 insertions(+), 9 deletions(-) create mode 100644 ErgometerServer/FileHandler.cs create mode 100644 ErgometerServer/packages.config diff --git a/ErgometerServer/ClientThread.cs b/ErgometerServer/ClientThread.cs index 1460881..e0cde8c 100644 --- a/ErgometerServer/ClientThread.cs +++ b/ErgometerServer/ClientThread.cs @@ -75,7 +75,6 @@ namespace ErgometerServer { name = input.DisplayName; loggedin = true; - Console.WriteLine(name + " (client) connected with password: " + input.Password); FileHandler.CreateSession(session, name); } } @@ -95,7 +94,6 @@ namespace ErgometerServer { chat.Add(new ChatMessage(name, input.ChatMessage, false)); server.SendToDoctor(input); - Console.WriteLine(name + ": " + input.ChatMessage); } else NetHelper.SendNetCommand(client, new NetCommand(NetCommand.ResponseType.NOTLOGGEDIN, session)); @@ -108,8 +106,17 @@ namespace ErgometerServer FileHandler.WriteChat(session, chat); client.Close(); break; + case NetCommand.CommandType.ERROR: + Console.WriteLine("An error occured, assuming client disconnected"); + loggedin = false; + running = false; + Console.WriteLine(name + " logged out due to an error"); + FileHandler.WriteMetingen(session, metingen); + FileHandler.WriteChat(session, chat); + client.Close(); + break; default: - throw new FormatException("Unknown command"); + throw new FormatException("Unknown command"); } } diff --git a/ErgometerServer/DoctorThread.cs b/ErgometerServer/DoctorThread.cs index 2dc6a40..f3ed1a4 100644 --- a/ErgometerServer/DoctorThread.cs +++ b/ErgometerServer/DoctorThread.cs @@ -100,6 +100,12 @@ namespace ErgometerServer throw new FormatException("Unknown Command"); } + break; + case NetCommand.CommandType.ERROR: + Console.WriteLine("An error occured, assuming docter disconnected"); + running = false; + Console.WriteLine("Doctor logged out due to an error"); + client.Close(); break; default: throw new FormatException("Unknown Command"); diff --git a/ErgometerServer/ErgometerServer.csproj b/ErgometerServer/ErgometerServer.csproj index 03ff5a0..67b48bc 100644 --- a/ErgometerServer/ErgometerServer.csproj +++ b/ErgometerServer/ErgometerServer.csproj @@ -37,6 +37,10 @@ False ..\..\..\ErgometerLibrary\ErgometerLibrary\ErgometerLibrary\bin\Debug\ErgometerLibrary.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True + @@ -49,11 +53,13 @@ + +