1
0
mirror of synced 2025-01-18 14:24:02 +01:00

Add read stubs, implement card detail and avatar

This commit is contained in:
asesidaa 2023-02-13 01:46:08 +08:00
parent 805611027c
commit 14f171792e
34 changed files with 738 additions and 39 deletions

View File

@ -1,4 +1,5 @@
using System.Text;
using System.Linq.Expressions;
using System.Text;
using ChoETL;
using Throw;
@ -19,20 +20,24 @@ public static class XmlSerializationExtensions
public static string SerializeCardData<T>(this T source, string xpath) where T : class
{
var buffer = new StringBuilder();
using var writer = new ChoXmlWriter<T>(buffer).WithXPath(xpath).UseXmlSerialization();
writer.Configuration.OmitXmlDeclaration = false;
writer.Configuration.DoNotEmitXmlNamespace = true;
writer.Write(source);
using (var writer = new ChoXmlWriter<T>(buffer).WithXPath(xpath).UseXmlSerialization())
{
writer.Configuration.OmitXmlDeclaration = false;
writer.Configuration.DoNotEmitXmlNamespace = true;
writer.Write(source);
}
return buffer.ToString();
}
public static string SerializeCardDataList<T>(this IEnumerable<T> source, string xpath) where T : class
{
var buffer = new StringBuilder();
using var writer = new ChoXmlWriter<T>(buffer).WithXPath(xpath).UseXmlSerialization();
writer.Configuration.OmitXmlDeclaration = false;
writer.Configuration.DoNotEmitXmlNamespace = true;
writer.Write(source);
using (var writer = new ChoXmlWriter<T>(buffer).WithXPath(xpath).UseXmlSerialization())
{
writer.Configuration.OmitXmlDeclaration = false;
writer.Configuration.DoNotEmitXmlNamespace = true;
writer.Write(source);
}
return buffer.ToString();
}
}

View File

@ -0,0 +1,32 @@
using System.ComponentModel;
using System.Xml.Serialization;
namespace Application.Dto;
public class AvatarDto
{
[XmlAttribute(AttributeName = "id")]
public int Id { get; set; }
[XmlElement(ElementName = "card_id")]
public long CardId { get; set; }
[XmlElement(ElementName = "avatar_id")]
public int AvatarId { get; set; }
[XmlElement("created")]
[DefaultValue("")]
public string Created { get; set; } = string.Empty;
[XmlElement("modified")]
[DefaultValue("")]
public string Modified { get; set; } = string.Empty;
[XmlElement("new_flag")]
[DefaultValue(1)]
public int NewFlag { get; set; } = 1;
[XmlElement("use_flag")]
[DefaultValue(1)]
public int UseFlag { get; set; } = 1;
}

View File

@ -0,0 +1,67 @@
using System.ComponentModel;
using System.Xml.Serialization;
namespace Application.Dto;
public class CardDetailDto
{
[XmlAttribute(AttributeName = "id")]
public int Id { get; set; } = -1;
public bool ShouldSerializeId()
{
return Id != -1;
}
[XmlElement(ElementName = "card_id")]
public long CardId { get; set; }
[XmlElement(ElementName = "pcol1")]
public int Pcol1 { get; set; }
[XmlElement(ElementName = "pcol2")]
public int Pcol2 { get; set; }
[XmlElement(ElementName = "pcol3")]
public int Pcol3 { get; set; }
[XmlElement(ElementName = "score_i1")]
public long ScoreI1 { get; set; }
[XmlElement(ElementName = "score_ui1")]
public long ScoreUi1 { get; set; }
[XmlElement(ElementName = "score_ui2")]
public long ScoreUi2 { get; set; }
[XmlElement(ElementName = "score_ui3")]
public long ScoreUi3 { get; set; }
[XmlElement(ElementName = "score_ui4")]
public long ScoreUi4 { get; set; }
[XmlElement(ElementName = "score_ui5")]
public long ScoreUi5 { get; set; }
[XmlElement(ElementName = "score_ui6")]
public long ScoreUi6 { get; set; }
[XmlElement(ElementName = "score_bi1")]
public long ScoreBi1 { get; set; }
[XmlElement(ElementName = "last_play_tenpo_id")]
[DefaultValue("GC local server")]
public string LastPlayShopId { get; set; } = "GC local server";
[XmlElement("fcol1")]
public int Fcol1 { get; set; }
[XmlElement("fcol2")]
public int Fcol2 { get; set; }
[XmlElement("fcol3")]
public int Fcol3 { get; set; }
[XmlIgnore]
public DateTime LastPlayTime { get; set; } = DateTime.MinValue;
}

View File

@ -0,0 +1,30 @@
using System.Xml.Serialization;
namespace Application.Dto;
public class ItemDto
{
[XmlAttribute(AttributeName = "id")]
public int Id { get; set; }
[XmlElement(ElementName = "card_id")]
public long CardId { get; set; }
[XmlElement(ElementName = "item_id")]
public int ItemId { get; set; }
[XmlElement(ElementName = "item_num")]
public int ItemNum { get; set; } = 90;
[XmlElement("created")]
public string Created { get; set; } = "1";
[XmlElement("modified")]
public string Modified { get; set; } = "1";
[XmlElement("new_flag")]
public int NewFlag { get; set; }
[XmlElement("use_flag")]
public int UseFlag { get; set; } = 1;
}

View File

@ -0,0 +1,61 @@
using System.Diagnostics.CodeAnalysis;
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Application.Mappers;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Application.Game.Card.Read;
public record ReadAllCardDetailsQuery(long CardId) : IRequestWrapper<string>;
public class ReadAllCardDetailsQueryHandler : CardRequestHandlerBase<ReadAllCardDetailsQuery, string>
{
private const string CARD_DETAILS_XPATH = "/root/card_detail/record";
private const string EMPTY_XPATH = "/root/card_detail";
private readonly ILogger<ReadAllCardDetailsQueryHandler> logger;
public ReadAllCardDetailsQueryHandler(ICardDependencyAggregate aggregate, ILogger<ReadAllCardDetailsQueryHandler> logger) : base(aggregate)
{
this.logger = logger;
}
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records",
Justification = "Card details will return all records by design, which results in a large number of DB records")]
public override async Task<ServiceResult<string>> Handle(ReadAllCardDetailsQuery request, CancellationToken cancellationToken)
{
var exists = await CardDbContext.CardMains.AnyAsync(card => card.CardId == request.CardId, cancellationToken: cancellationToken);
if (!exists)
{
logger.LogWarning("Card id: {CardId} does not exist!", request.CardId);
return ServiceResult.Failed<string>(
new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered));
}
var cardDetails = await CardDbContext.CardDetails
.Where(detail => detail.CardId == request.CardId)
.ToListAsync(cancellationToken: cancellationToken);
string result;
if (cardDetails.Count == 0)
{
result = new object().SerializeCardData(EMPTY_XPATH);
}
else
{
var dtoList = cardDetails.Select((detail, i) =>
{
var dto = detail.CardDetailToDto();
dto.Id = i;
return dto;
});
result = dtoList.SerializeCardDataList(CARD_DETAILS_XPATH);
}
return new ServiceResult<string>(result);
}
}

View File

@ -0,0 +1,49 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Dto;
using Application.Interfaces;
using Domain.Config;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Application.Game.Card.Read;
public record ReadAvatarQuery(long CardId) : IRequestWrapper<string>;
public class ReadAvatarQueryHandler : CardRequestHandlerBase<ReadAvatarQuery, string>
{
private const string AVATAR_XPATH = "/root/avatar/record";
private readonly GameConfig config;
public ReadAvatarQueryHandler(ICardDependencyAggregate aggregate, IOptions<GameConfig> options) : base(aggregate)
{
config = options.Value;
}
public override Task<ServiceResult<string>> Handle(ReadAvatarQuery request, CancellationToken cancellationToken)
{
var count = config.AvatarCount;
var list = new List<AvatarDto>();
for (int i = 0; i < count; i++)
{
var avatar = new AvatarDto
{
Id = i,
CardId = request.CardId,
AvatarId = i,
Created = "2013-01-01",
Modified = "2013-01-01",
NewFlag = 0,
UseFlag = 1
};
list.Add(avatar);
}
var result = list.SerializeCardDataList(AVATAR_XPATH);
return Task.FromResult(new ServiceResult<string>(result));
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCardBDataQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadCardBDataQueryHandler : CardRequestHandlerBase<ReadCardBDataQuery, string>
{
public ReadCardBDataQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadCardBDataQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,50 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Dto;
using Application.Interfaces;
using Application.Mappers;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace Application.Game.Card.Read;
public record ReadCardDetailQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadCardDetailQueryHandler : CardRequestHandlerBase<ReadCardDetailQuery, string>
{
private const string CARD_DETAILS_XPATH = "/root/card_detail";
private readonly ILogger<ReadCardDetailQueryHandler> logger;
public ReadCardDetailQueryHandler(ICardDependencyAggregate aggregate, ILogger<ReadCardDetailQueryHandler> logger) : base(aggregate)
{
this.logger = logger;
}
public override async Task<ServiceResult<string>> Handle(ReadCardDetailQuery request, CancellationToken cancellationToken)
{
var exists = await CardDbContext.CardMains.AnyAsync(card => card.CardId == request.CardId, cancellationToken: cancellationToken);
if (!exists)
{
logger.LogWarning("Card id: {CardId} does not exist!", request.CardId);
return ServiceResult.Failed<string>(
new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered));
}
var queryCondition = request.Data.DeserializeCardData<CardDetailDto>();
var detail = await CardDbContext.CardDetails.FirstOrDefaultAsync(cardDetail =>
cardDetail.CardId == request.CardId &&
cardDetail.Pcol1 == queryCondition.Pcol1 &&
cardDetail.Pcol2 == queryCondition.Pcol2 &&
cardDetail.Pcol3 == queryCondition.Pcol3, cancellationToken: cancellationToken);
var dto = detail?.CardDetailToDto();
var result = dto?.SerializeCardData(CARD_DETAILS_XPATH) ??
new object().SerializeCardData(CARD_DETAILS_XPATH);
return new ServiceResult<string>(result);
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCoinQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadCoinQueryHandler : CardRequestHandlerBase<ReadCoinQuery, string>
{
public ReadCoinQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadCoinQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCondQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadCondQueryHandler : CardRequestHandlerBase<ReadCondQuery, string>
{
public ReadCondQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadCondQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadEventRewardQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadEventRewardQueryHandler : CardRequestHandlerBase<ReadEventRewardQuery, string>
{
public ReadEventRewardQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadEventRewardQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadGetMessageQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadGetMessageQueryHandler : CardRequestHandlerBase<ReadGetMessageQuery, string>
{
public ReadGetMessageQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadGetMessageQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,49 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Dto;
using Application.Interfaces;
using Domain.Config;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Application.Game.Card.Read;
public record ReadItemQuery(long CardId) : IRequestWrapper<string>;
public class ReadItemQueryHandler : CardRequestHandlerBase<ReadItemQuery, string>
{
private const string ITEM_XPATH = "/root/item/record";
private readonly GameConfig config;
public ReadItemQueryHandler(ICardDependencyAggregate aggregate, IOptions<GameConfig> options) : base(aggregate)
{
config = options.Value;
}
public override Task<ServiceResult<string>> Handle(ReadItemQuery request, CancellationToken cancellationToken)
{
var count = config.AvatarCount;
var list = new List<ItemDto>();
for (int i = 0; i < count; i++)
{
var avatar = new ItemDto()
{
Id = i,
CardId = request.CardId,
ItemId = i,
ItemNum = 90,
Created = "2013-01-01",
Modified = "2013-01-01",
NewFlag = 0,
UseFlag = 1
};
list.Add(avatar);
}
var result = list.SerializeCardDataList(ITEM_XPATH);
return Task.FromResult(new ServiceResult<string>(result));
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicAouQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadMusicAouQueryHandler : CardRequestHandlerBase<ReadMusicAouQuery, string>
{
public ReadMusicAouQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadMusicAouQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicExtraQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadMusicExtraQueryHandler : CardRequestHandlerBase<ReadMusicExtraQuery, string>
{
public ReadMusicExtraQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadMusicExtraQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadMusicQueryHandler : CardRequestHandlerBase<ReadMusicQuery, string>
{
public ReadMusicQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadMusicQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadNavigatorQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadNavigatorQueryHandler : CardRequestHandlerBase<ReadNavigatorQuery, string>
{
public ReadNavigatorQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadNavigatorQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadSkinQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadSkinQueryHandler : CardRequestHandlerBase<ReadSkinQuery, string>
{
public ReadSkinQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadSkinQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadSoundEffectQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadSoundEffectQueryHandler : CardRequestHandlerBase<ReadSoundEffectQuery, string>
{
public ReadSoundEffectQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadSoundEffectQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadTitleQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadTitleQueryHandler : CardRequestHandlerBase<ReadTitleQuery, string>
{
public ReadTitleQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadTitleQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadTotalTrophyQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadTotalTrophyQueryHandler : CardRequestHandlerBase<ReadTotalTrophyQuery, string>
{
public ReadTotalTrophyQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadTotalTrophyQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadUnlockKeynumQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadUnlockKeynumQueryHandler : CardRequestHandlerBase<ReadUnlockKeynumQuery, string>
{
public ReadUnlockKeynumQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadUnlockKeynumQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,22 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadUnlockRewardQuery(long CardId, string Data) : IRequestWrapper<string>;
public class ReadUnlockRewardQueryHandler : CardRequestHandlerBase<ReadUnlockRewardQuery, string>
{
public ReadUnlockRewardQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}
public override Task<ServiceResult<string>> Handle(ReadUnlockRewardQuery request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,11 @@
using Application.Dto;
using Domain.Entities;
using Riok.Mapperly.Abstractions;
namespace Application.Mappers;
[Mapper]
public static partial class CardDetailMapper
{
public static partial CardDetailDto CardDetailToDto(this CardDetail cardDetail);
}

View File

@ -11,15 +11,16 @@
<ItemGroup>
<PackageReference Include="CertificateManager" Version="1.0.8" />
<PackageReference Include="ChoETL" Version="1.2.1.47" />
<PackageReference Include="ChoETL" Version="1.2.1.48" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="Config.Net" Version="4.19.0" />
<PackageReference Include="Config.Net" Version="5.1.3" />
<PackageReference Include="Config.Net.Json" Version="4.19.0" />
<PackageReference Include="EmbedIO" Version="3.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0-preview.5.22301.12" />
<PackageReference Include="sqlite-net2" Version="2.1.0-preB" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.2" />
<PackageReference Include="System.Security.Cryptography.X509Certificates" Version="4.3.2" />
<PackageReference Include="Unosquare.Swan.Lite" Version="3.1.0" />
</ItemGroup>
<ItemGroup>

View File

@ -158,7 +158,7 @@ public static class Configs
};
public static readonly IAppSettings SETTINGS =
new ConfigurationBuilder<IAppSettings>().UseJsonFile(PathHelper.ConfigFilePath).Build();
new ConfigurationBuilder<IAppSettings>().UseJsonConfig(PathHelper.ConfigFilePath).Build();
public const int DEFAULT_AVATAR_COUNT = 323;
public const int DEFAULT_NAVIGATOR_COUNT = 94;

View File

@ -101,18 +101,14 @@ public class ServerController : WebApiController
for (var i = 0; i < count; i++)
{
var data = responseList[i];
var fileUrl = data.FileName;
if (Configs.SETTINGS.DownloadEvents)
{
fileUrl = data.FileName.StartsWith("/") ? $"{DataUrl}{data.FileName}" : $"{DataUrl}/{data.FileName}";
}
var fileUrl = data.FileName.StartsWith("/") ? $"{DataUrl}{data.FileName}" : $"{DataUrl}/{data.FileName}";
dataString.Append($"{i},{fileUrl},{data.NotBeforeUnixTime},{data.NotAfterUnixTime},{data.Md5},{data.Index}");
dataString.Append('\n');
}
return $"count={count}\n" +
"nexttime=1\n" +
dataString.ToString().TrimEnd('\n');
(Configs.SETTINGS.DownloadEvents ? dataString.ToString().TrimEnd('\n') : "");
}
[Route(HttpVerbs.Get, "/gameinfo.php")]

View File

@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="BinarySerializer" Version="8.6.3-alpha" />
<PackageReference Include="NetCoreServer" Version="6.2.0" />
<PackageReference Include="NetCoreServer" Version="6.6.0" />
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
</ItemGroup>

View File

@ -9,10 +9,10 @@ namespace Infrastructure.Common;
public class CertificateService
{
private const string ENHANCED_KEY_USAGE_OID = "2.5.29.37";
private const X509KeyUsageFlags ROOT_CA_X509_KEY_USAGE_FLAGS = X509KeyUsageFlags.KeyCertSign |
X509KeyUsageFlags.DataEncipherment |
X509KeyUsageFlags.KeyEncipherment |
X509KeyUsageFlags.DigitalSignature;
X509KeyUsageFlags.CrlSign;
private const X509KeyStorageFlags X509_KEY_STORAGE_FLAGS_MACHINE = X509KeyStorageFlags.PersistKeySet |
X509KeyStorageFlags.MachineKeySet |
@ -63,7 +63,7 @@ public class CertificateService
private static readonly ValidityPeriod VALIDITY_PERIOD = new()
{
ValidFrom = DateTime.UtcNow,
ValidTo = DateTime.UtcNow.AddYears(3)
ValidTo = DateTime.UtcNow.AddYears(1)
};
private static readonly OidCollection OID_COLLECTION = new()
@ -121,11 +121,13 @@ public class CertificateService
return existingCert;
}
logger.LogInformation("Existing CN not found! Removing old certificates and genrate new ones...");
logger.LogInformation("Existing certs not found or are not valid! " +
"Removing old certificates and genrate new ones...");
}
RemovePreviousCert(StoreName.My, StoreLocation.LocalMachine);
RemovePreviousCert(StoreName.Root, StoreLocation.LocalMachine);
RemovePreviousCert(StoreName.Root, StoreLocation.CurrentUser);
return GenerateCertificate();
}
@ -155,7 +157,7 @@ public class CertificateService
var cert = createCertificates.NewRsaChainedCertificate(
CERT_DISTINGUISHED_NAME,
CERT_BASIC_CONSTRAINTS,
new BasicConstraints(),
VALIDITY_PERIOD,
subjectAlternativeName,
rootCa,
@ -187,12 +189,15 @@ public class CertificateService
AddCertToStore(rootCaWithPrivateKey, StoreName.My, StoreLocation.LocalMachine);
AddCertToStore(rootCaWithPrivateKey, StoreName.Root, StoreLocation.LocalMachine);
AddCertToStore(certWithPrivateKey, StoreName.My, StoreLocation.LocalMachine);
AddCertToStore(certWithPrivateKey, StoreName.My, StoreLocation.CurrentUser);
logger.LogInformation("Added new certs to store!");
}
Directory.CreateDirectory(CERT_DIR);
File.WriteAllBytes(ROOT_CERT_PATH, rootCaWithPrivateKey.Export(X509ContentType.Pfx));
File.WriteAllBytes(CERT_PATH, certWithPrivateKey.Export(X509ContentType.Pfx));
logger.LogInformation("New certs saved!");
return certWithPrivateKey;
}
@ -219,7 +224,7 @@ public class CertificateService
{
var store = new X509Store(storeName, storeLocation);
store.Open(OpenFlags.ReadWrite);
var result = store.Certificates.Find(X509FindType.FindByIssuerName, ROOT_CA_CN, true);
var result = store.Certificates.Find(X509FindType.FindByIssuerName, ROOT_CA_CN, false);
if (result.Any())
{
@ -291,9 +296,16 @@ public class CertificateService
var cert = result.First();
var extensions = cert.Extensions;
if (extensions.Select(extension => extension.Oid).Any(oid => oid?.Value == OidLookup.ServerAuthentication.Value))
var enhancedUsage = extensions.FirstOrDefault(extension => ENHANCED_KEY_USAGE_OID.Equals(extension.Oid?.Value));
if (enhancedUsage is X509EnhancedKeyUsageExtension usages)
{
return cert;
foreach (var usage in usages.EnhancedKeyUsages)
{
if (OidLookup.ServerAuthentication.Value!.Equals(usage.Value))
{
return cert;
}
}
}
logger.LogInformation("Certificate CN={CommonName} does not include server authentication!", commonName);
return null;

View File

@ -41,12 +41,15 @@ public class CardController : BaseController<CardController>
result = await Mediator.Send(new ReadCardQuery(request.CardId));
break;
case CardRequestType.ReadCardDetail:
result = await Mediator.Send(new ReadCardDetailQuery(request.CardId, request.Data));
break;
case CardRequestType.ReadCardDetails:
result = await Mediator.Send(new ReadAllCardDetailsQuery(request.CardId));
break;
case CardRequestType.ReadCardBData:
break;
case CardRequestType.ReadAvatar:
result = await Mediator.Send(new ReadAvatarQuery(request.CardId));
break;
case CardRequestType.ReadItem:
break;
@ -138,7 +141,10 @@ public class CardController : BaseController<CardController>
if (result.Succeeded)
{
return Ok(result.Data);
var normalResult = "1\n" +
"1,1\n" +
$"{result.Data}";
return Ok(normalResult);
}
// Here error is not null since Succeeded => Error is null;

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>

View File

@ -32,10 +32,10 @@
<ItemGroup>
<PackageReference Include="GenFu" Version="1.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.6" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.0.11" />
<PackageReference Include="protobuf-net" Version="3.1.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.10" PrivateAssets="all" />
<PackageReference Include="MudBlazor" Version="6.0.17" />
<PackageReference Include="protobuf-net" Version="3.1.22" />
</ItemGroup>
<ItemGroup>

View File

@ -252,7 +252,7 @@ else
<Column T="SongPlayData" Field="@nameof(SongPlayData.LastPlayTime)" Title="Last Play Time"/>
</Columns>
<ChildRowContent>
@if (context.ShowDetails)
@if (context.Item.ShowDetails)
{
<MudTr>
<td colspan="5">
@ -263,7 +263,7 @@ else
</CardHeaderContent>
</MudCardHeader>
<MudCardContent Class="pa-0">
<MudTable Items="@context.SongPlaySubDataList"
<MudTable Items="@context.Item.SongPlaySubDataList"
Context="SongPlayDetail"
Elevation="0"
Filter="data => data.ClearState != ClearState.NotPlayed">

View File

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.1.17" />
<PackageReference Include="protobuf-net" Version="3.1.22" />
</ItemGroup>
</Project>