diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index 3b6a08b0..f75d6fb2 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -3,10 +3,10 @@ using System.Text.Json; using System.Xml.Serialization; using LBPUnion.ProjectLighthouse.Files; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Levels; using LBPUnion.ProjectLighthouse.PlayerData; using LBPUnion.ProjectLighthouse.PlayerData.Profiles; using LBPUnion.ProjectLighthouse.Serialization; -using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -122,6 +122,27 @@ public class UserController : ControllerBase if (update.MehHash != null) user.MehHash = update.MehHash; if (update.BooHash != null) user.BooHash = update.BooHash; + + if (update.Slots != null) + { + foreach (UserUpdateSlot? updateSlot in update.Slots) + { + // ReSharper disable once MergeIntoNegatedPattern + if (updateSlot.Type != SlotType.User || updateSlot.Location == null || updateSlot.SlotId == 0) continue; + + Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == updateSlot.SlotId); + if (slot == null) continue; + + if (slot.CreatorId != gameToken.UserId) continue; + + Location? loc = await this.database.Locations.FirstOrDefaultAsync(l => l.Id == slot.LocationId); + + if (loc == null) throw new ArgumentNullException(); + + loc.X = updateSlot.Location.X; + loc.Y = updateSlot.Location.Y; + } + } if (update.PlanetHash != null) { diff --git a/ProjectLighthouse/PlayerData/Profiles/UserUpdate.cs b/ProjectLighthouse/PlayerData/Profiles/UserUpdate.cs index f25e29dd..86f00311 100644 --- a/ProjectLighthouse/PlayerData/Profiles/UserUpdate.cs +++ b/ProjectLighthouse/PlayerData/Profiles/UserUpdate.cs @@ -1,4 +1,5 @@ #nullable enable +using System.Collections.Generic; using System.Xml.Serialization; namespace LBPUnion.ProjectLighthouse.PlayerData.Profiles; @@ -17,6 +18,10 @@ public class UserUpdate [XmlElement("planets")] public string? PlanetHash { get; set; } + [XmlArray("slots")] + [XmlArrayItem("slot")] + public List? Slots { get; set; } + [XmlElement("yay2")] public string? YayHash { get; set; } diff --git a/ProjectLighthouse/PlayerData/Profiles/UserUpdateSlot.cs b/ProjectLighthouse/PlayerData/Profiles/UserUpdateSlot.cs new file mode 100644 index 00000000..6c44f9be --- /dev/null +++ b/ProjectLighthouse/PlayerData/Profiles/UserUpdateSlot.cs @@ -0,0 +1,20 @@ +#nullable enable +using System.Xml.Serialization; +using LBPUnion.ProjectLighthouse.Levels; + +namespace LBPUnion.ProjectLighthouse.PlayerData.Profiles; + +[XmlRoot("slot")] +public class UserUpdateSlot +{ + + [XmlElement("type")] + public SlotType? Type { get; set; } + + [XmlElement("id")] + public int? SlotId { get; set; } + + [XmlElement("location")] + public Location? Location { get; set; } + +} \ No newline at end of file