Add currently active client mods in ProfileActivityService (#523)
* Add currently active client mods in ProfileActivityService * Add method to fetch active client mods on profile
This commit is contained in:
@@ -6,6 +6,7 @@ using SPTarkov.Server.Core.Models.Eft.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Request;
|
||||
using SPTarkov.Server.Core.Models.Eft.Game;
|
||||
using SPTarkov.Server.Core.Servers;
|
||||
using SPTarkov.Server.Core.Services;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
namespace SPTarkov.Server.Core.Callbacks;
|
||||
@@ -16,6 +17,7 @@ public class GameCallbacks(
|
||||
Watermark watermark,
|
||||
SaveServer saveServer,
|
||||
GameController gameController,
|
||||
ProfileActivityService profileActivityService,
|
||||
TimeUtil timeUtil
|
||||
) : IOnLoad
|
||||
{
|
||||
@@ -173,4 +175,19 @@ public class GameCallbacks(
|
||||
{
|
||||
return new ValueTask<string>(httpResponseUtil.NullResponse());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle singleplayer/clientmods
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ValueTask<string> ReceiveClientMods(
|
||||
string url,
|
||||
SendClientModsRequest request,
|
||||
MongoId sessionID
|
||||
)
|
||||
{
|
||||
profileActivityService.SetProfileActiveClientMods(sessionID, request.ActiveClientMods);
|
||||
|
||||
return new ValueTask<string>(httpResponseUtil.NullResponse());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using SPTarkov.Server.Core.Models.Spt.Services;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
|
||||
namespace SPTarkov.Server.Core.Models.Eft.Game;
|
||||
|
||||
public record SendClientModsRequest : IRequestData
|
||||
{
|
||||
[JsonPropertyName("activeClientMods")]
|
||||
public List<ProfileActiveClientMods> ActiveClientMods { get; set; } = [];
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using SPTarkov.Server.Core.Models.Eft.Match;
|
||||
using SPTarkov.Server.Core.Models.Spt.Location;
|
||||
|
||||
@@ -8,6 +9,7 @@ namespace SPTarkov.Server.Core.Models.Spt.Services
|
||||
public long ClientStartedTimestamp { get; set; }
|
||||
public long LastActive { get; set; }
|
||||
public ProfileActivityRaidData? RaidData { get; set; } = null;
|
||||
public IReadOnlyList<ProfileActiveClientMods> ActiveClientMods { get; set; } = [];
|
||||
}
|
||||
|
||||
public class ProfileActivityRaidData
|
||||
@@ -16,4 +18,16 @@ namespace SPTarkov.Server.Core.Models.Spt.Services
|
||||
public RaidChanges? RaidAdjustments { get; set; } = null;
|
||||
public LocationTransit? LocationTransit { get; set; } = null;
|
||||
}
|
||||
|
||||
public record ProfileActiveClientMods
|
||||
{
|
||||
[JsonPropertyName("modName")]
|
||||
public required string Name { get; init; }
|
||||
|
||||
[JsonPropertyName("modGUID")]
|
||||
public required string GUID { get; init; }
|
||||
|
||||
[JsonPropertyName("modVersion")]
|
||||
public required Version Version { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,16 @@ public class GameStaticRouter : StaticRouter
|
||||
await gameCallbacks.SendSurveyOpinion(url, info as SendSurveyOpinionRequest, sessionID),
|
||||
typeof(SendSurveyOpinionRequest)
|
||||
),
|
||||
new RouteAction(
|
||||
"/singleplayer/clientmods",
|
||||
async (url, info, sessionID, output) =>
|
||||
await gameCallbacks.ReceiveClientMods(
|
||||
url,
|
||||
info as SendClientModsRequest,
|
||||
sessionID
|
||||
),
|
||||
typeof(SendClientModsRequest)
|
||||
),
|
||||
]
|
||||
) { }
|
||||
}
|
||||
|
||||
@@ -117,4 +117,32 @@ public class ProfileActivityService(TimeUtil timeUtil)
|
||||
currentActiveProfile.LastActive = timeUtil.GetTimeStamp();
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<ProfileActiveClientMods> GetProfileActiveClientMods(MongoId sessionId)
|
||||
{
|
||||
if (!ContainsActiveProfile(sessionId))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if (_activeProfiles.TryGetValue(sessionId, out var currentActiveProfile))
|
||||
{
|
||||
return currentActiveProfile.ActiveClientMods;
|
||||
}
|
||||
|
||||
throw new Exception($"Unable to retrieve active client mods for session: {sessionId}");
|
||||
}
|
||||
|
||||
public void SetProfileActiveClientMods(MongoId sessionId, IReadOnlyList<ProfileActiveClientMods> activeClientMods)
|
||||
{
|
||||
if (!ContainsActiveProfile(sessionId))
|
||||
{
|
||||
AddActiveProfile(sessionId, timeUtil.GetTimeStamp());
|
||||
}
|
||||
|
||||
if (_activeProfiles.TryGetValue(sessionId, out var currentActiveProfile))
|
||||
{
|
||||
currentActiveProfile.ActiveClientMods = activeClientMods;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user