diff --git a/game-server/app/servers/connector/handler/entryHandler.ts b/game-server/app/servers/connector/handler/entryHandler.ts index ebc829a8e..86add5168 100644 --- a/game-server/app/servers/connector/handler/entryHandler.ts +++ b/game-server/app/servers/connector/handler/entryHandler.ts @@ -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'; diff --git a/game-server/app/servers/gate/handler/gateHandler.ts b/game-server/app/servers/gate/handler/gateHandler.ts index ca4b5b65e..20472c80e 100644 --- a/game-server/app/servers/gate/handler/gateHandler.ts +++ b/game-server/app/servers/gate/handler/gateHandler.ts @@ -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'; diff --git a/game-server/app/servers/guild/handler/cityActivityHandler.ts b/game-server/app/servers/guild/handler/cityActivityHandler.ts index 13050c623..8fe1b96ab 100644 --- a/game-server/app/servers/guild/handler/cityActivityHandler.ts +++ b/game-server/app/servers/guild/handler/cityActivityHandler.ts @@ -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"; diff --git a/game-server/app/servers/guild/handler/raceActivityHandler.ts b/game-server/app/servers/guild/handler/raceActivityHandler.ts index 0f00e40a7..6d472f83e 100644 --- a/game-server/app/servers/guild/handler/raceActivityHandler.ts +++ b/game-server/app/servers/guild/handler/raceActivityHandler.ts @@ -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, {}); diff --git a/game-server/app/services/connectorService.ts b/game-server/app/services/connectorService.ts index 2ff6f27f3..9a2c98ccf 100644 --- a/game-server/app/services/connectorService.ts +++ b/game-server/app/services/connectorService.ts @@ -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'; diff --git a/game-server/app/services/guildActivity/guildActivityService.ts b/game-server/app/services/guildActivity/guildActivityService.ts index 790212b47..223c618b5 100644 --- a/game-server/app/services/guildActivity/guildActivityService.ts +++ b/game-server/app/services/guildActivity/guildActivityService.ts @@ -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; diff --git a/game-server/app/services/gvg/gvgBattleMemory.ts b/game-server/app/services/gvg/gvgBattleMemory.ts index a72b2a4f0..074e8deae 100644 --- a/game-server/app/services/gvg/gvgBattleMemory.ts +++ b/game-server/app/services/gvg/gvgBattleMemory.ts @@ -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 diff --git a/game-server/app/services/gvg/gvgBattleService.ts b/game-server/app/services/gvg/gvgBattleService.ts index 998921533..9a7d1e9a1 100644 --- a/game-server/app/services/gvg/gvgBattleService.ts +++ b/game-server/app/services/gvg/gvgBattleService.ts @@ -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"; diff --git a/game-server/app/services/refreshService.ts b/game-server/app/services/refreshService.ts index 7dc66e08a..0c179d742 100644 --- a/game-server/app/services/refreshService.ts +++ b/game-server/app/services/refreshService.ts @@ -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"; diff --git a/game-server/app/services/timeTaskService.ts b/game-server/app/services/timeTaskService.ts index 2e0b3d6a5..dd3355c80 100644 --- a/game-server/app/services/timeTaskService.ts +++ b/game-server/app/services/timeTaskService.ts @@ -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'; diff --git a/game-server/app/util/dispatcher.ts b/game-server/app/util/dispatcher.ts new file mode 100644 index 000000000..64a4e1579 --- /dev/null +++ b/game-server/app/util/dispatcher.ts @@ -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>()); + } + + //测试代码 + // 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() + } + 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]; +} \ No newline at end of file diff --git a/game-server/app/util/routeUtil.ts b/game-server/app/util/routeUtil.ts index dceb2a561..aa8ebd69b 100644 --- a/game-server/app/util/routeUtil.ts +++ b/game-server/app/util/routeUtil.ts @@ -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) {