public void Update() { try { UpdateCount++; if (UpdateCount > Plugin.Config.DelayTicksBetweenExports) { UpdateCount = 0; } if (UpdateCount != 0) { return; } stopwatch.Start(); /* We just peek, as we visit this player multiple times. */ long playerId = stack.Peek(); ConcurrentBag <List <MyCubeGrid> > gridGroups = GridFinder.FindGridList(playerId, Plugin.Config.BackupConnections); string path = Plugin.CreatePath(); foreach (List <MyCubeGrid> grids in gridGroups) { try { /* * if false is returned we already exported the gird and * need to continue with the next one * * If true is returned we added a new grid to the list and therefore * end this tick. */ if (BackupSingleGrid(playerId, grids, path)) { return; } } catch (Exception e) { Log.Warn(e, "Could not export grids"); } } /* If we reach the end of this for loop this player is basically done. so off of the stack it goes */ stack.Pop(); } finally { stopwatch.Stop(); } }
public void ExportGrid(string filename, string gridName = null) { MyCharacter character = null; if (gridName == null) { if (Context.Player == null) { Context.Respond("You need to enter a Grid name where the grid will be spawned at."); return; } var player = ((MyPlayer)Context.Player).Identity; if (player.Character == null) { Context.Respond("Player has no character to spawn the grid close to!"); return; } character = player.Character; } List <MyCubeGrid> grids = GridFinder.FindGridList(gridName, character, Plugin.Config.IncludeConnectedGrids); if (grids == null) { Context.Respond("Multiple grids found. Try to rename them first or try a different subgrid for identification!"); return; } if (grids.Count == 0) { Context.Respond("No grids found. Check your viewing angle or try the correct name!"); return; } if (GridManager.SaveGrid(Plugin.CreatePath(filename), filename, Plugin.Config.KeepOriginalOwner, Plugin.Config.ExportProjectorBlueprints, grids)) { Context.Respond("Export Complete!"); } else { Context.Respond("Export Failed!"); } }
public void Save(string gridNameOrEntityId = null) { MyCharacter character = null; if (gridNameOrEntityId == null) { if (Context.Player == null) { Context.Respond("You need to enter a Grid name where the grid will be spawned at."); return; } var player = ((MyPlayer)Context.Player).Identity; if (player.Character == null) { Context.Respond("Player has no character to spawn the grid close to!"); return; } character = player.Character; } List <MyCubeGrid> grids = GridFinder.FindGridList(gridNameOrEntityId, character, Plugin.Config.BackupConnections); if (grids == null) { Context.Respond("Multiple grids found. Try to rename them first or try a different subgrid for identification!"); return; } if (grids.Count == 0) { Context.Respond("No grids found. Check your viewing angle or try the correct name!"); return; } if (Plugin.BackupGridsManually(grids, out MyCubeGrid biggestGrid, out long playerId, Context)) { Context.Respond("Export Complete for Grid " + biggestGrid.DisplayName + " (EntityID: #" + biggestGrid.EntityId + ") for PlayerID: #" + playerId); }
public void Outboundwormhole(string ip, string outfile, double xgate, double ygate, double zgate) { BoundingSphereD gate = new BoundingSphereD(new Vector3D(xgate, ygate, zgate), Config.InRadiusGate); foreach (var entity in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref gate)) { var grid = (entity as VRage.Game.ModAPI.IMyCubeGrid); if (grid != null) { var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(entity); if (playerInCharge != null && OwnershipUtils.GetOwner(entity as MyCubeGrid) == playerInCharge.IdentityId)//hasrighttomove(playerInCharge, entity as MyCubeGrid)) { var WormholeDrives = new List <IMyJumpDrive>(); var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); gts.GetBlocksOfType(WormholeDrives); if (Config.DontNeedJD) { List <MyCubeGrid> grids = GridFinder.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids); if (grids == null) { return; } if (grids.Count == 0) { return; } var filename = playerInCharge.SteamUserId.ToString() + "_" + grid.GetFriendlyName() + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(new Vector3D(xgate, ygate, zgate)); if (GridManager.SaveGrid(CreatePath(outfile, filename), filename, ip, Config.KeepOriginalOwner, Config.ExportProjectorBlueprints, grids)) { foreach (var delgrid in grids) { delgrid.Delete(); } } } else if (WormholeDrives.Count > 0) { foreach (var WormholeDrive in WormholeDrives) { if (WormholeDrive.OwnerId == playerInCharge.IdentityId && WormholeDrive.Enabled && WormholeDrive.CurrentStoredPower == WormholeDrive.MaxStoredPower && (WormholeDrive.BlockDefinition.SubtypeId.ToString() == Config.JumpDriveSubid || Config.WorkWithAllJD)) { WormholeDrive.CurrentStoredPower = 0; if (Config.DisableJD) { foreach (var jd in WormholeDrives) { jd.Enabled = false; } } List <MyCubeGrid> grids = GridFinder.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids); if (grids == null) { return; } if (grids.Count == 0) { return; } var filename = playerInCharge.SteamUserId.ToString() + "_" + playerInCharge.DisplayName + "_" + grid.DisplayName + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(new Vector3D(xgate, ygate, zgate)); if (GridManager.SaveGrid(CreatePath(outfile, filename), filename, ip, Config.KeepOriginalOwner, Config.ExportProjectorBlueprints, grids)) { foreach (var delgrid in grids) { delgrid.Delete(); } } } } } } } } }
public void Wormholetransferout(string name, string sendto, double xgate, double ygate, double zgate) { Vector3D gatepoint = new Vector3D(xgate, ygate, zgate); BoundingSphereD gate = new BoundingSphereD(gatepoint, Config.RadiusGate); foreach (var entity in MyAPIGateway.Entities.GetTopMostEntitiesInSphere(ref gate)) { var grid = (entity as IMyCubeGrid); if (grid != null) { var WormholeDrives = new List <IMyJumpDrive>(); Log.Warn("test a"); var gts = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(grid); gts.GetBlocksOfType(WormholeDrives); if (WormholeDrives.Count > 0) { foreach (var WormholeDrive in WormholeDrives) { if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == WormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD) { Request request = null; try { request = MyAPIGateway.Utilities.SerializeFromXML <Request>(WormholeDrive.CustomData); } catch { } string pickeddestination = null; if (request != null) { if (request.PluginRequest) { if (request.Destination != null) { if (sendto.Split(',').Any(s => s.Trim() == request.Destination.Trim())) { pickeddestination = request.Destination.Trim(); } } Request reply = new Request { PluginRequest = false, Destination = null, Destinations = sendto.Split(',').Select(s => s.Trim()).ToArray() }; WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply); } } else { Request reply = new Request { PluginRequest = false, Destination = null, Destinations = sendto.Split(',').Select(s => s.Trim()).ToArray() }; WormholeDrive.CustomData = MyAPIGateway.Utilities.SerializeToXML <Request>(reply); } if (Config.AutoSend && sendto.Split(',').Length == 1) { pickeddestination = sendto.Split(',')[0].Trim(); } if (pickeddestination != null) { if (WormholeDrive.IsWorking && WormholeDrive.CurrentStoredPower == WormholeDrive.MaxStoredPower) { var playerInCharge = MyAPIGateway.Players.GetPlayerControllingEntity(entity); if (playerInCharge != null && HasRightToMove(playerInCharge, entity as MyCubeGrid)) { WormholeDrive.CurrentStoredPower = 0; foreach (var DisablingWormholeDrive in WormholeDrives) { if (Config.JumpDriveSubid.Split(',').Any(s => s.Trim() == DisablingWormholeDrive.BlockDefinition.SubtypeId) || Config.WorkWithAllJD) { DisablingWormholeDrive.Enabled = false; } } List <MyCubeGrid> grids = GridFinder.FindGridList(grid.EntityId.ToString(), playerInCharge as MyCharacter, Config.IncludeConnectedGrids); if (grids == null) { return; } if (grids.Count == 0) { return; } Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(gatepoint); //NEED TO DROP ENEMY GRIDS if (Config.WormholeGates.Any(s => s.Name.Trim() == pickeddestination.Split(':')[0])) { foreach (WormholeGate internalwormhole in Config.WormholeGates) { if (internalwormhole.Name.Trim() == pickeddestination.Split(':')[0].Trim()) { var box = WormholeDrive.GetTopMostParent().WorldAABB; var togatepoint = new Vector3D(internalwormhole.X, internalwormhole.Y, internalwormhole.Z); var togate = new BoundingSphereD(togatepoint, Config.RadiusGate); Utilities.UpdateGridsPositionAndStopLive(WormholeDrive.GetTopMostParent(), Utilities.FindFreePos(togate, (float)(Vector3D.Distance(box.Center, box.Max) + 50))); Sandbox.Game.MyVisualScriptLogicProvider.CreateLightning(togatepoint); } } } else { var destination = pickeddestination.Split(':'); var filename = destination[0] + "_" + playerInCharge.SteamUserId.ToString() + "_" + LegalCharOnly(playerInCharge.DisplayName) + "_" + LegalCharOnly(grid.DisplayName) + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"); List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>(); foreach (MyCubeGrid mygrid in grids) { if (!(grid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder)) { throw new ArgumentException(mygrid + " has a ObjectBuilder thats not for a CubeGrid"); } objectBuilders.Add(objectBuilder); } MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>(); definition.Id = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), filename); definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray(); List <ulong> playerIds = new List <ulong>(); foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids) { foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks) { if (!Config.KeepOriginalOwner) { cubeBlock.Owner = 0L; cubeBlock.BuiltBy = 0L; } if (!Config.ExportProjectorBlueprints) { if (cubeBlock is MyObjectBuilder_ProjectorBase projector) { projector.ProjectedGrids = null; } } if (cubeBlock is MyObjectBuilder_Cockpit cockpit) { if (cockpit.Pilot != null) { var playersteam = cockpit.Pilot.PlayerSteamId; var player = PlayerUtils.GetIdentityByNameOrId(playersteam.ToString()); playerIds.Add(playersteam); ModCommunication.SendMessageTo(new JoinServerMessage(destination[1] + ":" + destination[2]), playersteam); } } } } MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>(); builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition }; foreach (var playerId in playerIds) { var player = PlayerUtils.GetIdentityByNameOrId(playerId.ToString()); player.Character.EnableBag(false); Sandbox.Game.MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, 0); player.Character.Close(); } if (MyObjectBuilderSerializer.SerializeXML(CreatePath(Config.Folder + "/" + admingatesfolder, filename), false, builderDefinition)) { foreach (var delgrid in grids) { delgrid.Close(); } } } } } } } } } } } }
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()); } }