Compare commits

...

25 Commits
v1.3 ... v1.6

Author SHA1 Message Date
Kei-Luna
283358f1ec Update version.txt 2026-04-30 06:01:05 +09:00
Kei-Luna
5d8b3f2bad Merge pull request #6 from cs8425/work-for-linux
fix some bug, upgrade to dotnet 10 and add docs for linux
2026-04-30 05:43:01 +09:00
cs8425
a992bc86c5 Merge remote-tracking branch 'origin/main' into work-for-linux 2026-04-29 22:38:36 +08:00
cs8425
d97eae6f5b update README_linux.md 2026-04-29 22:38:13 +08:00
cs8425
04121eb357 try workflow build for linux 2026-04-29 22:34:14 +08:00
cs8425
391879a483 bump github workflow to dotnet 10 2026-04-29 20:28:11 +08:00
cs8425
8e3323dd94 fix pem format not export when first create CA cert 2026-04-29 19:34:25 +08:00
cs8425
7e83d2ccd2 fix racing between AutoSave and process exit 2026-04-29 19:30:57 +08:00
Naruse
408113963b Merge branch 'main' of https://github.com/MikuLeaks/MikuSB 2026-04-29 16:00:34 +08:00
Naruse
fcf0bf0843 add call item 2026-04-29 16:00:10 +08:00
Kei-Luna
2bf7554c53 Unlock GM menu 2026-04-29 16:57:11 +09:00
Naruse
50121d619b add skin part 2026-04-29 15:42:25 +08:00
Naruse
e8bb77e90e logistic index 2026-04-29 13:04:17 +08:00
Naruse
5f173ce8d2 add badge 2026-04-29 12:41:45 +08:00
Naruse
9b8fa5d7c8 add profile item 2026-04-29 11:02:11 +08:00
Naruse
1969c1ec89 use enum for item slots 2026-04-29 09:46:21 +08:00
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
cs8425
5f3fc0c746 add docs for running on Linux 2026-04-29 02:53:08 +08:00
cs8425
2fe795d29a also export CA cert in pem format 2026-04-29 02:52:48 +08:00
cs8425
b256fe7b01 fix proxy log and proxy https connection always return 404 2026-04-28 23:16:13 +08:00
cs8425
e93dadafe8 fix infinite loop for auto SaveDatabase 2026-04-28 22:49:58 +08:00
cs8425
34b93ad55d fix infinite loop when pressed ctrl+c 2026-04-28 21:09:14 +08:00
cs8425
3eca16a661 upgrade to dotnet 10 2026-04-28 20:19:17 +08:00
53 changed files with 1180 additions and 113 deletions

View File

@@ -9,6 +9,9 @@ on:
permissions: permissions:
contents: write contents: write
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs: jobs:
build-release: build-release:
runs-on: windows-latest runs-on: windows-latest
@@ -18,7 +21,7 @@ jobs:
- uses: actions/setup-dotnet@v4 - uses: actions/setup-dotnet@v4
with: with:
dotnet-version: 9.0.x dotnet-version: 10.0.x
- name: Read version - name: Read version
id: version id: version
@@ -54,3 +57,55 @@ jobs:
files: | files: |
artifacts/MikuSB-win-x64.zip artifacts/MikuSB-win-x64.zip
artifacts/MikuSB-win-x64.zip.sha256 artifacts/MikuSB-win-x64.zip.sha256
build-release-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Publish server
run: |
dotnet publish ./MikuSB/MikuSB.csproj -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true --property:PublishDir=../artifacts/dist
- name: Read version
id: version
shell: bash
run: |
line=$(head -n 1 version.txt | xargs)
VERSION=${line#v=}
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
if [ -z "$VERSION" ]; then
echo "version.txt is empty."
VERSION=${SHORT_HASH}
fi
if [[ "${{ env.BRANCH_NAME }}" == "main" ]]; then
echo "tag=v${VERSION}" >> $GITHUB_OUTPUT
else
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
echo "tag=${SAFE_NAME}-v${VERSION}-${SHORT_HASH}" >> $GITHUB_OUTPUT
fi
- name: Assemble release package
run: |
packageDir="./artifacts/dist/"
zipFile="MikuSB-linux-x64.zip"
cp ./version.txt ${packageDir}
pushd ${packageDir}
zip -r ../${zipFile} .
popd
sha256sum ./artifacts/${zipFile} > ./artifacts/${zipFile}.sha256
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
generate_release_notes: true
files: |
./artifacts/MikuSB-linux-x64.zip
./artifacts/MikuSB-linux-x64.zip.sha256

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CETCompat>false</CETCompat> <CETCompat>false</CETCompat>
@@ -21,7 +21,6 @@
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.10" /> <PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.10" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.172" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.172" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" />
<PackageReference Include="System.Management" Version="9.0.0" /> <PackageReference Include="System.Management" Version="9.0.0" />
</ItemGroup> </ItemGroup>

View File

@@ -60,6 +60,7 @@ public class ServerOption
public string FallbackLanguage { get; set; } = "EN"; public string FallbackLanguage { get; set; } = "EN";
public string[] DefaultPermissions { get; set; } = ["Admin"]; public string[] DefaultPermissions { get; set; } = ["Admin"];
public ServerProfile ServerProfile { get; set; } = new(); public ServerProfile ServerProfile { get; set; } = new();
public bool EnableGmMenu { get; set; } = true;
public bool AutoCreateUser { get; set; } = true; public bool AutoCreateUser { get; set; } = true;
public bool SavePersonalDebugFile { get; set; } = false; public bool SavePersonalDebugFile { get; set; } = false;
public bool AutoSendResponseWhenNoHandler { get; set; } = true; public bool AutoSendResponseWhenNoHandler { get; set; } = true;

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

@@ -0,0 +1,24 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace MikuSB.Data.Excel;
[ResourceEntity("call_item.json")]
public class CallItemExcel : ExcelResource
{
public uint Genre { get; set; }
public uint Detail { get; set; }
public uint Particular { get; set; }
public uint Level { get; set; }
public string I18n { get; set; } = "";
public override uint GetId()
{
return (uint)I18n.GetHashCode();
}
public override void Loaded()
{
GameData.CallItemData.Add(GetId(), this);
}
}

View File

@@ -0,0 +1,27 @@
using Newtonsoft.Json;
namespace MikuSB.Data.Excel;
[ResourceEntity("card_skin_parts.json")]
public class CardSkinPartsExcel : ExcelResource
{
public uint Genre { get; set; }
public uint Detail { get; set; }
public uint Particular { get; set; }
public uint Level { get; set; }
public uint Icon { get; set; }
public int AppearID { get; set; }
[JsonProperty("profile")] public List<List<int>> CardSkinID { get; set; } = [];
public string I18n { get; set; } = "";
[JsonIgnore] public ulong TemplateId { get; set; }
public override uint GetId()
{
return (uint)I18n.GetHashCode();
}
public override void Loaded()
{
TemplateId = GameResourceTemplateId.FromGdpl(Genre, Detail, Particular, Level);
GameData.CardSkinPartsData.Add(Icon, this);
}
}

View File

@@ -0,0 +1,22 @@
namespace MikuSB.Data.Excel;
[ResourceEntity("profile.json")]
public class ProfileExcel : ExcelResource
{
public uint Genre { get; set; }
public uint Detail { get; set; }
public uint Particular { get; set; }
public uint Level { get; set; }
public string I18n { get; set; } = "";
public string LuaType { get; set; } = "";
public override uint GetId()
{
return (uint)I18n.GetHashCode();
}
public override void Loaded()
{
GameData.ProfileData.Add(GetId(), this);
}
}

View File

@@ -16,12 +16,15 @@ 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; } = [];
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, CardSkinPartsExcel> CardSkinPartsData { get; private set; } = [];
public static Dictionary<uint, CallItemExcel> CallItemData { get; private set; } = [];
} }
public static class GameResourceTemplateId public static class GameResourceTemplateId

View File

@@ -24,13 +24,13 @@ public class CharacterInfo
public uint WeaponUniqueId { get; set; } public uint WeaponUniqueId { get; set; }
public uint SkinId { get; set; } public uint SkinId { get; set; }
public uint WeaponSkinId { get; set; } public uint WeaponSkinId { get; set; }
public uint SupportTeamIndex { get; set; } = 1;
public ItemFlagEnum Flag { get; set; } = ItemFlagEnum.FLAG_READED; public ItemFlagEnum Flag { get; set; } = ItemFlagEnum.FLAG_READED;
public uint Expiration { get; set; } public uint Expiration { get; set; }
[SugarColumn(IsJson = true)] public List<uint> UnlockedSkin { get; set; } = []; [SugarColumn(IsJson = true)] public List<uint> UnlockedSkin { get; set; } = [];
[SugarColumn(IsJson = true)] public List<uint> Spines { get; set; } = []; [SugarColumn(IsJson = true)] public List<uint> Spines { get; set; } = [];
[SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = []; [SugarColumn(IsJson = true)] public List<uint> Affixs { get; set; } = [];
// Key = EqSlot (= support card Detail), Value = support card UniqueId [SugarColumn(IsJson = true)] public Dictionary<uint, uint> SupportSlots { get; set; } = []; // Key = EqSlot (= support card Detail), Value = support card UniqueId
[SugarColumn(IsJson = true)] public Dictionary<uint, uint> SupportSlots { get; set; } = [];
public long Timestamp { get; set; } public long Timestamp { get; set; }
public uint Count { get; set; } = 1; public uint Count { get; set; } = 1;
@@ -56,9 +56,10 @@ public class CharacterInfo
proto.Enhance.Spines.AddRange(Spines.Select(x => (ulong)x)); proto.Enhance.Spines.AddRange(Spines.Select(x => (ulong)x));
proto.Enhance.Affixs.AddRange(Affixs); proto.Enhance.Affixs.AddRange(Affixs);
proto.Slots[4] = WeaponUniqueId; proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_WEAPON] = WeaponUniqueId;
proto.Slots[5] = SkinId; proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_SKIN] = SkinId;
proto.Slots[6] = WeaponSkinId; proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_WEAPON_SKIN] = WeaponSkinId;
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_SUPPORTERINDEX] = SupportTeamIndex;
foreach (var (slot, uid) in SupportSlots) foreach (var (slot, uid) in SupportSlots)
proto.Slots[slot] = uid; proto.Slots[slot] = uid;

View File

@@ -14,7 +14,10 @@ public class DatabaseHelper
public static readonly ConcurrentDictionary<int, List<BaseDatabaseDataHelper>> UidInstanceMap = []; public static readonly ConcurrentDictionary<int, List<BaseDatabaseDataHelper>> UidInstanceMap = [];
public static readonly List<int> ToSaveUidList = []; public static readonly List<int> ToSaveUidList = [];
public static long LastSaveTick = DateTime.UtcNow.Ticks; public static long LastSaveTick = DateTime.UtcNow.Ticks;
public static Thread? SaveThread;
private static int _saving = 0;
private static Task? _saveTask;
private static CancellationTokenSource? _cts;
public static bool LoadAccount; public static bool LoadAccount;
public static bool LoadAllData; public static bool LoadAllData;
@@ -77,15 +80,11 @@ public class DatabaseHelper
while (!res.IsCompleted) while (!res.IsCompleted)
{ {
Thread.Sleep(100);
} }
LastSaveTick = DateTime.UtcNow.Ticks; _cts = new CancellationTokenSource();
_saveTask = RunAutoSave(_cts.Token);
SaveThread = new Thread(() =>
{
while (true) CalcSaveDatabase();
});
SaveThread.Start();
LoadAllData = true; LoadAllData = true;
} }
@@ -248,6 +247,35 @@ public class DatabaseHelper
ToSaveUidList.RemoveAll(x => x == key); ToSaveUidList.RemoveAll(x => x == key);
} }
public static void Stop()
{
_cts?.Cancel();
}
public static async Task WaitAsync()
{
if (_saveTask != null)
await _saveTask;
}
private static async Task RunAutoSave(CancellationToken token)
{
LastSaveTick = DateTime.UtcNow.Ticks;
try
{
while (!token.IsCancellationRequested)
{
CalcSaveDatabase();
await Task.Delay(100, token);
}
}
catch (OperationCanceledException)
{
// exit normally
// Console.WriteLine($"RunAutoSave exit! - OperationCanceledException");
}
}
// Auto save per 5 min // Auto save per 5 min
public static void CalcSaveDatabase() public static void CalcSaveDatabase()
{ {
@@ -257,6 +285,10 @@ public class DatabaseHelper
public static void SaveDatabase() public static void SaveDatabase()
{ {
// ensure only one SaveDatabase() runnig
if (Interlocked.Exchange(ref _saving, 1) == 1)
return;
try try
{ {
var prev = DateTime.Now; var prev = DateTime.Now;
@@ -281,11 +313,18 @@ public class DatabaseHelper
Math.Round(t, 2).ToString(CultureInfo.InvariantCulture))); Math.Round(t, 2).ToString(CultureInfo.InvariantCulture)));
ToSaveUidList.Clear(); ToSaveUidList.Clear();
// Thread.Sleep(5000); // for test if saving process taking too long
} }
catch (Exception e) catch (Exception e)
{ {
logger.Error("An error occurred while saving the database", e); logger.Error("An error occurred while saving the database", e);
} }
finally
{
// release lock
Volatile.Write(ref _saving, 0);
}
LastSaveTick = DateTime.UtcNow.Ticks; LastSaveTick = DateTime.UtcNow.Ticks;
} }

View File

@@ -56,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; }
} }
@@ -73,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;
@@ -81,6 +83,7 @@ public class GameWeaponInfo : GrowableItemInfo
} }
public class GameSkinInfo : BaseGameItemInfo public class GameSkinInfo : BaseGameItemInfo
{ {
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
public uint SkinType { get; set; } public uint SkinType { get; set; }
public override Item ToProto() public override Item ToProto()
{ {
@@ -91,7 +94,8 @@ public class GameSkinInfo : BaseGameItemInfo
Count = ItemCount, Count = ItemCount,
Flag = (uint)Flag, Flag = (uint)Flag,
}; };
proto.Slots[11] = Math.Min(SkinType, 1); proto.Slots[(uint)ItemSkinSlotTypeEnum.SLOT_CARD_SKIL_TYPE] = Math.Min(SkinType, 1);
foreach (var (slot, uid) in PartSlots) proto.Slots[slot] = uid;
return proto; return proto;
} }
} }
@@ -114,7 +118,7 @@ public class GameSupportCardInfo : BaseGameItemInfo
Exp = Exp Exp = Exp
} }
}; };
proto.Slots[1] = AffixId; proto.Slots[(uint)ItemSupportCardSlotTypeEnum.SLOT_AFFIXINDEX] = AffixId;
return proto; return proto;
} }
} }

View File

@@ -1,13 +0,0 @@
namespace MikuSB.Enums.Item;
public enum ItemFlagEnum
{
FLAG_USE = 1,// 使用中
FLAG_LOCK = 2,// 锁定中
FLAG_READED = 4,// 道具已查看
FLAG_LEAVE = 8,// 角色大招后离场
FLAG_WEAPON_DEFAULT = 16,// 武器显示原始样式
FLAG_WEAPON_AUDIO = 32,// 武器消音器音效
FLAG_ROLE_LIKE = 64,// 心选角色
}

View File

@@ -26,3 +26,55 @@ public enum ItemTypeEnum
TYPE_AR = 24, //AR道具 TYPE_AR = 24, //AR道具
TYPE_CALL = 25, //电话陪伴道具 TYPE_CALL = 25, //电话陪伴道具
} }
public enum ItemCardSlotTypeEnum
{
SLOT_SUPPORTERCARD1 = 1, // 后勤卡
SLOT_SUPPORTERCARD2 = 2, // 后勤卡
SLOT_SUPPORTERCARD3 = 3, // 后勤卡
SLOT_WEAPON = 4, // 武器
SLOT_SKIN = 5, // 时装
SLOT_WEAPON_SKIN = 6, // 武器时装
SLOT_SUPPORTERINDEX = 7, // 当前使用的后勤组
SLOT_SUPPORTERCARD4 = 8, // 后勤卡
SLOT_SUPPORTERCARD5 = 9, // 后勤卡
SLOT_SUPPORTERCARD6 = 10, // 后勤卡
SLOT_SUPPORTERCARD7 = 11, // 后勤卡
SLOT_SUPPORTERCARD8 = 12, // 后勤卡
SLOT_SUPPORTERCARD9 = 13, // 后勤卡
}
public enum ItemSkinPartSlotTypeEnum
{
SLOT_SkinPartSlot1 = 1,
SLOT_SkinPartSlot2 = 2,
SLOT_SkinPartSlot3 = 3,
SLOT_SkinPartSlot4 = 4,
SLOT_SkinPartSlot5 = 5,
SLOT_SkinPartSlot6 = 6,
SLOT_SkinPartSlot7 = 7,
SLOT_SkinPartSlot8 = 8,
SLOT_SkinPartSlot9 = 9,
SLOT_SkinPartSlot10 = 10,
}
public enum ItemSkinSlotTypeEnum
{
SLOT_CARD_SKIL_TYPE = 11
}
public enum ItemSupportCardSlotTypeEnum
{
SLOT_AFFIXINDEX = 1 // 可洗练的初始词缀索引
}
public enum ItemFlagEnum
{
FLAG_USE = 1, // 使用中
FLAG_LOCK = 2, // 锁定中
FLAG_READED = 4, // 道具已查看
FLAG_LEAVE = 8, // 角色大招后离场
FLAG_WEAPON_DEFAULT = 16, // 武器显示原始样式
FLAG_WEAPON_AUDIO = 32, // 武器消音器音效
FLAG_ROLE_LIKE = 64, // 心选角色
}

View File

@@ -0,0 +1,24 @@
namespace MikuSB.Enums.Player;
public enum ProfileShowItemTypeEnum
{
SHOWITEM_CARD1 = 1, //第1个展示卡
SHOWITEM_CARD2 = 2, //第2个展示卡
SHOWITEM_CARD3 = 3, //第3个展示卡
SHOWITEM_GIRL = 4, //看板娘
SHOWITEM_FACE = 5, //头像
SHOWITEM_FRAME = 6, //头像框
SHOWITEM_CARD4 = 7, //第4个展示卡
SHOWITEM_CARD5 = 8, //第5个展示卡
SHOWITEM_SKIN1 = 9, //第1个展示皮肤
SHOWITEM_SKIN2 = 10, //第2个展示皮肤
SHOWITEM_SKIN3 = 11, //第3个展示皮肤
SHOWITEM_SKIN4 = 12, //第4个展示皮肤
SHOWITEM_SKIN5 = 13, //第5个展示皮肤
SHOWITEM_BADGE1 = 14, //第一个展示勋章
SHOWITEM_BADGE2 = 15, //第二个展示勋章
SHOWITEM_BADGE3 = 16, //第三个展示勋章
SHOWITEM_COVER = 17, //展示封面
SHOWITEM_NAMECARD = 18, //展示名片
SHOWITEM_BUBBLE = 19, //聊天气泡
}

View File

@@ -35,6 +35,9 @@ public class ServerTextCHS
/// </summary> /// </summary>
public class WordTextCHS public class WordTextCHS
{ {
public string CallItem => "召唤道具";
public string SkinPart => "皮肤部件";
public string Profile => "个人资料";
public string WeaponSkin => "武器皮肤"; public string WeaponSkin => "武器皮肤";
public string SupportCard => "支援卡"; public string SupportCard => "支援卡";
public string Weapon => "武器"; public string Weapon => "武器";
@@ -240,7 +243,10 @@ public class GiveAllTextCHS
"注意:-1 表示全部"; "注意:-1 表示全部";
public string Usage => "用法:/giveall weapon <detail/-1> -p<特定> -l<等級>\n" + public string Usage => "用法:/giveall weapon <detail/-1> -p<特定> -l<等級>\n" +
"用法:/giveall weaponskin <detail/-1> -p<特定>\n" + "用法:/giveall weaponskin <detail/-1> -p<特定>\n" +
"用法:/giveall card <detail/-1> -p<特定> -l<等級>"; "用法:/giveall card <detail/-1> -p<特定> -l<等級>" +
"用法:/giveall profile <detail/-1> -g<类型> -p<特定> -l<等级>" +
"用法:/giveall skinpart <detail/-1> -g<類型> -p<特定> -l<等級>" +
"用法:/giveall call <detail/-1> -g<類型> -p<特定> -l<等級>";
public string NotFound => "未找到 {0}"; public string NotFound => "未找到 {0}";
public string GiveAllItems => "已向玩家添加 {0} 个 {1}"; public string GiveAllItems => "已向玩家添加 {0} 个 {1}";
} }

View File

@@ -35,6 +35,9 @@ public class ServerTextCHT
/// </summary> /// </summary>
public class WordTextCHT public class WordTextCHT
{ {
public string CallItem => "召喚道具";
public string SkinPart => "外觀部件";
public string Profile => "個人資料";
public string WeaponSkin => "武器外觀"; public string WeaponSkin => "武器外觀";
public string SupportCard => "支援卡"; public string SupportCard => "支援卡";
public string Weapon => "武器"; public string Weapon => "武器";
@@ -240,7 +243,10 @@ public class GiveAllTextCHT
"注意:-1 表示全部"; "注意:-1 表示全部";
public string Usage => "用法:/giveall weapon <detail/-1> -p<特定> -l<等級>\n" + public string Usage => "用法:/giveall weapon <detail/-1> -p<特定> -l<等級>\n" +
"用法:/giveall weaponskin <detail/-1> -p<特定>\n" + "用法:/giveall weaponskin <detail/-1> -p<特定>\n" +
"用法:/giveall card <detail/-1> -p<特定> -l<等級>"; "用法:/giveall card <detail/-1> -p<特定> -l<等級>" +
"用法:/giveall profile <detail/-1> -g<類型> -p<特定> -l<等級>" +
"用法:/giveall skinpart <detail/-1> -g<類型> -p<特定> -l<等級>" +
"用法:/giveall call <detail/-1> -g<類型> -p<特定> -l<等級>";
public string NotFound => "未找到 {0}"; public string NotFound => "未找到 {0}";
public string GiveAllItems => "已向玩家添加 {0} 個 {1}"; public string GiveAllItems => "已向玩家添加 {0} 個 {1}";
} }

View File

@@ -35,6 +35,9 @@ public class ServerTextEN
/// </summary> /// </summary>
public class WordTextEN public class WordTextEN
{ {
public string CallItem => "Call Item";
public string SkinPart => "Skin Part";
public string Profile => "Profile";
public string WeaponSkin => "Weapon Skin"; public string WeaponSkin => "Weapon Skin";
public string Valk => "Valkyrie"; public string Valk => "Valkyrie";
public string Material => "Material"; public string Material => "Material";
@@ -206,7 +209,10 @@ public class GiveAllTextEN
"Note: -1 means all"; "Note: -1 means all";
public string Usage => "Usage: /giveall weapon <detail/-1> -p<particular> -l<level>\n" + public string Usage => "Usage: /giveall weapon <detail/-1> -p<particular> -l<level>\n" +
"Usage: /giveall weaponskin <detail/-1> -p<particular>\n" + "Usage: /giveall weaponskin <detail/-1> -p<particular>\n" +
"Usage: /giveall card <detail/-1> -p<particular> -l<level>"; "Usage: /giveall card <detail/-1> -p<particular> -l<level>" +
"Usage: /giveall profile <detail/-1> -g<genre> -p<particular> -l<level>" +
"Usage: /giveall skinpart <detail/-1> -g<genre> -p<particular> -l<level>" +
"Usage: /giveall call <detail/-1> -g<genre> -p<particular> -l<level>";
public string NotFound => "{0} not found!"; public string NotFound => "{0} not found!";
public string GiveAllItems => "Added {0} {1} to player!"; public string GiveAllItems => "Added {0} {1} to player!";
} }

View File

@@ -148,13 +148,29 @@ public class IConsole
#endregion #endregion
public static string ListenConsole() public static async Task ListenConsole(CancellationToken exitToken)
{ {
while (true) while (!exitToken.IsCancellationRequested)
{ {
ConsoleKeyInfo keyInfo; ConsoleKeyInfo keyInfo;
try { keyInfo = Console.ReadKey(true); } try
catch (InvalidOperationException) { continue; } {
if (!Console.KeyAvailable)
{
await Task.Delay(10, exitToken);
continue;
}
keyInfo = Console.ReadKey(true);
}
catch (OperationCanceledException)
{
break;
}
catch (InvalidOperationException)
{
await Task.Delay(50, exitToken);
continue;
}
switch (keyInfo.Key) switch (keyInfo.Key)
{ {

View File

@@ -96,7 +96,7 @@ public class CommandGiveAll : ICommands
foreach (var config in GameData.WeaponSkinData.Values) foreach (var config in GameData.WeaponSkinData.Values)
{ {
var weaponSkin = await player.InventoryManager! var weaponSkin = await player.InventoryManager!
.AddWeaponSkinItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, 1, false); .AddWeaponSkinItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
if (weaponSkin != null) weaponSkins.Add(weaponSkin); if (weaponSkin != null) weaponSkins.Add(weaponSkin);
} }
} }
@@ -114,4 +114,112 @@ public class CommandGiveAll : ICommands
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()));
} }
[CommandMethod("profile")]
public async ValueTask GiveAllProfile(CommandArg arg)
{
if (!await arg.CheckOnlineTarget()) return;
if (await arg.GetOption('p') is not int particular) return;
if (await arg.GetOption('l') is not int level) return;
if (await arg.GetOption('g') is not int genre) return;
var detail = arg.GetInt(0);
var player = arg.Target!.Player!;
List<BaseGameItemInfo> profileItems = [];
if (detail == -1)
{
// add all
foreach (var config in GameData.ProfileData.Values)
{
var profile = await player.InventoryManager!
.AddProfileItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
if (profile != null) profileItems.Add(profile);
}
}
else
{
var profile = await player.InventoryManager!.AddProfileItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false);
if (profile == null)
{
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.Profile")));
return;
}
profileItems.Add(profile);
}
if (profileItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(profileItems));
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.Profile"), profileItems.Count.ToString()));
}
[CommandMethod("skinpart")]
public async ValueTask GiveAllSkinPart(CommandArg arg)
{
if (!await arg.CheckOnlineTarget()) return;
if (await arg.GetOption('p') is not int particular) return;
if (await arg.GetOption('l') is not int level) return;
if (await arg.GetOption('g') is not int genre) return;
var detail = arg.GetInt(0);
var player = arg.Target!.Player!;
List<BaseGameItemInfo> skinPartItems = [];
if (detail == -1)
{
// add all
foreach (var config in GameData.CardSkinPartsData.Values)
{
var skinPart = await player.InventoryManager!
.AddSkinPartItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
if (skinPart != null) skinPartItems.Add(skinPart);
}
}
else
{
var skinPart = await player.InventoryManager!.AddSkinPartItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false);
if (skinPart == null)
{
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.SkinPart")));
return;
}
skinPartItems.Add(skinPart);
}
if (skinPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(skinPartItems));
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.SkinPart"), skinPartItems.Count.ToString()));
}
[CommandMethod("call")]
public async ValueTask GiveAllCallItem(CommandArg arg)
{
if (!await arg.CheckOnlineTarget()) return;
if (await arg.GetOption('p') is not int particular) return;
if (await arg.GetOption('l') is not int level) return;
if (await arg.GetOption('g') is not int genre) return;
var detail = arg.GetInt(0);
var player = arg.Target!.Player!;
List<BaseGameItemInfo> callItems = [];
if (detail == -1)
{
// add all
foreach (var config in GameData.CallItemData.Values)
{
var callItem = await player.InventoryManager!
.AddCallItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
if (callItem != null) callItems.Add(callItem);
}
}
else
{
var callItem = await player.InventoryManager!.AddCallItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false);
if (callItem == null)
{
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.CallItem")));
return;
}
callItems.Add(callItem);
}
if (callItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(callItems));
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.CallItem"), callItems.Count.ToString()));
}
} }

View File

@@ -25,7 +25,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
UniqueId = InventoryData.NextUniqueUid++, UniqueId = InventoryData.NextUniqueUid++,
Level = weaponLevel, Level = weaponLevel,
Break = GetWeaponBreak(weaponLevel), Break = GetWeaponBreak(weaponLevel),
ItemType = ItemTypeEnum.TYPE_WEAPON, ItemType = genre,
ItemCount = 1 ItemCount = 1
}; };
InventoryData.Weapons[weaponInfo.UniqueId] = weaponInfo; InventoryData.Weapons[weaponInfo.UniqueId] = weaponInfo;
@@ -67,13 +67,13 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
if (genre != ItemTypeEnum.TYPE_CARD_SKIN) return null; if (genre != ItemTypeEnum.TYPE_CARD_SKIN) return null;
var skinData = GameData.CardSkinData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level); var skinData = GameData.CardSkinData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
if (skinData == null) return null; if (skinData == null) return null;
var templateId = GameResourceTemplateId.FromGdpl((uint)genre,detail,particular,level); var templateId = GameResourceTemplateId.FromGdpl((uint)genre,detail,particular,level);
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
var skinInfo = new GameSkinInfo var skinInfo = new GameSkinInfo
{ {
TemplateId = templateId, TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++, UniqueId = InventoryData.NextUniqueUid++,
ItemType = ItemTypeEnum.TYPE_CARD_SKIN, ItemType = genre,
ItemCount = 1 ItemCount = 1
}; };
InventoryData.Skins[skinInfo.UniqueId] = skinInfo; InventoryData.Skins[skinInfo.UniqueId] = skinInfo;
@@ -111,7 +111,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
{ {
TemplateId = templateId, TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++, UniqueId = InventoryData.NextUniqueUid++,
ItemType = ItemTypeEnum.TYPE_AR, ItemType = genre,
ItemCount = 1 ItemCount = 1
}; };
InventoryData.Items[arInfo.UniqueId] = arInfo; InventoryData.Items[arInfo.UniqueId] = arInfo;
@@ -171,7 +171,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
{ {
TemplateId = templateId, TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++, UniqueId = InventoryData.NextUniqueUid++,
ItemType = ItemTypeEnum.TYPE_MANIFESTATION, ItemType = genre,
ItemCount = 1 ItemCount = 1
}; };
InventoryData.Items[manifestInfo.UniqueId] = manifestInfo; InventoryData.Items[manifestInfo.UniqueId] = manifestInfo;
@@ -240,7 +240,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
{ {
TemplateId = templateId, TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++, UniqueId = InventoryData.NextUniqueUid++,
ItemType = ItemTypeEnum.TYPE_WEAPON_SKIN, ItemType = genre,
ItemCount = 1 ItemCount = 1
}; };
InventoryData.Items[skinInfo.UniqueId] = skinInfo; InventoryData.Items[skinInfo.UniqueId] = skinInfo;
@@ -249,4 +249,67 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
return skinInfo; return skinInfo;
} }
public async ValueTask<BaseGameItemInfo?> AddProfileItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
{
if (genre < ItemTypeEnum.TYPE_PROFILE || genre > ItemTypeEnum.TYPE_ANALYST) return null;
var profileData = GameData.ProfileData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
if (profileData == null) return null;
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
var profileInfo = new BaseGameItemInfo
{
TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++,
ItemType = genre,
ItemCount = 1
};
InventoryData.Items[profileInfo.UniqueId] = profileInfo;
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([profileInfo]));
return profileInfo;
}
public async ValueTask<BaseGameItemInfo?> AddSkinPartItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
{
if (genre != ItemTypeEnum.TYPE_CARD_SKIN_PART) return null;
var skinPartData = GameData.CardSkinPartsData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
if (skinPartData == null) return null;
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
var skinPartInfo = new BaseGameItemInfo
{
TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++,
ItemType = genre,
ItemCount = 1
};
InventoryData.Items[skinPartInfo.UniqueId] = skinPartInfo;
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([skinPartInfo]));
return skinPartInfo;
}
public async ValueTask<BaseGameItemInfo?> AddCallItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
{
if (genre != ItemTypeEnum.TYPE_CALL) return null;
var callData = GameData.CallItemData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
if (callData == null) return null;
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
var callInfo = new BaseGameItemInfo
{
TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++,
ItemType = genre,
ItemCount = 1
};
InventoryData.Items[callInfo.UniqueId] = callInfo;
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([callInfo]));
return callInfo;
}
} }

View File

@@ -210,6 +210,7 @@ public class PlayerInstance(PlayerGameData data)
Sex = Data.Gender, Sex = Data.Gender,
Vigor = Data.Vigor, Vigor = Data.Vigor,
Solutions = { LineupManager.LineupData.LineupInfo.Values.Select(x => x.ToProto()) }, Solutions = { LineupManager.LineupData.LineupInfo.Values.Select(x => x.ToProto()) },
Badges = { InventoryManager.InventoryData.Items.Values.Where(x => x.ItemType == ItemTypeEnum.TYPE_BADGE).Select(x => (ulong)x.UniqueId) }
}; };
foreach (var chara in CharacterManager.CharacterData.Characters) proto.Items.Add(chara.ToProto()); foreach (var chara in CharacterManager.CharacterData.Characters) proto.Items.Add(chara.ToProto());

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CETCompat>false</CETCompat> <CETCompat>false</CETCompat>
@@ -22,7 +22,6 @@
<ProjectReference Include="..\Common\Common.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\TcpSharp\TcpSharp.csproj" /> <ProjectReference Include="..\TcpSharp\TcpSharp.csproj" />
<ProjectReference Include="..\Proto\Proto.csproj" /> <ProjectReference Include="..\Proto\Proto.csproj" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -11,7 +11,7 @@ public class Daily_SetSelectSuit : ICallGSHandler
var req = JsonSerializer.Deserialize<GirlWeaponSkinParam>(param); var req = JsonSerializer.Deserialize<GirlWeaponSkinParam>(param);
if (req == null) if (req == null)
{ {
await CallGSRouter.SendScript(connection, "GirlWeaponSkin_Change", "{}"); await CallGSRouter.SendScript(connection, "Daily_SetSelectSuit", "{}");
return; return;
} }
var rsp = $"{{\"SuitId\":{req.Suit}}}"; var rsp = $"{{\"SuitId\":{req.Suit}}}";

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

@@ -0,0 +1,57 @@
using Azure;
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.Nodes;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
[CallGSApi("GirlSkinParts_Update")]
public class GirlSkinParts_Update : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var req = JsonSerializer.Deserialize<GirlSkinPartsUpdateParam>(param);
if (req == null)
{
await CallGSRouter.SendScript(connection, "GirlSkinParts_Update", "{\"sErr\":\"error.BadParam\"}");
return;
}
var player = connection.Player!;
var data = new List<GameSkinInfo>();
foreach(var partId in req.PartsId)
{
var partData = player.InventoryManager.GetNormalItem(partId);
if (partData == null) continue;
var partExcel = GameData.CardSkinPartsData.Values.FirstOrDefault(x => x.TemplateId == partData.TemplateId);
if (partExcel == null) continue;
var skinData = player.InventoryManager.GetSkinItem(req.SkinId);
if (skinData == null) continue;
skinData.PartSlots[partExcel.Detail] = partData.UniqueId;
data.Add(skinData);
}
var sync = new NtfSyncPlayer
{
Items = { data.Select(x => x.ToProto()) }
};
await CallGSRouter.SendScript(connection, "GirlSkinParts_Update", "{}", sync);
}
}
internal sealed class GirlSkinPartsUpdateParam
{
[JsonPropertyName("tbPartsID")]
public List<uint> PartsId { get; set; } = [];
[JsonPropertyName("nSkinId")]
public uint SkinId { get; set; }
}

View File

@@ -13,7 +13,7 @@ public class GirlWeaponSkin_Change : ICallGSHandler
var req = JsonSerializer.Deserialize<GirlWeaponSkinParam>(param); var req = JsonSerializer.Deserialize<GirlWeaponSkinParam>(param);
if (req == null) if (req == null)
{ {
await CallGSRouter.SendScript(connection, "GirlWeaponSkin_Change", "{}"); await CallGSRouter.SendScript(connection, "GirlWeaponSkin_Change", "{\"err\":\"error.BadParam\"}");
return; return;
} }
@@ -33,7 +33,7 @@ public class GirlWeaponSkin_Change : ICallGSHandler
Items = { cardData.ToProto() } Items = { cardData.ToProto() }
}; };
await CallGSRouter.SendScript(connection, "GirlWeaponSkin_Change", "{}", sync); await CallGSRouter.SendScript(connection, "GirlWeaponSkin_Change", "null", sync);
} }
} }

View File

@@ -0,0 +1,37 @@
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
[CallGSApi("RoleCard_SetSupporterTeamIndex")]
public class RoleCard_SetSupporterTeamIndex : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var req = JsonSerializer.Deserialize<SetSupporterTeamIndexParam>(param);
if (req == null)
{
await CallGSRouter.SendScript(connection, "RoleCard_SetSupporterTeamIndex", "{\"err\":\"error.BadParam\"}");
return;
}
var player = connection.Player!;
var cardData = player.CharacterManager.GetCharacterByGUID(req.CardId);
if (cardData == null) return;
cardData.SupportTeamIndex = req.Index;
var sync = new NtfSyncPlayer
{
Items = { cardData.ToProto() }
};
await CallGSRouter.SendScript(connection, "RoleCard_SetSupporterTeamIndex", "null", sync);
}
}
internal sealed class SetSupporterTeamIndexParam
{
[JsonPropertyName("Id")]
public uint CardId { get; set; }
public uint Index { get; set; }
}

View File

@@ -1,4 +1,4 @@
using MikuSB.Database; using MikuSB.Enums.Player;
using MikuSB.Proto; using MikuSB.Proto;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@@ -8,8 +8,6 @@ namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_ChangeShowCard")] [CallGSApi("PlayerSetting_ChangeShowCard")]
public class PlayerSetting_ChangeShowCard : ICallGSHandler public class PlayerSetting_ChangeShowCard : ICallGSHandler
{ {
private const int ShowItemGirlIndex = 4;
public async Task Handle(Connection connection, string param, ushort seqNo) public async Task Handle(Connection connection, string param, ushort seqNo)
{ {
var player = connection.Player!; var player = connection.Player!;
@@ -23,13 +21,9 @@ public class PlayerSetting_ChangeShowCard : ICallGSHandler
await CallGSRouter.SendScript(connection, "PlayerSetting_ChangeShowCard", "{}"); await CallGSRouter.SendScript(connection, "PlayerSetting_ChangeShowCard", "{}");
return; return;
} }
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_GIRL, card.Guid);
player.SetShowItem(ShowItemGirlIndex, card.Guid);
DatabaseHelper.SaveDatabaseType(player.Data);
var sync = new NtfSyncPlayer(); var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems); sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_ChangeShowCard", "{}", sync); await CallGSRouter.SendScript(connection, "PlayerSetting_ChangeShowCard", "{}", sync);
} }
} }

View File

@@ -0,0 +1,49 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetProfileFace")]
public class PlayerSetting_SetProfileFace : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetProfileFaceParam>(param);
if (req == null)
return;
if (req.HeadItemId > 0)
{
var item = player.InventoryManager.GetNormalItem(req.HeadItemId);
if (item == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetProfileFace", "{\"err\":\"error.BadParam\"}");
return;
}
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_FACE, item.UniqueId);
}
if (req.FrameItemId > 0)
{
var item = player.InventoryManager.GetNormalItem(req.FrameItemId);
if (item == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetProfileFace", "{\"err\":\"error.BadParam\"}");
return;
}
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_FRAME, item.UniqueId);
}
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetProfileFace", "null", sync);
}
}
internal sealed class SetProfileFaceParam
{
[JsonPropertyName("nHeadItemID")] public uint HeadItemId { get; set; }
[JsonPropertyName("nFrameItemID")] public uint FrameItemId { get; set; }
}

View File

@@ -0,0 +1,43 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetShowBadge")]
public class PlayerSetting_SetShowBadge : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetShowBadgeParam>(param);
if (req == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBadge", "{\"err\":\"error.BadParam\"}");
return;
}
var slots = new[]
{
ProfileShowItemTypeEnum.SHOWITEM_BADGE1,
ProfileShowItemTypeEnum.SHOWITEM_BADGE2,
ProfileShowItemTypeEnum.SHOWITEM_BADGE3
};
for (int i = 0; i < slots.Length; i++)
{
var uniqueId = i < req.Badges.Count ? req.Badges[i] : 0;
player.SetShowItem((int)slots[i], uniqueId);
}
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBadge", "null", sync);
}
}
internal sealed class SetShowBadgeParam
{
[JsonPropertyName("tbBadge")]
public List<uint> Badges { get; set; } = [];
}

View File

@@ -0,0 +1,36 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetShowBubble")]
public class PlayerSetting_SetShowBubble : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetShowBubbleParam>(param);
if (req == null)
return;
var item = player.InventoryManager.GetNormalItem(req.Id);
if (item == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBubble", "{\"err\":\"error.BadParam\"}");
return;
}
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_BUBBLE, item.UniqueId);
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowBubble", "null", sync);
}
}
internal sealed class SetShowBubbleParam
{
[JsonPropertyName("nID")]
public uint Id { get; set; }
}

View File

@@ -0,0 +1,36 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetShowCover")]
public class PlayerSetting_SetShowCover : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetShowCoverParam>(param);
if (req == null)
return;
var item = player.InventoryManager.GetNormalItem(req.Id);
if (item == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowCover", "{\"err\":\"error.BadParam\"}");
return;
}
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_COVER, item.UniqueId);
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowCover", "null", sync);
}
}
internal sealed class SetShowCoverParam
{
[JsonPropertyName("nID")]
public uint Id { get; set; }
}

View File

@@ -0,0 +1,36 @@
using MikuSB.Enums.Player;
using MikuSB.Proto;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
[CallGSApi("PlayerSetting_SetShowNameCard")]
public class PlayerSetting_SetShowNameCard : ICallGSHandler
{
public async Task Handle(Connection connection, string param, ushort seqNo)
{
var player = connection.Player!;
var req = JsonSerializer.Deserialize<SetShowNameCardParam>(param);
if (req == null)
return;
var item = player.InventoryManager.GetNormalItem(req.Id);
if (item == null)
{
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowNameCard", "{\"err\":\"error.BadParam\"}");
return;
}
player.SetShowItem((int)ProfileShowItemTypeEnum.SHOWITEM_NAMECARD, item.UniqueId);
var sync = new NtfSyncPlayer();
sync.ShowItems.AddRange(player.Data.ShowItems);
await CallGSRouter.SendScript(connection, "PlayerSetting_SetShowNameCard", "null", sync);
}
}
internal sealed class SetShowNameCardParam
{
[JsonPropertyName("nID")]
public uint Id { get; set; }
}

View File

@@ -25,7 +25,8 @@ public class SupporterCard_Equip : ICallGSHandler
return; return;
} }
var slot = (uint)req.EqSlot; var teamIndex = card.SupportTeamIndex;
var slot = GetTeamIndex((uint)req.EqSlot, teamIndex);
// If an existing card is equipped in this slot and bForce is false, ask for confirmation // If an existing card is equipped in this slot and bForce is false, ask for confirmation
if (!req.Force && req.CurrentEquippedUid != 0 && card.SupportSlots.TryGetValue(slot, out var existing) && existing != 0) if (!req.Force && req.CurrentEquippedUid != 0 && card.SupportSlots.TryGetValue(slot, out var existing) && existing != 0)
@@ -46,6 +47,14 @@ public class SupporterCard_Equip : ICallGSHandler
var responseApi = string.IsNullOrEmpty(req.Model) ? "Logistics_Change" : "Logistics_Equip"; var responseApi = string.IsNullOrEmpty(req.Model) ? "Logistics_Change" : "Logistics_Equip";
await CallGSRouter.SendScript(connection, responseApi, "{}", sync); await CallGSRouter.SendScript(connection, responseApi, "{}", sync);
} }
private uint GetTeamIndex(uint slot, uint teamIndex)
{
if (teamIndex == 1) return slot;
if (teamIndex == 2) return slot + 7;
if (teamIndex == 3) return slot + 10;
return slot;
}
} }
internal sealed class SupporterCardEquipParam internal sealed class SupporterCardEquipParam

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

@@ -53,6 +53,7 @@ public class HandlerReqLogin : Handler
await connection.Player.OnEnterGame(); await connection.Player.OnEnterGame();
connection.Player.Connection = connection; connection.Player.Connection = connection;
await connection.SendPacket(new PacketRspLogin(connection.Player!)); await connection.SendPacket(new PacketRspLogin(connection.Player!));
await SendDebugLoginState(connection);
await connection.Player.OnHeartBeat(); await connection.Player.OnHeartBeat();
await connection.SendPacket(new PacketNtfUpdateFriend(connection.Player!)); await connection.SendPacket(new PacketNtfUpdateFriend(connection.Player!));
@@ -118,4 +119,14 @@ public class HandlerReqLogin : Handler
}); });
} }
} }
private static async Task SendDebugLoginState(Connection connection)
{
var response = new JsonObject
{
["IsDebug"] = ConfigManager.Config.ServerOption.EnableGmMenu
};
await CallGSRouter.SendScript(connection, "gm.notifylogin", response.ToJsonString());
}
} }

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CETCompat>false</CETCompat> <CETCompat>false</CETCompat>

View File

@@ -160,7 +160,7 @@ public class LoaderManager : MikuSB
} }
} }
public static void InitCommand() public static async Task InitCommand(CancellationToken exitToken)
{ {
// Register the command handlers // Register the command handlers
try try
@@ -178,6 +178,6 @@ public class LoaderManager : MikuSB
IConsole.OnConsoleExcuteCommand += CommandExecutor.ConsoleExcuteCommand; IConsole.OnConsoleExcuteCommand += CommandExecutor.ConsoleExcuteCommand;
CommandExecutor.OnRunCommand += (sender, e) => { CommandManager.HandleCommand(e, sender); }; CommandExecutor.OnRunCommand += (sender, e) => { CommandManager.HandleCommand(e, sender); };
IConsole.ListenConsole(); await IConsole.ListenConsole(exitToken);
} }
} }

View File

@@ -18,6 +18,10 @@ public class MikuSB
public static readonly Listener Listener = new(); public static readonly Listener Listener = new();
public static readonly CommandManager CommandManager = new(); public static readonly CommandManager CommandManager = new();
// for exit signal
private static readonly CancellationTokenSource _cts = new();
private static int _exitCode = 0;
public static async Task Main() public static async Task Main()
{ {
var time = DateTime.Now; var time = DateTime.Now;
@@ -50,11 +54,15 @@ public class MikuSB
ResourceManager.IsLoaded = true; ResourceManager.IsLoaded = true;
HandbookGenerator.GenerateAll(); HandbookGenerator.GenerateAll();
LoaderManager.InitCommand(); var consoleTask = Task.Run(() => LoaderManager.InitCommand(_cts.Token), _cts.Token);
var elapsed = DateTime.Now - time; var elapsed = DateTime.Now - time;
Logger.Info(I18NManager.Translate("Server.ServerInfo.ServerStarted", Logger.Info(I18NManager.Translate("Server.ServerInfo.ServerStarted",
Math.Round(elapsed.TotalSeconds, 2).ToString(CultureInfo.InvariantCulture))); Math.Round(elapsed.TotalSeconds, 2).ToString(CultureInfo.InvariantCulture)));
await consoleTask;
await ProcessExit(Volatile.Read(ref _exitCode));
} }
#region Exit #region Exit
@@ -64,30 +72,40 @@ public class MikuSB
AppDomain.CurrentDomain.ProcessExit += (_, _) => AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{ {
Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown")); Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown"));
ProcessExit(); RequestShutdown(0);
}; };
AppDomain.CurrentDomain.UnhandledException += (obj, arg) => AppDomain.CurrentDomain.UnhandledException += (obj, arg) =>
{ {
Logger.Error(I18NManager.Translate("Server.ServerInfo.UnhandledException", obj.GetType().Name), Logger.Error(I18NManager.Translate("Server.ServerInfo.UnhandledException", obj.GetType().Name),
(Exception)arg.ExceptionObject); (Exception)arg.ExceptionObject);
Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown")); Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown"));
ProcessExit(); RequestShutdown(1);
Environment.Exit(1);
}; };
Console.CancelKeyPress += (_, eventArgs) => Console.CancelKeyPress += (_, eventArgs) =>
{ {
Logger.Info(I18NManager.Translate("Server.ServerInfo.CancelKeyPressed")); Logger.Info(I18NManager.Translate("Server.ServerInfo.CancelKeyPressed"));
eventArgs.Cancel = true; eventArgs.Cancel = true;
Environment.Exit(0); RequestShutdown(0);
}; };
} }
private static void ProcessExit() private static void RequestShutdown(int exitCode)
{
Interlocked.Exchange(ref _exitCode, exitCode);
_cts.Cancel();
}
private static async Task ProcessExit(int exitCode)
{ {
SocketListener.Connections.Values.ToList().ForEach(x => x.Stop(true)); SocketListener.Connections.Values.ToList().ForEach(x => x.Stop(true));
DatabaseHelper.SaveThread?.Interrupt();
DatabaseHelper.SaveDatabase(); DatabaseHelper.Stop(); // notify stop
await DatabaseHelper.WaitAsync(); // wait AutoSave thread exit
DatabaseHelper.SaveDatabase(); // final flush
Environment.Exit(exitCode);
} }
# endregion # endregion

View File

@@ -9,7 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\MikuSB-Win64-Debug</PublishDir> <PublishDir>bin\MikuSB-Win64-Debug</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId> <_TargetId>Folder</_TargetId>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained> <SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile> <PublishSingleFile>false</PublishSingleFile>

View File

@@ -9,7 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\MikuSB-MultiFile\</PublishDir> <PublishDir>bin\MikuSB-MultiFile\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId> <_TargetId>Folder</_TargetId>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained> <SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile> <PublishSingleFile>false</PublishSingleFile>

View File

@@ -9,7 +9,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\MikuSB-OneFile\</PublishDir> <PublishDir>bin\MikuSB-OneFile\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol> <PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId> <_TargetId>Folder</_TargetId>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained> <SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile> <PublishSingleFile>true</PublishSingleFile>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CETCompat>false</CETCompat> <CETCompat>false</CETCompat>

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>MikuSB.Proxy</RootNamespace> <RootNamespace>MikuSB.Proxy</RootNamespace>

View File

@@ -30,7 +30,8 @@ public sealed class ProxyCertificateAuthority
RootCerPath); RootCerPath);
} }
public string RootCerPath => Path.Combine(CertificateDirectory, "MikuSB.Proxy.Root.cer"); public string RootCerPath => Path.Join(CertificateDirectory, "MikuSB.Proxy.Root.cer");
public string RootCerPemPath => Path.Join(CertificateDirectory, "MikuSB.Proxy.Root.pem");
private static string CertificateDirectory => Path.Combine(AppContext.BaseDirectory, "proxy-certs"); private static string CertificateDirectory => Path.Combine(AppContext.BaseDirectory, "proxy-certs");
@@ -55,6 +56,12 @@ public sealed class ProxyCertificateAuthority
if (!File.Exists(RootCerPath)) if (!File.Exists(RootCerPath))
File.WriteAllBytes(RootCerPath, existing.Export(X509ContentType.Cert)); File.WriteAllBytes(RootCerPath, existing.Export(X509ContentType.Cert));
if (!File.Exists(RootCerPemPath))
{
string pemString = existing.ExportCertificatePem();
File.WriteAllText(RootCerPemPath, pemString);
}
return existing; return existing;
} }
@@ -78,6 +85,9 @@ public sealed class ProxyCertificateAuthority
File.WriteAllBytes(pfxPath, exportable.Export(X509ContentType.Pfx, Password)); File.WriteAllBytes(pfxPath, exportable.Export(X509ContentType.Pfx, Password));
File.WriteAllBytes(RootCerPath, exportable.Export(X509ContentType.Cert)); File.WriteAllBytes(RootCerPath, exportable.Export(X509ContentType.Cert));
_logger.LogInformation("Created MikuSB proxy root certificate at {CertificatePath}", RootCerPath); _logger.LogInformation("Created MikuSB proxy root certificate at {CertificatePath}", RootCerPath);
File.WriteAllText(RootCerPemPath, exportable.ExportCertificatePem());
_logger.LogInformation("Created MikuSB proxy root certificate (PEM) at {CertificatePath}", RootCerPemPath);
return exportable; return exportable;
} }

View File

@@ -5,6 +5,7 @@ using System.Net.Sockets;
using System.Security.Authentication; using System.Security.Authentication;
using System.Text; using System.Text;
using MikuSB.Configuration; using MikuSB.Configuration;
using MikuSB.Util;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@@ -15,7 +16,7 @@ public sealed class ProxyServer(
IOptions<ProxyOptions> options, IOptions<ProxyOptions> options,
ProxyCertificateAuthority certificateAuthority, ProxyCertificateAuthority certificateAuthority,
HttpClient httpClient, HttpClient httpClient,
ILogger<ProxyServer> logger) : BackgroundService Logger logger) : BackgroundService
{ {
private const string ListenAddress = "127.0.0.1"; private const string ListenAddress = "127.0.0.1";
private const string ServerHost = "127.0.0.1"; private const string ServerHost = "127.0.0.1";
@@ -53,14 +54,14 @@ public sealed class ProxyServer(
{ {
if (!_options.Enabled) if (!_options.Enabled)
{ {
logger.LogInformation("MikuSB proxy is disabled"); logger.Info("MikuSB proxy is disabled");
return; return;
} }
var address = IPAddress.Parse(ListenAddress); var address = IPAddress.Parse(ListenAddress);
_listener = new TcpListener(address, _options.Port); _listener = new TcpListener(address, _options.Port);
_listener.Start(); _listener.Start();
logger.LogInformation("MikuSB proxy listening on {Address}:{Port}", ListenAddress, _options.Port); logger.Info($"MikuSB proxy listening on {ListenAddress}:{_options.Port}");
try try
{ {
@@ -85,6 +86,7 @@ public sealed class ProxyServer(
{ {
using (client) using (client)
{ {
logger.Info($"Proxy New client: {client.Client.RemoteEndPoint}");
try try
{ {
await HandleClientCoreAsync(client, cancellationToken); await HandleClientCoreAsync(client, cancellationToken);
@@ -100,12 +102,13 @@ public sealed class ProxyServer(
} }
catch (AuthenticationException ex) catch (AuthenticationException ex)
{ {
logger.LogWarning(ex, "Proxy TLS authentication failed"); logger.Warn($"Proxy TLS authentication failed: {ex}");
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogWarning(ex, "Proxy client failed"); logger.Warn($"Proxy client failed {ex}");
} }
logger.Info($"Proxy client close: {client.Client.RemoteEndPoint}");
} }
} }
@@ -187,7 +190,7 @@ public sealed class ProxyServer(
{ {
var pathAndQuery = request.GetPathAndQuery(); var pathAndQuery = request.GetPathAndQuery();
var uri = new Uri($"http://{ServerHost}:{_options.ServerHttpPort}{pathAndQuery}"); var uri = new Uri($"http://{ServerHost}:{_options.ServerHttpPort}{pathAndQuery}");
logger.LogInformation("[Proxy] Redirect: {Method} {Host}{Path} -> {Uri}", request.Method, request.HostOverride ?? request.Host, pathAndQuery, uri); logger.Info($"Redirect: {request.Method} {request.HostOverride ?? request.Host}{pathAndQuery} -> {uri}");
await SendHttpRequestAsync(clientStream, request, uri, true, cancellationToken); await SendHttpRequestAsync(clientStream, request, uri, true, cancellationToken);
} }
@@ -202,7 +205,7 @@ public sealed class ProxyServer(
if (IsSelfReference(uri)) if (IsSelfReference(uri))
{ {
logger.LogWarning("[Proxy] Self-reference blocked: {Method} {Uri}", request.Method, uri); logger.Info($"Self-reference blocked: {request.Method} {uri}");
await WriteSimpleResponseAsync(clientStream, HttpStatusCode.LoopDetected, "Proxy self-reference detected", cancellationToken); await WriteSimpleResponseAsync(clientStream, HttpStatusCode.LoopDetected, "Proxy self-reference detected", cancellationToken);
return; return;
} }
@@ -351,7 +354,10 @@ public sealed class ProxyServer(
public string GetPathAndQuery() public string GetPathAndQuery()
{ {
if (Uri.TryCreate(Target, UriKind.Absolute, out var uri)) // "/query?version=a.b.c&platform=PC"
// => Uri.TryCreate() return true && uri.Scheme == "file"
// => will return "/query%3Fversion=a.b.c&platform=PC" cause 404
if (Uri.TryCreate(Target, UriKind.Absolute, out var uri) && uri.IsAbsoluteUri && (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
return uri.PathAndQuery; return uri.PathAndQuery;
if (string.IsNullOrEmpty(Target)) if (string.IsNullOrEmpty(Target))

66
README_linux.md Normal file
View File

@@ -0,0 +1,66 @@
# MikuSB on Linux
## Config
### setup steam launch options as following
`HTTP_PROXY="http://127.0.0.1:8888" HTTPS_PROXY="http://127.0.0.1:8888" ALL_PROXY="http://127.0.0.1:8888" %command%`
### start local server and keep it running
```
./MikuSB
```
### find root CA cert, and create ca bundle
root CA cert, should in the path: `proxy-certs/MikuSB.Proxy.Root.pem`
### setup root CA for proton/wine
not sure, even I remove Proton PFX (Wine prefix) folder, without redo this step, still no cert issue.
`Proton Hotfix` is the proton version which selected in steam `Force the use of a specific Steam Play compatibility tool`
```bash
APPID=<THE-APP-ID-OF-THE-GAME>
STEAM_COMPAT_DATA_PATH=~/.steam/steam/steamapps/compatdata/$APPID/pfx
STEAM_WINE_PATH="$HOME/.steam/steam/steamapps/common/Proton Hotfix/files/bin/wine"
WINEPREFIX=$STEAM_COMPAT_DATA_PATH $STEAM_WINE_PATH certutil -addstore -f Root proxy-certs/MikuSB.Proxy.Root.pem
```
### start the game and enjoy
## development
1. Restore dependencies and build.
```bash
dotnet build
```
2. run it
```bash
dotnet run --project ./MikuSB
```
## release build
```bash
DOTNET_CLI_UI_LANGUAGE=en time dotnet publish ./MikuSB/MikuSB.csproj -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true --property:PublishDir=../publish
# output will in ./publish/*
cd ./publish
# start server
./MikuSB
```
## TODO:
* [ ] tool/script for CA cert create and install to proton/wine
* [ ] automatic done in main program

View File

@@ -17,17 +17,17 @@ public static class SdkServer
{ {
public static void Start(string[] args) public static void Start(string[] args)
{ {
BuildWebHost(args).RunAsync(); var builder = Host.CreateDefaultBuilder(args)
} .ConfigureWebHostDefaults(webBuilder =>
private static IWebHost BuildWebHost(string[] args)
{ {
var builder = WebHost.CreateDefaultBuilder(args) webBuilder
.UseStartup<Startup>() .UseStartup<Startup>()
.ConfigureLogging((_, logging) => { logging.ClearProviders(); }) .ConfigureLogging((_, logging) => { logging.ClearProviders(); })
.UseUrls(ConfigManager.Config.HttpServer.GetDisplayAddress()); .UseUrls(ConfigManager.Config.HttpServer.GetDisplayAddress());
});
return builder.Build(); var host = builder.Build();
host.RunAsync();
} }
} }
@@ -91,7 +91,7 @@ public class Startup
{ {
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
}); });
services.AddSingleton<Logger>(_ => new Logger("HttpServer")); services.AddSingleton<Logger>(_ => new Logger("Proxy"));
services.AddMikuSbProxy(ConfigManager.Config.Proxy); services.AddMikuSbProxy(ConfigManager.Config.Proxy);
} }
} }

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>MikuSB.SdkServer</RootNamespace> <RootNamespace>MikuSB.SdkServer</RootNamespace>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<CETCompat>false</CETCompat> <CETCompat>false</CETCompat>
@@ -11,7 +11,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.2" /> <PackageReference Include="Google.Protobuf" Version="3.29.2" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1 +1 @@
v=1.3 v=1.6