115 lines
2.7 KiB
Markdown
115 lines
2.7 KiB
Markdown
## 需求概述
|
||
|
||
- 项目的主要业务需求:
|
||
|
||
给定一个服务端模板,开启n个服务器,并在接口请求时返回可用服务器的地址。
|
||
管理在线服务器的数量。
|
||
|
||
- 项目的非功能需求:
|
||
|
||
分布式系统(会同时运行在多台机器上)
|
||
|
||
### 功能需求
|
||
|
||
- 根据给定的服务端模板,可用端口范围生成多个服务器实例。
|
||
- 回收已经标记为结束的服务器。
|
||
- 接口请求时,返回一个可用的服务器ip。
|
||
- 记录对局的id,开始时间,结束时间,参与玩家id到数据库中。
|
||
|
||
## 非功能需求
|
||
|
||
- 可以增加机器的数量。例如有A,B两台机器,A机器资源占满,B机器有余量。收到请求时,会在B机器开启新的服务器并返回ip
|
||
- 保持一定数量的可用服务器,在请求时可以立刻返回。
|
||
|
||
## 界面设计和交互
|
||
|
||
无ui需求,bat就行。
|
||
|
||
## 接口需求
|
||
|
||
### `func getServer()`
|
||
|
||
- 接口描述:提供模版类型,获取一个可用的服务器ip,并记录该对局的参与玩家。
|
||
|
||
- 返回值:
|
||
|
||
- String类型的ip地址(带端口)
|
||
|
||
- Int类型的对局id
|
||
|
||
- 参数列表:
|
||
- `List<Player> players`
|
||
- `String type`
|
||
|
||
### `func informEnd()`
|
||
|
||
- 接口描述:告知系统某个对局结束了
|
||
|
||
- 返回值:无
|
||
|
||
- 参数列表:
|
||
- `int id`
|
||
|
||
### `func getPlayerServer()`
|
||
|
||
- 接口描述:获取某个玩家还在进行中的对局的服务器的ip地址
|
||
|
||
- 返回值:
|
||
- String 类型的ip地址(带端口),未在对局中返回null
|
||
- Int 类型的对局id,未在对局中返回-1
|
||
|
||
- 参数列表:
|
||
- `Player player`
|
||
|
||
### `func containPlayer()`
|
||
|
||
- 接口描述:查询某个玩家是否在对局中。
|
||
- 返回值:
|
||
- bool
|
||
- 参数列表:
|
||
- `Player player`
|
||
|
||
## 数据库结构
|
||
|
||
- `match`
|
||
|
||
| id(int) | start(datetime) | end(datetime) | players(text) | type(varchar) |
|
||
|---------|-----------------|---------------|--------------------------------------|---------------|
|
||
| 1 | 1678554776 | 1678554784 | TONY_All,Sanseyooyea,PlayerA,PlayerB | bedwars |
|
||
|
||
## API 使用
|
||
|
||
依赖:
|
||
|
||
```kotlin
|
||
dependencies {
|
||
compileOnly("com.mohist.mistyrain:MultiServerMan-API:${version}")
|
||
}
|
||
```
|
||
|
||
使用:
|
||
|
||
```java
|
||
List<ProxyPlayer> players;
|
||
|
||
MultiServerManAPI api=MultiServerManAPIProvider.getAPI();
|
||
api.getServer("default",players);
|
||
```
|
||
|
||
## Q&A
|
||
|
||
1. Q: 不同类型的服务端是怎么区分的
|
||
|
||
A: 每个子端保留多种模版
|
||
|
||
2. Q: 数据库类型
|
||
|
||
A: MySQL / MariaDB
|
||
|
||
3. Q: getServer是需要负责把玩家传到子服还是只是提供服务器并记录玩家
|
||
|
||
A: 只提供服务器并记录玩家
|
||
|
||
4. Q: 服务端启动方式
|
||
|
||
A: 启动脚本,参数为端口+自定义参数 |