public override void Init(MyObjectBuilder_SessionComponent sessionComponent) { base.Init(sessionComponent); // Only servers can run this session component if(!Session.IsServer) return; MyObjectBuilder_VisualScriptManagerSessionComponent ob = (MyObjectBuilder_VisualScriptManagerSessionComponent) sessionComponent; m_objectBuilder = ob; m_relativePathsToAbsolute.Clear(); m_stateMachineDefinitionFilePaths.Clear(); // Runs game started event m_firstUpdate = ob.FirstRun; // load vanilla level script files if (ob.LevelScriptFiles != null) foreach (string relativeFilePath in ob.LevelScriptFiles) { var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath); // Add only existing files if(MyFileSystem.FileExists(absolutePath)) { m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath); } else { MyLog.Default.WriteLine(relativeFilePath + " Level Script was not found."); Debug.Fail(relativeFilePath + " Level Script was not found."); } } // load vanilla mission manchines if(ob.StateMachines != null) foreach (var relativeFilePath in ob.StateMachines) { var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath); // Add only existing files if (MyFileSystem.FileExists(absolutePath)) { if (!m_relativePathsToAbsolute.ContainsKey(relativeFilePath)) { m_stateMachineDefinitionFilePaths.Add(absolutePath); } m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath); } else { MyLog.Default.WriteLine(relativeFilePath + " Mission File was not found."); Debug.Fail(relativeFilePath + " Mission File was not found."); } } // Load mission machines and level scripts from mods // Overrides vanilla files if(Session.Mods != null) { foreach (var modItem in Session.Mods) { // First try is a mod archive var directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.PublishedFileId + ".sbm"); if (!MyFileSystem.DirectoryExists(directoryPath)) { directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.Name); if(!MyFileSystem.DirectoryExists(directoryPath)) directoryPath = null; } if (!string.IsNullOrEmpty(directoryPath)) { foreach (var filePath in MyFileSystem.GetFiles(directoryPath, "*", MySearchOption.AllDirectories)) { var extension = Path.GetExtension(filePath); var relativePath = MyFileSystem.MakeRelativePath(Path.Combine(directoryPath, "VisualScripts"), filePath); if (extension == ".vs" || extension == ".vsc") { if(m_relativePathsToAbsolute.ContainsKey(relativePath)) m_relativePathsToAbsolute[relativePath] = filePath; else m_relativePathsToAbsolute.Add(relativePath, filePath); } } } } } // Provider will compile all required scripts for the session. MyVSAssemblyProvider.Init(m_relativePathsToAbsolute.Values); // Retrive the Level script instances m_levelScripts = new CachingList<IMyLevelScript>(); var scriptInstances = MyVSAssemblyProvider.GetLevelScriptInstances(); if(scriptInstances != null) { scriptInstances.ForEach(script => m_levelScripts.Add(script)); } m_levelScripts.ApplyAdditions(); // Store the names of the level scripts m_runningLevelScriptNames = m_levelScripts.Select(x => x.GetType().Name).ToArray(); m_failedLevelScriptExceptionTexts = new string[m_runningLevelScriptNames.Length]; // mission manager initialization - state machine definitions m_smManager = new MyVSStateMachineManager(); foreach (var stateMachineFilePath in m_stateMachineDefinitionFilePaths) { m_smManager.AddMachine(stateMachineFilePath); } }
public override void Init(MyObjectBuilder_SessionComponent sessionComponent) { base.Init(sessionComponent); // Only servers can run this session component if (!Session.IsServer) { return; } MyObjectBuilder_VisualScriptManagerSessionComponent ob = (MyObjectBuilder_VisualScriptManagerSessionComponent)sessionComponent; m_objectBuilder = ob; m_relativePathsToAbsolute.Clear(); m_stateMachineDefinitionFilePaths.Clear(); // Runs game started event m_firstUpdate = ob.FirstRun; // load vanilla level script files if (ob.LevelScriptFiles != null) { foreach (string relativeFilePath in ob.LevelScriptFiles) { var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath); // Add only existing files if (MyFileSystem.FileExists(absolutePath)) { m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath); } else { MyLog.Default.WriteLine(relativeFilePath + " Level Script was not found."); Debug.Fail(relativeFilePath + " Level Script was not found."); } } } // load vanilla mission manchines if (ob.StateMachines != null) { foreach (var relativeFilePath in ob.StateMachines) { var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath); // Add only existing files if (MyFileSystem.FileExists(absolutePath)) { if (!m_relativePathsToAbsolute.ContainsKey(relativeFilePath)) { m_stateMachineDefinitionFilePaths.Add(absolutePath); } m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath); } else { MyLog.Default.WriteLine(relativeFilePath + " Mission File was not found."); Debug.Fail(relativeFilePath + " Mission File was not found."); } } } // Load mission machines and level scripts from mods // Overrides vanilla files if (Session.Mods != null) { foreach (var modItem in Session.Mods) { // First try is a mod archive var directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.PublishedFileId + ".sbm"); if (!MyFileSystem.DirectoryExists(directoryPath)) { directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.Name); if (!MyFileSystem.DirectoryExists(directoryPath)) { directoryPath = null; } } if (!string.IsNullOrEmpty(directoryPath)) { foreach (var filePath in MyFileSystem.GetFiles(directoryPath, "*", MySearchOption.AllDirectories)) { var extension = Path.GetExtension(filePath); var relativePath = MyFileSystem.MakeRelativePath(Path.Combine(directoryPath, "VisualScripts"), filePath); if (extension == ".vs" || extension == ".vsc") { if (m_relativePathsToAbsolute.ContainsKey(relativePath)) { m_relativePathsToAbsolute[relativePath] = filePath; } else { m_relativePathsToAbsolute.Add(relativePath, filePath); } } } } } } // Provider will compile all required scripts for the session. MyVSAssemblyProvider.Init(m_relativePathsToAbsolute.Values); // Retrive the Level script instances m_levelScripts = new CachingList <IMyLevelScript>(); var scriptInstances = MyVSAssemblyProvider.GetLevelScriptInstances(); if (scriptInstances != null) { scriptInstances.ForEach(script => m_levelScripts.Add(script)); } m_levelScripts.ApplyAdditions(); // Store the names of the level scripts m_runningLevelScriptNames = m_levelScripts.Select(x => x.GetType().Name).ToArray(); m_failedLevelScriptExceptionTexts = new string[m_runningLevelScriptNames.Length]; // mission manager initialization - state machine definitions m_smManager = new MyVSStateMachineManager(); foreach (var stateMachineFilePath in m_stateMachineDefinitionFilePaths) { m_smManager.AddMachine(stateMachineFilePath); } }
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()); }