@@ -35,15 +35,106 @@ def join_server():
3535
3636---
3737
38- ## 2. 房间控制 API (Lobby API)
38+ ## 2. Linux 服务器部署指南 (Headless Mode)
39+
40+ 在 Linux 服务器上运行游戏客户端通常需要图形界面支持。为了在纯命令行环境(Headless Server)中运行 OpenClaw,你需要使用 ` Xvfb ` 来模拟显示环境。
41+
42+ ### 2.1 依赖安装
43+
44+ 在 Debian/Ubuntu 系统上,你需要安装 Mono 运行时和 Xvfb:
45+
46+ ``` bash
47+ # 安装 Mono (OpenRA 运行环境)
48+ sudo apt update
49+ sudo apt install mono-complete
50+
51+ # 安装 Xvfb (虚拟显示服务)
52+ sudo apt install xvfb
53+ ```
54+
55+ ### 2.2 获取游戏本体
56+
57+ OpenClaw 需要完整的 OpenRA 游戏文件才能运行。
58+
59+ ** 源码编译步骤** :
60+
61+ 1 . ** 安装构建依赖** (Ubuntu/Debian)
62+ ``` bash
63+ # 安装 git, make, unzip
64+ sudo apt install git make unzip
65+
66+ # 安装 .NET SDK (用于编译)
67+ # 参考: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu
68+ sudo apt-get update && \
69+ sudo apt-get install -y dotnet-sdk-6.0
70+ ```
71+
72+ 2. ** 拉取代码**
73+ ` ` ` bash
74+ git clone -b dev https://github.com/jmctsh/OpenCodeAlert.git
75+ cd OpenCodeAlert
76+ ` ` `
77+
78+ 3. ** 编译与资源下载**
79+ ` ` ` bash
80+ # 下载依赖库并编译
81+ make all
82+
83+ # 这一步会自动下载必要的资源文件
84+ ` ` `
85+
86+
87+ # ## 2.3 启动脚本 (Headless Launch)
88+
89+ 使用 ` xvfb-run` 命令来启动游戏客户端,这样它就不会因为找不到显示器而报错。
90+
91+ ` ` ` bash
92+ # 在 Linux 服务器上运行
93+ xvfb-run -a ./launch-game.sh Game.Mod=copilot Launch.Connect=115.191.61.19:27940
94+ ` ` `
95+
96+ * ` -a` : 自动寻找可用的显示编号。
97+ * ` ./launch-game.sh` : 确保该脚本有执行权限 (` chmod +x launch-game.sh` )。
98+
99+ # ## 2.4 Python 集成示例
100+
101+ 你的 Python 脚本也应该通过 ` xvfb-run` 来启动游戏进程:
102+
103+ ` ` ` python
104+ import subprocess
105+ import os
106+
107+ def join_server_headless ():
108+ # 确保使用 Linux 启动脚本
109+ game_executable = " ./launch-game.sh"
110+
111+ # 构建启动命令,前缀加上 xvfb-run
112+ cmd = [
113+ " xvfb-run" , " -a" ,
114+ game_executable,
115+ " Game.Mod=copilot" ,
116+ " Launch.Connect=115.191.61.19:27940"
117+ ]
118+
119+ # 启动进程
120+ print(f" Starting OpenRA headless: {' '.join(cmd)}" )
121+ subprocess.Popen(cmd)
122+
123+ if __name__ == " __main__" :
124+ join_server_headless ()
125+ ` ` `
126+
127+ ---
128+
129+ # # 3. 房间控制 API (Lobby API)
39130
40131当 OpenClaw 进入房间(Lobby)后,客户端会开启一个 TCP 监听端口(默认 ** 7446** ),允许外部程序通过 JSON 指令控制房间设置。
41132
42133* ** 端口** : 7446
43134* ** 协议** : TCP / JSON
44135* ** 编码** : UTF-8
45136
46- ### 2 .1 请求格式 (Request)
137+ # ## 3 .1 请求格式 (Request)
47138
48139` ` ` json
49140{
@@ -56,7 +147,7 @@ def join_server():
56147}
57148` ` `
58149
59- ### 2 .2 响应格式 (Response)
150+ # ## 3 .2 响应格式 (Response)
60151
61152` ` ` json
62153{
@@ -73,9 +164,9 @@ def join_server():
73164
74165---
75166
76- ## 3 . 可用指令列表
167+ # # 4 . 可用指令列表
77168
78- ### 3 .1 基础控制
169+ # ## 4 .1 基础控制
79170
80171| 命令 | 参数 | 说明 |
81172| :--- | :--- | :--- |
@@ -85,7 +176,7 @@ def join_server():
85176| ` set_spectator` | ` {}` | 切换为观察者 |
86177| ` set_ready` | ` {" ready" : true}` | 设置准备状态 (true/false) |
87178
88- ### 3 .2 房主专用 (Host Only)
179+ # ## 4 .2 房主专用 (Host Only)
89180
90181| 命令 | 参数 | 说明 |
91182| :--- | :--- | :--- |
@@ -96,15 +187,15 @@ def join_server():
96187| ` kick` | ` {" clientIndex" : 1}` | 踢出玩家 |
97188| ` start_game` | ` {}` | 开始游戏 |
98189
99- ### 3 .3 查询
190+ # ## 4 .3 查询
100191
101192| 命令 | 参数 | 说明 |
102193| :--- | :--- | :--- |
103194| ` get_lobby_info` | ` {}` | 获取当前房间详细信息(玩家、槽位、地图等) |
104195
105196---
106197
107- ## 4 . Python 调用示例
198+ # # 5 . Python 调用示例
108199
109200` ` ` python
110201import socket
0 commit comments