public GridStamp GenerateGridStamp() { GridStamp Stamp = new GridStamp(Grids); Stamp.UpdateBiggestGrid(BiggestGrid); return(Stamp); }
public int SyncWithDisk() { PlayerInfo Data; LoadInfoFile(out Data); string[] files = Directory.GetFiles(FolderPath, "*.sbc"); List <GridStamp> gridStamps = new List <GridStamp>(Data.Grids); int newGrids = 0; foreach (var f in files) { if (!f.EndsWith(".sbc")) { continue; } string gridName = Path.GetFileNameWithoutExtension(f); bool found = false; foreach (var stamp in gridStamps) { if (stamp.GridName == gridName) { found = true; gridStamps.Remove(stamp); break; } } if (found) { continue; } var newStamp = new GridStamp(); newStamp.GridName = gridName; newStamp.ForceSpawnNearPlayer = true; Data.Grids.Add(newStamp); newGrids++; } // delete stamps for grids no longer present foreach (var stamp in gridStamps) { Data.Grids.Remove(stamp); } SaveInfoFile(Data); Log.Info($"Deleted {gridStamps.Count} that weren't on disk for {SteamID}"); Log.Info($"Found {newGrids} that weren't registered for {SteamID}"); return(newGrids); }
private static void AutoHangarWorker() { //Significant performance increase Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <MyCubeGrid> ExportedGrids = new List <MyCubeGrid>(); List <long> ExportPlayerIdentities = new List <long>(); Log.Warn("AutoHangar: Getting Players!"); foreach (MyIdentity player in MySession.Static.Players.GetAllIdentities()) { if (player == null) { continue; } DateTime LastLogin; LastLogin = player.LastLoginTime; ulong SteamID = MySession.Static.Players.TryGetSteamId(player.IdentityId); if (SteamID == 0) { continue; } if (LastLogin.AddDays(Config.AutoHangarDayAmount) < DateTime.Now) { //AutoHangarBlacklist if (!Config.AutoHangarPlayerBlacklist.Any(x => x.SteamID == SteamID)) { ExportPlayerIdentities.Add(player.IdentityId); } } } Log.Warn("AutoHangar: Total players to check:" + ExportPlayerIdentities.Count()); int GridCounter = 0; //This gets all the grids foreach (long player in ExportPlayerIdentities) { ulong id = MySession.Static.Players.TryGetSteamId(player); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); ConcurrentBag <List <MyCubeGrid> > gridGroups = GridUtilities.FindGridList(player, false); //Log.Warn(player + ":" + gridGroups.Count); if (gridGroups.Count == 0) { continue; } long LargestGridID = 0; if (Config.KeepPlayersLargestGrid) { //First need to find their largets grid int BlocksCount = 0; foreach (List <MyCubeGrid> grids in gridGroups) { int GridBlockCounts = 0; int LargestSingleGridCount = 0; MyCubeGrid LargetsGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > LargestSingleGridCount) { LargestSingleGridCount = grid.BlocksCount; LargetsGrid = grid; } } GridBlockCounts = LargetsGrid.BlocksCount; if (GridBlockCounts > BlocksCount) { BlocksCount = GridBlockCounts; LargestGridID = LargetsGrid.EntityId; } } } if (gridGroups.Count == 0) { continue; } PlayerHangar PlayersHangar = new PlayerHangar(id, null); foreach (List <MyCubeGrid> grids in gridGroups) { if (grids.Count == 0) { continue; } if (grids[0].IsRespawnGrid && Config.DeleteRespawnPods) { grids[0].Close(); continue; } GridResult Result = new GridResult(); Result.Grids = grids; var BiggestGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } } Result.BiggestGrid = BiggestGrid; if (Config.KeepPlayersLargestGrid) { if (BiggestGrid.EntityId == LargestGridID) { //Skip players largest grid continue; } } //Grid Size Checks if (BiggestGrid.GridSizeEnum == MyCubeSize.Large) { if (BiggestGrid.IsStatic && !Config.AutoHangarStaticGrids) { continue; } else if (!BiggestGrid.IsStatic && !Config.AutoHangarLargeGrids) { continue; } } else if (BiggestGrid.GridSizeEnum == MyCubeSize.Small && !Config.AutoHangarSmallGrids) { continue; } GridStamp Stamp = Result.GenerateGridStamp(); GridUtilities.FormatGridName(PlayersHangar, Stamp); if (PlayersHangar.SaveGridsToFile(Result, Stamp.GridName)) { //Load player file and update! //Fill out grid info and store in file PlayersHangar.SaveGridStamp(Stamp, false, true); GridCounter++; Log.Info(Result.BiggestGrid.DisplayName + " was sent to Hangar due to inactivity!"); } else { Log.Info(Result.BiggestGrid.DisplayName + " FAILED to Hangar due to inactivity!"); } } //Save players file! PlayersHangar.SavePlayerFile(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Log.Warn("Finished Hangaring: " + GridCounter + " grids! Action took: " + ts.ToString()); }
public void HangarRemove(string NameOrSteamID, string GridNameOrNumber) { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); if (Utils.AdminTryGetPlayerSteamID(NameOrSteamID, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); if (!methods.LoadInfoFile(out PlayerInfo Data)) { return; } if (Int32.TryParse(GridNameOrNumber, out int result)) { if (result > Data.Grids.Count) { chat.Respond("This hangar slot is empty! Select a grid that is in the hangar!"); return; } if (result != 0) { GridStamp Grid = Data.Grids[result - 1]; Data.Grids.RemoveAt(result - 1); string path = Path.Combine(methods.FolderPath, Grid.GridName + ".sbc"); File.Delete(path); chat.Respond(string.Format("{0} was successfully deleted!", Grid.GridName)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } else if (result == 0) { int counter = 0; foreach (var grid in Data.Grids) { string path = Path.Combine(methods.FolderPath, grid.GridName + ".sbc"); File.Delete(path); counter++; } Data.Grids.Clear(); chat.Respond(string.Format("Successfully deleted {0} grids!", counter)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } } else { foreach (var grid in Data.Grids) { if (grid.GridName == GridNameOrNumber) { Data.Grids.Remove(grid); string path = Path.Combine(methods.FolderPath, grid.GridName + ".sbc"); File.Delete(path); chat.Respond(string.Format("{0} was successfully deleted!", grid.GridName)); FileSaver.Save(Path.Combine(methods.FolderPath, "PlayerInfo.json"), Data); return; } } } } }
public void HangarDetails(string NameOrSteamID, string GridNameOrNumber) { Parallel.Invoke(() => { if (!Plugin.Config.PluginEnabled) { return; } Chat chat = new Chat(Context, true); if (Utils.AdminTryGetPlayerSteamID(NameOrSteamID, chat, out ulong SteamID)) { GridMethods methods = new GridMethods(SteamID, Plugin.Config.FolderDirectory); methods.LoadInfoFile(out PlayerInfo Data); if (Int32.TryParse(GridNameOrNumber, out int result)) { GridStamp Grid = Data.Grids[result - 1]; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("__________•°•[ Ship Properties ]•°•__________"); stringBuilder.AppendLine("Estimated Market Value: " + Grid.MarketValue + " [sc]"); stringBuilder.AppendLine("GridMass: " + Grid.GridMass + "kg"); stringBuilder.AppendLine("Num of Small Grids: " + Grid.SmallGrids); stringBuilder.AppendLine("Num of Large Grids: " + Grid.LargeGrids); stringBuilder.AppendLine("Max Power Output: " + Grid.MaxPowerOutput); stringBuilder.AppendLine("Build Percentage: " + Math.Round(Grid.GridBuiltPercent * 100, 2) + "%"); stringBuilder.AppendLine("Max Jump Distance: " + Grid.JumpDistance); stringBuilder.AppendLine("Ship PCU: " + Grid.GridPCU); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("__________•°•[ Block Count ]•°•__________"); foreach (KeyValuePair <string, int> pair in Grid.BlockTypeCount) { stringBuilder.AppendLine(pair.Key + ": " + pair.Value); } if (Context.Player != null) { ModCommunication.SendMessageTo(new DialogMessage(Grid.GridName, $"Ship Information", stringBuilder.ToString()), Context.Player.SteamUserId); } else { chat.Respond(stringBuilder.ToString()); } } else { //Scan containg Grids if the user typed one foreach (var grid in Data.Grids) { if (grid.GridName == GridNameOrNumber) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("__________•°•[ Ship Properties ]•°•__________"); stringBuilder.AppendLine("Estimated Market Value: " + grid.MarketValue + " [sc]"); stringBuilder.AppendLine("GridMass: " + grid.GridMass + "kg"); stringBuilder.AppendLine("Num of Small Grids: " + grid.SmallGrids); stringBuilder.AppendLine("Num of Large Grids: " + grid.LargeGrids); stringBuilder.AppendLine("Max Power Output: " + grid.MaxPowerOutput); stringBuilder.AppendLine("Build Percentage: " + Math.Round(grid.GridBuiltPercent * 100, 2) + "%"); stringBuilder.AppendLine("Max Jump Distance: " + grid.JumpDistance); stringBuilder.AppendLine("Ship PCU: " + grid.GridPCU); stringBuilder.AppendLine(); stringBuilder.AppendLine(); stringBuilder.AppendLine("__________•°•[ Block Count ]•°•__________"); foreach (KeyValuePair <string, int> pair in grid.BlockTypeCount) { stringBuilder.AppendLine(pair.Key + ": " + pair.Value); } if (Context.Player != null) { ModCommunication.SendMessageTo(new DialogMessage(grid.GridName, $"Ship Information", stringBuilder.ToString()), Context.Player.SteamUserId); } else { chat.Respond(stringBuilder.ToString()); } // Context.Respond("You removed " + grid.GridName + " from the market!"); } } } } }); }
public static async Task <int> SaveAutohangarGrids(Dictionary <long, List <AutoHangarItem> > scannedGrids) { int GridCounter = 0; try { Watcher.Reset(); Watcher.Start(); //Now that we have our complete collection, lets loop through the grids foreach (KeyValuePair <long, List <AutoHangarItem> > kvp in scannedGrids) { List <AutoHangarItem> allGrids = kvp.Value; if (Config.KeepPlayersLargestGrid) { AutoHangarItem largest = allGrids.Aggregate((i1, i2) => i1.blocksCount > i2.blocksCount ? i1 : i2); allGrids.Remove(largest); } //No sense in running everything if this list is empty if (allGrids.Count == 0) { continue; } //Grab Players Hangar ulong id = MySession.Static.Players.TryGetSteamId(kvp.Key); PlayerHangar PlayersHangar = new PlayerHangar(id, null); foreach (AutoHangarItem item in allGrids) { //remove respawn grids if (item.largestGrid.IsRespawnGrid && Config.DeleteRespawnPods) { //Close all grids item.grids.Close("Autohangar deleted respawn pod"); continue; } GridResult Result = new GridResult(); Result.Grids = item.grids; Result.BiggestGrid = item.largestGrid; GridStamp Stamp = Result.GenerateGridStamp(); PlayersHangar.SelectedPlayerFile.FormatGridName(Stamp); bool val = await PlayersHangar.SaveGridsToFile(Result, Stamp.GridName); if (val) { //Load player file and update! //Fill out grid info and store in file PlayersHangar.SaveGridStamp(Stamp, false, true); GridCounter++; Log.Info(Result.BiggestGrid.DisplayName + " was sent to Hangar due to inactivity!"); } else { Log.Info(Result.BiggestGrid.DisplayName + " FAILED to Hangar! Check read error above for more info!"); } } PlayersHangar.SavePlayerFile(); } Watcher.Stop(); Log.Warn($"Finished Hangaring: {GridCounter} grids! Action took: {Watcher.Elapsed}"); return(GridCounter); } catch (Exception ex) { Log.Error(ex); } Watcher.Stop(); return(GridCounter); }