# HG changeset patch # User Stephane Lenclud # Date 1453760195 -3600 # Node ID e10744f29ef3ced96479282f0b6dccda20673fe1 # Parent 729e91c7d5b295d2a62eff5982ad13b507c67ac3 Published v0.8.5.0 Now properly work out current client based on priorities when a client connects, disconnects or change its priority. diff -r 729e91c7d5b2 -r e10744f29ef3 Server/MainForm.cs --- a/Server/MainForm.cs Mon Jan 25 21:26:30 2016 +0100 +++ b/Server/MainForm.cs Mon Jan 25 23:16:35 2016 +0100 @@ -1494,6 +1494,25 @@ } } + + /// + /// Find the client with the highest priority if any. + /// + /// Our highest priority client or null if not a single client is connected. + public ClientData FindHighestPriorityClient() + { + ClientData highestPriorityClient = null; + foreach (var client in iClients) + { + if (highestPriorityClient == null || client.Value.Priority > highestPriorityClient.Priority) + { + highestPriorityClient = client.Value; + } + } + + return highestPriorityClient; + } + /// /// /// @@ -1516,7 +1535,19 @@ Program.iMainForm.treeViewClients.Nodes.Remove(Program.iMainForm.treeViewClients.Nodes.Find(aSessionId, false)[0]); } - if (iClients.Count == 0) + if (iCurrentClientSessionId == aSessionId) + { + //The current client is closing + iCurrentClientData = null; + //Find the client with the highest priority and set it as current + ClientData newCurrentClient = FindHighestPriorityClient(); + if (newCurrentClient!=null) + { + SetCurrentClient(newCurrentClient.SessionId, true); + } + } + + if (iClients.Count == 0) { //Clear our screen when last client disconnects ClearLayout(); @@ -1789,6 +1820,12 @@ client.Priority = aPriority; //Update our tree-view UpdateClientTreeViewNode(client); + //Change our current client as per new priority + ClientData newCurrentClient = FindHighestPriorityClient(); + if (newCurrentClient!=null) + { + SetCurrentClient(newCurrentClient.SessionId); + } } } } diff -r 729e91c7d5b2 -r e10744f29ef3 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Mon Jan 25 21:26:30 2016 +0100 +++ b/Server/SharpDisplayManager.csproj Mon Jan 25 23:16:35 2016 +0100 @@ -34,7 +34,7 @@ index.htm false 0 - 0.8.4.0 + 0.8.5.0 false true true