Skip to content

Commit abdf61c

Browse files
committed
refactor(i18n): #376
1 parent 4ab9b93 commit abdf61c

File tree

5 files changed

+116
-61
lines changed

5 files changed

+116
-61
lines changed

common/common-core/src/main/java/com/iohao/game/action/skeleton/protocol/HeadMetadata.java

Lines changed: 81 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.io.Serializable;
3434

3535
/**
36+
* Meta information
37+
* <p>
3638
* 元信息
3739
*
3840
* @author 渔民小镇
@@ -66,6 +68,11 @@ public final class HeadMetadata implements Serializable {
6668
int cmdMerge;
6769

6870
/**
71+
* Source logic server client ID
72+
* <p>
73+
* If the request is initiated by an external server,
74+
* this value should be the external server's clientId (a server's unique identifier).
75+
* <p>
6976
* 来源逻辑服 client id
7077
* <pre>
7178
* 比如是对外服发起的请求,这个来源就是对外服的 clientId
@@ -77,6 +84,17 @@ public final class HeadMetadata implements Serializable {
7784
int sourceClientId;
7885

7986
/**
87+
* Target logic server endPointClientId
88+
* Used to specify which server should process the request
89+
* <p>
90+
* For example, with two chess servers (game logic servers) A and B:
91+
* When players Player1 and Player2 are in a match, if they started playing on Chess Server A,
92+
* then all subsequent requests must be assigned to Chess Server A for processing.
93+
* <p>
94+
* endPointClientId refers to the server's unique identifier.
95+
* <p>
96+
* see {@link com.iohao.game.common.kit.HashKit}
97+
* <p>
8098
* 目标逻辑服 endPointClientId
8199
* <pre>
82100
* 用于指定请求由哪个服务器处理
@@ -108,15 +126,23 @@ public final class HeadMetadata implements Serializable {
108126
byte rpcCommandType;
109127

110128
/**
111-
* 扩展字段
112-
* <pre>
113-
* 开发者有特殊业务可以通过这个字段来扩展元信息,该字段的信息会跟随每一个请求;
114-
* </pre>
129+
* Extended field. Developers can use this field to extend meta-information for special business needs.
130+
* The data in this field will be included with every request.
131+
* <p>
132+
* 扩展字段,开发者有特殊业务可以通过这个字段来扩展元信息,该字段的信息会跟随每一个请求。
115133
*/
116134
byte[] attachmentData;
117135

118136
/**
119-
* netty 的 channelId。
137+
* netty channelId
138+
* <p>
139+
* The framework stores Netty's channelId to allow the external server to look up the corresponding connection.
140+
* <p>
141+
* After a player logs in, the framework will use the player's userId to locate the corresponding connection (channel) instead of the channelId,
142+
* because the channelId string is too long, and transmitting this value to the logic server each time would slightly impact performance.
143+
* <p>
144+
* Once the player logs in, the framework will no longer use this property.
145+
* However, if needed, developers can repurpose this field for their own use.
120146
* <pre>
121147
* 框架存放 netty 的 channelId 是为了能在对外服查找到对应的连接。
122148
* 当玩家登录后,框架将会使用玩家的 userId 来查找对应的连接(channel),而不是 channelId ;
@@ -130,39 +156,69 @@ public final class HeadMetadata implements Serializable {
130156
/** 消息标记号;由前端请求时设置,服务器响应时会携带上 */
131157
int msgId;
132158

133-
/** 框架自用字段。将来变化可能较大,开发者请不要使用。 */
159+
/**
160+
* Framework's internal fields. Future changes are likely to be significant, so developers should refrain from using them.
161+
* <p>
162+
* 框架自用字段。将来变化可能较大,开发者请不要使用。
163+
*/
134164
int stick;
135165

136166
/**
167+
* The IDs of multiple game logic servers bound to the player
168+
* <pre>
169+
* All requests related to this game logic server will be routed to the bound game logic server for processing.
170+
* Even if multiple game logic servers of the same type are running, requests will still be directed to the originally bound server.
171+
* </pre>
172+
* <p>
137173
* 玩家绑定的多个游戏逻辑服 id
138174
* <pre>
139175
* 所有与该游戏逻辑服相关的请求都将被分配给已绑定的游戏逻辑服处理。
140176
* 即使启动了多个同类型的游戏逻辑服,该请求仍将被分配给已绑定的游戏逻辑服处理。
141177
* </pre>
142178
*/
143179
int[] bindingLogicServerIds;
144-
/** 框架自用字段。将来变化可能较大,开发者请不要使用。 */
180+
/**
181+
* Framework's internal fields. Future changes are likely to be significant, so developers should refrain from using them.
182+
* <p>
183+
* 框架自用字段。将来变化可能较大,开发者请不要使用。
184+
*/
145185
int cacheCondition;
146186
/**
147-
* 自定义数据,专为开发者预留的一个字段,开发者可以利用该字段来传递自定义数据
148-
* <pre>
149-
* 该字段由开发者自己定义,框架不会对数据做任何处理,也不会做任何检查,
150-
* 开发者可以利用该字段来传递任何数据,包括自定义对象。
151-
* </pre>
187+
* Custom data, a field reserved specifically for developers.
188+
* Developers can use this field to pass custom data.
189+
* The field is entirely user-defined—the framework will neither process nor validate its contents.
190+
* Developers can leverage it to transmit any data, including custom objects.
191+
* <p>
192+
* 自定义数据,专为开发者预留的一个字段,开发者可以利用该字段来传递自定义数据。
193+
* 该字段由开发者自己定义,框架不会对数据做任何处理,也不会做任何检查,开发者可以利用该字段来传递任何数据,包括自定义对象。
152194
*/
153195
byte[] customData;
154-
/** 所选执行器 */
155196
ExecutorSelectEnum executorSelect;
156-
/** traceId */
157197
String traceId;
158-
/** 框架自用字段。将来变化可能较大,开发者请不要使用。 */
198+
/**
199+
* Framework's internal fields. Future changes are likely to be significant, so developers should refrain from using them.
200+
* <p>
201+
* 框架自用字段。将来变化可能较大,开发者请不要使用。
202+
*/
159203
byte[] userProcessorExecutorSelectorBytes;
160-
/** 临时变量 */
204+
/**
205+
* Temporary variable
206+
* <p>
207+
* 临时变量
208+
*/
161209
transient Object other;
162210
transient int withNo;
163-
/** 请求命令类型: 0 心跳,1 业务 */
211+
/**
212+
* Request command type: 0 Heartbeat, 1 Business
213+
* <p>
214+
* 请求命令类型: 0 心跳,1 业务
215+
*/
164216
transient int cmdCode;
165-
/** 协议开关,用于一些协议级别的开关控制,比如 安全加密校验等。 : 0 不校验 */
217+
/**
218+
* Protocol switch: Used for protocol-level control (e.g., security encryption verification). 0: No verification
219+
* <p>
220+
* 协议开关,用于一些协议级别的开关控制,比如 安全加密校验等。 : 0 不校验
221+
*/
166222
transient int protocolSwitch;
167223
/** 预留 inet */
168224
@Ignore
@@ -176,18 +232,6 @@ public HeadMetadata setCmdInfo(CmdInfo cmdInfo) {
176232
return this;
177233
}
178234

179-
/**
180-
* 得到 cmdInfo 命令路由信息
181-
* <pre>
182-
* 如果只是为了获取 cmd 与 subCmd,下面的方式效率会更高
183-
* cmd = CmdKit.getCmd(cmdMerge);
184-
* subCmd = CmdKit.getSubCmd(cmdMerge);
185-
*
186-
* 但实际上更推荐使用 CmdInfo,这样使得代码书写简洁,也更容易理解,毕竟代码是给人看的。
187-
* </pre>
188-
*
189-
* @return cmdInfo
190-
*/
191235
public CmdInfo getCmdInfo() {
192236
return CmdInfo.of(this.cmdMerge);
193237
}
@@ -198,16 +242,18 @@ public HeadMetadata setCmdMerge(int cmdMerge) {
198242
}
199243

200244
/**
201-
* 类似 clone
245+
* Simple clone
202246
* <p>
203-
* 使用场景
247+
* Usage scenario (使用场景
204248
* <pre>
205-
* 与其他游戏逻辑服通信时可以使用
206-
* 方法中给 HeadMetadata 赋值了玩家的必要属性:
249+
* Can be used when communicating with other game logic servers.
250+
* The method assigns necessary player attributes to HeadMetadata.
251+
*
252+
* (与其他游戏逻辑服通信时可以使用,方法中给 HeadMetadata 赋值了玩家的必要属性)
207253
* userId、attachmentData、channelId、bindingLogicServerIds、customData
208254
* traceId、executorSelect
209255
* </pre>
210-
* 以下属性不会赋值,如有需要,请自行赋值
256+
* Unassigned by default. Set manually when required. (以下属性不会赋值,如有需要,请自行赋值
211257
* <pre>
212258
* cmdMerge
213259
* sourceClientId

common/common-core/src/main/resources/iohao.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gameExternalServer=GameExternalServer
33
cmdName=Routing
44
# see BrokerClientNodeInfo.java
55
gameServerAmount=Number of servers
6-
# ExternalJoinEnum
6+
# ExternalJoinEnum.java
77
connectionWay=Connection way
88
# about brokerServer
99
gameBrokerServer=GameBrokerServer
@@ -37,15 +37,15 @@ timeRangeInOutHourTitle=%d:00 execute[%s];
3737
timeRangeInOutMinuteTitle=[%d~%d minutes, execute:%d]
3838
# see ActionCommandRegions.java
3939
cmdMergeLimit=%s exceeds the maximum default value. Please set the capacity manually if necessary. Default maximum capacity %d, current capacity %d
40-
# see ProtobufCheckActionParserListener
40+
# see ProtobufCheckActionParserListener.java
4141
protobufAnnotationCheck=Note that the protocol class does not have the ProtobufClass annotation added
42-
# see TextDocumentGenerate
42+
# see TextDocumentGenerate.java
4343
textDocumentTitle=Game Document Format Description
4444
textDocumentBroadcastTitle=Other broadcast interfaces
4545
textDocumentCmd=Routing
4646
textDocumentBroadcast=Broadcast
4747
textDocumentErrorCodeTitle=Error Code
48-
# see DefaultUserHook
48+
# see DefaultUserHook.java
4949
userHookInto=[PlayerOnline] CountOnline
5050
userHookQuit=[PlayerOffline] CountOnline
5151
# see InternalAboutFlowContext.java

common/common-core/src/main/resources/iohao_zh_CN.properties

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gameExternalServer=游戏对外服
33
cmdName=路由
44
# see BrokerClientNodeInfo.java
55
gameServerAmount=服务器的数量
6-
# ExternalJoinEnum
6+
# ExternalJoinEnum.java
77
connectionWay=连接方式
88
# about brokerServer
99
gameBrokerServer=游戏网关(Broker)
@@ -37,17 +37,16 @@ timeRangeInOutHourTitle=%d:00 共 %s 次;
3737
timeRangeInOutMinuteTitle=[%d~%d分钟,%d 次]
3838
# see ActionCommandRegions.java
3939
cmdMergeLimit=%s 超过最大默认值,如有需要请手动设置容量。默认最大容量 %d. 当前容量 %d
40-
# see ProtobufCheckActionParserListener
40+
# see ProtobufCheckActionParserListener.java
4141
protobufAnnotationCheck=注意,协议类没有添加 ProtobufClass 注解
42-
# see TextDocumentGenerate
42+
# see TextDocumentGenerate.java
4343
textDocumentTitle=游戏文档格式说明
4444
textDocumentBroadcastTitle=其它广播推送
4545
textDocumentCmd=路由
4646
textDocumentBroadcast=广播
4747
textDocumentErrorCodeTitle=错误码
48-
# see DefaultUserHook
48+
# see DefaultUserHook.java
4949
userHookInto=[玩家上线] 在线数量
5050
userHookQuit=[玩家下线] 在线数量
5151
# see InternalAboutFlowContext.java
5252
bindingUserId=请登录后使用该方法. see FlowContext.bindingUserId.
53-

common/common-validation/src/main/java/com/iohao/game/common/validation/Validation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Validator getValidator() throws Exception {
7777
ClassScanner classScanner = new ClassScanner(packageName, clazz -> clazz.getName().equals(className));
7878
List<Class<?>> classList = classScanner.listScan();
7979
if (classList.isEmpty()) {
80-
throw new Exception("缺少类: " + className);
80+
throw new ClassNotFoundException(className);
8181
}
8282

8383
Class<?> clazz = classList.getFirst();
@@ -101,7 +101,7 @@ private String getValidatorClassName() {
101101
try {
102102
className = ResourceKit.readStr(fileName, StandardCharsets.UTF_8);
103103
} catch (Exception e) {
104-
log.info("读取 {} 失败,将使用默认类 {} 来处理", fileName, defaultValidator);
104+
log.info("Use the default class {} to handle it because reading {} failed.", defaultValidator, fileName);
105105
}
106106

107107
if (StringUtils.isBlank(className)) {

external/external-core/src/main/java/com/iohao/game/external/core/session/UserSession.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
import com.iohao.game.external.core.message.ExternalCodecKit;
2828

2929
/**
30-
* UserSession 接口
31-
* <pre>
32-
* 对应的动态属性接口 {@link UserSessionOption}
33-
* </pre>
30+
* UserSession interface
31+
* <p>
32+
* UserSession 接口, 对应的动态属性接口 {@link UserSessionOption}
3433
*
3534
* @author 渔民小镇
3635
* @date 2023-02-18
36+
* @see UserSessionOption UserSessionOption for dynamic properties
3737
*/
3838
public interface UserSession extends AttrOptionDynamic {
3939
/**
@@ -61,38 +61,46 @@ public interface UserSession extends AttrOptionDynamic {
6161
long getUserId();
6262

6363
/**
64+
* authVerified
65+
* <p>
6466
* 是否进行身份验证
6567
*
66-
* @return true 已经身份验证了,表示登录过了。
68+
* @return true: logged in. (true 已经身份验证了,表示登录过了。
6769
*/
6870
boolean isVerifyIdentity();
6971

7072
/**
71-
* 当前用户(玩家)的 State
73+
* UserSessionState of current player
7274
*
73-
* @return 当前用户(玩家)的 State
75+
* @return State
7476
*/
7577
UserSessionState getState();
7678

7779
/**
80+
* UserChannelId of current player
81+
* <p>
7882
* 当前用户(玩家)的 UserChannelId
7983
*
80-
* @return 当前用户(玩家)的 UserChannelId
84+
* @return UserChannelId
8185
*/
8286
UserChannelId getUserChannelId();
8387

8488
/**
89+
* Adds user info to request.
90+
* <p>
91+
* Developers can extend data via HeadMetadata.setAttachmentData(byte[]), which will be forwarded to the logic server.
92+
* <p>
8593
* 给请求消息加上一些 user 自身的数据
86-
* <pre>
87-
* 如果开发者要扩展数据,可通过 {@link HeadMetadata#setAttachmentData(byte[])} 字段来扩展
88-
* 这些数据可以传递到逻辑服
89-
* </pre>
94+
* <p>
95+
* 如果开发者要扩展数据,可通过 {@link HeadMetadata#setAttachmentData(byte[])} 字段来扩展,这些数据可以传递到逻辑服
9096
*
91-
* @param requestMessage 请求消息
97+
* @param requestMessage requestMessage
9298
*/
9399
void employ(BarMessage requestMessage);
94100

95101
/**
102+
* Attach user data to HeadMetadata
103+
* <p>
96104
* 给 HeadMetadata 加上一些 user 自身的数据
97105
*
98106
* @param headMetadata HeadMetadata
@@ -108,16 +116,18 @@ public interface UserSession extends AttrOptionDynamic {
108116
<T> T writeAndFlush(Object message);
109117

110118
/**
111-
* 获取玩家 ip
119+
* Get player IP
112120
*
113121
* @return 玩家 ip
114122
*/
115123
String getIp();
116124

117125
/**
126+
* Creates RequestMessage with user's own info.
127+
* <p>
118128
* 创建 RequestMessage,内部会将 User 自身的相关信息设置到 RequestMessage 中。
119129
*
120-
* @param cmdInfo 路由
130+
* @param cmdInfo cmdInfo
121131
* @return RequestMessage
122132
* @since 21.15
123133
*/

0 commit comments

Comments
 (0)