mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 12:43:58 +00:00
Compare commits
23 Commits
v2.4
...
e628a010be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e628a010be | ||
|
|
738a7d4e14 | ||
|
|
0058ba0db6 | ||
|
|
46d945f3ce | ||
|
|
e5ecdc7f2a | ||
|
|
30c52b6aa8 | ||
|
|
3ffb7ebf29 | ||
|
|
400db16f39 | ||
|
|
42b1ad1024 | ||
|
|
5aa5ef92d0 | ||
|
|
c34ad5eb1e | ||
|
|
8a597e24b6 | ||
|
|
9763f1f8d9 | ||
|
|
933ba097f9 | ||
|
|
c10d380e11 | ||
|
|
6c5d546026 | ||
|
|
9e518edb8e | ||
|
|
79fad7df2e | ||
|
|
68a7d6cc61 | ||
|
|
548c77850e | ||
|
|
d8c356a01f | ||
|
|
26991c9706 | ||
|
|
4ee11618be |
18
Common/Data/Excel/HouseFurniturePosData.cs
Normal file
18
Common/Data/Excel/HouseFurniturePosData.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("house/FurniturePos.json")]
|
||||||
|
public class HouseFurniturePosExcel : ExcelResource
|
||||||
|
{
|
||||||
|
public uint AreaId { get; set; }
|
||||||
|
public uint GroupId { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId()
|
||||||
|
{
|
||||||
|
return (AreaId << 48) | (GroupId << 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.HouseFurniturePosData.TryAdd(GetId(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Common/Data/Excel/SupportAffixExcel.cs
Normal file
27
Common/Data/Excel/SupportAffixExcel.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("item/support/affix.json")]
|
||||||
|
public class SupportAffixExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public int Id { get; set; }
|
||||||
|
[JsonExtensionData] public IDictionary<string, JToken> ExtraData { get; set; } = new Dictionary<string, JToken>();
|
||||||
|
|
||||||
|
public int TierCount =>
|
||||||
|
ExtraData
|
||||||
|
.Where(x => x.Key != "ID" && x.Key != "Sift" && x.Key != "Comment")
|
||||||
|
.Select(x => x.Value)
|
||||||
|
.OfType<JObject>()
|
||||||
|
.Select(x => x.Count)
|
||||||
|
.DefaultIfEmpty(0)
|
||||||
|
.Max();
|
||||||
|
|
||||||
|
public override uint GetId() => (uint)Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.SupportAffixData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Common/Data/Excel/SupportAffixPoolExcel.cs
Normal file
35
Common/Data/Excel/SupportAffixPoolExcel.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("item/support/affix_pool.json")]
|
||||||
|
public class SupportAffixPoolExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public int Id { get; set; }
|
||||||
|
public List<int> AffixGroup1 { get; set; } = [];
|
||||||
|
public int Weight1 { get; set; }
|
||||||
|
public List<int> AffixGroup2 { get; set; } = [];
|
||||||
|
public int Weight2 { get; set; }
|
||||||
|
public List<int> AffixGroup3 { get; set; } = [];
|
||||||
|
public int Weight3 { get; set; }
|
||||||
|
public List<int> AffixGroup4 { get; set; } = [];
|
||||||
|
public int Weight4 { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<(IReadOnlyList<int> Affixs, int Weight)> Groups
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (AffixGroup1.Count > 0 && Weight1 > 0) yield return (AffixGroup1, Weight1);
|
||||||
|
if (AffixGroup2.Count > 0 && Weight2 > 0) yield return (AffixGroup2, Weight2);
|
||||||
|
if (AffixGroup3.Count > 0 && Weight3 > 0) yield return (AffixGroup3, Weight3);
|
||||||
|
if (AffixGroup4.Count > 0 && Weight4 > 0) yield return (AffixGroup4, Weight4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override uint GetId() => (uint)Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.SupportAffixPoolData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,9 @@ public class SupportCardExcel : ExcelResource
|
|||||||
public uint Level { get; set; }
|
public uint Level { get; set; }
|
||||||
public uint Icon { get; set; }
|
public uint Icon { get; set; }
|
||||||
public uint ProvideExp { get; set; }
|
public uint ProvideExp { get; set; }
|
||||||
|
public uint Color { get; set; }
|
||||||
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
|
[JsonProperty("LevelLimitID")] public int LevelLimitId { get; set; }
|
||||||
|
[JsonProperty("AffixPool")] public List<int> AffixPool { get; set; } = [];
|
||||||
|
|
||||||
public uint MaxLevel => LevelLimitId switch
|
public uint MaxLevel => LevelLimitId switch
|
||||||
{
|
{
|
||||||
@@ -21,6 +23,12 @@ public class SupportCardExcel : ExcelResource
|
|||||||
_ => 10
|
_ => 10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Number of affixes granted initially
|
||||||
|
public int InitialAffixCount => Color >= 5 ? 2 : 1;
|
||||||
|
|
||||||
|
// Total maximum affixes (including ones unlocked at max level)
|
||||||
|
public int TotalAffixCount => Color >= 5 ? 3 : 2;
|
||||||
|
|
||||||
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
public ulong TemplateId => GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
|
||||||
|
|
||||||
public override uint GetId() => Icon;
|
public override uint GetId() => Icon;
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public static class GameData
|
|||||||
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; } = [];
|
||||||
|
public static Dictionary<int, SupportAffixExcel> SupportAffixData { get; private set; } = [];
|
||||||
|
public static Dictionary<int, SupportAffixPoolExcel> SupportAffixPoolData { get; private set; } = [];
|
||||||
public static Dictionary<uint, WeaponSkinExcel> WeaponSkinData { get; private set; } = [];
|
public static Dictionary<uint, WeaponSkinExcel> WeaponSkinData { get; private set; } = [];
|
||||||
public static Dictionary<uint, DailyLevelExcel> DailyLevelData { get; private set; } = [];
|
public static Dictionary<uint, DailyLevelExcel> DailyLevelData { get; private set; } = [];
|
||||||
public static Dictionary<uint, ProfileExcel> ProfileData { get; private set; } = [];
|
public static Dictionary<uint, ProfileExcel> ProfileData { get; private set; } = [];
|
||||||
@@ -31,6 +33,7 @@ public static class GameData
|
|||||||
public static Dictionary<uint, WeaponPartsExcel> WeaponPartsData { get; private set; } = [];
|
public static Dictionary<uint, WeaponPartsExcel> WeaponPartsData { get; private set; } = [];
|
||||||
public static Dictionary<uint, GuideExcel> GuideData { get; private set; } = [];
|
public static Dictionary<uint, GuideExcel> GuideData { get; private set; } = [];
|
||||||
public static Dictionary<uint, DormGiftExcel> DormGiftData { get; private set; } = [];
|
public static Dictionary<uint, DormGiftExcel> DormGiftData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, HouseFurniturePosExcel> HouseFurniturePosData { get; private set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GameResourceTemplateId
|
public static class GameResourceTemplateId
|
||||||
|
|||||||
@@ -106,6 +106,8 @@ public class GameSkinInfo : BaseGameItemInfo
|
|||||||
public class GameSupportCardInfo : BaseGameItemInfo
|
public class GameSupportCardInfo : BaseGameItemInfo
|
||||||
{
|
{
|
||||||
public uint AffixId { get; set; }
|
public uint AffixId { get; set; }
|
||||||
|
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
|
||||||
|
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -120,6 +122,7 @@ public class GameSupportCardInfo : BaseGameItemInfo
|
|||||||
Exp = Exp
|
Exp = Exp
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
proto.Enhance.Affixs.AddRange(Affixs);
|
||||||
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
|
proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,9 +222,16 @@ public class HelpTextCHS
|
|||||||
public class AccountTextCHS
|
public class AccountTextCHS
|
||||||
{
|
{
|
||||||
public string Desc => "管理 SDK 登录使用的账号映射";
|
public string Desc => "管理 SDK 登录使用的账号映射";
|
||||||
public string Usage => "用法: /account create <邮箱> <UID>";
|
public string Usage =>
|
||||||
|
"用法: /account create <邮箱> <UID>\n" +
|
||||||
|
"用法: /account delete <邮箱|UID>\n" +
|
||||||
|
"用法: /account list";
|
||||||
public string Created => "已创建账号映射: {0} -> UID {1}";
|
public string Created => "已创建账号映射: {0} -> UID {1}";
|
||||||
public string CreateFailed => "创建账号映射失败: {0}";
|
public string CreateFailed => "创建账号映射失败: {0}";
|
||||||
|
public string Deleted => "已删除账号映射: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "删除账号映射失败: {0}";
|
||||||
|
public string DeleteOnline => "账号在线时无法删除: {0} -> UID {1}";
|
||||||
|
public string NotFound => "未找到账号: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -222,9 +222,16 @@ public class HelpTextCHT
|
|||||||
public class AccountTextCHT
|
public class AccountTextCHT
|
||||||
{
|
{
|
||||||
public string Desc => "管理 SDK 登入使用的帳號映射";
|
public string Desc => "管理 SDK 登入使用的帳號映射";
|
||||||
public string Usage => "用法: /account create <郵箱> <UID>";
|
public string Usage =>
|
||||||
|
"用法: /account create <郵箱> <UID>\n" +
|
||||||
|
"用法: /account delete <郵箱|UID>\n" +
|
||||||
|
"用法: /account list";
|
||||||
public string Created => "已建立帳號映射: {0} -> UID {1}";
|
public string Created => "已建立帳號映射: {0} -> UID {1}";
|
||||||
public string CreateFailed => "建立帳號映射失敗: {0}";
|
public string CreateFailed => "建立帳號映射失敗: {0}";
|
||||||
|
public string Deleted => "已刪除帳號映射: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "刪除帳號映射失敗: {0}";
|
||||||
|
public string DeleteOnline => "帳號在線時無法刪除: {0} -> UID {1}";
|
||||||
|
public string NotFound => "未找到帳號: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -188,9 +188,16 @@ public class HelpTextEN
|
|||||||
public class AccountTextEN
|
public class AccountTextEN
|
||||||
{
|
{
|
||||||
public string Desc => "Manage account mappings for SDK logins";
|
public string Desc => "Manage account mappings for SDK logins";
|
||||||
public string Usage => "Usage: /account create <email> <uid>";
|
public string Usage =>
|
||||||
|
"Usage: /account create <email> <uid>\n" +
|
||||||
|
"Usage: /account delete <email|uid>\n" +
|
||||||
|
"Usage: /account list";
|
||||||
public string Created => "Created account mapping: {0} -> UID {1}";
|
public string Created => "Created account mapping: {0} -> UID {1}";
|
||||||
public string CreateFailed => "Failed to create account mapping: {0}";
|
public string CreateFailed => "Failed to create account mapping: {0}";
|
||||||
|
public string Deleted => "Deleted account mapping: {0} -> UID {1}";
|
||||||
|
public string DeleteFailed => "Failed to delete account mapping: {0}";
|
||||||
|
public string DeleteOnline => "Cannot delete account while online: {0} -> UID {1}";
|
||||||
|
public string NotFound => "Account not found: {0}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ public static class ConfigManager
|
|||||||
//LoadHotfixData();
|
//LoadHotfixData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SaveConfig()
|
||||||
|
{
|
||||||
|
SaveData(Config, ConfigFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
private static void LoadConfigData()
|
private static void LoadConfigData()
|
||||||
{
|
{
|
||||||
var file = new FileInfo(ConfigFilePath);
|
var file = new FileInfo(ConfigFilePath);
|
||||||
@@ -43,9 +48,26 @@ public static class ConfigManager
|
|||||||
Config = JsonConvert.DeserializeObject<ConfigContainer>(json)!;
|
Config = JsonConvert.DeserializeObject<ConfigContainer>(json)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config.Loader.Arguments = NormalizeLoaderArguments(Config.Loader.Arguments);
|
||||||
SaveData(Config, ConfigFilePath);
|
SaveData(Config, ConfigFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string[] NormalizeLoaderArguments(string[]? arguments)
|
||||||
|
{
|
||||||
|
var result = new List<string>(arguments ?? []);
|
||||||
|
var userDataDirectory = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "Client_User_Data"));
|
||||||
|
Directory.CreateDirectory(userDataDirectory);
|
||||||
|
|
||||||
|
var userDirArgument = $"-userdir={userDataDirectory}";
|
||||||
|
var existingIndex = result.FindIndex(x => x.StartsWith("-userdir=", StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingIndex >= 0)
|
||||||
|
result[existingIndex] = userDirArgument;
|
||||||
|
else
|
||||||
|
result.Add(userDirArgument);
|
||||||
|
|
||||||
|
return result.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
private static void LoadHotfixData()
|
private static void LoadHotfixData()
|
||||||
{
|
{
|
||||||
var file = new FileInfo(HotfixFilePath);
|
var file = new FileInfo(HotfixFilePath);
|
||||||
|
|||||||
46
Common/Util/PatchDownloadService.cs
Normal file
46
Common/Util/PatchDownloadService.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
|
namespace MikuSB.Util;
|
||||||
|
|
||||||
|
public static class PatchDownloadService
|
||||||
|
{
|
||||||
|
private static readonly Logger Logger = new("PatchDownloader");
|
||||||
|
private const string PatchRelativePath = @"Patch\MikuSB-Patch.dll";
|
||||||
|
private const string PatchDownloadUrl = "https://github.com/Kei-Luna/MikuSB-Patch/releases/download/MikuSB-Patch/MikuSB-Patch.dll";
|
||||||
|
private const int DownloadTimeoutSeconds = 60;
|
||||||
|
|
||||||
|
public static void EnsurePatchPresent()
|
||||||
|
{
|
||||||
|
var patchPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, PatchRelativePath));
|
||||||
|
if (File.Exists(patchPath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(patchPath)!);
|
||||||
|
Logger.Warn($"Patch DLL not found. Downloading to {patchPath}.");
|
||||||
|
|
||||||
|
using var client = CreateHttpClient();
|
||||||
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(DownloadTimeoutSeconds));
|
||||||
|
using var response = client.GetAsync(PatchDownloadUrl, HttpCompletionOption.ResponseHeadersRead, cts.Token)
|
||||||
|
.GetAwaiter().GetResult();
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
using var source = response.Content.ReadAsStreamAsync(cts.Token).GetAwaiter().GetResult();
|
||||||
|
using var destination = File.Create(patchPath);
|
||||||
|
source.CopyTo(destination);
|
||||||
|
|
||||||
|
Logger.Info("Patch DLL download completed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient CreateHttpClient()
|
||||||
|
{
|
||||||
|
var client = new HttpClient
|
||||||
|
{
|
||||||
|
Timeout = Timeout.InfiniteTimeSpan
|
||||||
|
};
|
||||||
|
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Add(
|
||||||
|
new ProductInfoHeaderValue("MikuSB-PatchDownloader", BuildVersion.Current));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
using MikuSB.Database;
|
||||||
using MikuSB.Database.Account;
|
using MikuSB.Database.Account;
|
||||||
using MikuSB.Enums.Player;
|
using MikuSB.Enums.Player;
|
||||||
using MikuSB.Internationalization;
|
using MikuSB.Internationalization;
|
||||||
|
using MikuSB.GameServer.Server;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Command.Commands;
|
namespace MikuSB.GameServer.Command.Commands;
|
||||||
|
|
||||||
@@ -34,4 +37,61 @@ public class CommandAccount : ICommands
|
|||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.CreateFailed", ex.Message));
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.CreateFailed", ex.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CommandMethod("delete")]
|
||||||
|
public async ValueTask Delete(CommandArg arg)
|
||||||
|
{
|
||||||
|
if (!await arg.CheckArgCnt(1))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var identifier = arg.Args[0].Trim();
|
||||||
|
var account = int.TryParse(identifier, out var uid) && uid > 0
|
||||||
|
? AccountData.GetAccountByUid(uid)
|
||||||
|
: AccountData.GetAccountByUserName(identifier);
|
||||||
|
|
||||||
|
if (account == null)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.NotFound", identifier));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Listener.GetActiveConnection(account.Uid) != null)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.DeleteOnline", account.Username,
|
||||||
|
account.Uid.ToString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountData.DeleteAccount(account.Uid);
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.Deleted", account.Username,
|
||||||
|
account.Uid.ToString()));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.Account.DeleteFailed", ex.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[CommandMethod("list")]
|
||||||
|
public async ValueTask List(CommandArg arg)
|
||||||
|
{
|
||||||
|
var accounts = DatabaseHelper.GetAllInstance<AccountData>()?
|
||||||
|
.OrderBy(account => account.Uid)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (accounts == null || accounts.Count == 0)
|
||||||
|
{
|
||||||
|
await arg.SendMsg("No accounts found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
builder.AppendLine("Accounts:");
|
||||||
|
foreach (var account in accounts)
|
||||||
|
builder.AppendLine($"{account.Username} -> UID {account.Uid}");
|
||||||
|
|
||||||
|
await arg.SendMsg(builder.ToString().TrimEnd());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using MikuSB.Data;
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database;
|
||||||
using MikuSB.Database.Inventory;
|
using MikuSB.Database.Inventory;
|
||||||
using MikuSB.Enums.Item;
|
using MikuSB.Enums.Item;
|
||||||
using MikuSB.Enums.Player;
|
using MikuSB.Enums.Player;
|
||||||
@@ -42,6 +43,7 @@ public class CommandGiveAll : ICommands
|
|||||||
weapons.Add(weapon);
|
weapons.Add(weapon);
|
||||||
}
|
}
|
||||||
if (weapons.Count > 0) await player.SendPacket(new PacketNtfCallScript(weapons));
|
if (weapons.Count > 0) await player.SendPacket(new PacketNtfCallScript(weapons));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.Weapon"), weapons.Count.ToString()));
|
I18NManager.Translate("Word.Weapon"), weapons.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,7 @@ public class CommandGiveAll : ICommands
|
|||||||
supportCards.Add(supportCard);
|
supportCards.Add(supportCard);
|
||||||
}
|
}
|
||||||
if (supportCards.Count > 0) await player.SendPacket(new PacketNtfCallScript(supportCards));
|
if (supportCards.Count > 0) await player.SendPacket(new PacketNtfCallScript(supportCards));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.SupportCard"), supportCards.Count.ToString()));
|
I18NManager.Translate("Word.SupportCard"), supportCards.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -111,6 +114,7 @@ public class CommandGiveAll : ICommands
|
|||||||
weaponSkins.Add(weaponSkin);
|
weaponSkins.Add(weaponSkin);
|
||||||
}
|
}
|
||||||
if (weaponSkins.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponSkins));
|
if (weaponSkins.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponSkins));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.WeaponSkin"), weaponSkins.Count.ToString()));
|
I18NManager.Translate("Word.WeaponSkin"), weaponSkins.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -147,6 +151,7 @@ public class CommandGiveAll : ICommands
|
|||||||
profileItems.Add(profile);
|
profileItems.Add(profile);
|
||||||
}
|
}
|
||||||
if (profileItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(profileItems));
|
if (profileItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(profileItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.Profile"), profileItems.Count.ToString()));
|
I18NManager.Translate("Word.Profile"), profileItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -183,6 +188,7 @@ public class CommandGiveAll : ICommands
|
|||||||
skinPartItems.Add(skinPart);
|
skinPartItems.Add(skinPart);
|
||||||
}
|
}
|
||||||
if (skinPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(skinPartItems));
|
if (skinPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(skinPartItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.SkinPart"), skinPartItems.Count.ToString()));
|
I18NManager.Translate("Word.SkinPart"), skinPartItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -219,6 +225,7 @@ public class CommandGiveAll : ICommands
|
|||||||
callItems.Add(callItem);
|
callItems.Add(callItem);
|
||||||
}
|
}
|
||||||
if (callItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(callItems));
|
if (callItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(callItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.CallItem"), callItems.Count.ToString()));
|
I18NManager.Translate("Word.CallItem"), callItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -255,6 +262,7 @@ public class CommandGiveAll : ICommands
|
|||||||
weaponPartItems.Add(weaponPart);
|
weaponPartItems.Add(weaponPart);
|
||||||
}
|
}
|
||||||
if (weaponPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponPartItems));
|
if (weaponPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponPartItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.WeaponPart"), weaponPartItems.Count.ToString()));
|
I18NManager.Translate("Word.WeaponPart"), weaponPartItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -291,6 +299,7 @@ public class CommandGiveAll : ICommands
|
|||||||
skinItems.Add(skin);
|
skinItems.Add(skin);
|
||||||
}
|
}
|
||||||
if (skinItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(skinItems));
|
if (skinItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(skinItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.Skin"), skinItems.Count.ToString()));
|
I18NManager.Translate("Word.Skin"), skinItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
@@ -327,6 +336,7 @@ public class CommandGiveAll : ICommands
|
|||||||
furnitureItems.Add(furniture);
|
furnitureItems.Add(furniture);
|
||||||
}
|
}
|
||||||
if (furnitureItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(furnitureItems));
|
if (furnitureItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(furnitureItems));
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
I18NManager.Translate("Word.Furniture"), furnitureItems.Count.ToString()));
|
I18NManager.Translate("Word.Furniture"), furnitureItems.Count.ToString()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using MikuSB.Database;
|
|||||||
using MikuSB.Database.Inventory;
|
using MikuSB.Database.Inventory;
|
||||||
using MikuSB.Enums.Item;
|
using MikuSB.Enums.Item;
|
||||||
using MikuSB.GameServer.Game.Player;
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
using MikuSB.GameServer.Server.Packet.Send.Misc;
|
using MikuSB.GameServer.Server.Packet.Send.Misc;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Game.Inventory;
|
namespace MikuSB.GameServer.Game.Inventory;
|
||||||
@@ -135,7 +136,18 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
|||||||
ItemType = genre,
|
ItemType = genre,
|
||||||
ItemCount = 1,
|
ItemCount = 1,
|
||||||
Level = cardLevel,
|
Level = cardLevel,
|
||||||
|
AffixId = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var affixCount = cardLevel >= spCard.MaxLevel ? spCard.TotalAffixCount : spCard.InitialAffixCount;
|
||||||
|
for (int i = 0; i < affixCount && i < spCard.AffixPool.Count; i++)
|
||||||
|
{
|
||||||
|
var (affixId, tier) = SupportAffixService.GenerateRandomAffix(spCard.AffixPool[i]);
|
||||||
|
if (affixId == 0) continue;
|
||||||
|
info.Affixs.Add(affixId);
|
||||||
|
info.Affixs.Add(tier);
|
||||||
|
}
|
||||||
|
|
||||||
InventoryData.SupportCards[info.UniqueId] = info;
|
InventoryData.SupportCards[info.UniqueId] = info;
|
||||||
|
|
||||||
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));
|
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([info]));
|
||||||
|
|||||||
@@ -214,6 +214,10 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
};
|
};
|
||||||
|
|
||||||
foreach (var chara in CharacterManager.CharacterData.Characters) proto.Items.Add(chara.ToProto());
|
foreach (var chara in CharacterManager.CharacterData.Characters) proto.Items.Add(chara.ToProto());
|
||||||
|
foreach (var item in InventoryManager.InventoryData.Items.Values) proto.Items.Add(item.ToProto());
|
||||||
|
foreach (var skin in InventoryManager.InventoryData.Skins.Values) proto.Items.Add(skin.ToProto());
|
||||||
|
foreach (var weapon in InventoryManager.InventoryData.Weapons.Values) proto.Items.Add(weapon.ToProto());
|
||||||
|
foreach (var card in InventoryManager.InventoryData.SupportCards.Values) proto.Items.Add(card.ToProto());
|
||||||
foreach (var x in Data.Attrs)
|
foreach (var x in Data.Attrs)
|
||||||
{
|
{
|
||||||
uint gid = x.Gid;
|
uint gid = x.Gid;
|
||||||
@@ -226,9 +230,7 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ToDo
|
proto.Attrs[ToPackedAttrKey(gid, sid)] = val;
|
||||||
//Temporary fix for login issues(need to handle LoginRsp properly with zlib.)
|
|
||||||
//proto.Attrs[ToPackedAttrKey(gid, sid)] = val;
|
|
||||||
proto.Attrs[ToShiftedAttrKey(gid, sid)] = val;
|
proto.Attrs[ToShiftedAttrKey(gid, sid)] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,20 +327,49 @@ public class PlayerInstance(PlayerGameData data)
|
|||||||
|
|
||||||
private static IEnumerable<(uint Gid, uint Sid, uint Value)> BuildGirlFurnitureAttrs()
|
private static IEnumerable<(uint Gid, uint Sid, uint Value)> BuildGirlFurnitureAttrs()
|
||||||
{
|
{
|
||||||
// Unlock some furniture slots for every girl
|
|
||||||
// Each furniture attr int stores 10 slots using 3 bits per slot
|
|
||||||
// Value below means slot 0..9 = 1
|
|
||||||
const uint furnitureUnlockedValue = 153391689;
|
const uint furnitureUnlockedValue = 153391689;
|
||||||
|
var groupFurnitureByArea = new Dictionary<uint, uint>();
|
||||||
|
foreach (var pos in GameData.HouseFurniturePosData.Values)
|
||||||
|
{
|
||||||
|
var areaId = pos.AreaId;
|
||||||
|
var groupId = pos.GroupId;
|
||||||
|
uint selectedIndex = 1;
|
||||||
|
var shift = (groupId - 1) * 3;
|
||||||
|
if (!groupFurnitureByArea.TryGetValue(areaId, out var packed)) packed = 0;
|
||||||
|
packed |= (selectedIndex << (int)shift);
|
||||||
|
groupFurnitureByArea[areaId] = packed;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint girlId = 0; girlId <= 50; girlId++)
|
for (uint girlId = 0; girlId <= 50; girlId++)
|
||||||
{
|
{
|
||||||
// FurnitureStart..FurnitureEnd = 10..19
|
var baseSid = girlId * 50;
|
||||||
for (uint offset = 10; offset <= 19; offset++)
|
for (uint offset = 10; offset <= 19; offset++)
|
||||||
{
|
yield return (101, baseSid + offset, furnitureUnlockedValue);
|
||||||
uint sid = (girlId * 50) + offset;
|
|
||||||
yield return (101, sid, furnitureUnlockedValue);
|
if (groupFurnitureByArea.TryGetValue(girlId, out var groupValue))
|
||||||
}
|
yield return (101, baseSid + 20, groupValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Massage room furniture
|
||||||
|
// 10010..10019
|
||||||
|
for (uint sid = 10010; sid <= 10019; sid++)
|
||||||
|
yield return (101, sid, furnitureUnlockedValue);
|
||||||
|
|
||||||
|
// Massage room group state
|
||||||
|
yield return (101, 10020, 1);
|
||||||
|
|
||||||
|
// Hot spring furniture
|
||||||
|
// 15001..15010
|
||||||
|
for (uint sid = 15001; sid <= 15010; sid++)
|
||||||
|
yield return (101, sid, furnitureUnlockedValue);
|
||||||
|
|
||||||
|
// Beach furniture
|
||||||
|
// 17101..17110
|
||||||
|
for (uint sid = 17101; sid <= 17110; sid++)
|
||||||
|
yield return (101, sid, furnitureUnlockedValue);
|
||||||
|
|
||||||
|
for (uint sid = 30000; sid < 31000; sid++)
|
||||||
|
yield return (101, sid, furnitureUnlockedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<(uint Gid, uint Sid, uint Value)> BuildLobbyBootstrapAttrs()
|
private static IEnumerable<(uint Gid, uint Sid, uint Value)> BuildLobbyBootstrapAttrs()
|
||||||
|
|||||||
40
GameServer/Game/Support/SupportAffixService.cs
Normal file
40
GameServer/Game/Support/SupportAffixService.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Game.Support;
|
||||||
|
|
||||||
|
public static class SupportAffixService
|
||||||
|
{
|
||||||
|
// Returns (affixId, tier) - both 1-based. Returns (0,0) if pool not found.
|
||||||
|
public static (uint AffixId, uint Tier) GenerateRandomAffix(int poolId)
|
||||||
|
{
|
||||||
|
if (!GameData.SupportAffixPoolData.TryGetValue(poolId, out var pool))
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var groups = pool.Groups.ToList();
|
||||||
|
if (groups.Count == 0)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var totalWeight = groups.Sum(x => x.Weight);
|
||||||
|
var roll = Random.Shared.Next(totalWeight);
|
||||||
|
var cumulative = 0;
|
||||||
|
var selectedAffixs = groups[0].Affixs;
|
||||||
|
|
||||||
|
foreach (var (affixIds, weight) in groups)
|
||||||
|
{
|
||||||
|
cumulative += weight;
|
||||||
|
if (roll < cumulative)
|
||||||
|
{
|
||||||
|
selectedAffixs = affixIds;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedAffixs.Count == 0)
|
||||||
|
return (0, 0);
|
||||||
|
|
||||||
|
var affixId = selectedAffixs[Random.Shared.Next(selectedAffixs.Count)];
|
||||||
|
var tierCount = GameData.SupportAffixData.GetValueOrDefault(affixId)?.TierCount ?? 5;
|
||||||
|
var tier = (uint)(Random.Shared.Next(tierCount) + 1);
|
||||||
|
return ((uint)affixId, tier);
|
||||||
|
}
|
||||||
|
}
|
||||||
296
GameServer/Server/CallGS/Handlers/Girl/GirlCard_UpdateLevel.cs
Normal file
296
GameServer/Server/CallGS/Handlers/Girl/GirlCard_UpdateLevel.cs
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database;
|
||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.Enums.Item;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||||
|
|
||||||
|
[CallGSApi("GirlCard_UpdateLevel")]
|
||||||
|
public class GirlCard_UpdateLevel : ICallGSHandler
|
||||||
|
{
|
||||||
|
private const uint CashGroupId = 1;
|
||||||
|
private const uint SilverMoneyType = 3;
|
||||||
|
private const uint SilverSid = SilverMoneyType * 2 + 1;
|
||||||
|
private const uint RoleMaxLevel = 80;
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var player = connection.Player!;
|
||||||
|
var req = JsonSerializer.Deserialize<GirlCardUpdateLevelParam>(param);
|
||||||
|
if (req == null || req.Id == 0 || req.Materials == null || req.Materials.Count == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var card = player.CharacterManager.GetCharacterByGUID((uint)req.Id);
|
||||||
|
if (card == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cardTemplate = GameData.CardData.Values.FirstOrDefault(x =>
|
||||||
|
GameResourceTemplateId.FromGdpl(x.Genre, x.Detail, x.Particular, x.Level) == card.TemplateId);
|
||||||
|
if (cardTemplate == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var levelCap = GetCardLevelCap(player.Data.Level, cardTemplate.LevelLimitID);
|
||||||
|
if (levelCap == 0)
|
||||||
|
{
|
||||||
|
levelCap = card.Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (card.Level >= RoleMaxLevel)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.card_max_level\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestedMaterials = new Dictionary<uint, uint>();
|
||||||
|
foreach (var row in req.Materials)
|
||||||
|
{
|
||||||
|
if (row == null || row.Id == 0 || row.Num == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
requestedMaterials[(uint)row.Id] = requestedMaterials.GetValueOrDefault((uint)row.Id) + row.Num;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (requestedMaterials.Count == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ulong totalExp = 0;
|
||||||
|
ulong totalSilverCost = 0;
|
||||||
|
foreach (var (itemId, count) in requestedMaterials)
|
||||||
|
{
|
||||||
|
var item = player.InventoryManager.GetNormalItem(itemId);
|
||||||
|
if (item == null || item.ItemCount < count)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GameData.SuppliesData.TryGetValue((uint)item.TemplateId, out var supplies) || supplies.ProvideExp == 0)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalExp += (ulong)supplies.ProvideExp * count;
|
||||||
|
totalSilverCost += (ulong)supplies.ConsumeGold * count;
|
||||||
|
}
|
||||||
|
|
||||||
|
var silverAttr = GetOrCreateAttr(player.Data, CashGroupId, SilverSid);
|
||||||
|
if ((ulong)silverAttr.Val < totalSilverCost)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "{\"sErr\":\"tip.material_not_enough\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var syncItems = new List<Item>();
|
||||||
|
foreach (var (itemId, count) in requestedMaterials)
|
||||||
|
{
|
||||||
|
var item = player.InventoryManager.GetNormalItem(itemId)!;
|
||||||
|
item.ItemCount -= count;
|
||||||
|
|
||||||
|
if (item.ItemCount == 0)
|
||||||
|
{
|
||||||
|
player.InventoryManager.InventoryData.Items.Remove(item.UniqueId);
|
||||||
|
syncItems.Add(BuildRemovedProto(item));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
syncItems.Add(item.ToProto());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
silverAttr.Val -= checked((uint)totalSilverCost);
|
||||||
|
|
||||||
|
var (newLevel, newExp) = ApplyCardExp(card.Level, card.Exp, totalExp, levelCap);
|
||||||
|
card.Level = newLevel;
|
||||||
|
card.Exp = checked((int)newExp);
|
||||||
|
syncItems.Add(card.ToProto());
|
||||||
|
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.InventoryManager.InventoryData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.CharacterManager.CharacterData);
|
||||||
|
DatabaseHelper.SaveDatabaseType(player.Data);
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
sync.Items.AddRange(syncItems);
|
||||||
|
sync.Custom[player.ToPackedAttrKey(CashGroupId, SilverSid)] = silverAttr.Val;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(CashGroupId, SilverSid)] = silverAttr.Val;
|
||||||
|
|
||||||
|
await CallGSRouter.SendScript(connection, "GirlCard_UpdateLevel", "null", sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PlayerAttr GetOrCreateAttr(PlayerGameData data, uint gid, uint sid)
|
||||||
|
{
|
||||||
|
var attr = data.Attrs.FirstOrDefault(x => x.Gid == gid && x.Sid == sid);
|
||||||
|
if (attr != null)
|
||||||
|
return attr;
|
||||||
|
|
||||||
|
attr = new PlayerAttr
|
||||||
|
{
|
||||||
|
Gid = gid,
|
||||||
|
Sid = sid,
|
||||||
|
Val = 0
|
||||||
|
};
|
||||||
|
data.Attrs.Add(attr);
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Item BuildRemovedProto(BaseGameItemInfo item)
|
||||||
|
{
|
||||||
|
var proto = item.ToProto();
|
||||||
|
proto.Count = 0;
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetCardLevelCap(uint playerLevel, int levelLimitId)
|
||||||
|
{
|
||||||
|
var limits = LoadCardLevelLimit(levelLimitId);
|
||||||
|
if (limits.Count == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint nearestAccountLevel = 0;
|
||||||
|
uint nearestCardLevel = 0;
|
||||||
|
|
||||||
|
foreach (var (accountLevel, cardLevel) in limits)
|
||||||
|
{
|
||||||
|
if (accountLevel < playerLevel)
|
||||||
|
{
|
||||||
|
nearestAccountLevel = accountLevel;
|
||||||
|
nearestCardLevel = cardLevel;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (accountLevel == playerLevel)
|
||||||
|
return Math.Min(cardLevel, RoleMaxLevel);
|
||||||
|
|
||||||
|
var distance = accountLevel - nearestAccountLevel;
|
||||||
|
if (distance == 0)
|
||||||
|
return Math.Min(cardLevel, RoleMaxLevel);
|
||||||
|
|
||||||
|
var percent = (playerLevel - nearestAccountLevel) / (double)distance;
|
||||||
|
var interpolated = (uint)Math.Floor(nearestCardLevel + ((cardLevel - nearestCardLevel) * percent));
|
||||||
|
return Math.Min(interpolated, RoleMaxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.Min(nearestCardLevel, RoleMaxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<(uint AccountLevel, uint CardLevel)> LoadCardLevelLimit(int levelLimitId)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(
|
||||||
|
AppContext.BaseDirectory,
|
||||||
|
"Resources",
|
||||||
|
"item",
|
||||||
|
"level_limit.json");
|
||||||
|
|
||||||
|
if (!File.Exists(path))
|
||||||
|
return [];
|
||||||
|
|
||||||
|
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||||
|
var result = new List<(uint AccountLevel, uint CardLevel)>();
|
||||||
|
|
||||||
|
foreach (var row in doc.RootElement.EnumerateArray())
|
||||||
|
{
|
||||||
|
if (!row.TryGetProperty("ID", out var idProp) || idProp.GetInt32() != levelLimitId)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!row.TryGetProperty("Type", out var typeProp) || typeProp.GetInt32() != 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!row.TryGetProperty("Limit", out var limitProp) || limitProp.ValueKind != JsonValueKind.Object)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var property in limitProp.EnumerateObject())
|
||||||
|
{
|
||||||
|
if (!uint.TryParse(property.Name, out var accountLevel))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint cardLevel;
|
||||||
|
if (property.Value.ValueKind == JsonValueKind.Number)
|
||||||
|
{
|
||||||
|
cardLevel = property.Value.GetUInt32();
|
||||||
|
}
|
||||||
|
else if (property.Value.ValueKind == JsonValueKind.String &&
|
||||||
|
uint.TryParse(property.Value.GetString(), out var parsed))
|
||||||
|
{
|
||||||
|
cardLevel = parsed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add((accountLevel, cardLevel));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Sort((a, b) => a.AccountLevel.CompareTo(b.AccountLevel));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (uint Level, ulong Exp) ApplyCardExp(uint level, int currentExp, ulong addedExp, uint levelCap)
|
||||||
|
{
|
||||||
|
var destLevel = level == 0 ? 1u : level;
|
||||||
|
var destExp = (ulong)Math.Max(0, currentExp) + addedExp;
|
||||||
|
|
||||||
|
if (levelCap > 0 && destLevel >= levelCap)
|
||||||
|
return (destLevel, destExp);
|
||||||
|
|
||||||
|
while (destLevel < RoleMaxLevel)
|
||||||
|
{
|
||||||
|
var needExp = GetCardNeedExp(destLevel);
|
||||||
|
if (needExp == 0 || destExp < needExp)
|
||||||
|
break;
|
||||||
|
|
||||||
|
destExp -= needExp;
|
||||||
|
destLevel++;
|
||||||
|
|
||||||
|
if (levelCap > 0 && destLevel >= levelCap)
|
||||||
|
return (levelCap, destExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (destLevel, destExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetCardNeedExp(uint currentLevel)
|
||||||
|
{
|
||||||
|
if (GameData.UpgradeExpData.TryGetValue((int)currentLevel, out var row))
|
||||||
|
return row.CardNeedExp;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GirlCardUpdateLevelParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("tbMaterials")]
|
||||||
|
public List<GirlCardLevelMaterial> Materials { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class GirlCardLevelMaterial
|
||||||
|
{
|
||||||
|
[JsonPropertyName("Id")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("Num")]
|
||||||
|
public uint Num { get; set; }
|
||||||
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
using MikuSB.Util.Extensions;
|
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
|
||||||
|
|
||||||
// Client requests server time to calculate timezone offset.
|
// Client requests server time to calculate timezone offset.
|
||||||
// nTime1/nTime2 are DST transition reference timestamps; returning the same value means no offset.
|
// In the client, ZoneTime.lua hardcodes sTime1/sTime2; if nTime1/nTime2 are false, the client ignores this update.
|
||||||
|
// Otherwise, offset = nTimeX - ParseTimeNative(sTimeX).
|
||||||
[CallGSApi("ZoneTime_ReqTime")]
|
[CallGSApi("ZoneTime_ReqTime")]
|
||||||
public class ZoneTime_ReqTime : ICallGSHandler
|
public class ZoneTime_ReqTime : ICallGSHandler
|
||||||
{
|
{
|
||||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
{
|
{
|
||||||
var now = Extensions.GetUnixSec();
|
var arg = $"{{\"nTime1\":false,\"nTime2\":false}}";
|
||||||
var arg = $"{{\"nTime1\":{now},\"nTime2\":{now}}}";
|
|
||||||
await CallGSRouter.SendScript(connection, "ZoneTime_ChangeTime", arg);
|
await CallGSRouter.SendScript(connection, "ZoneTime_ChangeTime", arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using MikuSB.Data;
|
using MikuSB.Data;
|
||||||
using MikuSB.Database;
|
using MikuSB.Database;
|
||||||
|
using MikuSB.GameServer.Game.Support;
|
||||||
using MikuSB.Proto;
|
using MikuSB.Proto;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@@ -19,7 +20,7 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportCard = player.InventoryManager.InventoryData.Items.GetValueOrDefault((uint)req.SupportCardUid);
|
var supportCard = player.InventoryManager.GetSupportCardItem((uint)req.SupportCardUid);
|
||||||
if (supportCard == null)
|
if (supportCard == null)
|
||||||
{
|
{
|
||||||
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
await CallGSRouter.SendScript(connection, "Logistics_Upgrade", "{}");
|
||||||
@@ -68,10 +69,11 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply exp and level up
|
// Apply exp and level up
|
||||||
|
if (supportCard.Level == 0) supportCard.Level = 1;
|
||||||
supportCard.Exp += gainedExp;
|
supportCard.Exp += gainedExp;
|
||||||
while (supportCard.Level < maxLevel)
|
while (supportCard.Level < maxLevel)
|
||||||
{
|
{
|
||||||
var expNeeded = GetExpNeeded(supportCard.Level + 1);
|
var expNeeded = GetExpNeeded(supportCard.Level);
|
||||||
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
|
if (expNeeded == 0 || supportCard.Exp < expNeeded) break;
|
||||||
supportCard.Exp -= expNeeded;
|
supportCard.Exp -= expNeeded;
|
||||||
supportCard.Level++;
|
supportCard.Level++;
|
||||||
@@ -80,6 +82,23 @@ public class SupporterCard_Upgrade : ICallGSHandler
|
|||||||
{
|
{
|
||||||
supportCard.Exp = 0;
|
supportCard.Exp = 0;
|
||||||
supportCard.Level = maxLevel;
|
supportCard.Level = maxLevel;
|
||||||
|
|
||||||
|
// Unlock next affix slot when reaching max level for the first time
|
||||||
|
if (supportCardExcel != null)
|
||||||
|
{
|
||||||
|
var currentSlots = supportCard.Affixs.Count / 2;
|
||||||
|
var totalSlots = supportCardExcel.TotalAffixCount;
|
||||||
|
if (currentSlots < totalSlots && currentSlots < supportCardExcel.AffixPool.Count)
|
||||||
|
{
|
||||||
|
var poolId = supportCardExcel.AffixPool[currentSlots];
|
||||||
|
var (affixId, tier) = SupportAffixService.GenerateRandomAffix(poolId);
|
||||||
|
if (affixId > 0)
|
||||||
|
{
|
||||||
|
supportCard.Affixs.Add(affixId);
|
||||||
|
supportCard.Affixs.Add(tier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncItems.Add(supportCard.ToProto());
|
syncItems.Add(supportCard.ToProto());
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ 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;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
||||||
@@ -18,21 +20,45 @@ namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
|||||||
[Opcode(CmdIds.ReqLogin)]
|
[Opcode(CmdIds.ReqLogin)]
|
||||||
public class HandlerReqLogin : Handler
|
public class HandlerReqLogin : Handler
|
||||||
{
|
{
|
||||||
|
private static readonly Logger Logger = new("ReqLogin");
|
||||||
|
|
||||||
|
private static string? ExtractSdkAuthToken(string? token)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(token))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var normalized = Uri.UnescapeDataString(token).Trim();
|
||||||
|
var padding = normalized.Length % 4;
|
||||||
|
if (padding > 0)
|
||||||
|
normalized = normalized.PadRight(normalized.Length + (4 - padding), '=');
|
||||||
|
|
||||||
|
var json = Encoding.UTF8.GetString(Convert.FromBase64String(normalized));
|
||||||
|
using var document = JsonDocument.Parse(json);
|
||||||
|
return document.RootElement.TryGetProperty("authToken", out var authToken)
|
||||||
|
? authToken.GetString()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override async Task OnHandle(Connection connection, byte[] data, ushort seqNo)
|
public override async Task OnHandle(Connection connection, byte[] data, ushort seqNo)
|
||||||
{
|
{
|
||||||
var req = ReqLogin.Parser.ParseFrom(data);
|
var req = ReqLogin.Parser.ParseFrom(data);
|
||||||
|
var sdkAuthToken = ExtractSdkAuthToken(req.Token);
|
||||||
var account = AccountData.GetAccountByComboToken(req.Token)
|
var account = AccountData.GetAccountByComboToken(req.Token)
|
||||||
?? AccountData.GetAccountByDispatchToken(req.Token)
|
?? AccountData.GetAccountByDispatchToken(req.Token)
|
||||||
?? AccountData.GetAccountByUid(10001)
|
?? AccountData.GetAccountByComboToken(sdkAuthToken ?? "")
|
||||||
?? AccountData.GetAccountByUid(1);
|
?? AccountData.GetAccountByDispatchToken(sdkAuthToken ?? "");
|
||||||
if (account == null)
|
if (account == null)
|
||||||
{
|
{
|
||||||
account = AccountData.CreateAccount("default@mikusb.local", 10001, "");
|
Logger.Warn($"Rejected login: provider={req.Provider}, token={req.Token}, authToken={sdkAuthToken}");
|
||||||
if (account == null)
|
await connection.SendPacket(CmdIds.NtfLogout);
|
||||||
{
|
return;
|
||||||
await connection.SendPacket(CmdIds.NtfLogout);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!ResourceManager.IsLoaded)
|
if (!ResourceManager.IsLoaded)
|
||||||
// resource manager not loaded, return
|
// resource manager not loaded, return
|
||||||
@@ -61,7 +87,6 @@ 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!);
|
ApplySavedGirlSkinTypes(connection.Player!);
|
||||||
await connection.SendPacket(new PacketNtfCallScript(connection.Player!.InventoryManager.InventoryData));
|
|
||||||
await SendGirlSkinTypeOnLogin(connection);
|
await SendGirlSkinTypeOnLogin(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class PacketRspLogin : BasePacket
|
|||||||
};
|
};
|
||||||
|
|
||||||
var bytes = Google.Protobuf.MessageExtensions.ToByteArray(proto);
|
var bytes = Google.Protobuf.MessageExtensions.ToByteArray(proto);
|
||||||
Logger.Info($"RspLogin proto size: {bytes.Length} bytes (limit: 65535)");
|
Logger.Info($"RspLogin proto size: {bytes.Length} bytes");
|
||||||
|
|
||||||
SetData(bytes);
|
SetData(bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public static class GameLaunchService
|
|||||||
public static int Launch(params string[] extraGameArguments)
|
public static int Launch(params string[] extraGameArguments)
|
||||||
{
|
{
|
||||||
ConfigManager.LoadConfig();
|
ConfigManager.LoadConfig();
|
||||||
|
PatchDownloadService.EnsurePatchPresent();
|
||||||
var options = LaunchOptions.FromConfig(extraGameArguments);
|
var options = LaunchOptions.FromConfig(extraGameArguments);
|
||||||
return Launch(options);
|
return Launch(options);
|
||||||
}
|
}
|
||||||
@@ -292,11 +293,14 @@ public sealed class LaunchOptions
|
|||||||
public static LaunchOptions FromConfig(IEnumerable<string>? extraGameArguments = null)
|
public static LaunchOptions FromConfig(IEnumerable<string>? extraGameArguments = null)
|
||||||
{
|
{
|
||||||
var config = ConfigManager.Config;
|
var config = ConfigManager.Config;
|
||||||
|
var serverBaseDirectory = AppContext.BaseDirectory;
|
||||||
var gamePath = ResolvePath(config.Loader.GamePath, AppContext.BaseDirectory);
|
var gamePath = ResolvePath(config.Loader.GamePath, AppContext.BaseDirectory);
|
||||||
var patchPaths = ResolvePatchPaths(config.Loader.PatchPaths, AppContext.BaseDirectory);
|
var patchPaths = ResolvePatchPaths(config.Loader.PatchPaths, serverBaseDirectory);
|
||||||
var gameArgs = new List<string>(config.Loader.Arguments ?? []);
|
var gameArgs = new List<string>(config.Loader.Arguments ?? []);
|
||||||
if (extraGameArguments is not null)
|
if (extraGameArguments is not null)
|
||||||
gameArgs.AddRange(extraGameArguments.Where(x => !string.IsNullOrWhiteSpace(x)));
|
gameArgs.AddRange(extraGameArguments.Where(x => !string.IsNullOrWhiteSpace(x)));
|
||||||
|
gameArgs = EnsureUserDirArgument(gameArgs, serverBaseDirectory);
|
||||||
|
PersistResolvedArgumentsIfChanged(config, gameArgs);
|
||||||
|
|
||||||
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
if (config.Loader.SetAllProxy && config.Proxy.Enabled)
|
if (config.Loader.SetAllProxy && config.Proxy.Enabled)
|
||||||
@@ -329,6 +333,31 @@ public sealed class LaunchOptions
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<string> EnsureUserDirArgument(List<string> gameArgs, string baseDirectory)
|
||||||
|
{
|
||||||
|
var userDataDirectory = Path.GetFullPath(Path.Combine(baseDirectory, "Client_User_Data"));
|
||||||
|
Directory.CreateDirectory(userDataDirectory);
|
||||||
|
|
||||||
|
var userDirArgument = $"-userdir={userDataDirectory}";
|
||||||
|
var existingIndex = gameArgs.FindIndex(x => x.StartsWith("-userdir=", StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingIndex >= 0)
|
||||||
|
gameArgs[existingIndex] = userDirArgument;
|
||||||
|
else
|
||||||
|
gameArgs.Add(userDirArgument);
|
||||||
|
|
||||||
|
return gameArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PersistResolvedArgumentsIfChanged(Configuration.ConfigContainer config, List<string> gameArgs)
|
||||||
|
{
|
||||||
|
var currentArgs = config.Loader.Arguments ?? [];
|
||||||
|
if (currentArgs.SequenceEqual(gameArgs, StringComparer.Ordinal))
|
||||||
|
return;
|
||||||
|
|
||||||
|
config.Loader.Arguments = gameArgs.ToArray();
|
||||||
|
ConfigManager.SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
private static string? ResolvePath(string? value, string baseDirectory)
|
private static string? ResolvePath(string? value, string baseDirectory)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(value))
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
|||||||
@@ -22,16 +22,35 @@ public class LoaderManager : MikuSB
|
|||||||
public static void InitConfig()
|
public static void InitConfig()
|
||||||
{
|
{
|
||||||
// Initialize log
|
// Initialize log
|
||||||
var counter = 0;
|
var logDir = ConfigManager.Config.Path.LogPath;
|
||||||
FileInfo file;
|
var logFile = new FileInfo(Path.Combine(logDir, "Server.log"));
|
||||||
while (true)
|
logFile.Directory?.Create();
|
||||||
|
|
||||||
|
if (logFile.Exists)
|
||||||
{
|
{
|
||||||
file = new FileInfo(ConfigManager.Config.Path.LogPath + $"/{DateTime.Now:yyyy-MM-dd}-{++counter}.log");
|
// Read start time from first log line, fall back to file creation time
|
||||||
if (file is not { Exists: false, Directory: not null }) continue;
|
DateTime logStartTime;
|
||||||
file.Directory.Create();
|
try
|
||||||
break;
|
{
|
||||||
|
var firstLine = File.ReadLines(logFile.FullName).FirstOrDefault() ?? "";
|
||||||
|
// Format: [HH:mm:ss] ...
|
||||||
|
var timeStr = firstLine.Length >= 10 ? firstLine[1..9] : "";
|
||||||
|
var dateStr = logFile.CreationTime.ToString("yyyy-MM-dd");
|
||||||
|
logStartTime = DateTime.TryParse($"{dateStr} {timeStr}", out var parsed)
|
||||||
|
? parsed
|
||||||
|
: logFile.CreationTime;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
logStartTime = logFile.CreationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
var backupName = $"Server-backup-{logStartTime:yyyy.MM.dd-HH.mm.ss}.log";
|
||||||
|
var backupFile = new FileInfo(Path.Combine(logDir, backupName));
|
||||||
|
logFile.MoveTo(backupFile.FullName, overwrite: true);
|
||||||
}
|
}
|
||||||
Logger.SetLogFile(file);
|
|
||||||
|
Logger.SetLogFile(new FileInfo(Path.Combine(logDir, "Server.log")));
|
||||||
|
|
||||||
// Init all directories
|
// Init all directories
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ dotnet build
|
|||||||
```
|
```
|
||||||
2. Set `GamePath` in `Config.json` to the path of your game executable.
|
2. Set `GamePath` in `Config.json` to the path of your game executable.
|
||||||
3. Start the server and run the `game` command.
|
3. Start the server and run the `game` command.
|
||||||
4. Enjoy.
|
4. Create an account in the server console.
|
||||||
|
5. Enjoy.
|
||||||
|
|
||||||
## Feature List
|
## Feature List
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ dotnet build
|
|||||||
```
|
```
|
||||||
2. Config.json の`GamePath`にあなたのゲームの実行ファイルのパスを書き込みます
|
2. Config.json の`GamePath`にあなたのゲームの実行ファイルのパスを書き込みます
|
||||||
3. サーバーを起動し`game`コマンドを入力します
|
3. サーバーを起動し`game`コマンドを入力します
|
||||||
4. 楽しむ
|
4. サーバーコンソールでアカウントを作成する
|
||||||
|
5. 楽しむ
|
||||||
|
|
||||||
## 機能一覧
|
## 機能一覧
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using MikuSB.Configuration;
|
using MikuSB.Configuration;
|
||||||
using MikuSB.Database.Account;
|
using MikuSB.Database.Account;
|
||||||
@@ -13,8 +14,6 @@ public class RouteController : ControllerBase
|
|||||||
{
|
{
|
||||||
public static ConfigContainer Config = ConfigManager.Config;
|
public static ConfigContainer Config = ConfigManager.Config;
|
||||||
|
|
||||||
private const int DefaultAccountUid = 10001;
|
|
||||||
|
|
||||||
public static object BuildServerList(string version = "")
|
public static object BuildServerList(string version = "")
|
||||||
{
|
{
|
||||||
return new
|
return new
|
||||||
@@ -129,29 +128,15 @@ public class RouteController : ControllerBase
|
|||||||
return Ok(rsp);
|
return Ok(rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AccountData EnsureDefaultAccount()
|
private static AccountData? ResolveAccountByUid(string? uid)
|
||||||
{
|
|
||||||
var account = AccountData.GetAccountByUid(DefaultAccountUid)
|
|
||||||
?? AccountData.GetAccountByEmail("default@mikusb.local");
|
|
||||||
if (account != null)
|
|
||||||
return account;
|
|
||||||
|
|
||||||
return AccountData.CreateAccount("default@mikusb.local", DefaultAccountUid, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AccountData ResolveAccountByUid(string? uid)
|
|
||||||
{
|
{
|
||||||
if (int.TryParse(uid, out var parsedUid))
|
if (int.TryParse(uid, out var parsedUid))
|
||||||
{
|
return AccountData.GetAccountByUid(parsedUid);
|
||||||
var accountByUid = AccountData.GetAccountByUid(parsedUid);
|
|
||||||
if (accountByUid != null)
|
|
||||||
return accountByUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EnsureDefaultAccount();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AccountData ResolveAccountForSdkLogin(string? email, string? uid, string? token)
|
private static AccountData? ResolveAccountForSdkLogin(string? email, string? uid, string? token)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(token))
|
if (!string.IsNullOrWhiteSpace(token))
|
||||||
{
|
{
|
||||||
@@ -174,18 +159,78 @@ public class RouteController : ControllerBase
|
|||||||
return ResolveAccountByUid(uid);
|
return ResolveAccountByUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<string?> GetJsonBodyValue(string propertyName)
|
||||||
|
{
|
||||||
|
if (!Request.HasJsonContentType())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Request.EnableBuffering();
|
||||||
|
Request.Body.Position = 0;
|
||||||
|
|
||||||
|
using var reader = new StreamReader(Request.Body, Encoding.UTF8, leaveOpen: true);
|
||||||
|
var body = await reader.ReadToEndAsync();
|
||||||
|
Request.Body.Position = 0;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(body))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var document = JsonDocument.Parse(body);
|
||||||
|
if (document.RootElement.ValueKind != JsonValueKind.Object)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return document.RootElement.TryGetProperty(propertyName, out var value)
|
||||||
|
? value.GetString()
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IActionResult BuildLoginFailedResponse(string message)
|
||||||
|
{
|
||||||
|
object rsp = new
|
||||||
|
{
|
||||||
|
code = 1001,
|
||||||
|
data = (object?)null,
|
||||||
|
msg = message
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IActionResult BuildNotFoundResponse(string message)
|
||||||
|
{
|
||||||
|
object rsp = new
|
||||||
|
{
|
||||||
|
code = 1001,
|
||||||
|
data = (object?)null,
|
||||||
|
msg = message
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(rsp);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet("/seasun/loginByToken")]
|
[HttpGet("/seasun/loginByToken")]
|
||||||
[HttpPost("/seasun/loginByToken")]
|
[HttpPost("/seasun/loginByToken")]
|
||||||
public IActionResult LoginByToken(
|
public async Task<IActionResult> LoginByToken(
|
||||||
[FromQuery] string? uid,
|
[FromQuery] string? uid,
|
||||||
[FromQuery] string? token,
|
[FromQuery] string? token,
|
||||||
[FromForm] string? form_uid,
|
[FromForm] string? form_uid,
|
||||||
[FromForm] string? form_token
|
[FromForm] string? form_token
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var account = ResolveAccountForSdkLogin(null, uid ?? form_uid, token ?? form_token);
|
var finalUid = uid ?? form_uid ?? await GetJsonBodyValue("uid");
|
||||||
var finalUid = account.Uid.ToString();
|
var finalToken = token ?? form_token ?? await GetJsonBodyValue("token");
|
||||||
var finalToken = account.GenerateComboToken();
|
var account = ResolveAccountForSdkLogin(null, finalUid, finalToken);
|
||||||
|
if (account == null)
|
||||||
|
return BuildLoginFailedResponse("Account not found.");
|
||||||
|
|
||||||
|
var responseUid = account.Uid.ToString();
|
||||||
|
var responseToken = account.GenerateComboToken();
|
||||||
|
|
||||||
object rsp = new
|
object rsp = new
|
||||||
{
|
{
|
||||||
@@ -195,13 +240,13 @@ public class RouteController : ControllerBase
|
|||||||
associatedAccounts = Array.Empty<string>(),
|
associatedAccounts = Array.Empty<string>(),
|
||||||
isFirstLogin = false,
|
isFirstLogin = false,
|
||||||
isNeedKoreaSciAuth = false,
|
isNeedKoreaSciAuth = false,
|
||||||
ksOpenId = $"ks_{finalUid}",
|
ksOpenId = $"ks_{responseUid}",
|
||||||
nickname = account.Username,
|
nickname = account.Username,
|
||||||
passportId = finalUid,
|
passportId = responseUid,
|
||||||
playerFillAgeUrl = "",
|
playerFillAgeUrl = "",
|
||||||
status = 0,
|
status = 0,
|
||||||
thirdPartyUid = "",
|
thirdPartyUid = "",
|
||||||
token = finalToken,
|
token = responseToken,
|
||||||
type = "guest",
|
type = "guest",
|
||||||
uid = account.Uid
|
uid = account.Uid
|
||||||
},
|
},
|
||||||
@@ -213,7 +258,7 @@ public class RouteController : ControllerBase
|
|||||||
|
|
||||||
[HttpGet("/seasun/login")]
|
[HttpGet("/seasun/login")]
|
||||||
[HttpPost("/seasun/login")]
|
[HttpPost("/seasun/login")]
|
||||||
public IActionResult Login(
|
public async Task<IActionResult> Login(
|
||||||
[FromQuery] string? uid,
|
[FromQuery] string? uid,
|
||||||
[FromQuery] string? token,
|
[FromQuery] string? token,
|
||||||
[FromQuery] string? email,
|
[FromQuery] string? email,
|
||||||
@@ -222,10 +267,53 @@ public class RouteController : ControllerBase
|
|||||||
[FromForm] string? form_email
|
[FromForm] string? form_email
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var finalEmail = email ?? form_email;
|
var finalEmail = email ?? form_email ?? await GetJsonBodyValue("email");
|
||||||
var account = ResolveAccountForSdkLogin(finalEmail, uid ?? form_uid, token ?? form_token);
|
if (!string.IsNullOrWhiteSpace(finalEmail))
|
||||||
var finalUid = account.Uid.ToString();
|
{
|
||||||
var finalToken = account.GenerateComboToken();
|
var normalizedEmail = finalEmail.Trim();
|
||||||
|
var accountData = AccountData.GetAccountByEmail(normalizedEmail);
|
||||||
|
if (accountData == null)
|
||||||
|
{
|
||||||
|
if (!ConfigManager.Config.ServerOption.AutoCreateUser) return BuildLoginFailedResponse("Account not found.");
|
||||||
|
AccountData.CreateAccount(normalizedEmail, 0, "123456");
|
||||||
|
accountData = AccountData.GetAccountByEmail(normalizedEmail)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalUidValue = accountData.Uid.ToString();
|
||||||
|
var finalTokenValue = accountData.GenerateComboToken();
|
||||||
|
|
||||||
|
object emailLoginRsp = new
|
||||||
|
{
|
||||||
|
code = 0,
|
||||||
|
data = new
|
||||||
|
{
|
||||||
|
associatedAccounts = Array.Empty<string>(),
|
||||||
|
isFirstLogin = false,
|
||||||
|
isNeedKoreaSciAuth = false,
|
||||||
|
ksOpenId = $"ks_{finalUidValue}",
|
||||||
|
nickname = accountData.Username,
|
||||||
|
passportId = finalUidValue,
|
||||||
|
playerFillAgeUrl = "",
|
||||||
|
status = 0,
|
||||||
|
thirdPartyUid = "",
|
||||||
|
token = finalTokenValue,
|
||||||
|
type = "guest",
|
||||||
|
uid = accountData.Uid
|
||||||
|
},
|
||||||
|
msg = "操作成功"
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(emailLoginRsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalUid = uid ?? form_uid ?? await GetJsonBodyValue("uid");
|
||||||
|
var finalToken = token ?? form_token ?? await GetJsonBodyValue("token");
|
||||||
|
var account = ResolveAccountForSdkLogin(finalEmail, finalUid, finalToken);
|
||||||
|
if (account == null)
|
||||||
|
return BuildLoginFailedResponse("Account not found.");
|
||||||
|
|
||||||
|
var responseUid = account.Uid.ToString();
|
||||||
|
var responseToken = account.GenerateComboToken();
|
||||||
|
|
||||||
object rsp = new
|
object rsp = new
|
||||||
{
|
{
|
||||||
@@ -235,13 +323,13 @@ public class RouteController : ControllerBase
|
|||||||
associatedAccounts = Array.Empty<string>(),
|
associatedAccounts = Array.Empty<string>(),
|
||||||
isFirstLogin = false,
|
isFirstLogin = false,
|
||||||
isNeedKoreaSciAuth = false,
|
isNeedKoreaSciAuth = false,
|
||||||
ksOpenId = $"ks_{finalUid}",
|
ksOpenId = $"ks_{responseUid}",
|
||||||
nickname = account.Username,
|
nickname = account.Username,
|
||||||
passportId = finalUid,
|
passportId = responseUid,
|
||||||
playerFillAgeUrl = "",
|
playerFillAgeUrl = "",
|
||||||
status = 0,
|
status = 0,
|
||||||
thirdPartyUid = "",
|
thirdPartyUid = "",
|
||||||
token = finalToken,
|
token = responseToken,
|
||||||
type = "guest",
|
type = "guest",
|
||||||
uid = account.Uid
|
uid = account.Uid
|
||||||
},
|
},
|
||||||
@@ -259,6 +347,9 @@ public class RouteController : ControllerBase
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
var account = ResolveAccountByUid(uid ?? form_uid);
|
var account = ResolveAccountByUid(uid ?? form_uid);
|
||||||
|
if (account == null)
|
||||||
|
return BuildNotFoundResponse("Account not found.");
|
||||||
|
|
||||||
var uidString = account.Uid.ToString();
|
var uidString = account.Uid.ToString();
|
||||||
|
|
||||||
object rsp = new
|
object rsp = new
|
||||||
@@ -338,7 +429,11 @@ public class RouteController : ControllerBase
|
|||||||
[HttpGet("/account/query-uid/{appId}")]
|
[HttpGet("/account/query-uid/{appId}")]
|
||||||
public IActionResult QueryUid(string appId, [FromQuery] string authInfo)
|
public IActionResult QueryUid(string appId, [FromQuery] string authInfo)
|
||||||
{
|
{
|
||||||
var uid = ResolveAccountByUid(ExtractUid(authInfo)).Uid.ToString();
|
var account = ResolveAccountByUid(ExtractUid(authInfo));
|
||||||
|
if (account == null)
|
||||||
|
return BuildNotFoundResponse("Account not found.");
|
||||||
|
|
||||||
|
var uid = account.Uid.ToString();
|
||||||
|
|
||||||
object rsp = new
|
object rsp = new
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,34 +1,108 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using MikuSB.Util;
|
using MikuSB.Util;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace MikuSB.SdkServer.Utils;
|
namespace MikuSB.SdkServer.Utils;
|
||||||
|
|
||||||
public class RequestLoggingMiddleware(RequestDelegate next)
|
public class RequestLoggingMiddleware(RequestDelegate next)
|
||||||
{
|
{
|
||||||
|
private const long MaxLoggedBodyBytes = 1024 * 1024;
|
||||||
|
|
||||||
|
private static bool ShouldSkip(string path)
|
||||||
|
=> path.StartsWith("/report") || path.Contains("/log/") || path == "/alive";
|
||||||
|
|
||||||
|
private static bool ShouldLogBody(HttpRequest request)
|
||||||
|
{
|
||||||
|
if (request.ContentLength is null or 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (request.ContentLength > MaxLoggedBodyBytes)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(request.ContentType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return request.ContentType.Contains("json", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| request.ContentType.Contains("text", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| request.ContentType.Contains("xml", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| request.ContentType.Contains("x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string SanitizeForLog(string value)
|
||||||
|
{
|
||||||
|
var builder = new StringBuilder(value.Length);
|
||||||
|
foreach (var ch in value)
|
||||||
|
{
|
||||||
|
if (ch == '\r')
|
||||||
|
{
|
||||||
|
builder.Append(@"\r");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == '\n')
|
||||||
|
{
|
||||||
|
builder.Append(@"\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (char.IsControl(ch))
|
||||||
|
{
|
||||||
|
builder.Append(@"\u");
|
||||||
|
builder.Append(((int)ch).ToString("x4"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.Append(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task<string> ReadBodyAsString(HttpRequest request)
|
||||||
|
{
|
||||||
|
request.EnableBuffering();
|
||||||
|
request.Body.Position = 0;
|
||||||
|
|
||||||
|
using var reader = new StreamReader(request.Body, Encoding.UTF8, leaveOpen: true);
|
||||||
|
var body = await reader.ReadToEndAsync();
|
||||||
|
|
||||||
|
request.Body.Position = 0;
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task InvokeAsync(HttpContext context, Logger logger)
|
public async Task InvokeAsync(HttpContext context, Logger logger)
|
||||||
{
|
{
|
||||||
var request = context.Request;
|
var request = context.Request;
|
||||||
var method = request.Method;
|
var method = request.Method;
|
||||||
var path = request.Path + request.QueryString;
|
var path = request.Path.ToString();
|
||||||
|
var pathWithQuery = path + request.QueryString;
|
||||||
|
|
||||||
|
if (ConfigManager.Config.HttpServer.EnableLog && !ShouldSkip(path))
|
||||||
|
{
|
||||||
|
var body = ShouldLogBody(request)
|
||||||
|
? SanitizeForLog(await ReadBodyAsString(request))
|
||||||
|
: "<omitted>";
|
||||||
|
logger.Info($"REQ {method} {pathWithQuery} body={body}");
|
||||||
|
}
|
||||||
|
|
||||||
await next(context);
|
await next(context);
|
||||||
|
|
||||||
var statusCode = context.Response.StatusCode;
|
var statusCode = context.Response.StatusCode;
|
||||||
|
|
||||||
if (path.StartsWith("/report") || path.Contains("/log/") || path == "/alive")
|
if (ShouldSkip(path))
|
||||||
return;
|
return;
|
||||||
if (!ConfigManager.Config.HttpServer.EnableLog) return;
|
if (!ConfigManager.Config.HttpServer.EnableLog) return;
|
||||||
if (statusCode == 200)
|
if (statusCode == 200)
|
||||||
{
|
{
|
||||||
logger.Info($"{method} {path} => {statusCode}");
|
logger.Info($"{method} {pathWithQuery} => {statusCode}");
|
||||||
}
|
}
|
||||||
else if (statusCode == 404)
|
else if (statusCode == 404)
|
||||||
{
|
{
|
||||||
logger.Warn($"{method} {path} => {statusCode}");
|
logger.Warn($"{method} {pathWithQuery} => {statusCode}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.Error($"{method} {path} => {statusCode}");
|
logger.Error($"{method} {pathWithQuery} => {statusCode}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class BasePacket
|
|||||||
public long Timestamp { get; set; }
|
public long Timestamp { get; set; }
|
||||||
public IMessage? Message { get; set; }
|
public IMessage? Message { get; set; }
|
||||||
public PacketFraming Framing { get; set; }
|
public PacketFraming Framing { get; set; }
|
||||||
|
public int UncompressedBodySize { get; set; }
|
||||||
|
|
||||||
public BasePacket(ushort cmdId)
|
public BasePacket(ushort cmdId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using MikuSB.Enums.Packet;
|
using MikuSB.Enums.Packet;
|
||||||
using MikuSB.Util;
|
using MikuSB.Util;
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace MikuSB.TcpSharp
|
namespace MikuSB.TcpSharp
|
||||||
@@ -63,11 +64,11 @@ namespace MikuSB.TcpSharp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] Encode(ushort packetId, byte[] payload, PacketFraming framing = PacketFraming.FourByteLittleEndianLength)
|
public byte[] Encode(ushort packetId, byte[] payload, PacketFraming framing = PacketFraming.FourByteLittleEndianLength, int uncompressedSize = 0)
|
||||||
{
|
{
|
||||||
return framing switch
|
return framing switch
|
||||||
{
|
{
|
||||||
PacketFraming.TwoByteBigEndianLength => EncodeTwoByteFrame(packetId, payload),
|
PacketFraming.TwoByteBigEndianLength => EncodeTwoByteFrame(packetId, payload, uncompressedSize),
|
||||||
PacketFraming.FourByteLittleEndianLength => EncodeFourByteFrame(packetId, payload),
|
PacketFraming.FourByteLittleEndianLength => EncodeFourByteFrame(packetId, payload),
|
||||||
_ => EncodeFourByteFrame(packetId, payload)
|
_ => EncodeFourByteFrame(packetId, payload)
|
||||||
};
|
};
|
||||||
@@ -220,8 +221,20 @@ namespace MikuSB.TcpSharp
|
|||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] EncodeTwoByteFrame(ushort packetId, byte[] payload)
|
private const int CompressionThreshold = 60000;
|
||||||
|
|
||||||
|
private static byte[] ZlibCompress(byte[] data)
|
||||||
{
|
{
|
||||||
|
using var ms = new MemoryStream();
|
||||||
|
using (var zlib = new ZLibStream(ms, CompressionLevel.Optimal, leaveOpen: true))
|
||||||
|
zlib.Write(data, 0, data.Length);
|
||||||
|
return ms.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] EncodeTwoByteFrame(ushort packetId, byte[] payload, int uncompressedSize = 0)
|
||||||
|
{
|
||||||
|
if (payload.Length > CompressionThreshold)
|
||||||
|
payload = ZlibCompress(payload);
|
||||||
var wrappedPayload = WrapPayload(payload);
|
var wrappedPayload = WrapPayload(payload);
|
||||||
var buffer = new byte[HeaderSize4Byte + wrappedPayload.Length];
|
var buffer = new byte[HeaderSize4Byte + wrappedPayload.Length];
|
||||||
|
|
||||||
@@ -246,7 +259,9 @@ namespace MikuSB.TcpSharp
|
|||||||
const int wrapperHeaderSize = 35;
|
const int wrapperHeaderSize = 35;
|
||||||
var wrapped = new byte[wrapperHeaderSize + payload.Length];
|
var wrapped = new byte[wrapperHeaderSize + payload.Length];
|
||||||
BinaryPrimitives.WriteUInt16LittleEndian(wrapped.AsSpan(6, 2), (ushort)payload.Length);
|
BinaryPrimitives.WriteUInt16LittleEndian(wrapped.AsSpan(6, 2), (ushort)payload.Length);
|
||||||
wrapped[11] = 1;
|
if (payload.Length >= 2 && payload[0] == 0x78 &&
|
||||||
|
(payload[1] == 0x01 || payload[1] == 0x5E || payload[1] == 0x9C || payload[1] == 0xDA))
|
||||||
|
wrapped[10] = 2;
|
||||||
payload.CopyTo(wrapped.AsSpan(wrapperHeaderSize));
|
payload.CopyTo(wrapped.AsSpan(wrapperHeaderSize));
|
||||||
|
|
||||||
return wrapped;
|
return wrapped;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v=2.4
|
v=3.1
|
||||||
Reference in New Issue
Block a user