Skip to content

Commit c55d9ca

Browse files
committed
feat(本地化): 添加网络模块RPC超时和消息编码异常的本地化支持
添加了两个新的本地化键值用于网络模块的错误提示: 1. RPC调用超时提示 2. 消息对象编码异常提示 同时在相关代码中替换了硬编码的错误信息为本地化字符串
1 parent 844e445 commit c55d9ca

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

GameFrameX.Localization/Keys.NetWork.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,25 @@ public static class NetWork
109109
/// 参数: {0} - 类型名称
110110
/// </remarks>
111111
public const string FailedToCreateObjectPool = "NetWork.FailedToCreateObjectPool";
112+
113+
/// <summary>
114+
/// RPC call timeout! Message is: {0} / RPC调用超时!消息为:{0}
115+
/// </summary>
116+
/// <remarks>
117+
/// 键名: NetWork.RpcCallTimeout
118+
/// 用途: 当RPC调用超时时记录错误
119+
/// 参数: {0} - 消息内容
120+
/// </remarks>
121+
public const string RpcCallTimeout = "NetWork.RpcCallTimeout";
122+
123+
/// <summary>
124+
/// If the message object is encoded abnormally, check the error log, exception: {0} / 如果消息对象编码异常,请检查错误日志,异常:{0}
125+
/// </summary>
126+
/// <remarks>
127+
/// 键名: NetWork.MessageEncodingError
128+
/// 用途: 当消息对象编码异常时记录错误
129+
/// 参数: {0} - 异常消息
130+
/// </remarks>
131+
public const string MessageEncodingError = "NetWork.MessageEncodingError";
112132
}
113133
}

GameFrameX.Localization/Localization/Messages/Resources.resx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@
349349
<value>Failed to create object pool for type {0}</value>
350350
</data>
351351

352+
<data name="NetWork.RpcCallTimeout" xml:space="preserve">
353+
<value>RPC call timeout! Message is: {0}</value>
354+
</data>
355+
356+
<data name="NetWork.MessageEncodingError" xml:space="preserve">
357+
<value>If the message object is encoded abnormally, check the error log, exception: {0}</value>
358+
</data>
359+
352360
<!-- Launcher module log and error keys -->
353361
<data name="Launcher.ServerStartBegin" xml:space="preserve">
354362
<value>Starting server {0}</value>

GameFrameX.Localization/Localization/Messages/Resources.zh-CN.resx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@
381381
<value>无法为类型 {0} 创建对象池</value>
382382
</data>
383383

384+
<data name="NetWork.RpcCallTimeout" xml:space="preserve">
385+
<value>RPC调用超时!消息为:{0}</value>
386+
</data>
387+
388+
<data name="NetWork.MessageEncodingError" xml:space="preserve">
389+
<value>如果消息对象编码异常,请检查错误日志,异常:{0}</value>
390+
</data>
391+
384392
<!-- Launcher模块日志和错误键名 -->
385393
<data name="Launcher.ServerStartBegin" xml:space="preserve">
386394
<value>开始启动服务器{0}</value>

GameFrameX.NetWork/NetworkMessagePackage.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using GameFrameX.NetWork.Abstractions;
3636
using GameFrameX.NetWork.Messages;
3737
using GameFrameX.ProtoBuf.Net;
38+
using GameFrameX.Foundation.Localization.Core;
3839

3940
namespace GameFrameX.NetWork;
4041

@@ -165,7 +166,9 @@ public static NetworkMessagePackage Create(INetworkMessage message, INetworkMess
165166
}
166167
catch (Exception e)
167168
{
168-
LogHelper.Error("If the message object is encoded abnormally, check the error log, exception:" + e);
169+
LogHelper.Error(LocalizationService.GetString(
170+
GameFrameX.Localization.Keys.NetWork.MessageEncodingError,
171+
e?.Message ?? "Unknown exception"));
169172
throw;
170173
}
171174
}

GameFrameX.NetWork/RpcSession.RpcData.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
using GameFrameX.Foundation.Utility;
3434
using GameFrameX.NetWork.Abstractions;
35+
using GameFrameX.Foundation.Localization.Core;
3536

3637
namespace GameFrameX.NetWork;
3738

@@ -158,7 +159,9 @@ public bool IncrementalElapseTime(long millisecondsTime)
158159
ElapseTime += millisecondsTime;
159160
if (ElapseTime >= Timeout)
160161
{
161-
var error = "Rpc call timeout! Message is :" + RequestMessage;
162+
var error = LocalizationService.GetString(
163+
GameFrameX.Localization.Keys.NetWork.RpcCallTimeout,
164+
RequestMessage?.ToString() ?? "null");
162165
_tcs.TrySetResult(new RpcResult(error));
163166
return true;
164167
}

0 commit comments

Comments
 (0)