From 258fb6da8c361f528e29cfb97bf2e36e309cb489 Mon Sep 17 00:00:00 2001 From: Toaster Date: Tue, 3 Dec 2024 20:36:33 +0100 Subject: [PATCH 1/4] Implement moving levels with sticker/deco cursor --- .../Database/GameDatabaseContext.Levels.cs | 20 +++++++++++++++++++ .../Endpoints/Game/UserEndpoints.cs | 12 +++++++++++ .../Types/UserData/SerializedUpdateData.cs | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs index e74b7925..eb530343 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs @@ -5,9 +5,11 @@ using Refresh.Common.Constants; using Refresh.GameServer.Authentication; using Refresh.GameServer.Endpoints.ApiV3.DataTypes.Request; +using Refresh.GameServer.Endpoints.Game.DataTypes.Request; using Refresh.GameServer.Endpoints.Game.Levels.FilterSettings; using Refresh.GameServer.Extensions; using Refresh.GameServer.Services; +using Refresh.GameServer.Types; using Refresh.GameServer.Types.Activity; using Refresh.GameServer.Types.Assets; using Refresh.GameServer.Types.Levels; @@ -143,6 +145,24 @@ public GameLevel GetStoryLevelById(int id) return level; } + public GameLevel? UpdateLevelLocation(GameLevelRequest levelRequest, GameUser author) + { + // Verify if this level can be updated + GameLevel? Level = this.GetLevelById(levelRequest.LevelId); + if (Level == null) return null; + + Debug.Assert(Level.Publisher != null); + if (Level.Publisher.UserId != author.UserId) return null; + + this.Write(() => + { + Level.LocationX = levelRequest.Location.X; + Level.LocationY = levelRequest.Location.Y; + }); + + return Level; + } + public void DeleteLevel(GameLevel level) { this.Write(() => diff --git a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs index a24544b9..a3f09ad9 100644 --- a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs @@ -7,6 +7,7 @@ using Refresh.Common.Constants; using Refresh.GameServer.Authentication; using Refresh.GameServer.Database; +using Refresh.GameServer.Endpoints.Game.DataTypes.Request; using Refresh.GameServer.Endpoints.Game.DataTypes.Response; using Refresh.GameServer.Services; using Refresh.GameServer.Types.Data; @@ -63,6 +64,8 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont public string? UpdateUser(RequestContext context, GameDatabaseContext database, GameUser user, string body, IDataStore dataStore, Token token, GuidCheckerService guidChecker) { SerializedUpdateData? data = null; + + context.Logger.LogInfo(BunkumCategory.UserContent, body); // This stupid shit is caused by LBP sending two different root elements for this endpoint // LBP is just fantastic man @@ -123,6 +126,15 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont } } } + + if(data.Levels != null) + { + // since you can only update level's locations through this endpoint, update their locations + foreach(GameLevelRequest Level in data.Levels) + { + database.UpdateLevelLocation(Level, user); + } + } if (data.PlanetsHash != null && !dataStore.ExistsInStore(data.PlanetsHash)) { diff --git a/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs b/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs index 386d997f..df84efc9 100644 --- a/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs +++ b/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs @@ -1,5 +1,7 @@ using System.Xml.Serialization; using Realms; +using Refresh.GameServer.Endpoints.Game.DataTypes.Request; +using Refresh.GameServer.Types.Levels; namespace Refresh.GameServer.Types.UserData; @@ -32,4 +34,7 @@ public class SerializedUpdateData [XmlElement("meh2")] public string? MehFaceHash { get; set; } + + [XmlArray("slots")] + public List? Levels { get; set; } } \ No newline at end of file From 7c79928df419d9434fa53f01373ff6d309e812b8 Mon Sep 17 00:00:00 2001 From: Toaster Date: Wed, 4 Dec 2024 21:30:25 +0100 Subject: [PATCH 2/4] Remove debugging --- Refresh.GameServer/Endpoints/Game/UserEndpoints.cs | 2 -- Refresh.GameServer/Types/UserData/SerializedUpdateData.cs | 1 - 2 files changed, 3 deletions(-) diff --git a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs index a3f09ad9..de8e011a 100644 --- a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs @@ -64,8 +64,6 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont public string? UpdateUser(RequestContext context, GameDatabaseContext database, GameUser user, string body, IDataStore dataStore, Token token, GuidCheckerService guidChecker) { SerializedUpdateData? data = null; - - context.Logger.LogInfo(BunkumCategory.UserContent, body); // This stupid shit is caused by LBP sending two different root elements for this endpoint // LBP is just fantastic man diff --git a/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs b/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs index df84efc9..74ab3f93 100644 --- a/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs +++ b/Refresh.GameServer/Types/UserData/SerializedUpdateData.cs @@ -1,7 +1,6 @@ using System.Xml.Serialization; using Realms; using Refresh.GameServer.Endpoints.Game.DataTypes.Request; -using Refresh.GameServer.Types.Levels; namespace Refresh.GameServer.Types.UserData; From ed76e9e218be1d863e00d6824a9c042e2c66b2ba Mon Sep 17 00:00:00 2001 From: Toaster Date: Fri, 6 Dec 2024 22:57:08 +0100 Subject: [PATCH 3/4] Move verification code from database to endpoint method, Add some error handling --- .../Database/GameDatabaseContext.Levels.cs | 16 +++------- .../Endpoints/Game/UserEndpoints.cs | 32 +++++++++++++++++-- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs index eb530343..11fd6ae2 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Levels.cs @@ -5,7 +5,6 @@ using Refresh.Common.Constants; using Refresh.GameServer.Authentication; using Refresh.GameServer.Endpoints.ApiV3.DataTypes.Request; -using Refresh.GameServer.Endpoints.Game.DataTypes.Request; using Refresh.GameServer.Endpoints.Game.Levels.FilterSettings; using Refresh.GameServer.Extensions; using Refresh.GameServer.Services; @@ -145,22 +144,15 @@ public GameLevel GetStoryLevelById(int id) return level; } - public GameLevel? UpdateLevelLocation(GameLevelRequest levelRequest, GameUser author) + public GameLevel? UpdateLevelLocation(GameLevel level, GameLocation location) { - // Verify if this level can be updated - GameLevel? Level = this.GetLevelById(levelRequest.LevelId); - if (Level == null) return null; - - Debug.Assert(Level.Publisher != null); - if (Level.Publisher.UserId != author.UserId) return null; - this.Write(() => { - Level.LocationX = levelRequest.Location.X; - Level.LocationY = levelRequest.Location.Y; + level.LocationX = location.X; + level.LocationY = location.Y; }); - return Level; + return level; } public void DeleteLevel(GameLevel level) diff --git a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs index de8e011a..7dfb5fa6 100644 --- a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs @@ -11,6 +11,7 @@ using Refresh.GameServer.Endpoints.Game.DataTypes.Response; using Refresh.GameServer.Services; using Refresh.GameServer.Types.Data; +using Refresh.GameServer.Types.Levels; using Refresh.GameServer.Types.Lists; using Refresh.GameServer.Types.Roles; using Refresh.GameServer.Types.UserData; @@ -127,11 +128,36 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont if(data.Levels != null) { - // since you can only update level's locations through this endpoint, update their locations - foreach(GameLevelRequest Level in data.Levels) + int failedLevelUpdates = 0; + + // Since you can only update level's locations through this endpoint, update their locations + foreach(GameLevelRequest LevelRequest in data.Levels) { - database.UpdateLevelLocation(Level, user); + // Incase there is no location data provided for this level for some reason + if(LevelRequest.Location == null) + { + failedLevelUpdates++; + continue; + } + + // Verify if this level can be updated + GameLevel? Level = database.GetLevelById(LevelRequest.LevelId); + if (Level == null) + { + failedLevelUpdates++; + continue; + } + + if (Level.Publisher == null || Level.Publisher.UserId != user.UserId) + { + failedLevelUpdates++; + continue; + } + + database.UpdateLevelLocation(Level, LevelRequest.Location); } + + if(failedLevelUpdates > 0) database.AddErrorNotification("Level update failed", $"Failed to update {failedLevelUpdates} out of {data.Levels.Count} level locations.", user); } if (data.PlanetsHash != null && !dataStore.ExistsInStore(data.PlanetsHash)) From 6cf526c84ac4e9f7261007a361199f167411b4fe Mon Sep 17 00:00:00 2001 From: Toaster Date: Fri, 6 Dec 2024 23:02:39 +0100 Subject: [PATCH 4/4] Fix minor inconsistencies in my code style --- Refresh.GameServer/Endpoints/Game/UserEndpoints.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs index 7dfb5fa6..9581d5ca 100644 --- a/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/UserEndpoints.cs @@ -126,15 +126,15 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont } } - if(data.Levels != null) + if (data.Levels != null) { int failedLevelUpdates = 0; // Since you can only update level's locations through this endpoint, update their locations - foreach(GameLevelRequest LevelRequest in data.Levels) + foreach (GameLevelRequest LevelRequest in data.Levels) { // Incase there is no location data provided for this level for some reason - if(LevelRequest.Location == null) + if (LevelRequest.Location == null) { failedLevelUpdates++; continue; @@ -157,7 +157,7 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont database.UpdateLevelLocation(Level, LevelRequest.Location); } - if(failedLevelUpdates > 0) database.AddErrorNotification("Level update failed", $"Failed to update {failedLevelUpdates} out of {data.Levels.Count} level locations.", user); + if (failedLevelUpdates > 0) database.AddErrorNotification("Level update failed", $"Failed to update {failedLevelUpdates} out of {data.Levels.Count} level locations.", user); } if (data.PlanetsHash != null && !dataStore.ExistsInStore(data.PlanetsHash))