forked from PGR/ascnet
1
0
Fork 0

sussy 2.9 changes, and finally shard unlock implementation

This commit is contained in:
rfi 2023-12-02 14:28:19 +07:00
parent 228dacb901
commit e69b8541af
11 changed files with 223 additions and 21 deletions

View File

@ -58,4 +58,14 @@ namespace AscNet.Common
} }
} }
} }
public class ServerCodeException : Exception
{
public int Code { get; set; }
public ServerCodeException(string message, int code)
: base(message)
{
Code = code;
}
}
} }

View File

@ -7,6 +7,7 @@ using AscNet.Common.MsgPack;
using AscNet.Common.Util; using AscNet.Common.Util;
using Newtonsoft.Json; using Newtonsoft.Json;
using AscNet.Table.V2.share.equip; using AscNet.Table.V2.share.equip;
using AscNet.Table.V2.share.character.quality;
namespace AscNet.Common.Database namespace AscNet.Common.Database
{ {
@ -53,23 +54,36 @@ namespace AscNet.Common.Database
return character; return character;
} }
public void AddCharacter(uint id) /// <summary>
/// Don't forget to send Equip, Fashion, and the Character notify after using this!
/// </summary>
/// <param name="id"></param>
/// <exception cref="ServerCodeException"></exception>
public AddCharacterRet AddCharacter(uint id)
{ {
AddCharacterRet ret = new();
CharacterTable? character = CharacterTableReader.Instance.FromId((int)id); CharacterTable? character = CharacterTableReader.Instance.FromId((int)id);
CharacterSkillTable? characterSkill = CharacterSkillTableReader.Instance.FromCharacterId((int)id); CharacterSkillTable? characterSkill = CharacterSkillTableReader.Instance.FromCharacterId((int)id);
CharacterQualityTable? characterQuality = TableReaderV2.Parse<CharacterQualityTable>().OrderBy(x => x.Quality).FirstOrDefault(x => x.CharacterId == id);
if (character is null || characterSkill is null) if (character is null || characterSkill is null || characterQuality is null)
throw new ArgumentException("Invalid character id!", nameof(id)); {
// CharacterManagerGetCharacterDataNotFound
throw new ServerCodeException("Invalid character id!", 20009021);
}
if (Characters.FirstOrDefault(x => x.Id == character.Id) is not null) if (Characters.FirstOrDefault(x => x.Id == character.Id) is not null)
throw new ArgumentException("Character already obtained!", nameof(id)); {
// CharacterManagerCreateCharacterAlreadyExist
throw new ServerCodeException("Character already obtained!", 20009022);
}
NotifyCharacterDataList.NotifyCharacterDataListCharacterData characterData = new() NotifyCharacterDataList.NotifyCharacterDataListCharacterData characterData = new()
{ {
Id = (uint)character.Id, Id = (uint)character.Id,
Level = 1, Level = 1,
Exp = 0, Exp = 0,
Quality = 1, Quality = characterQuality.Quality,
InitQuality = 1, InitQuality = characterQuality.Quality,
Star = 0, Star = 0,
Grade = 1, Grade = 1,
FashionId = (uint)character.DefaultNpcFashtionId, FashionId = (uint)character.DefaultNpcFashtionId,
@ -89,15 +103,19 @@ namespace AscNet.Common.Database
Id = uint.Parse(x.ToString().Take(6).ToArray()), Id = uint.Parse(x.ToString().Take(6).ToArray()),
Level = 1 Level = 1
})); }));
Fashions.Add(new() FashionList fashion = new()
{ {
Id = character.DefaultNpcFashtionId, Id = character.DefaultNpcFashtionId,
IsLock = false IsLock = false
}); };
Fashions.Add(fashion);
ret.Fashion = fashion;
if (character.EquipId > 0) if (character.EquipId > 0)
AddEquip((uint)character.EquipId, character.Id); ret.Equip = AddEquip((uint)character.EquipId, character.Id);
Characters.Add(characterData); Characters.Add(characterData);
ret.Character = characterData;
return ret;
} }
public NotifyCharacterDataList.NotifyCharacterDataListCharacterData? AddCharacterExp(int characterId, int exp, int maxLvl = 0) public NotifyCharacterDataList.NotifyCharacterDataListCharacterData? AddCharacterExp(int characterId, int exp, int maxLvl = 0)
@ -167,7 +185,7 @@ namespace AscNet.Common.Database
}; };
} }
public void AddEquip(uint equipId, int characterId = 0) public NotifyEquipDataList.NotifyEquipDataListEquipData AddEquip(uint equipId, int characterId = 0)
{ {
NotifyEquipDataList.NotifyEquipDataListEquipData equipData = new() NotifyEquipDataList.NotifyEquipDataListEquipData equipData = new()
{ {
@ -186,6 +204,7 @@ namespace AscNet.Common.Database
}; };
Equips.Add(equipData); Equips.Add(equipData);
return equipData;
} }
public NotifyEquipDataList.NotifyEquipDataListEquipData? AddEquipExp(int equipId, int exp) public NotifyEquipDataList.NotifyEquipDataListEquipData? AddEquipExp(int equipId, int exp)
@ -282,4 +301,11 @@ namespace AscNet.Common.Database
[JsonProperty("TemplateId")] [JsonProperty("TemplateId")]
public int TemplateId { get; set; } public int TemplateId { get; set; }
} }
public struct AddCharacterRet
{
public NotifyCharacterDataList.NotifyCharacterDataListCharacterData Character { get; set; }
public NotifyEquipDataList.NotifyEquipDataListEquipData Equip { get; set; }
public FashionList Fashion { get; set; }
}
} }

View File

@ -32,7 +32,7 @@ namespace AscNet.Common.MsgPack
public String ServerBean { get; set; } public String ServerBean { get; set; }
public Int32 LoginPlatform { get; set; } public Int32 LoginPlatform { get; set; }
public String ClientVersion { get; set; } public String ClientVersion { get; set; }
public Int32 UserId { get; set; } public dynamic UserId { get; set; }
} }
@ -2360,6 +2360,13 @@ namespace AscNet.Common.MsgPack
} }
[global::MessagePack.MessagePackObject(true)]
public class EnterChallengeResponse
{
public Int32 Code { get; set; }
}
[global::MessagePack.MessagePackObject(true)] [global::MessagePack.MessagePackObject(true)]
public class TeamSetTeamResponse public class TeamSetTeamResponse
{ {

View File

@ -22,11 +22,85 @@ namespace AscNet.GameServer.Handlers
{ {
public int Code; public int Code;
} }
[MessagePackObject(true)]
public class CharacterExchangeRequest
{
public int TemplateId;
}
[MessagePackObject(true)]
public class CharacterExchangeResponse
{
public int Code;
}
[MessagePackObject(true)]
public class FashionSyncNotify
{
public List<FashionList> FashionList = new();
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion #endregion
internal class CharacterModule internal class CharacterModule
{ {
[RequestPacketHandler("CharacterExchangeRequest")]
public static void CharacterExchangeRequestHandler(Session session, Packet.Request packet)
{
CharacterExchangeRequest request = packet.Deserialize<CharacterExchangeRequest>();
CharacterTable? characterData = TableReaderV2.Parse<CharacterTable>().FirstOrDefault(x => x.Id == request.TemplateId);
if (characterData is null)
{
CharacterExchangeResponse rsp = new()
{
// CharacterManagerGetCharacterTemplateNotFound
Code = 20009001
};
session.SendResponse(rsp, packet.Id);
return;
}
if (!session.inventory.Items.Any(x => x.Id == characterData.ItemId && x.Count >= 50))
{
CharacterExchangeResponse rsp = new()
{
// ItemCountNotEnough
Code = 20012004
};
session.SendResponse(rsp, packet.Id);
return;
}
NotifyItemDataList notifyItemData = new();
// idk if it's always 50, please investigate later...
notifyItemData.ItemDataList.Add(session.inventory.Do(characterData.ItemId, 50 * -1));
session.SendPush(notifyItemData);
try
{
NotifyEquipDataList notifyEquipData = new();
FashionSyncNotify fashionSync = new();
NotifyCharacterDataList notifyCharacterData = new();
var addRet = session.character.AddCharacter((uint)request.TemplateId);
notifyEquipData.EquipDataList.Add(addRet.Equip);
fashionSync.FashionList.Add(addRet.Fashion);
notifyCharacterData.CharacterDataList.Add(addRet.Character);
session.SendPush(notifyEquipData);
session.SendPush(notifyCharacterData);
}
catch (ServerCodeException ex)
{
CharacterExchangeResponse rsp = new() { Code = ex.Code };
session.SendResponse(rsp, packet.Id);
return;
}
session.SendResponse(new CharacterExchangeResponse(), packet.Id);
}
[RequestPacketHandler("CharacterUpgradeSkillGroupRequest")] [RequestPacketHandler("CharacterUpgradeSkillGroupRequest")]
public static void CharacterUpgradeSkillGroupRequestHandler(Session session, Packet.Request packet) public static void CharacterUpgradeSkillGroupRequestHandler(Session session, Packet.Request packet)
{ {

View File

@ -194,6 +194,12 @@ namespace AscNet.GameServer.Handlers
session.SendResponse(new TeamSetTeamResponse(), packet.Id); session.SendResponse(new TeamSetTeamResponse(), packet.Id);
} }
[RequestPacketHandler("EnterChallengeRequest")]
public static void HandleEnterChallengeRequestHandler(Session session, Packet.Request packet)
{
session.SendResponse(new EnterChallengeResponse(), packet.Id);
}
[RequestPacketHandler("FightSettleRequest")] [RequestPacketHandler("FightSettleRequest")]
public static void FightSettleRequestHandler(Session session, Packet.Request packet) public static void FightSettleRequestHandler(Session session, Packet.Request packet)
{ {

View File

@ -0,0 +1,35 @@
using MessagePack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AscNet.GameServer.Handlers
{
#region MsgPackScheme
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
[MessagePackObject(true)]
public class GetAndroidOrIosMoneyCardResponse
{
public int Code;
public int MoneyCard;
public int Count;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#endregion
internal class ItemModule
{
[RequestPacketHandler("GetAndroidOrIosMoneyCardRequest")]
public static void GetAndroidOrIosMoneyCardRequestHandler(Session session, Packet.Request packet)
{
session.SendResponse(new GetAndroidOrIosMoneyCardResponse()
{
Code = 0,
Count = 0,
MoneyCard = 0
}, packet.Id);
}
}
}

View File

@ -18,6 +18,17 @@ namespace AscNet.GameServer.Handlers
public int Code; public int Code;
} }
[MessagePackObject(true)]
public class TouchBoardMutualRequest
{
public int CharacterId;
}
[MessagePackObject(true)]
public class TouchBoardMutualResponse
{
}
[MessagePackObject(true)] [MessagePackObject(true)]
public class ChangeCommunicationRequest public class ChangeCommunicationRequest
{ {
@ -51,5 +62,13 @@ namespace AscNet.GameServer.Handlers
session.SendResponse(new ChangeCommunicationResponse(), packet.Id); session.SendResponse(new ChangeCommunicationResponse(), packet.Id);
} }
[RequestPacketHandler("TouchBoardMutualRequest")]
public static void TouchBoardMutualRequestHandler(Session session, Packet.Request packet)
{
TouchBoardMutualRequest request = MessagePackSerializer.Deserialize<TouchBoardMutualRequest>(packet.Content);
session.SendResponse(new TouchBoardMutualResponse(), packet.Id);
}
} }
} }

View File

@ -108,7 +108,7 @@ namespace AscNet.SDKServer.Controllers
}); });
}); });
app.MapGet("/api/Login/Login", ([FromQuery] int loginType, [FromQuery] int userId, [FromQuery] string token, [FromQuery] string clientIp) => app.MapGet("/api/Login/Login", ([FromQuery] int loginType, [FromQuery] int userId, [FromQuery] string token, [FromQuery] string? clientIp) =>
{ {
Account? account = Account.FromToken(token); Account? account = Account.FromToken(token);

View File

@ -16,7 +16,7 @@ namespace AscNet.SDKServer.Controllers
public static void Register(WebApplication app) public static void Register(WebApplication app)
{ {
app.MapGet("/prod/client/config/com.kurogame.punishing.grayraven.en.pc/{version}/standalone/config.tab", (HttpContext ctx) => app.MapGet("/prod/client/config/{package}/{version}/standalone/config.tab", (HttpContext ctx) =>
{ {
List<RemoteConfig> remoteConfigs = new(); List<RemoteConfig> remoteConfigs = new();
ServerVersionConfig versionConfig = versions.GetValueOrDefault((string)ctx.Request.RouteValues["version"]!) ?? versions.First().Value; ServerVersionConfig versionConfig = versions.GetValueOrDefault((string)ctx.Request.RouteValues["version"]!) ?? versions.First().Value;
@ -27,11 +27,21 @@ namespace AscNet.SDKServer.Controllers
remoteConfigs.AddConfig("ApplicationVersion", (string)ctx.Request.RouteValues["version"]!); remoteConfigs.AddConfig("ApplicationVersion", (string)ctx.Request.RouteValues["version"]!);
remoteConfigs.AddConfig("Debug", true); remoteConfigs.AddConfig("Debug", true);
remoteConfigs.AddConfig("External", true); remoteConfigs.AddConfig("External", true);
remoteConfigs.AddConfig("Channel", 1);
remoteConfigs.AddConfig("PayCallbackUrl", "empty"); remoteConfigs.AddConfig("PayCallbackUrl", "empty");
remoteConfigs.AddConfig("PrimaryCdns", "http://prod-encdn-akamai.kurogame.net/prod|http://prod-encdn-aliyun.kurogame.net/prod"); switch ((string?)ctx.Request.RouteValues["package"])
remoteConfigs.AddConfig("SecondaryCdns", "http://prod-encdn-aliyun.kurogame.net/prod"); {
remoteConfigs.AddConfig("CdnInvalidTime", 600); case "com.kurogame.haru.kuro":
remoteConfigs.AddConfig("PrimaryCdns", "http://prod-zspnsalicdn.kurogame.com/prod");
remoteConfigs.AddConfig("SecondaryCdns", "http://prod-zspnstxcdn.kurogame.com/prod");
remoteConfigs.AddConfig("Channel", 2);
break;
default:
remoteConfigs.AddConfig("PrimaryCdns", "http://prod-encdn-akamai.kurogame.net/prod|http://prod-encdn-aliyun.kurogame.net/prod");
remoteConfigs.AddConfig("SecondaryCdns", "http://prod-encdn-aliyun.kurogame.net/prod");
remoteConfigs.AddConfig("Channel", 1);
break;
}
remoteConfigs.AddConfig("CdnInvalidTime", 60);
remoteConfigs.AddConfig("MtpEnabled", false); remoteConfigs.AddConfig("MtpEnabled", false);
remoteConfigs.AddConfig("MemoryLimit", 2048); remoteConfigs.AddConfig("MemoryLimit", 2048);
remoteConfigs.AddConfig("CloseMsgEncrypt", false); remoteConfigs.AddConfig("CloseMsgEncrypt", false);
@ -44,12 +54,16 @@ namespace AscNet.SDKServer.Controllers
remoteConfigs.AddConfig("DownloadMethod", 1); remoteConfigs.AddConfig("DownloadMethod", 1);
remoteConfigs.AddConfig("PcPayCallbackList", $"{Common.Common.config.GameServer.Host}/api/XPay/KuroPayResult"); remoteConfigs.AddConfig("PcPayCallbackList", $"{Common.Common.config.GameServer.Host}/api/XPay/KuroPayResult");
// 2.9.0
remoteConfigs.AddConfig("WatermarkType", 2);
remoteConfigs.AddConfig("ChannelServerListStr", $"1#{Common.Common.config.GameServer.RegionName}#{Common.Common.config.GameServer.Host}/api/Login/Login");
string serializedObject = TsvTool.SerializeObject(remoteConfigs); string serializedObject = TsvTool.SerializeObject(remoteConfigs);
SDKServer.log.Info(serializedObject); SDKServer.log.Info(serializedObject);
return serializedObject; return serializedObject;
}); });
app.MapGet("/prod/client/notice/config/com.kurogame.punishing.grayraven.en.pc/{version}/LoginNotice.json", (HttpContext ctx) => app.MapGet("/prod/client/notice/config/{package}/{version}/LoginNotice.json", (HttpContext ctx) =>
{ {
LoginNotice notice = new() LoginNotice notice = new()
{ {
@ -66,7 +80,7 @@ namespace AscNet.SDKServer.Controllers
return serializedObject; return serializedObject;
}); });
app.MapGet("/prod/client/notice/config/com.kurogame.punishing.grayraven.en.pc/{version}/ScrollTextNotice.json", (HttpContext ctx) => app.MapGet("/prod/client/notice/config/{package}/{version}/ScrollTextNotice.json", (HttpContext ctx) =>
{ {
ScrollTextNotice notice = new() ScrollTextNotice notice = new()
{ {
@ -86,7 +100,7 @@ namespace AscNet.SDKServer.Controllers
return serializedObject; return serializedObject;
}); });
app.MapGet("/prod/client/notice/config/com.kurogame.punishing.grayraven.en.pc/{version}/ScrollPicNotice.json", (HttpContext ctx) => app.MapGet("/prod/client/notice/config/{package}/{version}/ScrollPicNotice.json", (HttpContext ctx) =>
{ {
ScrollPicNotice notice = new() ScrollPicNotice notice = new()
{ {
@ -117,7 +131,7 @@ namespace AscNet.SDKServer.Controllers
return serializedObject; return serializedObject;
}); });
app.MapGet("/prod/client/notice/config/com.kurogame.punishing.grayraven.en.pc/{version}/GameNotice.json", (HttpContext ctx) => app.MapGet("/prod/client/notice/config/{package}/{version}/GameNotice.json", (HttpContext ctx) =>
{ {
List<GameNotice> notices = new(); List<GameNotice> notices = new();

View File

@ -56,7 +56,11 @@ namespace AscNet.SDKServer
} }
catch (Exception ex) catch (Exception ex)
{ {
#if DEBUG
log.Error($"{ex} Request below:");
#else
log.Error($"{ex.Message} Request below:"); log.Error($"{ex.Message} Request below:");
#endif
} }
finally finally
{ {

View File

@ -12,5 +12,12 @@
"IndexMd5": "c5d4baac85a6e37b8109ea43dc045d31", "IndexMd5": "c5d4baac85a6e37b8109ea43dc045d31",
"IndexSha1": "5e1c9a7213857d9f1c1223f4871feb425a598294", "IndexSha1": "5e1c9a7213857d9f1c1223f4871feb425a598294",
"LaunchIndexSha1": "def7cf0ae2dbc6a31c5f85632f1d82d1f1d6cbfa" "LaunchIndexSha1": "def7cf0ae2dbc6a31c5f85632f1d82d1f1d6cbfa"
},
"2.9.0": {
"DocumentVersion": "2.9.15",
"LaunchModuleVersion": "2.9.15",
"IndexMd5": "c5d4baac85a6e37b8109ea43dc045d31",
"IndexSha1": "ee9b1d7242fe7ff9621f3b7451c969b06b8f7638",
"LaunchIndexSha1": "7e0de243ba0074fe2e5c194d686c693e29f65b92"
} }
} }