Compare commits

...

10 Commits

Author SHA1 Message Date
Naruse
e32319aa50 fix black screen after clicking love icon 2026-04-29 09:22:35 +08:00
Kei-Luna
846139347a Implement Weapon_Evolution 2026-04-29 09:58:35 +09:00
Kei-Luna
d1102b444c Implement Weapon_Break 2026-04-29 09:40:36 +09:00
Kei-Luna
3611624073 Update version.txt 2026-04-29 09:01:38 +09:00
Kei-Luna
c61ac08dd3 Fixed a critical issue with in-game chat. 2026-04-29 09:01:20 +09:00
Kei-Luna
720f56c708 fix 2026-04-29 06:59:22 +09:00
Kei-Luna
5fa42bdb23 Merge pull request #2 from ahasasjeb/main 2026-04-29 06:34:49 +09:00
lvjia
2f8d0c6afc Fix debug command i18n keys 2026-04-28 14:05:32 +08:00
lvjia
f6204134a9 /debug Multiple languages
Co-authored-by: Copilot <copilot@github.com>
2026-04-28 13:09:34 +08:00
lvjia
57ce0e183b Rewrite girl skin type handling 2026-04-28 12:47:05 +08:00
16 changed files with 494 additions and 17 deletions

View File

@@ -0,0 +1,34 @@
using Newtonsoft.Json;
namespace MikuSB.Data.Excel;
[ResourceEntity("break.json")]
public class BreakExcel : ExcelResource
{
[JsonProperty("ID")] public int Id { get; set; }
[JsonProperty("Items1")] public List<List<int>> Items1 { get; set; } = [];
[JsonProperty("Items2")] public List<List<int>> Items2 { get; set; } = [];
[JsonProperty("Items3")] public List<List<int>> Items3 { get; set; } = [];
[JsonProperty("Items4")] public List<List<int>> Items4 { get; set; } = [];
[JsonProperty("Items5")] public List<List<int>> Items5 { get; set; } = [];
[JsonProperty("Items6")] public List<List<int>> Items6 { get; set; } = [];
public List<List<int>> GetItems(uint breakLevel) => breakLevel switch
{
1 => Items1,
2 => Items2,
3 => Items3,
4 => Items4,
5 => Items5,
6 => Items6,
_ => []
};
public override uint GetId() => (uint)Id;
public override void Loaded()
{
GameData.BreakData[Id] = this;
}
}

View File

@@ -16,6 +16,7 @@ public static class GameData
public static Dictionary<uint, ArItemExcel> ArItemData { get; private set; } = []; public static Dictionary<uint, ArItemExcel> ArItemData { get; private set; } = [];
public static Dictionary<uint, ManifestationExcel> ManifestationData { get; private set; } = []; public static Dictionary<uint, ManifestationExcel> ManifestationData { get; private set; } = [];
public static Dictionary<uint, Rogue3DDifficultExcel> Rogue3DDifficultData { get; private set; } = []; public static Dictionary<uint, Rogue3DDifficultExcel> Rogue3DDifficultData { get; private set; } = [];
public static Dictionary<int, BreakExcel> BreakData { get; private set; } = [];
public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = []; public static Dictionary<uint, SpineExcel> SpineData { get; private set; } = [];
public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = []; public static Dictionary<uint, NodeConditionExcel> NodeConditionData { get; private set; } = [];
public static List<SupportCardExcel> SupportCardData { get; private set; } = []; public static List<SupportCardExcel> SupportCardData { get; private set; } = [];

View File

@@ -20,6 +20,9 @@ public class InventoryData : BaseDatabaseDataHelper
[SugarColumn(IsJson = true)] [SugarColumn(IsJson = true)]
public Dictionary<uint, GameSupportCardInfo> SupportCards { get; set; } = []; // Key: UniqueId public Dictionary<uint, GameSupportCardInfo> SupportCards { get; set; } = []; // Key: UniqueId
[SugarColumn(IsJson = true)]
public Dictionary<uint, uint> SkinTypesBySkinId { get; set; } = []; // Key: nSkinId, Value: client nType
} }
public class BaseGameItemInfo public class BaseGameItemInfo
@@ -53,6 +56,7 @@ public abstract class GrowableItemInfo : BaseGameItemInfo
public new uint Level { get; set; } public new uint Level { get; set; }
public new uint Exp { get; set; } public new uint Exp { get; set; }
public uint Break { get; set; } public uint Break { get; set; }
public uint Evolue { get; set; }
public uint EquipAvatarId { get; set; } public uint EquipAvatarId { get; set; }
} }
@@ -70,7 +74,8 @@ public class GameWeaponInfo : GrowableItemInfo
{ {
Level = Level, Level = Level,
Exp = Exp, Exp = Exp,
Break = Break Break = Break,
Evolue = Evolue
} }
}; };
return proto; return proto;
@@ -88,7 +93,7 @@ public class GameSkinInfo : BaseGameItemInfo
Count = ItemCount, Count = ItemCount,
Flag = (uint)Flag, Flag = (uint)Flag,
}; };
proto.Slots[11] = SkinType; proto.Slots[11] = Math.Min(SkinType, 1);
return proto; return proto;
} }
} }

View File

@@ -124,6 +124,7 @@ public class CommandTextCHS
public HelpTextCHS Help { get; } = new(); public HelpTextCHS Help { get; } = new();
public GirlTextCHS Girl { get; } = new(); public GirlTextCHS Girl { get; } = new();
public GiveAllTextCHS GiveAll { get; } = new(); public GiveAllTextCHS GiveAll { get; } = new();
public DebugTextCHS Debug { get; } = new();
} }
#endregion #endregion
@@ -244,6 +245,21 @@ public class GiveAllTextCHS
public string GiveAllItems => "已向玩家添加 {0} 个 {1}"; public string GiveAllItems => "已向玩家添加 {0} 个 {1}";
} }
/// <summary>
/// path: Game.Command.Debug
/// </summary>
public class DebugTextCHS
{
public string Desc => "调试包输出开关";
public string Usage => "用法: /debug [on|off|simple|detail|file]";
public string Enabled => "已启用调试包输出。";
public string Disabled => "已禁用调试包输出。";
public string SimpleEnabled => "已启用简单调试包输出。";
public string DetailEnabled => "已启用详细调试包输出。";
public string FileEnabled => "个人调试文件输出已启用。";
public string FileDisabled => "个人调试文件输出已禁用。";
}
#endregion #endregion
#endregion #endregion

View File

@@ -124,6 +124,7 @@ public class CommandTextCHT
public HelpTextCHT Help { get; } = new(); public HelpTextCHT Help { get; } = new();
public GirlTextCHT Girl { get; } = new(); public GirlTextCHT Girl { get; } = new();
public GiveAllTextCHT GiveAll { get; } = new(); public GiveAllTextCHT GiveAll { get; } = new();
public DebugTextCHT Debug { get; } = new();
} }
#endregion #endregion
@@ -244,6 +245,21 @@ public class GiveAllTextCHT
public string GiveAllItems => "已向玩家添加 {0} 個 {1}"; public string GiveAllItems => "已向玩家添加 {0} 個 {1}";
} }
/// <summary>
/// path: Game.Command.Debug
/// </summary>
public class DebugTextCHT
{
public string Desc => "切換調試封包輸出";
public string Usage => "用法: /debug [on|off|simple|detail|file]";
public string Enabled => "已啟用調試封包輸出。";
public string Disabled => "已停用調試封包輸出。";
public string SimpleEnabled => "已啟用簡易調試封包輸出。";
public string DetailEnabled => "已啟用詳細調試封包輸出。";
public string FileEnabled => "個人調試檔案輸出已啟用。";
public string FileDisabled => "個人調試檔案輸出已停用。";
}
#endregion #endregion
#endregion #endregion

View File

@@ -83,6 +83,7 @@ public class CommandTextEN
public HelpTextEN Help { get; } = new(); public HelpTextEN Help { get; } = new();
public GirlTextEN Girl { get; } = new(); public GirlTextEN Girl { get; } = new();
public GiveAllTextEN GiveAll { get; } = new(); public GiveAllTextEN GiveAll { get; } = new();
public DebugTextEN Debug { get; } = new();
} }
#endregion #endregion
@@ -210,6 +211,21 @@ public class GiveAllTextEN
public string GiveAllItems => "Added {0} {1} to player!"; public string GiveAllItems => "Added {0} {1} to player!";
} }
/// <summary>
/// path: Game.Command.Debug
/// </summary>
public class DebugTextEN
{
public string Desc => "Toggle debug packet output";
public string Usage => "Usage: /debug [on|off|simple|detail|file]";
public string Enabled => "Debug packet output enabled.";
public string Disabled => "Debug packet output disabled.";
public string SimpleEnabled => "Simple debug packet output enabled.";
public string DetailEnabled => "Detailed debug packet output enabled.";
public string FileEnabled => "Personal debug file output enabled.";
public string FileDisabled => "Personal debug file output disabled.";
}
#endregion #endregion
#endregion #endregion

View File

@@ -38,9 +38,9 @@ public class PlayerCommandSender(PlayerInstance player) : ICommandSender
Type = ChatType.Friend, Type = ChatType.Friend,
Sender = (uint)ConfigManager.Config.ServerOption.ServerProfile.Uid, Sender = (uint)ConfigManager.Config.ServerOption.ServerProfile.Uid,
Recver = (uint)Player.Uid, Recver = (uint)Player.Uid,
Text = msg, Text = ChatMessageHelper.NormalizeForClient(msg),
Profile = Player.ToServerFriendProto(), Profile = Player.ToServerFriendProto(),
TimeStamp = (uint)Extensions.GetUnixMs() TimeStamp = ChatMessageHelper.BuildClientTimestamp()
}; };
await Player.SendPacket(CmdIds.NtfFriendChat, data); await Player.SendPacket(CmdIds.NtfFriendChat, data);
} }

View File

@@ -0,0 +1,69 @@
using MikuSB.Configuration;
using MikuSB.Enums.Player;
using MikuSB.Util;
using MikuSB.Internationalization;
namespace MikuSB.GameServer.Command.Commands;
[CommandInfo("debug", "Game.Command.Debug.Desc", "Game.Command.Debug.Usage", ["dbg"], [PermEnum.Admin, PermEnum.Support])]
public class CommandDebug : ICommands
{
private static readonly Logger Logger = new("CommandManager");
[CommandDefault]
public async ValueTask ToggleDebug(CommandArg arg)
{
var option = arg.Args.FirstOrDefault()?.ToLowerInvariant() ?? "on";
var serverOption = ConfigManager.Config.ServerOption;
var message = option switch
{
"on" => EnableDebug(serverOption),
"off" => DisableDebug(serverOption),
"simple" => EnableSimpleDebug(serverOption),
"detail" => EnableDetailDebug(serverOption),
"file" => ToggleDebugFile(serverOption),
_ => I18NManager.Translate("Game.Command.Debug.Usage")
};
Logger.Info(message);
await arg.SendMsg(message);
}
private static string EnableDebug(ServerOption serverOption)
{
serverOption.EnableDebug = true;
serverOption.DebugMessage = true;
serverOption.DebugDetailMessage = true;
return I18NManager.Translate("Game.Command.Debug.Enabled");
}
private static string DisableDebug(ServerOption serverOption)
{
serverOption.EnableDebug = false;
return I18NManager.Translate("Game.Command.Debug.Disabled");
}
private static string EnableSimpleDebug(ServerOption serverOption)
{
serverOption.EnableDebug = true;
serverOption.DebugMessage = true;
serverOption.DebugDetailMessage = false;
return I18NManager.Translate("Game.Command.Debug.SimpleEnabled");
}
private static string EnableDetailDebug(ServerOption serverOption)
{
serverOption.EnableDebug = true;
serverOption.DebugMessage = true;
serverOption.DebugDetailMessage = true;
return I18NManager.Translate("Game.Command.Debug.DetailEnabled");
}
private static string ToggleDebugFile(ServerOption serverOption)
{
serverOption.SavePersonalDebugFile = !serverOption.SavePersonalDebugFile;
return serverOption.SavePersonalDebugFile
? I18NManager.Translate("Game.Command.Debug.FileEnabled")
: I18NManager.Translate("Game.Command.Debug.FileDisabled");
}
}

View File

@@ -0,0 +1,27 @@
using System.Text.RegularExpressions;
namespace MikuSB.GameServer.Game.Player;
public static partial class ChatMessageHelper
{
[GeneratedRegex(@"\s+")]
private static partial Regex MultiWhitespaceRegex();
public static uint BuildClientTimestamp()
{
return (uint)MikuSB.Util.Extensions.Extensions.GetUnixSec();
}
public static string NormalizeForClient(string? text)
{
if (string.IsNullOrWhiteSpace(text))
return string.Empty;
var normalized = text
.Replace("\r\n", " ")
.Replace('\r', ' ')
.Replace('\n', ' ');
return MultiWhitespaceRegex().Replace(normalized, " ").Trim();
}
}

View File

@@ -160,9 +160,9 @@ public class PlayerInstance(PlayerGameData data)
Sender = sendUid, Sender = sendUid,
Recver = recvUid, Recver = recvUid,
Emoji = emojiId ?? 0, Emoji = emojiId ?? 0,
Text = message ?? "", Text = ChatMessageHelper.NormalizeForClient(message),
Profile = Data.ToProfileProto(), Profile = Data.ToProfileProto(),
TimeStamp = (uint)Extensions.GetUnixMs() TimeStamp = ChatMessageHelper.BuildClientTimestamp()
}; };
await SendPacket(CmdIds.NtfFriendChat, data); await SendPacket(CmdIds.NtfFriendChat, data);

View File

@@ -12,11 +12,19 @@ public class EnterGirlRoom : ICallGSHandler
var req = JsonSerializer.Deserialize<EnterGirlRoomParam>(param); var req = JsonSerializer.Deserialize<EnterGirlRoomParam>(param);
var response = new JsonObject var response = new JsonObject
{ {
["nCardId"] = req?.CardId ?? 1, ["nCardId"] = 0,
["nSkinId"] = req?.SkinId ?? 0, ["nSkinId"] = 0,
["bOpen"] = true ["bOpen"] = false
}; };
if (req == null)
{
await CallGSRouter.SendScript(connection, "EnterGirlRoom", response.ToJsonString());
return;
}
response["nCardId"] = req.CardId;
response["nSkinId"] = req.SkinId;
response["bOpen"] = true;
await CallGSRouter.SendScript(connection, "EnterGirlRoom", response.ToJsonString()); await CallGSRouter.SendScript(connection, "EnterGirlRoom", response.ToJsonString());
} }
} }
@@ -26,6 +34,6 @@ internal sealed class EnterGirlRoomParam
[JsonPropertyName("nSkinId")] [JsonPropertyName("nSkinId")]
public int SkinId { get; set; } public int SkinId { get; set; }
[JsonPropertyName("nCardID")] [JsonPropertyName("nCardId")]
public uint CardId { get; set; } public uint CardId { get; set; }
} }

View File

@@ -1,4 +1,9 @@
using MikuSB.Proto; using MikuSB.Data;
using MikuSB.Database;
using MikuSB.Database.Inventory;
using MikuSB.Enums.Item;
using MikuSB.GameServer.Game.Player;
using MikuSB.Proto;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@@ -11,9 +16,10 @@ public class GirlSkin_ChangeSkinType : ICallGSHandler
public async Task Handle(Connection connection, string param, ushort seqNo) public async Task Handle(Connection connection, string param, ushort seqNo)
{ {
var req = JsonSerializer.Deserialize<ChangeSkinTypeParam>(param); var req = JsonSerializer.Deserialize<ChangeSkinTypeParam>(param);
var skinType = ClampClientSkinType(req?.Type ?? 0);
var response = new JsonObject var response = new JsonObject
{ {
["nType"] = req?.Type ?? 1, ["nType"] = skinType,
["nSkinId"] = req?.SkinId ["nSkinId"] = req?.SkinId
}; };
if (req == null) if (req == null)
@@ -23,14 +29,20 @@ public class GirlSkin_ChangeSkinType : ICallGSHandler
} }
var player = connection.Player!; var player = connection.Player!;
var skinData = player.InventoryManager.GetSkinItem(req.SkinId); var skinData = GetOrCreateSkinItem(player, req.SkinId);
if (skinData != null)
skinData.SkinType = skinType;
player.InventoryManager.InventoryData.SkinTypesBySkinId ??= [];
player.InventoryManager.InventoryData.SkinTypesBySkinId[req.SkinId] = skinType;
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
if (skinData == null) if (skinData == null)
{ {
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString()); await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
return; return;
} }
skinData.SkinType = req.Type;
var sync = new NtfSyncPlayer var sync = new NtfSyncPlayer
{ {
Items = { skinData.ToProto() } Items = { skinData.ToProto() }
@@ -38,6 +50,42 @@ public class GirlSkin_ChangeSkinType : ICallGSHandler
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString(), sync); await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString(), sync);
} }
internal static uint ClampClientSkinType(uint skinType)
{
return Math.Min(skinType, 1);
}
internal static GameSkinInfo? GetOrCreateSkinItem(PlayerInstance player, uint skinId)
{
var inventoryData = player.InventoryManager.InventoryData;
if (inventoryData.Skins.TryGetValue(skinId, out var skinInfo))
return skinInfo;
if (!GameData.CardSkinData.TryGetValue(skinId, out var skinData))
return null;
var templateId = GameResourceTemplateId.FromGdpl(skinData.Genre, skinData.Detail, skinData.Particular, skinData.Level);
skinInfo = player.InventoryManager.GetSkinItemByTemplateId(templateId);
if (skinInfo != null)
{
inventoryData.Skins.Remove(skinInfo.UniqueId);
skinInfo.UniqueId = skinId;
}
else
{
skinInfo = new GameSkinInfo
{
UniqueId = skinId,
TemplateId = templateId,
ItemType = ItemTypeEnum.TYPE_CARD_SKIN,
ItemCount = 1
};
}
inventoryData.Skins[skinId] = skinInfo;
return skinInfo;
}
} }
internal sealed class ChangeSkinTypeParam internal sealed class ChangeSkinTypeParam

View File

@@ -0,0 +1,98 @@
using MikuSB.Data;
using MikuSB.Database;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Weapon;
// s2c: function(sErr) — send "null" on success (json.decode("null") = nil = falsy in Lua)
[CallGSApi("Weapon_Break")]
public class Weapon_Break : ICallGSHandler
{
private const uint MaxBreak = 6;
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<WeaponBreakParam>(param);
if (req == null || req.WeaponId == 0)
{
await CallGSRouter.SendScript(connection, "Weapon_Break", "\"error.BadParam\"");
return;
}
var weapon = player.InventoryManager.InventoryData.Weapons.GetValueOrDefault((uint)req.WeaponId);
if (weapon == null)
{
await CallGSRouter.SendScript(connection, "Weapon_Break", "\"error.BadParam\"");
return;
}
if (weapon.Break >= MaxBreak)
{
await CallGSRouter.SendScript(connection, "Weapon_Break", "\"tip.already_max_break\"");
return;
}
var nextBreak = weapon.Break + 1;
// Look up break cost from WeaponExcel → BreakExcel
var weaponExcel = GameData.WeaponData.Values.FirstOrDefault(x =>
GameResourceTemplateId.FromGdpl(x.Genre, x.Detail, x.Particular, x.Level) == weapon.TemplateId);
var requestedMaterials = new Dictionary<ulong, uint>();
if (weaponExcel != null && GameData.BreakData.TryGetValue(weaponExcel.BreakMatID, out var breakExcel))
{
foreach (var row in breakExcel.GetItems(nextBreak))
{
if (row.Count < 5) continue;
var tid = GameResourceTemplateId.FromGdpl(
(uint)row[0], (uint)row[1], (uint)row[2], (uint)row[3]);
requestedMaterials[tid] = requestedMaterials.GetValueOrDefault(tid) + (uint)row[4];
}
}
// Validate materials
foreach (var (tid, count) in requestedMaterials)
{
var item = player.InventoryManager.InventoryData.Items.Values.FirstOrDefault(x => x.TemplateId == tid);
if (item == null || item.ItemCount < count)
{
await CallGSRouter.SendScript(connection, "Weapon_Break", "\"tip.not_material_for_break\"");
return;
}
}
// Consume materials
var syncItems = new List<Item>();
foreach (var (tid, count) in requestedMaterials)
{
var item = player.InventoryManager.InventoryData.Items.Values.First(x => x.TemplateId == tid);
item.ItemCount -= count;
var proto = item.ToProto();
if (item.ItemCount == 0)
{
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
proto.Count = 0;
}
syncItems.Add(proto);
}
weapon.Break = nextBreak;
syncItems.Add(weapon.ToProto());
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
var sync = new NtfSyncPlayer();
sync.Items.AddRange(syncItems);
await CallGSRouter.SendScript(connection, "Weapon_Break", "null", sync);
}
}
internal sealed class WeaponBreakParam
{
[JsonPropertyName("Id")]
public int WeaponId { get; set; }
}

View File

@@ -0,0 +1,77 @@
using MikuSB.Database;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Weapon;
// s2c: function(sErr) — send "null" on success
// Id = target weapon UniqueId
// nItemId = material item UniqueId (weapon or supply item to consume)
[CallGSApi("Weapon_Evolution")]
public class Weapon_Evolution : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<WeaponEvolutionParam>(param);
if (req == null || req.WeaponId == 0 || req.MaterialId == 0)
{
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\"");
return;
}
var weapon = player.InventoryManager.InventoryData.Weapons.GetValueOrDefault((uint)req.WeaponId);
if (weapon == null)
{
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"error.BadParam\"");
return;
}
var syncItems = new List<Item>();
// Material can be a weapon or a regular item
if (player.InventoryManager.InventoryData.Weapons.TryGetValue((uint)req.MaterialId, out var matWeapon))
{
player.InventoryManager.InventoryData.Weapons.Remove((uint)req.MaterialId);
var removed = matWeapon.ToProto();
removed.Count = 0;
syncItems.Add(removed);
}
else if (player.InventoryManager.InventoryData.Items.TryGetValue((uint)req.MaterialId, out var matItem))
{
matItem.ItemCount--;
var proto = matItem.ToProto();
if (matItem.ItemCount == 0)
{
player.InventoryManager.InventoryData.Items.Remove(matItem.UniqueId);
proto.Count = 0;
}
syncItems.Add(proto);
}
else
{
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "\"tip.not_material\"");
return;
}
weapon.Evolue++;
syncItems.Add(weapon.ToProto());
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
var sync = new NtfSyncPlayer();
sync.Items.AddRange(syncItems);
await CallGSRouter.SendScript(connection, "Weapon_Evolution", "null", sync);
}
}
internal sealed class WeaponEvolutionParam
{
[JsonPropertyName("Id")]
public int WeaponId { get; set; }
[JsonPropertyName("nItemId")]
public int MaterialId { get; set; }
}

View File

@@ -4,12 +4,14 @@ using MikuSB.Database.Account;
using MikuSB.Database.Player; using MikuSB.Database.Player;
using MikuSB.GameServer.Game.Player; using MikuSB.GameServer.Game.Player;
using MikuSB.GameServer.Server.CallGS; using MikuSB.GameServer.Server.CallGS;
using MikuSB.GameServer.Server.CallGS.Handlers.Girl;
using MikuSB.GameServer.Server.Packet.Send.Friend; using MikuSB.GameServer.Server.Packet.Send.Friend;
using MikuSB.GameServer.Server.Packet.Send.Login; using MikuSB.GameServer.Server.Packet.Send.Login;
using MikuSB.GameServer.Server.Packet.Send.Misc; using MikuSB.GameServer.Server.Packet.Send.Misc;
using MikuSB.Proto; using MikuSB.Proto;
using MikuSB.TcpSharp; using MikuSB.TcpSharp;
using MikuSB.Util; using MikuSB.Util;
using System.Text.Json.Nodes;
namespace MikuSB.GameServer.Server.Packet.Recv.Login; namespace MikuSB.GameServer.Server.Packet.Recv.Login;
@@ -54,6 +56,66 @@ public class HandlerReqLogin : Handler
await connection.Player.OnHeartBeat(); await connection.Player.OnHeartBeat();
await connection.SendPacket(new PacketNtfUpdateFriend(connection.Player!)); await connection.SendPacket(new PacketNtfUpdateFriend(connection.Player!));
ApplySavedGirlSkinTypes(connection.Player!);
await connection.SendPacket(new PacketNtfCallScript(connection.Player!.InventoryManager.InventoryData)); await connection.SendPacket(new PacketNtfCallScript(connection.Player!.InventoryManager.InventoryData));
await SendGirlSkinTypeOnLogin(connection);
}
private static void ApplySavedGirlSkinTypes(PlayerInstance player)
{
var inventoryData = player.InventoryManager.InventoryData;
inventoryData.SkinTypesBySkinId ??= [];
var changed = false;
foreach (var (skinId, skinType) in inventoryData.SkinTypesBySkinId.ToArray())
{
var clamped = GirlSkin_ChangeSkinType.ClampClientSkinType(skinType);
if (clamped != skinType)
{
inventoryData.SkinTypesBySkinId[skinId] = clamped;
changed = true;
}
var skinData = GirlSkin_ChangeSkinType.GetOrCreateSkinItem(player, skinId);
if (skinData != null && skinData.SkinType != clamped)
{
skinData.SkinType = clamped;
changed = true;
}
}
if (changed)
DatabaseHelper.SaveDatabaseType(inventoryData);
}
private static async Task SendGirlSkinTypeOnLogin(Connection connection)
{
var player = connection.Player;
if (player == null)
return;
var inventoryData = player.InventoryManager.InventoryData;
inventoryData.SkinTypesBySkinId ??= [];
foreach (var (skinId, skinType) in inventoryData.SkinTypesBySkinId)
{
var clamped = GirlSkin_ChangeSkinType.ClampClientSkinType(skinType);
var skinData = GirlSkin_ChangeSkinType.GetOrCreateSkinItem(player, skinId);
var response = new JsonObject
{
["nType"] = clamped,
["nSkinId"] = skinId
};
if (skinData == null)
{
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString());
continue;
}
await CallGSRouter.SendScript(connection, "GirlSkin_ChangeSkinType", response.ToJsonString(), new NtfSyncPlayer
{
Items = { skinData.ToProto() }
});
}
} }
} }

View File

@@ -1 +1 @@
v=1.2 v=1.4