mirror of
https://github.com/CyberL1/MyMcRealms.git
synced 2024-11-21 13:38:21 -05:00
feat: show whitelisted players in invites menu
This commit is contained in:
parent
fbc1e64d18
commit
9115402ff1
67
MyMcRealms/Controllers/OpsController.cs
Normal file
67
MyMcRealms/Controllers/OpsController.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
using MyMcRealms.Attributes;
|
||||
using MyMcRealms.MyMcAPI;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class OpsController : ControllerBase
|
||||
{
|
||||
[HttpPost("{wId}/{uuid}")]
|
||||
public async Task<ActionResult<OpsResponse>> OpPlayer(int wId, string uuid)
|
||||
{
|
||||
var api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY"));
|
||||
var world = (await api.GetAllServers()).Servers[wId];
|
||||
|
||||
var ops = world.Ops;
|
||||
var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid);
|
||||
|
||||
List<string> opNames = [];
|
||||
|
||||
foreach (var op in ops)
|
||||
{
|
||||
opNames.Add(op.Name);
|
||||
}
|
||||
|
||||
api.ExecuteCommand($"op {player.Name}");
|
||||
opNames.Add(player.Name);
|
||||
|
||||
var opsResponse = new OpsResponse
|
||||
{
|
||||
Ops = opNames
|
||||
};
|
||||
|
||||
return Ok(opsResponse);
|
||||
}
|
||||
|
||||
[HttpDelete("{wId}/{uuid}")]
|
||||
public async Task<ActionResult<OpsResponse>> DeopPlayerAsync(int wId, string uuid)
|
||||
{
|
||||
var api = new MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY"));
|
||||
var world = (await api.GetAllServers()).Servers[wId];
|
||||
|
||||
var ops = world.Ops;
|
||||
var player = world.Whitelist.Find(p => p.Uuid.Replace("-", "") == uuid);
|
||||
|
||||
List<string> opNames = [];
|
||||
|
||||
foreach (var op in ops)
|
||||
{
|
||||
opNames.Add(op.Name);
|
||||
}
|
||||
|
||||
api.ExecuteCommand($"deop {player.Name}");
|
||||
opNames.Remove(player.Name);
|
||||
|
||||
var opsResponse = new OpsResponse
|
||||
{
|
||||
Ops = opNames
|
||||
};
|
||||
|
||||
return Ok(opsResponse);
|
||||
}
|
||||
}
|
||||
}
|
@ -74,32 +74,79 @@ namespace MyMcRealms.Controllers
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<WorldResponse>> GetWorldById(int id)
|
||||
{
|
||||
return NotFound("World not found");
|
||||
var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers();
|
||||
var world = worlds.Servers[id];
|
||||
|
||||
string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Owner" : world.Ops[0].Name;
|
||||
string worldOwnerUuid = world.Ops.ToArray().Length == 0 ? "069a79f444e94726a5befca90e38aaf5" : world.Ops[0].Uuid;
|
||||
string worldName = world.Ops.ToArray().Length == 0 ? world.ServerName : $"{world.Ops[0].Name}'s server";
|
||||
List<Player> whitelistedPlayers = [];
|
||||
|
||||
foreach (var player in world.Whitelist)
|
||||
{
|
||||
Player whitelistedPlayer = new()
|
||||
{
|
||||
Name = player.Name,
|
||||
Uuid = player.Uuid,
|
||||
Accepted = true,
|
||||
Online = false,
|
||||
Operator = world.Ops.Find(p => p.Name == player.Name) != null,
|
||||
Permission = world.Ops.Find(p => p.Name == player.Name) != null ? "OPERATOR" : "MEMBER",
|
||||
};
|
||||
|
||||
whitelistedPlayers.Add(whitelistedPlayer);
|
||||
}
|
||||
|
||||
// [HttpPut("{id}/open")]
|
||||
// public async Task<ActionResult<bool>> Open(int id)
|
||||
// {
|
||||
// var world = worlds.Find(w => w.Id == id);
|
||||
WorldResponse response = new()
|
||||
{
|
||||
Id = id,
|
||||
Owner = worldOwnerName,
|
||||
OwnerUUID = worldOwnerUuid,
|
||||
Name = worldName,
|
||||
Motd = world.Motd,
|
||||
State = "OPEN",
|
||||
WorldType = "NORMAL",
|
||||
MaxPlayers = 10,
|
||||
MinigameId = null,
|
||||
MinigameName = null,
|
||||
MinigameImage = null,
|
||||
ActiveSlot = 1,
|
||||
Member = false,
|
||||
Players = whitelistedPlayers,
|
||||
DaysLeft = 7,
|
||||
Expired = false,
|
||||
ExpiredTrial = false,
|
||||
ActiveVersion = world.GameVersion
|
||||
};
|
||||
|
||||
// if (world == null) return NotFound("World not found");
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/open")]
|
||||
public async Task<ActionResult<bool>> Open(int id)
|
||||
{
|
||||
var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers();
|
||||
var world = worlds.Servers[id];
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
// Turn off whitelist
|
||||
|
||||
// return Ok(true);
|
||||
// }
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// [HttpPut("{id}/close")]
|
||||
// public async Task<ActionResult<bool>> Close(int id)
|
||||
// {
|
||||
// var world = worlds.FirstOrDefault(w => w.Id == id);
|
||||
[HttpPut("{id}/close")]
|
||||
public async Task<ActionResult<bool>> Close(int id)
|
||||
{
|
||||
var worlds = await new MyMcAPI.MyMcAPI(Environment.GetEnvironmentVariable("MYMC_API_KEY")).GetAllServers();
|
||||
var world = worlds.Servers[id];
|
||||
|
||||
// if (world == null) return NotFound("World not found");
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
// Turn on whitelist
|
||||
|
||||
// return Ok(true);
|
||||
// }
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpGet("v1/{wId}/join/pc")]
|
||||
public async Task<ActionResult<ConnectionResponse>> Join(int wId)
|
||||
|
@ -15,6 +15,7 @@
|
||||
public bool Online { get; set; }
|
||||
public List<Op> Ops { get; set; } = null!;
|
||||
public List<Ban> Banlist { get; set; } = null!;
|
||||
public List<Whitelist> Whitelist { get; set; } = null!;
|
||||
public string OwnersToken { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
|
9
MyMcRealms/MyMcAPI/Responses/ConsoleResponse.cs
Normal file
9
MyMcRealms/MyMcAPI/Responses/ConsoleResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
namespace MyMcRealms.MyMcAPI.Responses
|
||||
{
|
||||
public class ConsoleResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = null!;
|
||||
}
|
||||
}
|
@ -25,5 +25,21 @@ namespace MyMcRealms.MyMcAPI
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public HttpResponseMessage? ExecuteCommand(string command)
|
||||
{
|
||||
string json = $"{{ \"command\": \"{command}\" }}";
|
||||
|
||||
StringContent content = new(json, System.Text.Encoding.UTF8, "application/json");
|
||||
var response = httpClient.PostAsync("console", content).Result;
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
Console.WriteLine("error while doing POST /console");
|
||||
return null;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
MyMcRealms/Responses/OpsResponse.cs
Normal file
7
MyMcRealms/Responses/OpsResponse.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Minecraft_Realms_Emulator.Responses
|
||||
{
|
||||
public class OpsResponse
|
||||
{
|
||||
public List<string> Ops { get; set; } = null!;
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace MyMcRealms.Entities
|
||||
public string? Motd { get; set; }
|
||||
public string State { get; set; } = "OPEN";
|
||||
public string WorldType { get; set; } = "NORMAL";
|
||||
// public List<Player> Players { get; set; } = [];
|
||||
public List<Player> Players { get; set; } = [];
|
||||
public int MaxPlayers { get; set; } = 10;
|
||||
public string? MinigameName { get; set; }
|
||||
public int? MinigameId { get; set; }
|
||||
@ -27,4 +27,14 @@ namespace MyMcRealms.Entities
|
||||
public string Compatibility { get; set; } = string.Empty;
|
||||
public string ActiveVersion { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class Player
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Uuid { get; set; } = string.Empty;
|
||||
public bool Operator { get; set; }
|
||||
public bool Accepted { get; set; }
|
||||
public bool Online { get; set; }
|
||||
public string Permission { get; set; } = "MEMBER";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user