新增 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: 类型定义
27 lines
662 B
Python
27 lines
662 B
Python
import time
|
|
|
|
DEDUP_TTL = 30.0
|
|
MAX_DEDUP_ENTRIES = 200
|
|
|
|
_dedup_cache: dict[int, float] = {}
|
|
|
|
|
|
def is_duplicate(message_index: int) -> bool:
|
|
now = time.monotonic()
|
|
if message_index in _dedup_cache:
|
|
if now - _dedup_cache[message_index] < DEDUP_TTL:
|
|
return True
|
|
_dedup_cache[message_index] = now
|
|
if len(_dedup_cache) > MAX_DEDUP_ENTRIES:
|
|
stale = [k for k, v in _dedup_cache.items() if now - v > DEDUP_TTL]
|
|
for k in stale:
|
|
del _dedup_cache[k]
|
|
return False
|
|
|
|
|
|
def mark_seen(message_index: int) -> None:
|
|
_dedup_cache[message_index] = time.monotonic()
|
|
|
|
|
|
def reset() -> None:
|
|
_dedup_cache.clear() |