✨ feat(选服): 服务器即将开启状态不可进入
This commit is contained in:
@@ -13,7 +13,7 @@ import { sendMessageToUser } from "../../../services/pushService";
|
||||
import { isCheckWord, isSkipEncode } from "../../../pubUtils/sdkUtil";
|
||||
import { isDevelopEnv } from "../../../services/utilService";
|
||||
import { isNumber } from "underscore";
|
||||
import { redisClient } from "../../../services/redisService";
|
||||
import { getServerCreateTime, redisClient } from "../../../services/redisService";
|
||||
import { checkRouteParam } from "../../../services/checkParam";
|
||||
import { isApiClose } from "../../../services/chatService";
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import { getExpByLv } from '../../../pubUtils/data';
|
||||
import { reportCreateRoleEventToTa, reportTAEvent, reportTAUserSet } from '../../../services/sdkService';
|
||||
import { saveLoginAndOutLog } from '../../../pubUtils/logUtil';
|
||||
import { sendMessageToAllWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
|
||||
import { getIpLocation } from '../../../services/roleService';
|
||||
import { checkServerIsOpen, getIpLocation } from '../../../services/roleService';
|
||||
import { dispatch } from '../../../pubUtils/dispatcher';
|
||||
import { leaveRaceActivityToRemote } from '../../../services/guildActivity/guildActivityService';
|
||||
|
||||
@@ -62,12 +62,17 @@ export class EntryHandler {
|
||||
}
|
||||
|
||||
let ip = this.getIp(session);
|
||||
if(!await checkServerIsOpen(serverId, ip, user.uid)) {
|
||||
return resResult(STATUS.SERVER_IS_NOT_OPEN)
|
||||
}
|
||||
|
||||
|
||||
let ipLocation = await getIpLocation(ip);
|
||||
let role = await RoleModel.findByUidAndSetTime(user.uid, serverId, ip, ipLocation, null, true);
|
||||
if (!role) {
|
||||
return resResult(STATUS.ROLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
let serverName = this.app.getServerId();
|
||||
await roleLogin(role.roleId, user.userCode, serverName, role.createTime, role.serverId, role.lv, role.topLineupCe); // 保存在线用户
|
||||
await this.addSession(user, role, session);
|
||||
|
||||
@@ -14,6 +14,9 @@ import { pick } from 'underscore';
|
||||
import { Reward } from '../domain/battleField/pvp';
|
||||
import { CheckMeterial } from './role/checkMaterial';
|
||||
import IP2Region from "ip2region";
|
||||
import { getServerCreateTime } from './redisService';
|
||||
import { checkWhiteList } from '../pubUtils/sysUtil';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
const query = new IP2Region({ disableIpv6: true });
|
||||
|
||||
|
||||
@@ -301,4 +304,13 @@ export async function getIpLocation(ip: string) {
|
||||
} catch(e) {
|
||||
console.error('setIpLocation', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 服务器是否开启
|
||||
export async function checkServerIsOpen(serverId: number, ip: string, uid: number) {
|
||||
let isWhiteList = await checkWhiteList(pinus.app.get('env'), ip, uid, serverId);
|
||||
if(isWhiteList) return true;
|
||||
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
return serverTime <= nowSeconds();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export const STATUS = {
|
||||
LOGIN_ERR: { code: 5, simStr: '检测到您的账号异地登录,已被迫下线' },
|
||||
REDLOCK_ERR: { code: 6, simStr: '请勿频繁操作' },
|
||||
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
|
||||
SERVER_IS_NOT_OPEN: { code: 7, simStr: '即将开启,敬请期待' },
|
||||
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
|
||||
BLOCK_WORDS: { code: 9, simStr: '内容含有敏感字符' },
|
||||
BLOCKED: { code: 10, simStr: '您已被封禁' },
|
||||
|
||||
@@ -16,6 +16,14 @@ module.exports = () => {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SERVER_MAINTENANCE);
|
||||
return;
|
||||
}
|
||||
} else if(server && server.openTime > nowSeconds()) {
|
||||
let isWhiteList = await checkWhiteList(ctx.app.config.realEnv, ctx.clientIp, ctx.uid, serverId);
|
||||
if (isWhiteList) {
|
||||
return await next();
|
||||
} else {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SERVER_IS_NOT_OPEN);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
return await next();
|
||||
|
||||
Reference in New Issue
Block a user