//Admin Commands public static void AdminSave(Hangar Plugin, CommandContext Context, string GridNameOrEntityID) { HangarChecks Checks = new HangarChecks(Context, Plugin, true); Task T = new Task(() => Checks.AdminSaveGrid(GridNameOrEntityID)); T.Start(); }
public static void AdminLoad(Hangar Plugin, CommandContext Context, string NameOrSteamID, string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin, true); Task T = new Task(() => Checks.AdminLoadGrid(NameOrSteamID, GridNameOrNumber)); T.Start(); }
public static void HangarDetails(Hangar Plugin, CommandContext Context, string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin); Task T = new Task(() => Checks.HangarInfo(GridNameOrNumber)); T.Start(); }
public static void RemoveOffer(Hangar Plugin, CommandContext Context, string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin); Task T = new Task(() => Checks.RemoveOffer(GridNameOrNumber)); T.Start(); }
public static void Sell(Hangar Plugin, CommandContext Context, string GridNameOrNumber, string Price, string Description) { HangarChecks Checks = new HangarChecks(Context, Plugin); Task T = new Task(() => Checks.SellGrid(GridNameOrNumber, Price, Description)); T.Start(); }
public static void List(Hangar Plugin, CommandContext Context) { HangarChecks Checks = new HangarChecks(Context, Plugin); Task T = new Task(() => Checks.ListGrids()); T.Start(); }
public static void LoadGrid(Hangar Plugin, CommandContext Context, string GridNameOrNumber, bool LoadAtSavePosition = false) { HangarChecks Checks = new HangarChecks(Context, Plugin); Task T = new Task(() => Checks.LoadGrid(GridNameOrNumber, LoadAtSavePosition)); T.Start(); }
public GridMethods(ulong UserSteamID, string FolderDirectory, HangarChecks checks = null) { FolderPath = Path.Combine(FolderDirectory, UserSteamID.ToString()); Directory.CreateDirectory(FolderPath); SteamID = UserSteamID; if (checks != null) { HangarChecker = checks; Context = checks.Context; Config = checks.Plugin.Config; chat = new Chat(Context, checks._Admin); } }
public void HangarDetails(string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.HangarInfo(GridNameOrNumber); }
private void UpdatePublicOffers() { //Update all public offer market items! if (!Hangar.IsRunning) { return; } //Need to remove existing ones string PublicOfferPath = Plugin.Market.ServerOffersDir; //Clear list GridMarket.PublicOfferseGridList.Clear(); foreach (PublicOffers offer in Plugin.Config.PublicOffers) { if (offer.Forsale && (offer.Name != null || offer.Name != "")) { string GridFilePath = System.IO.Path.Combine(PublicOfferPath, offer.Name + ".sbc"); Hangar.Debug("Blueprint Path: " + GridFilePath); MyObjectBuilderSerializer.DeserializeXML(GridFilePath, out MyObjectBuilder_Definitions myObjectBuilder_Definitions); MyObjectBuilder_ShipBlueprintDefinition[] shipBlueprint = null; try { shipBlueprint = myObjectBuilder_Definitions.ShipBlueprints; } catch { Hangar.Debug("Error on BP: " + offer.Name + "! Most likely you put in the SBC5 file! Dont do that!"); continue; } MyObjectBuilder_CubeGrid grid = shipBlueprint[0].CubeGrids[0]; byte[] Definition = MyAPIGateway.Utilities.SerializeToBinary(grid); HangarChecks.GetPublicOfferBPDetails(shipBlueprint, out GridStamp stamp); //Straight up add new ones MarketList NewList = new MarketList(); NewList.Steamid = 0; NewList.Name = offer.Name; NewList.Seller = offer.Seller; NewList.SellerFaction = offer.SellerFaction; NewList.Price = offer.Price; NewList.Description = offer.Description; NewList.GridDefinition = Definition; NewList.GridBuiltPercent = stamp.GridBuiltPercent; NewList.NumberofBlocks = stamp.NumberofBlocks; NewList.SmallGrids = stamp.SmallGrids; NewList.LargeGrids = stamp.LargeGrids; NewList.BlockTypeCount = stamp.BlockTypeCount; //Need to setTotalBuys GridMarket.PublicOfferseGridList.Add(NewList); Hangar.Debug("Adding new public offer: " + offer.Name); } } //Update Everything! Comms.SendListToModOnInitilize(); MarketData Data = new MarketData(); Data.List = GridMarket.PublicOfferseGridList; //Write to file FileSaver.Save(Plugin.Market.ServerMarketFileDir, Data); //File.WriteAllText(Main.ServerMarketFileDir, JsonConvert.SerializeObject(Data)); //This will force the market to update the market items }
public void GridSell(string GridNameOrNumber, string Price, string Description) { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.SellGrid(GridNameOrNumber, Price, Description); }
public void RemoveOffer(string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.RemoveOffer(GridNameOrNumber); }
public void List() { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.ListGrids(); }
public void delete(string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.DeleteGrid(GridNameOrNumber); }
public void Save() { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.SaveGrid(); }
public void Load(string GridNameOrNumber, bool LoadAtSavePosition = false) { HangarChecks Checks = new HangarChecks(Context, Plugin); Checks.LoadGrid(GridNameOrNumber, LoadAtSavePosition); }
public void AdminLoad(string NameOrSteamID, string GridNameOrNumber) { HangarChecks Checks = new HangarChecks(Context, Plugin, true); Checks.AdminLoadGrid(NameOrSteamID, GridNameOrNumber); }
public void AdminSave(string GridName = null) { HangarChecks Checks = new HangarChecks(Context, Plugin, true); Checks.AdminSaveGrid(GridName); }
private void UnderPlanetWorker(Hangar Plugin) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int GridCounter = 0; int TotalGridCounter = 0; Dictionary <long, List <Result> > ToSaveGrids = new Dictionary <long, List <Result> >(); Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group => { try { List <MyCubeGrid> gridList = new List <MyCubeGrid>(); var BiggestGrid = group.Nodes.First().NodeData; Result result = new Result(); foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Physics == null) { continue; } if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } TotalGridCounter += 1; gridList.Add(grid); } if (gridList.Count == 0) { return; } result.grids = gridList; result.biggestGrid = BiggestGrid; result.GridName = BiggestGrid.DisplayName; Vector3D Position = BiggestGrid.PositionComp.GetPosition(); if (!Vector3D.IsZero(MyGravityProviderSystem.CalculateNaturalGravityInPoint(Position))) { MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(Position); //Main.Debug("Planet Min Radius: " + planet.MinimumRadius); double distance = Vector3D.Distance(Position, planet.PositionComp.GetPosition()); //Main.Debug("Your distance from center: " + distance); if (distance < planet.MinimumRadius * .7) { //Will save grid! if (ToSaveGrids.ContainsKey(BiggestGrid.BigOwners[0])) { //Dictionary already contains grid! ToSaveGrids[BiggestGrid.BigOwners[0]].Add(result); } else { List <Result> AllGrids = new List <Result>(); AllGrids.Add(result); ToSaveGrids.Add(BiggestGrid.BigOwners[0], AllGrids); } return; } else { return; } } else { return; } } catch (Exception ex) { Hangar.Debug("Help", ex); } }); //Attempt save! foreach (var item in ToSaveGrids) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(item.Key); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { continue; } foreach (Result R in item.Value) { //Fix invalid characters Utils.FormatGridName(Data, R); if (methods.SaveGrids(R.grids, R.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(R, Plugin.Config, out GridStamp Grid); Grid.ForceSpawnNearPlayer = true; Grid.GridName = R.GridName; Data.Grids.Add(Grid); GridCounter += 1; Hangar.Debug(R.biggestGrid.DisplayName + " was sent to Hangar due to inside planet!"); } else { Hangar.Debug(R.biggestGrid.DisplayName + " FAILED to Hangar due to inside planet!"); } } //Save file methods.SaveInfoFile(Data); } stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; Hangar.Debug("PlanetHangar: Found [" + GridCounter + "] grids out of [" + TotalGridCounter + "] total grids under planet! Action took: " + ts.ToString()); }
public void SaveAll() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); int GridCounter = 0; int TotalGridCounter = 0; Dictionary <long, List <Result> > ToSaveGrids = new Dictionary <long, List <Result> >(); Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group => { List <MyCubeGrid> gridList = new List <MyCubeGrid>(); var BiggestGrid = group.Nodes.First().NodeData; Result result = new Result(); foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Physics == null) { continue; } if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } TotalGridCounter += 1; gridList.Add(grid); } if (gridList.Count == 0) { return; } result.grids = gridList; result.biggestGrid = BiggestGrid; if (ToSaveGrids.ContainsKey(BiggestGrid.BigOwners[0])) { //Dictionary already contains grid! ToSaveGrids[BiggestGrid.BigOwners[0]].Add(result); } else { List <Result> AllGrids = new List <Result>(); AllGrids.Add(result); ToSaveGrids.Add(BiggestGrid.BigOwners[0], AllGrids); } }); //Attempt save! foreach (var item in ToSaveGrids) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(item.Key); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { continue; } foreach (Result R in item.Value) { //Fix invalid characters Utils.FormatGridName(Data, R); if (methods.SaveGrids(R.grids, R.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(R, Plugin.Config, out GridStamp Grid); Grid.GridName = R.GridName; Data.Grids.Add(Grid); GridCounter += 1; Hangar.Debug(R.biggestGrid.DisplayName + " was sent to Hangar due to inside planet!"); } else { Hangar.Debug(R.biggestGrid.DisplayName + " FAILED to Hangar due to inside planet!"); } } //Save file methods.SaveInfoFile(Data); } stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; Hangar.Debug("SaveAll: Found [" + GridCounter + "] grids out of [" + TotalGridCounter + "] total grids under planet! Action took: " + ts.ToString()); }
private void AutoHangarWorker(Hangar Plugin) { //Significant performance increase if (MySession.Static.Ready) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); List <MyCubeGrid> ExportedGrids = new List <MyCubeGrid>(); List <MyIdentity> ExportPlayerIdentities = new List <MyIdentity>(); Hangar.Debug("AutoHangar: Getting Players!"); var PlayerIdentities = MySession.Static.Players.GetAllIdentities().OfType <MyIdentity>(); foreach (MyIdentity player in PlayerIdentities) { if (player == null) { continue; } DateTime LastLogin; LastLogin = player.LastLoginTime; ulong SteamID = MySession.Static.Players.TryGetSteamId(player.IdentityId); if (LastLogin.AddDays(Plugin.Config.AutoHangarDayAmount) < DateTime.Now) { //AutoHangarBlacklist if (!Plugin.Config.AutoHangarPlayerBlacklist.Any(x => x.SteamID == SteamID)) { ExportPlayerIdentities.Add(player); } } } Hangar.Debug("AutoHangar: Total players to check-" + ExportPlayerIdentities.Count()); int GridCounter = 0; //This gets all the grids foreach (MyIdentity player in ExportPlayerIdentities) { ulong id = 0; try { id = MySession.Static.Players.TryGetSteamId(player.IdentityId); } catch { Hangar.Debug("Identitiy doesnt have a SteamID! Shipping!"); continue; } if (id == 0) { //Sanity check continue; } GridMethods methods = new GridMethods(id, Plugin.Config.FolderDirectory); //string path = GridMethods.CreatePathForPlayer(Config.FolderDirectory, id); if (!methods.LoadInfoFile(out PlayerInfo Data)) { return; } ConcurrentBag <List <MyCubeGrid> > gridGroups = GridFinder.FindGridList(player.IdentityId, false); if (gridGroups.Count == 0) { continue; } long LargestGridID = 0; if (Plugin.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; } } } foreach (List <MyCubeGrid> grids in gridGroups) { if (grids.Count == 0) { continue; } if (grids[0].IsRespawnGrid && Plugin.Config.DeleteRespawnPods) { grids[0].Close(); continue; } Result result = new Result(); result.grids = grids; var BiggestGrid = grids[0]; foreach (MyCubeGrid grid in grids) { if (grid.BlocksCount > BiggestGrid.BlocksCount) { BiggestGrid = grid; } } if (Plugin.Config.KeepPlayersLargestGrid) { if (BiggestGrid.EntityId == LargestGridID) { //Skip players largest grid continue; } } //Grid Size Checks if (BiggestGrid.GridSizeEnum == MyCubeSize.Large) { if (BiggestGrid.IsStatic && !Plugin.Config.AutoHangarStaticGrids) { continue; } else if (!BiggestGrid.IsStatic && !Plugin.Config.AutoHangarLargeGrids) { continue; } } else if (BiggestGrid.GridSizeEnum == MyCubeSize.Small && !Plugin.Config.AutoHangarSmallGrids) { continue; } result.biggestGrid = BiggestGrid; result.GetGrids = true; //Check for existing grid names Utils.FormatGridName(Data, result); if (methods.SaveGrids(result.grids, result.GridName, Plugin)) { //Load player file and update! //Fill out grid info and store in file HangarChecks.GetBPDetails(result, Plugin.Config, out GridStamp Grid); Grid.GridName = result.GridName; Data.Grids.Add(Grid); GridCounter++; Hangar.Debug(result.biggestGrid.DisplayName + " was sent to Hangar due to inactivity!"); } else { Hangar.Debug(result.biggestGrid.DisplayName + " FAILED to Hangar due to inactivity!"); } } //Save players file! methods.SaveInfoFile(Data); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Hangar.Debug("AutoHangar: Finished Hangaring -" + GridCounter + " grids! Action took: " + ts.ToString()); } }