-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-hook.patch
More file actions
32 lines (29 loc) · 1.07 KB
/
Copy pathserver-hook.patch
File metadata and controls
32 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
在 phira-mp-plus-server/src/session_actor.rs 中修改 handle_chat:
1. 添加 import:
```rust
// 文件顶部已有 import,无需新增(serde_json 已在 workspace 中)
```
2. 在 `if !user.server.live_config.read().await.chat_enabled {` 检查之后,
`let res: Result<()> = async {` 之前插入:
```rust
// ── chat-auth 插件鉴权 ──
// 如 chat-auth 插件已安装,调用 is_authorized 检查用户
match user.server.plugin_manager
.call_plugin_api("chat-auth", "is_authorized", &[serde_json::json!(user.id)])
.await
{
Ok(val) => {
if !val.as_bool().unwrap_or(false) {
return Some(ServerCommand::Chat(Err(
"未授权:请先通过 HTTP POST /api/chat-auth 完成鉴权".to_string()
)));
}
}
Err(ref e) if e.contains("not found") => {
// 插件未安装 → 放行(向后兼容)
}
Err(e) => {
tracing::warn!(?e, "chat-auth plugin call failed, allowing chat");
}
}
```