init
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
import { UserModel } from '@db/User';
|
||||
import { LadderMatchRecModel } from '@db/LadderMatchRec';
|
||||
import { PvpRecordModel } from '@db/PvpRecord';
|
||||
import { BattleRecordModel } from '@db/BattleRecord';
|
||||
import { STATUS, WAR_TYPE } from '@consts';
|
||||
import { UserModel } from '../../../shared/db/User';
|
||||
import { LadderMatchRecModel } from '../../../shared/db/LadderMatchRec';
|
||||
import { PvpRecordModel } from '../../../shared/db/PvpRecord';
|
||||
import { BattleRecordModel } from '../../../shared/db/BattleRecord';
|
||||
import { STATUS, WAR_TYPE } from '../../../shared/consts';
|
||||
import { Controller } from 'egg';
|
||||
import * as fs from 'fs';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { NoticeModel } from '@db/Notice';
|
||||
import { ServerParamWithRole, GroupParam } from '../domain/gameField/serverlist';
|
||||
import { reloadResources } from 'app/pubUtils/data';
|
||||
import { ServerlistModel } from '@db/Serverlist';
|
||||
import { dispatch } from 'app/pubUtils/dispatcher';
|
||||
import { RoleModel } from '../../../shared/db/Role';
|
||||
import { NoticeModel } from '../../../shared/db/Notice';
|
||||
import { ServerParamWithRole, GroupParam } from '../../../shared/domain/gameField/serverlist';
|
||||
import { reloadResources } from '../../../shared/pubUtils/data';
|
||||
import { ServerlistModel } from '../../../shared/db/Serverlist';
|
||||
import { dispatch } from '../../../shared/pubUtils/dispatcher';
|
||||
import { RedisClient } from 'redis';
|
||||
import { REDIS_KEY } from '@consts';
|
||||
import { RegionModel } from '@db/Region';
|
||||
import { getRandEelmWithWeight } from 'app/pubUtils/util';
|
||||
import { getLocalRplUrl, getRemoteRplUrl, getRemoteRplPrefix } from 'app/pubUtils/battleUtils'
|
||||
import { ChannelInfoModel } from '@db/ChannelInfo';
|
||||
import { GVGVestigeRecModel } from '@db/GVGVestigeRec';
|
||||
import { GVGBattleRecModel } from '@db/GVGBattleRec';
|
||||
import { PackageModel } from '@db/Package';
|
||||
import { nowSeconds } from 'app/pubUtils/timeUtil';
|
||||
import { REDIS_KEY } from '../../../shared/consts';
|
||||
import { RegionModel } from '../../../shared/db/Region';
|
||||
import { getRandEelmWithWeight } from '../../../shared/pubUtils/util';
|
||||
import { getLocalRplUrl, getRemoteRplUrl, getRemoteRplPrefix } from '../../../shared/pubUtils/battleUtils'
|
||||
import { ChannelInfoModel } from '../../../shared/db/ChannelInfo';
|
||||
import { GVGVestigeRecModel } from '../../../shared/db/GVGVestigeRec';
|
||||
import { GVGBattleRecModel } from '../../../shared/db/GVGBattleRec';
|
||||
import { PackageModel } from '../../../shared/db/Package';
|
||||
import { nowSeconds } from '../../../shared/pubUtils/timeUtil';
|
||||
const sendToWormhole = require('stream-wormhole');
|
||||
const pump = require('mz-modules/pump');
|
||||
|
||||
@@ -49,12 +49,16 @@ export default class GameController extends Controller {
|
||||
const { ctx } = this;
|
||||
const { version, platformAppid, platformAppId, addressType, platform: clientPlatform } = ctx.request.body;
|
||||
|
||||
console.log('****** checkReview realEnv:', this.app.config.realEnv);
|
||||
let curRegion = await RegionModel.findRegionByEnv(this.app.config.realEnv);
|
||||
console.log('****** checkReview curRegion:', JSON.stringify(curRegion, null, 2));
|
||||
if(!curRegion) {
|
||||
console.log('****** checkReview curRegion is null');
|
||||
return ctx.body = ctx.service.utils.resResult(STATUS.VERSION_ERR);
|
||||
}
|
||||
|
||||
if(curRegion.addressType != addressType) {
|
||||
console.log('****** checkReview addressType mismatch:', curRegion.addressType, '!=', addressType);
|
||||
return ctx.body = ctx.service.utils.resResult(STATUS.ADDRESS_ERR);
|
||||
}
|
||||
|
||||
@@ -202,29 +206,31 @@ export default class GameController extends Controller {
|
||||
const { ctx } = this;
|
||||
const { app, userCode } = ctx;
|
||||
|
||||
let redisClient: RedisClient = app.context.redisClient;
|
||||
let hash = await redisClient.hvalsAsync(REDIS_KEY.SYS_SERVER);
|
||||
let connectors = hash.map(cur => JSON.parse(cur));
|
||||
let redisClient: RedisClient = (app.context as any).redisClient;
|
||||
let hash = await (redisClient as any).hvalsAsync(REDIS_KEY.SYS_SERVER);
|
||||
let connectors = hash.map((cur: string) => JSON.parse(cur));
|
||||
|
||||
if (!connectors || connectors.length === 0) {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.CONNECTOR_ERR);
|
||||
return
|
||||
}
|
||||
// select connector
|
||||
let sum = connectors.reduce((pre, cur) => pre + (cur['num']||0), 0);
|
||||
let sum = connectors.reduce((pre: number, cur: any) => pre + (cur['num']||0), 0);
|
||||
let res;
|
||||
if(sum > 0) {
|
||||
let serversWithWeight = connectors.map(cur => ({...cur, weight: sum - (cur['num']||0)}));
|
||||
let serversWithWeight = connectors.map((cur: any) => ({...cur, weight: sum - (cur['num']||0)}));
|
||||
let randResult = getRandEelmWithWeight(serversWithWeight);
|
||||
res = randResult.dic;
|
||||
}
|
||||
if(!res) {
|
||||
res = await dispatch(ctx.app.context.redisClient, userCode, connectors, 'connector');
|
||||
res = await dispatch((ctx.app.context as any).redisClient, userCode, connectors, 'connector');
|
||||
}
|
||||
let { id, serverType, clientHost, clientPort, num = 0 } = res;
|
||||
// 使用类型断言确保TypeScript知道res是ServerInfo类型
|
||||
const serverInfo = res as any;
|
||||
let { id, serverType, clientHost, clientPort, num = 0 } = serverInfo;
|
||||
|
||||
await redisClient.hsetAsync(REDIS_KEY.SYS_SERVER, id, JSON.stringify({ serverType, clientHost, clientPort, id, num: num + 1 }));
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
|
||||
await (redisClient as any).hsetAsync(REDIS_KEY.SYS_SERVER, id, JSON.stringify({ serverType, clientHost, clientPort, id, num: num + 1 }));
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { host: serverInfo.clientHost, port: serverInfo.clientPort });
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Controller } from 'egg';
|
||||
import { GetGuildInfoByUserParam, GetRoleByServerParam, GetRoleByUidParam, GetServerAndUidParam, GetServerListParam, GetServerParam, GuildNameCallBackParam, IOSRefundParam, PayCallback37Data, RoleNameCallBackParam, SendGiftCodeParam } from '../domain/sdk';
|
||||
import { GetGuildInfoByUserParam, GetRoleByServerParam, GetRoleByUidParam, GetServerAndUidParam, GetServerListParam, GetServerParam, GuildNameCallBackParam, IOSRefundParam, PayCallback37Data, RoleNameCallBackParam, SendGiftCodeParam } from '../../../shared/domain/sdk';
|
||||
|
||||
export default class SdkController extends Controller {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Controller } from 'egg';
|
||||
import { RegionModel } from '@db/Region';
|
||||
import { STATUS } from '@consts';
|
||||
import { checkWhiteList } from 'app/pubUtils/sysUtil';
|
||||
import { checkWhiteList } from '@pubUtils/sysUtil';
|
||||
|
||||
export default class UpdateController extends Controller {
|
||||
public async getversion() {
|
||||
|
||||
Reference in New Issue
Block a user