unify timestamps

This commit is contained in:
Spirtix 2023-07-27 19:06:19 +02:00
parent c0f7959e82
commit 9c3c374741
3 changed files with 164 additions and 164 deletions

View File

@ -155,7 +155,7 @@ public class ContentController : Controller {
ItemID = itemData.ItemID, ItemID = itemData.ItemID,
Quantity = item.Quantity, Quantity = item.Quantity,
Uses = itemData.Uses, Uses = itemData.Uses,
ModifiedDate = DateTime.Now, ModifiedDate = new DateTime(DateTime.Now.Ticks),
Item = itemData Item = itemData
}; };
userItemData.Add(uid); userItemData.Add(uid);

View File

@ -1,146 +1,146 @@
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using sodoff.Model; using sodoff.Model;
using sodoff.Schema; using sodoff.Schema;
using sodoff.Util; using sodoff.Util;
namespace sodoff.Controllers.Common; namespace sodoff.Controllers.Common;
public class ProfileController : Controller { public class ProfileController : Controller {
private readonly DBContext ctx; private readonly DBContext ctx;
public ProfileController(DBContext ctx) { public ProfileController(DBContext ctx) {
this.ctx = ctx; this.ctx = ctx;
} }
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ProfileWebService.asmx/GetUserProfileByUserID")] [Route("ProfileWebService.asmx/GetUserProfileByUserID")]
public IActionResult GetUserProfileByUserID([FromForm] string apiToken, [FromForm] string userId) { public IActionResult GetUserProfileByUserID([FromForm] string apiToken, [FromForm] string userId) {
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User; User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.User;
if (user is null) { if (user is null) {
// TODO: what response for not logged in? // TODO: what response for not logged in?
return Ok(); return Ok();
} }
Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId); Viking? viking = ctx.Vikings.FirstOrDefault(e => e.Id == userId);
return Ok(GetProfileDataFromViking(viking)); return Ok(GetProfileDataFromViking(viking));
} }
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ProfileWebService.asmx/GetUserProfile")] [Route("ProfileWebService.asmx/GetUserProfile")]
public IActionResult GetUserProfile([FromForm] string apiToken) { public IActionResult GetUserProfile([FromForm] string apiToken) {
Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking; Viking? viking = ctx.Sessions.FirstOrDefault(e => e.ApiToken == apiToken)?.Viking;
User? user = viking?.User; User? user = viking?.User;
if (user is null || viking is null) { if (user is null || viking is null) {
// TODO: what response for not logged in? // TODO: what response for not logged in?
return Ok(); return Ok();
} }
return Ok(GetProfileDataFromViking(viking)); return Ok(GetProfileDataFromViking(viking));
} }
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ProfileWebService.asmx/GetDetailedChildList")] [Route("ProfileWebService.asmx/GetDetailedChildList")]
public Schema.UserProfileDataList? GetDetailedChildList([FromForm] string parentApiToken) { public Schema.UserProfileDataList? GetDetailedChildList([FromForm] string parentApiToken) {
User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User; User? user = ctx.Sessions.FirstOrDefault(e => e.ApiToken == parentApiToken)?.User;
if (user is null) if (user is null)
// TODO: what response for not logged in? // TODO: what response for not logged in?
return null; return null;
if (user.Vikings.Count <= 0) if (user.Vikings.Count <= 0)
return null; return null;
UserProfileData[] profiles = user.Vikings.Select(GetProfileDataFromViking).ToArray(); UserProfileData[] profiles = user.Vikings.Select(GetProfileDataFromViking).ToArray();
return new UserProfileDataList { return new UserProfileDataList {
UserProfiles = profiles UserProfiles = profiles
}; };
} }
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("ProfileWebService.asmx/GetQuestions")] [Route("ProfileWebService.asmx/GetQuestions")]
public IActionResult GetQuestions([FromForm] string apiToken) { public IActionResult GetQuestions([FromForm] string apiToken) {
return Ok(new ProfileQuestionData { return Ok(new ProfileQuestionData {
Lists = new ProfileQuestionList[] { Lists = new ProfileQuestionList[] {
new ProfileQuestionList { new ProfileQuestionList {
ID = 4, ID = 4,
Questions = new ProfileQuestion[] { Questions = new ProfileQuestion[] {
new ProfileQuestion { new ProfileQuestion {
CategoryID = 3, CategoryID = 3,
IsActive = "true", // this is a string, which makes me sad IsActive = "true", // this is a string, which makes me sad
Locale = "en-US", Locale = "en-US",
Ordinal = 1, Ordinal = 1,
ID = 48, ID = 48,
DisplayText = "How Did You Hear About US ?", DisplayText = "How Did You Hear About US ?",
Answers = new ProfileAnswer[] { Answers = new ProfileAnswer[] {
new ProfileAnswer { new ProfileAnswer {
ID = 320, ID = 320,
DisplayText = "TV Commercial", DisplayText = "TV Commercial",
Locale = "en-US", Locale = "en-US",
Ordinal = 1, Ordinal = 1,
QuestionID = 48 QuestionID = 48
}, },
new ProfileAnswer { new ProfileAnswer {
ID = 324, ID = 324,
DisplayText = "I bought the RIders Of Berk DVD", DisplayText = "I bought the RIders Of Berk DVD",
Locale = "en-US", Locale = "en-US",
Ordinal = 5, Ordinal = 5,
QuestionID = 48 QuestionID = 48
}, },
new ProfileAnswer { new ProfileAnswer {
ID = 325, ID = 325,
DisplayText = "I bought the Defenders of Berk DVD", DisplayText = "I bought the Defenders of Berk DVD",
Locale = "en-US", Locale = "en-US",
Ordinal = 6, Ordinal = 6,
QuestionID = 48 QuestionID = 48
} }
} }
} }
} }
} }
} }
}); });
} }
private UserProfileData GetProfileDataFromViking(Viking viking) { private UserProfileData GetProfileDataFromViking(Viking viking) {
// Get the avatar data // Get the avatar data
AvatarData avatarData = null; AvatarData avatarData = null;
if (viking.AvatarSerialized is not null) { if (viking.AvatarSerialized is not null) {
avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized); avatarData = XmlUtil.DeserializeXml<AvatarData>(viking.AvatarSerialized);
} }
// Build the AvatarDisplayData // Build the AvatarDisplayData
AvatarDisplayData avatar = new AvatarDisplayData { AvatarDisplayData avatar = new AvatarDisplayData {
AvatarData = avatarData, AvatarData = avatarData,
UserInfo = new UserInfo { UserInfo = new UserInfo {
MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder MembershipID = "ef84db9-59c6-4950-b8ea-bbc1521f899b", // placeholder
UserID = viking.Id, UserID = viking.Id,
ParentUserID = viking.UserId, ParentUserID = viking.UserId,
Username = viking.Name, Username = viking.Name,
FirstName = viking.Name, FirstName = viking.Name,
MultiplayerEnabled = true, MultiplayerEnabled = true,
Locale = "en-US", // placeholder Locale = "en-US", // placeholder
GenderID = Gender.Male, // placeholder GenderID = Gender.Male, // placeholder
OpenChatEnabled = true, OpenChatEnabled = true,
IsApproved = true, IsApproved = true,
RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder RegistrationDate = new DateTime(DateTime.Now.Ticks), // placeholder
CreationDate = new DateTime(DateTime.Now.Ticks), // placeholder CreationDate = new DateTime(DateTime.Now.Ticks), // placeholder
FacebookUserID = 0 FacebookUserID = 0
}, },
UserSubscriptionInfo = new UserSubscriptionInfo { UserSubscriptionInfo = new UserSubscriptionInfo {
UserID = viking.UserId, UserID = viking.UserId,
MembershipID = 130687131, // placeholder MembershipID = 130687131, // placeholder
SubscriptionTypeID = 2, // placeholder SubscriptionTypeID = 2, // placeholder
SubscriptionDisplayName = "NonMember", // placeholder SubscriptionDisplayName = "NonMember", // placeholder
SubscriptionPlanID = 41, // placeholder SubscriptionPlanID = 41, // placeholder
SubscriptionID = -3, // placeholder SubscriptionID = -3, // placeholder
IsActive = false, // placeholder IsActive = false, // placeholder
}, },
RankID = 0, // placeholder RankID = 0, // placeholder
AchievementInfo = null, // placeholder AchievementInfo = null, // placeholder
Achievements = new UserAchievementInfo[] { Achievements = new UserAchievementInfo[] {
new UserAchievementInfo { new UserAchievementInfo {
UserID = Guid.Parse(viking.Id), UserID = Guid.Parse(viking.Id),
AchievementPointTotal = 5000, AchievementPointTotal = 5000,
@ -158,21 +158,21 @@ public class ProfileController : Controller {
AchievementPointTotal = 5000, AchievementPointTotal = 5000,
RankID = 30, RankID = 30,
PointTypeID = 10 PointTypeID = 10
}, },
} }
}; };
return new UserProfileData { return new UserProfileData {
ID = viking.Id, ID = viking.Id,
AvatarInfo = avatar, AvatarInfo = avatar,
AchievementCount = 0, AchievementCount = 0,
MythieCount = 0, MythieCount = 0,
AnswerData = new UserAnswerData { UserID = viking.Id }, AnswerData = new UserAnswerData { UserID = viking.Id },
GameCurrency = 1000, GameCurrency = 1000,
CashCurrency = 1000, CashCurrency = 1000,
ActivityCount = 0, ActivityCount = 0,
BuddyCount = 0, BuddyCount = 0,
UserGradeData = new UserGrade { UserGradeID = 0 } UserGradeData = new UserGrade { UserGradeID = 0 }
}; };
} }
} }

View File

@ -40,7 +40,7 @@ public class RoomService {
UserItemPositionID = roomItem.Id, UserItemPositionID = roomItem.Id,
ItemID = (int)itemRequest.Item.ItemID, ItemID = (int)itemRequest.Item.ItemID,
ItemStateID = defaultState.ItemStateID, ItemStateID = defaultState.ItemStateID,
StateChangeDate = DateTime.Now StateChangeDate = new DateTime(DateTime.Now.Ticks)
}; };
states.Add(userDefaultState); states.Add(userDefaultState);
itemRequest.UserItemState = userDefaultState; itemRequest.UserItemState = userDefaultState;
@ -140,7 +140,7 @@ public class RoomService {
} }
} }
DateTime stateChange = DateTime.Now; DateTime stateChange = new DateTime(DateTime.Now.Ticks);
if (nextStateID == -1) { if (nextStateID == -1) {
nextStateID = pos.UserItemState.ItemStateID; nextStateID = pos.UserItemState.ItemStateID;
stateChange = pos.UserItemState.StateChangeDate; stateChange = pos.UserItemState.StateChangeDate;
@ -182,7 +182,7 @@ public class RoomService {
ItemStateCriteriaExpiry? expiry = (ItemStateCriteriaExpiry?)currState.Rule.Criterias.Find(x => x.Type == ItemStateCriteriaType.StateExpiry); ItemStateCriteriaExpiry? expiry = (ItemStateCriteriaExpiry?)currState.Rule.Criterias.Find(x => x.Type == ItemStateCriteriaType.StateExpiry);
if (expiry != null) { if (expiry != null) {
DateTime start = pos.UserItemState.StateChangeDate; DateTime start = pos.UserItemState.StateChangeDate;
if (start.AddSeconds(expiry.Period) <= DateTime.Now) if (start.AddSeconds(expiry.Period) <= new DateTime(DateTime.Now.Ticks))
return expiry.EndStateID; return expiry.EndStateID;
} }