-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8796a05
commit 435a453
Showing
11 changed files
with
351 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,58 @@ | ||
using MinecraftLaunch; | ||
using MinecraftLaunch.Components.Resolver; | ||
using MinecraftLaunch.Components.Installer; | ||
using MinecraftLaunch.Components.Watcher; | ||
using MinecraftLaunch.Classes.Models.Event; | ||
|
||
GameResolver gameResolver = new("C:\\Users\\w\\Downloads\\.minecraft"); | ||
# region ServerPing | ||
|
||
VanlliaInstaller vanlliaInstaller = new(gameResolver, "1.12.2"); | ||
vanlliaInstaller.ProgressChanged += (_, args) => { | ||
Console.WriteLine($"{args.Progress * 100:0.00} - {args.Status} - {args.ProgressStatus}"); | ||
}; | ||
ServerPingWatcher serverPingWatcher = new(25565, "mc.163mc.cn", 47); | ||
|
||
await vanlliaInstaller.InstallAsync(); | ||
serverPingWatcher.ServerConnectionProgressChanged += OnServerConnectionProgressChanged; | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
Console.WriteLine(); | ||
serverPingWatcher.ServerLatencyChanged += (_, args) => { | ||
Console.WriteLine($"{args.Latency}ms"); | ||
}; | ||
|
||
ForgeInstaller forgeInstaller = new(gameResolver.GetGameEntity("1.12.2"), | ||
(await ForgeInstaller.EnumerableFromVersionAsync("1.12.2")).First(), | ||
"C:\\Program Files\\Java\\jdk1.8.0_301\\bin\\javaw.exe", | ||
"1.12.2-forge-114514"); | ||
await serverPingWatcher.StartAsync(); | ||
|
||
forgeInstaller.ProgressChanged += (_, args) => { | ||
void OnServerConnectionProgressChanged(object? sender, ProgressChangedEventArgs args) { | ||
Console.WriteLine($"{args.Progress * 100:0.00} - {args.Status} - {args.ProgressStatus}"); | ||
}; | ||
if (args.Status == TaskStatus.Canceled) { | ||
serverPingWatcher.ServerConnectionProgressChanged -= OnServerConnectionProgressChanged; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
# region Forge Install | ||
|
||
//GameResolver gameResolver = new("C:\\Users\\w\\Downloads\\.minecraft"); | ||
|
||
//VanlliaInstaller vanlliaInstaller = new(gameResolver, "1.12.2"); | ||
//vanlliaInstaller.ProgressChanged += (_, args) => { | ||
// Console.WriteLine($"{args.Progress * 100:0.00} - {args.Status} - {args.ProgressStatus}"); | ||
//}; | ||
|
||
//await vanlliaInstaller.InstallAsync(); | ||
|
||
//Console.WriteLine(); | ||
//Console.WriteLine(); | ||
//Console.WriteLine(); | ||
//Console.WriteLine(); | ||
//Console.WriteLine(); | ||
|
||
//ForgeInstaller forgeInstaller = new(gameResolver.GetGameEntity("1.12.2"), | ||
// (await ForgeInstaller.EnumerableFromVersionAsync("1.12.2")).First(), | ||
// "C:\\Program Files\\Java\\jdk1.8.0_301\\bin\\javaw.exe", | ||
// "1.12.2-forge-114514"); | ||
|
||
//forgeInstaller.ProgressChanged += (_, args) => { | ||
// Console.WriteLine($"{args.Progress * 100:0.00} - {args.Status} - {args.ProgressStatus}"); | ||
//}; | ||
|
||
//await forgeInstaller.InstallAsync(); | ||
|
||
#endregion | ||
|
||
await forgeInstaller.InstallAsync(); | ||
Console.ReadKey(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace MinecraftLaunch.Classes.Interfaces; | ||
|
||
/// <summary> | ||
/// 监视器统一接口 | ||
/// </summary> | ||
public interface IWatcher { | ||
void Start(); | ||
} |
7 changes: 7 additions & 0 deletions
7
MinecraftLaunch/Classes/Models/Event/ServerLatencyChangedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
namespace MinecraftLaunch.Classes.Models.Event; | ||
public sealed class ServerLatencyChangedEventArgs : EventArgs { | ||
public long Latency { get; set; } | ||
public PingPayload Response { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
public sealed class PingPayload { | ||
[JsonPropertyName("favicon")] public string Icon { get; set; } | ||
[JsonPropertyName("version")] public VersionPayload Version { get; set; } | ||
[JsonPropertyName("players")] public PlayersPayload Players { get; set; } | ||
[JsonPropertyName("modinfo")] public ServerPingModInfo ModInfo { get; set; } | ||
[JsonPropertyName("description")] public JsonElement Description { get; set; } | ||
} | ||
|
||
[JsonSerializable(typeof(PingPayload))] | ||
sealed partial class PingPayloadContext : JsonSerializerContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
public sealed class Player { | ||
[JsonPropertyName("id")] public string Id { get; set; } | ||
[JsonPropertyName("name")] public string Name { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
public sealed class PlayersPayload { | ||
[JsonPropertyName("max")] public int Max { get; set; } | ||
[JsonPropertyName("online")] public int Online { get; set; } | ||
[JsonPropertyName("sample")] public Player[] Sample { get; set; } | ||
} |
13 changes: 13 additions & 0 deletions
13
MinecraftLaunch/Classes/Models/ServerPing/ServerPingModInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
public sealed class ServerPingModInfo { | ||
[JsonPropertyName("type")] public string Type { get; set; } | ||
[JsonPropertyName("modList")] public IEnumerable<ModInfo> ModList { get; set; } | ||
} | ||
|
||
public sealed class ModInfo { | ||
[JsonPropertyName("modid")] public string ModId { get; set; } | ||
[JsonPropertyName("version")] public string Version { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MinecraftLaunch.Classes.Models.ServerPing; | ||
|
||
public sealed class VersionPayload { | ||
[JsonPropertyName("name")] public string Name { get; set; } | ||
[JsonPropertyName("protocol")] public int Protocol { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.