From 14f171792e80aaade699f3b48c4d5c6df25342d7 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Mon, 13 Feb 2023 01:46:08 +0800 Subject: [PATCH] Add read stubs, implement card detail and avatar --- .../Extensions/XmlSerializationExtensions.cs | 25 ++++--- Application/Dto/AvatarDto.cs | 32 +++++++++ Application/Dto/CardDetailDto.cs | 67 +++++++++++++++++++ Application/Dto/ItemDto.cs | 30 +++++++++ .../Game/Card/Read/ReadAllCardDetailsQuery.cs | 61 +++++++++++++++++ Application/Game/Card/Read/ReadAvatarQuery.cs | 49 ++++++++++++++ .../Game/Card/Read/ReadCardBDataQuery.cs | 22 ++++++ .../Game/Card/Read/ReadCardDetailQuery.cs | 50 ++++++++++++++ Application/Game/Card/Read/ReadCoinQuery.cs | 22 ++++++ Application/Game/Card/Read/ReadCondQuery.cs | 22 ++++++ .../Game/Card/Read/ReadEventRewardQuery.cs | 22 ++++++ .../Game/Card/Read/ReadGetMessageQuery.cs | 22 ++++++ Application/Game/Card/Read/ReadItemQuery.cs | 49 ++++++++++++++ .../Game/Card/Read/ReadMusicAouQuery.cs | 22 ++++++ .../Game/Card/Read/ReadMusicExtraQuery.cs | 22 ++++++ Application/Game/Card/Read/ReadMusicQuery.cs | 22 ++++++ .../Game/Card/Read/ReadNavigatorQuery.cs | 22 ++++++ Application/Game/Card/Read/ReadSkinQuery.cs | 22 ++++++ .../Game/Card/Read/ReadSoundEffectQuery.cs | 22 ++++++ Application/Game/Card/Read/ReadTitleQuery.cs | 22 ++++++ .../Game/Card/Read/ReadTotalTrophyQuery.cs | 22 ++++++ .../Game/Card/Read/ReadUnlockKeynumQuery.cs | 22 ++++++ .../Game/Card/Read/ReadUnlockRewardQuery.cs | 22 ++++++ Application/Mappers/CardDetailMapper.cs | 11 +++ .../GC-local-server-rewrite.csproj | 7 +- GC-local-server-rewrite/common/Configs.cs | 2 +- .../controllers/ServerController.cs | 8 +-- GCRelayServer/GCRelayServer.csproj | 2 +- Infrastructure/Common/CertificateService.cs | 30 ++++++--- MainServer/Controllers/Game/CardController.cs | 8 ++- MatchServer/MatchServer.csproj | 2 +- MudAdmin/MudAdmin.csproj | 8 +-- MudAdmin/Pages/User.razor | 4 +- SharedProject/SharedProject.csproj | 2 +- 34 files changed, 738 insertions(+), 39 deletions(-) create mode 100644 Application/Dto/AvatarDto.cs create mode 100644 Application/Dto/CardDetailDto.cs create mode 100644 Application/Dto/ItemDto.cs create mode 100644 Application/Game/Card/Read/ReadAllCardDetailsQuery.cs create mode 100644 Application/Game/Card/Read/ReadAvatarQuery.cs create mode 100644 Application/Game/Card/Read/ReadCardBDataQuery.cs create mode 100644 Application/Game/Card/Read/ReadCardDetailQuery.cs create mode 100644 Application/Game/Card/Read/ReadCoinQuery.cs create mode 100644 Application/Game/Card/Read/ReadCondQuery.cs create mode 100644 Application/Game/Card/Read/ReadEventRewardQuery.cs create mode 100644 Application/Game/Card/Read/ReadGetMessageQuery.cs create mode 100644 Application/Game/Card/Read/ReadItemQuery.cs create mode 100644 Application/Game/Card/Read/ReadMusicAouQuery.cs create mode 100644 Application/Game/Card/Read/ReadMusicExtraQuery.cs create mode 100644 Application/Game/Card/Read/ReadMusicQuery.cs create mode 100644 Application/Game/Card/Read/ReadNavigatorQuery.cs create mode 100644 Application/Game/Card/Read/ReadSkinQuery.cs create mode 100644 Application/Game/Card/Read/ReadSoundEffectQuery.cs create mode 100644 Application/Game/Card/Read/ReadTitleQuery.cs create mode 100644 Application/Game/Card/Read/ReadTotalTrophyQuery.cs create mode 100644 Application/Game/Card/Read/ReadUnlockKeynumQuery.cs create mode 100644 Application/Game/Card/Read/ReadUnlockRewardQuery.cs create mode 100644 Application/Mappers/CardDetailMapper.cs diff --git a/Application/Common/Extensions/XmlSerializationExtensions.cs b/Application/Common/Extensions/XmlSerializationExtensions.cs index ae5240a..7a39b30 100644 --- a/Application/Common/Extensions/XmlSerializationExtensions.cs +++ b/Application/Common/Extensions/XmlSerializationExtensions.cs @@ -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(this T source, string xpath) where T : class { var buffer = new StringBuilder(); - using var writer = new ChoXmlWriter(buffer).WithXPath(xpath).UseXmlSerialization(); - writer.Configuration.OmitXmlDeclaration = false; - writer.Configuration.DoNotEmitXmlNamespace = true; - writer.Write(source); + using (var writer = new ChoXmlWriter(buffer).WithXPath(xpath).UseXmlSerialization()) + { + writer.Configuration.OmitXmlDeclaration = false; + writer.Configuration.DoNotEmitXmlNamespace = true; + writer.Write(source); + } return buffer.ToString(); } - public static string SerializeCardDataList(this IEnumerable source, string xpath) where T : class { var buffer = new StringBuilder(); - using var writer = new ChoXmlWriter(buffer).WithXPath(xpath).UseXmlSerialization(); - writer.Configuration.OmitXmlDeclaration = false; - writer.Configuration.DoNotEmitXmlNamespace = true; - writer.Write(source); + using (var writer = new ChoXmlWriter(buffer).WithXPath(xpath).UseXmlSerialization()) + { + writer.Configuration.OmitXmlDeclaration = false; + writer.Configuration.DoNotEmitXmlNamespace = true; + writer.Write(source); + } + return buffer.ToString(); } } \ No newline at end of file diff --git a/Application/Dto/AvatarDto.cs b/Application/Dto/AvatarDto.cs new file mode 100644 index 0000000..edad571 --- /dev/null +++ b/Application/Dto/AvatarDto.cs @@ -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; +} \ No newline at end of file diff --git a/Application/Dto/CardDetailDto.cs b/Application/Dto/CardDetailDto.cs new file mode 100644 index 0000000..63d6bd7 --- /dev/null +++ b/Application/Dto/CardDetailDto.cs @@ -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; +} \ No newline at end of file diff --git a/Application/Dto/ItemDto.cs b/Application/Dto/ItemDto.cs new file mode 100644 index 0000000..e67f6fb --- /dev/null +++ b/Application/Dto/ItemDto.cs @@ -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; +} \ No newline at end of file diff --git a/Application/Game/Card/Read/ReadAllCardDetailsQuery.cs b/Application/Game/Card/Read/ReadAllCardDetailsQuery.cs new file mode 100644 index 0000000..5af4e68 --- /dev/null +++ b/Application/Game/Card/Read/ReadAllCardDetailsQuery.cs @@ -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; + +public class ReadAllCardDetailsQueryHandler : CardRequestHandlerBase +{ + private const string CARD_DETAILS_XPATH = "/root/card_detail/record"; + private const string EMPTY_XPATH = "/root/card_detail"; + + private readonly ILogger logger; + + public ReadAllCardDetailsQueryHandler(ICardDependencyAggregate aggregate, ILogger 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> 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( + 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(result); + } +} diff --git a/Application/Game/Card/Read/ReadAvatarQuery.cs b/Application/Game/Card/Read/ReadAvatarQuery.cs new file mode 100644 index 0000000..27381e3 --- /dev/null +++ b/Application/Game/Card/Read/ReadAvatarQuery.cs @@ -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; + +public class ReadAvatarQueryHandler : CardRequestHandlerBase +{ + private const string AVATAR_XPATH = "/root/avatar/record"; + + private readonly GameConfig config; + + public ReadAvatarQueryHandler(ICardDependencyAggregate aggregate, IOptions options) : base(aggregate) + { + config = options.Value; + } + + public override Task> Handle(ReadAvatarQuery request, CancellationToken cancellationToken) + { + var count = config.AvatarCount; + var list = new List(); + 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(result)); + } +} diff --git a/Application/Game/Card/Read/ReadCardBDataQuery.cs b/Application/Game/Card/Read/ReadCardBDataQuery.cs new file mode 100644 index 0000000..0b21202 --- /dev/null +++ b/Application/Game/Card/Read/ReadCardBDataQuery.cs @@ -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; + +public class ReadCardBDataQueryHandler : CardRequestHandlerBase +{ + public ReadCardBDataQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadCardBDataQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadCardDetailQuery.cs b/Application/Game/Card/Read/ReadCardDetailQuery.cs new file mode 100644 index 0000000..31aafe8 --- /dev/null +++ b/Application/Game/Card/Read/ReadCardDetailQuery.cs @@ -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; + +public class ReadCardDetailQueryHandler : CardRequestHandlerBase +{ + private const string CARD_DETAILS_XPATH = "/root/card_detail"; + + private readonly ILogger logger; + + public ReadCardDetailQueryHandler(ICardDependencyAggregate aggregate, ILogger logger) : base(aggregate) + { + this.logger = logger; + } + + public override async Task> 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( + new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered)); + } + + var queryCondition = request.Data.DeserializeCardData(); + 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(result); + } +} diff --git a/Application/Game/Card/Read/ReadCoinQuery.cs b/Application/Game/Card/Read/ReadCoinQuery.cs new file mode 100644 index 0000000..12895ff --- /dev/null +++ b/Application/Game/Card/Read/ReadCoinQuery.cs @@ -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; + +public class ReadCoinQueryHandler : CardRequestHandlerBase +{ + public ReadCoinQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadCoinQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadCondQuery.cs b/Application/Game/Card/Read/ReadCondQuery.cs new file mode 100644 index 0000000..55b7294 --- /dev/null +++ b/Application/Game/Card/Read/ReadCondQuery.cs @@ -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; + +public class ReadCondQueryHandler : CardRequestHandlerBase +{ + public ReadCondQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadCondQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadEventRewardQuery.cs b/Application/Game/Card/Read/ReadEventRewardQuery.cs new file mode 100644 index 0000000..894dd26 --- /dev/null +++ b/Application/Game/Card/Read/ReadEventRewardQuery.cs @@ -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; + +public class ReadEventRewardQueryHandler : CardRequestHandlerBase +{ + public ReadEventRewardQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadEventRewardQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadGetMessageQuery.cs b/Application/Game/Card/Read/ReadGetMessageQuery.cs new file mode 100644 index 0000000..598231d --- /dev/null +++ b/Application/Game/Card/Read/ReadGetMessageQuery.cs @@ -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; + +public class ReadGetMessageQueryHandler : CardRequestHandlerBase +{ + public ReadGetMessageQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadGetMessageQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadItemQuery.cs b/Application/Game/Card/Read/ReadItemQuery.cs new file mode 100644 index 0000000..33a6b06 --- /dev/null +++ b/Application/Game/Card/Read/ReadItemQuery.cs @@ -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; + +public class ReadItemQueryHandler : CardRequestHandlerBase +{ + private const string ITEM_XPATH = "/root/item/record"; + + private readonly GameConfig config; + + public ReadItemQueryHandler(ICardDependencyAggregate aggregate, IOptions options) : base(aggregate) + { + config = options.Value; + } + + public override Task> Handle(ReadItemQuery request, CancellationToken cancellationToken) + { + var count = config.AvatarCount; + var list = new List(); + 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(result)); + } +} \ No newline at end of file diff --git a/Application/Game/Card/Read/ReadMusicAouQuery.cs b/Application/Game/Card/Read/ReadMusicAouQuery.cs new file mode 100644 index 0000000..942f0f5 --- /dev/null +++ b/Application/Game/Card/Read/ReadMusicAouQuery.cs @@ -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; + +public class ReadMusicAouQueryHandler : CardRequestHandlerBase +{ + public ReadMusicAouQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadMusicAouQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadMusicExtraQuery.cs b/Application/Game/Card/Read/ReadMusicExtraQuery.cs new file mode 100644 index 0000000..08bebd8 --- /dev/null +++ b/Application/Game/Card/Read/ReadMusicExtraQuery.cs @@ -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; + +public class ReadMusicExtraQueryHandler : CardRequestHandlerBase +{ + public ReadMusicExtraQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadMusicExtraQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadMusicQuery.cs b/Application/Game/Card/Read/ReadMusicQuery.cs new file mode 100644 index 0000000..e0aa78b --- /dev/null +++ b/Application/Game/Card/Read/ReadMusicQuery.cs @@ -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; + +public class ReadMusicQueryHandler : CardRequestHandlerBase +{ + public ReadMusicQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadMusicQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadNavigatorQuery.cs b/Application/Game/Card/Read/ReadNavigatorQuery.cs new file mode 100644 index 0000000..d46a980 --- /dev/null +++ b/Application/Game/Card/Read/ReadNavigatorQuery.cs @@ -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; + +public class ReadNavigatorQueryHandler : CardRequestHandlerBase +{ + public ReadNavigatorQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadNavigatorQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadSkinQuery.cs b/Application/Game/Card/Read/ReadSkinQuery.cs new file mode 100644 index 0000000..e9341a7 --- /dev/null +++ b/Application/Game/Card/Read/ReadSkinQuery.cs @@ -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; + +public class ReadSkinQueryHandler : CardRequestHandlerBase +{ + public ReadSkinQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadSkinQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadSoundEffectQuery.cs b/Application/Game/Card/Read/ReadSoundEffectQuery.cs new file mode 100644 index 0000000..aa32bb3 --- /dev/null +++ b/Application/Game/Card/Read/ReadSoundEffectQuery.cs @@ -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; + +public class ReadSoundEffectQueryHandler : CardRequestHandlerBase +{ + public ReadSoundEffectQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadSoundEffectQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadTitleQuery.cs b/Application/Game/Card/Read/ReadTitleQuery.cs new file mode 100644 index 0000000..a754385 --- /dev/null +++ b/Application/Game/Card/Read/ReadTitleQuery.cs @@ -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; + +public class ReadTitleQueryHandler : CardRequestHandlerBase +{ + public ReadTitleQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadTitleQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadTotalTrophyQuery.cs b/Application/Game/Card/Read/ReadTotalTrophyQuery.cs new file mode 100644 index 0000000..f7f0439 --- /dev/null +++ b/Application/Game/Card/Read/ReadTotalTrophyQuery.cs @@ -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; + +public class ReadTotalTrophyQueryHandler : CardRequestHandlerBase +{ + public ReadTotalTrophyQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadTotalTrophyQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadUnlockKeynumQuery.cs b/Application/Game/Card/Read/ReadUnlockKeynumQuery.cs new file mode 100644 index 0000000..7120437 --- /dev/null +++ b/Application/Game/Card/Read/ReadUnlockKeynumQuery.cs @@ -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; + +public class ReadUnlockKeynumQueryHandler : CardRequestHandlerBase +{ + public ReadUnlockKeynumQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadUnlockKeynumQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Game/Card/Read/ReadUnlockRewardQuery.cs b/Application/Game/Card/Read/ReadUnlockRewardQuery.cs new file mode 100644 index 0000000..acee326 --- /dev/null +++ b/Application/Game/Card/Read/ReadUnlockRewardQuery.cs @@ -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; + +public class ReadUnlockRewardQueryHandler : CardRequestHandlerBase +{ + public ReadUnlockRewardQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate) + { + } + + public override Task> Handle(ReadUnlockRewardQuery request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/Application/Mappers/CardDetailMapper.cs b/Application/Mappers/CardDetailMapper.cs new file mode 100644 index 0000000..94c9f5a --- /dev/null +++ b/Application/Mappers/CardDetailMapper.cs @@ -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); +} \ No newline at end of file diff --git a/GC-local-server-rewrite/GC-local-server-rewrite.csproj b/GC-local-server-rewrite/GC-local-server-rewrite.csproj index 0644ae7..1ba03de 100644 --- a/GC-local-server-rewrite/GC-local-server-rewrite.csproj +++ b/GC-local-server-rewrite/GC-local-server-rewrite.csproj @@ -11,15 +11,16 @@ - + - + - + + diff --git a/GC-local-server-rewrite/common/Configs.cs b/GC-local-server-rewrite/common/Configs.cs index b8bd31e..25c93c3 100644 --- a/GC-local-server-rewrite/common/Configs.cs +++ b/GC-local-server-rewrite/common/Configs.cs @@ -158,7 +158,7 @@ public static class Configs }; public static readonly IAppSettings SETTINGS = - new ConfigurationBuilder().UseJsonFile(PathHelper.ConfigFilePath).Build(); + new ConfigurationBuilder().UseJsonConfig(PathHelper.ConfigFilePath).Build(); public const int DEFAULT_AVATAR_COUNT = 323; public const int DEFAULT_NAVIGATOR_COUNT = 94; diff --git a/GC-local-server-rewrite/controllers/ServerController.cs b/GC-local-server-rewrite/controllers/ServerController.cs index dd56c16..c7e629e 100644 --- a/GC-local-server-rewrite/controllers/ServerController.cs +++ b/GC-local-server-rewrite/controllers/ServerController.cs @@ -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")] diff --git a/GCRelayServer/GCRelayServer.csproj b/GCRelayServer/GCRelayServer.csproj index 0fe1f1c..cff841b 100644 --- a/GCRelayServer/GCRelayServer.csproj +++ b/GCRelayServer/GCRelayServer.csproj @@ -9,7 +9,7 @@ - + diff --git a/Infrastructure/Common/CertificateService.cs b/Infrastructure/Common/CertificateService.cs index 55244a3..6494c09 100644 --- a/Infrastructure/Common/CertificateService.cs +++ b/Infrastructure/Common/CertificateService.cs @@ -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; diff --git a/MainServer/Controllers/Game/CardController.cs b/MainServer/Controllers/Game/CardController.cs index b87ddf4..0373da0 100644 --- a/MainServer/Controllers/Game/CardController.cs +++ b/MainServer/Controllers/Game/CardController.cs @@ -41,12 +41,15 @@ public class CardController : BaseController 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 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; diff --git a/MatchServer/MatchServer.csproj b/MatchServer/MatchServer.csproj index a40166b..38c35c9 100644 --- a/MatchServer/MatchServer.csproj +++ b/MatchServer/MatchServer.csproj @@ -7,7 +7,7 @@ - + diff --git a/MudAdmin/MudAdmin.csproj b/MudAdmin/MudAdmin.csproj index 7d287c2..7a96b13 100644 --- a/MudAdmin/MudAdmin.csproj +++ b/MudAdmin/MudAdmin.csproj @@ -32,10 +32,10 @@ - - - - + + + + diff --git a/MudAdmin/Pages/User.razor b/MudAdmin/Pages/User.razor index b87ba8e..b2882b6 100644 --- a/MudAdmin/Pages/User.razor +++ b/MudAdmin/Pages/User.razor @@ -252,7 +252,7 @@ else - @if (context.ShowDetails) + @if (context.Item.ShowDetails) { @@ -263,7 +263,7 @@ else - diff --git a/SharedProject/SharedProject.csproj b/SharedProject/SharedProject.csproj index df65cef..9a702e8 100644 --- a/SharedProject/SharedProject.csproj +++ b/SharedProject/SharedProject.csproj @@ -8,7 +8,7 @@ - +