forked from SoDOff-Project/sodoff
SoD 1.6 fixes
- CreateRaisedPet endpoint - support for 1.6 apiKey + util class for management apiKey version recognition
This commit is contained in:
parent
80481713e3
commit
47e1bfb065
@ -95,7 +95,7 @@ public class AuthenticationController : Controller {
|
||||
Username = user.Username,
|
||||
MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder
|
||||
FacebookUserID = 0,
|
||||
MultiplayerEnabled = (apiKey != "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"),
|
||||
MultiplayerEnabled = !ClientVersion.IsOldSoD(apiKey),
|
||||
IsApproved = true,
|
||||
Age = 24,
|
||||
OpenChatEnabled = true
|
||||
@ -110,7 +110,7 @@ public class AuthenticationController : Controller {
|
||||
UserID = viking.Uid.ToString(),
|
||||
Username = viking.Name,
|
||||
FacebookUserID = 0,
|
||||
MultiplayerEnabled = (apiKey != "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"),
|
||||
MultiplayerEnabled = !ClientVersion.IsOldSoD(apiKey),
|
||||
IsApproved = true,
|
||||
Age = 24,
|
||||
OpenChatEnabled = true
|
||||
|
@ -271,6 +271,53 @@ public class ContentController : Controller {
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("ContentWebService.asmx/CreateRaisedPet")] // used by SoD 1.6
|
||||
[VikingSession]
|
||||
public RaisedPetData? CreateRaisedPet(Viking viking, int petTypeID) {
|
||||
// Update the RaisedPetData with the info
|
||||
String dragonId = Guid.NewGuid().ToString();
|
||||
|
||||
var raisedPetData = new RaisedPetData();
|
||||
raisedPetData.IsPetCreated = true;
|
||||
raisedPetData.PetTypeID = petTypeID;
|
||||
raisedPetData.RaisedPetID = 0; // Initially make zero, so the db auto-fills
|
||||
raisedPetData.EntityID = Guid.Parse(dragonId);
|
||||
raisedPetData.Name = string.Concat("Dragon-", dragonId.AsSpan(0, 8)); // Start off with a random name
|
||||
raisedPetData.IsSelected = false; // The api returns false, not sure why
|
||||
raisedPetData.CreateDate = new DateTime(DateTime.Now.Ticks);
|
||||
raisedPetData.UpdateDate = new DateTime(DateTime.Now.Ticks);
|
||||
raisedPetData.GrowthState = new RaisedPetGrowthState { Name = "BABY" };
|
||||
int imageSlot = (viking.Images.Select(i => i.ImageSlot).DefaultIfEmpty(-1).Max() + 1);
|
||||
raisedPetData.ImagePosition = imageSlot;
|
||||
// NOTE: Placing an egg into a hatchery slot calls CreatePet, but doesn't SetImage.
|
||||
// NOTE: We need to force create an image slot because hatching multiple eggs at once would create dragons with the same slot
|
||||
Image image = new Image {
|
||||
ImageType = "EggColor", // NOTE: The game doesn't seem to use anything other than EggColor.
|
||||
ImageSlot = imageSlot,
|
||||
Viking = viking,
|
||||
};
|
||||
// Save the dragon in the db
|
||||
Dragon dragon = new Dragon {
|
||||
EntityId = Guid.NewGuid(),
|
||||
Viking = viking,
|
||||
RaisedPetData = XmlUtil.SerializeXml(raisedPetData),
|
||||
};
|
||||
|
||||
ctx.Dragons.Add(dragon);
|
||||
ctx.Images.Add(image);
|
||||
|
||||
if (petTypeID != 2) {
|
||||
// Minisaurs should not be set as active pet
|
||||
viking.SelectedDragon = dragon;
|
||||
ctx.Update(viking);
|
||||
}
|
||||
ctx.SaveChanges();
|
||||
|
||||
return GetRaisedPetDataFromDragon(dragon);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Produces("application/xml")]
|
||||
[Route("V2/ContentWebService.asmx/CreatePet")]
|
||||
|
@ -116,7 +116,7 @@ public class ProfileController : Controller {
|
||||
avatarData.Id = viking.Id;
|
||||
}
|
||||
|
||||
if (avatarData != null && (apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013")) {
|
||||
if (avatarData != null && ClientVersion.Use2019SoDTutorial(apiKey)) {
|
||||
if (avatarData.Part.FirstOrDefault(e => e.PartType == "Sword") is null) {
|
||||
var extraParts = new AvatarDataPart[] {
|
||||
new AvatarDataPart {
|
||||
@ -139,7 +139,7 @@ public class ProfileController : Controller {
|
||||
ParentUserID = viking.UserId.ToString(),
|
||||
Username = viking.Name,
|
||||
FirstName = viking.Name,
|
||||
MultiplayerEnabled = (apiKey != "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" && apiKey != "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"),
|
||||
MultiplayerEnabled = !ClientVersion.IsOldSoD(apiKey),
|
||||
Locale = "en-US", // placeholder
|
||||
GenderID = Gender.Male, // placeholder
|
||||
OpenChatEnabled = true,
|
||||
|
@ -131,7 +131,7 @@ public class RegistrationController : Controller {
|
||||
ctx.Vikings.Add(v);
|
||||
ctx.SaveChanges();
|
||||
|
||||
if (apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013") {
|
||||
if (ClientVersion.Use2013SoDTutorial(apiKey)) {
|
||||
keyValueService.SetPairData(null, v, null, 2017, new Schema.PairData {
|
||||
Pairs = new Schema.Pair[]{
|
||||
new Schema.Pair {
|
||||
|
@ -1,5 +1,6 @@
|
||||
using sodoff.Model;
|
||||
using sodoff.Schema;
|
||||
using sodoff.Util;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -17,19 +18,23 @@ public class MissionService {
|
||||
}
|
||||
|
||||
public Mission GetMissionWithProgress(int missionId, int userId, string apiKey) {
|
||||
Mission mission;
|
||||
if (missionId == 999 && apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013") { // TODO This is not a pretty solution with hard-coded values.
|
||||
mission = missionStore.GetMission(10999);
|
||||
mission.MissionID = 999;
|
||||
} else if (missionId == 999 && apiKey == "a2a09a0a-7c6e-4e9b-b0f7-22034d799013") {
|
||||
mission = missionStore.GetMission(20999);
|
||||
mission.MissionID = 999;
|
||||
} else if (missionId == 999 && apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013") {
|
||||
Mission mission = null;
|
||||
|
||||
if (missionId == 999) { // TODO This is not a pretty solution with hard-coded values.
|
||||
if (ClientVersion.Use2013SoDTutorial(apiKey)) {
|
||||
mission = missionStore.GetMission(30999);
|
||||
} else if (ClientVersion.Use2016SoDTutorial(apiKey)) {
|
||||
mission = missionStore.GetMission(20999);
|
||||
} else if (ClientVersion.Use2019SoDTutorial(apiKey)) {
|
||||
mission = missionStore.GetMission(10999);
|
||||
}
|
||||
mission.MissionID = 999;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (mission is null) {
|
||||
mission = missionStore.GetMission(missionId);
|
||||
}
|
||||
|
||||
UpdateMissionRecursive(mission, userId);
|
||||
return mission;
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ public class MissionStoreSingleton {
|
||||
}
|
||||
|
||||
public int[] GetActiveMissions(string apiKey) {
|
||||
if (apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013") {
|
||||
if (ClientVersion.Use2013SoDTutorial(apiKey)) {
|
||||
return activeMissionsV1;
|
||||
}
|
||||
return activeMissions;
|
||||
}
|
||||
|
||||
public int[] GetUpcomingMissions(string apiKey) {
|
||||
if (apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013") {
|
||||
if (ClientVersion.Use2013SoDTutorial(apiKey)) {
|
||||
return upcomingMissionsV1;
|
||||
}
|
||||
return upcomingMissions;
|
||||
|
30
src/Util/ClientVersion.cs
Normal file
30
src/Util/ClientVersion.cs
Normal file
@ -0,0 +1,30 @@
|
||||
namespace sodoff.Util;
|
||||
public class ClientVersion {
|
||||
public static bool IsOldSoD(string apiKey) {
|
||||
return (
|
||||
apiKey == "a1a06a0a-7c6e-4e9b-b0f7-22034d799013" ||
|
||||
apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013" ||
|
||||
apiKey == "a2a09a0a-7c6e-4e9b-b0f7-22034d799013" ||
|
||||
apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"
|
||||
);
|
||||
}
|
||||
public static bool Use2013SoDTutorial(string apiKey) {
|
||||
return (
|
||||
apiKey == "a1a06a0a-7c6e-4e9b-b0f7-22034d799013" ||
|
||||
apiKey == "a1a13a0a-7c6e-4e9b-b0f7-22034d799013"
|
||||
);
|
||||
}
|
||||
public static bool Use2016SoDTutorial(string apiKey) {
|
||||
return (
|
||||
apiKey == "a2a09a0a-7c6e-4e9b-b0f7-22034d799013"
|
||||
);
|
||||
}
|
||||
public static bool Use2019SoDTutorial(string apiKey) {
|
||||
return (
|
||||
apiKey == "a3a12a0a-7c6e-4e9b-b0f7-22034d799013"
|
||||
);
|
||||
}
|
||||
public static bool Use2021SoDTutorial(string apiKey) {
|
||||
return !IsOldSoD(apiKey);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user