public static void FormatGridName(PlayerHangar Data, GridStamp result) { try { result.GridName = FileSaver.CheckInvalidCharacters(result.GridName); // Log.Warn("Running GridName Checks: {" + GridName + "} :" + Test); if (Data.SelectedPlayerFile.AnyGridsMatch(result.GridName)) { //There is already a grid with that name! bool NameCheckDone = false; int a = 1; while (!NameCheckDone) { if (Data.SelectedPlayerFile.AnyGridsMatch(result.GridName + "[" + a + "]")) { a++; } else { //Hangar.Debug("Name check done! " + a); NameCheckDone = true; break; } } //Main.Debug("Saving grid name: " + GridName); result.GridName = result.GridName + "[" + a + "]"; } } catch (Exception e) { Log.Warn(e); } }
private static void PurchasePlayerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity, ulong Owner) { //Log.Error("A"); if (!MySession.Static.Players.TryGetIdentityFromSteamID(Owner, out MyIdentity OwnerIdentity)) { return; } //Have a successfull buy RemoveMarketListing(Owner, Offer.Name); //Transfer grid if (PlayerHangar.TransferGrid(Owner, Buyer, Offer.Name)) { Chat.Send($"Successfully purchased {Offer.Name} from {OwnerIdentity.DisplayName}! Check your hangar!", Buyer); MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price); MyBankingSystem.ChangeBalance(OwnerIdentity.IdentityId, Offer.Price); } }
private static void PurchaseServerGrid(MarketListing Offer, ulong Buyer, MyIdentity BuyerIdentity) { if (!File.Exists(Offer.FileSBCPath)) { Log.Error($"{Offer.FileSBCPath} doesnt exsist! Was this removed prematurely?"); return; } var ToInfo = new PlayerInfo(); ToInfo.LoadFile(Hangar.MainPlayerDirectory, Buyer); //Log.Error("TotalBuys: " + ToInfo.GetServerOfferPurchaseCount(Offer.Name)); if (Offer.TotalPerPlayer != 0 && ToInfo.GetServerOfferPurchaseCount(Offer.Name) >= Offer.TotalPerPlayer) { Chat.Send($"You have reached your buy limit for this offer!", Buyer); return; } GridStamp Stamp = new GridStamp(Offer.FileSBCPath); Stamp.GridName = Offer.Name; //Log.Error("C"); if (PlayerHangar.TransferGrid(ToInfo, Stamp)) { //Log.Error("Changing Balance"); MyBankingSystem.ChangeBalance(BuyerIdentity.IdentityId, -1 * Offer.Price); Chat.Send($"Successfully purchased {Offer.Name}! Check your hangar!", Buyer); GridOfferBought(Offer, Buyer); //Hangar.Config.RefreshModel(); } }
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 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); }