ForcePilot/backend/package/yuxi/channel/extensions/minecraft/accounts.py
Kris b3b6c95094 feat(channel): 添加 Minecraft 渠道扩展
新增 Minecraft 渠道扩展,支持在 Yuxi 平台中集成 Minecraft 游戏服务器渠道。

包含以下功能模块:
- client: Minecraft 客户端封装
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- auth: 认证管理
- accounts: 账户管理
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- protocol: Minecraft 协议处理
- rcon: RCON 远程控制
- keepalive: 连接保活
- version_adapter: 版本适配
- setup: 初始化设置
- types: 类型定义
2026-05-21 11:26:52 +08:00

86 lines
3.4 KiB
Python

import logging
from yuxi.channel.extensions.minecraft.config import McAccountConfig, McConfig
from yuxi.channel.extensions.minecraft.types import ResolvedMcAccount
logger = logging.getLogger(__name__)
def list_mc_account_ids(cfg: McConfig) -> list[str]:
if cfg.accounts:
return [acc.account_id for acc in cfg.accounts]
return ["default"]
def resolve_mc_account(cfg: McConfig, account_id: str = "default") -> ResolvedMcAccount:
account_cfg = cfg.get_account(account_id)
if account_cfg is None:
if account_id == "default":
account_cfg = McAccountConfig(
host=cfg.host,
port=cfg.port,
version=cfg.version,
auth_mode=cfg.auth_mode,
username=cfg.username,
dm_policy=cfg.dm_policy,
group_policy=cfg.group_policy,
require_mention=cfg.require_mention,
allow_from=cfg.allow_from,
text_chunk_limit=cfg.text_chunk_limit,
reconnect_max_retries=cfg.reconnect_max_retries,
keep_alive_timeout=cfg.keep_alive_timeout,
rate_limit_window=cfg.rate_limit_window,
rate_limit_max=cfg.rate_limit_max,
)
else:
raise KeyError(f"Account '{account_id}' not found")
host = account_cfg.host or cfg.host
port = account_cfg.port or cfg.port
version = account_cfg.version if account_cfg.host else cfg.version
auth_mode = account_cfg.auth_mode if account_cfg.host else cfg.auth_mode
username = account_cfg.username or cfg.username
dm_policy = account_cfg.dm_policy if account_cfg.host else cfg.dm_policy
group_policy = account_cfg.group_policy if account_cfg.host else cfg.group_policy
require_mention = account_cfg.require_mention if account_cfg.host else cfg.require_mention
allow_from = account_cfg.allow_from or cfg.allow_from
text_chunk_limit = account_cfg.text_chunk_limit or cfg.text_chunk_limit
reconnect_max_retries = account_cfg.reconnect_max_retries or cfg.reconnect_max_retries
keep_alive_timeout = account_cfg.keep_alive_timeout or cfg.keep_alive_timeout
rate_limit_window = account_cfg.rate_limit_window or cfg.rate_limit_window
rate_limit_max = account_cfg.rate_limit_max or cfg.rate_limit_max
return ResolvedMcAccount(
account_id=account_id,
enabled=account_cfg.enabled,
name=account_cfg.name or account_id,
host=host,
port=port,
version=version,
auth_mode=auth_mode,
username=username,
microsoft_email=account_cfg.microsoft_email,
microsoft_password=account_cfg.microsoft_password,
rcon_port=account_cfg.rcon_port or cfg.rcon_port,
rcon_password=account_cfg.rcon_password,
dm_enabled=account_cfg.dm_enabled,
dm_policy=dm_policy,
group_policy=group_policy,
require_mention=require_mention,
allow_from=allow_from,
text_chunk_limit=text_chunk_limit,
reconnect_max_retries=reconnect_max_retries,
keep_alive_timeout=keep_alive_timeout,
rate_limit_window=rate_limit_window,
rate_limit_max=rate_limit_max,
)
def has_configured_state(cfg: McConfig) -> bool:
if cfg.host and cfg.username:
return True
for acc in cfg.accounts:
if acc.host and acc.username:
return True
return False