Compare commits

...

3 Commits

Author SHA1 Message Date
b6a73df815 feat: change world on slot switch 2024-07-07 14:14:21 +02:00
cbecb21ea3 feat: entrypoint 2024-07-07 12:59:32 +02:00
1a3804e865 feat: make reset world work 2024-07-07 11:01:49 +02:00
5 changed files with 54 additions and 17 deletions

View File

@ -10,6 +10,7 @@
<ItemGroup>
<EmbeddedResource Include="Resources\files\template\Dockerfile" />
<EmbeddedResource Include="Resources\files\template\entrypoint" />
</ItemGroup>
<ItemGroup>

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 slot-{world.ActiveSlot}");
server.RebootServer();
return Ok(true);
}
@ -850,6 +857,11 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
_context.SaveChanges();
}
var server = new DockerHelper(world);
server.RunCommand($"sed -i 's#level-name=slot-{world.ActiveSlot}#level-name=slot-{sId}#' server.properties");
server.RebootServer();
world.ActiveSlot = sId;
world.Minigame = null;
world.WorldType = nameof(WorldTypeEnum.NORMAL);

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} /bin/sh -c \"{command}\"";
Process commandProcess = new();
commandProcess.StartInfo = commandProcessInfo;
commandProcess.Start();
}
}
}

View File

@ -1,11 +1,7 @@
FROM eclipse-temurin:21-jre-alpine
WORKDIR /server
COPY . .
RUN mkdir mc
WORKDIR mc
RUN apk upgrade
RUN apk add openssl
@ -15,19 +11,8 @@ 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
RUN java -jar server.jar
RUN echo "$(openssl rand -hex 20)" > .rcon-pwd
RUN echo eula=true > eula.txt
RUN echo "enable-rcon=true" >> server.properties
RUN echo "rcon.password=$(cat .rcon-pwd)" >> server.properties
RUN echo "password: $(cat .rcon-pwd)" >> /root/.rcon-cli.yaml
RUN rm .rcon-pwd
CMD ["java", "-jar", "server.jar"]
ENTRYPOINT ["/entrypoint"]

View File

@ -0,0 +1,14 @@
#!/bin/sh
RCON_PASSWORD="$(openssl rand -hex 20)"
echo "password: $RCON_PASSWORD" >> /root/.rcon-cli.yaml
[ ! -f eula.txt ] && echo "eula=true" > eula.txt
if [ ! -f server.properties ]; then
echo "enable-rcon=true" >> server.properties
echo "rcon.password=$RCON_PASSWORD" >> server.properties
echo "level-name=slot-1" >> server.properties
fi
java -jar server.jar