Skip to content

Commit

Permalink
up 更新语言文件
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Mar 4, 2024
1 parent 5fd2dc0 commit f6f5bc9
Show file tree
Hide file tree
Showing 65 changed files with 781 additions and 750 deletions.
25 changes: 21 additions & 4 deletions src/ColorMC.Core/Asm/NettyServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ public static class NettyServer
private static ServerBootstrap s_bootstrap;
private static IChannel s_channel;

/// <summary>
/// 客户端信道
/// </summary>
private static readonly List<IChannel> s_channels = [];

/// <summary>
/// 获取所有正在使用的端口
/// </summary>
/// <returns>端口列表</returns>
private static List<int> PortIsUsed()
{
var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
Expand All @@ -31,10 +38,14 @@ private static List<int> PortIsUsed()
return allPorts;
}

/// <summary>
/// 获取一个没有使用的端口
/// </summary>
/// <returns>端口</returns>
private static int GetFirstAvailablePort()
{
var portUsed = PortIsUsed();
if (portUsed.Count > 50000)
if (portUsed.Count > 5000)
{
return -1;
}
Expand All @@ -50,6 +61,10 @@ private static int GetFirstAvailablePort()
while (true);
}

/// <summary>
/// 启动游戏端口服务器
/// </summary>
/// <returns></returns>
public static async Task<int> RunServerAsync()
{
if (s_channel != null)
Expand All @@ -66,8 +81,7 @@ public static async Task<int> RunServerAsync()
s_bootstrap
.ChildHandler(new ActionChannelInitializer<IChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
pipeline.AddLast("echo", new EchoServerHandler());
channel.Pipeline.AddLast("colormc", new EchoServerHandler());
}));

int port = GetFirstAvailablePort();
Expand All @@ -82,6 +96,9 @@ public static async Task<int> RunServerAsync()
}
}

/// <summary>
/// 停止游戏端口服务器
/// </summary>
private static async void Stop()
{
await s_channel.CloseAsync();
Expand Down Expand Up @@ -128,7 +145,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message)
{
if (message is IByteBuffer buffer)
{
ColorMCCore.NettyPack?.Invoke(context.Channel, buffer);
ColorMCCore.OnNettyPack(context.Channel, buffer);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ColorMC.Core/Config/ConfigUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static bool Load(string local, bool quit = false)
}
catch (Exception e)
{
ColorMCCore.Error(LanguageHelper.Get("Core.Config.Error1"), e, true);
ColorMCCore.OnError(LanguageHelper.Get("Core.Config.Error1"), e, true);
}
}
else if (!quit)
Expand Down
104 changes: 77 additions & 27 deletions src/ColorMC.Core/CoreMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,88 @@ public static class ColorMCCore
/// </summary>
/// <param name="text">消息</param>
public delegate void UpdateState(string? text);
public delegate Task<bool> UpdateSelect(string? text);
/// <summary>
/// 启动选择框
/// </summary>
/// <param name="text">消息</param>
/// <returns>是否确定</returns>
public delegate Task<bool> ChoiseCall(string? text);
/// <summary>
/// 没有Java
/// </summary>
public delegate void NoJava();
/// <summary>
/// Java解压
/// </summary>
public delegate void JavaUnzip();
public delegate Task<bool> LoginFail(LoginObj obj);
/// <summary>
/// 登录失败是否继续运行
/// </summary>
/// <param name="obj">账户</param>
/// <returns>是否继续运行</returns>
public delegate Task<bool> LoginFailRun(LoginObj obj);
/// <summary>
/// OAuth登录
/// </summary>
/// <param name="url">网址</param>
/// <param name="code">登陆码</param>
public delegate void LoginOAuthCode(string url, string code);
/// <summary>
/// 游戏复写
/// </summary>
/// <param name="obj">游戏实例</param>
/// <returns>是否复写</returns>
public delegate Task<bool> GameOverwirte(GameSettingObj obj);
/// <summary>
/// 整合包进度更新
/// </summary>
/// <param name="size">总进度</param>
/// <param name="now">目前进度</param>
public delegate void PackUpdate(int size, int now);
/// <summary>
/// 下载器状态更新
/// </summary>
/// <param name="state">状态</param>
public delegate void DownloaderUpdate(DownloadState state);
/// <summary>
/// 下载项目状态更新
/// </summary>
/// <param name="obj">项目</param>
public delegate void DownloadItemUpdate(DownloadItemObj obj);
/// <summary>
/// 压缩包导入状态改变
/// </summary>
/// <param name="state">状态</param>
public delegate void PackState(CoreRunState state);
/// <summary>
/// 游戏启动信息更新
/// </summary>
/// <param name="obj">游戏实例</param>
/// <param name="state">当前状态</param>
public delegate void GameLaunch(GameSettingObj obj, LaunchState state);
public delegate void DownloadItemUpdate(DownloadItemObj obj);

/// <summary>
/// 开始下载
/// 下载用的回调
/// </summary>
public static Func<ICollection<DownloadItemObj>, Task<bool>>? OnStartDownload;
public static Func<ICollection<DownloadItemObj>, Task<bool>>? TopDownload;

/// <summary>
/// 错误显示回调
/// 标题 错误 关闭程序
/// </summary>
public static event Action<string?, Exception?, bool>? OnError;
public static event Action<string?, Exception?, bool>? Error;
/// <summary>
/// 游戏日志回调
/// </summary>
public static event Action<GameSettingObj, string?>? OnGameLog;
public static event Action<GameSettingObj, string?>? GameLog;
/// <summary>
/// 语言重载
/// </summary>
public static event Action<LanguageType>? OnLanguageReload;

public static event Action<LanguageType>? LanguageReload;
/// <summary>
/// 收到游戏数据包
/// </summary>
public static Action<IChannel, IByteBuffer>? NettyPack;

public static event Action<IChannel, IByteBuffer>? NettyPack;
/// <summary>
/// 游戏退出事件
/// </summary>
Expand Down Expand Up @@ -132,7 +178,6 @@ public static class ColorMCCore

internal static ConcurrentDictionary<string, IGameHandel> Games = [];


/// <summary>
/// 初始化阶段1
/// </summary>
Expand Down Expand Up @@ -176,34 +221,34 @@ public static void Close()
Stop?.Invoke();
}

public static void Error(string text, Exception? e, bool close)
public static void KillGame(string uuid)
{
OnError?.Invoke(text, e, close);
Logs.Error(text, e);
if (Games.TryGetValue(uuid, out var handel))
{
handel.Kill();
}
}

public static void GameLog(GameSettingObj obj, string? text)
internal static void OnError(string text, Exception? e, bool close)
{
OnGameLog?.Invoke(obj, text);
Error?.Invoke(text, e, close);
Logs.Error(text, e);
}

public static void LanguageReload(LanguageType type)
internal static void OnGameLog(GameSettingObj obj, string? text)
{
OnLanguageReload?.Invoke(type);
GameLog?.Invoke(obj, text);
}

public static void OnGameExit(GameSettingObj obj, LoginObj obj1, int code)
internal static void OnLanguageReload(LanguageType type)
{
Games.TryRemove(obj.UUID, out _);
GameExit?.Invoke(obj, obj1, code);
LanguageReload?.Invoke(type);
}

public static void KillGame(string uuid)
internal static void OnGameExit(GameSettingObj obj, LoginObj obj1, int code)
{
if (Games.TryGetValue(uuid, out var handel))
{
handel.Kill();
}
Games.TryRemove(obj.UUID, out _);
GameExit?.Invoke(obj, obj1, code);
}

internal static void AddGame(string uuid, IGameHandel handel)
Expand All @@ -213,4 +258,9 @@ internal static void AddGame(string uuid, IGameHandel handel)
Games[uuid] = handel;
}
}

internal static void OnNettyPack(IChannel channel, IByteBuffer buffer)
{
NettyPack?.Invoke(channel, buffer);
}
}
7 changes: 3 additions & 4 deletions src/ColorMC.Core/Downloader/DownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ private static void Clear()

public static Task<bool> StartAsync(ICollection<DownloadItemObj> list)
{
if (ColorMCCore.OnStartDownload == null)
if (ColorMCCore.TopDownload == null)
{
return StartAsync(list, null, null);
}
else
{
return ColorMCCore.OnStartDownload(list);
return ColorMCCore.TopDownload(list);
}
}

Expand All @@ -141,8 +141,7 @@ public static Task<bool> StartAsync(ICollection<DownloadItemObj> list)
/// <param name="list">下载列表</param>
/// <returns>结果</returns>
public static async Task<bool> StartAsync(ICollection<DownloadItemObj> list,
ColorMCCore.DownloaderUpdate? update,
ColorMCCore.DownloadItemUpdate? update1)
ColorMCCore.DownloaderUpdate? update, ColorMCCore.DownloadItemUpdate? update1)
{
var names = new List<string>();
//下载器是否在运行
Expand Down
Loading

0 comments on commit f6f5bc9

Please sign in to comment.