diff --git a/admin.php b/admin.php index 4ddd342..1ebb00a 100644 --- a/admin.php +++ b/admin.php @@ -209,6 +209,7 @@ if (is_file($ossTxt)) {
🧾 收银员管理
💳 充值对账
🛒 充值商店配置
+
📜 用户协议
🛡️ 安全配置(2FA / IP白名单 / 入口令牌)
@@ -288,6 +289,7 @@ function go(p) { else if (p==='cashier_manage') loadCashierManage(c); else if (p==='recharge_orders') loadRechargeOrders(c); else if (p==='shop_config') loadShopConfig(c); + else if (p==='rules') loadRules(c); } // 检查登录状态 @@ -4480,6 +4482,78 @@ async function loadShopConfig(el) { loadShopConfigData(); } +async function loadRules(el) { + el.innerHTML = '
加载中...
'; + try { + const res = await fetch('api/sync.php?action=rules_content', { + credentials: 'same-origin', + headers: { 'Content-Type': 'application/json' } + }); + const data = await res.json(); + if (!data.success || !data.data) { + el.innerHTML = '
❌ 加载失败:' + esc(data.message || '未知错误') + '
'; + return; + } + const d = data.data; + // 服务器未配置用户协议 + if (d.skipped || !d.has_agreement) { + el.innerHTML = `
+

📜 用户协议 · 玩家签署情况

+

服务器未配置用户协议(Web 目录 rules/ 下没有 .md 文件)。

+

此时登录页不显示勾选门控,也不要求玩家签章。

+
`; + return; + } + + const list = d.signed_list || []; + const totalSigned = d.total_signed || 0; + const curVersion = list.filter(r => r.current_version).length; + + let html = `
`; + html += `

📜 用户协议 · 玩家签署情况

`; + html += `
`; + html += ``; + html += `
`; + + html += '
'; + html += `
${totalSigned}
已签署玩家
`; + html += `
${curVersion}
当前版本已签
`; + html += `
${totalSigned - curVersion}
旧版本待重签
`; + html += `
`; + + // 协议元信息 + html += '

当前协议

'; + html += `

协议标题:${esc(d.title || '(无)')}
`; + html += `版本指纹:${esc(d.fingerprint || '')} | 共 ${d.line_count || 0} 行

`; + html += `

玩家端可通过登录页「查看协议原文」或 /rules 阅读正文;后台此处仅监控签署进度。

`; + html += '
'; + + // 签署清单表 + html += '

签署记录(按签署时间倒序,最多显示 200 条)

'; + if (list.length === 0) { + html += '

暂无玩家签署记录。玩家登录 Web 端并勾选「已阅用户协议」后,此处将生成签章回执并在此登记。

'; + } else { + html += ''; + html += ''; + for (const r of list) { + const when = r.signed_at > 0 ? new Date(r.signed_at * 1000).toLocaleString('zh-CN') : '未知'; + const verBadge = r.current_version + ? '✔ 当前版本' + : '⚠ 旧版本(协议已更新,需重签)'; + html += `` + + `` + + ``; + } + html += '
玩家签署时间版本状态
${esc(r.player)}${when}${verBadge}
'; + } + html += '
'; + + el.innerHTML = html; + } catch (e) { + el.innerHTML = '
加载失败:' + esc(e.message) + '
'; + } +} + async function loadShopConfigData() { const el = document.getElementById('shopConfigList'); if (!el) return; diff --git a/player.php b/player.php index 8372074..3758f0a 100644 --- a/player.php +++ b/player.php @@ -381,6 +381,7 @@ if ($currentVersion !== $BUILD_VERSION) { +
@@ -1273,6 +1274,99 @@ if ($currentVersion !== $BUILD_VERSION) { else if (page === 'credit') renderCredit(c); else if (page === 'recharge') renderRecharge(c); else if (page === 'orders') renderMyOrders(c); + else if (page === 'rules') renderRules(c); + } + + // ==================== 用户协议(玩家端查看协议原文) ==================== + // 数据源:api/sync.php?action=rules_content(读 Web 目录 rules/*.md) + // rules 目录无 .md → 提示"服务器未配置用户协议" + async function renderRules(el) { + el.innerHTML = `
正在加载用户协议...
`; + let d = null; + try { + const res = await fetch('api/sync.php?action=rules_content', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + credentials: 'same-origin' + }); + const json = await res.json(); + if (json.success && json.data) d = json.data; + } catch (e) { + el.innerHTML = `
协议加载失败:${e.message}
`; + return; + } + if (!d || d.skipped || !d.has_agreement) { + el.innerHTML = `
+

📜 用户协议

+

服务器当前未配置用户协议(rules 目录无协议文件)。

+
`; + return; + } + // 渲染:用 原文 + 简单 markdown 转 html(标题/列表/加粗),不引入外部依赖 + el.innerHTML = `
+
+

📜 ${esc(d.title || '服务器用户协议')}

+ +
+
+ ${renderMarkdownLite(d.content)} +
+

协议版本指纹:${esc(d.fingerprint || '')} | 共 ${d.line_count || 0} 行

+
`; + } + + // 轻量 markdown → HTML(仅处理标题/无序列表/加粗/表格分隔线/引用/代码/链接,足够展示协议) + function renderMarkdownLite(md) { + if (!md) return ''; + const lines = String(md).split('\n'); + let html = ''; + let inList = false; + const closeList = () => { if (inList) { html += ''; inList = false; } }; + for (let raw of lines) { + let s = raw; + // 表格分隔线丢弃 + if (s.trim().match(/^\|?[\s:|-]+\|?$/) && s.trim().length > 1 && s.includes('-')) { closeList(); continue; } + // 代码围栏 ``` 整行丢弃(json 动作配置已在后端剥离,双保险) + if (s.trim().startsWith('```')) { closeList(); continue; } + // 标题 + if (s.match(/^#{1,6}\s/)) { + closeList(); + const lvl = s.match(/^#+/)[0].length; + const txt = s.replace(/^#+\s*/, ''); + const sz = Math.max(15, 22 - lvl); + html += `
${esc(txt)}
`; + continue; + } + // 无序列表 + if (s.match(/^\s*[-*+]\s+/)) { + if (!inList) { html += '