# ra2-lan-platform **Repository Path**: wangcc1987/ra2-lan-platform ## Basic Information - **Project Name**: ra2-lan-platform - **Description**: No description available - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-16 - **Last Updated**: 2026-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 红警2 局域网对战平台 > 类浩方/11平台的局域网版, 支持红警2 原版联机对战 + 同队伍语音 + 观战/录像 + 战绩排行. > **纯局域网, 零服务端依赖**. ## 功能特性 - 🎮 **联机对战**: IPX 隧道自动转发, 支持红警2/尤里复仇/共和国之辉 - 🔍 **自动发现**: UDP 组播, 同网段玩家自动可见 - 🎤 **同队伍语音**: Opus 编解码, 红队/蓝队独立语音频道, Space PTT - 👀 **实时观战**: 旁观者加入房间但不参与游戏 - 📹 **录像系统**: 主机自动录像, 支持录像 P2P 下载与回放 - 📊 **战绩排行**: 本地 SQLite 存储, Elo 积分系统 - 🪟 **现代 UI**: Flet (Flutter 引擎) 渲染, 暗色主题 ## 系统要求 - **操作系统**: Windows 10/11 (x64) - **Python**: 3.10+ - **依赖**: 红警2 原版或兼容版本 (含尤里复仇/共和国之辉) - **网络**: 同一局域网 (有组播权限) ## 快速开始 ### 一键启动 (推荐) ```bash # Linux/macOS ./scripts/run.sh # Windows scripts\run.bat # 或直接 Python python scripts/run.py ``` 这个脚本会自动: 1. 检查 Python 版本 2. 安装依赖 (flet, opuslib, sounddevice, ...) 3. 下载 IPXWrapper.dll 到 `third_party/` 4. 创建默认配置 5. 启动应用 ### 手动启动 ```bash # 1. 装依赖 pip install -r requirements.txt # 2. 下载 IPXWrapper.dll python scripts/download_ipxwrapper.py # 或手动下载: https://github.com/solemnwarning/ipxwrapper/releases # 解压后将 ipxwrapper.dll 放到 third_party/ # 3. 运行 python main.py ``` ### 玩家 1. 启动客户端 2. 在设置中指定红警2 安装目录 3. 点击 "创建房间" 或加入现有房间 4. 选择队伍 (红/蓝) 或旁观 5. host 点击 "开始游戏" → "启动红警2" 6. 按 `Space` 开启语音 ## 项目结构 ``` ra2-lan-platform/ ├── main.py # 入口 ├── requirements.txt # Python 依赖 ├── build.spec # PyInstaller 打包配置 ├── config.example.json # 配置示例 ├── src/ │ ├── app.py # Application 主类 │ ├── config.py # Config 加载/保存 │ ├── network/ │ │ ├── multicast.py # 组播套接字 │ │ ├── discovery.py # 房间/玩家发现 │ │ ├── replay_server.py # 录像分发 TCP 服务 │ │ └── replay_client.py # 录像下载 TCP 客户端 │ ├── room/ │ │ ├── models.py # Room, Player 数据模型 │ │ └── manager.py # RoomManager │ ├── voice/ │ │ └── manager.py # VoiceManager (Opus + 组播) │ ├── stats/ │ │ ├── database.py # SQLite 封装 │ │ ├── elo.py # Elo 计算 │ │ └── manager.py # StatsManager │ ├── game/ │ │ ├── injector.py # IPXWrapper 注入 │ │ └── launcher.py # 启动游戏 │ └── ui/ │ └── main_window.py # Flet 主窗口 ├── third_party/ # IPXWrapper.dll 放在这 ├── scripts/ │ ├── run.py # 一键启动 │ ├── run.sh / run.bat # 系统脚本 │ └── download_ipxwrapper.py # IPXWrapper 下载 ├── tests/ # 37 个测试 │ ├── test_database.py # 7 个 │ ├── test_discovery.py # 9 个 │ ├── test_elo.py # 6 个 │ ├── test_replay.py # 3 个 │ └── test_room.py # 12 个 └── docs/ ├── 01-architecture.md # 系统架构 ├── 02-protocol.md # 协议详细规范 └── 04-development-plan.md # 开发路线图 ``` ## 文档 - [01-architecture.md](docs/01-architecture.md) — 系统架构 - [02-protocol.md](docs/02-protocol.md) — 协议详细规范 - [04-development-plan.md](docs/04-development-plan.md) — 开发路线图 ## 开发环境 (macOS) ```bash # Python 3.10+ 必须 (3.9 上 flet Tabs 会崩溃) uv venv --python 3.13 .venv uv pip install -r requirements.txt --python .venv/bin/python .venv/bin/python -m pytest tests/ -v # 跑测试 .venv/bin/python main.py # 启动 ``` 语音提示: macOS 上 keyboard 全局热键需要 root, 请使用房间页的"说话"按钮 或窗口内空格键; 首次开麦需授权麦克风。 ## 技术栈 - **语言**: Python 3.10+ - **GUI**: Flet (基于 Flutter) - **IPX 隧道**: [IPXWrapper](https://github.com/solemnwarning/ipxwrapper) (0.7.2) - **音频**: opuslib + sounddevice + numpy - **PTT**: keyboard (全局热键) - **数据库**: SQLite (Python 内置) - **打包**: PyInstaller ## 协议端口 | 端口 | 用途 | |------|------| | 8472 | IPX 隧道 (替代默认 213) | | 9999 | 房间发现/心跳 | | 10000 | 语音 (3 个队伍地址) | | 11000 | 录像传输 (TCP) | ## 测试 ```bash python -m pytest tests/ -v ``` 40 个测试覆盖: - 数据库 CRUD、Elo 计算 - 房间发现协议 (心跳、去重、版本) - 录像上传/下载 roundtrip - 房间生命周期 (创建/开始/结束/战绩联动) - 房间加入/离开/关闭协议 (单播 room_join/room_leave、广播 room_close、房主掉线清理) ## 打包 (Windows) > PyInstaller 不能跨平台编译, exe 必须在 Windows 机器上构建。 ```bat git clone https://gitee.com/wangcc1987/ra2-lan-platform.git cd ra2-lan-platform py -3.12 -m venv .venv .venv\Scripts\pip install -r requirements.txt .venv\Scripts\pyinstaller build.spec ``` 产物: `dist\ra2-lan-platform\ra2-lan-platform.exe` (目录版, 整个文件夹分发)。 可选增强: - 语音: `third_party/opus.dll` (libopus 1.6.1 x64) 已随仓库提供, 打包时自动带入; 缺失时语音自动禁用, 其他功能不受影响 - 联机: 从 [IPXWrapper releases](https://github.com/solemnwarning/ipxwrapper/releases) 下载 `ipxwrapper.dll` 放到 `third_party/` (也可在应用内用下载脚本) - 首次运行弹防火墙提示时允许访问 (UDP 8472/9999/10000, TCP 11000) ## 许可证 GPLv3 (因使用 IPXWrapper, GPLv3). ## 致谢 - [IPXWrapper](https://github.com/solemnwarning/ipxwrapper) — IPX 隧道实现 - [Opus Codec](https://opus-codec.org/) — 音频编解码 - [Flet](https://flet.dev/) — Python GUI 框架 - [PyInstaller](https://www.pyinstaller.org/) — Python 打包工具