update dragon

This commit is contained in:
hictooth 2023-06-25 09:56:36 +01:00
parent 86b39923f6
commit ad2212f354
4 changed files with 67 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import mitmproxy.http
methods = [ methods = [
'GetRules', 'GetRules',
'LoginParent', 'LoginParent',
'AuthenticateUser',
'RegisterParent', 'RegisterParent',
'GetSubscriptionInfo', 'GetSubscriptionInfo',
'GetUserInfoByApiToken', 'GetUserInfoByApiToken',

View File

@ -5,6 +5,7 @@ using sodoff.Util;
namespace sodoff.Attributes; namespace sodoff.Attributes;
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class DecryptRequest : Attribute, IAsyncActionFilter { public class DecryptRequest : Attribute, IAsyncActionFilter {
const string key = "56BB211B-CF06-48E1-9C1D-E40B5173D759"; const string key = "56BB211B-CF06-48E1-9C1D-E40B5173D759";

View File

@ -64,6 +64,24 @@ public class AuthenticationController : Controller {
return Ok(response); return Ok(response);
} }
[HttpPost]
[Produces("application/xml")]
[Route("v3/AuthenticationWebService.asmx/AuthenticateUser")]
[DecryptRequest("username")]
[DecryptRequest("password")]
public bool AuthenticateUser() {
String username = Request.Form["username"];
String password = Request.Form["password"];
// Authenticate the user
User? user = ctx.Users.FirstOrDefault(e => e.Username == username);
if (user is null || new PasswordHasher<object>().VerifyHashedPassword(null, user.Password, password) != PasswordVerificationResult.Success) {
return false;
}
return true;
}
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("AuthenticationWebService.asmx/GetUserInfoByApiToken")] [Route("AuthenticationWebService.asmx/GetUserInfoByApiToken")]

View File

@ -271,6 +271,8 @@ public class ContentController : Controller {
ctx.Dragons.Add(dragon); ctx.Dragons.Add(dragon);
ctx.SaveChanges(); ctx.SaveChanges();
// TODO: handle CommonInventoryRequests here too
return Ok(new CreatePetResponse { return Ok(new CreatePetResponse {
RaisedPetData = GetRaisedPetDataFromDragon(dragon) RaisedPetData = GetRaisedPetDataFromDragon(dragon)
}); });
@ -296,10 +298,12 @@ public class ContentController : Controller {
}); });
} }
dragon.RaisedPetData = XmlUtil.SerializeXml(raisedPetRequest.RaisedPetData); dragon.RaisedPetData = XmlUtil.SerializeXml(UpdateDragon(dragon, raisedPetRequest.RaisedPetData));
ctx.Update(dragon); ctx.Update(dragon);
ctx.SaveChanges(); ctx.SaveChanges();
// TODO: handle CommonInventoryRequests here too
return Ok(new SetRaisedPetResponse { return Ok(new SetRaisedPetResponse {
RaisedPetSetResult = RaisedPetSetResult.Success RaisedPetSetResult = RaisedPetSetResult.Success
}); });
@ -508,6 +512,48 @@ public class ContentController : Controller {
return data; return data;
} }
// Needs to merge newDragonData into dragonData
private RaisedPetData UpdateDragon (Dragon dragon, RaisedPetData newDragonData) {
RaisedPetData dragonData = XmlUtil.DeserializeXml<RaisedPetData>(dragon.RaisedPetData);
// The simple attributes
dragonData.IsPetCreated = newDragonData.IsPetCreated;
if (newDragonData.ValidationMessage is not null) dragonData.ValidationMessage = newDragonData.ValidationMessage;
if (newDragonData.EntityID is not null) dragonData.EntityID = newDragonData.EntityID;
if (newDragonData.Name is not null) dragonData.Name = newDragonData.Name;
dragonData.PetTypeID = newDragonData.PetTypeID;
if (newDragonData.GrowthState is not null) dragonData.GrowthState = newDragonData.GrowthState;
if (newDragonData.ImagePosition is not null) dragonData.ImagePosition = newDragonData.ImagePosition;
if (newDragonData.Geometry is not null) dragonData.Geometry = newDragonData.Geometry;
if (newDragonData.Texture is not null) dragonData.Texture = newDragonData.Texture;
dragonData.Gender = newDragonData.Gender;
if (newDragonData.Accessories is not null) dragonData.Accessories = newDragonData.Accessories;
if (newDragonData.Colors is not null) dragonData.Colors = newDragonData.Colors;
if (newDragonData.Skills is not null) dragonData.Skills = newDragonData.Skills;
if (newDragonData.States is not null) dragonData.States = newDragonData.States;
dragonData.IsSelected = newDragonData.IsSelected;
dragonData.IsReleased = newDragonData.IsReleased;
dragonData.UpdateDate = newDragonData.UpdateDate;
// Attributes is special - the entire list isn't re-sent, so we need to manually update each
if (dragonData.Attributes is null) dragonData.Attributes = new RaisedPetAttribute[] { };
if (newDragonData.Attributes is not null) {
foreach (RaisedPetAttribute newAttribute in newDragonData.Attributes) {
RaisedPetAttribute? attribute = dragonData.Attributes.FirstOrDefault(a => a.Key == newAttribute.Key);
if (attribute is null) {
dragonData.Attributes.Append(newAttribute);
}
else {
attribute.Value = newAttribute.Value;
attribute.Type = newAttribute.Type;
}
}
}
return dragonData;
}
private ImageData? GetImageData (Viking viking, String ImageType, int ImageSlot) { private ImageData? GetImageData (Viking viking, String ImageType, int ImageSlot) {
Image? image = viking.Images.FirstOrDefault(e => e.ImageType == ImageType && e.ImageSlot == ImageSlot); Image? image = viking.Images.FirstOrDefault(e => e.ImageType == ImageType && e.ImageSlot == ImageSlot);
if (image is null) { if (image is null) {