Exemple #1
0
        /// <summary>
        /// Modifies the dedicated XML document
        /// with the configured options of
        /// the dedicatedItem
        /// </summary>
        /// <param name="dedicatedXml">The dedicated XML document</param>
        /// <param name="dedicatedItem">The dedicated item</param>
        private void ModifyDedicatedXml(XmlDocument dedicatedXml, DedicatedItem dedicatedItem)
        {
            if (dedicatedItem.Port > 0)
            {
                _logger.Debug("Writing port...");
                WritePort(dedicatedXml, dedicatedItem.Port);
            }

            if (!string.IsNullOrWhiteSpace(dedicatedItem.GameName))
            {
                _logger.Debug("Writing game name...");
                WriteGameName(dedicatedXml, dedicatedItem.GameName);
            }

            if (dedicatedItem.RandomLevelOrder)
            {
                _logger.Debug("Randomizing level order...");
                RandomizeLevelOrder(dedicatedXml);
            }
            else if (dedicatedItem.RandomStartLevel)
            {
                _logger.Debug("Randomizing start level...");
                RandomizeStartLevel(dedicatedXml);
            }
        }
Exemple #2
0
        /// <summary>
        /// Launches a single server
        /// </summary>
        /// <param name="dedicatedItem">The dedicated item</param>
        /// <returns>The server object or null in error cases</returns>
        private LotrcServer LaunchSingleServer(DedicatedItem dedicatedItem)
        {
            var dedicatedFileName = dedicatedItem.FileName;
            var dedicatedFilePath = _documentsServerDirectoryPath + Path.DirectorySeparatorChar + dedicatedFileName;

            if (!File.Exists(dedicatedFilePath))
            {
                _logger.Warn($"Filtered out not existent dedicated file '{dedicatedFileName}'");
                return(null);
            }

            // TODO: add logic to randomize level order/start level

            var dedicatedXml = new XmlDocument();

            try {
                dedicatedXml.Load(dedicatedFilePath);
            } catch (Exception exc) {
                _logger.Error($"Failed to load '{dedicatedFilePath}': {exc.Message}");
                return(null);
            }

            ModifyDedicatedXml(dedicatedXml, dedicatedItem);

            var fileContent = dedicatedXml.OuterXml;

            // var fileContent = File.ReadAllText(dedicatedFilePath);

            try {
                File.WriteAllText(_targetFilePath, fileContent);
            } catch (Exception exc) {
                _logger.Error($"Failed to write content of '{dedicatedFileName}' into '{_targetFileName}': {exc.Message}");
                return(null);
            }

            _logger.Debug($"Wrote content of '{dedicatedFileName}' into '{_targetFileName}'");

            Process process;

            try {
                process = Process.Start(_serverFileName); // start ConquestServer.exe
            } catch (Exception exception) {
                _logger.Error($"Failed to launch server ('{_serverFileName}' in directory '{_serverFilePath}'). Please make sure that this application is inside the same directory as the ConquestServer.exe. Error: {exception.Message}");
                return(null);
            }

            var server = new LotrcServer {
                ProcessId     = process.Id,
                DedicatedItem = dedicatedItem
            };

            return(server);
        }