mirror of
https://gitea.tendokyu.moe/Kayori/Medusa.net.git
synced 2026-10-11 16:58:08 +03:00
Extracted shared card lookup logic into CardInquireLookup, used by both Inquire and GnInquire handlers. Removed old unused GnInquire handler. Made User.Pin settable instead of init-only.
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Abstractions.Entities
|
||||
public class User: IdentityUser<int>
|
||||
{
|
||||
public int PaseliAmount { get; set; } = 0;
|
||||
public string Pin { get; init; } = "0000";
|
||||
public string Pin { get; set; } = "0000";
|
||||
|
||||
public List<Card> Cards { get; init; } = null!;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class AuthPassCardManegementHandler(ICardService cardService) : Handler<A
|
||||
status = 116;
|
||||
}
|
||||
|
||||
if (card!.User.Pin != req.Password)
|
||||
if (card?.User.Pin != req.Password)
|
||||
{
|
||||
status = 116;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using Abstractions;
|
||||
using Abstractions.Entities;
|
||||
using Abstractions.Services;
|
||||
using Server.Services;
|
||||
|
||||
namespace Server.Handlers.Common.Card;
|
||||
|
||||
/// <summary>
|
||||
/// Result of resolving a card for an `inquire`/`gninquire`-style request.
|
||||
/// When <see cref="ErrorStatus"/> is set, the other fields are unpopulated and the
|
||||
/// caller should return an early-out response carrying that status.
|
||||
/// </summary>
|
||||
internal sealed record CardInquireLookup(
|
||||
int? ErrorStatus,
|
||||
string KonamiId,
|
||||
Abstractions.Entities.Card? ExistingCard,
|
||||
IMedusaPlugin? Plugin,
|
||||
bool ProfileExists)
|
||||
{
|
||||
/// <summary>
|
||||
/// Shared validation/lookup chain used by both InquireCardManagementHandler and
|
||||
/// GnInquireCardManagementHandler: resolves the plugin for the model's game code,
|
||||
/// converts the card UID to a Konami ID, and checks whether a profile exists for it.
|
||||
/// </summary>
|
||||
public static async Task<CardInquireLookup> ResolveAsync(string? cardId, string model,
|
||||
IPluginService pluginService, ICardService cardService)
|
||||
{
|
||||
var gameCode = model.Split(':')[0];
|
||||
var plugin = pluginService.FindPlugin(gameCode);
|
||||
|
||||
if (string.IsNullOrEmpty(cardId))
|
||||
{
|
||||
return new CardInquireLookup(111, "", null, null, false);
|
||||
}
|
||||
|
||||
var konamiId = cardService.ConvertUidToKonamiId(cardId);
|
||||
|
||||
if (string.IsNullOrEmpty(konamiId))
|
||||
{
|
||||
return new CardInquireLookup(111, "", null, null, false);
|
||||
}
|
||||
|
||||
var existingCard = await cardService.FindByKonamiId(konamiId);
|
||||
|
||||
if (existingCard is null)
|
||||
{
|
||||
return new CardInquireLookup(112, konamiId, null, null, false);
|
||||
}
|
||||
|
||||
if (plugin is null)
|
||||
{
|
||||
return new CardInquireLookup(113, konamiId, existingCard, null, false);
|
||||
}
|
||||
|
||||
var profileExists = await pluginService.DoesProfileExistAsync(plugin, cardId);
|
||||
|
||||
return new CardInquireLookup(null, konamiId, existingCard, plugin, profileExists);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Abstractions.Handlers;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Server.Handlers.Common.Card;
|
||||
|
||||
public class GnInquire : HandlerWithoutRequest<XDocument>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Module("cardmng");
|
||||
Method("gninquire");
|
||||
}
|
||||
|
||||
public override XDocument Handle(string model) {
|
||||
var response = new XDocument(
|
||||
new XElement("response",
|
||||
new XElement("status", "0"),
|
||||
new XElement("data",
|
||||
new XElement("inquire",
|
||||
new XElement("card",
|
||||
new XElement("cardid", "1234567890123456"),
|
||||
new XElement("konamiid", "KONAMI123456"),
|
||||
new XElement("profileexists", "1")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -16,64 +16,29 @@ namespace Server.Handlers.Common.Card
|
||||
|
||||
public override async Task<GnInquireResponse> HandleAsync(InquireRequest req, string model)
|
||||
{
|
||||
var splitModel = model.Split(':');
|
||||
var gameCode = splitModel[0];
|
||||
var lookup = await CardInquireLookup.ResolveAsync(req.CardId, model, pluginService, cardService);
|
||||
|
||||
var plugin = pluginService.FindPlugin(gameCode);
|
||||
|
||||
var cardId = req.CardId;
|
||||
|
||||
var inquireResponse = new GnInquireResponse()
|
||||
if (lookup.ErrorStatus is { } errorStatus)
|
||||
{
|
||||
Status = 0
|
||||
return new GnInquireResponse { Status = errorStatus };
|
||||
}
|
||||
|
||||
var flag = lookup.ProfileExists ? "1" : "0";
|
||||
var newFlag = lookup.ProfileExists ? "0" : "1";
|
||||
|
||||
return new GnInquireResponse
|
||||
{
|
||||
Status = 0,
|
||||
Binded = 0,
|
||||
DataId = lookup.KonamiId,
|
||||
EcFlag = 1,
|
||||
Expired = 0,
|
||||
NewFlag = newFlag,
|
||||
IsGeniune = flag,
|
||||
ExtidFlag = flag,
|
||||
RefId = lookup.KonamiId,
|
||||
UserIdFlag = flag
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(cardId))
|
||||
{
|
||||
inquireResponse.Status = 111;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var konamiId = cardService.ConvertUidToKonamiId(cardId);
|
||||
|
||||
if (string.IsNullOrEmpty(konamiId))
|
||||
{
|
||||
inquireResponse.Status = 111;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var exisitngCard = await cardService.FindByKonamiId(konamiId);
|
||||
|
||||
if (exisitngCard == null)
|
||||
{
|
||||
inquireResponse.Status = 112;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
if (plugin is null)
|
||||
{
|
||||
inquireResponse.Status = 113;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var profileExists = await pluginService.DoesProfileExistAsync(plugin, cardId);
|
||||
|
||||
var userIdFlag = profileExists ? "1" : "0";
|
||||
var extIdFlag = profileExists ? "1" : "0";
|
||||
var newFlag = profileExists ? "0" : "1";
|
||||
var isGeniune = profileExists ? "1" : "0";
|
||||
|
||||
inquireResponse.Binded = 0;
|
||||
inquireResponse.DataId = konamiId;
|
||||
inquireResponse.EcFlag = 1;
|
||||
inquireResponse.Expired = 0;
|
||||
inquireResponse.NewFlag = newFlag;
|
||||
inquireResponse.IsGeniune = isGeniune;
|
||||
inquireResponse.ExtidFlag = extIdFlag;
|
||||
inquireResponse.RefId = konamiId;
|
||||
inquireResponse.UserIdFlag = userIdFlag;
|
||||
|
||||
return inquireResponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,62 +16,28 @@ public class InquireCardManagementHandler(IPluginService pluginService, ICardSer
|
||||
|
||||
public override async Task<InquireResponse> HandleAsync(InquireRequest req, string model)
|
||||
{
|
||||
var splitModel = model.Split(':');
|
||||
var gameCode = splitModel[0];
|
||||
|
||||
var plugin = pluginService.FindPlugin(gameCode);
|
||||
var lookup = await CardInquireLookup.ResolveAsync(req.CardId, model, pluginService, cardService);
|
||||
|
||||
var cardId = req.CardId;
|
||||
|
||||
var inquireResponse = new InquireResponse()
|
||||
if (lookup.ErrorStatus is { } errorStatus)
|
||||
{
|
||||
Status = 0
|
||||
return new InquireResponse { Status = errorStatus };
|
||||
}
|
||||
|
||||
var flag = lookup.ProfileExists ? "1" : "0";
|
||||
var newFlag = lookup.ProfileExists ? "0" : "1";
|
||||
|
||||
return new InquireResponse
|
||||
{
|
||||
Status = 0,
|
||||
Binded = 0,
|
||||
DataId = lookup.KonamiId,
|
||||
EcFlag = 1,
|
||||
Expired = 0,
|
||||
NewFlag = newFlag,
|
||||
ExtidFlag = flag,
|
||||
RefId = lookup.ExistingCard!.Id.ToString().PadLeft(16, '0'),
|
||||
UserIdFlag = flag,
|
||||
Pcode = lookup.KonamiId
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(cardId))
|
||||
{
|
||||
inquireResponse.Status = 111;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var konamiId = cardService.ConvertUidToKonamiId(cardId);
|
||||
|
||||
if(string.IsNullOrEmpty(konamiId))
|
||||
{
|
||||
inquireResponse.Status = 111;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var exisitngCard = await cardService.FindByKonamiId(konamiId);
|
||||
|
||||
if (exisitngCard == null)
|
||||
{
|
||||
inquireResponse.Status = 112;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
if (plugin is null)
|
||||
{
|
||||
inquireResponse.Status = 113;
|
||||
return inquireResponse;
|
||||
}
|
||||
|
||||
var profileExists = await pluginService.DoesProfileExistAsync(plugin, cardId);
|
||||
|
||||
var userIdFlag = profileExists ? "1" : "0";
|
||||
var extIdFlag = profileExists ? "1" : "0";
|
||||
var newFlag = profileExists ? "0" : "1";
|
||||
|
||||
inquireResponse.Binded = 0;
|
||||
inquireResponse.DataId = konamiId;
|
||||
inquireResponse.EcFlag = 1;
|
||||
inquireResponse.Expired = 0;
|
||||
inquireResponse.NewFlag = newFlag;
|
||||
inquireResponse.ExtidFlag = extIdFlag;
|
||||
inquireResponse.RefId = exisitngCard.Id.ToString().PadLeft(16, '0');
|
||||
inquireResponse.UserIdFlag = userIdFlag;
|
||||
inquireResponse.Pcode = konamiId;
|
||||
|
||||
return inquireResponse;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user