forked from SoDOff-Project/sodoff
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")]
|
||||
[Route("ContentWebService.asmx/GetProduct")] // used by World Of Jumpstart
|
||||
[VikingSession(UseLock=false)]
|
||||
public string? GetProduct(Viking viking) {
|
||||
return viking.ProductData;
|
||||
public string? GetProduct(Viking viking, [FromForm] string apiKey) {
|
||||
return Util.SavedData.Get(
|
||||
viking,
|
||||
ClientVersion.GetVersion(apiKey)
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
//[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/SetProduct")] // used by World Of Jumpstart
|
||||
[VikingSession]
|
||||
public bool SetProduct(Viking viking, [FromForm] string contentXml) {
|
||||
viking.ProductData = contentXml;
|
||||
public bool SetProduct(Viking viking, [FromForm] string contentXml, [FromForm] string apiKey) {
|
||||
Util.SavedData.Set(
|
||||
viking,
|
||||
ClientVersion.GetVersion(apiKey),
|
||||
contentXml
|
||||
);
|
||||
ctx.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
@ -78,30 +85,34 @@ public class ContentController : Controller {
|
||||
[HttpPost]
|
||||
//[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetCurrentPetByUserID")] // used by World Of Jumpstart
|
||||
public IActionResult GetCurrentPetByUserID([FromForm] Guid userId, [FromForm] bool isActive) {
|
||||
string? petData = ctx.Vikings.FirstOrDefault(e => e.Uid == userId)?.PetSerialized;
|
||||
if (petData is null)
|
||||
return Ok(XmlUtil.SerializeXml<PetData>(null));
|
||||
|
||||
return Ok(petData);
|
||||
public string GetCurrentPetByUserID([FromForm] Guid userId) {
|
||||
return GetCurrentPet(ctx.Vikings.FirstOrDefault(e => e.Uid == userId));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
//[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/GetCurrentPet")] // used by World Of Jumpstart
|
||||
public IActionResult GetCurrentPet(Viking viking, [FromForm] bool isActive) {
|
||||
if (viking.PetSerialized is null)
|
||||
return Ok(XmlUtil.SerializeXml<PetData>(null));
|
||||
|
||||
return Ok(viking.PetSerialized);
|
||||
[VikingSession]
|
||||
public string GetCurrentPet(Viking viking) {
|
||||
string? ret = Util.SavedData.Get(
|
||||
viking,
|
||||
ClientVersion.WoJS + 1
|
||||
);
|
||||
if (ret is null)
|
||||
return XmlUtil.SerializeXml<PetData>(null);
|
||||
return ret;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/SetCurrentPet")] // used by World Of Jumpstart
|
||||
[VikingSession]
|
||||
public bool SetCurrentPet(Viking viking, [FromForm] string contentXml) {
|
||||
viking.PetSerialized = contentXml;
|
||||
public bool SetCurrentPet(Viking viking, [FromForm] string? contentXml) {
|
||||
Util.SavedData.Set(
|
||||
viking,
|
||||
ClientVersion.WoJS + 1,
|
||||
contentXml
|
||||
);
|
||||
ctx.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
@ -110,10 +121,8 @@ public class ContentController : Controller {
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/DelCurrentPet")] // used by World Of Jumpstart
|
||||
[VikingSession]
|
||||
public bool DelCurrentPet(Viking viking, [FromForm] bool isActive) {
|
||||
viking.PetSerialized = null;
|
||||
ctx.SaveChanges();
|
||||
return true;
|
||||
public bool DelCurrentPet(Viking viking) {
|
||||
return SetCurrentPet(viking, null);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -112,6 +112,9 @@ public class DBContext : DbContext {
|
||||
builder.Entity<Viking>().HasMany(v => v.GameData)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
builder.Entity<Viking>().HasMany(v => v.SavedData)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
builder.Entity<Viking>().HasMany(v => v.ProfileAnswers)
|
||||
.WithOne(e => e.Viking);
|
||||
|
||||
@ -204,6 +207,13 @@ public class DBContext : DbContext {
|
||||
.WithMany(e => e.AchievementPoints)
|
||||
.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)
|
||||
.WithMany(i => i.ProfileAnswers)
|
||||
.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<GameData> GameData { 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 string? ProductData { get; set; }
|
||||
public string? PetSerialized { get; set; }
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ public class ClientVersion {
|
||||
apiKey == "1552008f-4a95-46f5-80e2-58574da65875"
|
||||
) {
|
||||
return WoJS;
|
||||
} else if (
|
||||
apiKey == "b4e0f71a-1cda-462a-97b3-0b355e87e0c8"
|
||||
) {
|
||||
return WoJS+10; // WoJS--Adventureland
|
||||
}
|
||||
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