From 838f15fed868a076251a22ad2db8261d9044dcbd Mon Sep 17 00:00:00 2001 From: Alan Moon Date: Wed, 13 Dec 2023 16:10:25 -0800 Subject: [PATCH] add BirthDate, CreationDate and Gender -Set Gender For Player -Put CreationDate and BirthDate into Viking model -Birthday Events Now Work --- src/Controllers/Common/ProfileController.cs | 14 +++++++++----- src/Controllers/Common/RegistrationController.cs | 13 ++++++++++--- src/Model/Viking.cs | 5 +++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Controllers/Common/ProfileController.cs b/src/Controllers/Common/ProfileController.cs index ab192aa..58dd57f 100644 --- a/src/Controllers/Common/ProfileController.cs +++ b/src/Controllers/Common/ProfileController.cs @@ -83,12 +83,15 @@ public class ProfileController : Controller { private UserProfileData GetProfileDataFromViking(Viking viking, [FromForm] string apiKey) { // Get the avatar data AvatarData avatarData = null; - Gender gender = Gender.Male; + Gender? gender = null; if (viking.AvatarSerialized is not null) { avatarData = XmlUtil.DeserializeXml(viking.AvatarSerialized); avatarData.Id = viking.Id; - gender = avatarData.GenderType; + if (gender is null) + gender = avatarData.GenderType; } + if (gender is null) + gender = Gender.Unknown; if (avatarData != null && ClientVersion.GetVersion(apiKey) == 0xa3a12a0a) { // TODO adjust version number: we don't know for which versions it is required (for 3.12 it is, for 3.19 and 3.0 it's not) if (avatarData.Part.FirstOrDefault(e => e.PartType == "Sword") is null) { @@ -118,9 +121,10 @@ public class ProfileController : Controller { GenderID = gender, OpenChatEnabled = true, IsApproved = true, - RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder - CreationDate = new DateTime(DateTime.Now.Ticks), // placeholder - FacebookUserID = 0 + RegistrationDate = viking.CreationDate, + CreationDate = viking.CreationDate, + FacebookUserID = 0, + BirthDate = viking.BirthDate }, UserSubscriptionInfo = new UserSubscriptionInfo { UserID = viking.UserId.ToString(), diff --git a/src/Controllers/Common/RegistrationController.cs b/src/Controllers/Common/RegistrationController.cs index f0b99bf..ff715ca 100644 --- a/src/Controllers/Common/RegistrationController.cs +++ b/src/Controllers/Common/RegistrationController.cs @@ -71,7 +71,7 @@ public class RegistrationController : Controller { } if (ctx.Users.Count(e => e.Username== u.Username) > 0) { return Ok(new RegistrationResult { Status = MembershipUserStatus.DuplicateUserName }); - } + } ctx.Users.Add(u); @@ -82,7 +82,9 @@ public class RegistrationController : Controller { User = u, InventoryItems = new List(), AchievementPoints = new List(), - Rooms = new List() + Rooms = new List(), + CreationDate = DateTime.UtcNow, + BirthDate = data.ChildList[0].BirthDate }; ctx.Vikings.Add(v); } @@ -142,12 +144,17 @@ public class RegistrationController : Controller { User = user, InventoryItems = items, AchievementPoints = new List(), - Rooms = new List() + Rooms = new List(), + CreationDate = DateTime.Now, + BirthDate = data.BirthDate }; uint gameVersion = ClientVersion.GetVersion(apiKey); missionService.SetUpMissions(v, gameVersion); + if (data.Gender == "Boy") v.Gender = Gender.Male; + else if (data.Gender == "Girl") v.Gender = Gender.Female; + ctx.Vikings.Add(v); ctx.SaveChanges(); diff --git a/src/Model/Viking.cs b/src/Model/Viking.cs index 4659dbc..baeee88 100644 --- a/src/Model/Viking.cs +++ b/src/Model/Viking.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; +using sodoff.Schema; namespace sodoff.Model; @@ -37,4 +38,8 @@ public class Viking { public virtual ICollection SavedData { get; set; } = null!; public virtual ICollection Parties { get; set; } = null!; public virtual Dragon? SelectedDragon { get; set; } + + public DateTime? CreationDate { get; set; } + public DateTime? BirthDate { get; set; } + public Gender? Gender { get; set; } }