game/DEPLOYMENT.md
2026-01-01 02:21:09 +08:00

141 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 扫雷游戏部署教程
## 项目结构
```
game/
├── app/ # React 前端(用户玩游戏)
├── server/ # Nakama 游戏服务器逻辑
├── docker-compose.yml
└── 游戏逻辑文档.txt
```
---
## 1. 部署 Nakama 游戏服务器
### 1.1 服务器准备
```bash
# 安装 Docker 和 Docker Compose
apt install docker.io docker-compose
```
### 1.2 启动服务
```bash
cd /path/to/game
# 构建并启动
docker-compose up -d --build
# [推荐] 方式2分别部署 (业务后端 + 游戏服)
# 1. 启动业务后端 (在 bindbox_game 目录)
# 2. 启动游戏服 (使用 docker-compose.cloud.yml, 需确保网络互通)
# docker-compose -f docker-compose.cloud.yml up -d
# [推荐] 方式3全量合并部署 (业务后端 + 游戏服 + 数据库)
# docker-compose -f docker-compose.all.yml up -d
# 云端部署 (由于是云端,通常使用拉取的镜像)
# docker-compose -f docker-compose.cloud.yml up -d
# 查看日志
docker-compose logs -f nakama
```
### 1.3 验证服务
- Nakama API: http://your-server:7350
- Nakama Console: http://your-server:7351
- CockroachDB UI: http://your-server:8081
---
## 2. 部署前端游戏
### 2.1 构建前端
```bash
cd /path/to/game/app
# 安装依赖
npm install
# 构建生产版本
npm run build
```
### 2.2 配置 Nginx
```nginx
server {
listen 80;
server_name game.1024tool.vip;
root /var/www/game;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
```
### 2.3 部署文件
```bash
# 将构建产物复制到服务器
scp -r dist/* root@server:/var/www/game/
# 重载 Nginx
nginx -s reload
```
---
## 3. 配置小程序对接
### 3.1 后端配置bindbox_game
`system_configs` 表添加:
```sql
INSERT INTO system_configs (key, value) VALUES
('nakama_server', 'wss://game.1024tool.vip:7350'),
('nakama_key', 'defaultkey');
```
### 3.2 前端跳转
小程序扫雷入口已配置跳转到:
```
https://game.1024tool.vip?ticket={ticket_token}
```
---
## 4. 完整流程
```
小程序点击「进入游戏」
调用 /api/app/games/enter
获取 ticket_token
跳转 webview: game.1024tool.vip?ticket=xxx
游戏前端连接 Nakama 服务器
开始对战
```
---
## 5. 常用命令
```bash
# 查看服务状态
docker-compose ps
# 重启服务
docker-compose restart nakama
# 查看实时日志
docker-compose logs -f
# 停止服务
docker-compose down
```