diff --git a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs index 9147b61..9abc19d 100644 --- a/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs +++ b/ErgometerIPR/ErgometerDoctorApplication/MainClient.cs @@ -24,6 +24,8 @@ namespace ErgometerDoctorApplication public static string HOST = "127.0.0.1"; public static int PORT = 8888; + public static List backlog; + //Server information public static List clients; @@ -47,6 +49,7 @@ namespace ErgometerDoctorApplication users = new Dictionary(); activesessions = new Dictionary(); oldSessionsData = new List>(); + backlog = new List(); } public static bool Connect(string password, out string error) @@ -212,13 +215,20 @@ namespace ErgometerDoctorApplication private static void HandToClient(NetCommand command) { + bool handled = false; foreach (ClientThread cl in clients) { if (cl.Session == command.Session) { cl.HandleCommand(command); + handled = true; } } + + if(!handled) + { + backlog.Add(command); + } } public static void SendNetCommand(NetCommand command) @@ -240,6 +250,22 @@ namespace ErgometerDoctorApplication return false; } + private static List GetBacklogForSession(int session) + { + List temp = new List(); + + for(int i=backlog.Count-1; i>= 0; i--) + { + if (backlog[i].Session == session) + { + temp.Add(backlog[i]); + backlog.RemoveAt(i); + } + } + + return temp; + } + public static void StartNewClient(string name, int session) { if (IsSessionRunning(session)) @@ -254,6 +280,14 @@ namespace ErgometerDoctorApplication thread.IsBackground = true; thread.Start(); + Thread.Sleep(5); + + List sessionbacklog = GetBacklogForSession(session); + for (int i = sessionbacklog.Count - 1; i >= 0; i--) + { + cl.HandleCommand(sessionbacklog[i]); + } + Thread.Sleep(5); SendNetCommand(new NetCommand(NetCommand.RequestType.PERSONALDATA, session)); } diff --git a/ErgometerIPR/ErgometerServer/DoctorThread.cs b/ErgometerIPR/ErgometerServer/DoctorThread.cs index 3f9037f..8359a30 100644 --- a/ErgometerIPR/ErgometerServer/DoctorThread.cs +++ b/ErgometerIPR/ErgometerServer/DoctorThread.cs @@ -35,6 +35,7 @@ namespace ErgometerServer case NetCommand.CommandType.LOGOUT: running = false; client.Close(); + server.backlog.Clear(); Console.WriteLine("Doctor logged out"); break; case NetCommand.CommandType.CHAT: diff --git a/ErgometerIPR/ErgometerServer/Server.cs b/ErgometerIPR/ErgometerServer/Server.cs index 0c850d5..74c6d71 100644 --- a/ErgometerIPR/ErgometerServer/Server.cs +++ b/ErgometerIPR/ErgometerServer/Server.cs @@ -20,6 +20,7 @@ namespace ErgometerServer public static List clients = new List(); private DoctorThread doctor; public Dictionary users; + public List backlog = new List(); public Server() { @@ -62,13 +63,30 @@ namespace ErgometerServer Thread thread = new Thread(new ThreadStart(doctor.run)); thread.IsBackground = true; thread.Start(); + + foreach(NetCommand command in backlog) + { + SendToDoctor(command); + Thread.Sleep(5); + } + } + + public void RemoveBacklogDisconnectedClient(int session) + { + for(int i=backlog.Count - 1; i>= 0; i--) + { + if (backlog[i].Session == session) + backlog.RemoveAt(i); + } } public void SendToDoctor(NetCommand command) { if (doctor != null) - { doctor.sendToDoctor(command); + else + { + backlog.Add(command); } }