示例#1
0
        /// <summary>
        /// Start a new map, loading entities from the map entity data string
        /// </summary>
        /// <param name="command"></param>
        private void StartNewMap(ICommandArgs command)
        {
            if (command.Count == 0)
            {
                Logger.Information("map <levelname> : changes server to specified map");
                return;
            }

            Client?.Disconnect(false);

            ClearMemory();

            var mapName = command[0];

            //Remove BSP extension
            if (mapName.EndsWith(FileExtensionUtils.AsExtension(Framework.Extension.BSP)))
            {
                mapName = Path.GetFileNameWithoutExtension(mapName);
            }

            EventSystem.DispatchEvent(EngineEvents.EngineNewMapRequest);

            if (!World.IsMapValid(mapName))
            {
                Logger.Error($"map change failed: '{mapName}' not found on server.");
                return;
            }

            Server.Stop();

            EventSystem.DispatchEvent(EngineEvents.EngineStartingServer);

            //Reset time
            //TODO: define constant for initial time
            _engineTime.ElapsedTime = 1;
            _engineTime.FrameTime   = 0;

            const ServerStartFlags flags = ServerStartFlags.None;

            if (!Server.Start(mapName, null, flags))
            {
                return;
            }

            Server.Activate();

            //Listen server hosts need to connect to their own server
            if (Client != null)
            {
                //Client.CommandContext.QueueCommands($"connect {NetAddresses.Local}");
                //TODO: set up client
                Client.LocalConnect();
            }
        }