Components
BaseComponent
BaseComponent()Source: hetu/data/component.py:223
所有组件的基类
Attributes
dtypes(np.dtype) — 组件的numpy格式的dtype信息
Methods
new_row
new_row(id_=None) -> numpy.recordSource: hetu/data/component.py:386
返回空数据行,id请设置为None,会自动生成规范雪花uuid,用于insert
new_rows
new_rows(size) -> numpy.rec.recarraySource: hetu/data/component.py:396
返回多行空数据行,用于批量insert
str_max_len
str_max_len(prop_name: str) -> intSource: hetu/data/component.py:406
返回字符串属性可存储的最大字符数(由该列 dtype 的列宽推导)。
用途:把可配置的长度上限钳到实际列宽,避免在调用方硬编码列宽,例如
min(user_cfg, MyComp.str_max_len("name"))。仅适用于字符串(U)/
字节(S)属性;其它 dtype 抛 ValueError。
dict_to_struct
dict_to_struct(data: dict) -> numpy.recordSource: hetu/data/component.py:424
从dict转换为c-struct like的类型,成为可直接传给数据库的行数据
struct_to_dict
struct_to_dict(data: numpy.record) -> dict[str, typing.Any]Source: hetu/data/component.py:431
从c-struct like的行数据转换为typed dict
duplicate
duplicate(namespace: str, suffix: str) -> type[hetu.data.component.BaseComponent]Source: hetu/data/component.py:437
复制一个新的副本组件。拥有相同的定义,但使用suffix结尾的新的名字。
注意:只能在 define_system 时,传递成员变量时使用,如:
@hetu.define_system(namespace="Loot", components=(Order.duplicate("Loot", "Copy"),))get_duplicates
get_duplicates(namespace: str) -> dict[str, type[hetu.data.component.BaseComponent]]Source: hetu/data/component.py:459
获取此Component在指定namespace下的所有副本实例
is_rls
is_rls() -> boolSource: hetu/data/component.py:464
判断此Component是否是RLS权限
Permission
Permission(*values)Source: hetu/common/permission.py:11
Bases: IntEnum
客户端访问权限级别。
用于 define_endpoint
/ define_system
暴露给客户端的调用权限,也用于
define_component
声明Component数据的读取权限。服务端内部代码不受这些权限
限制;业务逻辑中的写入权限和更细粒度安全检查仍需要自行实现。
Attributes
EVERYBODY(Any) — 任何客户端连接都允许访问;适合公开状态、公告、配置等低敏感数据。USER(Any) — 仅已登录客户端允许访问;要求ctx.caller有有效用户id。OWNER(Any) — Component行级读取权限;等同于RLS且预设rls_compare=("eq", "owner", "caller")。RLS(Any) — Component自定义行级读取权限;具体比较逻辑由rls_compare参数定义。GM(Any) — 只用于 System/Endpoint 的调用权限:已登录且ctx.is_gm()(group 以 “gm” 开头)的连接, 或管理员连接可以调用。GM 读数据和普通玩家一样,受 Component 权限与 RLS 限制;Component 不能用此权限。 Call permission for Systems/Endpoints only: logged-in connections whose group starts with “gm”, or admin connections. GMs read data like ordinary players.ADMIN(Any) — 仅管理员连接允许访问;要求ctx.is_admin()返回True。admin 是后台管理工具用的 root 级 权限,不要给游戏客户端的连接(GM 账号也不行),游戏里的管理功能用GM。 Admin connections only. Admin is root-level and meant for back-office tools: never give it to game-client connections (GMs included); in-game management usesGM.