begin working on sim room

This commit is contained in:
Mikhail Tyukin
2025-06-14 15:20:19 -04:00
parent ffbb5c792c
commit 0133f7f55b
7 changed files with 83 additions and 4 deletions

View File

@@ -82,6 +82,12 @@ namespace EpinelPS.Database
/// </summary>
public long AvailableAt;
}
public class SimroomData
{
public int CurrentDifficulty;
public int CurrentChapter;
public bool Entered = false;
}
public class ResetableData
{
public int WipeoutCount = 0;
@@ -89,6 +95,7 @@ namespace EpinelPS.Database
public int InterceptionTickets = 3;
public List<int> CompletedDailyMissions = [];
public int DailyMissionPoints;
public SimroomData SimRoomData = new();
}
public class WeeklyResetableData
{

View File

@@ -7,7 +7,7 @@ namespace EpinelPS.LobbyServer.Event
{
protected override async Task HandleAsync()
{
var req = await ReadData<ResChallengeEventStageData>();
var req = await ReadData<ReqChallengeEventStageData>();
var user = GetUser();
var response = new ResChallengeEventStageData();

View File

@@ -0,0 +1,26 @@
using EpinelPS.Utils;
namespace EpinelPS.LobbyServer.Event.Minigame.CE002
{
[PacketPath("/event/minigame/ce002/get")]
public class GetCe002Data : LobbyMsgHandler
{
protected override async Task HandleAsync()
{
var req = await ReadData<ReqGetMiniGameCe002Data>();
var user = GetUser();
var response = new ResGetMiniGameCe002Data
{
Data = new()
{
Ce002Id = req.Ce002Id
}
};
// TODO implement properly
await WriteDataAsync(response);
}
}
}

View File

@@ -100,9 +100,10 @@ namespace EpinelPS.LobbyServer
{
var encryptionToken = new PasetoBuilder().Use(ProtocolVersion.V4, Purpose.Local)
.WithKey(JsonDb.Instance.LauncherTokenKey, Encryption.SymmetricKey)
.Decode(token, new PasetoTokenValidationParameters() { ValidateLifetime = true });
.Decode(token, new PasetoTokenValidationParameters() { ValidateLifetime = true }) ?? throw new Exception("failed to decrypt");
var elem = (encryptionToken.Paseto.Payload["data"] as System.Text.Json.JsonElement?) ?? throw new Exception("expected data field in auth token");
var p = ((System.Text.Json.JsonElement)encryptionToken.Paseto.Payload["data"]).GetString() ?? throw new Exception("auth token cannot be null");
var p = elem.GetString() ?? throw new Exception("auth token cannot be null");
return JsonConvert.DeserializeObject<GameClientInfo>(p ?? throw new Exception("data cannot be null"));
}

View File

@@ -9,6 +9,7 @@ namespace EpinelPS.LobbyServer.Simroom
protected override async Task HandleAsync()
{
var req = await ReadData<ReqGetSimRoom>();
var user = GetUser();
var response = new ResGetSimRoom
{
@@ -55,6 +56,14 @@ namespace EpinelPS.LobbyServer.Simroom
NextLegacyBuffResetDate = Timestamp.FromDateTimeOffset(DateTime.UtcNow.AddDays(7))
};
if (user.ResetableData.SimRoomData.Entered)
{
response.Status = SimRoomStatus.Progress;
response.CurrentDifficulty = user.ResetableData.SimRoomData.CurrentDifficulty;
}
await WriteDataAsync(response);
}
}

View File

@@ -0,0 +1,26 @@
using EpinelPS.Utils;
using EpinelPS.Database;
namespace EpinelPS.LobbyServer.Simroom
{
[PacketPath("/simroom/quit")]
public class Quit : LobbyMsgHandler
{
protected override async Task HandleAsync()
{
var req = await ReadData<ReqQuitSimRoom>();
var user = GetUser();
ResQuitSimRoom response = new()
{
Result = SimRoomResult.SimRoomResultSuccess,
};
user.ResetableData.SimRoomData.Entered = false;
JsonDb.Save();
await WriteDataAsync(response);
}
}
}

View File

@@ -1,4 +1,5 @@
using EpinelPS.Utils;
using EpinelPS.Database;
namespace EpinelPS.LobbyServer.Simroom
{
@@ -8,12 +9,21 @@ namespace EpinelPS.LobbyServer.Simroom
protected override async Task HandleAsync()
{
var req = await ReadData<ReqSelectSimRoomDifficulty>();
var user = GetUser();
ResSelectSimRoomDifficulty response = new ResSelectSimRoomDifficulty
ResSelectSimRoomDifficulty response = new()
{
Result = SimRoomResult.SimRoomResultSuccess,
};
user.ResetableData.SimRoomData.Entered = true;
user.ResetableData.SimRoomData.CurrentDifficulty = req.Difficulty;
user.ResetableData.SimRoomData.CurrentChapter = req.StartingChapter;
// TODO: generate buffs
JsonDb.Save();
await WriteDataAsync(response);
}
}