Skip to content

fix: 修复 revbotservice Web 路径加载失败并增强 bothost 远端 PHP 报错可见性#219

Merged
amarillonmc merged 2 commits intonouveaufrom
codex/create-bot-control-system-in-bothost-gsrgdp
Feb 8, 2026
Merged

fix: 修复 revbotservice Web 路径加载失败并增强 bothost 远端 PHP 报错可见性#219
amarillonmc merged 2 commits intonouveaufrom
codex/create-bot-control-system-in-bothost-gsrgdp

Conversation

@amarillonmc
Copy link
Owner

Motivation

  • 服务器端 error_log 指出 bot/revbotservice.php 在 Web 环境下以相对路径包含 ./include/common.inc.php 失败,导致 GAME_ROOT 未定义并触发后续 fatal 错误。
  • 为了让 bothost 能更快定位此类远端 PHP 报错,需要在不破坏原有逻辑的前提下修复服务端路径问题并将远端错误暴露到 bothost 的状态汇总中。

Description

  • 修复 bot/revbotservice.php 启动目录与包含路径问题:基于 dirname(__DIR__) 计算游戏根目录并 chdir($gameRoot),改用 require_once 绝对路径加载依赖。
  • revbotservice.php 启动时确保 bot/lock/ 目录存在并自动创建以避免 scandir/touch 失败,并修正 array_search($botid, ...)array_search($id, ...) 的变量误用。
  • 新增独立守护程序 bothost/main.py 的行为调整:在流式日志解析中识别 Fatal error / Warning: / Uncaught Error,将对应 worker 标记为 remote_php_error 并写入 last_error,同时保留并在周期汇总中打印 last_error
  • 新增/更新文档与样例配置:添加 bothost/README.mdbothost/TASKS.mdbothost/config.example.json,在 README 中补充了关于 include(...common.inc.php) 错误的诊断说明及代理/TLS 建议(如 disable_env_proxyinsecure_skip_tls_verify)。

Testing

  • 已对服务端脚本做语法检查:运行 php -l bot/revbotservice.php,结果为 No syntax errors detected(通过)。
  • 已对 Python 守护端做字节码编译检查:运行 python -m py_compile bothost/main.py(通过)。
  • 已验证守护端帮助输出:运行 python bothost/main.py -h 并确认输出用法说明(通过)。

Codex Task

@augmentcode
Copy link

augmentcode bot commented Feb 8, 2026

🤖 Augment PR Summary

Summary: 修复了 bot/revbotservice.php 在 Web 环境下相对路径 include 失败的问题,并新增独立的 bothost 守护端用于远程托管 revbot 长连接与暴露远端 PHP 报错。



Changes:

  • revbotservice 基于脚本目录计算根目录并 chdir,改为绝对路径 require_once 加载依赖。
  • 启动时确保 bot/lock/ 目录存在(自动创建),减少 Web 环境下的锁目录相关报错。
  • 修正 bot id 清理逻辑中的变量误用($botid$id)。
  • 新增 bothost/main.py:多目标/多 worker 连接 revbotservice,解析日志并将 Fatal/Warning/Uncaught 错误写入 last_error
  • 新增 bothost 文档与示例配置(README/TASKS/config.example.json)。
Technical Notes: bothost 周期输出每个 worker 的状态(连接态、重启次数、错误次数、最近错误),便于快速定位远端执行异常。

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

$flag = bot_acts($id);
if ($flag == 0) {
unset($gamevars['botid'][array_search($botid, $gamevars['botid'])]);
unset($gamevars['botid'][array_search($id, $gamevars['botid'])]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 array_search($id, $gamevars['botid']) 找不到时会返回 false,而 unset($arr[false]) 可能因类型转换误删索引 0 的元素。可以考虑在 unset 前对返回值做 !== false 的判断,避免误删其他 bot id。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@amarillonmc amarillonmc merged commit 66c4558 into nouveau Feb 8, 2026
Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

$id = 0;
$dir = GAME_ROOT.'./bot/lock/';
if(!is_dir($dir)) {
mkdir($dir, 0777, true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdir($dir, 0777, true) 的返回值未检查;如果权限不足或并发创建导致失败,后续 scandir() / touch() 仍会执行并产生告警或让锁目录不可用。可以考虑在创建失败时显式记录/退出,以避免“看似继续跑但其实不可用”。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

include GAME_ROOT . './include/game.func.php';
include GAME_ROOT . './bot/revbot.func.php';

$gameRoot = dirname(__DIR__).DIRECTORY_SEPARATOR;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(无法在本次 review 中锚定到新增文件行,先在此备注)bothost/main.py 里拼接查询参数使用 full_url += "?" + urlencode(...),当 revbotservice_url 本身已包含 ? 时会生成无效 URL(...?a=b?c=d),可能导致连接目标不符合配置预期。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

chdir($gameRoot);
}

require_once $gameRoot.'include/common.inc.php';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(无法在本次 review 中锚定到新增文件行,先在此备注)bothost/main.py 通过 response.fp.raw._sock 这种私有属性设置读超时;在部分 Python/urllib 响应实现下可能拿不到底层 socket,从而 read_timeout_sec 不生效并导致 readline() 长时间阻塞、影响重连/退出。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant