1
1
mirror of https://github.com/CyberL1/MyMcRealms.git synced 2025-07-04 02:59:43 -04:00

Compare commits

...

18 Commits

13 changed files with 74 additions and 31 deletions

8
Gamemode.cs Normal file
View File

@ -0,0 +1,8 @@
using System;
public enum Gamemode
{
survival,
creative,
adventure
}

View File

@ -1,9 +0,0 @@
namespace MyMcRealms
{
public enum Compatility
{
COMPATIBLE,
OTHER,
OUTDATED
}
}

View File

@ -24,6 +24,11 @@ namespace MyMcRealms.Controllers
foreach (var world in allServers.Servers) foreach (var world in allServers.Servers)
{ {
if (world.WhitelistEnable && !(world.Whitelist.Any(p => p.Uuid.Replace("-", "") == playerUUID) || world.Ops.Any(p => p.Uuid.Replace("-", "") == playerUUID)))
{
continue;
}
var query = new MinecraftServerQuery().Query(world.Connect); var query = new MinecraftServerQuery().Query(world.Connect);
if (query == null) continue; if (query == null) continue;

View File

@ -45,7 +45,7 @@ namespace MyMcRealms.Controllers
ErrorResponse errorResponse = new() ErrorResponse errorResponse = new()
{ {
ErrorCode = 400, ErrorCode = 400,
ErrorMsg = "Player already whitelisteed" ErrorMsg = "Player already whitelisted"
}; };
return BadRequest(errorResponse); return BadRequest(errorResponse);

View File

@ -18,7 +18,7 @@ namespace MyMcRealms.Controllers
[HttpGet("client/compatible")] [HttpGet("client/compatible")]
public string GetCompatible() public string GetCompatible()
{ {
return Compatility.COMPATIBLE.ToString(); return "COMPATIBLE";
} }
[HttpGet("v1/news")] [HttpGet("v1/news")]
@ -26,7 +26,7 @@ namespace MyMcRealms.Controllers
{ {
var news = new NewsResponse var news = new NewsResponse
{ {
NewsLink = "https://github.com/CyberL1/Minecraft-Realms-Emulator", NewsLink = "https://github.com/CyberL1/MyMcRealms",
}; };
return news; return news;

View File

@ -40,18 +40,33 @@ namespace MyMcRealms.Controllers
bool isOlderVersion = SemVersion.Parse(gameVerision, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse("1.20.3", SemVersionStyles.OptionalPatch)) < 0; bool isOlderVersion = SemVersion.Parse(gameVerision, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse("1.20.3", SemVersionStyles.OptionalPatch)) < 0;
bool isCompatibleOnOlderVersions = isOlderVersion && !isCompatible.StartsWith("NEEDS_"); bool isCompatibleOnOlderVersions = isOlderVersion && isCompatible == "COMPATIBLE";
bool isBanned = world.Banlist.Any(p => p.Name == playerName); bool isBanned = world.Banlist.Any(p => p.Name == playerName);
string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Owner" : world.Ops[0].Name; string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Not claimed" : world.Ops[0].Name;
string worldOwnerUuid = world.Ops.ToArray().Length == 0 ? "069a79f444e94726a5befca90e38aaf5" : world.Ops[0].Uuid; string worldOwnerUuid = world.Ops.ToArray().Length == 0 ? "069a79f444e94726a5befca90e38aaf5" : world.Ops[0].Uuid.Replace("-", "");
string worldName = world.Ops.ToArray().Length == 0 ? world.ServerName : $"{world.Ops[0].Name}'s server"; string worldName = world.Ops.ToArray().Length == 0 ? world.ServerName : $"{world.Ops[0].Name}'s server";
string worldState = !isBanned ? "OPEN" : "CLOSED"; string worldState = !isBanned ? "OPEN" : "CLOSED";
// if (!isCompatibleOnOlderVersions) if (isOlderVersion && !isCompatibleOnOlderVersions)
// { {
// worldState = "CLOSED"; worldState = "CLOSED";
// } }
if (SemVersion.Parse(gameVerision, SemVersionStyles.OptionalPatch).ComparePrecedenceTo(SemVersion.Parse("1.19.4", SemVersionStyles.OptionalPatch)) < 0)
{
if (world.Motd.Length > 32)
{
world.Motd = world.Motd.Remove(32); // Pre 1.19.4 MOTD limit
}
}
else
{
if (world.Motd.Length > 52)
{
world.Motd = world.Motd.Remove(52); // Post 1.19.4 MOTD limit
}
}
WorldResponse response = new() WorldResponse response = new()
{ {
@ -59,7 +74,8 @@ namespace MyMcRealms.Controllers
Owner = worldOwnerName, Owner = worldOwnerName,
OwnerUUID = worldOwnerUuid, OwnerUUID = worldOwnerUuid,
Name = worldName, Name = worldName,
Motd = world.Motd, Motd = world.Motd.Replace("<22>", "§").Replace("&", "§"),
IsHardcore = world.Hardcore,
State = worldState, State = worldState,
WorldType = "NORMAL", WorldType = "NORMAL",
MaxPlayers = 10, MaxPlayers = 10,
@ -75,6 +91,10 @@ namespace MyMcRealms.Controllers
ActiveVersion = world.GameVersion ActiveVersion = world.GameVersion
}; };
if (world.Gamemode == "survival") response.GameMode = 0;
if (world.Gamemode == "creative") response.GameMode = 1;
if (world.Gamemode == "adventure") response.GameMode = 2;
allWorlds.Add(response); allWorlds.Add(response);
} }
} }
@ -109,9 +129,9 @@ namespace MyMcRealms.Controllers
return BadRequest(errorResponse); return BadRequest(errorResponse);
} }
string worldOwnerName = world.Ops.ToArray().Length == 0 ? "Owner" : world.Ops[0].Name; string worldOwnerName = world.Ops[0].Name;
string worldOwnerUuid = world.Ops.ToArray().Length == 0 ? "069a79f444e94726a5befca90e38aaf5" : world.Ops[0].Uuid; string worldOwnerUuid = world.Ops[0].Uuid;
string worldName = world.Ops.ToArray().Length == 0 ? world.ServerName : $"{world.Ops[0].Name}'s server"; string worldName = $"{world.Ops[0].Name}'s server";
List<PlayerResponse> whitelistedPlayers = []; List<PlayerResponse> whitelistedPlayers = [];
foreach (var player in whitelist.Result) foreach (var player in whitelist.Result)
@ -141,7 +161,8 @@ namespace MyMcRealms.Controllers
Owner = worldOwnerName, Owner = worldOwnerName,
OwnerUUID = worldOwnerUuid, OwnerUUID = worldOwnerUuid,
Name = worldName, Name = worldName,
Motd = world.Motd, Motd = world.Motd.Replace("<22>", "§"),
IsHardcore = world.Hardcore,
State = whitelist.Enabled ? "CLOSED" : "OPEN", State = whitelist.Enabled ? "CLOSED" : "OPEN",
WorldType = "NORMAL", WorldType = "NORMAL",
MaxPlayers = 10, MaxPlayers = 10,
@ -170,6 +191,10 @@ namespace MyMcRealms.Controllers
] ]
}; };
if (world.Gamemode == "survival") response.GameMode = 0;
if (world.Gamemode == "creative") response.GameMode = 1;
if (world.Gamemode == "adventure") response.GameMode = 2;
return Ok(response); return Ok(response);
} }

View File

@ -41,7 +41,7 @@ namespace Minecraft_Realms_Emulator.Middlewares
ErrorResponse errorResponse = new() ErrorResponse errorResponse = new()
{ {
ErrorCode = 403, ErrorCode = 403,
ErrorMsg = "This world isn't owner by anyone" ErrorMsg = "This world isn't owned by anyone"
}; };
httpContext.Response.StatusCode = 403; httpContext.Response.StatusCode = 403;

View File

@ -18,6 +18,8 @@
public List<Whitelist> Whitelist { get; set; } = null!; public List<Whitelist> Whitelist { get; set; } = null!;
public bool WhitelistEnable { get; set; } public bool WhitelistEnable { get; set; }
public string OwnersToken { get; set; } = string.Empty; public string OwnersToken { get; set; } = string.Empty;
public string Gamemode { get; set; } = null!;
public bool Hardcore { get; set; }
} }
public class Op public class Op

View File

@ -11,7 +11,7 @@
<PackageReference Include="DotNetEnv" Version="3.1.1" /> <PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Semver" Version="2.3.0" /> <PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -3,6 +3,12 @@
public class SlotResponse public class SlotResponse
{ {
public int SlotId { get; set; } public int SlotId { get; set; }
public SlotSettingsResponse Settings { get; set; } = null!;
public string Options { get; set; } = null!; public string Options { get; set; } = null!;
public SlotResponse()
{
Settings = new SlotSettingsResponse();
}
} }
} }

View File

@ -0,0 +1,7 @@
namespace MyMcRealms.Responses
{
public class SlotSettingsResponse
{
public bool Hardcore = false;
}
}

View File

@ -1,15 +1,14 @@
using System.Text.Json; namespace MyMcRealms.Responses
namespace MyMcRealms.Responses
{ {
public class WorldResponse public class WorldResponse
{ {
public int Id { get; set; } public int Id { get; set; }
// public Subscription? Subscription { get; set; }
public string? Owner { get; set; } public string? Owner { get; set; }
public string? OwnerUUID { get; set; } public string? OwnerUUID { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public string? Motd { get; set; } public string? Motd { get; set; }
public int GameMode { get; set; }
public bool IsHardcore { get; set; }
public string State { get; set; } = "OPEN"; public string State { get; set; } = "OPEN";
public string WorldType { get; set; } = "NORMAL"; public string WorldType { get; set; } = "NORMAL";
public List<PlayerResponse> Players { get; set; } = []; public List<PlayerResponse> Players { get; set; } = [];