mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 16:23:58 +00:00
Compare commits
30 Commits
9b8fa5d7c8
...
v1.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1fce4ca2e6 | ||
|
|
93c59e5730 | ||
|
|
f7814b0537 | ||
|
|
2fdda3157f | ||
|
|
f07c5f77fd | ||
|
|
2883ac3d41 | ||
|
|
49f4fdfda5 | ||
|
|
bcc5716f97 | ||
|
|
4bd66621bf | ||
|
|
14a611bf8e | ||
|
|
283358f1ec | ||
|
|
5d8b3f2bad | ||
|
|
a992bc86c5 | ||
|
|
d97eae6f5b | ||
|
|
04121eb357 | ||
|
|
391879a483 | ||
|
|
8e3323dd94 | ||
|
|
7e83d2ccd2 | ||
|
|
408113963b | ||
|
|
fcf0bf0843 | ||
|
|
2bf7554c53 | ||
|
|
50121d619b | ||
|
|
e8bb77e90e | ||
|
|
5f173ce8d2 | ||
|
|
5f3fc0c746 | ||
|
|
2fe795d29a | ||
|
|
b256fe7b01 | ||
|
|
e93dadafe8 | ||
|
|
34b93ad55d | ||
|
|
3eca16a661 |
57
.github/workflows/release.yml
vendored
57
.github/workflows/release.yml
vendored
@@ -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
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
@@ -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; } = false;
|
||||||
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;
|
||||||
|
|||||||
24
Common/Data/Excel/CallItemExcel.cs
Normal file
24
Common/Data/Excel/CallItemExcel.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
Common/Data/Excel/CardSkinPartsExcel.cs
Normal file
27
Common/Data/Excel/CardSkinPartsExcel.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Common/Data/Excel/Rogue3DDailyBuffExcel.cs
Normal file
18
Common/Data/Excel/Rogue3DDailyBuffExcel.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("dailybuff.json")]
|
||||||
|
public class Rogue3DDailyBuffExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("ID")] public uint Id { get; set; }
|
||||||
|
[JsonProperty("GroupID")] public uint GroupId { get; set; }
|
||||||
|
[JsonProperty("ScoreBuffID")] public uint ScoreBuffId { get; set; }
|
||||||
|
|
||||||
|
public override uint GetId() => Id;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.Rogue3DDailyBuffData[Id] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Common/Data/Excel/Rogue3DSeasonExcel.cs
Normal file
19
Common/Data/Excel/Rogue3DSeasonExcel.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("server_10_season.json")]
|
||||||
|
public class Rogue3DSeasonExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("SeasonID")] public uint SeasonId { get; set; }
|
||||||
|
[JsonProperty("Type")] public int Type { get; set; }
|
||||||
|
[JsonProperty("OpenTime")] public string OpenTime { get; set; } = "";
|
||||||
|
[JsonProperty("CloseTime")] public string CloseTime { get; set; } = "";
|
||||||
|
|
||||||
|
public override uint GetId() => SeasonId;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.Rogue3DSeasonData[SeasonId] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
Common/Data/Excel/Rogue3DTalentExcel.cs
Normal file
31
Common/Data/Excel/Rogue3DTalentExcel.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("server_03_talent.json")]
|
||||||
|
public class Rogue3DTalentExcel : ExcelResource
|
||||||
|
{
|
||||||
|
[JsonProperty("TalentID")] public uint TalentId { get; set; }
|
||||||
|
[JsonProperty("UnlockCondition")] private object? UnlockConditionRaw { get; set; }
|
||||||
|
[JsonIgnore] public uint UnlockCondition { get; private set; }
|
||||||
|
|
||||||
|
public override uint GetId() => TalentId;
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
UnlockCondition = ParseUnlockCondition(UnlockConditionRaw);
|
||||||
|
GameData.Rogue3DTalentData[TalentId] = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint ParseUnlockCondition(object? raw)
|
||||||
|
{
|
||||||
|
return raw switch
|
||||||
|
{
|
||||||
|
null => 0,
|
||||||
|
long value when value > 0 => (uint)value,
|
||||||
|
int value when value > 0 => (uint)value,
|
||||||
|
string text when uint.TryParse(text, out var value) => value,
|
||||||
|
_ => 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Common/Data/Excel/WeaponPartsExcel.cs
Normal file
24
Common/Data/Excel/WeaponPartsExcel.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.Data.Excel;
|
||||||
|
|
||||||
|
[ResourceEntity("weapon_parts.json")]
|
||||||
|
public class WeaponPartsExcel : 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; }
|
||||||
|
public string I18n { get; set; } = "";
|
||||||
|
public override uint GetId()
|
||||||
|
{
|
||||||
|
return (uint)I18n.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Loaded()
|
||||||
|
{
|
||||||
|
GameData.WeaponPartsData.Add(GetId(), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,6 +16,9 @@ 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<uint, Rogue3DSeasonExcel> Rogue3DSeasonData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, Rogue3DTalentExcel> Rogue3DTalentData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, Rogue3DDailyBuffExcel> Rogue3DDailyBuffData { get; private set; } = [];
|
||||||
public static Dictionary<int, BreakExcel> BreakData { 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; } = [];
|
||||||
@@ -23,6 +26,9 @@ public static class GameData
|
|||||||
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; } = [];
|
||||||
|
public static Dictionary<uint, CardSkinPartsExcel> CardSkinPartsData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, CallItemExcel> CallItemData { get; private set; } = [];
|
||||||
|
public static Dictionary<uint, WeaponPartsExcel> WeaponPartsData { get; private set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GameResourceTemplateId
|
public static class GameResourceTemplateId
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ 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; } = [];
|
||||||
@@ -58,6 +59,7 @@ public class CharacterInfo
|
|||||||
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_WEAPON] = WeaponUniqueId;
|
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_WEAPON] = WeaponUniqueId;
|
||||||
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_SKIN] = SkinId;
|
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_SKIN] = SkinId;
|
||||||
proto.Slots[(uint)ItemCardSlotTypeEnum.SLOT_WEAPON_SKIN] = 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;
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public abstract class GrowableItemInfo : BaseGameItemInfo
|
|||||||
|
|
||||||
public class GameWeaponInfo : GrowableItemInfo
|
public class GameWeaponInfo : GrowableItemInfo
|
||||||
{
|
{
|
||||||
|
[SugarColumn(IsJson = true)] public Dictionary<uint, ulong> PartSlots { get; set; } = [];
|
||||||
public override Item ToProto()
|
public override Item ToProto()
|
||||||
{
|
{
|
||||||
var proto = new Item
|
var proto = new Item
|
||||||
@@ -78,11 +79,13 @@ public class GameWeaponInfo : GrowableItemInfo
|
|||||||
Evolue = Evolue
|
Evolue = Evolue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
foreach (var (slot, uid) in PartSlots) proto.Slots[slot] = uid;
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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()
|
||||||
{
|
{
|
||||||
@@ -94,6 +97,7 @@ public class GameSkinInfo : BaseGameItemInfo
|
|||||||
Flag = (uint)Flag,
|
Flag = (uint)Flag,
|
||||||
};
|
};
|
||||||
proto.Slots[(uint)ItemSkinSlotTypeEnum.SLOT_CARD_SKIL_TYPE] = 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public class ServerTextCHS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WordTextCHS
|
public class WordTextCHS
|
||||||
{
|
{
|
||||||
|
public string WeaponPart => "武器部件";
|
||||||
|
public string CallItem => "召唤道具";
|
||||||
|
public string SkinPart => "皮肤部件";
|
||||||
public string Profile => "个人资料";
|
public string Profile => "个人资料";
|
||||||
public string WeaponSkin => "武器皮肤";
|
public string WeaponSkin => "武器皮肤";
|
||||||
public string SupportCard => "支援卡";
|
public string SupportCard => "支援卡";
|
||||||
@@ -242,7 +245,10 @@ public class GiveAllTextCHS
|
|||||||
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 profile <detail/-1> -g<类型> -p<特定> -l<等级>" +
|
||||||
|
"用法:/giveall skinpart <detail/-1> -g<類型> -p<特定> -l<等級>" +
|
||||||
|
"用法:/giveall weaponpart <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}!";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public class ServerTextCHT
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WordTextCHT
|
public class WordTextCHT
|
||||||
{
|
{
|
||||||
|
public string WeaponPart => "武器部件";
|
||||||
|
public string CallItem => "召喚道具";
|
||||||
|
public string SkinPart => "外觀部件";
|
||||||
public string Profile => "個人資料";
|
public string Profile => "個人資料";
|
||||||
public string WeaponSkin => "武器外觀";
|
public string WeaponSkin => "武器外觀";
|
||||||
public string SupportCard => "支援卡";
|
public string SupportCard => "支援卡";
|
||||||
@@ -242,7 +245,10 @@ public class GiveAllTextCHT
|
|||||||
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 profile <detail/-1> -g<類型> -p<特定> -l<等級>" +
|
||||||
|
"用法:/giveall skinpart <detail/-1> -g<類型> -p<特定> -l<等級>" +
|
||||||
|
"用法:/giveall weaponpart <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}!";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public class ServerTextEN
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WordTextEN
|
public class WordTextEN
|
||||||
{
|
{
|
||||||
|
public string WeaponPart => "Weapon Part";
|
||||||
|
public string CallItem => "Call Item";
|
||||||
|
public string SkinPart => "Skin Part";
|
||||||
public string Profile => "Profile";
|
public string Profile => "Profile";
|
||||||
public string WeaponSkin => "Weapon Skin";
|
public string WeaponSkin => "Weapon Skin";
|
||||||
public string Valk => "Valkyrie";
|
public string Valk => "Valkyrie";
|
||||||
@@ -208,7 +211,10 @@ public class GiveAllTextEN
|
|||||||
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 profile <detail/-1> -g<genre> -p<particular> -l<level>" +
|
||||||
|
"Usage: /giveall skinpart <detail/-1> -g<genre> -p<particular> -l<level>" +
|
||||||
|
"Usage: /giveall weaponpart <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!";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class IConsole
|
|||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Input = [];
|
Input = [];
|
||||||
CursorIndex = 0;
|
CursorIndex = 0;
|
||||||
if (InputHistory.Count >= HistoryMaxCount)
|
if (InputHistory.Count >= HistoryMaxCount)
|
||||||
InputHistory.RemoveAt(0);
|
InputHistory.RemoveAt(0);
|
||||||
InputHistory.Add(input);
|
InputHistory.Add(input);
|
||||||
HistoryIndex = InputHistory.Count;
|
HistoryIndex = InputHistory.Count;
|
||||||
@@ -80,7 +80,7 @@ public class IConsole
|
|||||||
public static void HandleUpArrow()
|
public static void HandleUpArrow()
|
||||||
{
|
{
|
||||||
if (InputHistory.Count == 0) return;
|
if (InputHistory.Count == 0) return;
|
||||||
|
|
||||||
if (HistoryIndex > 0)
|
if (HistoryIndex > 0)
|
||||||
{
|
{
|
||||||
HistoryIndex--;
|
HistoryIndex--;
|
||||||
@@ -94,7 +94,7 @@ public class IConsole
|
|||||||
public static void HandleDownArrow()
|
public static void HandleDownArrow()
|
||||||
{
|
{
|
||||||
if (HistoryIndex >= InputHistory.Count) return;
|
if (HistoryIndex >= InputHistory.Count) return;
|
||||||
|
|
||||||
HistoryIndex++;
|
HistoryIndex++;
|
||||||
if (HistoryIndex >= InputHistory.Count)
|
if (HistoryIndex >= InputHistory.Count)
|
||||||
{
|
{
|
||||||
@@ -102,7 +102,7 @@ public class IConsole
|
|||||||
Input = [];
|
Input = [];
|
||||||
CursorIndex = 0;
|
CursorIndex = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var history = InputHistory[HistoryIndex];
|
var history = InputHistory[HistoryIndex];
|
||||||
Input = [.. history];
|
Input = [.. history];
|
||||||
@@ -114,7 +114,7 @@ public class IConsole
|
|||||||
public static void HandleLeftArrow()
|
public static void HandleLeftArrow()
|
||||||
{
|
{
|
||||||
if (CursorIndex <= 0) return;
|
if (CursorIndex <= 0) return;
|
||||||
|
|
||||||
var (left, _) = Console.GetCursorPosition();
|
var (left, _) = Console.GetCursorPosition();
|
||||||
CursorIndex--;
|
CursorIndex--;
|
||||||
Console.SetCursorPosition(left - GetWidth(Input[CursorIndex].ToString()), Console.CursorTop);
|
Console.SetCursorPosition(left - GetWidth(Input[CursorIndex].ToString()), Console.CursorTop);
|
||||||
@@ -123,7 +123,7 @@ public class IConsole
|
|||||||
public static void HandleRightArrow()
|
public static void HandleRightArrow()
|
||||||
{
|
{
|
||||||
if (CursorIndex >= Input.Count) return;
|
if (CursorIndex >= Input.Count) return;
|
||||||
|
|
||||||
var (left, _) = Console.GetCursorPosition();
|
var (left, _) = Console.GetCursorPosition();
|
||||||
CursorIndex++;
|
CursorIndex++;
|
||||||
Console.SetCursorPosition(left + GetWidth(Input[CursorIndex - 1].ToString()), Console.CursorTop);
|
Console.SetCursorPosition(left + GetWidth(Input[CursorIndex - 1].ToString()), Console.CursorTop);
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,4 +150,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.Profile"), profileItems.Count.ToString()));
|
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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[CommandMethod("weaponpart")]
|
||||||
|
public async ValueTask GiveAllWeaponPart(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> weaponPartItems = [];
|
||||||
|
if (detail == -1)
|
||||||
|
{
|
||||||
|
// add all
|
||||||
|
foreach (var config in GameData.WeaponPartsData.Values)
|
||||||
|
{
|
||||||
|
var weaponPart = await player.InventoryManager!
|
||||||
|
.AddWeaponPartItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
|
||||||
|
if (weaponPart != null) weaponPartItems.Add(weaponPart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var weaponPart = await player.InventoryManager!.AddWeaponPartItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false);
|
||||||
|
if (weaponPart == null)
|
||||||
|
{
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.WeaponPart")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
weaponPartItems.Add(weaponPart);
|
||||||
|
}
|
||||||
|
if (weaponPartItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(weaponPartItems));
|
||||||
|
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
|
||||||
|
I18NManager.Translate("Word.WeaponPart"), weaponPartItems.Count.ToString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -270,4 +270,67 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
|
|||||||
|
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask<BaseGameItemInfo?> AddWeaponPartItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
|
||||||
|
{
|
||||||
|
if (genre != ItemTypeEnum.TYPE_WEAPON_PART) return null;
|
||||||
|
var weaponPartData = GameData.WeaponPartsData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
|
||||||
|
if (weaponPartData == null) return null;
|
||||||
|
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
|
||||||
|
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
|
||||||
|
var weaponPartInfo = new BaseGameItemInfo
|
||||||
|
{
|
||||||
|
TemplateId = templateId,
|
||||||
|
UniqueId = InventoryData.NextUniqueUid++,
|
||||||
|
ItemType = genre,
|
||||||
|
ItemCount = 1
|
||||||
|
};
|
||||||
|
InventoryData.Items[weaponPartInfo.UniqueId] = weaponPartInfo;
|
||||||
|
|
||||||
|
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([weaponPartInfo]));
|
||||||
|
|
||||||
|
return weaponPartInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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());
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database.Inventory;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
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; }
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
105
GameServer/Server/CallGS/Handlers/House/House_Request.cs
Normal file
105
GameServer/Server/CallGS/Handlers/House/House_Request.cs
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.House;
|
||||||
|
|
||||||
|
[CallGSApi("House_Request")]
|
||||||
|
public class House_Request : ICallGSHandler
|
||||||
|
{
|
||||||
|
private static readonly Random Random = new();
|
||||||
|
|
||||||
|
// GID for all house/arcade attributes
|
||||||
|
private const uint ArcadeGid = 101;
|
||||||
|
// HouseStorage.HouseArcadeStart = 18000
|
||||||
|
// Attr_GirlEndlessModeState = 5 → SID 18005
|
||||||
|
// ConditionType.TeachMode = 8, Attr_ConditionValStart = 36 → SID 18000+36+8 = 18044
|
||||||
|
private const uint EndlessModeStateSid = 18000 + 5;
|
||||||
|
private const uint TeachModeConditionSid = 18000 + 36 + 8; // = 18044
|
||||||
|
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<HouseRequestParam>(param);
|
||||||
|
if (req?.FuncName == null) return;
|
||||||
|
|
||||||
|
switch (req.FuncName)
|
||||||
|
{
|
||||||
|
case "ArcadeGameEnterMainUI":
|
||||||
|
await HandleArcadeGameEnterMainUI(connection);
|
||||||
|
break;
|
||||||
|
case "ArcadeGameEnter":
|
||||||
|
await HandleArcadeGameEnter(connection);
|
||||||
|
break;
|
||||||
|
case "ArcadeGameSettlement":
|
||||||
|
await HandleArcadeGameSettlement(connection);
|
||||||
|
break;
|
||||||
|
case "ArcadeGameLogSettlement":
|
||||||
|
await HandleArcadeGameLogSettlement(connection);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
var err = new JsonObject { ["FuncName"] = req.FuncName, ["sErr"] = "error.NotImplemented" };
|
||||||
|
await CallGSRouter.SendScript(connection, "House_Request", err.ToJsonString());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleArcadeGameEnterMainUI(Connection connection)
|
||||||
|
{
|
||||||
|
var girlList = new JsonArray();
|
||||||
|
for (int i = 1; i <= 25; i++)
|
||||||
|
girlList.Add(i);
|
||||||
|
|
||||||
|
var rsp = new JsonObject
|
||||||
|
{
|
||||||
|
["FuncName"] = "ArcadeGameEnterMainUI",
|
||||||
|
["tbUnlockGirlList"] = girlList
|
||||||
|
};
|
||||||
|
|
||||||
|
var player = connection.Player!;
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
|
||||||
|
sync.Custom[player.ToPackedAttrKey(ArcadeGid, TeachModeConditionSid)] = 1;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(ArcadeGid, TeachModeConditionSid)] = 1;
|
||||||
|
|
||||||
|
// Bits 1-25 set → all girls have endless mode unlocked
|
||||||
|
const uint endlessAllUnlocked = 0x3FFFFFE; // bits 1-25
|
||||||
|
sync.Custom[player.ToPackedAttrKey(ArcadeGid, EndlessModeStateSid)] = endlessAllUnlocked;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(ArcadeGid, EndlessModeStateSid)] = endlessAllUnlocked;
|
||||||
|
|
||||||
|
await CallGSRouter.SendScript(connection, "House_Request", rsp.ToJsonString(), sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleArcadeGameEnter(Connection connection)
|
||||||
|
{
|
||||||
|
var seed = Random.Next(1, 1_000_000_000);
|
||||||
|
var rsp = new JsonObject
|
||||||
|
{
|
||||||
|
["FuncName"] = "ArcadeGameEnter",
|
||||||
|
["nSeed"] = seed
|
||||||
|
};
|
||||||
|
await CallGSRouter.SendScript(connection, "House_Request", rsp.ToJsonString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleArcadeGameSettlement(Connection connection)
|
||||||
|
{
|
||||||
|
var rsp = new JsonObject
|
||||||
|
{
|
||||||
|
["FuncName"] = "ArcadeGameSettlement",
|
||||||
|
["nAddExp"] = 0
|
||||||
|
};
|
||||||
|
await CallGSRouter.SendScript(connection, "House_Request", rsp.ToJsonString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task HandleArcadeGameLogSettlement(Connection connection)
|
||||||
|
{
|
||||||
|
var rsp = new JsonObject { ["FuncName"] = "ArcadeGameLogSettlement" };
|
||||||
|
await CallGSRouter.SendScript(connection, "House_Request", rsp.ToJsonString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class HouseRequestParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("FuncName")]
|
||||||
|
public string? FuncName { get; set; }
|
||||||
|
}
|
||||||
@@ -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; } = [];
|
||||||
|
}
|
||||||
178
GameServer/Server/CallGS/Handlers/Rogue3D/Rogue3DStateHelper.cs
Normal file
178
GameServer/Server/CallGS/Handlers/Rogue3D/Rogue3DStateHelper.cs
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
using MikuSB.Data;
|
||||||
|
using MikuSB.Database.Player;
|
||||||
|
using MikuSB.GameServer.Game.Player;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Rogue3D;
|
||||||
|
|
||||||
|
internal static class Rogue3DStateHelper
|
||||||
|
{
|
||||||
|
private const uint GroupId = 124;
|
||||||
|
private const uint LevelPassStart = 20;
|
||||||
|
private const uint DailyBuffStart = 51;
|
||||||
|
private const uint DailyBuffEnd = 65;
|
||||||
|
private const int DailyBuffBitCount = 10;
|
||||||
|
private const int DailyBuffBitsPerValue = DailyBuffBitCount + 1;
|
||||||
|
private const uint DailyBuffMask = (1u << DailyBuffBitCount) - 1;
|
||||||
|
private const uint UnlockDiff1Sid = LevelPassStart + 1;
|
||||||
|
private const uint UnlockDiff2Sid = LevelPassStart + 2;
|
||||||
|
private const uint UnlockDiff3Sid = LevelPassStart + 3;
|
||||||
|
private const uint UnlockDiff4Sid = LevelPassStart + 4;
|
||||||
|
private static uint[]? ShuffledDailyBuffIds;
|
||||||
|
|
||||||
|
public static NtfSyncPlayer EnsureUnlockState(PlayerInstance player)
|
||||||
|
{
|
||||||
|
var sync = new NtfSyncPlayer();
|
||||||
|
|
||||||
|
EnsureMinAttr(player, UnlockDiff1Sid, 1, sync);
|
||||||
|
EnsureMinAttr(player, UnlockDiff2Sid, 1, sync);
|
||||||
|
EnsureMinAttr(player, UnlockDiff3Sid, 1, sync);
|
||||||
|
EnsureMinAttr(player, UnlockDiff4Sid, 1, sync);
|
||||||
|
|
||||||
|
foreach (var scienceSid in GetUnlockTalentScienceSids())
|
||||||
|
{
|
||||||
|
EnsureMinAttr(player, scienceSid, 1, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
EnsureDailyBuffAttrs(player, sync);
|
||||||
|
|
||||||
|
return sync;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<uint> GetUnlockTalentScienceSids()
|
||||||
|
{
|
||||||
|
return GameData.Rogue3DTalentData.Values
|
||||||
|
.Select(x => x.UnlockCondition)
|
||||||
|
.Where(x => x > 0)
|
||||||
|
.Distinct()
|
||||||
|
.OrderBy(x => x);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnsureDailyBuffAttrs(PlayerInstance player, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
var buffIds = GetOrCreateDailyBuffIds()
|
||||||
|
.Take((int)(DailyBuffEnd - DailyBuffStart + 1) * 3)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var index = 0;
|
||||||
|
for (var sid = DailyBuffStart; sid <= DailyBuffEnd; sid++)
|
||||||
|
{
|
||||||
|
uint packed = 0;
|
||||||
|
for (var slot = 0; slot < 3 && index < buffIds.Length; slot++, index++)
|
||||||
|
{
|
||||||
|
packed |= (buffIds[index] & DailyBuffMask) << (slot * DailyBuffBitsPerValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAttr(player, sid, packed, sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint[] GetOrCreateDailyBuffIds()
|
||||||
|
{
|
||||||
|
if (ShuffledDailyBuffIds != null)
|
||||||
|
{
|
||||||
|
return ShuffledDailyBuffIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupedBuffIds = GameData.Rogue3DDailyBuffData.Values
|
||||||
|
.Where(x => x.ScoreBuffId > 0 && x.ScoreBuffId <= DailyBuffMask)
|
||||||
|
.GroupBy(x => x.GroupId)
|
||||||
|
.OrderBy(x => x.Key)
|
||||||
|
.Select(x => x
|
||||||
|
.OrderBy(y => y.Id)
|
||||||
|
.Select(y => y.ScoreBuffId)
|
||||||
|
.Distinct()
|
||||||
|
.ToList())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var random = new Random();
|
||||||
|
foreach (var group in groupedBuffIds)
|
||||||
|
{
|
||||||
|
Shuffle(group, random);
|
||||||
|
}
|
||||||
|
Shuffle(groupedBuffIds, random);
|
||||||
|
|
||||||
|
var buffIds = new List<uint>();
|
||||||
|
var indexByGroup = new int[groupedBuffIds.Count];
|
||||||
|
var hasRemaining = true;
|
||||||
|
|
||||||
|
while (hasRemaining)
|
||||||
|
{
|
||||||
|
hasRemaining = false;
|
||||||
|
for (var i = 0; i < groupedBuffIds.Count; i++)
|
||||||
|
{
|
||||||
|
var group = groupedBuffIds[i];
|
||||||
|
var index = indexByGroup[i];
|
||||||
|
if (index >= group.Count)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffIds.Add(group[index]);
|
||||||
|
indexByGroup[i] = index + 1;
|
||||||
|
hasRemaining = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShuffledDailyBuffIds = buffIds.ToArray();
|
||||||
|
return ShuffledDailyBuffIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<uint> GetDailyBuffIds()
|
||||||
|
{
|
||||||
|
return GetOrCreateDailyBuffIds();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Shuffle<T>(IList<T> list, Random random)
|
||||||
|
{
|
||||||
|
for (var i = list.Count - 1; i > 0; i--)
|
||||||
|
{
|
||||||
|
var swapIndex = random.Next(i + 1);
|
||||||
|
(list[i], list[swapIndex]) = (list[swapIndex], list[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void EnsureMinAttr(PlayerInstance player, uint sid, uint value, NtfSyncPlayer sync, bool overwrite = false)
|
||||||
|
{
|
||||||
|
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||||
|
if (attr == null)
|
||||||
|
{
|
||||||
|
attr = new PlayerAttr { Gid = GroupId, Sid = sid, Val = value };
|
||||||
|
player.Data.Attrs.Add(attr);
|
||||||
|
AddSync(player, sync, sid, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!overwrite && attr.Val >= value) || (overwrite && attr.Val == value))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
attr.Val = value;
|
||||||
|
AddSync(player, sync, sid, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SetAttr(PlayerInstance player, uint sid, uint value, NtfSyncPlayer sync)
|
||||||
|
{
|
||||||
|
var attr = player.Data.Attrs.FirstOrDefault(x => x.Gid == GroupId && x.Sid == sid);
|
||||||
|
if (attr == null)
|
||||||
|
{
|
||||||
|
attr = new PlayerAttr { Gid = GroupId, Sid = sid };
|
||||||
|
player.Data.Attrs.Add(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr.Val == value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
attr.Val = value;
|
||||||
|
AddSync(player, sync, sid, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddSync(PlayerInstance player, NtfSyncPlayer sync, uint sid, uint value)
|
||||||
|
{
|
||||||
|
sync.Custom[player.ToPackedAttrKey(GroupId, sid)] = value;
|
||||||
|
sync.Custom[player.ToShiftedAttrKey(GroupId, sid)] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ public class Rogue3D_CheckOpenAct : ICallGSHandler
|
|||||||
{
|
{
|
||||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
{
|
{
|
||||||
await CallGSRouter.SendScript(connection, "Rogue3D_CheckOpenAct", "{\"bOpen\":true}");
|
var sync = Rogue3DStateHelper.EnsureUnlockState(connection.Player!);
|
||||||
|
await CallGSRouter.SendScript(connection, "Rogue3D_CheckOpenAct", "{\"bOpen\":true}", sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class Rogue3D_SelectMode : ICallGSHandler
|
|||||||
{
|
{
|
||||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
{
|
{
|
||||||
await CallGSRouter.SendScript(connection, "Rogue3D_SelectMode", "{}");
|
var sync = Rogue3DStateHelper.EnsureUnlockState(connection.Player!);
|
||||||
|
await CallGSRouter.SendScript(connection, "Rogue3D_SelectMode", "{}", sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||||
|
|
||||||
|
[CallGSApi("Weapon_ReplacePart")]
|
||||||
|
public class Weapon_ReplacePart : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<WeaponPartReplaceParam>(param);
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var player = connection.Player!;
|
||||||
|
var weaponData = player.InventoryManager.GetWeaponItem(req.Id);
|
||||||
|
if (weaponData == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "{}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint partId = 0;
|
||||||
|
if (req.PartId != -1)
|
||||||
|
{
|
||||||
|
var partData = player.InventoryManager.GetNormalItem((uint)req.PartId);
|
||||||
|
if (partData != null) partId = partData.UniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
|
weaponData.PartSlots[req.Type] = partId;
|
||||||
|
var sync = new NtfSyncPlayer
|
||||||
|
{
|
||||||
|
Items = { weaponData.ToProto() }
|
||||||
|
};
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ReplacePart", "null", sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class WeaponPartReplaceParam
|
||||||
|
{
|
||||||
|
public int PartId { get; set; }
|
||||||
|
public uint Type { get; set; }
|
||||||
|
public uint Id { get; set; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using MikuSB.Enums.Item;
|
||||||
|
using MikuSB.Proto;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Girl;
|
||||||
|
|
||||||
|
[CallGSApi("Weapon_ShowDefaultPart")]
|
||||||
|
public class Weapon_ShowDefaultPart : ICallGSHandler
|
||||||
|
{
|
||||||
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
|
{
|
||||||
|
var req = JsonSerializer.Deserialize<WeaponShowDefaultPartParam>(param);
|
||||||
|
if (req == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "{\"sErr\":\"error.BadParam\"}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var player = connection.Player!;
|
||||||
|
var weaponData = player.InventoryManager.GetWeaponItem(req.Id);
|
||||||
|
if (weaponData == null)
|
||||||
|
{
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "{}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.Flag == 1) weaponData.Flag = ItemFlagEnum.FLAG_WEAPON_DEFAULT;
|
||||||
|
else weaponData.Flag = ItemFlagEnum.FLAG_READED;
|
||||||
|
|
||||||
|
var sync = new NtfSyncPlayer
|
||||||
|
{
|
||||||
|
Items = { weaponData.ToProto() }
|
||||||
|
};
|
||||||
|
await CallGSRouter.SendScript(connection, "Weapon_ShowDefaultPart", "null", sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed class WeaponShowDefaultPartParam
|
||||||
|
{
|
||||||
|
[JsonPropertyName("nFlag")] public int Flag { get; set; }
|
||||||
|
public uint Id { get; set; }
|
||||||
|
}
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,44 +54,58 @@ 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
|
||||||
|
|
||||||
private static void RegisterExitEvent()
|
private static void RegisterExitEvent()
|
||||||
{
|
{
|
||||||
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
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -73,18 +74,27 @@ public sealed class ProxyServer(
|
|||||||
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
|
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
catch (SocketException) when (stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException) when (stoppingToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task StopAsync(CancellationToken cancellationToken)
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
// Cancel the BackgroundService token first so shutdown exceptions are treated as expected.
|
||||||
|
var stopTask = base.StopAsync(cancellationToken);
|
||||||
_listener?.Stop();
|
_listener?.Stop();
|
||||||
return base.StopAsync(cancellationToken);
|
await stopTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleClientAsync(TcpClient client, CancellationToken cancellationToken)
|
private async Task HandleClientAsync(TcpClient client, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
using (client)
|
using (client)
|
||||||
{
|
{
|
||||||
|
//logger.Debug($"Proxy New client: {client.Client.RemoteEndPoint}");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await HandleClientCoreAsync(client, cancellationToken);
|
await HandleClientCoreAsync(client, cancellationToken);
|
||||||
@@ -100,12 +110,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 +198,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);
|
if (ConfigManager.Config.HttpServer.EnableLog) 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 +213,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 +362,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))
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [.NET SDK 9.0](https://dotnet.microsoft.com/en-us/download/dotnet/9.0)
|
- [.NET SDK 10.0](https://dotnet.microsoft.com/en-us/download/dotnet/10.0)
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ English documentation is available in [README.md](README.md).
|
|||||||
|
|
||||||
## 要件
|
## 要件
|
||||||
|
|
||||||
- [.NET SDK 9.0](https://dotnet.microsoft.com/ja-jp/download/dotnet/9.0)
|
- [.NET SDK 10.0](https://dotnet.microsoft.com/ja-jp/download/dotnet/10.0)
|
||||||
|
|
||||||
## 起動方法
|
## 起動方法
|
||||||
|
|
||||||
|
|||||||
66
README_linux.md
Normal file
66
README_linux.md
Normal 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
|
||||||
@@ -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 =>
|
||||||
|
{
|
||||||
|
webBuilder
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.ConfigureLogging((_, logging) => { logging.ClearProviders(); })
|
||||||
|
.UseUrls(ConfigManager.Config.HttpServer.GetDisplayAddress());
|
||||||
|
});
|
||||||
|
|
||||||
private static IWebHost BuildWebHost(string[] args)
|
var host = builder.Build();
|
||||||
{
|
host.RunAsync();
|
||||||
var builder = WebHost.CreateDefaultBuilder(args)
|
|
||||||
.UseStartup<Startup>()
|
|
||||||
.ConfigureLogging((_, logging) => { logging.ClearProviders(); })
|
|
||||||
.UseUrls(ConfigManager.Config.HttpServer.GetDisplayAddress());
|
|
||||||
|
|
||||||
return builder.Build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v=1.4
|
v=1.8
|
||||||
Reference in New Issue
Block a user