Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement moving levels while decorating earth #697

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Refresh.GameServer/Database/GameDatabaseContext.Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -143,6 +144,17 @@ public GameLevel GetStoryLevelById(int id)
return level;
}

public GameLevel? UpdateLevelLocation(GameLevel level, GameLocation location)
{
this.Write(() =>
{
level.LocationX = location.X;
level.LocationY = location.Y;
});

return level;
}

public void DeleteLevel(GameLevel level)
{
this.Write(() =>
Expand Down
36 changes: 36 additions & 0 deletions Refresh.GameServer/Endpoints/Game/UserEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
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;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Lists;
using Refresh.GameServer.Types.Roles;
using Refresh.GameServer.Types.UserData;
Expand Down Expand Up @@ -123,6 +125,40 @@ public SerializedFriendsList GetFriends(RequestContext context, GameDatabaseCont
}
}
}

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)
{
// 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))
{
Expand Down
4 changes: 4 additions & 0 deletions Refresh.GameServer/Types/UserData/SerializedUpdateData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Xml.Serialization;
using Realms;
using Refresh.GameServer.Endpoints.Game.DataTypes.Request;

namespace Refresh.GameServer.Types.UserData;

Expand Down Expand Up @@ -32,4 +33,7 @@ public class SerializedUpdateData

[XmlElement("meh2")]
public string? MehFaceHash { get; set; }

[XmlArray("slots")]
public List<GameLevelRequest>? Levels { get; set; }
}
Loading