mirror of
https://github.com/CyberL1/MyMcRealms.git
synced 2025-06-28 17:39:42 -04:00
Import from Github
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
public class ConfigurationController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public ConfigurationController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult<Configuration> GetConfigurationAsync()
|
||||
{
|
||||
var configuration = _context.Configuration;
|
||||
return Ok(configuration);
|
||||
}
|
||||
}
|
||||
}
|
178
Minecraft-Realms-Emulator/Controllers/InvitesController.cs
Normal file
178
Minecraft-Realms-Emulator/Controllers/InvitesController.cs
Normal file
@ -0,0 +1,178 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
using Minecraft_Realms_Emulator.Requests;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class InvitesController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public InvitesController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet("pending")]
|
||||
public async Task<ActionResult<InviteList>> GetInvites()
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
string playerUUID = cookie.Split(";")[0].Split(":")[2];
|
||||
|
||||
var invites = await _context.Invites.Where(i => i.RecipeintUUID == playerUUID).Include(i => i.World).ToListAsync();
|
||||
|
||||
List<InviteResponse> invitesList = [];
|
||||
|
||||
foreach (var invite in invites)
|
||||
{
|
||||
InviteResponse inv = new()
|
||||
{
|
||||
InvitationId = invite.InvitationId,
|
||||
WorldName = invite.World.Name,
|
||||
WorldOwnerName = invite.World.Owner,
|
||||
WorldOwnerUuid = invite.World.OwnerUUID,
|
||||
Date = ((DateTimeOffset) invite.Date).ToUnixTimeMilliseconds(),
|
||||
};
|
||||
|
||||
invitesList.Add(inv);
|
||||
}
|
||||
|
||||
InviteList inviteListRespone = new()
|
||||
{
|
||||
Invites = invitesList
|
||||
};
|
||||
|
||||
return Ok(inviteListRespone);
|
||||
}
|
||||
[HttpPut("accept/{id}")]
|
||||
public ActionResult<bool> AcceptInvite(string id)
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
string playerUUID = cookie.Split(";")[0].Split(":")[2];
|
||||
|
||||
var invite = _context.Invites.Include(i => i.World).FirstOrDefault(i => i.InvitationId == id);
|
||||
|
||||
if (invite == null) return NotFound("Invite not found");
|
||||
|
||||
var player = _context.Players.Where(p => p.World.Id == invite.World.Id).FirstOrDefault(p => p.Uuid == playerUUID);
|
||||
|
||||
player.Accepted = true;
|
||||
|
||||
_context.Invites.Remove(invite);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPut("reject/{id}")]
|
||||
public ActionResult<bool> RejectInvite(string id)
|
||||
{
|
||||
var invite = _context.Invites.Include(i => i.World).FirstOrDefault(i => i.InvitationId == id);
|
||||
|
||||
if (invite == null) return NotFound("Invite not found");
|
||||
|
||||
_context.Invites.Remove(invite);
|
||||
|
||||
string cookie = Request.Headers.Cookie;
|
||||
string playerUUID = cookie.Split(";")[0].Split(":")[2];
|
||||
|
||||
var player = _context.Players.Where(p => p.World.Id == invite.World.Id).FirstOrDefault(p => p.Uuid == playerUUID);
|
||||
|
||||
_context.Players.Remove(player);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPost("{wId}")]
|
||||
public async Task<ActionResult<World>> InvitePlayer(int wId, PlayerRequest body)
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
string playerName = cookie.Split(";")[1].Split("=")[1];
|
||||
|
||||
if (body.Name == playerName) return Forbid("You cannot invite yourself");
|
||||
|
||||
var world = await _context.Worlds.Include(w => w.Players).FirstOrDefaultAsync(w => w.Id == wId);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
// Get player UUID
|
||||
var playerInfo = await new HttpClient().GetFromJsonAsync<MinecraftPlayerInfo>($"https://api.mojang.com/users/profiles/minecraft/{body.Name}");
|
||||
|
||||
var playerInDB = await _context.Players.Where(p => p.World.Id == wId).FirstOrDefaultAsync(p => p.Uuid == playerInfo.Id);
|
||||
|
||||
if (playerInDB?.Uuid == playerInfo.Id) return BadRequest("Player already invited");
|
||||
|
||||
Player player = new()
|
||||
{
|
||||
Name = body.Name,
|
||||
Uuid = playerInfo.Id,
|
||||
World = world
|
||||
};
|
||||
|
||||
_context.Players.Add(player);
|
||||
|
||||
Invite invite = new()
|
||||
{
|
||||
InvitationId = Guid.NewGuid().ToString(),
|
||||
World = world,
|
||||
RecipeintUUID = playerInfo.Id,
|
||||
Date = DateTime.UtcNow,
|
||||
};
|
||||
|
||||
_context.Invites.Add(invite);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(world);
|
||||
}
|
||||
|
||||
[HttpDelete("{wId}/invite/{uuid}")]
|
||||
public async Task<ActionResult<bool>> DeleteInvite(int wId, string uuid)
|
||||
{
|
||||
var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid);
|
||||
|
||||
_context.Players.Remove(player);
|
||||
|
||||
var invite = await _context.Invites.FirstOrDefaultAsync(i => i.RecipeintUUID == uuid);
|
||||
|
||||
if (invite != null) _context.Invites.Remove(invite);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpDelete("{wId}")]
|
||||
public async Task<ActionResult<bool>> LeaveWorld(int wId)
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
string playerUUID = cookie.Split(";")[0].Split(":")[2];
|
||||
|
||||
var world = await _context.Worlds.FirstOrDefaultAsync(w => w.Id == wId);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == playerUUID);
|
||||
|
||||
_context.Players.Remove(player);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
}
|
46
Minecraft-Realms-Emulator/Controllers/McoController.cs
Normal file
46
Minecraft-Realms-Emulator/Controllers/McoController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class McoController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public McoController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet("available")]
|
||||
public bool GetAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
[HttpGet("client/compatible")]
|
||||
public string GetCompatible()
|
||||
{
|
||||
return Compatility.COMPATIBLE.ToString();
|
||||
}
|
||||
|
||||
[HttpGet("v1/news")]
|
||||
public NewsResponse GetNews()
|
||||
{
|
||||
var newsLink = _context.Configuration.FirstOrDefault(s => s.Key == "newsLink");
|
||||
|
||||
var news = new NewsResponse
|
||||
{
|
||||
NewsLink = JsonConvert.DeserializeObject(newsLink.Value),
|
||||
};
|
||||
|
||||
return news;
|
||||
}
|
||||
}
|
||||
}
|
76
Minecraft-Realms-Emulator/Controllers/OpsController.cs
Normal file
76
Minecraft-Realms-Emulator/Controllers/OpsController.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class OpsController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public OpsController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpPost("{wId}/{uuid}")]
|
||||
public ActionResult<OpsResponse> OpPlayer(int wId, string uuid)
|
||||
{
|
||||
var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList();
|
||||
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid);
|
||||
|
||||
List<string> opNames = [];
|
||||
|
||||
foreach (var op in ops)
|
||||
{
|
||||
opNames.Add(op.Name);
|
||||
}
|
||||
|
||||
player.Permission = "OPERATOR";
|
||||
player.Operator = true;
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
opNames.Add(player.Name);
|
||||
|
||||
var opsResponse = new OpsResponse
|
||||
{
|
||||
Ops = opNames
|
||||
};
|
||||
|
||||
return Ok(opsResponse);
|
||||
}
|
||||
|
||||
[HttpDelete("{wId}/{uuid}")]
|
||||
public ActionResult<OpsResponse> DeopPlayer(int wId, string uuid)
|
||||
{
|
||||
var ops = _context.Players.Where(p => p.World.Id == wId && p.Operator == true).ToList();
|
||||
var player = _context.Players.Where(p => p.World.Id == wId).FirstOrDefault(p => p.Uuid == uuid);
|
||||
|
||||
List<string> opNames = [];
|
||||
|
||||
foreach (var op in ops)
|
||||
{
|
||||
opNames.Add(op.Name);
|
||||
}
|
||||
|
||||
player.Permission = "MEMBER";
|
||||
player.Operator = false;
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
opNames.Remove(player.Name);
|
||||
|
||||
var opsResponse = new OpsResponse
|
||||
{
|
||||
Ops = opNames
|
||||
};
|
||||
|
||||
return Ok(opsResponse);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class SubscriptionsController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public SubscriptionsController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<SubscriptionResponse>> Get(int id)
|
||||
{
|
||||
var world = await _context.Worlds.Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id);
|
||||
|
||||
if (world?.Subscription == null) return NotFound("Subscription not found");
|
||||
|
||||
var sub = new SubscriptionResponse
|
||||
{
|
||||
StartDate = ((DateTimeOffset)world.Subscription.StartDate).ToUnixTimeMilliseconds(),
|
||||
DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days,
|
||||
SubscriptionType = world.Subscription.SubscriptionType
|
||||
};
|
||||
|
||||
return Ok(sub);
|
||||
}
|
||||
}
|
||||
}
|
24
Minecraft-Realms-Emulator/Controllers/TrialController.cs
Normal file
24
Minecraft-Realms-Emulator/Controllers/TrialController.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class TrialController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public TrialController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetTrial")]
|
||||
public bool Get() {
|
||||
return bool.Parse(_context.Configuration.FirstOrDefault(x => x.Key == "trialMode").Value);
|
||||
}
|
||||
}
|
||||
}
|
279
Minecraft-Realms-Emulator/Controllers/WorldsController.cs
Normal file
279
Minecraft-Realms-Emulator/Controllers/WorldsController.cs
Normal file
@ -0,0 +1,279 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minecraft_Realms_Emulator.Attributes;
|
||||
using Minecraft_Realms_Emulator.Data;
|
||||
using Minecraft_Realms_Emulator.Entities;
|
||||
using Minecraft_Realms_Emulator.Requests;
|
||||
using Minecraft_Realms_Emulator.Responses;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Minecraft_Realms_Emulator.Controllers
|
||||
{
|
||||
[Route("[controller]")]
|
||||
[ApiController]
|
||||
[RequireMinecraftCookie]
|
||||
public class WorldsController : ControllerBase
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public WorldsController(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<ServersResponse>> GetWorlds()
|
||||
{
|
||||
string cookie = Request.Headers.Cookie;
|
||||
|
||||
string playerUUID = cookie.Split(";")[0].Split(":")[2];
|
||||
string playerName = cookie.Split(";")[1].Split("=")[1];
|
||||
|
||||
var ownedWorlds = await _context.Worlds.Where(w => w.OwnerUUID == playerUUID).Include(w => w.Subscription).ToListAsync();
|
||||
var memberWorlds = await _context.Players.Where(p => p.Uuid == playerUUID && p.Accepted).Include(p => p.World.Subscription).Select(p => p.World).ToListAsync();
|
||||
|
||||
List<WorldResponse> allWorlds = [];
|
||||
|
||||
if (ownedWorlds.ToArray().Length == 0)
|
||||
{
|
||||
var world = new World
|
||||
{
|
||||
Owner = playerName,
|
||||
OwnerUUID = playerUUID,
|
||||
Name = null,
|
||||
Motd = null,
|
||||
State = "UNINITIALIZED",
|
||||
WorldType = "NORMAL",
|
||||
MaxPlayers = 10,
|
||||
MinigameId = null,
|
||||
MinigameName = null,
|
||||
MinigameImage = null,
|
||||
ActiveSlot = 1,
|
||||
Member = false
|
||||
};
|
||||
|
||||
ownedWorlds.Add(world);
|
||||
_context.Worlds.Add(world);
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
foreach (var world in ownedWorlds)
|
||||
{
|
||||
WorldResponse response = new()
|
||||
{
|
||||
Id = world.Id,
|
||||
Owner = world.Owner,
|
||||
OwnerUUID = world.OwnerUUID,
|
||||
Name = world.Name,
|
||||
Motd = world.Motd,
|
||||
State = world.State,
|
||||
WorldType = world.WorldType,
|
||||
MaxPlayers = world.MaxPlayers,
|
||||
MinigameId = world.MinigameId,
|
||||
MinigameName = world.MinigameName,
|
||||
MinigameImage = world.MinigameImage,
|
||||
ActiveSlot = world.ActiveSlot,
|
||||
Member = world.Member,
|
||||
Players = world.Players
|
||||
};
|
||||
|
||||
if (world.Subscription != null)
|
||||
{
|
||||
response.DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days;
|
||||
response.Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0;
|
||||
response.ExpiredTrial = false;
|
||||
}
|
||||
|
||||
allWorlds.Add(response);
|
||||
}
|
||||
|
||||
foreach (var world in memberWorlds)
|
||||
{
|
||||
WorldResponse response = new()
|
||||
{
|
||||
Id = world.Id,
|
||||
Owner = world.Owner,
|
||||
OwnerUUID = world.OwnerUUID,
|
||||
Name = world.Name,
|
||||
Motd = world.Motd,
|
||||
State = world.State,
|
||||
WorldType = world.WorldType,
|
||||
MaxPlayers = world.MaxPlayers,
|
||||
MinigameId = world.MinigameId,
|
||||
MinigameName = world.MinigameName,
|
||||
MinigameImage = world.MinigameImage,
|
||||
ActiveSlot = world.ActiveSlot,
|
||||
Member = world.Member,
|
||||
Players = world.Players,
|
||||
DaysLeft = 0,
|
||||
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
|
||||
ExpiredTrial = false
|
||||
};
|
||||
|
||||
allWorlds.Add(response);
|
||||
}
|
||||
|
||||
ServersResponse servers = new()
|
||||
{
|
||||
Servers = allWorlds
|
||||
};
|
||||
|
||||
return Ok(servers);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<WorldResponse>> GetWorldById(int id)
|
||||
{
|
||||
var world = await _context.Worlds.Include(w => w.Players).Include(w => w.Subscription).FirstOrDefaultAsync(w => w.Id == id);
|
||||
|
||||
if (world?.Subscription == null) return NotFound("World not found");
|
||||
|
||||
WorldResponse response = new()
|
||||
{
|
||||
Id = world.Id,
|
||||
Owner = world.Owner,
|
||||
OwnerUUID = world.OwnerUUID,
|
||||
Name = world.Name,
|
||||
Motd = world.Motd,
|
||||
State = world.State,
|
||||
WorldType = world.WorldType,
|
||||
MaxPlayers = world.MaxPlayers,
|
||||
MinigameId = world.MinigameId,
|
||||
MinigameName = world.MinigameName,
|
||||
MinigameImage = world.MinigameImage,
|
||||
ActiveSlot = world.ActiveSlot,
|
||||
Member = world.Member,
|
||||
Players = world.Players,
|
||||
DaysLeft = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days,
|
||||
Expired = ((DateTimeOffset)world.Subscription.StartDate.AddDays(30) - DateTime.Today).Days < 0,
|
||||
ExpiredTrial = false
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
[HttpPost("{id}/initialize")]
|
||||
public async Task<ActionResult<World>> Initialize(int id, WorldCreateRequest body)
|
||||
{
|
||||
var worlds = await _context.Worlds.ToListAsync();
|
||||
|
||||
var world = worlds.Find(w => w.Id == id);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
if (world.State != "UNINITIALIZED") return NotFound("World already initialized");
|
||||
|
||||
var subscription = new Subscription
|
||||
{
|
||||
StartDate = DateTime.UtcNow,
|
||||
SubscriptionType = "NORMAL"
|
||||
};
|
||||
|
||||
world.Name = body.Name;
|
||||
world.Motd = body.Description;
|
||||
world.State = "OPEN";
|
||||
world.Subscription = subscription;
|
||||
|
||||
var defaultServerAddress = _context.Configuration.FirstOrDefault(x => x.Key == "defaultServerAddress");
|
||||
|
||||
var connection = new Connection
|
||||
{
|
||||
World = world,
|
||||
Address = JsonConvert.DeserializeObject(defaultServerAddress.Value)
|
||||
};
|
||||
|
||||
_context.Worlds.Update(world);
|
||||
|
||||
_context.Subscriptions.Add(subscription);
|
||||
_context.Connections.Add(connection);
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(world);
|
||||
}
|
||||
|
||||
[HttpPost("{id}/reset")]
|
||||
public ActionResult<bool> Reset(int id)
|
||||
{
|
||||
Console.WriteLine($"Resetting world {id}");
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/open")]
|
||||
public async Task<ActionResult<bool>> Open(int id)
|
||||
{
|
||||
var worlds = await _context.Worlds.ToListAsync();
|
||||
|
||||
var world = worlds.Find(w => w.Id == id);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
world.State = "OPEN";
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/close")]
|
||||
public async Task<ActionResult<bool>> Close(int id)
|
||||
{
|
||||
var worlds = await _context.Worlds.ToListAsync();
|
||||
|
||||
var world = worlds.FirstOrDefault(w => w.Id == id);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
world.State = "CLOSED";
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPost("{id}")]
|
||||
public async Task<ActionResult<bool>> UpdateWorld(int id, WorldCreateRequest body)
|
||||
{
|
||||
var worlds = await _context.Worlds.ToListAsync();
|
||||
|
||||
var world = worlds.Find(w => w.Id == id);
|
||||
|
||||
if (world == null) return NotFound("World not found");
|
||||
|
||||
world.Name = body.Name;
|
||||
world.Motd = body.Description;
|
||||
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
[HttpPost("{wId}/slot/{sId}")]
|
||||
public bool U(int wId, int sId, object o)
|
||||
{
|
||||
Console.WriteLine(o);
|
||||
return true;
|
||||
}
|
||||
|
||||
[HttpGet("{Id}/backups")]
|
||||
public async Task<ActionResult<BackupsResponse>> GetBackups(int id)
|
||||
{
|
||||
var backups = await _context.Backups.Where(b => b.World.Id == id).ToListAsync();
|
||||
|
||||
BackupsResponse worldBackups = new()
|
||||
{
|
||||
Backups = backups
|
||||
};
|
||||
|
||||
return Ok(worldBackups);
|
||||
}
|
||||
|
||||
[HttpGet("v1/{wId}/join/pc")]
|
||||
public ActionResult<Connection> Join(int wId)
|
||||
{
|
||||
var connection = _context.Connections.FirstOrDefault(x => x.World.Id == wId);
|
||||
|
||||
return Ok(connection);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user