Skip to content

Commit

Permalink
更新API文档,修复一处报错
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperzlib committed Oct 24, 2024
1 parent 3cfb8ac commit d169630
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 48 deletions.
125 changes: 78 additions & 47 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 获取游戏信息

```sh
GET /api/game/{clientId}
GET /api/v2/game/{clientId}
```

### 请求参数
Expand All @@ -16,27 +16,31 @@ GET /api/game/{clientId}
{
"status": 1,
"code": "OK",
"strengthConfig": {
"strength": 5, // 基础强度
"randomStrength": 5 // 随机强度,(强度范围:[strength, strength+randomStrength])
},
"gameConfig": {
"strength": {
"strength": 1, // 基础强度
"randomStrength": 10, // 随机强度,最终强度 = 基础强度 + random(0, 随机强度)
"minInterval": 10, // 最小随机间隔
"maxInterval": 15, // 最大随机间隔
"bChannelMultiplier": 1.0, // B通道强度倍数,如果存在此参数,则会启动B通道
},
"pulseId": "pulse-1" // 脉冲ID
"strengthChangeInterval": [15, 30], // 随机强度变化间隔,单位:秒
"enableBChannel": false, // 是否启用B通道
"bChannelStrengthMultiplier": 1, // B通道强度倍数
"pulseId": "d6f83af0", // 当前波形列表,可能是string或者string[]
"pulseMode": "single", // 波形播放模式,single: 单个波形, sequence: 列表顺序播放, random: 随机播放
"pulseChangeInterval": 60
},
"clientStrength": {
"strength": 0, // 当前强度
"limit": 20 // 强度上限
}
"strength": 0, // 客户端当前强度
"limit": 20 // 客户端强度上限
},
"currentPulseId": "d6f83af0" // 当前正在播放的波形ID
}
```

## 获取脉冲列表
## 获取波形列表

```sh
GET /api/game/{clientId}/pulse_list
GET /api/v2/pulse_list # 获取服务器配置的波形列表
GET /api/v2/game/{clientId}/pulse_list # 获取完整的波形列表(包括客户端自定义波形)
```

### 请求参数
Expand All @@ -51,21 +55,18 @@ GET /api/game/{clientId}/pulse_list
"code": "OK",
"pulseList": [
{
"id": "pulse-1",
"name": "脉冲1"
"id": "d6f83af0", // 波形ID
"name": "呼吸" // 波形名称
},
{
"id": "pulse-2",
"name": "脉冲2"
}
// ...
]
}
```

## 获取游戏强度配置
## 获取游戏强度信息

```sh
GET /api/game/{clientId}/strength_config
GET /api/v2/game/{clientId}/strength
```

### 请求参数
Expand All @@ -78,19 +79,17 @@ GET /api/game/{clientId}/strength_config
{
"status": 1,
"code": "OK",
"strengthConfig": { // 强度配置,同上
"strength": 5,
"randomStrength": 10,
"minInterval": 10,
"maxInterval": 15
"strengthConfig": {
"strength": 5, // 基础强度
"randomStrength": 5 // 随机强度,(强度范围:[strength, strength+randomStrength])
}
}
```

## 设置游戏强度配置

```sh
POST /api/game/{clientId}/strength_config
POST /api/v2/game/{clientId}/strength
```

### 请求参数
Expand All @@ -111,13 +110,7 @@ type SetStrengthConfigRequest = {
add?: number; // 增加随机强度
sub?: number; // 减少强度
set?: number; // 设置强度
},
minInterval?: {
set?: number; // 设置最低随机间隔
},
maxInterval?: {
set?: number; // 设置最高随机间隔
},
}
}
```
Expand Down Expand Up @@ -152,10 +145,10 @@ strength.add=1
}
```
## 获取游戏当前脉冲ID
## 获取游戏当前波形ID
```sh
GET /api/game/{clientId}/pulse_id
GET /api/v2/game/{clientId}/pulse
```
### 请求参数
Expand All @@ -168,14 +161,29 @@ GET /api/game/{clientId}/pulse_id
{
"status": 1,
"code": "OK",
"pulseId": "pulse-1"
"pulseId": "d6f83af0"
}
```
## 设置游戏当前脉冲ID
```json5
{
"status": 1,
"code": "OK",
"pulseId": [
"d6f83af0",
"7eae1e5f",
"eea0e4ce",
"2cbd592e"
]
}
```
## 设置游戏当前波形ID
```sh
POST /api/game/{clientId}/pulse_id
POST /api/v2/game/{clientId}/pulse
```
### 请求参数
Expand All @@ -186,14 +194,33 @@ POST /api/game/{clientId}/pulse_id
```json5
{
"pulseId": "pulse-1" // 脉冲ID
"pulseId": "d6f83af0" // 波形ID
}
```
```json5
{
"pulseId": [
"d6f83af0",
"7eae1e5f",
"eea0e4ce",
"2cbd592e"
] // 波形ID列表
}
```
使用x-www-form-urlencoded格式发送请求的Post Body:
```html
pulseId=pulse-1
pulseId=d6f83af0
```
```html
pulseId[]=d6f83af0&pulseId[]=7eae1e5f&pulseId[]=eea0e4ce&pulseId[]=2cbd592e
```
### 响应
Expand All @@ -202,8 +229,10 @@ pulseId=pulse-1
{
"status": 1,
"code": "OK",
"message": "成功设置了 1 个游戏的脉冲ID",
"successNum": 1
"message": "成功设置了 1 个游戏的波形ID",
"successClientIds": [
"3ab0773d-69d0-41af-b74b-9c6ce6507f65"
]
}
```
Expand All @@ -221,7 +250,7 @@ pulseId=pulse-1
## 一键开火
```sh
POST /api/game/{clientId}/fire
POST /api/v2/game/{clientId}/action/fire
```
### 请求参数
Expand All @@ -233,8 +262,10 @@ POST /api/game/{clientId}/fire
```json5
{
"strength": 20, // 一键开火强度,最高30
"time": 5000 // 一键开火时间,单位:毫秒,默认为5000,最高30000(30秒)
"strength": 20, // 一键开火强度,最高40
"time": 5000, // (可选)一键开火时间,单位:毫秒,默认为5000,最高30000(30秒)
"override": false, // (可选)多次一键开火时,是否重置时间,true为重置时间,false为叠加时间,默认为false
"pulseId": "d6f83af0" // (可选)一键开火的波形ID
}
```
Expand Down
2 changes: 2 additions & 0 deletions server/src/controllers/game/CoyoteGameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export class CoyoteGameController {
this.events.emit('gameStopped');

await this.setClientStrength(0);
// 必须清空临时强度
this._tempStrength = 0;

// 通知客户端当前强度
this.events.emit('strengthChanged', {
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/game/actions/GameFireAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type GameFireActionConfig = {
updateMode: "replace" | "append";
};

export const FIRE_MAX_STRENGTH = 30;
export const FIRE_MAX_STRENGTH = 40;
export const FIRE_MAX_DURATION = 30000;

export class GameFireAction extends AbstractGameAction<GameFireActionConfig> {
Expand Down
1 change: 1 addition & 0 deletions server/src/controllers/http/GameApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export class GameApiController {
strengthConfig: game.strengthConfig,
gameConfig,
clientStrength: game.clientStrength,
currentPulseId: game.pulsePlayList.getCurrentPulseId(),
});
} else {
apiResponse(ctx, {
Expand Down
2 changes: 2 additions & 0 deletions server/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export const setupRouter = (router: KoaRouter, wsRouter: WebSocketRouter) => {
router.post('/api/game/:id/fire', GameApiController.startActionFire);

// v2
router.get('/api/v2/pulse_list', GameApiController.getPulseList);
router.get('/api/v2/game/:id', GameApiController.gameInfo);
router.get('/api/v2/game/:id/strength', GameApiController.getGameStrength);
router.post('/api/v2/game/:id/strength', GameApiController.setGameStrength);
router.get('/api/v2/game/:id/pulse', GameApiController.getPulseId);
router.post('/api/v2/game/:id/pulse', GameApiController.setPulseId);
router.get('/api/v2/game/:id/pulse_list', GameApiController.getPulseList);

router.post('/api/v2/game/:id/action/fire', GameApiController.startActionFire);

Expand Down

0 comments on commit d169630

Please sign in to comment.