public async Task <IActionResult> Create([Bind("Label")] Modset modset, IFormFile data) { await _service.ParseArma3Modset(modset, data); if (ModelState.IsValid) { modset.GameType = GameServerType.Arma3; modset.AccessToken = GameServerService.GenerateToken(); modset.Label = modset.Label ?? modset.Name; _context.Add(modset); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(modset)); }
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)); }
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; } }
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); }