创建新区时检查之前列表

This commit is contained in:
liangtongchuan
2020-12-23 18:05:51 +08:00
parent be8ae18d24
commit 5cbeaa83e9
2 changed files with 8 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ export const STATUS = {
ROLE_NOT_FOUND: { code: 10005, simStr: '未找到角色' },
DUP_LOGIN: { code: 10006, simStr: '重复登录' },
NEW_SERVER_ERR: { code: 10007, simStr: '添加新服务器失败' },
SERVER_EXISTS: { code: 10008, simStr: '服务器已存在' },
// 战斗相关状态 20000 - 29999
// 战斗通用 20000 - 20099
BATTLE_MISS_INFO: { code: 20001, simStr: '缺少关卡信息' },

View File

@@ -22,6 +22,13 @@ export default class GameController extends Controller {
public async newServer() {
const { ctx } = this;
const { serverId, serverType, name, host, port, status } = ctx.request.body;
const serverList = await GameModel.getAllServerList();
for (let { id, host: preHost, port: prePort } of serverList) {
if (preHost === host && prePort === port && id === serverId) {
ctx.body = ctx.service.utils.resResult(STATUS.SERVER_EXISTS);
return;
}
}
const gameInfo = await GameModel.newServer(serverId, serverType, name, host, port, status);
if (gameInfo) {
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { gameInfo });