mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 16:43:59 +00:00
Compare commits
4 Commits
v2.4
...
548c77850e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
548c77850e | ||
|
|
d8c356a01f | ||
|
|
26991c9706 | ||
|
|
4ee11618be |
46
Common/Util/PatchDownloadService.cs
Normal file
46
Common/Util/PatchDownloadService.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
|
namespace MikuSB.Util;
|
||||||
|
|
||||||
|
public static class PatchDownloadService
|
||||||
|
{
|
||||||
|
private static readonly Logger Logger = new("PatchDownloader");
|
||||||
|
private const string PatchRelativePath = @"Patch\MikuSB-Patch.dll";
|
||||||
|
private const string PatchDownloadUrl = "https://github.com/Kei-Luna/MikuSB-Patch/releases/download/MikuSB-Patch/MikuSB-Patch.dll";
|
||||||
|
private const int DownloadTimeoutSeconds = 60;
|
||||||
|
|
||||||
|
public static void EnsurePatchPresent()
|
||||||
|
{
|
||||||
|
var patchPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, PatchRelativePath));
|
||||||
|
if (File.Exists(patchPath))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(patchPath)!);
|
||||||
|
Logger.Warn($"Patch DLL not found. Downloading to {patchPath}.");
|
||||||
|
|
||||||
|
using var client = CreateHttpClient();
|
||||||
|
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(DownloadTimeoutSeconds));
|
||||||
|
using var response = client.GetAsync(PatchDownloadUrl, HttpCompletionOption.ResponseHeadersRead, cts.Token)
|
||||||
|
.GetAwaiter().GetResult();
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
using var source = response.Content.ReadAsStreamAsync(cts.Token).GetAwaiter().GetResult();
|
||||||
|
using var destination = File.Create(patchPath);
|
||||||
|
source.CopyTo(destination);
|
||||||
|
|
||||||
|
Logger.Info("Patch DLL download completed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient CreateHttpClient()
|
||||||
|
{
|
||||||
|
var client = new HttpClient
|
||||||
|
{
|
||||||
|
Timeout = Timeout.InfiniteTimeSpan
|
||||||
|
};
|
||||||
|
|
||||||
|
client.DefaultRequestHeaders.UserAgent.Add(
|
||||||
|
new ProductInfoHeaderValue("MikuSB-PatchDownloader", BuildVersion.Current));
|
||||||
|
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
using MikuSB.Util.Extensions;
|
|
||||||
|
|
||||||
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
|
namespace MikuSB.GameServer.Server.CallGS.Handlers.Misc;
|
||||||
|
|
||||||
// Client requests server time to calculate timezone offset.
|
// Client requests server time to calculate timezone offset.
|
||||||
// nTime1/nTime2 are DST transition reference timestamps; returning the same value means no offset.
|
// In the client, ZoneTime.lua hardcodes sTime1/sTime2; if nTime1/nTime2 are false, the client ignores this update.
|
||||||
|
// Otherwise, offset = nTimeX - ParseTimeNative(sTimeX).
|
||||||
[CallGSApi("ZoneTime_ReqTime")]
|
[CallGSApi("ZoneTime_ReqTime")]
|
||||||
public class ZoneTime_ReqTime : ICallGSHandler
|
public class ZoneTime_ReqTime : ICallGSHandler
|
||||||
{
|
{
|
||||||
public async Task Handle(Connection connection, string param, ushort seqNo)
|
public async Task Handle(Connection connection, string param, ushort seqNo)
|
||||||
{
|
{
|
||||||
var now = Extensions.GetUnixSec();
|
var arg = $"{{\"nTime1\":false,\"nTime2\":false}}";
|
||||||
var arg = $"{{\"nTime1\":{now},\"nTime2\":{now}}}";
|
|
||||||
await CallGSRouter.SendScript(connection, "ZoneTime_ChangeTime", arg);
|
await CallGSRouter.SendScript(connection, "ZoneTime_ChangeTime", arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public static class GameLaunchService
|
|||||||
public static int Launch(params string[] extraGameArguments)
|
public static int Launch(params string[] extraGameArguments)
|
||||||
{
|
{
|
||||||
ConfigManager.LoadConfig();
|
ConfigManager.LoadConfig();
|
||||||
|
PatchDownloadService.EnsurePatchPresent();
|
||||||
var options = LaunchOptions.FromConfig(extraGameArguments);
|
var options = LaunchOptions.FromConfig(extraGameArguments);
|
||||||
return Launch(options);
|
return Launch(options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v=2.4
|
v=2.5
|
||||||
Reference in New Issue
Block a user