feat(server): attempt to op the realm owner on join

This commit is contained in:
CyberL1 2024-07-06 18:09:07 +02:00
parent 50042e96ad
commit 28e678bce9
2 changed files with 30 additions and 1 deletions

View File

@ -907,9 +907,13 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
{
var connection = _context.Connections.Include(c => c.World).FirstOrDefault(x => x.World.Id == wId);
var isRunning = new DockerHelper(connection.World).IsRunning();
var query = new MinecraftServerQuery().Query(connection.Address);
if (query == null) new DockerHelper(connection.World).StartServer();
if (!isRunning)
{
new DockerHelper(connection.World).StartServer();
}
while (query == null)
{
@ -917,6 +921,14 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
query = new MinecraftServerQuery().Query(connection.Address);
}
string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2];
if (connection.World.OwnerUUID == playerUUID)
{
new DockerHelper(connection.World).ExecuteCommand($"op {connection.World.Owner}");
}
return Ok(connection);
}

View File

@ -17,6 +17,23 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Helpers
serverProcess.Start();
}
public bool IsRunning()
{
ProcessStartInfo containerStateProcessInfo = new();
containerStateProcessInfo.FileName = "docker";
containerStateProcessInfo.Arguments = $"inspect realm-server-{world.Id} -f {{{{.State.Running}}}}";
containerStateProcessInfo.RedirectStandardOutput = true;
Process containerStateProcess = new();
containerStateProcess.StartInfo = containerStateProcessInfo;
containerStateProcess.Start();
containerStateProcess.WaitForExit();
return bool.Parse(containerStateProcess.StandardOutput.ReadToEnd());
}
public void StartServer()
{
ProcessStartInfo serverProcessInfo = new();