Esempio n. 1
0
        void DrawClientsList()
        {
            var clients = Server.Clients.ToList();

            // Resize window if number of connected clients changes
            if (clients.Count != numClientsDisplayed)
            {
                numClientsDisplayed = clients.Count;
                resized             = true;
            }
            // Get list of client descriptions
            IDictionary <IClient, string> clientDescriptions = new Dictionary <IClient, string> ();

            if (clients.Count > 0)
            {
                foreach (var client in clients)
                {
                    try {
                        var clientName = client.Name;
                        clientDescriptions [client] = (clientName.Length == 0 ? unknownClientNameText : clientName) + " @ " + client.Address;
                    } catch (ClientDisconnectedException) {
                    }
                }
            }

            // Display the list of clients
            if (clientDescriptions.Any())
            {
                foreach (var entry in clientDescriptions)
                {
                    var client      = entry.Key;
                    var description = entry.Value;
                    GUILayout.BeginHorizontal();
                    GUILayoutExtensions.Light(IsClientActive(client), lightStyle);
                    GUILayout.Label(description, stretchyLabelStyle);
                    if (GUILayout.Button(new GUIContent(Icons.Instance.ButtonDisconnectClient, "Disconnect client"),
                                         buttonStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                    {
                        if (Config.ConfirmRemoveClient)
                        {
                            ClientDisconnectDialog.Show(client);
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(noClientsConnectedText, labelStyle);
                GUILayout.EndHorizontal();
            }
        }
Esempio n. 2
0
 void DrawServerStatus()
 {
     GUILayoutExtensions.Light(Server.Running, lightStyle);
     if (Server.Running)
     {
         GUILayout.Label(serverOnlineText, stretchyLabelStyle);
     }
     else
     {
         GUILayout.Label(serverOfflineText, stretchyLabelStyle);
     }
 }
Esempio n. 3
0
        void DrawClients(IServer server)
        {
            var clients = server.Clients.ToList();
            IDictionary <IClient, string> clientDescriptions = new Dictionary <IClient, string> ();

            if (clients.Count > 0)
            {
                foreach (var client in clients)
                {
                    try {
                        var clientName = client.Name;
                        clientDescriptions [client] = (clientName.Length == 0 ? unknownClientNameText : clientName) + " @ " + client.Address;
                    } catch (ClientDisconnectedException) {
                    }
                }
            }

            if (clientDescriptions.Any())
            {
                foreach (var entry in clientDescriptions)
                {
                    var client      = entry.Key;
                    var description = entry.Value;
                    GUILayout.BeginHorizontal();
                    GUILayoutExtensions.Light(IsClientActive(client), lightStyle);
                    GUILayout.Label(description, stretchyLabelStyle);
                    if (GUILayout.Button(new GUIContent(Icons.Instance.ButtonDisconnectClient, "Disconnect client"),
                                         buttonStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                    {
                        if (config.Configuration.ConfirmRemoveClient)
                        {
                            ClientDisconnectDialog.Show(client);
                        }
                        else
                        {
                            client.Close();
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(noClientsConnectedText, labelStyle);
                GUILayout.EndHorizontal();
            }
        }
Esempio n. 4
0
        void DrawServer(Server.Server server, bool forceExpanded = false)
        {
            var running       = server.Running;
            var editingServer = editServers.ContainsKey(server.Id);
            var expanded      = forceExpanded || expandServers.Contains(server.Id);

            GUILayout.BeginHorizontal();
            if (!forceExpanded)
            {
                var icons = Icons.Instance;
                if (GUILayout.Button(new GUIContent(expanded ? icons.ButtonCollapse : icons.ButtonExpand, expanded ? "Collapse" : "Expand"),
                                     expandStyle, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                {
                    if (expanded)
                    {
                        expandServers.Remove(server.Id);
                    }
                    else
                    {
                        expandServers.Add(server.Id);
                    }
                    expanded = !expanded;
                    Resized  = true;
                }
            }
            GUILayoutExtensions.Light(running, lightStyle);
            if (!editingServer)
            {
                GUILayout.Label(server.Name, labelStyle);
            }
            else
            {
                editServers [server.Id].DrawName();
            }
            GUILayout.EndHorizontal();

            if (editingServer)
            {
                editServers [server.Id].Draw();
            }
            else if (expanded)
            {
                string protocol;
                if (server.Protocol == Protocol.ProtocolBuffersOverTCP)
                {
                    protocol = protobufOverTcpText;
                }
                else if (server.Protocol == Protocol.ProtocolBuffersOverWebsockets)
                {
                    protocol = protobufOverWebSocketsText;
                }
                else
                {
                    protocol = protobufOverSerialIOText;
                }
                GUILayout.Label(protocolText + protocol, labelStyle);
                foreach (var line in server.Address.Split('\n'))
                {
                    GUILayout.Label(line, labelStyle);
                }
                GUILayout.Label(server.Info, labelStyle);
                DrawClients(server);
            }

            GUILayout.BeginHorizontal();
            GUI.enabled = !editingServer;
            if (GUILayout.Button(running ? stopServerText : startServerText, buttonStyle))
            {
                Errors.Clear();
                Resized = true;
                EventHandlerExtensions.Invoke(running ? OnStopServerPressed : OnStartServerPressed, this, new ServerEventArgs(server));
            }
            GUI.enabled = !running;
            if (GUILayout.Button(editingServer ? saveServerText : editServerText, buttonStyle))
            {
                if (editingServer)
                {
                    var newServer = editServers[server.Id].Save();
                    if (newServer != null)
                    {
                        editServers.Remove(server.Id);
                        config.Configuration.ReplaceServer(newServer);
                        config.Save();
                        core.Replace(newServer.Create());
                    }
                }
                else
                {
                    editServers[server.Id] = new EditServer(this, config.Configuration.GetServer(server.Id));
                }
                Resized = true;
            }
            GUI.enabled = !editingServer && !running;
            if (GUILayout.Button(removeServerText, buttonStyle))
            {
                config.Configuration.RemoveServer(server.Id);
                config.Save();
                core.Remove(server.Id);
                Resized = true;
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }