예제 #1
0
        public async Task <Server> UpdateConfiguration(int id, ServerConfigurationModel configurationModel)
        {
            var server = await Get(id);

            var existingProperties = ServerPropertiesSerializer.Deserialize(server.SerializedProperties);
            var mergedProperties   = ServerPropertiesSerializer.Merge(existingProperties, configurationModel.Properties);

            server.SerializedProperties = ServerPropertiesSerializer.Serialize(mergedProperties);
            server.MainPort             = configurationModel.ServerPort;
            server.MemoryAllocationMB   = configurationModel.MemoryAllocationMB;
            server.Description          = configurationModel.Description;
            server.World = _context.Worlds.FirstOrDefault(w => w.ID == configurationModel.WorldID);
            server.Image = _context.Images.FirstOrDefault(i => i.ID == configurationModel.ImageID);

            if (server.Image.SupportsMods && configurationModel.ModIDs != null)
            {
                server.Mods = configurationModel.ModIDs.Select(i => _context.Mods.FirstOrDefault(m => m.ID == i)).ToList();
            }

            server.NeedsRecreate = true;

            _context.Update(server);
            await _context.SaveChangesAsync();

            return(server);
        }
예제 #2
0
        public void ModelSerializesCorrectly()
        {
            var serverProperties = new ServerProperties();

            var data = ServerPropertiesSerializer.Serialize(serverProperties);

            Assert.DoesNotContain("_", data);
            Assert.NotEmpty(data);
        }
예제 #3
0
        public async Task <Server> Add(ServerAddModel serverAddModel)
        {
            var serializedProperties = ServerPropertiesSerializer.Serialize(new ServerProperties());

            var server = new Server
            {
                Description          = serverAddModel.Description,
                Image                = _context.Images.FirstOrDefault(i => i.ID == serverAddModel.ImageID),
                World                = _context.Worlds.FirstOrDefault(w => w.ID == serverAddModel.WorldID),
                SerializedProperties = serializedProperties,
                MainPort             = serverAddModel.ServerPort,
                MemoryAllocationMB   = serverAddModel.MemoryAllocationMB,
                QueryPort            = serverAddModel.ServerPort + 1000,
                RconPort             = serverAddModel.ServerPort + 2000
            };

            if (server.Image == null)
            {
                throw new BadInputException("No such image");
            }

            if (server.World == null)
            {
                throw new BadInputException("No such world");
            }

            if (server.Image.SupportsMods && serverAddModel.ModIDs != null)
            {
                server.Mods = serverAddModel.ModIDs.Select(id => _context.Mods.FirstOrDefault(m => m.ID == id)).ToArray();
            }

            await _context.Servers.AddAsync(server);

            await _context.SaveChangesAsync();

            return(server);
        }