1
1
mirror of https://github.com/CyberL1/MyMcRealms.git synced 2025-07-01 10:29:42 -04:00

Compare commits

..

20 Commits

Author SHA1 Message Date
eb5f50be7b chore: update mod to 1.21.5 2025-05-20 22:30:25 +02:00
15af6a794a fix: display real hardcore property (not the difficulty one) 2024-12-21 13:12:16 +01:00
67d324971e fix: slots on <1.21.1 2024-12-13 22:25:10 +01:00
0e06049d6e fix: display motd on >1.21.1 2024-12-10 00:31:05 +01:00
8f94aa8bdd fix: replace "�" with "§" in realm settings 2024-11-29 12:52:36 +01:00
ef35843140 chore: remove unused code, fix a typo 2024-11-23 14:45:35 +01:00
2245a95d55 chore: fix a typo 2024-10-03 17:10:03 +02:00
617ab4c11a fix: motd cutting on newer version 2024-10-03 17:07:33 +02:00
88974eee33 fix: do not send non-accessible servers to the player 2024-10-02 20:22:02 +02:00
6a7322943a chore: update packages 2024-09-29 18:52:30 +02:00
29f3b9133f chore: remove unused checks 2024-09-22 18:57:09 +02:00
79c97c7415 fix: check if world's motd is longer than the limit first (idk some C# shenanigans) 2024-09-22 08:31:02 +02:00
9976c0bbb5 fix: cut world's motd to its limit 2024-09-21 13:16:01 +02:00
6e27e44746 fix: dashless world owner uuid 2024-09-21 12:48:52 +02:00
7f7444249c feat: also replace & 2024-09-16 12:42:05 +02:00
abcf7b87e2 fix: replace invalid character for use with color codes 2024-09-16 12:23:55 +02:00
368e2c0e1b Owner => Not claimed 2024-09-13 14:58:19 +02:00
10c85cec19 fix for real 2024-09-09 10:53:42 +02:00
44a86e2733 revert the fix as it broke newer versions lol 2024-09-08 21:43:20 +02:00
27f9435a6a fix: typo 2024-09-08 21:13:06 +02:00
13 changed files with 72 additions and 29 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)
{
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);
if (query == null) continue;

View File

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

View File

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

View File

@ -40,26 +40,42 @@ namespace MyMcRealms.Controllers
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);
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 worldOwnerName = world.Ops.ToArray().Length == 0 ? "Not claimed" : world.Ops[0].Name;
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 worldState = !isBanned ? "OPEN" : "CLOSED";
if (!isCompatibleOnOlderVersions)
if (isOlderVersion && !isCompatibleOnOlderVersions)
{
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()
{
Id = AllServers.Servers.IndexOf(world),
Owner = worldOwnerName,
OwnerUUID = worldOwnerUuid,
Name = worldName,
Motd = world.Motd,
Motd = world.Motd.Replace("<22>", "§").Replace("&", "§"),
IsHardcore = world.Hardcore,
State = worldState,
WorldType = "NORMAL",
MaxPlayers = 10,
@ -75,6 +91,10 @@ namespace MyMcRealms.Controllers
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);
}
}
@ -109,9 +129,9 @@ namespace MyMcRealms.Controllers
return BadRequest(errorResponse);
}
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";
string worldOwnerName = world.Ops[0].Name;
string worldOwnerUuid = world.Ops[0].Uuid;
string worldName = $"{world.Ops[0].Name}'s server";
List<PlayerResponse> whitelistedPlayers = [];
foreach (var player in whitelist.Result)
@ -141,7 +161,8 @@ namespace MyMcRealms.Controllers
Owner = worldOwnerName,
OwnerUUID = worldOwnerUuid,
Name = worldName,
Motd = world.Motd,
Motd = world.Motd.Replace("<22>", "§"),
IsHardcore = world.Hardcore,
State = whitelist.Enabled ? "CLOSED" : "OPEN",
WorldType = "NORMAL",
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);
}

View File

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

View File

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

View File

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

View File

@ -3,6 +3,12 @@
public class SlotResponse
{
public int SlotId { get; set; }
public SlotSettingsResponse Settings { 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 int Id { get; set; }
// public Subscription? Subscription { get; set; }
public string? Owner { get; set; }
public string? OwnerUUID { get; set; }
public string? Name { 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 WorldType { get; set; } = "NORMAL";
public List<PlayerResponse> Players { get; set; } = [];