Exemplo n.º 1
0
        public static List <MyEntityListInfoItem> GetEntityList(MyEntityTypeEnum selectedType)
        {
            MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();
            List <MyEntityListInfoItem>    list          = new List <MyEntityListInfoItem>(entities.Count);
            ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();

            switch (selectedType)
            {
            case MyEntityTypeEnum.Grids:
            case MyEntityTypeEnum.SmallGrids:
            case MyEntityTypeEnum.LargeGrids:
                foreach (MyCubeGrid grid in entities)
                {
                    if (grid == null)
                    {
                        continue;
                    }
                    if (((selectedType != MyEntityTypeEnum.LargeGrids) || (grid.GridSizeEnum != MyCubeSize.Small)) && ((((selectedType != MyEntityTypeEnum.SmallGrids) || (grid.GridSizeEnum != MyCubeSize.Large)) && (!grid.Closed && (grid.Physics != null))) && ReferenceEquals(MyGridPhysicalHierarchy.Static.GetRoot(grid), grid)))
                    {
                        CreateListInfoForGrid(grid, out m_gridItem);
                        AccountChildren(grid);
                        list.Add(m_gridItem);
                    }
                }
                return(list);

            case MyEntityTypeEnum.Characters:
                break;

            case MyEntityTypeEnum.FloatingObjects:
                foreach (MyEntity entity in entities)
                {
                    MyFloatingObject obj2 = entity as MyFloatingObject;
                    if (obj2 != null)
                    {
                        if (obj2.Closed)
                        {
                            continue;
                        }
                        if (obj2.Physics == null)
                        {
                            continue;
                        }
                        list.Add(new MyEntityListInfoItem(obj2.DisplayName, obj2.EntityId, 0, 0, obj2.Physics.Mass, obj2.PositionComp.GetPosition(), obj2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(obj2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                    MyInventoryBagEntity entity2 = entity as MyInventoryBagEntity;
                    if (((entity2 != null) && !entity2.Closed) && (entity2.Physics != null))
                    {
                        MyIdentity identity2   = MySession.Static.Players.TryGetIdentity(entity2.OwnerIdentityId);
                        string     ownerName   = "";
                        float      ownerLogin  = 0f;
                        float      ownerLogout = 0f;
                        if (identity2 != null)
                        {
                            ownerName   = identity2.DisplayName;
                            ownerLogin  = (int)(DateTime.Now - identity2.LastLoginTime).TotalSeconds;
                            ownerLogout = (int)(DateTime.Now - identity2.LastLogoutTime).TotalSeconds;
                        }
                        list.Add(new MyEntityListInfoItem(entity2.DisplayName, entity2.EntityId, 0, 0, entity2.Physics.Mass, entity2.PositionComp.GetPosition(), entity2.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(entity2, onlinePlayers), ownerName, entity2.OwnerIdentityId, ownerLogin, ownerLogout));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Planets:
                foreach (MyPlanet planet in entities)
                {
                    if (planet == null)
                    {
                        continue;
                    }
                    if (!planet.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(planet.StorageName, planet.EntityId, 0, 0, 0f, planet.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(planet, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            case MyEntityTypeEnum.Asteroids:
                foreach (MyVoxelBase base2 in entities)
                {
                    if (base2 == null)
                    {
                        continue;
                    }
                    if (!(base2 is MyPlanet) && !base2.Closed)
                    {
                        list.Add(new MyEntityListInfoItem(base2.StorageName, base2.EntityId, 0, 0, 0f, base2.PositionComp.GetPosition(), 0f, MySession.GetPlayerDistance(base2, onlinePlayers), "", 0L, 0f, 0f));
                    }
                }
                return(list);

            default:
                throw new ArgumentOutOfRangeException();
            }
            foreach (MyIdentity identity in MySession.Static.Players.GetAllIdentities())
            {
                MyPlayer.PlayerId id;
                string            displayName = identity.DisplayName;
                if (Sync.Players.TryGetPlayerId(identity.IdentityId, out id))
                {
                    MyPlayer player = null;
                    if (!Sync.Players.TryGetPlayerById(id, out player))
                    {
                        object[] objArray1 = new object[] { displayName, " (", MyTexts.Get(MyCommonTexts.OfflineStatus), ")" };
                        displayName = string.Concat(objArray1);
                    }
                }
                if (identity.Character != null)
                {
                    list.Add(new MyEntityListInfoItem(displayName, identity.Character.EntityId, 0, 0, identity.Character.CurrentMass, identity.Character.PositionComp.GetPosition(), identity.Character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                }
                else
                {
                    foreach (long num in identity.SavedCharacters)
                    {
                        MyCharacter character;
                        if (MyEntities.TryGetEntityById <MyCharacter>(num, out character, false))
                        {
                            list.Add(new MyEntityListInfoItem(displayName, num, 0, 0, character.CurrentMass, character.PositionComp.GetPosition(), character.Physics.LinearVelocity.Length(), 0f, identity.DisplayName, identity.IdentityId, (float)((int)(DateTime.Now - identity.LastLoginTime).TotalSeconds), (float)((int)(DateTime.Now - identity.LastLogoutTime).TotalSeconds)));
                        }
                    }
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        private static void CreateListInfoForGrid(MyCubeGrid grid, out MyEntityListInfoItem item)
        {
            long   owner     = 0L;
            string ownerName = string.Empty;

            if (grid.BigOwners.Count > 0)
            {
                MyIdentity identity = MySession.Static.Players.TryGetIdentity(grid.BigOwners[0]);
                if (identity != null)
                {
                    ownerName = identity.DisplayName;
                    owner     = grid.BigOwners[0];
                }
            }
            item = new MyEntityListInfoItem(grid.DisplayName, grid.EntityId, grid.BlocksCount, grid.BlocksPCU, grid.Physics.Mass, grid.PositionComp.GetPosition(), grid.Physics.LinearVelocity.Length(), MySession.GetPlayerDistance(grid, MySession.Static.Players.GetOnlinePlayers()), ownerName, owner, MySession.GetOwnerLoginTimeSeconds(grid), MySession.GetOwnerLogoutTimeSeconds(grid));
        }
Exemplo n.º 3
0
        public string SendHttpResponseResponse(HttpListenerRequest request)
        {
            StringBuilder sb     = new StringBuilder();
            JsonWriter    writer = new JsonWriter(sb);

            switch (request.Url.AbsolutePath)
            {
            //case "/gc/collect/0":
            //    GC.Collect(0);
            //    break;
            //case "/gc/collect/1":
            //    GC.Collect(1);
            //    break;
            //case "/gc/collect/2":
            //    GC.Collect(2);
            //    break;
            case "/metrics/v1/server":
                int    usedPCU            = 0;
                int    maxPlayers         = 0;
                int    maxFactionCount    = 0;
                int    maxFloatingObjects = 0;
                int    maxGridSize        = 0;
                int    maxBlocksPerPlayer = 0;
                string blockLimit         = "";
                int    totalPCU           = 0;
                int    modCount           = 0;
                if (MySession.Static != null)
                {
                    if (MySession.Static.GlobalBlockLimits != null)
                    {
                        usedPCU = MySession.Static.GlobalBlockLimits.PCUBuilt;
                    }
                    maxPlayers         = MySession.Static.MaxPlayers;
                    maxFactionCount    = MySession.Static.MaxFactionsCount;
                    maxFloatingObjects = MySession.Static.MaxFloatingObjects;
                    maxGridSize        = MySession.Static.MaxGridSize;
                    maxBlocksPerPlayer = MySession.Static.MaxBlocksPerPlayer;
                    totalPCU           = MySession.Static.TotalPCU;
                    modCount           = MySession.Static.Mods.Count;
                    switch (MySession.Static.BlockLimitsEnabled)
                    {
                    case MyBlockLimitsEnabledEnum.GLOBALLY:
                        blockLimit = "globally";
                        break;

                    case MyBlockLimitsEnabledEnum.NONE:
                        blockLimit = "none";
                        break;

                    case MyBlockLimitsEnabledEnum.PER_FACTION:
                        blockLimit = "faction";
                        break;

                    case MyBlockLimitsEnabledEnum.PER_PLAYER:
                        blockLimit = "player";
                        break;
                    }
                }
                writer.WriteObjectStart();
                writer.WritePropertyName("Version");
                writer.Write(MyFinalBuildConstants.APP_VERSION_STRING_DOTS.ToString());
                writer.WritePropertyName("ServerName");
                writer.Write(MySandboxGame.ConfigDedicated.ServerName);
                writer.WritePropertyName("WorldName");
                writer.Write(MySandboxGame.ConfigDedicated.WorldName);
                writer.WritePropertyName("IsReady");
                writer.Write(MySession.Static != null && MySession.Static.Ready);
                writer.WritePropertyName("SimSpeed");
                writer.Write(Sync.ServerSimulationRatio);
                writer.WritePropertyName("SimulationCpuLoad");
                writer.Write((float)(int)Sync.ServerCPULoad);
                writer.WritePropertyName("TotalTime");
                writer.Write(MySandboxGame.TotalTimeInMilliseconds / 1000);
                writer.WritePropertyName("Players");
                writer.Write((Sync.Clients != null) ? (Sync.Clients.Count - 1) : 0);
                writer.WritePropertyName("UsedPCU");
                writer.Write(usedPCU);
                writer.WritePropertyName("MaxPlayers");
                writer.Write(maxPlayers);
                writer.WritePropertyName("MaxFactionsCount");
                writer.Write(maxFactionCount);
                writer.WritePropertyName("MaxFloatingObjects");
                writer.Write(maxFloatingObjects);
                writer.WritePropertyName("MaxGridSize");
                writer.Write(maxGridSize);
                writer.WritePropertyName("MaxBlocksPerPlayer");
                writer.Write(maxBlocksPerPlayer);
                writer.WritePropertyName("BlockLimitsEnabled");
                writer.Write(blockLimit);
                writer.WritePropertyName("TotalPCU");
                writer.Write(totalPCU);
                writer.WritePropertyName("ModCount");
                writer.Write(modCount);
                writer.WritePropertyName("SaveDuration");
                writer.Write(saveDuration);
                writer.WriteObjectEnd();
                break;

            case "/metrics/v1/load":
                writer.WriteArrayStart();
                LoadEvent loadEv;
                while (!loadEvents.Empty)
                {
                    if (loadEvents.TryDequeueBack(out loadEv))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("ServerCPULoad");
                        writer.Write(loadEv.ServerCPULoad);
                        writer.WritePropertyName("ServerCPULoadSmooth");
                        writer.Write(loadEv.ServerCPULoadSmooth);
                        writer.WritePropertyName("ServerSimulationRatio");
                        writer.Write(loadEv.ServerSimulationRatio);
                        writer.WritePropertyName("ServerThreadLoad");
                        writer.Write(loadEv.ServerThreadLoad);
                        writer.WritePropertyName("ServerThreadLoadSmooth");
                        writer.Write(loadEv.ServerThreadLoadSmooth);
                        writer.WritePropertyName("MillisecondsInThePast");
                        writer.Write((DateTime.Now - loadEv.Occurred).TotalMilliseconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/process":
                System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
                writer.WriteObjectStart();
                writer.WritePropertyName("PrivateMemorySize64");
                writer.Write(currentProcess.PrivateMemorySize64);
                writer.WritePropertyName("VirtualMemorySize64");
                writer.Write(currentProcess.VirtualMemorySize64);
                writer.WritePropertyName("WorkingSet64");
                writer.Write(currentProcess.WorkingSet64);
                writer.WritePropertyName("NonpagedSystemMemorySize64");
                writer.Write(currentProcess.NonpagedSystemMemorySize64);
                writer.WritePropertyName("PagedMemorySize64");
                writer.Write(currentProcess.PagedMemorySize64);
                writer.WritePropertyName("PagedSystemMemorySize64");
                writer.Write(currentProcess.PagedSystemMemorySize64);
                writer.WritePropertyName("PeakPagedMemorySize64");
                writer.Write(currentProcess.PeakPagedMemorySize64);
                writer.WritePropertyName("PeakVirtualMemorySize64");
                writer.Write(currentProcess.PeakVirtualMemorySize64);
                writer.WritePropertyName("PeakWorkingSet64");
                writer.Write(currentProcess.PeakWorkingSet64);
                writer.WritePropertyName("GCLatencyMode");
                writer.Write((int)System.Runtime.GCSettings.LatencyMode);
                writer.WritePropertyName("GCIsServerGC");
                writer.Write(System.Runtime.GCSettings.IsServerGC);
                writer.WritePropertyName("GCTotalMemory");
                writer.Write(GC.GetTotalMemory(false));
                writer.WritePropertyName("GCMaxGeneration");
                writer.Write(GC.MaxGeneration);
                writer.WritePropertyName("GCCollectionCount0");
                writer.Write(GC.CollectionCount(0));
                writer.WritePropertyName("GCCollectionCount1");
                writer.Write(GC.CollectionCount(1));
                writer.WritePropertyName("GCCollectionCount2");
                writer.Write(GC.CollectionCount(2));
                writer.WriteObjectEnd();
                break;

            case "/metrics/v1/events":
                writer.WriteArrayStart();
                Event ev;
                while (!events.Empty)
                {
                    if (events.TryDequeueBack(out ev))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("Type");
                        writer.Write(ev.Type);
                        writer.WritePropertyName("Text");
                        writer.Write(ev.Text);
                        writer.WritePropertyName("Tags");
                        writer.WriteArrayStart();
                        foreach (var tag in ev.Tags)
                        {
                            writer.Write(tag);
                        }
                        writer.WriteArrayEnd();
                        writer.WritePropertyName("SecondsInThePast");
                        writer.Write((DateTime.Now - ev.Occurred).TotalSeconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/players":
                writer.WriteArrayStart();
                PlayerEvent playerEv;
                while (!playerEvents.Empty)
                {
                    if (playerEvents.TryDequeueBack(out playerEv))
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("Type");
                        writer.Write(playerEv.Type);
                        writer.WritePropertyName("SteamId");
                        writer.Write(playerEv.SteamId);
                        writer.WritePropertyName("MillisecondsInThePast");
                        writer.Write((DateTime.Now - playerEv.Occurred).TotalMilliseconds);
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/grids":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();
                    MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();

                    Type      type  = typeof(MyEntities);
                    FieldInfo info  = type.GetField("m_entitiesForUpdateOnce", BindingFlags.NonPublic | BindingFlags.Static);
                    object    value = info.GetValue(null);
                    CachingList <MyEntity> m_entitiesForUpdateOnce = value as CachingList <MyEntity>;
                    List <long>            x_entitiesForUpdateOnce = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <ConcurrentCachingList <MyEntity>, MyEntity> m_entitiesForUpdate = value as MyDistributedUpdater <ConcurrentCachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate10", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForUpdate10 = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate10 = new List <long>();

                    info  = type.GetField("m_entitiesForUpdate100", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForUpdate100 = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForUpdate100 = new List <long>();

                    info  = type.GetField("m_entitiesForSimulate", BindingFlags.NonPublic | BindingFlags.Static);
                    value = info.GetValue(null);
                    MyDistributedUpdater <CachingList <MyEntity>, MyEntity> m_entitiesForSimulate = value as MyDistributedUpdater <CachingList <MyEntity>, MyEntity>;
                    List <long> x_entitiesForSimulate = new List <long>();

                    Torch.InvokeBlocking(() =>
                    {
                        x_entitiesForUpdateOnce = m_entitiesForUpdateOnce.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate     = m_entitiesForUpdate.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate10   = m_entitiesForUpdate10.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForUpdate100  = m_entitiesForUpdate100.List.Select((x) => x.EntityId).ToList();
                        x_entitiesForSimulate   = m_entitiesForSimulate.List.Select((x) => x.EntityId).ToList();
                    });

                    bool IsConcealed(MyCubeGrid grid)
                    {
                        int NeedsUpdateMatches = 0;
                        int RegistedMatches    = 0;

                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.BEFORE_NEXT_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdateOnce.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_10TH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate10.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.EACH_100TH_FRAME) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForUpdate100.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }
                        if ((grid.NeedsUpdate & MyEntityUpdateEnum.SIMULATE) > MyEntityUpdateEnum.NONE)
                        {
                            NeedsUpdateMatches++;
                            if (x_entitiesForSimulate.Any((x) => x == grid.EntityId))
                            {
                                RegistedMatches++;
                            }
                        }

                        return(NeedsUpdateMatches > 0 && RegistedMatches == 0);
                    }

                    foreach (MyEntity item in entities)
                    {
                        MyCubeGrid myCubeGrid = item as MyCubeGrid;
                        if (myCubeGrid != null && !myCubeGrid.Closed && myCubeGrid.Physics != null)
                        {
                            long   steamId       = 0L;
                            string displayName   = string.Empty;
                            string factionTag    = string.Empty;
                            string factionName   = string.Empty;
                            long   groupEntityId = 0L;
                            if (myCubeGrid.BigOwners.Count > 0)
                            {
                                steamId = myCubeGrid.BigOwners[0];

                                MyIdentity myIdentity = MySession.Static.Players.TryGetIdentity(steamId);
                                if (myIdentity != null)
                                {
                                    displayName = myIdentity.DisplayName;
                                }

                                IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(steamId);
                                if (myFaction != null)
                                {
                                    factionTag  = myFaction.Tag;
                                    factionName = myFaction.Name;
                                }
                            }

                            foreach (var group in MyCubeGridGroups.Static.Physical.Groups)
                            {
                                bool found = false;

                                foreach (var node in group.Nodes)
                                {
                                    if (node.NodeData != myCubeGrid)
                                    {
                                        continue;
                                    }

                                    groupEntityId = group.Nodes.OrderByDescending(x => x.NodeData.BlocksCount).First().NodeData.EntityId;
                                    found         = true;
                                    break;
                                }

                                if (found)
                                {
                                    break;
                                }
                            }

                            int conveyorInventoryBlockCount = 0;
                            int conveyorEndpointBlockCount  = 0;
                            int conveyorLineCount           = 0;
                            int conveyorConnectorCount      = 0;
                            if (myCubeGrid?.GridSystems?.ConveyorSystem != null)
                            {
                                type = myCubeGrid.GridSystems.ConveyorSystem.GetType();
                                conveyorInventoryBlockCount = (type.GetField("m_inventoryBlocks", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyCubeBlock>).Count;
                                conveyorEndpointBlockCount  = (type.GetField("m_conveyorEndpointBlocks", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <IMyConveyorEndpointBlock>).Count;
                                conveyorLineCount           = (type.GetField("m_lines", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyConveyorLine>).Count;
                                conveyorConnectorCount      = (type.GetField("m_connectors", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(myCubeGrid.GridSystems.ConveyorSystem) as HashSet <MyShipConnector>).Count;
                            }

                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(myCubeGrid.DisplayName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(myCubeGrid.EntityId);
                            writer.WritePropertyName("PhysicsGroupEntityId");
                            writer.Write(groupEntityId);
                            writer.WritePropertyName("GridSize");
                            writer.Write(myCubeGrid.GridSizeEnum == MyCubeSize.Large ? "Large" : "Small");
                            writer.WritePropertyName("BlocksCount");
                            writer.Write(myCubeGrid.BlocksCount);
                            writer.WritePropertyName("Mass");
                            writer.Write(myCubeGrid.Physics.Mass);
                            writer.WritePropertyName("LinearSpeed");
                            writer.Write(myCubeGrid.Physics.LinearVelocity.Length());
                            writer.WritePropertyName("DistanceToPlayer");
                            writer.Write(MySession.GetPlayerDistance(myCubeGrid, onlinePlayers));
                            writer.WritePropertyName("OwnerSteamId");
                            writer.Write(steamId);
                            writer.WritePropertyName("OwnerDisplayName");
                            writer.Write(displayName);
                            writer.WritePropertyName("OwnerFactionTag");
                            writer.Write(factionTag);
                            writer.WritePropertyName("OwnerFactionName");
                            writer.Write(factionName);
                            writer.WritePropertyName("IsPowered");
                            writer.Write(myCubeGrid.GridSystems.ResourceDistributor.ResourceStateByType(MyResourceDistributorComponent.ElectricityId, withRecompute: false) != MyResourceStateEnum.NoPower);
                            writer.WritePropertyName("PCU");
                            writer.Write(myCubeGrid.BlocksPCU);
                            writer.WritePropertyName("IsConcealed");
                            writer.Write(IsConcealed(myCubeGrid));
                            writer.WritePropertyName("DampenersEnabled");
                            writer.Write(myCubeGrid.DampenersEnabled);
                            writer.WritePropertyName("IsStatic");
                            writer.Write(myCubeGrid.Physics.IsStatic);
                            writer.WritePropertyName("ConveyorSystemInventoryBlockCount");
                            writer.Write(conveyorInventoryBlockCount);
                            writer.WritePropertyName("ConveyorSystemEndpointBlockCount");
                            writer.Write(conveyorEndpointBlockCount);
                            writer.WritePropertyName("ConveyorSystemLineCount");
                            writer.Write(conveyorLineCount);
                            writer.WritePropertyName("ConveyorSystemConnectorCount");
                            writer.Write(conveyorConnectorCount);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/asteroids":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    MyConcurrentHashSet <MyEntity> entities = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyVoxelBase myVoxelBase = item as MyVoxelBase;
                        if (myVoxelBase != null && !(myVoxelBase is MyPlanet) && !myVoxelBase.Closed)
                        {
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(myVoxelBase.StorageName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(myVoxelBase.EntityId);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/planets":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    MyConcurrentHashSet <MyEntity> entities = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyPlanet myPlanet = item as MyPlanet;
                        if (myPlanet != null && !myPlanet.Closed)
                        {
                            string storageName = myPlanet.StorageName;
                            long   entityId    = myPlanet.EntityId;
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(storageName);
                            writer.WritePropertyName("EntityId");
                            writer.Write(entityId);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/floatingObjects":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    ICollection <MyPlayer>         onlinePlayers = MySession.Static.Players.GetOnlinePlayers();
                    MyConcurrentHashSet <MyEntity> entities      = MyEntities.GetEntities();
                    foreach (MyEntity item in entities)
                    {
                        MyFloatingObject     myFloatingObject     = item as MyFloatingObject;
                        MyInventoryBagEntity myInventoryBagEntity = item as MyInventoryBagEntity;
                        if (myFloatingObject != null || myInventoryBagEntity != null)
                        {
                            string value  = string.Empty;
                            long   value2 = 0L;
                            string value3 = string.Empty;
                            float  value4 = 0f;
                            float  value5 = 0f;
                            float  value6 = 0f;
                            string value7 = string.Empty;
                            if (myFloatingObject != null)
                            {
                                if (myFloatingObject.Closed || myFloatingObject.Physics == null)
                                {
                                    continue;
                                }
                                value  = myFloatingObject.DisplayName;
                                value2 = myFloatingObject.EntityId;
                                value3 = "FloatingObject";
                                value4 = myFloatingObject.Physics.Mass;
                                value5 = myFloatingObject.Physics.LinearVelocity.Length();
                                value6 = MySession.GetPlayerDistance(myFloatingObject, onlinePlayers);
                                var def = MyDefinitionManager.Static.GetPhysicalItemDefinition(new MyDefinitionId(myFloatingObject.Item.Content.TypeId, myFloatingObject.Item.Content.SubtypeId));
                                value7 = def.DisplayNameText;
                            }
                            else if (myInventoryBagEntity != null)
                            {
                                if (myInventoryBagEntity.Closed || myInventoryBagEntity.Physics == null)
                                {
                                    continue;
                                }
                                value  = myInventoryBagEntity.DisplayName;
                                value2 = myInventoryBagEntity.EntityId;
                                value3 = "Bag";
                                value4 = myInventoryBagEntity.Physics.Mass;
                                value5 = myInventoryBagEntity.Physics.LinearVelocity.Length();
                                value6 = MySession.GetPlayerDistance(myInventoryBagEntity, onlinePlayers);
                                value7 = "Bag";
                            }
                            writer.WriteObjectStart();
                            writer.WritePropertyName("DisplayName");
                            writer.Write(value);
                            writer.WritePropertyName("EntityId");
                            writer.Write(value2);
                            writer.WritePropertyName("Kind");
                            writer.Write(value3);
                            writer.WritePropertyName("Mass");
                            writer.Write(value4);
                            writer.WritePropertyName("LinearSpeed");
                            writer.Write(value5);
                            writer.WritePropertyName("DistanceToPlayer");
                            writer.Write(value6);
                            writer.WritePropertyName("TypeDisplayName");
                            writer.Write(value7);
                            writer.WriteObjectEnd();
                        }
                    }
                }
                writer.WriteArrayEnd();
                break;

            case "/metrics/v1/session/factions":
                writer.WriteArrayStart();
                if (MySession.Static != null && MySession.Static.Ready)
                {
                    List <MyFaction> factions = MySession.Static.Factions.Select((x) => x.Value).ToList();
                    foreach (MyFaction myfaction in factions)
                    {
                        writer.WriteObjectStart();
                        writer.WritePropertyName("AcceptHumans");
                        writer.Write(myfaction.AcceptHumans);
                        writer.WritePropertyName("AutoAcceptMember");
                        writer.Write(myfaction.AutoAcceptMember);
                        writer.WritePropertyName("AutoAcceptPeace");
                        writer.Write(myfaction.AutoAcceptPeace);
                        writer.WritePropertyName("EnableFriendlyFire");
                        writer.Write(myfaction.EnableFriendlyFire);
                        writer.WritePropertyName("FactionId");
                        writer.Write(myfaction.FactionId);
                        writer.WritePropertyName("FounderId");
                        writer.Write(myfaction.FounderId);
                        writer.WritePropertyName("MemberCount");
                        writer.Write(myfaction.Members.Count);
                        writer.WritePropertyName("Name");
                        writer.Write(myfaction.Name);
                        writer.WritePropertyName("Tag");
                        writer.Write(myfaction.Tag);
                        writer.WritePropertyName("NPCOnly");
                        writer.Write(myfaction.Members.All((x) => MySession.Static.Players.IdentityIsNpc(x.Value.PlayerId)));
                        writer.WriteObjectEnd();
                    }
                }
                writer.WriteArrayEnd();
                break;
            }

            return(sb.ToString());
        }