feat: assign address to world on creation

This commit is contained in:
CyberL1 2024-02-20 09:45:21 +01:00
parent db64404c92
commit ca57e03ee3

View File

@ -20,9 +20,9 @@ namespace Minecraft_Realms_Emulator.Controllers
public async Task<ActionResult<ServersArray>> GetWorlds() public async Task<ActionResult<ServersArray>> GetWorlds()
{ {
var worlds = await _context.Worlds.ToListAsync(); var worlds = await _context.Worlds.ToListAsync();
string cookie = Request.Headers.Cookie; string cookie = Request.Headers.Cookie;
string playerUUID = cookie.Split(";")[0].Split(":")[2]; string playerUUID = cookie.Split(";")[0].Split(":")[2];
string playerName = cookie.Split(";")[1].Split("=")[1]; string playerName = cookie.Split(";")[1].Split("=")[1];
@ -92,12 +92,20 @@ namespace Minecraft_Realms_Emulator.Controllers
var subscription = new Subscription var subscription = new Subscription
{ {
World = world, World = world,
StartDate = ((DateTimeOffset) DateTime.Now).ToUnixTimeMilliseconds().ToString(), StartDate = ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(),
SubscriptionType = SubscriptionType.NORMAL.ToString() SubscriptionType = SubscriptionType.NORMAL.ToString()
}; };
var connection = new Connection
{
World = world,
Address = "127.0.0.1"
};
_context.Worlds.Update(world); _context.Worlds.Update(world);
_context.Subscriptions.Add(subscription); _context.Subscriptions.Add(subscription);
_context.Connections.Add(connection);
_context.SaveChanges(); _context.SaveChanges();
@ -131,7 +139,7 @@ namespace Minecraft_Realms_Emulator.Controllers
public async Task<ActionResult<bool>> Close(int id) public async Task<ActionResult<bool>> Close(int id)
{ {
var worlds = await _context.Worlds.ToListAsync(); var worlds = await _context.Worlds.ToListAsync();
var world = worlds.Find(w => w.Id == id); var world = worlds.Find(w => w.Id == id);
if (world == null) return NotFound("World not found"); if (world == null) return NotFound("World not found");