// admin nobeacon scan
        public override bool HandleCommand(ulong userId, string[] words)
        {
            HashSet <IMyEntity> grids = CubeGrids.ScanGrids(userId, words);

            bool confirm = true;

            /*
             * if (words.FirstOrDefault(x => x.ToLower() == "confirm") != null)
             * {
             *      confirm = true;
             * }
             */
            int count = 0;

            foreach (IMyEntity entity in grids)
            {
                if (!(entity is IMyCubeGrid))
                {
                    continue;
                }

                IMyCubeGrid grid = (IMyCubeGrid)entity;
                MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid);
                if (confirm)
                {
                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity, true);
                }

                long   ownerId   = 0;
                string ownerName = "";
                if (CubeGrids.GetBigOwners(gridBuilder).Count > 0)
                {
                    ownerId   = CubeGrids.GetBigOwners(gridBuilder).First();
                    ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                }

                if (confirm)
                {
                    Logging.WriteLineAndConsole("Cleanup", string.Format("Cleanup Removed Grid - Id: {0} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName));
                }

                count++;
            }

            Communication.SendPrivateInformation(userId, string.Format("Operation deletes {0} grids", count));
            return(true);
        }
Ejemplo n.º 2
0
        private void ExtractCommandFromEntity(IMyEntity entity)
        {
            IMyCubeGrid grid = (IMyCubeGrid)entity;
            MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(grid);

            if (gridBuilder == null)
            {
                return;
            }

            string command = string.Empty;

            foreach (MyObjectBuilder_CubeBlock block in gridBuilder.CubeBlocks)
            {
                MyObjectBuilder_Beacon beacon = block as MyObjectBuilder_Beacon;
                if (beacon != null)
                {
                    command = beacon.CustomName;
                    break;
                }
            }

            string player   = entity.DisplayName.Replace("CommRelay", string.Empty);
            long   playerId = long.Parse(player);
            ulong  steamId  = PlayerMap.Instance.GetSteamIdFromPlayerId(playerId);

            Wrapper.GameAction(() =>
            {
                entity.DisplayName = string.Empty;
                BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
            });

            Essentials.Log.Info("COMMAND {1} - {2}: {0}", command, playerId, entity.EntityId);
            if (!m_processedRelays.Contains(entity.EntityId))
            {
                m_processedRelays.Add(entity.EntityId);
                Essentials.Instance.HandleChatMessage(steamId, command);
            }
            else
            {
                Essentials.Log.Info("Ignoring repeat beacon: {0}");
            }
        }
Ejemplo n.º 3
0
        static public void RevealAll()
        {
            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            Wrapper.GameAction(() =>
            {
                MyAPIGateway.Entities.GetEntities(entities);
            });

            List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>();
            int count = 0;

            Wrapper.GameAction(() =>
            {
                foreach (IMyEntity entity in entities)
                {
                    if (entity.InScene)
                    {
                        continue;
                    }

                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                    if (builder == null)
                    {
                        continue;
                    }

                    count++;
                    IMyCubeGrid grid = (IMyCubeGrid)entity;
                    long ownerId     = 0;
                    string ownerName = "";
                    if (CubeGrids.GetBigOwners(builder).Count > 0)
                    {
                        ownerId   = CubeGrids.GetBigOwners(builder).First();
                        ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                    }

                    //grid.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
                    //grid.InScene = true;
                    //grid.CastShadows = true;
                    builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
                    MyAPIGateway.Entities.RemapObjectBuilder(builder);
                    Logging.WriteLineAndConsole("Conceal", string.Format("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId));

                    IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
                    if (newEntity == null)
                    {
                        Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
                        continue;
                    }

                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                    MyAPIGateway.Entities.AddEntity(newEntity, true);
                    addList.Add(newEntity.GetObjectBuilder());
                    MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
                    addList.Clear();
                }
            });

            Logging.WriteLineAndConsole(string.Format("Revealed {0} grids", count));
        }
Ejemplo n.º 4
0
        private static void RevealEntity(KeyValuePair <IMyEntity, string> item)
        {
            IMyEntity entity = item.Key;
            string    reason = item.Value;
            //Wrapper.GameAction(() =>
            //{
            MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);

            if (builder == null)
            {
                return;
            }

            IMyCubeGrid grid      = (IMyCubeGrid)entity;
            long        ownerId   = 0;
            string      ownerName = "";

            if (CubeGrids.GetBigOwners(builder).Count > 0)
            {
                ownerId   = CubeGrids.GetBigOwners(builder).First();
                ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
            }

            /*
             * entity.InScene = true;
             * entity.CastShadows = true;
             * entity.Visible = true;
             */

            builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
            MyAPIGateway.Entities.RemapObjectBuilder(builder);
            //builder.EntityId = 0;

            if (RemovedGrids.Contains(entity.EntityId))
            {
                Logging.WriteLineAndConsole("Conceal", string.Format("Revealing - Id: {0} DUPE FOUND Display: {1} OwnerId: {2} OwnerName: {3}  Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
                BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
            }
            else
            {
                if (!PluginSettings.Instance.DynamicConcealServerOnly)
                {
                    IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
                    Logging.WriteLineAndConsole("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}  Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason));
                    if (newEntity == null)
                    {
                        Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
                        return;
                    }

                    RemovedGrids.Add(entity.EntityId);
                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                    MyAPIGateway.Entities.AddEntity(newEntity, true);

                    /*CC
                     * if (PluginSettings.Instance.DynamicClientConcealEnabled)
                     * {
                     *      ClientEntityManagement.AddEntityState(newEntity.EntityId);
                     * }
                     */

                    builder.EntityId = newEntity.EntityId;
                    List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>();
                    addList.Add(newEntity.GetObjectBuilder());
                    MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
                    Logging.WriteLineAndConsole("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}  Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason));
                }
                else
                {
                    Logging.WriteLineAndConsole("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}  Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
                    entity.InScene = true;
                    // Send to users, client will remove if doesn't need - this solves login problem

                    /*CC
                     * if (PluginSettings.Instance.DynamicClientConcealEnabled)
                     * {
                     *      ClientEntityManagement.AddEntityState(entity.EntityId);
                     *      List<MyObjectBuilder_EntityBase> addList = new List<MyObjectBuilder_EntityBase>();
                     *      addList.Add(entity.GetObjectBuilder());
                     * MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
                     * }
                     */
                    Logging.WriteLineAndConsole("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}  Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
                }
            }
            //});
        }
Ejemplo n.º 5
0
        private static void ConcealEntity(IMyEntity entity)
        {
            int pos = 0;

            try
            {
                if (!entity.InScene)
                {
                    return;
                }

                MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                if (builder == null)
                {
                    return;
                }

                pos = 1;
                IMyCubeGrid grid      = (IMyCubeGrid)entity;
                long        ownerId   = 0;
                string      ownerName = "";
                if (CubeGrids.GetOwner(builder, out ownerId))
                {
                    //ownerId = grid.BigOwners.First();
                    ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                }

                pos = 2;
                if (entity.Physics != null)
                {
                    entity.Physics.LinearVelocity  = Vector3.Zero;
                    entity.Physics.AngularVelocity = Vector3.Zero;
                }

                /*
                 * entity.InScene = false;
                 * entity.CastShadows = false;
                 * entity.Visible = false;
                 */

                builder.PersistentFlags = MyPersistentEntityFlags2.None;
                MyAPIGateway.Entities.RemapObjectBuilder(builder);

                pos = 3;
                if (RemovedGrids.Contains(entity.EntityId))
                {
                    Logging.WriteLineAndConsole("Conceal", string.Format("Concealing - Id: {0} DUPE FOUND - Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                }
                else
                {
                    if (!PluginSettings.Instance.DynamicConcealServerOnly)
                    {
                        /*
                         * if (PluginSettings.Instance.DynamicBlockManagementEnabled)
                         * {
                         *      bool enable = false;
                         *      lock (BlockManagement.Instance.GridDisabled)
                         *      {
                         *              if(BlockManagement.Instance.GridDisabled.Contains(entity.EntityId))
                         *                      enable = true;
                         *      }
                         *
                         *      if(enable)
                         *              BlockManagement.Instance.EnableGrid((IMyCubeGrid)entity);
                         * }
                         */
                        IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
                        Logging.WriteLineAndConsole("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
                        if (newEntity == null)
                        {
                            Logging.WriteLineAndConsole("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
                            return;
                        }

                        RemovedGrids.Add(entity.EntityId);
                        BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                        MyAPIGateway.Entities.AddEntity(newEntity, false);
                        Logging.WriteLineAndConsole("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
                    }
                    else
                    {
                        Logging.WriteLineAndConsole("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                        entity.InScene = false;
                        Logging.WriteLineAndConsole("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("ConcealEntity({1}): {0}", ex.ToString(), pos));
            }
        }
Ejemplo n.º 6
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.DockingEnabled)
            {
                return(false);
            }

            if (words.Length < 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            if (m_docking)
            {
                Communication.SendPrivateInformation(userId, "Server is busy");
                return(true);
            }

            m_docking = true;
            try
            {
                String pylonName = String.Join(" ", words);

                /*
                 * int timeLeft;
                 * if (Entity.CheckCoolDown(pylonName, out timeLeft))
                 * {
                 *      Communication.Message(String.Format("The docking zone '{0}' is on cooldown.  Please wait a {1} seconds before trying to dock/undock again.", pylonName, Math.Max(0, timeLeft)));
                 *      return;
                 * }
                 */

                if (PlayerMap.Instance.GetPlayerIdsFromSteamId(userId).Count < 1)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Unable to find player Id: {0}", userId));
                    return(true);
                }

                long playerId = PlayerMap.Instance.GetPlayerIdsFromSteamId(userId).First();

                Dictionary <String, List <IMyCubeBlock> > testList;
                List <IMyCubeBlock> beaconList;
                DockingZone.FindByName(pylonName, out testList, out beaconList, playerId);
                if (beaconList.Count == 4)
                {
                    // Check ownership
                    foreach (IMyCubeBlock entityBlock in beaconList)
                    {
                        IMyTerminalBlock terminal = (IMyTerminalBlock)entityBlock;
                        if (!terminal.HasPlayerAccess(playerId))
                        {
                            Communication.SendPrivateInformation(userId, string.Format("You do not have permission to use '{0}'.  You must either own all the beacons or they must be shared with faction.", pylonName));
                            return(true);
                        }
                    }

                    // Check for bounding box intsection of other docking zones
                    int intersectElement = 0;
                    if (Entity.CheckForIntersection(testList, beaconList, out intersectElement))
                    {
                        Communication.SendPrivateInformation(userId, string.Format("The docking zone '{0}' intersects with docking zone '{1}'.  Make sure you place your docking zones so they don't overlap.", pylonName, testList.ElementAt(intersectElement).Key));
                        return(true);
                    }

                    // Check if ship already docked in this zone
                    IMyCubeBlock       e             = beaconList[0];
                    IMyCubeGrid        parent        = (IMyCubeGrid)e.Parent;
                    long[]             beaconListIds = beaconList.Select(b => b.EntityId).ToArray();
                    long               ownerId       = beaconList.First().OwnerId;
                    List <DockingItem> checkItems    = Docking.Instance.Find(d => d.PlayerId == ownerId && d.TargetEntityId == parent.EntityId && d.DockingBeaconIds.Intersect(beaconListIds).Count() == 4);
                    if (checkItems.Count >= PluginSettings.Instance.DockingShipsPerZone)
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Docking zone already '{0}' already contains the maximum capacity of ships.", pylonName));
                        return(true);
                    }

                    // Figure out center of docking area, and other distance information
                    double   maxDistance = 99;
                    Vector3D vPos        = new Vector3D(0, 0, 0);

                    foreach (IMyCubeBlock b in beaconList)
                    {
                        Vector3D beaconPos = Entity.GetBlockEntityPosition(b);
                        vPos += beaconPos;
                    }

                    vPos = vPos / 4;
                    foreach (IMyCubeBlock b in beaconList)
                    {
                        Vector3D beaconPos = Entity.GetBlockEntityPosition(b);
                        maxDistance = Math.Min(maxDistance, Vector3D.Distance(vPos, beaconPos));
                    }

                    // Find ship in docking area
                    IMyCubeGrid         dockingEntity = null;
                    HashSet <IMyEntity> cubeGrids     = new HashSet <IMyEntity>();
                    MyAPIGateway.Entities.GetEntities(cubeGrids, f => f is IMyCubeGrid);
                    foreach (IMyCubeGrid gridCheck in cubeGrids)
                    {
                        if (gridCheck.IsStatic || gridCheck == parent)
                        {
                            continue;
                        }

                        double distance = Vector3D.Distance(gridCheck.GetPosition(), vPos);
                        if (distance < maxDistance)
                        {
                            dockingEntity = gridCheck;
                            break;
                        }
                    }

                    // Figure out if the ship fits in docking area, and then save ship
                    if (dockingEntity != null)
                    {
                        // Get bounding box of both the docking zone and docking ship
                        OrientedBoundingBoxD targetBounding  = Entity.GetBoundingBox(beaconList);
                        OrientedBoundingBoxD dockingBounding = Entity.GetBoundingBox(dockingEntity);

                        // Make sure the docking zone contains the docking ship.  If they intersect or are disjointed, then fail
                        if (!Entity.GreaterThan(dockingBounding.HalfExtent * 2, targetBounding.HalfExtent * 2))
                        {
                            Communication.SendPrivateInformation(userId, string.Format("The ship '{0}' is too large for it's carrier.  The ship's bounding box must fit inside the docking zone bounding box!", dockingEntity.DisplayName));
                            return(true);
                        }

                        if (targetBounding.Contains(ref dockingBounding) != ContainmentType.Contains)
                        {
                            Communication.SendPrivateInformation(userId, string.Format("The ship '{0}' is not fully inside the docking zone '{1}'.  Make sure the ship is fully contained inside the docking zone", dockingEntity.DisplayName, pylonName));
                            return(true);
                        }

                        // Calculate the mass and ensure the docking ship is less than half the mass of the dock
                        float parentMass  = Entity.CalculateMass(parent);
                        float dockingMass = Entity.CalculateMass(dockingEntity);
                        if (dockingMass > parentMass)
                        {
                            Communication.SendPrivateInformation(userId, string.Format("The ship you're trying to dock is too heavy for it's carrier.  The ship mass must be less than half the large ship / stations mass! (DM={0}kg CM={1}kg)", dockingMass, parentMass));
                            return(true);
                        }

                        // Check to see if the ship is piloted, if it is, error out.
                        // TODO: Check to see if we can get a real time copy of this entity?
                        List <IMySlimBlock> blocks = new List <IMySlimBlock>();
                        dockingEntity.GetBlocks(blocks, x => x.FatBlock != null && x.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Cockpit));
                        foreach (IMySlimBlock slim_cbe in blocks)
                        {
                            MyObjectBuilder_Cockpit c = (MyObjectBuilder_Cockpit)slim_cbe.FatBlock.GetObjectBuilderCubeBlock();
                            if (c.Pilot != null)
                            {
                                Communication.SendPrivateInformation(userId, string.Format("Ship in docking zone '{0}' has a pilot!  Please exit the ship before trying to dock.  (Sometimes this can lag a bit.  Wait 10 seconds and try again)", pylonName));
                                return(true);
                            }
                        }

                        // Save position and rotation information.  Some fun stuff here.
                        // Get our dock rotation as a quaternion
                        Quaternion saveQuat = Quaternion.CreateFromRotationMatrix(parent.WorldMatrix.GetOrientation());
                        // Transform docked ship's local position by inverse of the the parent (unwinds parent) and save it for when we undock
                        Vector3D savePos = Vector3D.Transform(dockingEntity.GetPosition() - parent.GetPosition(), Quaternion.Inverse(saveQuat));
                        // Get local rotation of dock ship, and save it for when we undock
                        saveQuat = Quaternion.Inverse(saveQuat) * Quaternion.CreateFromRotationMatrix(dockingEntity.WorldMatrix.GetOrientation());

                        // Save ship to file and remove
                        FileInfo info = new FileInfo(Path.Combine(Essentials.PluginPath, "Docking", string.Format("docked_{0}_{1}_{2}.sbc", ownerId, parent.EntityId, dockingEntity.EntityId)));
                        if (!Directory.Exists(info.DirectoryName))
                        {
                            Directory.CreateDirectory(info.DirectoryName);
                        }
                        //CubeGridEntity dockingGrid = new CubeGridEntity((MyObjectBuilder_CubeGrid)dockingEntity.GetObjectBuilder(), dockingEntity);
                        MyObjectBuilder_CubeGrid gridBuilder = CubeGrids.SafeGetObjectBuilder(dockingEntity);
                        if (gridBuilder == null)
                        {
                            Communication.SendPrivateInformation(userId, string.Format("Failed to load entity for export: {0}", dockingEntity.DisplayName));
                            return(true);
                        }

                        // Save item
                        DockingItem dockItem = new DockingItem
                        {
                            DockedEntityId   = dockingEntity.EntityId,
                            TargetEntityId   = parent.EntityId,
                            PlayerId         = ownerId,
                            DockingBeaconIds = beaconList.Select(s => s.EntityId).ToArray( ),
                            DockedName       = dockingEntity.DisplayName,
                            SavePos          = savePos,
                            SaveQuat         = saveQuat
                        };
                        Docking.Instance.Add(dockItem);

                        // Serialize and save ship to file
                        MyObjectBuilderSerializer.SerializeXML(info.FullName, false, gridBuilder);
                        //BaseObjectManager.SaveContentFile<MyObjectBuilder_CubeGrid, MyObjectBuilder_CubeGridSerializer>(gridBuilder, info);
                        BaseEntityNetworkManager.BroadcastRemoveEntity(dockingEntity);
                        //dockingEntity.Close();

                        Communication.SendPrivateInformation(userId, string.Format("Docked ship '{0}' in docking zone '{1}'.", dockItem.DockedName, pylonName));
                        Log.Info("Docked ship \"{0}\" in docking zone \"{1}\". Saved to {2}", dockItem.DockedName, pylonName, info.FullName);

                        /*
                         * // Add a cool down
                         * DockingCooldownItem cItem = new DockingCooldownItem();
                         * cItem.name = pylonName;
                         * cItem.startTime = DateTime.Now;
                         * PluginDocking.CooldownList.Add(cItem);
                         */
                    }
                    else
                    {
                        Communication.SendPrivateInformation(userId, string.Format("No ships in docking zone '{0}'.", pylonName));
                    }
                }
                else if (beaconList.Count > 4)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Too many beacons with the name or another zone with the name '{0}'.  Place only 4 beacons to create a zone or try a different zone name.", pylonName));
                }
                else
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can not locate docking zone '{0}'.  There must be 4 beacons with the name '{0}' to create a docking zone.  Beacons must be fully built!", pylonName));
                }

                return(true);
            }
            catch (SecurityException ex)
            {
                Log.Error("Can't access docked ship file.", ex);
                return(false);
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error("Can't access docked ship file.", ex);
                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                Log.Error("Directory does not exist", ex);
                return(false);
            }
            catch (IOException ex)
            {
                return(false);
            }
            finally
            {
                m_docking = false;
            }
        }
Ejemplo n.º 7
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            bool force = words.FirstOrDefault(x => x.ToLower() == "force") != null;

            HashSet <IMyEntity> entities = new HashSet <IMyEntity>();

            Wrapper.GameAction(() => MyAPIGateway.Entities.GetEntities(entities));

            List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>();
            int count = 0;

            Wrapper.GameAction(() =>
            {
                foreach (IMyEntity entity in entities)
                {
                    if (entity.InScene)
                    {
                        continue;
                    }

                    if (!(entity is IMyCubeGrid))
                    {
                        continue;
                    }

                    MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                    if (builder == null)
                    {
                        continue;
                    }

                    count++;
                    if (!force)
                    {
                        continue;
                    }

                    IMyCubeGrid grid = (IMyCubeGrid)entity;
                    long ownerId     = 0;
                    string ownerName = "";
                    if (grid.BigOwners.Count > 0)
                    {
                        ownerId   = grid.BigOwners.First();
                        ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                    }

                    grid.PersistentFlags    = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
                    grid.InScene            = true;
                    grid.CastShadows        = true;
                    builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
                    MyAPIGateway.Entities.RemapObjectBuilder(builder);
                    Log.Info("Conceal", string.Format("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId));

                    /*
                     * entity.InScene = true;
                     * entity.CastShadows = true;
                     * entity.Visible = true;
                     */

                    //CubeGridEntity newEntity = new CubeGridEntity(builder);
                    //SectorObjectManager.Instance.AddEntity(newEntity);

                    BaseEntityNetworkManager.BroadcastRemoveEntity(entity);
                    MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(builder);
                    addList.Add(builder);
                    MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
                    addList.Clear();
                }
            });

            Log.Info(!force ? string.Format("Command would Reveal {0} grids.  Type /admin reveal force to reveal them.", count) : string.Format("Command Revealed {0} grids", count));

            return(true);
        }
Ejemplo n.º 8
0
        public override bool HandleCommand(ulong userId, string[] words)
        {
            bool force = words.FirstOrDefault(x => x.ToLower( ) == "force") != null;
            bool now   = false;

            if (words.Count( ) > 1 && words[1] == "now")
            {
                now = true;
            }

            if (force && !now)
            {
                EntityManagement.RevealAll( );
            }

            else
            {
                HashSet <IMyEntity> entities = new HashSet <IMyEntity>( );
                Wrapper.GameAction(() => MyAPIGateway.Entities.GetEntities(entities));

                List <MyObjectBuilder_EntityBase> addList = new List <MyObjectBuilder_EntityBase>( );
                int count = 0;

                if (!now)
                {
                    Wrapper.GameAction(() =>
                    {
                        foreach (IMyEntity entity in entities)
                        {
                            if (entity.InScene)
                            {
                                continue;
                            }

                            if (!(entity is IMyCubeGrid))
                            {
                                continue;
                            }

                            MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                            if (builder == null)
                            {
                                continue;
                            }

                            //if ( now )
                            //    EntityManagement.RevealEntity( new KeyValuePair<IMyEntity, string>( entity, "Immediate force reveal" ) );

                            count++;
                        }
                    });
                }

                if (now)
                {
                    Wrapper.GameAction(() =>
                    {
                        foreach (IMyEntity entity in entities)
                        {
                            if (entity.InScene)
                            {
                                continue;
                            }

                            if (!(entity is IMyCubeGrid))
                            {
                                continue;
                            }

                            MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                            if (builder == null)
                            {
                                continue;
                            }

                            count++;

                            IMyCubeGrid grid = (IMyCubeGrid)entity;
                            long ownerId     = 0;
                            string ownerName = "";
                            if (grid.BigOwners.Count > 0)
                            {
                                ownerId   = grid.BigOwners.First( );
                                ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
                            }


                            builder.PersistentFlags = (MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.CastShadows);
                            MyAPIGateway.Entities.RemapObjectBuilder(builder);

                            //Log.Info("Conceal", string.Format("Force Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, builder.EntityId));
                            Log.Info("Revealing");

                            IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
                            entity.InScene      = true;
                            entity.OnAddedToScene(entity);
                            BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
                            MyAPIGateway.Entities.AddEntity(newEntity);
                            MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(newEntity));
                            entity.Physics.LinearVelocity  = Vector3.Zero;
                            entity.Physics.AngularVelocity = Vector3.Zero;
                        }
                    });
                }

                if (!now)
                {
                    Log.Info(string.Format("Command would reveal {0} grids.  Type /admin reveal force to reveal them.", count));
                }

                else
                {
                    Log.Info(string.Format("Command revealed {0} grids.", count));
                }
            }
            return(true);
        }
        public override void Handle()
        {
            if (!PluginSettings.Instance.NewUserTransportEnabled)
            {
                return;
            }

            if (!m_init)
            {
                m_init = true;
                Init();
            }

            if (!m_ready)
            {
                return;
            }

            if (MyAPIGateway.Players == null)
            {
                return;
            }

            List <IMyPlayer> players = new List <IMyPlayer>();
            bool             result  = false;

//			Wrapper.GameAction(() =>
//			{
            try
            {
                MyAPIGateway.Players.GetPlayers(players, null);
                result = true;
            }
            catch (Exception ex)
            {
                Logging.WriteLineAndConsole(string.Format("Transport(): Unable to get player list: {0}", ex.ToString()));
            }
//			});

            if (!result)
            {
                return;
            }

            lock (m_newUserList)
            {
                for (int r = m_newUserList.Count - 1; r >= 0; r--)
                {
                    ulong steamId = m_newUserList[r];

                    IMyPlayer player = players.FirstOrDefault(x => x.SteamUserId == steamId && x.Controller != null && x.Controller.ControlledEntity != null);
                    if (player != null)
                    {
                        Logging.WriteLineAndConsole(string.Format("Player entered game, starting movement."));
                        m_newUserList.RemoveAt(r);

                        // In Game
                        IMyEntity playerEntity = player.Controller.ControlledEntity.Entity;
                        // Player spawned in space suit, ug.
                        if (!(playerEntity.GetTopMostParent() is IMyCubeGrid))
                        {
                            continue;
                        }

                        IMyEntity entity = playerEntity.GetTopMostParent();
                        MyObjectBuilder_CubeGrid cubeGrid = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
                        if (cubeGrid == null)
                        {
                            continue;
                        }

                        Vector3D validPosition    = Vector3D.Zero;
                        Vector3D asteroidPosition = Vector3D.Zero;

                        if (PluginSettings.Instance.NewUserTransportSpawnType == NewUserTransportSpawnPoint.Asteroids)
                        {
                            FindViableAsteroid(out validPosition, out asteroidPosition);
                        }
                        else if (PluginSettings.Instance.NewUserTransportSpawnType == NewUserTransportSpawnPoint.Origin)
                        {
                            validPosition = MathUtility.RandomPositionFromPoint(Vector3D.Zero, PluginSettings.Instance.NewUserTransportDistance);
                        }

                        if (validPosition == Vector3D.Zero)
                        {
                            Logging.WriteLineAndConsole("Could not find a valid asteroid to drop off a new user.");
                            continue;
                        }

                        Logging.WriteLineAndConsole(string.Format("Attempting to move user to: {0}", General.Vector3DToString(validPosition)));

                        Wrapper.GameAction(() =>
                        {
                            if (player.Controller != null && player.Controller.ControlledEntity != null)
                            {
                                player.Controller.ControlledEntity.Use();
                            }
                        });

                        Thread.Sleep(100);
                        cubeGrid.PositionAndOrientation = new MyPositionAndOrientation(validPosition, Vector3.Forward, Vector3.Up);
                        List <MyObjectBuilder_EntityBase> list = new List <MyObjectBuilder_EntityBase>();
                        list.Add(cubeGrid);

                        IMyEntity newEntity = null;
                        Wrapper.GameAction(() =>
                        {
                            BaseEntityNetworkManager.BroadcastRemoveEntity(entity);
                            MyAPIGateway.Entities.RemapObjectBuilder(cubeGrid);
                            newEntity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(cubeGrid);
                            MyAPIGateway.Multiplayer.SendEntitiesCreated(list);
                        });


                        /*
                         * CubeGridEntity gridEntity = new CubeGridEntity(cubeGrid);
                         * gridEntity.PositionAndOrientation = CubeGrids.CreatePositionAndOrientation(validPosition, asteroidPosition);
                         * SectorObjectManager.Instance.AddEntity(gridEntity);
                         */

                        /*
                         * Wrapper.GameAction(() =>
                         * {
                         *      MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(cubeGrid);
                         * });
                         */

                        //Communication.SendPrivateInformation(steamId, string.Format("Welcome {0}.  We are moving you closer to an asteroid ... please stand by ...", PlayerMap.Instance.GetPlayerNameFromSteamId(steamId)));

                        //CubeGridEntity grid = new CubeGridEntity((MyObjectBuilder_CubeGrid)entity.GetObjectBuilder(), entity);
                        //if (!CubeGrids.WaitForLoadingEntity(grid))
                        //	continue;

                        /*
                         * foreach(CubeBlockEntity block in grid.CubeBlocks)
                         * {
                         *      if(block is CockpitEntity)
                         *      {
                         *              block.IntegrityPercent = 0.1f;
                         *              Logging.WriteLineAndConsole(string.Format("Removing User From Cockpit: {0}", steamId));
                         *      }
                         * }
                         */

                        /*
                         *
                         * //						Wrapper.GameAction(() =>
                         * //						{
                         *      // This should boot them out of their ship: it does not, it kills them :(
                         * //							MyAPIGateway.Entities.RemoveEntity(entity);
                         *      MyAPIGateway.Entities.RemapObjectBuilder(cubeGrid);
                         * //						});
                         *
                         * CubeGridEntity gridEntity = new CubeGridEntity(cubeGrid);
                         * gridEntity.PositionAndOrientation = CubeGrids.CreatePositionAndOrientation(validPosition, asteroidPosition);
                         * SectorObjectManager.Instance.AddEntity(gridEntity);
                         * //Communication.SendPrivateInformation(steamId, string.Format("You have been moved!  You should be within {0} meters of an asteroid.", PluginSettings.Instance.NewUserTransportDistance));
                         */
                    }
                }
            }

            base.Handle();
        }