From 0e5437c5b7831f4acc369d6c0bf627b30229c827 Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Mon, 10 Feb 2025 10:10:37 +0000 Subject: [PATCH] some fixes to PR * remove unnecessary deserialize - serialize * use EmbeddedResource to read missions and badges files * remove dead (and commented out) code * define missing database model relation in DBContext.cs * revert unrelated changes --- src/Controllers/Common/ContentController.cs | 134 ++--- src/Model/DBContext.cs | 41 +- src/Model/Viking.cs | 5 +- src/Program.cs | 1 - src/Resources/missions/stepsmissions_1_2.xml | 497 ------------------- src/Schema/StepTask.cs | 12 +- src/Schema/StepTaskObjective.cs | 17 +- src/Schema/World.cs | 4 +- src/Services/MissionService.cs | 20 - src/Services/WorldIdService.cs | 54 +- src/sodoff.csproj | 10 +- 11 files changed, 118 insertions(+), 677 deletions(-) delete mode 100644 src/Resources/missions/stepsmissions_1_2.xml diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index 9e7c5c6..ab4da8a 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -37,7 +37,7 @@ public class ContentController : Controller { GameDataService gameDataService, DisplayNamesService displayNamesService, NeighborhoodService neighborhoodService, - WorldIdService worldIdService, + WorldIdService worldIdService, IOptions config ) { this.ctx = ctx; @@ -2120,107 +2120,79 @@ public class ContentController : Controller { public IActionResult GetTreasureChest() { // TODO: This is a placeholder return Ok(new TreasureChestData()); - } - - //Oh boy it's the AL code stuff you guys ready for p a i n - + } + [HttpPost] [Produces("application/xml")] [Route("MissionWebService.asmx/GetWorldId")] // used by Math Blaster and WoJS Adventureland - public IActionResult GetWorldId([FromForm] int gameId, [FromForm] string sceneName, [FromForm] string apiKey) - { - var result = worldIdService.GetWorldID(sceneName); - return Ok(result); + public IActionResult GetWorldId([FromForm] int gameId, [FromForm] string sceneName) { + return Ok(worldIdService.GetWorldID(sceneName)); + } + + [HttpPost] + // [Produces("application/xml")] + [Route("MissionWebService.asmx/GetMission")] // old ("step") missions - used by MB and WoJS lands + public IActionResult GetMission([FromForm] int gameId, [FromForm] int type) { + if (gameId == 1) return Ok(XmlUtil.ReadResourceXmlString("missions.step_missions_wojs_al")); + return Ok(); + } + + [HttpPost] + // [Produces("application/xml")] + [Route("MissionWebService.asmx/GetStep")] // old ("step") missions - used by MB and WoJS lands + public IActionResult GetMissionStep([FromForm] int stepId) { + return Ok(System.IO.File.ReadAllText($"./Resources/missions/steps/{stepId}.xml")); + } + + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/GetUserMission")] // old ("step") missions - used by MB and WoJS lands + [VikingSession] + public IActionResult GetUserMission(Viking viking, [FromForm] int worldId) { + return Ok(missionService.GetUserMissionData(viking, worldId)); + } + + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/SetUserMission")] // old ("step") missions - used by MB and WoJS lands + [VikingSession] + public IActionResult SetUserMission(Viking viking, [FromForm] int worldId, [FromForm] int missionId, [FromForm] int stepId, [FromForm] int taskId) { + missionService.SetOrUpdateUserMissionData(viking, worldId, missionId, stepId, taskId); + return Ok(true); + } + + [HttpPost] + [Produces("application/xml")] + [Route("ContentWebService.asmx/SetUserMissionComplete")] // old ("step") missions - used by MB and WoJS lands + [VikingSession] + public IActionResult SetUserMissionComplete(Viking viking, [FromForm] int worldId, [FromForm] int missionId) { + return Ok(missionService.SetUserMissionCompleted(viking, worldId, missionId, true)); } [HttpPost] //[Produces("application/xml")] - [Route("MissionWebService.asmx/GetBadge")] - public IActionResult GetBadge([FromForm] int gameId) - { - if (gameId == 1) return Ok(System.IO.File.ReadAllText("./Resources/missions/badge_wojs_al.xml")); - return Ok(); // if it doesn't work/causes errors then: return Ok(XmlUtil.SerializeXml(new BadgeData())); + [Route("MissionWebService.asmx/GetBadge")] // old ("step") missions - used by MB and WoJS lands + public IActionResult GetBadge([FromForm] int gameId) { + if (gameId == 1) return Ok(XmlUtil.ReadResourceXmlString("missions.badge_wojs_al.xml")); + return Ok(); } [HttpPost] [Produces("application/xml")] - [Route("MissionWebService.asmx/GetMission")] - public IActionResult GetMission([FromForm] int gameId, [FromForm] int type, [FromForm] string apiKey) - { - MissionData mission = missionService.GetMissionDataFromFile(ClientVersion.GetVersion(apiKey), gameId, type); - if (mission != null) return Ok(mission); - else return Ok(new MissionData()); - } - - [HttpPost] - [Produces("application/xml")] - [Route("ContentWebService.asmx/GetUserMission")] + [Route("ContentWebService.asmx/SetUserBadgeComplete")] // old ("step") missions - used by MB and WoJS lands [VikingSession] - public IActionResult GetUserMission(Viking viking, [FromForm] int worldId, [FromForm] string apiKey) - { - //if (ClientVersion.GetVersion(apiKey) <= ClientVersion.WoJS_AdvLand) - //{ - return Ok(missionService.GetUserMissionData(viking, worldId)); - //} - - return Ok(new Schema.UserMissionData()); - } - - [HttpPost] - [Produces("application/xml")] - [Route("ContentWebService.asmx/SetUserMission")] - [VikingSession] - public IActionResult SetUserMission(Viking viking, [FromForm] int worldId, [FromForm] int missionId, [FromForm] int stepId, [FromForm] int taskId, [FromForm] string apiKey) - { - //if (ClientVersion.GetVersion(apiKey) <= ClientVersion.WoJS_AdvLand) - //{ - missionService.SetOrUpdateUserMissionData(viking, worldId, missionId, stepId, taskId); - return Ok(true); // assuming true or false response here - //} - - return Ok(false); - } - - [HttpPost] - [Produces("application/xml")] - [Route("ContentWebService.asmx/SetUserMissionComplete")] - [VikingSession] - public IActionResult SetUserMissionComplete(Viking viking, [FromForm] int worldId, [FromForm] int missionId, [FromForm] string apiKey) - { - //if (ClientVersion.GetVersion(apiKey) <= ClientVersion.WoJS_AdvLand) - //{ - return Ok(missionService.SetUserMissionCompleted(viking, worldId, missionId, true)); - //} - - return Ok(false); - } - - [HttpPost] - [Produces("application/xml")] - [Route("ContentWebService.asmx/SetUserBadgeComplete")] - [VikingSession] - public IActionResult SetUserBadgeComplete(Viking viking, [FromForm] int badgeId) - { + public IActionResult SetUserBadgeComplete(Viking viking, [FromForm] int badgeId) { return Ok(missionService.SetUserBadgeComplete(viking, badgeId)); } [HttpPost] [Produces("application/xml")] - [Route("ContentWebService.asmx/GetUserBadgeComplete")] + [Route("ContentWebService.asmx/GetUserBadgeComplete")] // old ("step") missions - used by MB and WoJS lands [VikingSession] - public IActionResult GetUserBadgeComplete(Viking viking) - { + public IActionResult GetUserBadgeComplete(Viking viking) { return Ok(missionService.GetUserBadgesCompleted(viking)); } - [HttpPost] - [Produces("application/xml")] - [Route("MissionWebService.asmx/GetStep")] - public IActionResult GetMissionStep([FromForm] int stepId, [FromForm] string apiKey) - { - return Ok(missionService.GetMissionStepFromFile(ClientVersion.GetVersion(apiKey), stepId)); - } - [HttpPost] [Produces("application/xml")] [Route("ContentWebService.asmx/GetRevealIndex")] // used by World Of Jumpstart (Learning Games) diff --git a/src/Model/DBContext.cs b/src/Model/DBContext.cs index 3a963af..1832763 100644 --- a/src/Model/DBContext.cs +++ b/src/Model/DBContext.cs @@ -3,8 +3,7 @@ using Microsoft.Extensions.Options; using sodoff.Configuration; namespace sodoff.Model; -public class DBContext : DbContext -{ +public class DBContext : DbContext { public DbSet Users { get; set; } = null!; public DbSet Vikings { get; set; } = null!; public DbSet Dragons { get; set; } = null!; @@ -28,32 +27,30 @@ public class DBContext : DbContext // we had a brief debate on whether it's neighborhoods or neighborheed public DbSet Groups { get; set; } = null!; public DbSet Ratings { get; set; } = null!; - public DbSet RatingRanks { get; set; } = null!; + public DbSet RatingRanks { get; set; } = null!; public DbSet UserMissionData { get; set; } = null!; public DbSet UserBadgesCompleted { get; set; } = null!; private readonly IOptions config; - public DBContext(IOptions config) - { + public DBContext(IOptions config) { this.config = config; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { -#if USE_POSTGRESQL + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { + #if USE_POSTGRESQL if (config.Value.DbProvider == DbProviders.PostgreSQL) { optionsBuilder.UseNpgsql(config.Value.DbConnection).UseLazyLoadingProxies(); return; } -#endif -#if USE_MYSQL + #endif + #if USE_MYSQL if (config.Value.DbProvider == DbProviders.MySQL) { optionsBuilder.UseMySQL(config.Value.DbConnection).UseLazyLoadingProxies(); return; } -#endif -#if USE_SQLITE + #endif + #if USE_SQLITE if (config.Value.DbProvider == DbProviders.SQLite) { string DbPath; if (String.IsNullOrEmpty(config.Value.DbPath)) { @@ -64,12 +61,11 @@ public class DBContext : DbContext optionsBuilder.UseSqlite($"Data Source={DbPath}").UseLazyLoadingProxies(); return; } -#endif + #endif throw new Exception($"Unsupported DbProvider {config.Value.DbProvider}"); } - protected override void OnModelCreating(ModelBuilder builder) - { + protected override void OnModelCreating(ModelBuilder builder) { // Sessions builder.Entity().HasOne(s => s.User) .WithMany(e => e.Sessions) @@ -154,6 +150,12 @@ public class DBContext : DbContext builder.Entity().HasMany(v => v.Ratings) .WithOne(r => r.Viking); + builder.Entity().HasMany(v => v.UserMissions) + .WithOne(r => r.Viking); + + builder.Entity().HasMany(v => v.UserBadgesCompleted) + .WithOne(r => r.Viking); + // Dragons builder.Entity().HasOne(d => d.Viking) .WithMany(e => e.Dragons) @@ -290,5 +292,14 @@ public class DBContext : DbContext builder.Entity().HasMany(rr => rr.Ratings) .WithOne(r => r.Rank); + + // old ("step") missions + builder.Entity().HasOne(r => r.Viking) + .WithMany(v => v.UserMissions) + .HasForeignKey(r => r.VikingId); + + builder.Entity().HasOne(r => r.Viking) + .WithMany(v => v.UserBadgesCompleted) + .HasForeignKey(r => r.VikingId); } } diff --git a/src/Model/Viking.cs b/src/Model/Viking.cs index 163e51d..a787107 100644 --- a/src/Model/Viking.cs +++ b/src/Model/Viking.cs @@ -5,8 +5,7 @@ using sodoff.Schema; namespace sodoff.Model; [Index(nameof(Uid))] -public class Viking -{ +public class Viking { [Key] public int Id { get; set; } @@ -43,7 +42,7 @@ public class Viking public virtual ICollection Groups { get; set; } = null!; public virtual ICollection Ratings { get; set; } = null!; public virtual Dragon? SelectedDragon { get; set; } - public virtual ICollection UserMissions { get; set; } = null!; + public virtual ICollection UserMissions { get; set; } = null!; public virtual ICollection UserBadgesCompleted { get; set; } = null!; public DateTime? CreationDate { get; set; } diff --git a/src/Program.cs b/src/Program.cs index d50819b..91cbbaa 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -41,7 +41,6 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); - bool assetServer = builder.Configuration.GetSection("AssetServer").GetValue("Enabled"); string assetIP = builder.Configuration.GetSection("AssetServer").GetValue("ListenIP"); int assetPort = builder.Configuration.GetSection("AssetServer").GetValue("Port"); diff --git a/src/Resources/missions/stepsmissions_1_2.xml b/src/Resources/missions/stepsmissions_1_2.xml deleted file mode 100644 index a135623..0000000 --- a/src/Resources/missions/stepsmissions_1_2.xml +++ /dev/null @@ -1,497 +0,0 @@ - - - - 4 - Lost Island Mission 1 - - - Welcome to Training Island - 1 - - - 1 - 1 - - - 2 - 2 - - - 3 - 3 - - - 4 - 4 - - - 5 - 5 - - - 179 - 349 - - - 6 - 6 - - - 7 - 7 - - - 8 - 8 - - - 9 - 9 - - - 10 - 10 - - - 23 - 18 - - - 24 - 19 - - - - 18 - Lost Island Mission 2 - - - Mission 2- Congrats! Take the ship to Lost Island and get familar with home base. - 1 - - - 26 - 250 - - - 27 - 251 - - - 28 - 252 - - - 106 - 348 - - - 29 - 253 - - - 30 - 254 - - - 31 - 255 - - - 32 - 256 - - - 33 - 257 - - - - 19 - Lost Island Mission 3 - - - Mission 3- Introduction to Lost Shores - 1 - - - 34 - 258 - - - 35 - 259 - - - 36 - 260 - - - 37 - 261 - - - 38 - 262 - - - 39 - 263 - - - 40 - 264 - - - - 20 - Lost Island Mission 4 - - - Mission 4- Explore Lost Island and intro to the store - 1 - - - 41 - 265 - - - 42 - 266 - - - 43 - 267 - - - 44 - 268 - - - 45 - 269 - - - - 21 - Lost Island Mission 5 - - - Mission 5- Explore the mountain with Hops - 1 - - - 46 - 270 - - - 47 - 271 - - - 48 - 272 - - - 49 - 273 - - - 50 - 274 - - - 51 - 275 - - - - 22 - Lost Island Mission 6 - - - Mission 6- Punk Punk invade- Time to clean house - 1 - - - 52 - 276 - - - 53 - 277 - - - 54 - 278 - - - 55 - 279 - 280 - 281 - 282 - 283 - - - 56 - 284 - - - 57 - 285 - - - 58 - 286 - - - - 23 - Lost Island Mission 7 - - - Mission 7- Get the Lost Shores ready for the celebration - 1 - - - 59 - 287 - - - 60 - 288 - - - 61 - 289 - 290 - 291 - - - 62 - 292 - 293 - 294 - - - 63 - 295 - - - 64 - 296 - - - 65 - 297 - - - 66 - 298 - - - 67 - 299 - - - - 24 - Lost Island Mission 8 - - - Mission 8- Lets Party - 1 - - - 68 - 300 - - - 69 - 301 - - - 70 - 302 - - - 71 - 303 - - - 72 - 304 - - - 73 - 305 - - - 74 - 306 - - - 75 - 307 - - - 76 - 308 - - - 77 - 309 - - - 78 - 310 - - - - 25 - Lost Island Mission 9 - - - Mission 9- Find where Punk Punks are coming from. - 1 - - - 79 - 311 - - - 80 - 312 - - - 81 - 313 - - - 82 - 314 - - - 83 - 315 - - - 84 - 316 - - - 85 - 317 - - - - 26 - Lost Island Mission 10 - - - Mission 10- Introduce Rabbit holes and get statue - 1 - - - 86 - 318 - - - 87 - 319 - - - 88 - 320 - - - 89 - 321 - - - 90 - 322 - - - 91 - 323 - - - 92 - 324 - 325 - - - 93 - 326 - - - - 27 - Lost Island Mission 11 - - - Mission 11- Protect Lost Island from the Punk Punks - 1 - - - 94 - 327 - - - 95 - 328 - - - 96 - 329 - - - 97 - 330 - - - 98 - 331 - - - 99 - 332 - - - 100 - 333 - - - - 28 - Lost Island Mission 12 - - - Mission 12- Need to take the statue back to the valley - 1 - - - 101 - 334 - - - 102 - 335 - - - 103 - 336 - - - 104 - 338 - - - 105 - 339 - - - - diff --git a/src/Schema/StepTask.cs b/src/Schema/StepTask.cs index 3ddf5a0..40fd516 100644 --- a/src/Schema/StepTask.cs +++ b/src/Schema/StepTask.cs @@ -9,44 +9,34 @@ namespace sodoff.Schema [XmlElement(ElementName = "TaskID")] public int TaskID; - // Token: 0x0400043C RID: 1084 [XmlElement(ElementName = "Type")] public string Type; - // Token: 0x0400043D RID: 1085 [XmlElement(ElementName = "Dialog", IsNullable = true)] public StepTaskDialog Dialog; - // Token: 0x0400043E RID: 1086 [XmlElement(ElementName = "Message")] public StepTaskMessage[] Message; - // Token: 0x0400043F RID: 1087 [XmlElement(ElementName = "SetupGroup", IsNullable = true)] public string SetupGroup; - // Token: 0x04000440 RID: 1088 [XmlElement(ElementName = "SetupScene", IsNullable = true)] public string SetupScene; - // Token: 0x04000441 RID: 1089 [XmlElement(ElementName = "Help")] public StepTaskHelp[] Help; - // Token: 0x04000442 RID: 1090 [XmlElement(ElementName = "RewardPlayerItem")] public StepTaskRewardPlayerItem[] RewardPlayerItem; - // Token: 0x04000443 RID: 1091 [XmlElement(ElementName = "Experience")] public int Experience; - // Token: 0x04000444 RID: 1092 [XmlElement(ElementName = "Time", IsNullable = true)] public int? Time; - // Token: 0x04000445 RID: 1093 [XmlElement(ElementName = "Objective")] public StepTaskObjective Objective; } -} \ No newline at end of file +} diff --git a/src/Schema/StepTaskObjective.cs b/src/Schema/StepTaskObjective.cs index f5c730a..79406af 100644 --- a/src/Schema/StepTaskObjective.cs +++ b/src/Schema/StepTaskObjective.cs @@ -9,64 +9,49 @@ namespace sodoff.Schema [XmlElement(ElementName = "Beacon", IsNullable = true)] public bool? Beacon; - // Token: 0x0400045B RID: 1115 [XmlElement(ElementName = "NPC", IsNullable = true)] public string NPC; - // Token: 0x0400045C RID: 1116 [XmlElement(ElementName = "Marker", IsNullable = true)] public string Marker; - // Token: 0x0400045D RID: 1117 [XmlElement(ElementName = "Scene", IsNullable = true)] public string Scene; - // Token: 0x0400045E RID: 1118 [XmlElement(ElementName = "Range", IsNullable = true)] public float? Range; - // Token: 0x0400045F RID: 1119 [XmlElement(ElementName = "Module", IsNullable = true)] public string Module; - // Token: 0x04000460 RID: 1120 [XmlElement(ElementName = "Group", IsNullable = true)] public string Group; - // Token: 0x04000461 RID: 1121 [XmlElement(ElementName = "Object", IsNullable = true)] public string Object; - // Token: 0x04000462 RID: 1122 [XmlElement(ElementName = "StoreID", IsNullable = true)] public int? StoreID; - // Token: 0x04000463 RID: 1123 [XmlElement(ElementName = "ItemID", IsNullable = true)] public int? ItemID; - // Token: 0x04000464 RID: 1124 [XmlElement(ElementName = "ItemName", IsNullable = true)] public string ItemName; - // Token: 0x04000465 RID: 1125 [XmlElement(ElementName = "CategoryID", IsNullable = true)] public int? CategoryID; - // Token: 0x04000466 RID: 1126 [XmlElement(ElementName = "AttributeID")] public int[] AttributeID; - // Token: 0x04000467 RID: 1127 [XmlElement(ElementName = "Quantity", IsNullable = true)] public int? Quantity; - // Token: 0x04000468 RID: 1128 [XmlElement(ElementName = "Photo", IsNullable = true)] public StepTaskObjectivePhoto Photo; - // Token: 0x04000469 RID: 1129 [XmlElement(ElementName = "Creative", IsNullable = true)] public StepTaskObjectiveCreative Creative; } -} \ No newline at end of file +} diff --git a/src/Schema/World.cs b/src/Schema/World.cs index a357226..1fc1c6e 100644 --- a/src/Schema/World.cs +++ b/src/Schema/World.cs @@ -2,11 +2,11 @@ using System.Xml.Serialization; [XmlRoot(ElementName = "World", Namespace = "")] [Serializable] -public class World +public class World { [XmlElement(ElementName = "Scene")] public string Scene; [XmlElement(ElementName = "ID")] public int ID; -} \ No newline at end of file +} diff --git a/src/Services/MissionService.cs b/src/Services/MissionService.cs index fdb4e65..f32f27c 100644 --- a/src/Services/MissionService.cs +++ b/src/Services/MissionService.cs @@ -54,26 +54,6 @@ public class MissionService { return mission; } - public MissionData GetMissionDataFromFile(uint gameVersion, int gameId, int type) - { - //if (gameVersion <= ClientVersion.WoJS_AdvLand) - //{ - return XmlUtil.DeserializeXml(File.ReadAllText($"./Resources/missions/stepsmissions_{gameId}_{type}.xml")); - //} - - return new MissionData(); - } - - public Step GetMissionStepFromFile(uint gameVersion, int id) - { - //if (gameVersion <= ClientVersion.WoJS_AdvLand) - //{ - return XmlUtil.DeserializeXml(File.ReadAllText($"./Resources/missions/steps/{id}.xml")); - //} - - return new Step(); - } - public Schema.UserMissionData GetUserMissionData(Viking viking, int worldId) { Schema.UserMissionData umdRes = new Schema.UserMissionData(); diff --git a/src/Services/WorldIdService.cs b/src/Services/WorldIdService.cs index f41e85d..c20bce0 100644 --- a/src/Services/WorldIdService.cs +++ b/src/Services/WorldIdService.cs @@ -1,29 +1,25 @@ -using sodoff.Schema; -using sodoff.Util; - -namespace sodoff.Services; - - -public class WorldIdService { - - Dictionary worlds_id = new(); - - public WorldIdService() - { - var worlds = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("worlds")); - //Console.WriteLine("We are confirming this thing works"); - foreach (var w in worlds) - { - worlds_id[w.Scene] = w.ID; - } - } - - public int GetWorldID(string mapName) - { - //Console.WriteLine(worlds_id[mapName]); - if (worlds_id.ContainsKey(mapName)) - return worlds_id[mapName]; - else - return 0; - } -} \ No newline at end of file +using sodoff.Schema; +using sodoff.Util; + +namespace sodoff.Services; + +public class WorldIdService { + Dictionary worlds_id = new(); + + public WorldIdService() + { + var worlds = XmlUtil.DeserializeXml(XmlUtil.ReadResourceXmlString("worlds")); + foreach (var w in worlds) + { + worlds_id[w.Scene] = w.ID; + } + } + + public int GetWorldID(string mapName) + { + if (worlds_id.ContainsKey(mapName)) + return worlds_id[mapName]; + else + return 0; + } +} diff --git a/src/sodoff.csproj b/src/sodoff.csproj index 136d82e..9f6f083 100644 --- a/src/sodoff.csproj +++ b/src/sodoff.csproj @@ -139,10 +139,16 @@ PreserveNewest - + PreserveNewest - + + PreserveNewest + + + PreserveNewest + + PreserveNewest