mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2024-11-23 22:58:21 -05:00
feat(realms): docker helper
This commit is contained in:
parent
ab237667a3
commit
8e51111564
@ -6,7 +6,7 @@ using Minecraft_Realms_Emulator.Entities;
|
|||||||
using Minecraft_Realms_Emulator.Requests;
|
using Minecraft_Realms_Emulator.Requests;
|
||||||
using Minecraft_Realms_Emulator.Responses;
|
using Minecraft_Realms_Emulator.Responses;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
@ -5,7 +5,7 @@ using Minecraft_Realms_Emulator.Enums;
|
|||||||
using Minecraft_Realms_Emulator.Helpers;
|
using Minecraft_Realms_Emulator.Helpers;
|
||||||
using Minecraft_Realms_Emulator.Responses;
|
using Minecraft_Realms_Emulator.Responses;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
@ -3,7 +3,7 @@ using Minecraft_Realms_Emulator.Attributes;
|
|||||||
using Minecraft_Realms_Emulator.Data;
|
using Minecraft_Realms_Emulator.Data;
|
||||||
using Minecraft_Realms_Emulator.Responses;
|
using Minecraft_Realms_Emulator.Responses;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
@ -4,7 +4,7 @@ using Minecraft_Realms_Emulator.Attributes;
|
|||||||
using Minecraft_Realms_Emulator.Data;
|
using Minecraft_Realms_Emulator.Data;
|
||||||
using Minecraft_Realms_Emulator.Responses;
|
using Minecraft_Realms_Emulator.Responses;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
@ -4,7 +4,7 @@ using Minecraft_Realms_Emulator.Data;
|
|||||||
using Minecraft_Realms_Emulator.Enums;
|
using Minecraft_Realms_Emulator.Enums;
|
||||||
using Minecraft_Realms_Emulator.Helpers;
|
using Minecraft_Realms_Emulator.Helpers;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
@ -5,6 +5,7 @@ using Minecraft_Realms_Emulator.Data;
|
|||||||
using Minecraft_Realms_Emulator.Entities;
|
using Minecraft_Realms_Emulator.Entities;
|
||||||
using Minecraft_Realms_Emulator.Enums;
|
using Minecraft_Realms_Emulator.Enums;
|
||||||
using Minecraft_Realms_Emulator.Helpers;
|
using Minecraft_Realms_Emulator.Helpers;
|
||||||
|
using Minecraft_Realms_Emulator.Modes.Realms.Helpers;
|
||||||
using Minecraft_Realms_Emulator.Requests;
|
using Minecraft_Realms_Emulator.Requests;
|
||||||
using Minecraft_Realms_Emulator.Responses;
|
using Minecraft_Realms_Emulator.Responses;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -13,7 +14,7 @@ using System.Diagnostics;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Modes.Realms
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
||||||
{
|
{
|
||||||
[Route("modes/realms/[controller]")]
|
[Route("modes/realms/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
@ -275,15 +276,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms
|
|||||||
CommandBlocks = false
|
CommandBlocks = false
|
||||||
};
|
};
|
||||||
|
|
||||||
// Run docker container
|
new DockerHelper().CreateServer(world.Id, port);
|
||||||
ProcessStartInfo serverProcessInfo = new();
|
|
||||||
|
|
||||||
serverProcessInfo.FileName = "docker";
|
|
||||||
serverProcessInfo.Arguments = $"run -d --name realm-server-{world.Id} -p {port}:25565 realm-server";
|
|
||||||
|
|
||||||
Process serverProcess = new();
|
|
||||||
serverProcess.StartInfo = serverProcessInfo;
|
|
||||||
serverProcess.Start();
|
|
||||||
|
|
||||||
_context.Worlds.Update(world);
|
_context.Worlds.Update(world);
|
||||||
|
|
||||||
@ -316,15 +309,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms
|
|||||||
|
|
||||||
if (world == null) return NotFound("World not found");
|
if (world == null) return NotFound("World not found");
|
||||||
|
|
||||||
// Start the server
|
new DockerHelper().StartServer(wId);
|
||||||
ProcessStartInfo serverProcessInfo = new();
|
|
||||||
|
|
||||||
serverProcessInfo.FileName = "docker";
|
|
||||||
serverProcessInfo.Arguments = $"container start realm-server-{world.Id}";
|
|
||||||
|
|
||||||
Process serverProcess = new();
|
|
||||||
serverProcess.StartInfo = serverProcessInfo;
|
|
||||||
serverProcess.Start();
|
|
||||||
|
|
||||||
world.State = nameof(StateEnum.OPEN);
|
world.State = nameof(StateEnum.OPEN);
|
||||||
|
|
||||||
@ -476,15 +461,7 @@ namespace Minecraft_Realms_Emulator.Modes.Realms
|
|||||||
|
|
||||||
if (world == null) return NotFound("World not found");
|
if (world == null) return NotFound("World not found");
|
||||||
|
|
||||||
// Remove docker container
|
new DockerHelper().DeleteServer(wId);
|
||||||
ProcessStartInfo serverProcessInfo = new();
|
|
||||||
|
|
||||||
serverProcessInfo.FileName = "docker";
|
|
||||||
serverProcessInfo.Arguments = $"container rm realm-server-{world.Id}";
|
|
||||||
|
|
||||||
Process serverProcess = new();
|
|
||||||
serverProcess.StartInfo = serverProcessInfo;
|
|
||||||
serverProcess.Start();
|
|
||||||
|
|
||||||
_context.Worlds.Remove(world);
|
_context.Worlds.Remove(world);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
@ -0,0 +1,43 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
|
||||||
|
{
|
||||||
|
public class DockerHelper
|
||||||
|
{
|
||||||
|
public void CreateServer(int id, int port)
|
||||||
|
{
|
||||||
|
ProcessStartInfo serverProcessInfo = new();
|
||||||
|
|
||||||
|
serverProcessInfo.FileName = "docker";
|
||||||
|
serverProcessInfo.Arguments = $"run -d --name realm-server-{id} -p {port}:25565 realm-server";
|
||||||
|
|
||||||
|
Process serverProcess = new();
|
||||||
|
serverProcess.StartInfo = serverProcessInfo;
|
||||||
|
serverProcess.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartServer(int id)
|
||||||
|
{
|
||||||
|
ProcessStartInfo serverProcessInfo = new();
|
||||||
|
|
||||||
|
serverProcessInfo.FileName = "docker";
|
||||||
|
serverProcessInfo.Arguments = $"container start realm-server-{id}";
|
||||||
|
|
||||||
|
Process serverProcess = new();
|
||||||
|
serverProcess.StartInfo = serverProcessInfo;
|
||||||
|
serverProcess.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteServer(int id)
|
||||||
|
{
|
||||||
|
ProcessStartInfo serverProcessInfo = new();
|
||||||
|
|
||||||
|
serverProcessInfo.FileName = "docker";
|
||||||
|
serverProcessInfo.Arguments = $"container rm realm-server-{id}";
|
||||||
|
|
||||||
|
Process serverProcess = new();
|
||||||
|
serverProcess.StartInfo = serverProcessInfo;
|
||||||
|
serverProcess.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user