feat: make reset world work

This commit is contained in:
CyberL1 2024-07-07 11:01:49 +02:00
parent 28e678bce9
commit 1a3804e865
3 changed files with 34 additions and 5 deletions

View File

@ -657,6 +657,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
public ActionResult<bool> Reset(int wId)
{
Console.WriteLine($"Resetting world {wId}");
var world = _context.Worlds.Find(wId);
var server = new DockerHelper(world);
server.RunCommand("rm -rf world");
server.RebootServer();
return Ok(true);
}

View File

@ -58,6 +58,18 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
serverProcess.Start();
}
public void RebootServer()
{
ProcessStartInfo serverProcessInfo = new();
serverProcessInfo.FileName = "docker";
serverProcessInfo.Arguments = $"container restart realm-server-{world.Id}";
Process serverProcess = new();
serverProcess.StartInfo = serverProcessInfo;
serverProcess.Start();
}
public void DeleteServer()
{
ProcessStartInfo serverProcessInfo = new();
@ -110,5 +122,18 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
commandProcess.Start();
}
public void RunCommand(string command)
{
ProcessStartInfo commandProcessInfo = new();
commandProcessInfo.FileName = "docker";
commandProcessInfo.Arguments = $"exec realm-server-{world.Id} {command}";
Process commandProcess = new();
commandProcess.StartInfo = commandProcessInfo;
commandProcess.Start();
}
}
}

View File

@ -1,13 +1,9 @@
FROM eclipse-temurin:21-jre-alpine
WORKDIR /server
COPY . .
RUN mkdir mc
WORKDIR mc
RUN apk upgrade
RUN apk add openssl
RUN apk add openssl at
RUN wget -O rcon-cli.tar.gz https://github.com/itzg/rcon-cli/releases/download/1.6.7/rcon-cli_1.6.7_linux_amd64.tar.gz
RUN tar xzf rcon-cli.tar.gz
@ -15,6 +11,7 @@ RUN tar xzf rcon-cli.tar.gz
RUN rm rcon-cli.tar.gz
RUN mv rcon-cli /bin/rcon-cli
WORKDIR mc
RUN wget -O server.jar https://piston-data.mojang.com/v1/objects/450698d1863ab5180c25d7c804ef0fe6369dd1ba/server.jar
EXPOSE 25565