示例#1
0
        internal void OnAddEntity(AddEntityOp op)
        {
            var entityId = new EntityId(op.EntityId);

            if (worker.EntityIdToEntity.ContainsKey(entityId))
            {
                throw new InvalidSpatialEntityStateException(
                          string.Format(Errors.EntityAlreadyExistsError, entityId.Id));
            }

            Profiler.BeginSample("OnAddEntity");
            var entity = EntityManager.CreateEntity();

            EntityManager.AddComponentData(entity, new SpatialEntityId
            {
                EntityId = entityId
            });
            EntityManager.AddComponent(entity, ComponentType.Create <NewlyAddedSpatialOSEntity>());

            foreach (var AddCommandCompoent in AddAllCommandComponents)
            {
                AddCommandCompoent(entity);
            }

            WorldCommands.AddWorldCommandRequesters(World, EntityManager, entity);
            worker.EntityIdToEntity.Add(entityId, entity);
            Profiler.EndSample();
        }
示例#2
0
        private void OnAddEntity(AddEntityOp op)
        {
            var entityId = op.EntityId;

            if (worker.EntityMapping.ContainsKey(entityId))
            {
                worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(Errors.DuplicateAdditionOfEntity)
                                               .WithField(LoggingUtils.LoggerName, LoggerName)
                                               .WithField(LoggingUtils.EntityId, entityId));
                return;
            }

            var entity = EntityManager.CreateEntity();

            EntityManager.AddComponentData(entity, new SpatialEntityId
            {
                EntityId = entityId
            });
            EntityManager.AddComponentData(entity, new NewlyAddedSpatialOSEntity());

            foreach (var AddCommandCompoent in AddAllCommandComponents)
            {
                AddCommandCompoent(entity);
            }

            WorldCommands.AddWorldCommandRequesters(World, EntityManager, entity);
            worker.EntityMapping.Add(entityId, entity);
        }
示例#3
0
        private void SetupDispatcherHandlers()
        {
            // Find all component specific dispatchers and create an instance.
            var componentDispatcherTypes = AppDomain.CurrentDomain.GetAssemblies()
                                           .SelectMany(assembly => assembly.GetTypes())
                                           .Where(type => typeof(ComponentDispatcherHandler).IsAssignableFrom(type) && !type.IsAbstract &&
                                                  type.GetCustomAttribute(typeof(DisableAutoRegisterAttribute)) ==
                                                  null);

            WorldCommands.AddWorldCommandRequesters(World, EntityManager, worker.WorkerEntity);
            foreach (var componentDispatcherType in componentDispatcherTypes)
            {
                AddDispatcherHandler((ComponentDispatcherHandler)
                                     Activator.CreateInstance(componentDispatcherType, worker, World));
            }

            Dispatcher.OnAddEntity(OnAddEntity);
            Dispatcher.OnRemoveEntity(OnRemoveEntity);
            Dispatcher.OnDisconnect(OnDisconnect);
            Dispatcher.OnCriticalSection(op => { inCriticalSection = op.InCriticalSection; });

            Dispatcher.OnAddComponent(OnAddComponent);
            Dispatcher.OnRemoveComponent(OnRemoveComponent);
            Dispatcher.OnComponentUpdate(OnComponentUpdate);
            Dispatcher.OnAuthorityChange(OnAuthorityChange);

            Dispatcher.OnCommandRequest(OnCommandRequest);
            Dispatcher.OnCommandResponse(OnCommandResponse);

            Dispatcher.OnCreateEntityResponse(OnCreateEntityResponse);
            Dispatcher.OnDeleteEntityResponse(OnDeleteEntityResponse);
            Dispatcher.OnReserveEntityIdsResponse(OnReserveEntityIdsResponse);
            Dispatcher.OnEntityQueryResponse(OnEntityQueryResponse);
        }
示例#4
0
 private void OnDisconnect(DisconnectOp op)
 {
     WorldCommands.DeallocateWorldCommandRequesters(EntityManager, worker.WorkerEntity);
     EntityManager.AddSharedComponentData(worker.WorkerEntity,
                                          new OnDisconnected {
         ReasonForDisconnect = op.Reason
     });
 }
示例#5
0
 // Sets up all the command hooks
 internal static void Init()
 {
     ModerationCommands.Init();
     BuildingCommands.Init();
     InfoCommands.Init();
     WorldCommands.Init();
     ZoneCommands.Init();
     MaintenanceCommands.Init();
     ChatCommands.Init();
 }
        private Entity SetupTestEntity()
        {
            var entity   = entityManager.CreateEntity();
            var entityId = new EntityId(TestEntityId);

            entityManager.AddComponentData(entity, new SpatialEntityId {
                EntityId = entityId
            });
            worker.EntityIdToEntity.Add(entityId, entity);

            WorldCommands.AddWorldCommandRequesters(world, entityManager, entity);

            return(entity);
        }
        internal void OnRemoveEntity(RemoveEntityOp op)
        {
            var entityId = op.EntityId;

            if (!worker.TryGetEntity(entityId, out var entity))
            {
                throw new InvalidSpatialEntityStateException(
                          string.Format(Errors.EntityNotFoundForDeleteError, entityId.Id));
            }

            WorldCommands.DeallocateWorldCommandRequesters(EntityManager, entity);
            EntityManager.DestroyEntity(worker.EntityIdToEntity[entityId]);
            worker.EntityIdToEntity.Remove(entityId);
        }
示例#8
0
文件: World.cs 项目: elavanis/Mud
        private void DoWorldCommands()
        {
            string command = null;

            while (WorldCommands.TryDequeue(out command))
            {
                switch (command)
                {
                case "GameStats":
                    GenerateGameStats();
                    break;
                }
            }
        }
示例#9
0
 // Sets up all the command hooks
 internal static void Init()
 {
     ModerationCommands.Init();
     BuildingCommands.Init();
     InfoCommands.Init();
     WorldCommands.Init();
     ZoneCommands.Init();
     MaintenanceCommands.Init();
     ChatCommands.Init();
     Logger.Log(LogType.Debug,
                "CommandManager: {0} commands registered ({1} hidden, {2} aliases)",
                Commands.Count,
                GetCommands(true).Length,
                Aliases.Count);
 }
示例#10
0
        public override bool ReadParams(CommandReader cmd)
        {
            // get image URL
            string urlstr = cmd.Next();

            if (!WorldCommands.parseUrl(ref urlstr, Player))
            {
                return(false);
            }

            // validate the image URL
            Uri url;

            if (!Uri.TryCreate(urlstr, UriKind.Absolute, out url))
            {
                Player.Message("DrawImage: Invalid URL given.");
                return(false);
            }
            else if (!url.Scheme.Equals(Uri.UriSchemeHttp) && !url.Scheme.Equals(Uri.UriSchemeHttps))
            {
                Player.Message("DrawImage: Invalid URL given. Only HTTP and HTTPS links are allowed.");
                return(false);
            }

            ImageUrl = url;

            // Check if player gave optional second argument (palette name)
            string paletteName = cmd.Next();

            if (paletteName != null)
            {
                Palette = BlockPalette.FindPalette(paletteName);
                if (Palette == null)
                {
                    Player.Message("DrawImage: Unrecognized palette \"{0}\". Available palettes are: \"{1}\"",
                                   paletteName, BlockPalette.Palettes.JoinToString(pal => pal.Name));
                    return(false);
                }
            }
            else
            {
                // default to "Light" (lit single-layer) palette
                Palette = BlockPalette.FindPalette("Light");
            }

            // All set
            return(true);
        }
示例#11
0
        private void OnRemoveEntity(RemoveEntityOp op)
        {
            var entityId = op.EntityId;

            if (!worker.TryGetEntity(entityId, out var entity))
            {
                worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(Errors.NoEntityFoundDuringDeletion)
                                               .WithField(LoggingUtils.LoggerName, LoggerName)
                                               .WithField(LoggingUtils.EntityId, entityId));
                return;
            }

            WorldCommands.DeallocateWorldCommandRequesters(EntityManager, entity);
            EntityManager.DestroyEntity(worker.EntityMapping[entityId]);
            worker.EntityMapping.Remove(entityId);
        }
示例#12
0
        private void SetupDispatcherHandlers()
        {
            // Find all component specific dispatchers and create an instance.
            var componentDispatcherTypes = AppDomain.CurrentDomain.GetAssemblies()
                                           .SelectMany(assembly => assembly.GetTypes())
                                           .Where(type => typeof(ComponentDispatcherHandler).IsAssignableFrom(type) && !type.IsAbstract);

            WorldCommands.AddWorldCommandRequesters(World, EntityManager, worker.WorkerEntity);
            foreach (var componentDispatcherType in componentDispatcherTypes)
            {
                var componentDispatcher =
                    (ComponentDispatcherHandler)Activator.CreateInstance(componentDispatcherType, worker, World);
                componentSpecificDispatchers.Add(componentDispatcher.ComponentId, componentDispatcher);
                AddAllCommandComponents.Add(componentDispatcher.AddCommandComponents);
                componentDispatcher.AddCommandComponents(worker.WorkerEntity);
            }

            dispatcher.OnAddEntity(OnAddEntity);
            dispatcher.OnRemoveEntity(OnRemoveEntity);
            dispatcher.OnDisconnect(OnDisconnect);
            dispatcher.OnCriticalSection(op => { inCriticalSection = op.InCriticalSection; });

            dispatcher.OnAddComponent(OnAddComponent);
            dispatcher.OnRemoveComponent(OnRemoveComponent);
            dispatcher.OnComponentUpdate(OnComponentUpdate);
            dispatcher.OnAuthorityChange(OnAuthorityChange);

            dispatcher.OnCommandRequest(OnCommandRequest);
            dispatcher.OnCommandResponse(OnCommandResponse);

            dispatcher.OnCreateEntityResponse(OnCreateEntityResponse);
            dispatcher.OnDeleteEntityResponse(OnDeleteEntityResponse);
            dispatcher.OnReserveEntityIdsResponse(OnReserveEntityIdsResponse);
            dispatcher.OnEntityQueryResponse(OnEntityQueryResponse);

            ClientError.ExceptionCallback = HandleException;
        }
        public void TearDown()
        {
            foreach (var entity in worker.EntityIdToEntity.Values)
            {
                try
                {
                    WorldCommands.DeallocateWorldCommandRequesters(entityManager, entity);
                }
                catch (Exception)
                {
                }
            }

            worker.EntityIdToEntity.Clear();

            using (var allEntities = entityManager.GetAllEntities())
            {
                foreach (var entity in allEntities.Where(x => x != worker.WorkerEntity))
                {
                    entityManager.DestroyEntity(entity);
                }
            }

            firstComponentDispatcher.Reset();
            secondComponentDispatcher.Reset();

            createEntityStorage.CommandRequestsInFlight.Clear();
            deleteEntityStorage.CommandRequestsInFlight.Clear();
            reserveEntityIdsStorage.CommandRequestsInFlight.Clear();
            entityQueryStorage.CommandRequestsInFlight.Clear();

            WorldCommands.CreateEntity.ResponsesProvider.CleanDataInWorld(world);
            WorldCommands.EntityQuery.ResponsesProvider.CleanDataInWorld(world);
            WorldCommands.DeleteEntity.ResponsesProvider.CleanDataInWorld(world);
            WorldCommands.ReserveEntityIds.ResponsesProvider.CleanDataInWorld(world);
        }
示例#14
0
        public override bool Prepare(Vector3I[] marks)
        {
            // Check the given marks
            if (marks == null)
            {
                throw new ArgumentNullException("marks");
            }
            if (marks.Length != 2)
            {
                throw new ArgumentException("DrawImage: Exactly 2 marks needed.", "marks");
            }

            // Make sure that a direction was given
            Vector3I delta = marks[1] - marks[0];

            if (Math.Abs(delta.X) == Math.Abs(delta.Y))
            {
                throw new ArgumentException(
                          "DrawImage: Second mark must specify a definite direction " +
                          "(north, east, south, or west) from first mark.",
                          "marks");
            }
            Marks = marks;

            // Download the image
            if (ImageBitmap == null)
            {
                ImageBitmap = WorldCommands.DownloadImage(ImageUrl.ToString(), Player);
                if (ImageBitmap == null)
                {
                    throw new Exception("Error downloading image");
                }
            }

            Vector3I endCoordOffset = CalculateCoordConversion(delta);

            // Calculate maximum bounds, and warn if we're pushing out of the map
            BoundingBox fullBounds = new BoundingBox(Marks[0], Marks[0] + endCoordOffset);

            if (fullBounds.XMin < 0 || fullBounds.XMax > Map.Width - 1)
            {
                Player.Message("&WDrawImage: Not enough room horizontally (X), image cut off.");
            }
            if (fullBounds.YMin < 0 || fullBounds.YMax > Map.Length - 1)
            {
                Player.Message("&WDrawImage: Not enough room horizontally (Y), image cut off.");
            }
            if (fullBounds.ZMin < 0 || fullBounds.ZMax > Map.Height - 1)
            {
                Player.Message("&WDrawImage: Not enough room vertically, image cut off.");
            }

            // clip bounds to world boundaries
            Bounds = Map.Bounds.GetIntersection(fullBounds);
            BlocksTotalEstimate = Bounds.Volume;

            // set starting coordinate
            imageX = minX;
            imageY = minY;
            layer  = 0;

            Brush = this;
            return(true);
        }