mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2025-04-02 14:08:36 -04:00
Compare commits
6 Commits
51251ee5a1
...
cc5adcffa3
Author | SHA1 | Date | |
---|---|---|---|
cc5adcffa3 | |||
1313f608ba | |||
10f547723c | |||
82e3abd103 | |||
0669c741b9 | |||
bf2d2ff641 |
@ -65,6 +65,9 @@ namespace Minecraft_Realms_Emulator.Controllers.Admin
|
||||
|
||||
if (world == null) return BadRequest("World not found");
|
||||
|
||||
world.State = "OPEN";
|
||||
_context.SaveChanges();
|
||||
|
||||
new DockerHelper(world).StartServer();
|
||||
|
||||
return Ok(true);
|
||||
@ -77,6 +80,9 @@ namespace Minecraft_Realms_Emulator.Controllers.Admin
|
||||
|
||||
if (world == null) return BadRequest("World not found");
|
||||
|
||||
world.State = "CLOSED";
|
||||
_context.SaveChanges();
|
||||
|
||||
new DockerHelper(world).StopServer();
|
||||
|
||||
return Ok(true);
|
||||
|
@ -17,14 +17,20 @@ else
|
||||
@server.State
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button class="btn btn-success" @onclick="StartServer">
|
||||
<i class="bi-caret-right-fill"></i>
|
||||
Start
|
||||
</button>
|
||||
<button class="btn btn-danger" @onclick="StopServer">
|
||||
<i class="bi-stop-circle-fill"></i>
|
||||
Stop
|
||||
</button>
|
||||
@if (server.State == "CLOSED")
|
||||
{
|
||||
<button class="btn btn-success" @onclick="StartServer">
|
||||
<i class="bi-caret-right-fill"></i>
|
||||
Start
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-danger" @onclick="StopServer">
|
||||
<i class="bi-stop-circle-fill"></i>
|
||||
Stop
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -47,6 +53,11 @@ else
|
||||
private List<string> logs = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await GetServer();
|
||||
}
|
||||
|
||||
public async Task GetServer()
|
||||
{
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
|
||||
@ -75,7 +86,9 @@ else
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
|
||||
|
||||
await JS.InvokeVoidAsync("serverLogsStream.start", DotNetObjectReference.Create(this), wId);
|
||||
await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/open", new StringContent(""));
|
||||
await GetServer();
|
||||
}
|
||||
|
||||
public async Task StopServer()
|
||||
@ -83,6 +96,8 @@ else
|
||||
HttpClient httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(Environment.GetEnvironmentVariable("ADMIN_KEY"));
|
||||
|
||||
await JS.InvokeVoidAsync("serverLogsStream.stop");
|
||||
await httpClient.PutAsync($"http://localhost:8080/api/admin/servers/{wId}/close", new StringContent(""));
|
||||
await GetServer();
|
||||
}
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
window.serverLogsStream = {
|
||||
logs: "x",
|
||||
|
||||
start: (dotNetObject, serverId) => {
|
||||
const logs = new EventSource(`http://localhost:8080/api/admin/servers/${serverId}/logs`, { withCredentials: true });
|
||||
logs = new EventSource(`http://localhost:8080/api/admin/servers/${serverId}/logs`, { withCredentials: true });
|
||||
|
||||
logs.onmessage = event => {
|
||||
dotNetObject.invokeMethodAsync("ReceiveLog", event.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
stop: () => logs.close()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user