Esempio n. 1
0
        /// <summary>
        /// Formats a map name as a file name
        /// </summary>
        /// <param name="mapName"></param>
        /// <returns></returns>
        public string FormatMapFileName(string mapName)
        {
            if (mapName == null)
            {
                throw new ArgumentNullException(nameof(mapName));
            }

            return(Path.Combine(_mapsDirectory, mapName + FileExtensionUtils.AsExtension(_bspExtension)));
        }
Esempio n. 2
0
        public BSPModelUtils(string bspModelNamePrefix, string mapsDirectory, string bspExtension)
        {
            _bspModelNamePrefix = bspModelNamePrefix ?? throw new ArgumentNullException(nameof(bspModelNamePrefix));
            _mapsDirectory      = mapsDirectory ?? throw new ArgumentNullException(nameof(mapsDirectory));
            _bspExtension       = bspExtension ?? throw new ArgumentNullException(nameof(bspExtension));

            _mapFileNameBaseRegexString =
                mapsDirectory
                + $"[{Regex.Escape(Path.DirectorySeparatorChar.ToString() + Path.AltDirectorySeparatorChar.ToString())}](\\w+)"
                + Regex.Escape(FileExtensionUtils.AsExtension(bspExtension));
        }
Esempio n. 3
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();
            }
        }