1- # OpenClaw 使用说明文档
1+ # OpenClaw AI 接入文档
22
3- 本文档详细介绍了如何让 OpenClaw AI 自主进入游戏房间, 并通过 TCP API 配置游戏参数 (阵营、队伍、位置等 )。
3+ 本文档面向 AI Agent、自动化脚本和服务进程,介绍如何以无头方式启动 OpenClaw, 并通过 TCP API 控制房间参数 (阵营、队伍、位置、开局等 )。
44
5- ## 1. 启动与进房 (Join Game)
5+ ## 1. 使用原则
66
7- OpenClaw 可以通过命令行参数直接启动 OpenRA 客户端并连接到指定服务器 。
7+ 本项目默认面向自动化环境,而不是面向真人交互界面 。
88
9- ### 启动命令格式
9+ - 推荐始终使用 ` Game.Platform=Headless ` 运行。
10+ - 推荐通过脚本或进程管理器拉起客户端。
11+ - 推荐在进入房间后通过 TCP API 完成配置,而不是依赖人工点击。
12+ - Windows 下优先使用仓库自带的 ` launch-game.cmd ` 作为启动入口。
1013
11- ``` cmd
12- # Windows (常规带UI模式)
13- OpenRA.Game.exe Game.Mod=copilot Launch.Connect=115.191.61.19:27940
14- ```
14+ ---
1515
16- * ` Game.Mod=copilot ` : 指定使用 Copilot 模组。
17- * ` Launch.Connect=115.191.61.19:27940 ` : 连接到指定的比赛服务器。
16+ ## 2. 获取与编译
1817
19- ### 示例
18+ OpenClaw 需要完整的 OpenRA 游戏文件才能运行。在 Windows 上可以使用 ` .NET SDK ` 或 ` Visual Studio ` 编译。
2019
21- ``` python
22- import subprocess
20+ ### 2.1 获取源码
2321
24- def join_server ():
25- cmd = [
26- " OpenRA.Game.exe" ,
27- " Game.Mod=copilot" ,
28- " Launch.Connect=115.191.61.19:27940"
29- ]
30- subprocess.Popen(cmd)
22+ ``` cmd
23+ git clone -b dev_win https://github.com/jmctsh/OpenCodeAlert.git
24+ cd OpenCodeAlert
3125```
3226
33- ---
34-
35- ## 2. Windows 服务器部署指南 (Headless Mode)
27+ ### 2.2 构建运行文件
3628
37- 在 Windows Server 等纯命令行或服务环境(Headless Server)中运行 OpenClaw 时,由于没有物理显示器,默认的图形渲染引擎可能会初始化失败或产生不必要的性能开销。
29+ ``` cmd
30+ make.cmd all
31+ ```
3832
39- 为了解决这个问题,本引擎专门开发了 ** Headless 无头渲染平台 ** 。你只需要在启动参数中指定 ` Game.Platform= Headless` 即可 。
33+ 该命令会下载依赖、准备资源,并生成运行 OpenClaw 所需的二进制文件与 Headless 平台支持文件 。
4034
41- ### 2.1 获取游戏本体与编译
35+ 如果你更习惯 IDE,也可以直接打开 ` OpenRA.sln ` ,使用 ` Release ` 配置生成解决方案。
4236
43- OpenClaw 需要完整的 OpenRA 游戏文件才能运行。在 Windows 上你需要使用 Visual Studio 或 .NET SDK 进行编译:
37+ ---
4438
45- ** 源码编译步骤 ** :
39+ ## 3. 无头启动与进房
4640
47- 1 . ** 安装构建依赖** (Windows)
48- * 下载并安装 ** .NET 6.0 SDK** (https://dotnet.microsoft.com/download/dotnet/6.0 )
49- * 安装 Git (用于拉取代码)
41+ ### 3.1 推荐启动命令
5042
51- 2 . ** 拉取代码**
52- ``` cmd
53- git clone -b dev_win https://github.com/jmctsh/OpenCodeAlert.git
54- cd OpenCodeAlert
55- ```
43+ 在仓库根目录的 ` PowerShell ` 中执行:
5644
57- 3. **编译与资源下载**
58- 你可以使用自带的 `make.cmd` 脚本进行编译:
59- ```cmd
60- # 在命令行中运行:
61- make.cmd all
62-
63- # 该脚本会自动下载必要的依赖库和资源文件,并编译生成所有可执行文件与 Headless 平台 DLL。
64- ```
65- *或者,你也可以直接用 Visual Studio 打开 `OpenRA.sln`,选择 Release 模式生成解决方案。*
45+ ``` powershell
46+ .\launch-game.cmd Game.Mod=copilot Game.Platform=Headless Launch.Connect=115.191.61.19:27940
47+ ```
6648
67- ### 2.2 启动无头模式 (Headless Launch)
49+ 参数说明:
6850
69- 使用 `Game.Platform=Headless` 参数启动游戏客户端,这样它就不会创建任何游戏窗口和声音设备,完美适配 Windows Server 和 Docker 容器环境。
51+ - ` Game.Mod=copilot ` : 使用 Copilot 模组。
52+ - ` Game.Platform=Headless ` : 启用无头渲染平台,不创建图形窗口和音频设备。
53+ - ` Launch.Connect=115.191.61.19:27940 ` : 启动后自动连接指定服务器。
7054
71- ```cmd
72- # 在 Windows Server 上无头运行
73- OpenRA.Game.exe Game.Mod=copilot Game.Platform=Headless Launch.Connect=115.191.61.19:27940
74- ```
55+ 说明:
7556
76- ### 2.3 Python 集成示例
57+ - ` launch-game.cmd ` 是当前仓库在 Windows 下的推荐入口。
58+ - 如果尚未完成构建,上述命令不会成功,因为运行文件尚未生成。
59+ - 在 ` PowerShell ` 中必须显式写成 ` .\launch-game.cmd ` ,不能直接写 ` launch-game.cmd ` 。
7760
78- 你的 Python 脚本也应该加上 ` Game.Platform=Headless ` 来启动游戏进程:
61+ ### 3.2 Python 启动示例
7962
8063``` python
8164import subprocess
82- import os
65+ from pathlib import Path
66+
67+
68+ def join_server_headless (repo_dir : str ):
69+ repo = Path(repo_dir)
70+ launcher = repo / " launch-game.cmd"
8371
84- def join_server_headless ():
85- game_executable = " OpenRA.Game.exe"
86-
87- # 构建启动命令,添加 Game.Platform=Headless
8872 cmd = [
89- game_executable,
90- " Game.Mod=copilot" ,
73+ str (launcher),
74+ " Game.Mod=copilot" ,
9175 " Game.Platform=Headless" ,
92- " Launch.Connect=115.191.61.19:27940"
76+ " Launch.Connect=115.191.61.19:27940" ,
9377 ]
94-
95- # 启动进程
96- print ( f " Starting OpenRA headless: { ' ' .join (cmd) } " )
97- subprocess.Popen(cmd)
78+
79+ print ( f " Starting OpenClaw headless: { ' ' .join(cmd) } " )
80+ subprocess.Popen (cmd, cwd = repo )
81+
9882
9983if __name__ == " __main__" :
100- join_server_headless()
84+ join_server_headless(r " D: \O penCodeAlert " )
10185```
10286
87+ ### 3.3 运行建议
88+
89+ - 在服务器、容器或 CI 环境中,始终使用无头模式。
90+ - 建议由外部守护进程统一管理启动、重启和日志采集。
91+ - 如果需要多实例运行,应为每个实例分配独立的工作目录、日志目录和端口策略。
92+
10393---
10494
105- ## 3 . 房间控制 API (Lobby API)
95+ ## 4 . 房间控制 API (Lobby API)
10696
10797当 OpenClaw 进入房间(Lobby)后,客户端会开启一个 TCP 监听端口(默认 ** 7446** ),允许外部程序通过 JSON 指令控制房间设置。
10898
10999* ** 端口** : 7446
110100* ** 协议** : TCP / JSON
111101* ** 编码** : UTF-8
112102
113- ### 3 .1 请求格式 (Request)
103+ ### 4 .1 请求格式 (Request)
114104
115105``` json
116106{
@@ -123,7 +113,7 @@ if __name__ == "__main__":
123113}
124114```
125115
126- ### 3 .2 响应格式 (Response)
116+ ### 4 .2 响应格式 (Response)
127117
128118``` json
129119{
@@ -140,9 +130,9 @@ if __name__ == "__main__":
140130
141131---
142132
143- ## 4 . 可用指令列表
133+ ## 5 . 可用指令列表
144134
145- ### 4 .1 基础控制
135+ ### 5 .1 基础控制
146136
147137| 命令 | 参数 | 说明 |
148138| :--- | :--- | :--- |
@@ -152,7 +142,7 @@ if __name__ == "__main__":
152142| ` set_spectator ` | ` {} ` | 切换为观察者 |
153143| ` set_ready ` | ` {"ready": true} ` | 设置准备状态 (true/false) |
154144
155- ### 4 .2 房主专用 (Host Only)
145+ ### 5 .2 房主专用 (Host Only)
156146
157147| 命令 | 参数 | 说明 |
158148| :--- | :--- | :--- |
@@ -163,15 +153,15 @@ if __name__ == "__main__":
163153| ` kick ` | ` {"clientIndex": 1} ` | 踢出玩家 |
164154| ` start_game ` | ` {} ` | 开始游戏 |
165155
166- ### 4 .3 查询
156+ ### 5 .3 查询
167157
168158| 命令 | 参数 | 说明 |
169159| :--- | :--- | :--- |
170160| ` get_lobby_info ` | ` {} ` | 获取当前房间详细信息(玩家、槽位、地图等) |
171161
172162---
173163
174- ## 5 . Python 调用示例
164+ ## 6 . Python 调用示例
175165
176166``` python
177167import socket
0 commit comments