Exemple #1
0
        internal virtual List <Entity> GetAllEntitiesWithOUTDataBlobs([NotNull] ComparableBitArray dataBlobMask)
        {
            if (dataBlobMask == null)
            {
                throw new ArgumentNullException(nameof(dataBlobMask));
            }

            if (dataBlobMask.Length != InternalDataBlobTypes.Count)
            {
                throw new ArgumentException("dataBlobMask must contain a bit value for each dataBlobType.");
            }

            var entities = new List <Entity>();

            for (int entityID = 0; entityID < EntityMasks.Count; entityID++)
            {
                ComparableBitArray entityMask = EntityMasks[entityID];
                if (entityMask == null)
                {
                    continue;
                }

                if ((entityMask & dataBlobMask) == BlankDataBlobMask())
                {
                    entities.Add(_entities[entityID]);
                }
            }

            return(entities);
        }
Exemple #2
0
        public List <Entity> GetAllEntitiesWithDataBlob <T>() where T : BaseDataBlob
        {
            int typeIndex = GetTypeIndex <T>();

            ComparableBitArray dataBlobMask = BlankDataBlobMask();

            dataBlobMask[typeIndex] = true;

            return(GetAllEntitiesWithDataBlobs(dataBlobMask));
        }
Exemple #3
0
        private static bool CheckAuthorization(Player authorizedPlayer, Entity entity)
        {
            // Get the datablob mask to avoid unnecessary validation checks on method calls.
            ComparableBitArray entityMask = entity.DataBlobMask;

            if (IsSystemBodyAuthorized(authorizedPlayer, entity, entityMask))
            {
                return(true);
            }

            if (IsOwnedEntityAuthorized(authorizedPlayer, entity, entityMask))
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        public List <Entity> GetAllEntitiesWithOUTDataBlobs(AuthenticationToken authToken, [NotNull] ComparableBitArray dataBlobMask)
        {
            List <Entity> allEntities        = GetAllEntitiesWithOUTDataBlobs(dataBlobMask);
            var           authorizedEntities = new List <Entity>();

            foreach (Entity entity in allEntities)
            {
                if (EntityAccessControl.IsAuthorized(Game, authToken, entity))
                {
                    authorizedEntities.Add(entity);
                }
            }

            return(authorizedEntities);
        }
 /// <summary>
 /// Quickly ensures bit values are equivilent.
 /// </summary>
 private bool Equals(ComparableBitArray other)
 {
     return(other != null && Length == other.Length && _backingValues.SequenceEqual(other._backingValues));
 }
Exemple #6
0
        private static bool IsSystemBodyAuthorized(Player authorizedPlayer, Entity entity, ComparableBitArray entityMask)
        {
            if (entityMask[EntityManager.GetTypeIndex <StarInfoDB>()] ||
                entityMask[EntityManager.GetTypeIndex <SystemBodyInfoDB>()] ||
                entityMask[EntityManager.GetTypeIndex <JPSurveyableDB>()] ||
                entityMask[EntityManager.GetTypeIndex <TransitableDB>()])
            {
                // Entity systemBody
                var entityPositionDB = entity.GetDataBlob <PositionDB>();

                List <Entity> factions = FactionsWithAccess(authorizedPlayer, AccessRole.SystemKnowledge);
                foreach (Entity faction in factions)
                {
                    var factionInfoDB = faction.GetDataBlob <FactionInfoDB>();
                    foreach (Guid knownSystem in factionInfoDB.KnownSystems)
                    {
                        if (knownSystem == entityPositionDB.SystemGuid)
                        {
                            if (!entityMask[EntityManager.GetTypeIndex <TransitableDB>()])
                            {
                                return(true);
                            }

                            if (factionInfoDB.KnownJumpPoints.ContainsKey(knownSystem))
                            {
                                List <Entity> knownJumpPoints = factionInfoDB.KnownJumpPoints[knownSystem];
                                foreach (Entity knownJumpPoint in knownJumpPoints)
                                {
                                    if (knownJumpPoint == entity)
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Exemple #7
0
        private static bool IsOwnedEntityAuthorized(Player authorizedPlayer, Entity entity, ComparableBitArray entityMask)
        {
            if (entityMask[EntityManager.GetTypeIndex <OwnedDB>()])
            {
                var entityOwnedDB = entity.GetDataBlob <OwnedDB>();
                var factions      = new List <Entity>();

                if (entityMask[EntityManager.GetTypeIndex <SensorProfileDB>()])
                {
                    factions = FactionsWithAccess(authorizedPlayer, AccessRole.SensorVision);
                }

                /*
                 * if (entityMask[EntityManager.GetTypeIndex<ColonyInfoDB>()])
                 * {
                 *  // Check if entity is a SensorContact
                 *  if (entityOwnedDB.OwnedByFaction == entityOwnedDB.ObjectOwner)
                 *  {
                 *      // Entity is not a SensorContact
                 *      factions = FactionsWithAccess(authorizedPlayer, AccessRole.ColonyVision);
                 *  }
                 * }
                 * else if (entityMask[EntityManager.GetTypeIndex<ShipInfoDB>()])
                 * {
                 *  var entityShipInfoDB = entity.GetDataBlob<ShipInfoDB>();
                 *  if (entityOwnedDB.OwnedByFaction == entityOwnedDB.ObjectOwner)
                 *  {
                 *      if (entityShipInfoDB.IsClassDefinition())
                 *      {
                 *          factions = FactionsWithAccess(authorizedPlayer, AccessRole.Intelligence);
                 *      }
                 *      else
                 *      {
                 *          // Entity is an actual ship
                 *          factions = FactionsWithAccess(authorizedPlayer, AccessRole.UnitVision);
                 *      }
                 *  }
                 * }
                 * else if (entityMask[EntityManager.GetTypeIndex<FactionInfoDB>()])
                 * {
                 *  if (entityOwnedDB.OwnedByFaction == entityOwnedDB.ObjectOwner)
                 *  {
                 *      factions = FactionsWithAccess(authorizedPlayer, AccessRole.FullAccess);
                 *  }
                 * } */

                foreach (Entity faction in factions)
                {
                    if (faction == entityOwnedDB.OwnedByFaction)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #8
0
 private static bool IsOwnedEntityAuthorized(Player authorizedPlayer, Entity entity, ComparableBitArray entityMask)
 {
     //TODO: TotalyHacked because f**k knows how we're going to do this now.
     return(true);
 }