mirror of
https://github.com/CyberL1/Minecraft-Realms-Emulator.git
synced 2025-04-02 14:08:36 -04:00
Compare commits
4 Commits
6cb43fcaa3
...
967518dc71
Author | SHA1 | Date | |
---|---|---|---|
967518dc71 | |||
1dc7194888 | |||
84548585ac | |||
f1a5ddd98c |
@ -610,15 +610,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
|
|||||||
return Ok(world);
|
return Ok(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{wId}/reset")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public ActionResult<bool> Reset(int wId)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Resetting world {wId}");
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("{wId}/open")]
|
[HttpPut("{wId}/open")]
|
||||||
[CheckForWorld]
|
[CheckForWorld]
|
||||||
[CheckRealmOwner]
|
[CheckRealmOwner]
|
||||||
@ -690,126 +681,6 @@ namespace Minecraft_Realms_Emulator.Modes.External
|
|||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("{wId}/slot/{sId}")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public async Task<ActionResult<(bool, ErrorResponse)>> UpdateSlot(int wId, int sId, SlotOptionsRequest body)
|
|
||||||
{
|
|
||||||
if (body.SlotName.Length > 10)
|
|
||||||
{
|
|
||||||
ErrorResponse errorResponse = new()
|
|
||||||
{
|
|
||||||
ErrorCode = 400,
|
|
||||||
ErrorMsg = "Slot name cannot exceed 10 characters"
|
|
||||||
};
|
|
||||||
|
|
||||||
return BadRequest(errorResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
var slots = await _context.Slots.Where(s => s.World.Id == wId).ToListAsync();
|
|
||||||
var slot = slots.Find(s => s.SlotId == sId);
|
|
||||||
|
|
||||||
slot.SlotName = body.SlotName;
|
|
||||||
slot.GameMode = body.GameMode;
|
|
||||||
slot.Difficulty = body.Difficulty;
|
|
||||||
slot.SpawnProtection = body.SpawnProtection;
|
|
||||||
slot.ForceGameMode = body.ForceGameMode;
|
|
||||||
slot.Pvp = body.Pvp;
|
|
||||||
slot.SpawnAnimals = body.SpawnAnimals;
|
|
||||||
slot.SpawnMonsters = body.SpawnMonsters;
|
|
||||||
slot.SpawnNPCs = body.SpawnNPCs;
|
|
||||||
slot.CommandBlocks = body.CommandBlocks;
|
|
||||||
|
|
||||||
_context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("{wId}/slot/{sId}")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public ActionResult<bool> SwitchSlot(int wId, int sId)
|
|
||||||
{
|
|
||||||
var world = _context.Worlds.Include(w => w.Minigame).FirstOrDefault(w => w.Id == wId);
|
|
||||||
var slot = _context.Slots.Where(s => s.World.Id == wId).Where(s => s.SlotId == sId).Any();
|
|
||||||
|
|
||||||
if (!slot)
|
|
||||||
{
|
|
||||||
string cookie = Request.Headers.Cookie;
|
|
||||||
string gameVersion = cookie.Split(";")[2].Split("=")[1];
|
|
||||||
|
|
||||||
_context.Slots.Add(new()
|
|
||||||
{
|
|
||||||
World = world,
|
|
||||||
SlotId = sId,
|
|
||||||
SlotName = "",
|
|
||||||
Version = gameVersion,
|
|
||||||
GameMode = 0,
|
|
||||||
Difficulty = 2,
|
|
||||||
SpawnProtection = 0,
|
|
||||||
ForceGameMode = false,
|
|
||||||
Pvp = true,
|
|
||||||
SpawnAnimals = true,
|
|
||||||
SpawnMonsters = true,
|
|
||||||
SpawnNPCs = true,
|
|
||||||
CommandBlocks = false
|
|
||||||
});
|
|
||||||
|
|
||||||
_context.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
world.ActiveSlot = sId;
|
|
||||||
world.Minigame = null;
|
|
||||||
world.WorldType = nameof(WorldTypeEnum.NORMAL);
|
|
||||||
|
|
||||||
_context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{wId}/backups")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public async Task<ActionResult<BackupsResponse>> GetBackups(int wId)
|
|
||||||
{
|
|
||||||
var backups = await _context.Backups.Where(b => b.Slot.World.Id == wId).ToListAsync();
|
|
||||||
|
|
||||||
BackupsResponse worldBackups = new()
|
|
||||||
{
|
|
||||||
Backups = backups
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(worldBackups);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{wId}/slot/{sId}/download")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public ActionResult<BackupDownloadResponse> GetBackup(int wId, int sId)
|
|
||||||
{
|
|
||||||
Backup backup = _context.Backups.Include(b => b.Slot).FirstOrDefault(b => b.Slot.World.Id == wId && b.Slot.Id == sId);
|
|
||||||
|
|
||||||
if (backup == null)
|
|
||||||
{
|
|
||||||
ErrorResponse errorResponse = new()
|
|
||||||
{
|
|
||||||
ErrorCode = 404,
|
|
||||||
ErrorMsg = "No backup found"
|
|
||||||
};
|
|
||||||
|
|
||||||
return NotFound(errorResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
BackupDownloadResponse backupDownloadResponse = new()
|
|
||||||
{
|
|
||||||
DownloadLink = backup.DownloadUrl,
|
|
||||||
ResourcePackUrl = backup.ResourcePackUrl,
|
|
||||||
ResourcePackHash = backup.ResourcePackHash,
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(backupDownloadResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("v1/{wId}/join/pc")]
|
[HttpGet("v1/{wId}/join/pc")]
|
||||||
public ActionResult<Connection> Join(int wId)
|
public ActionResult<Connection> Join(int wId)
|
||||||
{
|
{
|
||||||
@ -847,38 +718,5 @@ namespace Minecraft_Realms_Emulator.Modes.External
|
|||||||
|
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("templates/{type}")]
|
|
||||||
public ActionResult<TemplatesResponse> GetWorldTemplates(string type, int page, int pageSize)
|
|
||||||
{
|
|
||||||
var totalTemplates = _context.Templates.Where(t => t.Type == type).Count();
|
|
||||||
var templates = _context.Templates.Where(t => t.Type == type).Skip((page - 1) * pageSize).Take(pageSize).ToList();
|
|
||||||
|
|
||||||
TemplatesResponse templatesResponse = new()
|
|
||||||
{
|
|
||||||
Page = page,
|
|
||||||
Size = pageSize,
|
|
||||||
Total = totalTemplates,
|
|
||||||
Templates = templates
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(templatesResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPut("minigames/{mId}/{wId}")]
|
|
||||||
[CheckForWorld]
|
|
||||||
[CheckRealmOwner]
|
|
||||||
public ActionResult<bool> SwitchToMinigame(int mId, int wId)
|
|
||||||
{
|
|
||||||
var world = _context.Worlds.Find(wId);
|
|
||||||
var minigame = _context.Templates.FirstOrDefault(t => t.Type == nameof(WorldTemplateTypeEnum.MINIGAME) && t.Id == mId);
|
|
||||||
|
|
||||||
world.Minigame = minigame;
|
|
||||||
world.WorldType = nameof(WorldTypeEnum.MINIGAME);
|
|
||||||
|
|
||||||
_context.SaveChanges();
|
|
||||||
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -687,6 +687,15 @@ namespace Minecraft_Realms_Emulator.Modes.Realms.Controllers
|
|||||||
|
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
var connection = _context.Connections.FirstOrDefault(c => c.World.Id == wId);
|
||||||
|
var query = new MinecraftServerQuery().Query(connection.Address);
|
||||||
|
|
||||||
|
while (query != null)
|
||||||
|
{
|
||||||
|
await Task.Delay(1000);
|
||||||
|
query = new MinecraftServerQuery().Query(connection.Address);
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,7 @@ var db = scope.ServiceProvider.GetRequiredService<DataContext>();
|
|||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
var config = new ConfigHelper(db);
|
var mode = Environment.GetEnvironmentVariable("WORKMODE");
|
||||||
var mode = config.GetSetting(nameof(SettingsEnum.WorkMode));
|
|
||||||
|
|
||||||
if (mode == null)
|
if (mode == null)
|
||||||
{
|
{
|
||||||
@ -59,13 +58,13 @@ if (mode == null)
|
|||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Enum.IsDefined(typeof(WorkModeEnum), mode.Value))
|
if (!Enum.IsDefined(typeof(WorkModeEnum), mode))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Invalid server work mode, exiting");
|
Console.WriteLine("Invalid server work mode, exiting");
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.Value == nameof(WorkModeEnum.REALMS))
|
if (mode == nameof(WorkModeEnum.REALMS))
|
||||||
{
|
{
|
||||||
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
var resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
|
||||||
|
|
||||||
@ -117,7 +116,7 @@ if (mode.Value == nameof(WorkModeEnum.REALMS))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var rewriteOptions = new RewriteOptions().AddRewrite(@"^(?!api)(.*)$", $"modes/{mode.Value}/$1", true);
|
var rewriteOptions = new RewriteOptions().AddRewrite(@"^(?!api)(.*)$", $"modes/{mode}/$1", true);
|
||||||
app.UseRewriter(rewriteOptions);
|
app.UseRewriter(rewriteOptions);
|
||||||
|
|
||||||
app.UseMiddleware<MinecraftCookieMiddleware>();
|
app.UseMiddleware<MinecraftCookieMiddleware>();
|
||||||
@ -127,5 +126,5 @@ app.UseMiddleware<AdminKeyMiddleware>();
|
|||||||
app.UseMiddleware<CheckForWorldMiddleware>();
|
app.UseMiddleware<CheckForWorldMiddleware>();
|
||||||
app.UseMiddleware<RouteLoggingMiddleware>();
|
app.UseMiddleware<RouteLoggingMiddleware>();
|
||||||
|
|
||||||
Console.WriteLine($"Running in {mode.Value} mode");
|
Console.WriteLine($"Running in {mode} mode");
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
NewsLink,
|
NewsLink,
|
||||||
DefaultServerAddress,
|
DefaultServerAddress,
|
||||||
TrialMode,
|
TrialMode,
|
||||||
WorkMode,
|
|
||||||
OnlineMode,
|
OnlineMode,
|
||||||
AutomaticRealmsCreation
|
AutomaticRealmsCreation
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using Minecraft_Realms_Emulator.Shared.Enums;
|
namespace Minecraft_Realms_Emulator.Shared.Helpers.Config
|
||||||
|
|
||||||
namespace Minecraft_Realms_Emulator.Shared.Helpers.Config
|
|
||||||
{
|
{
|
||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
public string DefaultServerAddress { get; set; } = "127.0.0.1";
|
public string DefaultServerAddress { get; set; } = "127.0.0.1";
|
||||||
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
|
public string NewsLink { get; set; } = "https://github.com/CyberL1/Minecraft-Realms-Emulator";
|
||||||
public bool TrialMode { get; set; } = true;
|
public bool TrialMode { get; set; } = true;
|
||||||
public string WorkMode { get; set; } = nameof(WorkModeEnum.EXTERNAL);
|
|
||||||
public bool OnlineMode { get; set; } = false;
|
public bool OnlineMode { get; set; } = false;
|
||||||
public bool AutomaticRealmsCreation { get; set; } = true;
|
public bool AutomaticRealmsCreation { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user