feat: pass world to docker helper class

This commit is contained in:
CyberL1 2024-05-27 09:48:36 +02:00
parent 69fe834c6d
commit 7268cd0da7
2 changed files with 12 additions and 11 deletions

View File

@ -276,7 +276,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
CommandBlocks = false
};
new DockerHelper().CreateServer(world.Id, port);
new DockerHelper(world).CreateServer(port);
_context.Worlds.Update(world);
@ -309,7 +309,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
if (world == null) return NotFound("World not found");
new DockerHelper().StartServer(wId);
new DockerHelper(world).StartServer();
world.State = nameof(StateEnum.OPEN);
@ -461,7 +461,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
if (world == null) return NotFound("World not found");
new DockerHelper().DeleteServer(wId);
new DockerHelper(world).DeleteServer();
_context.Worlds.Remove(world);
_context.SaveChanges();

View File

@ -1,39 +1,40 @@
using System.Diagnostics;
using Minecraft_Realms_Emulator.Entities;
using System.Diagnostics;
namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
{
public class DockerHelper
public class DockerHelper(World world)
{
public void CreateServer(int id, int port)
public void CreateServer(int port)
{
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"run -d --name realm-server-{id} -p {port}:25565 realm-server";
serverProcessInfo.Arguments = $"run -d --name realm-server-{world.Id} -p {port}:25565 realm-server";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;
serverProcess.Start();
}
public void StartServer(int id)
public void StartServer()
{
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"container start realm-server-{id}";
serverProcessInfo.Arguments = $"container start realm-server-{world.Id}";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;
serverProcess.Start();
}
public void DeleteServer(int id)
public void DeleteServer()
{
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"container rm realm-server-{id}";
serverProcessInfo.Arguments = $"container rm realm-server-{world.Id}";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;