feat: start server if stopped on join

This commit is contained in:
CyberL1 2024-07-06 10:24:45 +02:00
parent 640cc80758
commit c1353de565

View File

@ -682,13 +682,8 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
while (query == null) while (query == null)
{ {
await Task.Delay(1000);
var newQuery = new MinecraftServerQuery().Query(connection.Address); query = new MinecraftServerQuery().Query(connection.Address);
if (newQuery != null)
{
break;
}
} }
return Ok(true); return Ok(true);
@ -909,9 +904,19 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
} }
[HttpGet("v1/{wId}/join/pc")] [HttpGet("v1/{wId}/join/pc")]
public ActionResult<Connection> Join(int wId) public async Task<ActionResult<Connection>> Join(int wId)
{ {
var connection = _context.Connections.FirstOrDefault(x => x.World.Id == wId); var connection = _context.Connections.Include(c => c.World).FirstOrDefault(x => x.World.Id == wId);
var query = new MinecraftServerQuery().Query(connection.Address);
if (query == null) new DockerHelper(connection.World).StartServer();
while (query == null)
{
await Task.Delay(1000);
query = new MinecraftServerQuery().Query(connection.Address);
}
return Ok(connection); return Ok(connection);
} }