コード例 #1
0
 //? UPLOAD SERVER
 public async Task UploadNewServer(baseMcServer baseServer, byte[] serverZip, IProgress <ActionProgressUpdate> deleteProgress = default, CancellationToken cancellationToken = default)
 {
     //Write zip to file
     //unzip to "workingDirectory"
     //Get ServerProperties from uploaded files
     throw new NotImplementedException();
 }
コード例 #2
0
        public async Task CreateServerSimple(string serverName,
                                             string minecraftVersion,
                                             string minRam,
                                             string maxRam,
                                             string workingFolder,
                                             string jarFile,
                                             string secondaryVersionNumber,
                                             ServerType serverType,
                                             int port)
        {
            baseMcServer baseMcServer = new baseMcServer
            {
                ServerName             = serverName,
                ServerType             = serverType,
                MinecraftVersion       = minecraftVersion,
                Port                   = port,
                MinRam                 = minRam,
                MaxRam                 = maxRam,
                WorkingFolder          = workingFolder,
                JarFile                = jarFile,
                SecondaryVersionNumber = secondaryVersionNumber
            };

            await CreateServer(baseMcServer);
        }
コード例 #3
0
        //? Create new servers
        // download jar files
        // add instance to DB
        // Setup EULA and ServerProperties files.
        public async Task <McServer> CreateNewServer(baseMcServer baseMcServer, IProgress <ActionProgressUpdate> createProgress = default, CancellationToken cancellationToken = default)
        {
            McServer createdMcServer = await _mcServerInstallManager.CreateMcServerOnDisk(baseMcServer, createProgress, cancellationToken);

            await _serverContext.Servers.AddAsync(createdMcServer.ToMinecraftServer(), cancellationToken);

            await _serverContext.SaveChangesAsync(cancellationToken);

            return(createdMcServer);
        }
コード例 #4
0
        public async Task CreateServer(baseMcServer newServerRequest)
        {
            var progressReport = new Progress <ActionProgressUpdate>((progressUpdate) =>
                                                                     Clients.Caller.CreateServer_ProgressUpdate(newServerRequest.ServerName, progressUpdate));

            var mcServer = await _serverActions.CreateNewServer(newServerRequest, progressReport, Context.ConnectionAborted);

            await Clients.Caller.CreateServer_ProgressUpdate(newServerRequest.ServerName, (1, "Server Created"));

            await Clients.All.ServerCreated(mcServer);
        }
コード例 #5
0
        //? GET
        public async Task <McServer> GetMinecraftServerFromDisk(baseMcServer mcServerIdentifier)
        {
            //Already have base properties
            var mcServer = new McServer(mcServerIdentifier);

            mcServer.ServerProperties = await _mcServerPropertyManager.GetServerPropertiesForServerAsync(mcServerIdentifier.WorkingFolder);

            //mcServer.BannedList = await _mcServerPropertyManager.GetBannedListForServerAsync(mcServerIdentifier);
            //mcServer.Usernames = await _mcServerPropertyManager.GetUsernamesForServerAsync(mcServerIdentifier);
            mcServer.IsEulaTrue = await _mcServerPropertyManager.GetEulaValue(mcServerIdentifier.WorkingFolder);

            return(mcServer);
        }
コード例 #6
0
        //? Create
        public async Task <McServer> CreateMcServerOnDisk(baseMcServer baseMcServer, IProgress <ActionProgressUpdate> createProgress = default, CancellationToken cancellationToken = default)
        {
            switch (baseMcServer.ServerType)
            {
            case ServerType.Vanilla:
                return(await CreateVanillaServerOnDisk(baseMcServer, createProgress, cancellationToken));

            case ServerType.Forge:
                return(await CreateForgeServerOnDisk(baseMcServer, createProgress, cancellationToken));

            case ServerType.Spigot:
                return(await CreateSpigotServerOnDisk(baseMcServer, createProgress, cancellationToken));

            case ServerType.Bedrock:
            default:
                throw new NotImplementedException();
            }
        }
コード例 #7
0
        private async Task <McServer> CreateForgeServerOnDisk(baseMcServer baseMcServer, IProgress <ActionProgressUpdate> createProgress = default, CancellationToken cancellationToken = default)
        {
            var jarFile = await _fileDownloader.GetForgeServerFile(baseMcServer.MinecraftVersion, baseMcServer.SecondaryVersionNumber);

            var workingDirectory      = Directory.CreateDirectory(baseMcServer.WorkingFolder); //Ensures folder exists.
            var fullyQualifiedJarFile = $@"{workingDirectory.FullName}\{baseMcServer.JarFile}";

            //Create JarFile
            await File.WriteAllBytesAsync(fullyQualifiedJarFile, jarFile, cancellationToken);

            //Setup EULA and ServerProperties. EULA is false until they change it.
            await _mcServerPropertyManager.WriteEula(baseMcServer.WorkingFolder, false);

            await _mcServerPropertyManager.WriteServerProperties(baseMcServer.WorkingFolder, _mcServerPropertyManager.GetDefaultServerProperties());

            //Get files just written. (in case they changed in the .2 seconds since they were written??? lol.)
            return(await GetMinecraftServerFromDisk(baseMcServer));
        }
コード例 #8
0
        private async Task <McServer> CreateSpigotServerOnDisk(baseMcServer baseMcServer, IProgress <ActionProgressUpdate> createProgress = default, CancellationToken cancellationToken = default)
        {
            var spigotInstallerFile   = _fileDownloader.GetSpigotInstallerFile(baseMcServer.MinecraftVersion, baseMcServer.SecondaryVersionNumber);
            var workingDirectory      = Directory.CreateDirectory(baseMcServer.WorkingFolder); //Ensures folder exists.
            var fullyQualifiedJarFile = $@"{workingDirectory.FullName}\SpigotInstaller.{baseMcServer.SecondaryVersionNumber}.jar";

            //Create JarFile
            await File.WriteAllBytesAsync(fullyQualifiedJarFile, spigotInstallerFile, cancellationToken);

            //Setup EULA and ServerProperties. EULA is false until they change it.
            await _mcServerPropertyManager.WriteEula(baseMcServer.WorkingFolder, false);

            await _mcServerPropertyManager.WriteServerProperties(baseMcServer.WorkingFolder, _mcServerPropertyManager.GetDefaultServerProperties());


            //Extra steps for Spigot.
            // TODO: need to run the installer, which will download git/etc.
            await RunJavaJarFile(fullyQualifiedJarFile, createProgress, cancellationToken);

            //Get files just written. (in case they changed in the .2 seconds since they were written??? lol.)
            return(await GetMinecraftServerFromDisk(baseMcServer));
        }
コード例 #9
0
        //Update
        // //PropertiesOfServer
        //

        private async Task <McServer> CreateVanillaServerOnDisk(baseMcServer baseMcServer, IProgress <ActionProgressUpdate> createProgress = default, CancellationToken cancellationToken = default)
        {
            baseMcServer.JarFile ??= $"server-{baseMcServer.MinecraftVersion}.jar";
            var jarFile = await _fileDownloader.GetVanillaServerFile(baseMcServer.MinecraftVersion);

            var workingDirectory      = Directory.CreateDirectory(baseMcServer.WorkingFolder); //Ensures folder exists.
            var fullyQualifiedJarFile = $@"{workingDirectory.FullName}\{baseMcServer.JarFile}";

            //Create JarFile
            await File.WriteAllBytesAsync(fullyQualifiedJarFile, jarFile, cancellationToken);

            //Setup EULA and ServerProperties. EULA is false until they change it.
            await _mcServerPropertyManager.WriteEula(baseMcServer.WorkingFolder, true, cancellationToken : cancellationToken);

            var defaultServerProperties = _mcServerPropertyManager.GetDefaultServerProperties();

            defaultServerProperties.First(x => x.Key == "server-port").Value = baseMcServer.Port.ToString();

            await _mcServerPropertyManager.WriteServerProperties(baseMcServer.WorkingFolder, defaultServerProperties, cancellationToken : cancellationToken);

            //Get files just written. (in case they changed in the .2 seconds since they were written??? lol.)
            return(await GetMinecraftServerFromDisk(baseMcServer));
        }
コード例 #10
0
 public Task CreateServer(baseMcServer newServerRequest)
 {
     throw new NotImplementedException();
 }