示例#1
0
        public RconConnection GetConnectionForServer(int serverId)
        {
            RconConnection connection = null;

            //lock (_connections)
            //{
            //connection = _connections.FirstOrDefault(c => c.ServerId == serverId);
            if (connection == null)
            {
                using (var scope = _serviceFactory.CreateScope())
                {
                    var server = scope.ServiceProvider.GetService <IServerRepository>().GetWithDockerInfo(serverId).Result;
                    if (!server.IsAlive)
                    {
                        throw new Exception("Server not alive");
                    }

                    var properties = ServerPropertiesSerializer.Deserialize(server.Server.SerializedProperties);

                    connection = new RconConnection(_rconIP, (ushort)server.Server.RconPort, properties.Rcon__Password, serverId);
                    //_connections.Add(connection);
                }
            }
            //}

            return(connection);
        }
示例#2
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);
        }
示例#3
0
        public void ModelDeserializesCorrectly()
        {
            var data = @"#Minecraft server properties
#(File Modification Datestamp)
max-tick-time=60000
generator-settings=
allow-nether=true
force-gamemode=false
gamemode=0
enable-query=false
player-idle-timeout=0
difficulty=1
spawn-monsters=true
op-permission-level=4
announce-player-achievements=true
pvp=true
snooper-enabled=true
level-type=DEFAULT
hardcore=false
enable-command-block=false
max-players=20
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
server-port=25565
server-ip=
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=10
resource-pack=
spawn-animals=true
white-list=false
generate-structures=true
online-mode=true
max-build-height=256
level-seed=
prevent-proxy-connections=false
motd=A Minecraft Server
enable-rcon=false";

            var serverProperties = ServerPropertiesSerializer.Deserialize(data);

            Assert.Equal("A Minecraft Server", serverProperties.Motd);
            Assert.Equal(25565, serverProperties.Server_Port);
        }