private async Task HandleFiles(GameServerConfiguration gsc, IFormFile modsetFile, IFormFile missionFile)
        {
            if (missionFile != null)
            {
                gsc.ServerMission = _service.UploadMissionFile(missionFile, gsc.GameServer);
            }

            if (modsetFile != null)
            {
                var modset = new Modset();
                var errors = await _service.ParseArma3Modset(modset, modsetFile);

                if (!string.IsNullOrEmpty(errors))
                {
                    ModelState.AddModelError("ModsetID", errors);
                    return;
                }
                await GetOrCreateModset(gsc, modset);
            }

            if (gsc.ModsetID != null)
            {
                var actualModset = await _context.Modsets.FindAsync(gsc.ModsetID.Value);

                var errors = _service.ValidateModsetOnServer(actualModset, gsc.GameServer);
                if (!string.IsNullOrEmpty(errors))
                {
                    ModelState.AddModelError("ModsetID", errors);
                    return;
                }
            }
        }
Esempio n. 2
0
        private static bool StartServer()
        {
            //TODO parse args for -config parameter!
            FileInfo dolserver = new FileInfo(Assembly.GetExecutingAssembly().Location);

            Directory.SetCurrentDirectory(dolserver.DirectoryName);
            FileInfo configFile            = new FileInfo("./config/serverconfig.xml");
            GameServerConfiguration config = new GameServerConfiguration();

            if (configFile.Exists)
            {
                config.LoadFromXMLFile(configFile);
            }
            else
            {
                if (!configFile.Directory.Exists)
                {
                    configFile.Directory.Create();
                }
                config.SaveToXMLFile(configFile);
            }

            GameServer.CreateInstance(config);

            return(GameServer.Instance.Start());
        }
Esempio n. 3
0
        [TestFixtureSetUp] public virtual void Init()
        {
            Directory.SetCurrentDirectory("../../debug");
            string CD = Directory.GetCurrentDirectory();

            Console.WriteLine(CD);
            if (GameServer.Instance == null)
            {
                FileInfo configFile            = new FileInfo("./config/serverconfig.xml");
                GameServerConfiguration config = new GameServerConfiguration();
                if (!configFile.Exists)
                {
                    config.SaveToXMLFile(configFile);
                }
                else
                {
                    config.LoadFromXMLFile(configFile);
                }
                GameServer.CreateInstance(config);
                Directory.SetCurrentDirectory(CD);
            }
            if (!GameServer.Instance.IsRunning)
            {
                Language.LanguageMgr.SetLangPath(Path.Combine(CD, "languages"));
                Console.WriteLine("Starting GameServer");
                if (!GameServer.Instance.Start())
                {
                    Console.WriteLine("Error init GameServer");
                }
            }
            else
            {
                Console.WriteLine("GameServer already running, skip init of Gameserver...");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create Game Server Instance for Tests
        /// </summary>
        public static void CreateGameServerInstance()
        {
            Console.WriteLine("Create Game Server Instance");
            DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().Location).LocalPath).Directory;

            Console.WriteLine("Code Base: " + CodeBase.FullName);
            DirectoryInfo FakeRoot = CodeBase.Parent;

            Console.WriteLine("Fake Root: " + FakeRoot.FullName);

            if (GameServer.Instance == null || GameServer.Instance.GetType() != typeof(GameServer))
            {
                GameServerConfiguration config = new GameServerConfiguration();
                config.RootDirectory      = FakeRoot.FullName;
                config.DBType             = ConnectionType.DATABASE_SQLITE;
                config.DBConnectionString = $"Data Source={Path.Combine(config.RootDirectory, "dol-tests-only.sqlite3.db")}";
                config.Port     = 0;             // Auto Choosing Listen Port
                config.UDPPort  = 0;             // Auto Choosing Listen Port
                config.IP       = System.Net.IPAddress.Parse("127.0.0.1");
                config.UDPIP    = System.Net.IPAddress.Parse("127.0.0.1");
                config.RegionIP = System.Net.IPAddress.Parse("127.0.0.1");

                GameServer.LoadTestDouble(new GameServerWithDefaultDB(config));

                Console.WriteLine("Game Server Instance Created !");
            }
        }
Esempio n. 5
0
        public virtual void Init()
        {
            DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath).Directory;

            Console.WriteLine("Code Base: " + CodeBase.FullName);
            DirectoryInfo FakeRoot = CodeBase.Parent;

            Console.WriteLine("Fake Root: " + FakeRoot.FullName);
            if (GameServer.Instance == null)
            {
                GameServerConfiguration config = new GameServerConfiguration();
                config.RootDirectory = FakeRoot.FullName;
                GameServer.CreateInstance(config);
            }
            if (!GameServer.Instance.IsRunning)
            {
                Console.WriteLine("Starting GameServer");
                if (!GameServer.Instance.Start())
                {
                    Console.WriteLine("Error init GameServer");
                }
            }
            else
            {
                Console.WriteLine("GameServer already running, skip init of Gameserver...");
            }
        }
Esempio n. 6
0
        static void LoadExistingSettings()
        {
            try
            {
                if (!File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml"))
                    return;

                ConfigFile = new FileInfo(Application.StartupPath + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml");
                Config = new GameServerConfiguration();

                if (ConfigFile.Exists)
                {
                    Config.LoadFromXMLFile(ConfigFile);
                    MainForm.serverTypeComboBox.Text = Config.ServerType.ToString().Replace("GST_", "");
                    MainForm.shortNameTextBox.Text = Config.ServerNameShort;
                    MainForm.FullNameTextBox.Text = Config.ServerName;
                }
                else
                {
                    Config.SaveToXMLFile(ConfigFile);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Create Game Server Instance for Tests
        /// </summary>
        public static void CreateGameServerInstance()
        {
            Console.WriteLine("Create Game Server Instance");
            DirectoryInfo CodeBase = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath).Directory;

            Console.WriteLine("Code Base: " + CodeBase.FullName);
            DirectoryInfo FakeRoot = CodeBase.Parent;

            Console.WriteLine("Fake Root: " + FakeRoot.FullName);

            if (GameServer.Instance == null)
            {
                GameServerConfiguration config = new GameServerConfiguration();
                config.RootDirectory      = FakeRoot.FullName;
                config.DBType             = ConnectionType.DATABASE_SQLITE;
                config.DBConnectionString = string.Format("Data Source={0};Version=3;Pooling=False;Cache Size=1073741824;Journal Mode=Off;Synchronous=Off;Foreign Keys=True;Default Timeout=60",
                                                          Path.Combine(config.RootDirectory, "dol-tests-only.sqlite3.db"));
                config.Port     = 0;             // Auto Choosing Listen Port
                config.UDPPort  = 0;             // Auto Choosing Listen Port
                config.IP       = System.Net.IPAddress.Parse("127.0.0.1");
                config.UDPIP    = System.Net.IPAddress.Parse("127.0.0.1");
                config.RegionIP = System.Net.IPAddress.Parse("127.0.0.1");
                GameServer.CreateInstance(config);
                Console.WriteLine("Game Server Instance Created !");
            }
        }
Esempio n. 8
0
        static void LoadExistingSettings()
        {
            try
            {
                if (!File.Exists(Application.StartupPath + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml"))
                {
                    return;
                }

                ConfigFile = new FileInfo(Application.StartupPath + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml");
                Config     = new GameServerConfiguration();

                if (ConfigFile.Exists)
                {
                    Config.LoadFromXMLFile(ConfigFile);
                    MainForm.serverTypeComboBox.Text = Config.ServerType.ToString().Replace("GST_", "");
                    MainForm.shortNameTextBox.Text   = Config.ServerNameShort;
                    MainForm.FullNameTextBox.Text    = Config.ServerName;
                }
                else
                {
                    Config.SaveToXMLFile(ConfigFile);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 9
0
 public void InitConfig()
 {
     if (dolConfig == null)
     {
         dolConfig = new GameServerConfiguration();
         dolConfig.LoadFromXMLFile(new FileInfo(QuestDesignerMain.WorkingDirectory + System.Configuration.ConfigurationManager.AppSettings["DOLServerConfigFile"]));
     }
 }
Esempio n. 10
0
        internal async Task SyncConfig(SftpClient client, GameConfig config, GameServerConfiguration currentConfig)
        {
            var wasUpdated = false;

            foreach (var file in config.ConfigFiles)
            {
                string fullPath     = GetFileFullPath(config, file);
                var    content      = string.Empty;
                var    lastWriteUTC = DateTime.MinValue;
                if (client.Exists(fullPath))
                {
                    content      = client.ReadAllText(fullPath);
                    lastWriteUTC = client.GetLastWriteTimeUtc(fullPath);
                }
                var dbFile = currentConfig.Files.FirstOrDefault(f => f.Path == file);
                if (dbFile == null)
                {
                    dbFile = new GameConfigurationFile()
                    {
                        Configuration = currentConfig,
                        Content       = content,
                        LastChangeUTC = lastWriteUTC,
                        Path          = file
                    };
                    currentConfig.Files.Add(dbFile);
                    _context.Add(dbFile);
                    wasUpdated = true;
                }
                else if (dbFile.Content != content)
                {
                    dbFile.Content       = content;
                    dbFile.LastChangeUTC = lastWriteUTC;
                    _context.Update(dbFile);
                    wasUpdated = true;
                }
            }

            if (wasUpdated)
            {
                await UpdateComputedProperties(currentConfig);

                _context.GameServerConfigurations.Update(currentConfig);
                await _context.SaveChangesAsync();
            }
            else if (currentConfig.Modset == null)
            {
                if (currentConfig.GameServer.Type == GameServerType.Arma3)
                {
                    await UpdateModset(currentConfig);

                    if (currentConfig.Modset != null)
                    {
                        _context.GameServerConfigurations.Update(currentConfig);
                        await _context.SaveChangesAsync();
                    }
                }
            }
        }
Esempio n. 11
0
 public PipelineFactory(ISocketChannel channel, MessageToMessageDecoder <IByteBuffer> decoder,
                        MessageToMessageEncoder <string> encoder, ClientSession.ClientSession clientSession, GameServerConfiguration configuration)
 {
     _channel       = channel;
     _decoder       = decoder;
     _encoder       = encoder;
     _clientSession = clientSession;
     _configuration = configuration;
 }
Esempio n. 12
0
        private async Task UpdateModset(GameServerConfiguration currentConfig)
        {
            var mods = currentConfig.Files.First(f => f.Path == "mods.txt").Content;

            if (currentConfig.Modset == null || currentConfig.Modset.ConfigurationFile != mods)
            {
                currentConfig.Modset = await _context.Modsets.Where(m => m.ConfigurationFile == mods).FirstOrDefaultAsync();

                currentConfig.ModsetID = currentConfig.Modset?.ModsetID;
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Set all data to default button event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void set_default_values_button_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedTab == sp_tab)
     {
         ResetSP();
     }
     else
     {
         currentConfig = new GameServerConfiguration();
         loadConfig();
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Save the GameServer configuration
 /// </summary>
 /// <param name="gsc">The GameServer configuration which should be saved.</param>
 /// <returns></returns>
 public static void saveCurrentConfiguration(GameServerConfiguration gsc)
 {
     try
     {
         FileInfo configFileInfo = new FileInfo(getCurrentConfigFile());
         gsc.SaveToXMLFile(configFileInfo);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Esempio n. 15
0
 private void CreateGameServerDefinitions(GameServerConfiguration gameServerConfiguration, int numberOfServers)
 {
     for (int i = 0; i < numberOfServers; i++)
     {
         var server = this.repositoryManager.CreateNew <GameServerDefinition>();
         server.ServerID            = (byte)i;
         server.Description         = $"Server {i}";
         server.NetworkPort         = 55901 + i;
         server.GameConfiguration   = this.gameConfiguration;
         server.ServerConfiguration = gameServerConfiguration;
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Gets the current configuration of the GameServer
        /// </summary>
        /// <returns></returns>
        public static GameServerConfiguration getCurrentConfiguration()
        {
            try
            {
                FileInfo configFileInfo        = new FileInfo(getCurrentConfigFile());
                GameServerConfiguration config = new GameServerConfiguration();
                config.LoadFromXMLFile(configFileInfo);

                return(config);
            }
            catch {
                throw;
            }
        }
Esempio n. 17
0
        internal async Task StartGameServer(ClaimsPrincipal user, GameServerConfiguration currentConfig)
        {
            await LogServerEvent(user, currentConfig.GameServer, GameLogEventType.ServerStart);

            var game = GetConfig(currentConfig.GameServer);

            await ApplyAllConfiguration(currentConfig, game);

            using (var client = GetClient(game.Server))
            {
                client.Connect();
                var result = client.RunCommand(game.StartCmd);
                Thread.Sleep(100);
                client.Disconnect();
            }
        }
        public async Task <IActionResult> Copy([Bind("GameServerConfigurationID,GameServerID,ServerName,ServerPassword,ServerMission,VoipServer,VoipChannel,VoipPassword,EventHref,EventImage,ModsetID,Label")] GameServerConfiguration gsc, IFormFile modset, IFormFile mission)
        {
            var source = await _context.GameServerConfigurations.FirstOrDefaultAsync(m => m.GameServerConfigurationID == gsc.GameServerConfigurationID);

            gsc.GameServer = await _context.GameServers
                             .Include(g => g.HostServer)
                             .FirstOrDefaultAsync(m => m.GameServerID == gsc.GameServerID);

            await HandleFiles(gsc, modset, mission);

            if (ModelState.IsValid)
            {
                var copy = new GameServerConfiguration();
                copy.AccessToken     = GameServerService.GenerateToken();
                copy.GameServerID    = gsc.GameServerID;
                copy.ServerName      = gsc.ServerName;
                copy.ServerPassword  = gsc.ServerPassword;
                copy.ServerMission   = gsc.ServerMission;
                copy.VoipServer      = gsc.VoipServer;
                copy.VoipChannel     = gsc.VoipChannel;
                copy.VoipPassword    = gsc.VoipPassword;
                copy.EventHref       = gsc.EventHref;
                copy.GamePersistName = gsc.GamePersistName;
                copy.EventImage      = gsc.EventImage;
                copy.ModsetID        = gsc.ModsetID;
                copy.Label           = gsc.Label;
                copy.Files           = (await _context.GameConfigurationFiles.Where(f => f.GameServerConfigurationID == gsc.GameServerConfigurationID).ToListAsync())
                                       .Select(f => new GameConfigurationFile()
                {
                    Configuration = copy,
                    Content       = f.Content,
                    Path          = f.Path
                }).ToList();
                await ApplyEditConfig(copy.Files, source, gsc);

                _context.Add(copy);
                _context.AddRange(copy.Files);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AdminGameServersController.Details), "AdminGameServers", new { id = gsc.GameServerID }));
            }
            ViewData["GameServerID"] = new SelectList(_context.GameServers, "GameServerID", "Label", gsc.GameServerID);
            PrepareDropdownLists(gsc);
            return(View(gsc));
        }
        public async Task <IActionResult> Edit(int id, [Bind("GameServerConfigurationID,VoipServer,VoipChannel,VoipPassword,EventHref,EventImage,Label")] GameServerConfiguration gsc)
        {
            if (id != gsc.GameServerConfigurationID)
            {
                return(NotFound());
            }

            var existing = await _context.GameServerConfigurations
                           .Include(g => g.GameServer).ThenInclude(g => g.HostServer)
                           .FirstOrDefaultAsync(m => m.GameServerConfigurationID == id);

            if (existing == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    existing.VoipServer      = gsc.VoipServer;
                    existing.VoipChannel     = gsc.VoipChannel;
                    existing.VoipPassword    = gsc.VoipPassword;
                    existing.EventHref       = gsc.EventHref;
                    existing.EventImage      = gsc.EventImage;
                    existing.GamePersistName = gsc.GamePersistName;
                    existing.Label           = gsc.Label;
                    _context.Update(existing);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GameServerConfigurationExists(existing.GameServerConfigurationID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id }));
            }
            return(View(existing));
        }
Esempio n. 20
0
 public ClientSession(GameServerConfiguration configuration, IEnumerable <IPacketController> packetControllers)
 {
     _isWorldClient = configuration is WorldConfiguration;
     foreach (var controller in packetControllers)
     {
         controller.RegisterSession(this);
         foreach (var methodInfo in controller.GetType().GetMethods().Where(x =>
                                                                            x.GetParameters().FirstOrDefault()?.ParameterType.BaseType == typeof(PacketDefinition)))
         {
             var type         = methodInfo.GetParameters().FirstOrDefault()?.ParameterType;
             var packetheader = (PacketHeaderAttribute)Array.Find(type?.GetCustomAttributes(true),
                                                                  ca => ca.GetType() == typeof(PacketHeaderAttribute));
             _headerMethod.Add(packetheader, new Tuple <IPacketController, Type>(controller, type));
             _controllerMethods.Add(packetheader,
                                    DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo));
         }
     }
 }
Esempio n. 21
0
 private async Task ApplyAllConfiguration(GameServerConfiguration currentConfig, GameConfig game)
 {
     if (!currentConfig.IsActive || currentConfig.GameServer.SyncFiles.Count > 0)
     {
         using (var client = GetSftpClient(currentConfig.GameServer.HostServer))
         {
             client.Connect();
             if (!currentConfig.IsActive)
             {
                 await ApplyConfiguration(currentConfig, game, client);
             }
             if (currentConfig.GameServer.SyncFiles.Count > 0)
             {
                 await UpdateSyncedFiles(currentConfig.GameServer, game, client);
             }
             client.Disconnect();
         }
     }
 }
Esempio n. 22
0
        // ReSharper disable once FunctionNeverReturns
        public void OnAction(Hashtable parameters)
        {
            Console.WriteLine("Starting GameServer ... please wait a moment!");
            FileInfo configFile;
            FileInfo currentAssembly = null;

            if (parameters["-config"] != null)
            {
                Console.WriteLine("Using config file: " + parameters["-config"]);
                configFile = new FileInfo((String)parameters["-config"]);
            }
            else
            {
                currentAssembly = new FileInfo(Assembly.GetEntryAssembly().Location);
                configFile      = new FileInfo(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "config" + Path.DirectorySeparatorChar + "serverconfig.xml");
            }

            GameServerConfiguration config = new GameServerConfiguration();

            if (configFile.Exists)
            {
                config.LoadFromXMLFile(configFile);
            }
            else
            {
                if (!configFile.Directory.Exists)
                {
                    configFile.Directory.Create();
                }
                config.SaveToXMLFile(configFile);
                if (File.Exists(currentAssembly.DirectoryName + Path.DirectorySeparatorChar + "DOLConfig.exe"))
                {
                    Console.WriteLine("No config file found, launching with default config and embedded database... (SQLite)");
                }
            }

            GameServer.CreateInstance(config);
            StartServer();

            while (true)
            {
            }
        }
        private void PrepareDropdownLists(GameServerConfiguration gameServerConfiguration)
        {
            ViewData["ModsetID"] = new SelectList(_context.Modsets, "ModsetID", "Name", gameServerConfiguration?.ModsetID);
            if (gameServerConfiguration.GameServer.HostServerID != null)
            {
                var gameConfig = _service.GetConfig(gameServerConfiguration.GameServer);

                if (!string.IsNullOrEmpty(gameConfig.MissionDirectory) && gameServerConfiguration.GameServer.Type == GameServerType.Arma3)
                {
                    using (var client = _service.GetSftpClient(gameConfig.Server))
                    {
                        client.Connect();
                        var missions = client.ListDirectory(gameConfig.MissionDirectory).Where(f => f.IsRegularFile).Select(f => Path.GetFileName(f.FullName)).Where(f => f.EndsWith(".pbo", StringComparison.OrdinalIgnoreCase)).Select(f => Path.GetFileNameWithoutExtension(f)).ToList();
                        missions.Sort();
                        ViewData["ServerMission"] = missions.Select(n => new SelectListItem(n, n)).ToList();
                        client.Disconnect();
                    }
                }
            }
        }
Esempio n. 24
0
        internal async Task UpdateComputedProperties(GameServerConfiguration currentConfig)
        {
            if (currentConfig.GameServer.Type == GameServerType.Arma3)
            {
                var cfg = currentConfig.Files.First(f => f.Path == "server.cfg").Content;

                var matchPassword = PasswordRegex.Match(cfg);
                currentConfig.ServerPassword = matchPassword.Success ? matchPassword.Groups[1].Value : "";

                var matchLabel = LabelRegex.Match(cfg);
                currentConfig.ServerName = matchLabel.Success ? matchLabel.Groups[1].Value : currentConfig.GameServer.Label;

                var matchMission = MissionRegex.Match(cfg);
                currentConfig.ServerMission = matchMission.Success ? matchMission.Groups[1].Value : "";

                await UpdateModset(currentConfig);

                currentConfig.LastChangeUTC = currentConfig.Files.Max(f => f.LastChangeUTC);
            }
        }
Esempio n. 25
0
        private void DOLConfig_Load(object sender, EventArgs e)
        {
            //load data from current config file
            try
            {
                toolstripStatusLabelValue = "Loading current configuration ...";
                currentConfig             = DOLConfigParser.getCurrentConfiguration();
                loadConfig();
                toolstripStatusLabelValue = null;
            }
            catch (System.IO.FileNotFoundException)
            {
                DialogResult result = MessageBox.Show("There is no configuration file present." + Environment.NewLine + "Do you want me to create the default configuration?" + Environment.NewLine + "Otherwise: Start the GameServer first.", "Config file not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (result == DialogResult.Yes)
                {
                    currentConfig = new GameServerConfiguration();
                    try
                    {
                        loadConfig();
                    }
                    catch (System.IO.FileNotFoundException) { }

                    saveConfig();
                    DOLConfig_Load(sender, e);
                    return;
                }
                else
                {
                    Close();
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show("There are not allowed values in the config file. Please edit them manually." + Environment.NewLine + "Exception: " + ex.Message, "Error in config file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 26
0
        private async Task ApplyConfiguration(GameServerConfiguration currentConfig, GameConfig game, SftpClient client)
        {
            foreach (var configFile in currentConfig.Files)
            {
                var fullpath = GetFileFullPath(game, configFile.Path);
                if (!client.Exists(fullpath) || client.ReadAllText(fullpath) != configFile.Content)
                {
                    WriteAllText(client, fullpath, configFile.Content);
                }
            }
            var activeList = await _context.GameServerConfigurations.Where(c => c.GameServerID == currentConfig.GameServerID && c.IsActive).ToListAsync();

            foreach (var active in activeList)
            {
                active.IsActive = false;
                _context.Update(active);
            }
            currentConfig.IsActive = true;
            _context.Update(currentConfig);
            await _context.SaveChangesAsync();
        }
        private async Task GetOrCreateModset(GameServerConfiguration gsc, Modset modset)
        {
            var existing = await _context.Modsets.FirstOrDefaultAsync(m => m.Name == modset.Name && m.ConfigurationFile == modset.ConfigurationFile);

            if (existing != null)
            {
                gsc.Modset   = existing;
                gsc.ModsetID = existing.ModsetID;
            }
            else
            {
                modset.GameType    = GameServerType.Arma3;
                modset.AccessToken = GameServerService.GenerateToken();
                modset.Label       = modset.Name;
                _context.Add(modset);
                await _context.SaveChangesAsync();

                gsc.Modset   = modset;
                gsc.ModsetID = modset.ModsetID;
            }
        }
Esempio n. 28
0
        private void CreateGameServerDefinitions(GameServerConfiguration gameServerConfiguration, int numberOfServers)
        {
            for (int i = 0; i < numberOfServers; i++)
            {
                var server = this.context.CreateNew <GameServerDefinition>();
                server.ServerID            = (byte)i;
                server.Description         = $"Server {i}";
                server.ExperienceRate      = 1.0f;
                server.GameConfiguration   = this.gameConfiguration;
                server.ServerConfiguration = gameServerConfiguration;

                var j = 0;
                foreach (var client in this.context.Get <GameClientDefinition>().ToList())
                {
                    var endPoint = this.context.CreateNew <GameServerEndpoint>();
                    endPoint.Client      = client;
                    endPoint.NetworkPort = 55901 + i + j;
                    server.Endpoints.Add(endPoint);
                    j += 20;
                }
            }
        }
        private async Task <GameServerConfiguration> GetActiveConfiguration(GameServer gameServer)
        {
            var currentConfig = await _context.GameServerConfigurations
                                .Include(g => g.Files)
                                .Include(g => g.Modset)
                                .Where(g => g.GameServerID == gameServer.GameServerID && g.IsActive)
                                .FirstOrDefaultAsync();

            if (currentConfig == null)
            {
                currentConfig = new GameServerConfiguration()
                {
                    IsActive    = true,
                    GameServer  = gameServer,
                    Label       = "Default",
                    Files       = new List <GameConfigurationFile>(),
                    AccessToken = GameServerService.GenerateToken()
                };
                _context.Add(currentConfig);
                await _context.SaveChangesAsync();
            }
            return(currentConfig);
        }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameServerInfoAdapter"/> class.
 /// </summary>
 /// <param name="gameServer">The game server.</param>
 /// <param name="configuration">The configuration.</param>
 public GameServerInfoAdapter(GameServer gameServer, GameServerConfiguration configuration)
 {
     this.gameServer    = gameServer;
     this.configuration = configuration;
     this.gameServer.PropertyChanged += this.OnGameServerPropertyChanged;
 }
Esempio n. 31
0
        /// <summary>
        /// Saves current config out of the form
        /// </summary>
        private void saveConfig()
        {
            toolstripStatusLabelValue = "Try to save configuration ...";
            if (currentConfig == null)
            {
                currentConfig = new GameServerConfiguration();
            }

            //Full Server Name
            if (this.full_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.full_server_name_textbox, "The value of \"Full Server Name\" is not set.");
                return;
            }
            currentConfig.ServerName = this.full_server_name_textbox.Text;

            //Short Server Name
            if (this.short_server_name_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.short_server_name_textbox, "The value of \"Short Server Name\" is not set.");
                return;
            }
            currentConfig.ServerNameShort = this.short_server_name_textbox.Text;

            switch (this.game_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "pvp":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvP;
                break;

            case "pve":
                currentConfig.ServerType = DOL.eGameServerType.GST_PvE;
                break;

            case "roleplay":
                currentConfig.ServerType = DOL.eGameServerType.GST_Roleplay;
                break;

            case "casual":
                currentConfig.ServerType = DOL.eGameServerType.GST_Casual;
                break;

            case "test":
                currentConfig.ServerType = DOL.eGameServerType.GST_Test;
                break;

            case "normal":
            default:
                currentConfig.ServerType = DOL.eGameServerType.GST_Normal;
                break;
            }

            //Parse Auto Account creation
            currentConfig.AutoAccountCreation = this.auto_account_creation_checkbox.Checked;

            //Ip
            if (ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.IP = new System.Net.IPAddress(ipToByteArray(this.ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(this.ip_textbox, "The value of \"IP\" is not allowed.");
                return;
            }

            //currentConfig.Ip = new System.Net.IPAddress();
            //Port
            if (this.port_textbox.Text.Length == 0 || Convert.ToUInt16(this.port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.port_textbox, "The value of \"TCP Port\" is not allowed.");
                return;
            }
            currentConfig.Port = Convert.ToUInt16(this.port_textbox.Text);

            //UDP port
            if (this.udp_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.udp_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.udp_port_textbox, "The value of \"UDP Port\" is not allowed.");
                return;
            }
            currentConfig.UDPPort = Convert.ToUInt16(this.udp_port_textbox.Text);

            //Detect Region IPs
            currentConfig.DetectRegionIP = this.detect_region_ip_checkbox.Checked;

            //Region IP
            if (region_ip_textbox.Text.Length == 0)
            {
                addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not set.");
                return;
            }
            try
            {
                currentConfig.RegionIP = new System.Net.IPAddress(ipToByteArray(this.region_ip_textbox.Text));
            }
            catch (Exception)
            {
                addWrongValueErrorHandler(this.region_ip_textbox, "The value of \"Region IP\" is not allowed.");
                return;
            }


            //Region port
            if (this.region_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.region_port_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.region_port_textbox, "The value of \"Region Port\" is not allowed.");
                return;
            }
            currentConfig.RegionPort = Convert.ToUInt16(this.region_port_textbox.Text);

            //Database Settings
            currentConfig.AutoSave = this.database_autosave_checkbox.Checked;

            //Auto database save interval
            if (this.database_autosave_interval_textbox.Text.Length == 0 || Convert.ToInt32(this.database_autosave_interval_textbox.Text) == 0)
            {
                addWrongValueErrorHandler(this.database_autosave_interval_textbox, "The value of \"Autosave Interval\" is not allowed.");
                return;
            }
            currentConfig.SaveInterval = Convert.ToInt32(this.database_autosave_interval_textbox.Text);

            //Database settings
            switch (this.database_type_selectbox.SelectedItem.ToString().ToLower())
            {
            case "xml":
                currentConfig.DBType = ConnectionType.DATABASE_XML;
                if (xml_path_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.xml_path_textbox, "The value of \"Directory\" in \"XML Database settings\" is not set.");
                    return;
                }
                currentConfig.DBConnectionString = xml_path_textbox.Text;
                break;

            case "sqlite":
                currentConfig.DBType = ConnectionType.DATABASE_SQLITE;
                break;

            case "mysql":
                currentConfig.DBType = ConnectionType.DATABASE_MYSQL;

                //Mysql connection string builder
                MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();

                //Host
                if (this.mysql_host_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_host_textbox, "The value of \"Server Address\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.Server = this.mysql_host_textbox.Text;

                //Port
                if (this.mysql_port_textbox.Text.Length == 0 || Convert.ToUInt16(this.mysql_port_textbox.Text) == 0)
                {
                    addWrongValueErrorHandler(this.mysql_port_textbox, "The value of \"Port\" in \"MySQL Database settings\" is not allowed.");
                    return;
                }
                sb.Port = Convert.ToUInt16(this.mysql_port_textbox.Text);

                //Database Name
                if (this.mysql_database_name_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_database_name_textbox, "The value of \"Database Name\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.Database = this.mysql_database_name_textbox.Text;

                //Username
                if (this.mysql_username_textbox.Text.Length == 0)
                {
                    addWrongValueErrorHandler(this.mysql_username_textbox, "The value of \"Username\" in \"MySQL Database settings\" is not set.");
                    return;
                }
                sb.UserID = this.mysql_username_textbox.Text;

                //Password
                sb.Password = this.mysql_password_textbox.Text;

                //Treat tiny as boolean
                sb.TreatTinyAsBoolean = false;

                //Set generated connection string
                currentConfig.DBConnectionString = sb.ConnectionString;

                //Just for fun: Test the connection
                mysql_test_button_Click(null, null);

                break;

            default:
                addWrongValueErrorHandler(this.database_type_selectbox, "There is no database connection selected.");
                return;
            }

            //Finally save all configuration
            DOLConfigParser.saveCurrentConfiguration(currentConfig);

            //And write extra properties
            if (this.extraOptions != null)
            {
                DOLConfigParser.saveExtraOptions(this.extraOptions);
            }

            toolstripStatusLabelValue = "Configuration saved.";
            toolstripTimer.Start();
        }