mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 16:28:50 -07:00
rework ProductData and Petz saves
- support for separate saves for lands via ClientVersion.GetVersion(apiKey) - add Adventureland apiKey to ClientVersion
This commit is contained in:
parent
2a20cbd758
commit
d557871fd3
@ -59,16 +59,23 @@ public class ContentController : Controller {
|
|||||||
//[Produces("application/xml")]
|
//[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/GetProduct")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/GetProduct")] // used by World Of Jumpstart
|
||||||
[VikingSession(UseLock=false)]
|
[VikingSession(UseLock=false)]
|
||||||
public string? GetProduct(Viking viking) {
|
public string? GetProduct(Viking viking, [FromForm] string apiKey) {
|
||||||
return viking.ProductData;
|
return Util.SavedData.Get(
|
||||||
|
viking,
|
||||||
|
ClientVersion.GetVersion(apiKey)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
//[Produces("application/xml")]
|
//[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/SetProduct")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/SetProduct")] // used by World Of Jumpstart
|
||||||
[VikingSession]
|
[VikingSession]
|
||||||
public bool SetProduct(Viking viking, [FromForm] string contentXml) {
|
public bool SetProduct(Viking viking, [FromForm] string contentXml, [FromForm] string apiKey) {
|
||||||
viking.ProductData = contentXml;
|
Util.SavedData.Set(
|
||||||
|
viking,
|
||||||
|
ClientVersion.GetVersion(apiKey),
|
||||||
|
contentXml
|
||||||
|
);
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -78,30 +85,34 @@ public class ContentController : Controller {
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
//[Produces("application/xml")]
|
//[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/GetCurrentPetByUserID")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/GetCurrentPetByUserID")] // used by World Of Jumpstart
|
||||||
public IActionResult GetCurrentPetByUserID([FromForm] Guid userId, [FromForm] bool isActive) {
|
public string GetCurrentPetByUserID([FromForm] Guid userId) {
|
||||||
string? petData = ctx.Vikings.FirstOrDefault(e => e.Uid == userId)?.PetSerialized;
|
return GetCurrentPet(ctx.Vikings.FirstOrDefault(e => e.Uid == userId));
|
||||||
if (petData is null)
|
|
||||||
return Ok(XmlUtil.SerializeXml<PetData>(null));
|
|
||||||
|
|
||||||
return Ok(petData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
//[Produces("application/xml")]
|
//[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/GetCurrentPet")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/GetCurrentPet")] // used by World Of Jumpstart
|
||||||
public IActionResult GetCurrentPet(Viking viking, [FromForm] bool isActive) {
|
[VikingSession]
|
||||||
if (viking.PetSerialized is null)
|
public string GetCurrentPet(Viking viking) {
|
||||||
return Ok(XmlUtil.SerializeXml<PetData>(null));
|
string? ret = Util.SavedData.Get(
|
||||||
|
viking,
|
||||||
return Ok(viking.PetSerialized);
|
ClientVersion.WoJS + 1
|
||||||
|
);
|
||||||
|
if (ret is null)
|
||||||
|
return XmlUtil.SerializeXml<PetData>(null);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/SetCurrentPet")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/SetCurrentPet")] // used by World Of Jumpstart
|
||||||
[VikingSession]
|
[VikingSession]
|
||||||
public bool SetCurrentPet(Viking viking, [FromForm] string contentXml) {
|
public bool SetCurrentPet(Viking viking, [FromForm] string? contentXml) {
|
||||||
viking.PetSerialized = contentXml;
|
Util.SavedData.Set(
|
||||||
|
viking,
|
||||||
|
ClientVersion.WoJS + 1,
|
||||||
|
contentXml
|
||||||
|
);
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -110,10 +121,8 @@ public class ContentController : Controller {
|
|||||||
[Produces("application/xml")]
|
[Produces("application/xml")]
|
||||||
[Route("ContentWebService.asmx/DelCurrentPet")] // used by World Of Jumpstart
|
[Route("ContentWebService.asmx/DelCurrentPet")] // used by World Of Jumpstart
|
||||||
[VikingSession]
|
[VikingSession]
|
||||||
public bool DelCurrentPet(Viking viking, [FromForm] bool isActive) {
|
public bool DelCurrentPet(Viking viking) {
|
||||||
viking.PetSerialized = null;
|
return SetCurrentPet(viking, null);
|
||||||
ctx.SaveChanges();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
@ -112,6 +112,9 @@ public class DBContext : DbContext {
|
|||||||
builder.Entity<Viking>().HasMany(v => v.GameData)
|
builder.Entity<Viking>().HasMany(v => v.GameData)
|
||||||
.WithOne(e => e.Viking);
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
|
builder.Entity<Viking>().HasMany(v => v.SavedData)
|
||||||
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
builder.Entity<Viking>().HasMany(v => v.ProfileAnswers)
|
builder.Entity<Viking>().HasMany(v => v.ProfileAnswers)
|
||||||
.WithOne(e => e.Viking);
|
.WithOne(e => e.Viking);
|
||||||
|
|
||||||
@ -204,6 +207,13 @@ public class DBContext : DbContext {
|
|||||||
.WithMany(e => e.AchievementPoints)
|
.WithMany(e => e.AchievementPoints)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
|
||||||
|
builder.Entity<SavedData>().HasKey(e => new { e.VikingId, e.SaveId });
|
||||||
|
|
||||||
|
builder.Entity<SavedData>()
|
||||||
|
.HasOne(e => e.Viking)
|
||||||
|
.WithMany(v => v.SavedData)
|
||||||
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
|
||||||
builder.Entity<ProfileAnswer>().HasOne(i => i.Viking)
|
builder.Entity<ProfileAnswer>().HasOne(i => i.Viking)
|
||||||
.WithMany(i => i.ProfileAnswers)
|
.WithMany(i => i.ProfileAnswers)
|
||||||
.HasForeignKey(e => e.VikingId);
|
.HasForeignKey(e => e.VikingId);
|
||||||
|
8
src/Model/SaveData.cs
Normal file
8
src/Model/SaveData.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace sodoff.Model;
|
||||||
|
public class SavedData {
|
||||||
|
public int VikingId { get; set; }
|
||||||
|
public uint SaveId { get; set; }
|
||||||
|
public string? SerializedData { get; set; }
|
||||||
|
|
||||||
|
public virtual Viking Viking { get; set; } = null!;
|
||||||
|
}
|
@ -32,8 +32,6 @@ public class Viking {
|
|||||||
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
public virtual ICollection<InventoryItem> InventoryItems { get; set; } = null!;
|
||||||
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
public virtual ICollection<GameData> GameData { get; set; } = null!;
|
||||||
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
public virtual ICollection<ProfileAnswer> ProfileAnswers { get; set; } = null!;
|
||||||
|
public virtual ICollection<SavedData> SavedData { get; set; } = null!;
|
||||||
public virtual Dragon? SelectedDragon { get; set; }
|
public virtual Dragon? SelectedDragon { get; set; }
|
||||||
|
|
||||||
public string? ProductData { get; set; }
|
|
||||||
public string? PetSerialized { get; set; }
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ public class ClientVersion {
|
|||||||
apiKey == "1552008f-4a95-46f5-80e2-58574da65875"
|
apiKey == "1552008f-4a95-46f5-80e2-58574da65875"
|
||||||
) {
|
) {
|
||||||
return WoJS;
|
return WoJS;
|
||||||
|
} else if (
|
||||||
|
apiKey == "b4e0f71a-1cda-462a-97b3-0b355e87e0c8"
|
||||||
|
) {
|
||||||
|
return WoJS+10; // WoJS--Adventureland
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
22
src/Util/SavedData.cs
Normal file
22
src/Util/SavedData.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using sodoff.Model;
|
||||||
|
|
||||||
|
namespace sodoff.Util;
|
||||||
|
public class SavedData {
|
||||||
|
public static string? Get(Viking? viking, uint saveId) {
|
||||||
|
return viking?.SavedData.FirstOrDefault(s => s.SaveId == saveId)?.SerializedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Set(Viking viking, uint saveId, string? contentXml) {
|
||||||
|
Console.WriteLine($"\n\n{saveId} {contentXml}\n");
|
||||||
|
Model.SavedData? savedData = viking.SavedData.FirstOrDefault(s => s.SaveId == saveId);
|
||||||
|
if (savedData is null) {
|
||||||
|
savedData = new() {
|
||||||
|
SaveId = saveId,
|
||||||
|
SerializedData = contentXml
|
||||||
|
};
|
||||||
|
viking.SavedData.Add(savedData);
|
||||||
|
} else {
|
||||||
|
savedData.SerializedData = contentXml;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user