系统:登录游戏前客户端版本号校验

This commit is contained in:
qiaoxin
2021-07-16 15:38:26 +08:00
parent 4df19fe90e
commit 4d1723b5c2
4 changed files with 28 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { STATUS } from '@consts';
import { CLIENT_VERSION, STATUS } from '@consts';
import { GameModel } from '@db/Game';
import { Controller } from 'egg';
import { RoleModel } from '@db/Role';
@@ -9,31 +9,42 @@ import { ServerlistModel } from '@db/Serverlist';
export default class GameController extends Controller {
public async checkVersion() {
const { ctx } = this;
const { version } = ctx.request.body;
if (version < CLIENT_VERSION) {//版本号太低
ctx.body = ctx.service.utils.resResult(STATUS.VERSION_ERR, { version: CLIENT_VERSION });
return;
}
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS);
return;
}
public async getServerList() {
const { ctx } = this;
let { serverType, auth, uid } = ctx;
let { serverType, auth, uid, clientVersion } = ctx;
console.log('clientVersion', clientVersion);
let serverList = new Array<GroupParam>();
let loginServerList = new Array<ServerParamWithRole>();
let allServers = await ServerlistModel.findByServerType(auth == 1? null: serverType);
let allServers = await ServerlistModel.findByServerType(auth == 1 ? null : serverType);
let roles = await RoleModel.findAllByUid(uid, true, true);
for(let server of allServers) {
for (let server of allServers) {
let curGroup = serverList.find(cur => cur.groupId == server.groupId);
if(!curGroup) {
if (!curGroup) {
curGroup = new GroupParam(server);
serverList.push(curGroup);
}
curGroup.pushServer(server);
let role = roles.find(role => role.serverId == server.id);
if(!!role) {
if (!!role) {
let curLoginInfo = new ServerParamWithRole(role, server);
loginServerList.push(curLoginInfo);
}
}
loginServerList.sort((a, b) => { return b.updatedAt.getTime() - a.updatedAt.getTime()});
loginServerList.sort((a, b) => { return b.updatedAt.getTime() - a.updatedAt.getTime() });
if (serverList && serverList.length > 0) {
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { serverList, loginServerList });
@@ -69,14 +80,14 @@ export default class GameController extends Controller {
let notice = await NoticeModel.getAllNotice(serverType);
let result = notice.map(cur => {
let {id, title, tag, type, content, time} = cur;
let { id, title, tag, type, content, time } = cur;
return {
id, title, tag, type, content, time
}
})
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { notice: result });
return
return
}
@@ -84,11 +95,11 @@ export default class GameController extends Controller {
const { ctx } = this;
try {
reloadResources();
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: true });
return;
} catch(e) {
} catch (e) {
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { isOK: false, err: e.stack });
return;
}