mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 16:28:50 -07:00
Compare commits
1 Commits
76c002c1e0
...
f515ab6f45
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f515ab6f45 |
@ -1109,17 +1109,14 @@ public class ContentController : Controller {
|
||||
foreach (var m in filterV2.MissionPair)
|
||||
if (m.MissionID != null)
|
||||
result.Missions.Add(missionService.GetMissionWithProgress((int)m.MissionID, viking.Id, gameVersion));
|
||||
// TODO: probably should also check for mission based on filterV2.ProductGroupID vs mission.GroupID
|
||||
} else {
|
||||
if (filterV2.GetCompletedMission ?? false) {
|
||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Completed))
|
||||
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, gameVersion));
|
||||
} else {
|
||||
var missionStatesById = viking.MissionStates.Where(x => x.MissionStatus != MissionStatus.Completed).ToDictionary(ms => ms.MissionId);
|
||||
HashSet<int> upcomingMissionIds = new(missionStore.GetUpcomingMissions(gameVersion));
|
||||
var combinedMissionIds = new HashSet<int>(missionStatesById.Keys);
|
||||
combinedMissionIds.UnionWith(upcomingMissionIds);
|
||||
foreach (var missionId in combinedMissionIds)
|
||||
result.Missions.Add(missionService.GetMissionWithProgress(missionId, viking.Id, gameVersion));
|
||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus != MissionStatus.Completed))
|
||||
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, gameVersion));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,6 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Encodings.Web;
|
||||
using sodoff.Model;
|
||||
using sodoff.Schema;
|
||||
using sodoff.Util;
|
||||
|
||||
namespace sodoff.Controllers.Common;
|
||||
public class ExportController : ControllerBase {
|
||||
@ -17,7 +15,7 @@ public class ExportController : ControllerBase {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("Export")]
|
||||
[Route("ImportExport.asmx/Export")]
|
||||
public IActionResult Export([FromForm] string username, [FromForm] string password) {
|
||||
// Authenticate user by Username
|
||||
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
||||
@ -38,8 +36,8 @@ public class ExportController : ControllerBase {
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("Import")]
|
||||
public IActionResult Import([FromForm] string username, [FromForm] string password, [FromForm] string vikingName, [FromForm] IFormFile dataFile, [FromForm] string? newVikingName) {
|
||||
[Route("ImportExport.asmx/Import")]
|
||||
public IActionResult Import([FromForm] string username, [FromForm] string password, [FromForm] string vikingName, [FromForm] IFormFile dataFile) {
|
||||
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
||||
if (user is null || new PasswordHasher<object>().VerifyHashedPassword(null, user.Password, password) == PasswordVerificationResult.Failed) {
|
||||
return Unauthorized("Invalid username or password.");
|
||||
@ -52,82 +50,37 @@ public class ExportController : ControllerBase {
|
||||
|
||||
foreach (var v in user_data.Vikings) {
|
||||
if (v.Name == vikingName) {
|
||||
if (String.IsNullOrEmpty(newVikingName))
|
||||
newVikingName = vikingName;
|
||||
|
||||
if (ctx.Vikings.Count(e => e.Name == newVikingName) > 0) {
|
||||
return Conflict("Viking name already in use");
|
||||
}
|
||||
|
||||
if (newVikingName != vikingName) {
|
||||
AvatarData avatarData = XmlUtil.DeserializeXml<AvatarData>(v.AvatarSerialized);
|
||||
avatarData.DisplayName = newVikingName;
|
||||
v.AvatarSerialized = XmlUtil.SerializeXml(avatarData);
|
||||
}
|
||||
|
||||
Viking viking = new Viking {
|
||||
Uid = Guid.NewGuid(),
|
||||
Name = newVikingName,
|
||||
Uid = v.Uid, // TODO check for unique or just generate new?
|
||||
Name = v.Name, // TODO check for unique
|
||||
User = user,
|
||||
AvatarSerialized = v.AvatarSerialized,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
CreationDate = v.CreationDate, // TODO or use now?
|
||||
BirthDate = v.BirthDate,
|
||||
Gender = v.Gender,
|
||||
GameVersion = v.GameVersion
|
||||
};
|
||||
user.Vikings.Add(viking);
|
||||
|
||||
Dictionary<int, Guid> dragonIds = new();
|
||||
foreach (var x in v.Dragons) {
|
||||
x.Viking = viking;
|
||||
x.EntityId = Guid.NewGuid();
|
||||
dragonIds.Add(x.Id, x.EntityId);
|
||||
x.Id = 0;
|
||||
// TODO check EntityId for unique or just generate new?
|
||||
x.Id = 0; // FIXME map old→new value for dragon id to update (stables) xml's
|
||||
ctx.Dragons.Add(x);
|
||||
}
|
||||
Dictionary<int, int> itemIds = new();
|
||||
foreach (var x in v.InventoryItems) {
|
||||
itemIds.Add(x.Id, x.ItemId);
|
||||
x.Id = 0;
|
||||
x.Viking = viking;
|
||||
ctx.InventoryItems.Add(x);
|
||||
}
|
||||
|
||||
ctx.SaveChanges(); // need for get new ids of dragons and items
|
||||
|
||||
HashSet<int> usedItemIds = new();
|
||||
foreach (var x in v.Rooms) {
|
||||
x.Viking = viking;
|
||||
if (int.TryParse(x.RoomId, out int roomID)) {
|
||||
// numeric room name is inventory item id
|
||||
// remap old value to new value based on item id value
|
||||
roomID = viking.InventoryItems.FirstOrDefault(e => e.ItemId == itemIds[roomID] && !usedItemIds.Contains(e.Id)).Id;
|
||||
usedItemIds.Add(roomID);
|
||||
x.RoomId = roomID.ToString();
|
||||
}
|
||||
ctx.Rooms.Add(x);
|
||||
}
|
||||
foreach (var x in v.PairData) {
|
||||
x.Viking = viking;
|
||||
if (x.PairId == 2014) { // stables data
|
||||
foreach (var p in x.Pairs.Where(e => e.Key.StartsWith("Stable"))) {
|
||||
StableData stableData = XmlUtil.DeserializeXml<StableData>(p.Value);
|
||||
stableData.InventoryID = viking.InventoryItems.FirstOrDefault(e => e.ItemId == stableData.ItemID && !usedItemIds.Contains(e.Id)).Id;
|
||||
usedItemIds.Add(stableData.InventoryID);
|
||||
foreach (var n in stableData.NestList) {
|
||||
if (n.PetID != 0)
|
||||
n.PetID = viking.Dragons.FirstOrDefault(d => d.EntityId == dragonIds[n.PetID]).Id;
|
||||
}
|
||||
p.Value = XmlUtil.SerializeXml(stableData);
|
||||
}
|
||||
}
|
||||
ctx.PairData.Add(x);
|
||||
}
|
||||
|
||||
foreach (var x in v.Images) {
|
||||
x.Viking = viking;
|
||||
ctx.Images.Add(x);
|
||||
}
|
||||
foreach (var x in v.InventoryItems) {
|
||||
x.Id = 0; // FIXME map old→new value for item id to update xml's and rooms
|
||||
x.Viking = viking;
|
||||
ctx.InventoryItems.Add(x);
|
||||
}
|
||||
foreach (var x in v.Rooms) {
|
||||
x.Viking = viking;
|
||||
ctx.Rooms.Add(x); // FIXME need update room name (if numeric)
|
||||
}
|
||||
foreach (var x in v.MissionStates) {
|
||||
x.Viking = viking;
|
||||
ctx.MissionStates.Add(x);
|
||||
@ -144,6 +97,10 @@ public class ExportController : ControllerBase {
|
||||
x.Viking = viking;
|
||||
ctx.AchievementPoints.Add(x);
|
||||
}
|
||||
foreach (var x in v.PairData) {
|
||||
x.Viking = viking;
|
||||
ctx.PairData.Add(x); // FIXME need update PetID in stable XML
|
||||
}
|
||||
foreach (var x in v.ProfileAnswers) {
|
||||
x.Viking = viking;
|
||||
ctx.ProfileAnswers.Add(x);
|
||||
@ -178,9 +135,7 @@ public class ExportController : ControllerBase {
|
||||
v.Neighborhood.Viking = viking;
|
||||
ctx.Neighborhoods.Add(v.Neighborhood);
|
||||
}
|
||||
|
||||
if (v.SelectedDragon != null)
|
||||
viking.SelectedDragon = viking.Dragons.FirstOrDefault(d => d.EntityId == dragonIds[v.SelectedDragon.Id]);
|
||||
// TODO set viking.SelectedDragon
|
||||
|
||||
ctx.SaveChanges();
|
||||
return Ok("OK");
|
||||
@ -188,16 +143,4 @@ public class ExportController : ControllerBase {
|
||||
}
|
||||
return Ok("Viking Not Found");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Export")]
|
||||
public IActionResult Export() {
|
||||
return Content(XmlUtil.ReadResourceXmlString("html.export"), "application/xhtml+xml");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Import")]
|
||||
public IActionResult Import() {
|
||||
return Content(XmlUtil.ReadResourceXmlString("html.import"), "application/xhtml+xml");
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace sodoff.Model;
|
||||
|
||||
[Index(nameof(EntityId), IsUnique = true)]
|
||||
public class Dragon {
|
||||
[Key]
|
||||
// [JsonIgnore] used in serialised xml (stables)
|
||||
|
@ -1,10 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace sodoff.Model;
|
||||
|
||||
[Index(nameof(Username), IsUnique = true)]
|
||||
public class User {
|
||||
[Key]
|
||||
public Guid Id { get; set; }
|
||||
|
@ -5,7 +5,7 @@ using sodoff.Schema;
|
||||
|
||||
namespace sodoff.Model;
|
||||
|
||||
[Index(nameof(Uid), IsUnique = true)]
|
||||
[Index(nameof(Uid))]
|
||||
public class Viking {
|
||||
[Key]
|
||||
[JsonIgnore]
|
||||
|
@ -1,16 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Export SoDOff account</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/Export" method="post">
|
||||
<label for="username">Username:</label><br />
|
||||
<input type="text" id="username" name="username" /><br />
|
||||
<label for="password">Password:</label><br />
|
||||
<input type="password" id="password" name="password" /><br /><br />
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Import SoDOff account</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/Import" method="post" enctype="multipart/form-data">
|
||||
<label for="username">Username:</label><br />
|
||||
<input type="text" id="username" name="username" /><br />
|
||||
<label for="password">Password:</label><br />
|
||||
<input type="password" id="password" name="password" /><br /><br />
|
||||
|
||||
<label for="vikingName">Viking name (in imported file):</label><br />
|
||||
<input type="text" id="vikingName" name="vikingName" /><br />
|
||||
<label for="newVikingName">New viking name:</label><br />
|
||||
<input type="text" id="newVikingName" name="newVikingName" /><br />
|
||||
<label for="dataFile">Account data:</label><br />
|
||||
<input type="file" id="dataFile" name="dataFile" /><br /><br />
|
||||
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -1,13 +0,0 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace sodoff.Schema;
|
||||
|
||||
[XmlRoot(ElementName = "NestData", Namespace = "")]
|
||||
[Serializable]
|
||||
public class NestData {
|
||||
[XmlElement(ElementName = "PetID")]
|
||||
public int PetID;
|
||||
|
||||
[XmlElement(ElementName = "ID")]
|
||||
public int ID;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace sodoff.Schema;
|
||||
|
||||
[XmlRoot(ElementName = "StableData", Namespace = "")]
|
||||
[Serializable]
|
||||
public class StableData {
|
||||
[XmlElement(ElementName = "Name")]
|
||||
public string Name;
|
||||
|
||||
[XmlElement(ElementName = "ID")]
|
||||
public int ID;
|
||||
|
||||
[XmlElement(ElementName = "ItemID")]
|
||||
public int ItemID;
|
||||
|
||||
[XmlElement(ElementName = "InventoryID")]
|
||||
public int InventoryID;
|
||||
|
||||
[XmlElement(ElementName = "Nests")]
|
||||
public List<NestData> NestList;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace sodoff.Schema;
|
||||
|
||||
[XmlRoot(ElementName = "UserRankData", Namespace = "")]
|
||||
[Serializable]
|
||||
public class UserRankData {
|
||||
[XmlElement(ElementName = "UserID")]
|
||||
public Guid UserID;
|
||||
|
||||
[XmlElement(ElementName = "Points")]
|
||||
public int Points;
|
||||
|
||||
[XmlElement(ElementName = "CurrentRank")]
|
||||
public UserRank CurrentRank;
|
||||
|
||||
[XmlElement(ElementName = "MemberRank")]
|
||||
public UserRank MemberRank;
|
||||
|
||||
[XmlElement(ElementName = "NextRank")]
|
||||
public UserRank NextRank;
|
||||
}
|
@ -8,8 +8,6 @@
|
||||
<DefineConstants>USE_SQLITE;$(DefineConstants)</DefineConstants>
|
||||
<DefineConstants>USE_POSTGRESQL;$(DefineConstants)</DefineConstants>
|
||||
<DefineConstants>USE_MYSQL;$(DefineConstants)</DefineConstants>
|
||||
|
||||
<NoWarn>8600,8601,8602,8603,8604,8618,8625,8629</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -155,11 +153,5 @@
|
||||
<EmbeddedResource Include="Resources\missions\badge_wojs_al.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\html\export.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Resources\html\import.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user