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)
|
foreach (var m in filterV2.MissionPair)
|
||||||
if (m.MissionID != null)
|
if (m.MissionID != null)
|
||||||
result.Missions.Add(missionService.GetMissionWithProgress((int)m.MissionID, viking.Id, gameVersion));
|
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 {
|
} else {
|
||||||
if (filterV2.GetCompletedMission ?? false) {
|
if (filterV2.GetCompletedMission ?? false) {
|
||||||
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Completed))
|
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus == MissionStatus.Completed))
|
||||||
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, gameVersion));
|
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, gameVersion));
|
||||||
} else {
|
} else {
|
||||||
var missionStatesById = viking.MissionStates.Where(x => x.MissionStatus != MissionStatus.Completed).ToDictionary(ms => ms.MissionId);
|
foreach (var mission in viking.MissionStates.Where(x => x.MissionStatus != MissionStatus.Completed))
|
||||||
HashSet<int> upcomingMissionIds = new(missionStore.GetUpcomingMissions(gameVersion));
|
result.Missions.Add(missionService.GetMissionWithProgress(mission.MissionId, viking.Id, 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ using System.Text.Json;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using sodoff.Model;
|
using sodoff.Model;
|
||||||
using sodoff.Schema;
|
|
||||||
using sodoff.Util;
|
|
||||||
|
|
||||||
namespace sodoff.Controllers.Common;
|
namespace sodoff.Controllers.Common;
|
||||||
public class ExportController : ControllerBase {
|
public class ExportController : ControllerBase {
|
||||||
@ -17,7 +15,7 @@ public class ExportController : ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("Export")]
|
[Route("ImportExport.asmx/Export")]
|
||||||
public IActionResult Export([FromForm] string username, [FromForm] string password) {
|
public IActionResult Export([FromForm] string username, [FromForm] string password) {
|
||||||
// Authenticate user by Username
|
// Authenticate user by Username
|
||||||
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
||||||
@ -38,8 +36,8 @@ public class ExportController : ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("Import")]
|
[Route("ImportExport.asmx/Import")]
|
||||||
public IActionResult Import([FromForm] string username, [FromForm] string password, [FromForm] string vikingName, [FromForm] IFormFile dataFile, [FromForm] string? newVikingName) {
|
public IActionResult Import([FromForm] string username, [FromForm] string password, [FromForm] string vikingName, [FromForm] IFormFile dataFile) {
|
||||||
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
|
||||||
if (user is null || new PasswordHasher<object>().VerifyHashedPassword(null, user.Password, password) == PasswordVerificationResult.Failed) {
|
if (user is null || new PasswordHasher<object>().VerifyHashedPassword(null, user.Password, password) == PasswordVerificationResult.Failed) {
|
||||||
return Unauthorized("Invalid username or password.");
|
return Unauthorized("Invalid username or password.");
|
||||||
@ -52,82 +50,37 @@ public class ExportController : ControllerBase {
|
|||||||
|
|
||||||
foreach (var v in user_data.Vikings) {
|
foreach (var v in user_data.Vikings) {
|
||||||
if (v.Name == vikingName) {
|
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 {
|
Viking viking = new Viking {
|
||||||
Uid = Guid.NewGuid(),
|
Uid = v.Uid, // TODO check for unique or just generate new?
|
||||||
Name = newVikingName,
|
Name = v.Name, // TODO check for unique
|
||||||
User = user,
|
User = user,
|
||||||
AvatarSerialized = v.AvatarSerialized,
|
AvatarSerialized = v.AvatarSerialized,
|
||||||
CreationDate = DateTime.UtcNow,
|
CreationDate = v.CreationDate, // TODO or use now?
|
||||||
BirthDate = v.BirthDate,
|
BirthDate = v.BirthDate,
|
||||||
Gender = v.Gender,
|
Gender = v.Gender,
|
||||||
GameVersion = v.GameVersion
|
GameVersion = v.GameVersion
|
||||||
};
|
};
|
||||||
user.Vikings.Add(viking);
|
user.Vikings.Add(viking);
|
||||||
|
|
||||||
Dictionary<int, Guid> dragonIds = new();
|
|
||||||
foreach (var x in v.Dragons) {
|
foreach (var x in v.Dragons) {
|
||||||
x.Viking = viking;
|
x.Viking = viking;
|
||||||
x.EntityId = Guid.NewGuid();
|
// TODO check EntityId for unique or just generate new?
|
||||||
dragonIds.Add(x.Id, x.EntityId);
|
x.Id = 0; // FIXME map old→new value for dragon id to update (stables) xml's
|
||||||
x.Id = 0;
|
|
||||||
ctx.Dragons.Add(x);
|
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) {
|
foreach (var x in v.Images) {
|
||||||
x.Viking = viking;
|
x.Viking = viking;
|
||||||
ctx.Images.Add(x);
|
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) {
|
foreach (var x in v.MissionStates) {
|
||||||
x.Viking = viking;
|
x.Viking = viking;
|
||||||
ctx.MissionStates.Add(x);
|
ctx.MissionStates.Add(x);
|
||||||
@ -144,6 +97,10 @@ public class ExportController : ControllerBase {
|
|||||||
x.Viking = viking;
|
x.Viking = viking;
|
||||||
ctx.AchievementPoints.Add(x);
|
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) {
|
foreach (var x in v.ProfileAnswers) {
|
||||||
x.Viking = viking;
|
x.Viking = viking;
|
||||||
ctx.ProfileAnswers.Add(x);
|
ctx.ProfileAnswers.Add(x);
|
||||||
@ -178,9 +135,7 @@ public class ExportController : ControllerBase {
|
|||||||
v.Neighborhood.Viking = viking;
|
v.Neighborhood.Viking = viking;
|
||||||
ctx.Neighborhoods.Add(v.Neighborhood);
|
ctx.Neighborhoods.Add(v.Neighborhood);
|
||||||
}
|
}
|
||||||
|
// TODO set viking.SelectedDragon
|
||||||
if (v.SelectedDragon != null)
|
|
||||||
viking.SelectedDragon = viking.Dragons.FirstOrDefault(d => d.EntityId == dragonIds[v.SelectedDragon.Id]);
|
|
||||||
|
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
return Ok("OK");
|
return Ok("OK");
|
||||||
@ -188,16 +143,4 @@ public class ExportController : ControllerBase {
|
|||||||
}
|
}
|
||||||
return Ok("Viking Not Found");
|
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.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace sodoff.Model;
|
namespace sodoff.Model;
|
||||||
|
|
||||||
[Index(nameof(EntityId), IsUnique = true)]
|
|
||||||
public class Dragon {
|
public class Dragon {
|
||||||
[Key]
|
[Key]
|
||||||
// [JsonIgnore] used in serialised xml (stables)
|
// [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;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace sodoff.Model;
|
namespace sodoff.Model;
|
||||||
|
|
||||||
[Index(nameof(Username), IsUnique = true)]
|
|
||||||
public class User {
|
public class User {
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
@ -5,7 +5,7 @@ using sodoff.Schema;
|
|||||||
|
|
||||||
namespace sodoff.Model;
|
namespace sodoff.Model;
|
||||||
|
|
||||||
[Index(nameof(Uid), IsUnique = true)]
|
[Index(nameof(Uid))]
|
||||||
public class Viking {
|
public class Viking {
|
||||||
[Key]
|
[Key]
|
||||||
[JsonIgnore]
|
[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_SQLITE;$(DefineConstants)</DefineConstants>
|
||||||
<DefineConstants>USE_POSTGRESQL;$(DefineConstants)</DefineConstants>
|
<DefineConstants>USE_POSTGRESQL;$(DefineConstants)</DefineConstants>
|
||||||
<DefineConstants>USE_MYSQL;$(DefineConstants)</DefineConstants>
|
<DefineConstants>USE_MYSQL;$(DefineConstants)</DefineConstants>
|
||||||
|
|
||||||
<NoWarn>8600,8601,8602,8603,8604,8618,8625,8629</NoWarn>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -155,11 +153,5 @@
|
|||||||
<EmbeddedResource Include="Resources\missions\badge_wojs_al.xml">
|
<EmbeddedResource Include="Resources\missions\badge_wojs_al.xml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
<EmbeddedResource Include="Resources\html\export.xml">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</EmbeddedResource>
|
|
||||||
<EmbeddedResource Include="Resources\html\import.xml">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user