🎈 perf(内存): roleRoute挂在app上
This commit is contained in:
@@ -22,7 +22,6 @@ import { reportCreateRoleEventToTa, reportTAEvent, reportTAUserSet } from '../..
|
||||
import { saveLoginAndOutLog } from '../../../pubUtils/logUtil';
|
||||
import { sendMessageToAllWithSuc, sendMessageToUserWithSuc } from '../../../services/pushService';
|
||||
import { checkServerIsOpen, getIpLocation } from '../../../services/roleService';
|
||||
import { dispatch } from '../../../pubUtils/dispatcher';
|
||||
import { leaveRaceActivityToRemote } from '../../../services/guildActivity/guildActivityService';
|
||||
import { getHiddenData } from '../../../services/dataService';
|
||||
import { leaveCity } from '../../../services/gvg/gvgBattleService';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { dispatch } from '../../../pubUtils/dispatcher';
|
||||
import { dispatch } from '../../../util/dispatcher';
|
||||
import { Application, BackendSession, HandlerService, pinus, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import { getGoldObject, handleCost } from "../../../services/role/rewardService"
|
||||
import { Rank } from "../../../services/rankService";
|
||||
import { checkTask } from "../../../services/task/taskService";
|
||||
import { guildInter } from "../../../pubUtils/interface";
|
||||
import { dispatch } from "../../../pubUtils/dispatcher";
|
||||
import { dispatch } from "../../../util/dispatcher";
|
||||
import { ServerRecordModel } from "../../../db/ServerRecords";
|
||||
import { sendMessageToCityWithSuc } from "../../../services/pushService";
|
||||
import { isDebugTime } from "../../../pubUtils/sdkUtil";
|
||||
|
||||
@@ -12,7 +12,7 @@ import { sendMessageToGuildWithSuc } from "../../../services/pushService";
|
||||
import { RaceActivityRankParam } from "../../../domain/battleField/guildActivity";
|
||||
import { GuildRankInfo } from "../../../domain/rank";
|
||||
import { ServerlistModel } from "../../../db/Serverlist";
|
||||
import { dispatch } from "../../../pubUtils/dispatcher";
|
||||
import { dispatch } from "../../../util/dispatcher";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
|
||||
@@ -47,7 +47,7 @@ import { getSurvey } from './gmService';
|
||||
import { ComBattleTeamModel } from '../db/ComBattleTeam';
|
||||
import { INFO_WINDOW } from '../pubUtils/dicParam';
|
||||
import { getLadderData } from './ladderService';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { dispatch } from '../util/dispatcher';
|
||||
import { PvpDataReturn } from '../domain/battleField/pvp';
|
||||
import { getHiddenData } from './dataService';
|
||||
import { ArtifactModel } from '../db/Artifact';
|
||||
|
||||
@@ -32,7 +32,7 @@ import { getRandSingleEelm } from "../../pubUtils/util";
|
||||
import { CounterModel } from "../../db/Counter";
|
||||
import { setInterval } from "timers";
|
||||
import { DicRaceActivity } from "../../pubUtils/dictionary/DicRaceActivity";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
import { dispatch } from "../../util/dispatcher";
|
||||
import { GuildModel } from "../../db/Guild";
|
||||
|
||||
let gateActivityObj: GateActivityObject;
|
||||
|
||||
@@ -4,7 +4,7 @@ import { pinus } from "pinus";
|
||||
import { GVG_CATAPULT, GVG_PERIOD } from "../../consts";
|
||||
import { GVGTeamModel, GVGTeamType } from "../../db/GVGTeam";
|
||||
import { GVGTeamMem } from "../../domain/battleField/gvgBattle";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
import { dispatch } from "../../util/dispatcher";
|
||||
import { getGVGPeriodData } from "./gvgService";
|
||||
|
||||
// 积分点占领情况,groupId_serverType_cityId -> GVGBattleData
|
||||
|
||||
@@ -13,7 +13,7 @@ import { GVGHeroInfo, PvpEnemies, PvpHeroInfo } from "../../domain/dbGeneral";
|
||||
import { getGroupKey, getGVGConfig, getGVGConfigFromRemote, getGVGPeriodData } from "./gvgService";
|
||||
import { GVGLeaguePrepareModel } from "../../db/GVGLeaguePrepare";
|
||||
import { pinus } from "pinus";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
import { dispatch } from "../../util/dispatcher";
|
||||
import { Rank } from "../rankService";
|
||||
import { KeyNameParam, LeagueRankInfo, myIdInter, RoleRankInfo } from "../../domain/rank";
|
||||
import { findKeys, getAllServerName, redisClient } from "../redisService";
|
||||
|
||||
@@ -2,7 +2,7 @@ import { FrontendOrBackendSession, pinus } from "pinus";
|
||||
import { shouldRefresh, shouldRefreshWeek } from '../pubUtils/util';
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { refDailyTask, refDailyTaskBox } from './task/taskService'
|
||||
import { dispatch } from "../pubUtils/dispatcher";
|
||||
import { dispatch } from "../util/dispatcher";
|
||||
import { sendMessageToUserWithSuc } from "./pushService";
|
||||
import { PUSH_ROUTE } from "../consts";
|
||||
import { isDebugTime } from "../pubUtils/sdkUtil";
|
||||
|
||||
@@ -12,7 +12,7 @@ import { sendMailByContent, SendMailFun, sendMailsByGmMail, } from './mailServic
|
||||
import { sendEndMsgToAllServer, sendGuildActivityStatus, setPreDayActiveData, incCurGuildActivityIndex } from './guildActivity/guildActivityService';
|
||||
import { sendUngotDividendJob, startGuildAuction, startWorldAuction, stopAuction } from './auctionService';
|
||||
import { DicGuildActivity } from '../pubUtils/dictionary/DicGuildActivity';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { dispatch } from '../util/dispatcher';
|
||||
import { createNewServer, initMarquee, setServerMainten } from './gmService';
|
||||
import moment = require('moment');
|
||||
import { reportOneOnline } from './authenticateService';
|
||||
|
||||
65
game-server/app/util/dispatcher.ts
Normal file
65
game-server/app/util/dispatcher.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as crc from 'crc';
|
||||
import { pinus } from 'pinus';
|
||||
|
||||
interface ServerInfo {
|
||||
id: string;
|
||||
serverType: string;
|
||||
host: string;
|
||||
port: number;
|
||||
clientHost?: string;
|
||||
clientPort?: number;
|
||||
frontend ?: boolean;
|
||||
|
||||
args ?: string | string[];
|
||||
cpu ?: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function dispatch(uid: string, connectors: ServerInfo[], serverType: string = '') {
|
||||
let roleRoute = pinus.app.get('roleRoute');
|
||||
if(!roleRoute) {
|
||||
pinus.app.set('roleRoute', new Map<string, Map<string, string>>());
|
||||
}
|
||||
|
||||
//测试代码
|
||||
// if (serverType == 'activity') {
|
||||
// if (uid == 'SPDtGqx9Gw') {
|
||||
// if (connectors.length > 1) {
|
||||
// connectors = connectors.filter(obj => { return obj.id != 'activity-server-1' })
|
||||
// }
|
||||
// } else {
|
||||
// connectors = connectors.filter(obj => { return obj.id == 'activity-server-1' })
|
||||
// }
|
||||
// }
|
||||
connectors.sort((a, b) => a.id > b.id? 1: -1);
|
||||
|
||||
if (serverType) {
|
||||
let roleRouteData = roleRoute.get(uid);
|
||||
let serverId = '';
|
||||
if (roleRouteData) {
|
||||
serverId = roleRouteData.get(serverType);
|
||||
if (serverId) {
|
||||
let index = connectors.findIndex(obj => { return obj.id === serverId });
|
||||
if (index != -1) {
|
||||
// console.log('aaaaaaaaa 1', roleRouteData)
|
||||
return connectors[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
let index = Math.abs(crc.crc32(uid)) % connectors.length;
|
||||
if (!roleRouteData) {
|
||||
roleRouteData = new Map<string, string>()
|
||||
}
|
||||
roleRouteData.set(serverType, connectors[index].id);
|
||||
roleRoute.set(uid, roleRouteData)
|
||||
// console.log('aaaaaaaaa 2', roleRouteData)
|
||||
return connectors[index];
|
||||
}
|
||||
pinus.app.set('roleRoute', roleRoute);
|
||||
let index = Math.abs(crc.crc32(uid)) % connectors.length;
|
||||
return connectors[index];
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { dispatch } from './dispatcher';
|
||||
import { Session, Application } from 'pinus';
|
||||
|
||||
export function chat(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
|
||||
Reference in New Issue
Block a user