diff --git a/gm-server/app/controller/game.ts b/gm-server/app/controller/game.ts index c0256a531..07080532f 100644 --- a/gm-server/app/controller/game.ts +++ b/gm-server/app/controller/game.ts @@ -31,6 +31,30 @@ export default class GameController extends Controller { return } + public async getWhiteList() { + const { ctx } = this; + const { id } = ctx.request.body; + + ctx.body = await ctx.service.game.getWhiteList(id); + return + } + + public async updateWhiteList() { + const { ctx } = this; + const { id, code, type, content } = ctx.request.body; + + ctx.body = await ctx.service.game.updateWhiteList(id, code, type, content); + return + } + + public async deleteWhiteList() { + const { ctx } = this; + const { id, code } = ctx.request.body; + + ctx.body = await ctx.service.game.deleteWhiteList(id, code); + return + } + public async getServers() { const { ctx } = this; diff --git a/gm-server/app/router.ts b/gm-server/app/router.ts index b7d528755..8b29f8cc6 100644 --- a/gm-server/app/router.ts +++ b/gm-server/app/router.ts @@ -55,6 +55,9 @@ export default (app: Application) => { router.post('/api/game/getregions', controller.game.getRegions); router.post('/api/game/getservers', controller.game.getServers); router.post('/api/game/getregionstategy', controller.game.getRegionStategy); + router.post('/api/game/getwhitelist', controller.game.getWhiteList); + router.post('/api/game/updatewhitelist', controller.game.updateWhiteList); + router.post('/api/game/deletewhitelist', controller.game.deleteWhiteList); router.post('/api/game/stopserverregister', controller.game.stopServerRegister); router.post('/api/game/swicthserverstatus', controller.game.switchServerStatus); diff --git a/gm-server/app/service/Game.ts b/gm-server/app/service/Game.ts index 8ea7e3cd0..4ee6662db 100644 --- a/gm-server/app/service/Game.ts +++ b/gm-server/app/service/Game.ts @@ -13,6 +13,8 @@ import { AccuseRecModel } from '@db/AccuseRec'; import { RegionModel } from '@db/Region'; import { ActivityGroupModel } from '@db/ActivityGroup'; import { nowSeconds } from '@pubUtils/timeUtil'; +import { WhiteListModel } from '@db/RegionWhiteList'; +import { RoleModel } from '@db/Role'; /** * Test Service @@ -90,6 +92,42 @@ export default class Game extends Service { }); } + public async getWhiteList(id: number) { + const { ctx } = this; + let region = await RegionModel.findRegionById(id); + if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + + let whitelist = await WhiteListModel.findByRegionId(id); + + return ctx.service.utils.resResult(STATUS.SUCCESS, { + whitelist + }); + } + + public async updateWhiteList(id: number, code: string, type: number, content: string) { + const { ctx } = this; + let region = await RegionModel.findRegionById(id); + if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + if(type == 1) { + let whitelist = await WhiteListModel.updateWhiteList(code, { type, regionId: region.id, env: region.env, ip: content }); + return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist }); + } else if(type == 2) { + let role = await RoleModel.findByRoleId(content, 'roleId userInfo serverId roleName'); + let whitelist = await WhiteListModel.updateWhiteList(code, { type, regionId: region.id, env: region.env, uid: role.userInfo.uid, serverId: role.serverId, roleId: role.roleId, roleName: role.roleName }); + return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist }); + } else { + return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + } + } + + public async deleteWhiteList(id: number, code: string) { + const { ctx } = this; + let region = await RegionModel.findRegionById(id); + if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS); + let whitelist = await WhiteListModel.deleteWhiteList(code); + return ctx.service.utils.resResult(STATUS.SUCCESS, { whitelist }); + } + // public async getMaintenanceList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { isOpen?: boolean } = {}) { // const { ctx } = this; diff --git a/shared/consts/constModules/sysConst.ts b/shared/consts/constModules/sysConst.ts index b5d9fcd94..7eb6753a3 100644 --- a/shared/consts/constModules/sysConst.ts +++ b/shared/consts/constModules/sysConst.ts @@ -712,7 +712,7 @@ export enum SERVER_STATUS { export enum WHITE_LIST_TYPE { IP = 1, // ip地址 - TEL = 2, // 玩家手机号 + UID = 2, // 玩家账号 } // 获取道具类型 diff --git a/shared/db/RegionWhiteList.ts b/shared/db/RegionWhiteList.ts new file mode 100644 index 000000000..8ebe94fd8 --- /dev/null +++ b/shared/db/RegionWhiteList.ts @@ -0,0 +1,63 @@ +import BaseModel from './BaseModel'; +import { prop, DocumentType, getModelForClass } from '@typegoose/typegoose'; +import { WHITE_LIST_TYPE } from '../consts'; + +export default class RegionWhiteList extends BaseModel { + + @prop({ required: true }) + code: string; // 编码 + + @prop({ required: true }) + regionId: number; // 大区区号 + + @prop({ required: true }) + env: string; // 环境变量 + + @prop({ required: true, enum: WHITE_LIST_TYPE }) + type: WHITE_LIST_TYPE; // 环境变量 + + @prop({ required: true }) + ip: string; // ip + + @prop({ required: true }) + serverId: number; // 小区id + + @prop({ required: true }) + uid: number; // 玩家uid + + @prop({ required: true }) + roleId: string; // 玩家角色id + + @prop({ required: true }) + roleName: string; // 玩家角色名 + + public static async checkIp(env: string, ip: string) { + const rec = await WhiteListModel.exists({ env, ip }); + return rec; + } + + public static async checkUid(env: string, serverId: number, uid: number) { + const rec = await WhiteListModel.exists({ env, serverId, uid }); + return rec; + } + + public static async findByRegionId(regionId: number) { + const rec: WhiteListModelType[] = await WhiteListModel.find({ regionId }); + return rec; + } + + public static async updateWhiteList(code: string, params: WhiteListModelTypeParam) { + const rec: WhiteListModelType = await WhiteListModel.findOneAndUpdate({ code }, params, { new: true, upsert: true }).lean(); + return rec; + } + + public static async deleteWhiteList(code: string) { + const rec: WhiteListModelType = await WhiteListModel.findOneAndDelete({ code }).lean(); + return rec; + } +} + +export let WhiteListModel = getModelForClass(RegionWhiteList) + +export interface WhiteListModelType extends Pick, keyof RegionWhiteList> { } +export type WhiteListModelTypeParam = Partial; // 将所有字段变成可选项 \ No newline at end of file diff --git a/shared/db/WhiteList.ts b/shared/db/WhiteList.ts deleted file mode 100644 index ed1e4c012..000000000 --- a/shared/db/WhiteList.ts +++ /dev/null @@ -1,35 +0,0 @@ -import BaseModel from './BaseModel'; -import { prop, DocumentType, getModelForClass } from '@typegoose/typegoose'; - -export default class WhiteList extends BaseModel { - - @prop({ required: true }) - regionId: number; // 大区区号 - - @prop({ required: true }) - env: string; // 环境变量 - - @prop({ required: true }) - ip: string; // ip - - @prop({ required: true }) - serverId: number; // 小区id - - @prop({ required: true }) - uid: number; // 玩家uid - - public static async checkIp(env: string, ip: string) { - const rec = await WhiteListModel.exists({ env, ip }); - return rec; - } - - public static async checkUid(env: string, serverId: number, uid: number) { - const rec = await WhiteListModel.exists({ env, serverId, uid }); - return rec; - } -} - -export const WhiteListModel = getModelForClass(WhiteList); - -export interface WhiteListModelType extends Pick, keyof WhiteList> { } -export type WhiteListModelTypeParam = Partial; // 将所有字段变成可选项 \ No newline at end of file diff --git a/shared/pubUtils/util.ts b/shared/pubUtils/util.ts index 54ebd39f9..967989f8f 100644 --- a/shared/pubUtils/util.ts +++ b/shared/pubUtils/util.ts @@ -10,7 +10,7 @@ import { HERO_CE_RATIO, ABI_STAGE, GACHA_TO_FLOOR, REFRESH_TIME, ROBOT_SYS_TYPE, import { findIndex } from 'underscore'; import { getTimeFunM } from './timeUtil'; import { Floor } from '../domain/activityField/gachaField'; -import { WhiteListModel } from '../db/WhiteList'; +import { WhiteListModel } from '../db/RegionWhiteList'; const randomName = require("chinese-random-name"); const moment = require('moment'); const crypto = require('crypto');