登录优化:gate可变为短链接
This commit is contained in:
+11
-1
@@ -18,7 +18,7 @@ import * as routeUtil from './app/util/routeUtil';
|
||||
import { preload } from './preload';
|
||||
import { globalFilter } from'./app/servers/connector/filter/global';
|
||||
import { guildAuthFilter } from'./app/servers/guild/filter/guildAuthFilter';
|
||||
import { connectRedis } from './config/redis';
|
||||
import { connectRedis } from './app/pubUtils/redis';
|
||||
import * as timeTaskService from './app/services/timeTaskService';
|
||||
import * as redlockCacheService from './app/services/redlockCacheService';
|
||||
import * as redLockService from './app/services/redLockService';
|
||||
@@ -213,6 +213,16 @@ app.configure(function () {
|
||||
|
||||
if (app.isMaster()) {
|
||||
// app.use(createRobotPlugin({scriptFile: __dirname + '/robot/robot.js'}));
|
||||
|
||||
app.event.on('add_servers', (server) => {
|
||||
redisService.setConnectors(server);
|
||||
})
|
||||
app.event.on('replace_servers', (server) => {
|
||||
redisService.setConnectors(server);
|
||||
})
|
||||
app.event.on('remove_servers', (server) => {
|
||||
redisService.removeConnectors(server);
|
||||
})
|
||||
}
|
||||
|
||||
// start app
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { dispatch } from '../../../util/dispatcher';
|
||||
import { dispatch } from '../../../pubUtils/dispatcher';
|
||||
import { Application, BackendSession, HandlerService, } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { getRewardByBlueprtId, gameData, getBossHpByBlueprtId } from '../pubUtil
|
||||
import { getFriendPointObject } from '../pubUtils/itemUtils';
|
||||
import { DicWar } from '../pubUtils/dictionary/DicWar';
|
||||
import { getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { dispatch } from '../util/dispatcher';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
|
||||
/**
|
||||
* 在给定的品质列表中随机返回一定数量的藏宝图Id
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as Redis from 'redis';
|
||||
import {REDIS_KEY} from '../consts'
|
||||
import { GameModel } from "../db/Game";
|
||||
import { promisifyAll } from 'bluebird';
|
||||
import { pinus } from 'pinus';
|
||||
import { pinus, ServerInfo } from 'pinus';
|
||||
import { GuildRankParam, GuildLeader, RankParam, LineupParam } from '../domain/rank';
|
||||
import { comBtlRanges } from '../pubUtils/data';
|
||||
import { setRankRedisFromDb } from './rankService';
|
||||
@@ -446,3 +446,22 @@ export function redisClient() {
|
||||
}
|
||||
|
||||
/**************** 数据库表end */
|
||||
|
||||
|
||||
/*************** 将connector服插入redis *******/
|
||||
|
||||
export async function setConnectors(servers: ServerInfo[]) {
|
||||
for(let server of servers) {
|
||||
if(server.serverType == 'connector') {
|
||||
let { serverType, clientHost, clientPort, id } = server;
|
||||
await redisClient().hsetAsync(REDIS_KEY.SYS_SERVER, server.id, JSON.stringify({ serverType, clientHost, clientPort, id }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeConnectors(servers: string[]) {
|
||||
for(let server of servers) {
|
||||
let hasServer = await redisClient().hgetAsync(REDIS_KEY.SYS_SERVER, server);
|
||||
if(!!hasServer) await redisClient().hdelAsync(REDIS_KEY.SYS_SERVER, server);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import { sendMailByContent } from './mailService';
|
||||
import { getGuildActivityByDic, sendEndMsgToAll, autoDeclare, sendGuildActivityStatus } from './guildActivityService';
|
||||
import { sendUngotDividendJob, startGuildAuction, startWorldAuction, stopAuction } from './auctionService';
|
||||
import { DicGuildActivity } from '../pubUtils/dictionary/DicGuildActivity';
|
||||
import { dispatch } from '../util/dispatcher';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { Rank } from './rankService';
|
||||
import { checkTask } from './taskService';
|
||||
import { everydayRefresh } from './connectorService';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import { dispatch } from './dispatcher';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { Session, Application } from 'pinus';
|
||||
|
||||
export function chat(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
|
||||
@@ -32,7 +32,7 @@ module.exports = {
|
||||
},
|
||||
'distribute': {
|
||||
'mongo': 'mongodb://dbop:zyzDev2021@dds-8vb5c74ba4263da41.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb5c74ba4263da42.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-506991391',
|
||||
'redis': 'r-8vb130185rp2ir3lqn.redis.zhangbei.rds.aliyuncs.com',
|
||||
'redispw': 'zyz_monitor_2021'
|
||||
'redis': 'r-8vb418l8kkju9sis8k.redis.zhangbei.rds.aliyuncs.com',
|
||||
'redispw': 'zyz_dev_2021'
|
||||
}
|
||||
};
|
||||
@@ -31,7 +31,7 @@ module.exports = {
|
||||
},
|
||||
'distribute': {
|
||||
'id': 'master-server-1',
|
||||
'host': '172.26.145.159',
|
||||
'host': '172.26.145.161',
|
||||
'port': 3005
|
||||
}
|
||||
};
|
||||
+6
-1
@@ -9,12 +9,14 @@
|
||||
"@types/request-promise": "^4.1.47",
|
||||
"bcrypt": "^5.0.0",
|
||||
"chinese-random-name": "^1.0.0",
|
||||
"crc": "^3.8.0",
|
||||
"lodash": "^4.17.20",
|
||||
"moment": "^2.27.0",
|
||||
"mongoose": "^5.10.4",
|
||||
"mongoose-lean-getters": "^0.1.2",
|
||||
"mongoose-lean-virtuals": "^0.7.6",
|
||||
"mongoose-transactions": "^1.1.4",
|
||||
"redis": "^3.1.2",
|
||||
"request": "^2.88.2",
|
||||
"request-promise": "^4.2.6",
|
||||
"underscore": "^1.12.0"
|
||||
@@ -27,5 +29,8 @@
|
||||
"url": "https://gitlab.trgame.cn/zyztech/zyz_server.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/redis": "^2.8.31"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +229,7 @@ export const REDIS_KEY = {
|
||||
GUILD_LV_RANK: "guildLvRank", // 公会等级排行榜
|
||||
HERO_RANK: "heroRank", // 武将排行榜
|
||||
SHOW_LINEUP: "showLineup", // 展示阵容
|
||||
SYS_SERVER: 'sysServer', // 全服connector服
|
||||
}
|
||||
|
||||
// 各排行榜对应hash的key
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
import * as crc from 'crc';
|
||||
import { ServerInfo } from 'pinus';
|
||||
|
||||
interface ServerInfo {
|
||||
id: string;
|
||||
serverType: string;
|
||||
host: string;
|
||||
port: number;
|
||||
clientHost?: string;
|
||||
clientPort?: number;
|
||||
frontend ?: boolean;
|
||||
|
||||
args ?: string | string[];
|
||||
cpu ?: number;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ declare module 'redis' {
|
||||
hgetallAsync(key: string): Promise<any>;
|
||||
// 增值
|
||||
hincrbyAsync(key: string, field: string, inc: number): Promise<number>;
|
||||
// 命令返回哈希表所有的值。
|
||||
hvalsAsync(key: string): Promise<any>;
|
||||
|
||||
// 移除并返回集合中的一个随机元素
|
||||
spopAsync(key: string, count?: number): Promise<number>;
|
||||
@@ -79,7 +81,7 @@ export function connectRedis(redisArr: string, redisPw: string) {
|
||||
|
||||
// 创建 redis 连接
|
||||
const oldRedisClient = Redis.createClient(6379, redisArr, {detect_buffers: true});
|
||||
oldRedisClient.auth(redisPw, (err, reply) => {
|
||||
oldRedisClient.auth(redisPw, (err, _reply) => {
|
||||
if (err) {
|
||||
console.log('redis err', err);
|
||||
} else {
|
||||
@@ -390,6 +390,23 @@ export function deepCopy(obj) {
|
||||
return target;
|
||||
};
|
||||
|
||||
export function readFile(addr: string) {
|
||||
return fs.readFileSync(path.resolve(__dirname, `${addr}`)).toString('utf8').replace(/^\uFEFF/, '');
|
||||
}
|
||||
|
||||
export function writeFile(addr: string, data: string) {
|
||||
return fs.writeFileSync(addr, data);
|
||||
}
|
||||
|
||||
export function readFileAndParseJson(path: string) {
|
||||
try {
|
||||
let readResult = readFile(path);
|
||||
return JSON.parse(readResult);
|
||||
} catch(e) {
|
||||
throw new Error(`connectors.json 格式错误:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function readJsonFile(fileName: string) {
|
||||
const folder = 'jsons';
|
||||
return fs.readFileSync(path.resolve(__dirname, `../resource/${folder}/${fileName}.json`)).toString('utf8').replace(/^\uFEFF/, '');
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[{"main":"/Users/bantu/zyz_server/game-server/dist/app.js","env":"development","id":"connector-server-1","host":"127.0.0.1","port":4050,"clientHost":"127.0.0.1","clientPort":3050,"frontend":"true","args":"--inspect=10001","serverType":"connector","remoterPaths":[{"namespace":"sys","serverType":"connector","path":"/Users/bantu/zyz_server/game-server/node_modules/pinus/dist/lib/common/remote/frontend"},{"namespace":"user","serverType":"connector","path":"/Users/bantu/zyz_server/game-server/dist/app/servers/connector/remote"}],"handlerPaths":["/Users/bantu/zyz_server/game-server/dist/app/servers/connector/handler"],"pid":28585}]
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
import 'reflect-metadata'
|
||||
import * as mongoose from 'mongoose';
|
||||
import { Application, IBoot } from 'egg';
|
||||
import { connectRedis } from './app/pubUtils/redis';
|
||||
|
||||
export default class FooBoot implements IBoot {
|
||||
private readonly app: Application;
|
||||
@@ -13,7 +14,9 @@ export default class FooBoot implements IBoot {
|
||||
// Ready to call configDidLoad,`
|
||||
// Config, plugin files are referred,`
|
||||
// this is the last chance to modify the config.
|
||||
await this.connectDB(this.app)
|
||||
await this.connectDB(this.app);
|
||||
await this.connectRedis(this.app);
|
||||
|
||||
}
|
||||
|
||||
configDidLoad() {
|
||||
@@ -54,6 +57,13 @@ export default class FooBoot implements IBoot {
|
||||
}
|
||||
}
|
||||
|
||||
public async connectRedis(app: Application) {
|
||||
const { url, pw } = app.config.redis
|
||||
if (url) {
|
||||
const redisClient = connectRedis(url, pw);
|
||||
app.context.redisClient = redisClient;
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ 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 { RedisClient } from 'redis';
|
||||
import { REDIS_KEY } from '@consts';
|
||||
|
||||
export default class GameController extends Controller {
|
||||
|
||||
@@ -106,4 +109,21 @@ export default class GameController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public async queryEnter() {
|
||||
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));
|
||||
|
||||
if (!connectors || connectors.length === 0) {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.CONNECTOR_ERR);
|
||||
return
|
||||
}
|
||||
// select connector
|
||||
let res = dispatch(userCode, connectors, 'connector');
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, { host: res.clientHost, port: res.clientPort });
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ export default (app: Application) => {
|
||||
router.post('/user/checkversion', tokenParser, controller.game.checkVersion);
|
||||
router.post('/game/getserverlist', tokenParser, controller.game.getServerList);
|
||||
router.post('/game/getnotice', tokenParser, controller.game.getnotice);
|
||||
router.post('/gate/queryenter', tokenParser, controller.game.queryEnter);
|
||||
router.post('/update/getversion', controller.update.getversion);
|
||||
router.post('/web/reloadresource', app.middleware.gmTokenParser(), controller.game.reloadResource);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://dbop:zyzdbopbantu@dds-8vbdb47c6fb58a541.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdb47c6fb58a542.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-500808098', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: 'r-8vb4i2kgl91886fkxd.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||
pw: 'zyz_2020'
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://dbop:zyzDev2021@dds-8vb5c74ba4263da41.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb5c74ba4263da42.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-506991391', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: 'r-8vbl8okinxn1zhkwh2.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||
pw: 'zyz_alpha_2021'
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://root:Bantus123@dds-8vb74337eab84d641.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb74337eab84d642.mongodb.zhangbei.rds.aliyuncs.com:3717/admin?replicaSet=mgset-504694158', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: 'r-8vbekkbb3z8ru2ckuj.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||
pw: 'zyz_isbn_2021'
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://127.0.0.1/zyz', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: '127.0.0.1', // 内网
|
||||
pw: ''
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://127.0.0.1/zyz', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: '127.0.0.1', // 内网
|
||||
pw: ''
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -24,6 +24,10 @@ export default (appInfo: EggAppInfo) => {
|
||||
url: 'mongodb://dbop:zyzMon2021@dds-8vb7474e31ba7ed41.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb7474e31ba7ed42.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-505529944', // 内网
|
||||
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||
};
|
||||
config.redis = {
|
||||
url: 'r-8vb130185rp2ir3lqn.redis.zhangbei.rds.aliyuncs.com', // 内网
|
||||
pw: 'zyz_monitor_2021'
|
||||
};
|
||||
|
||||
// config.alinode = {
|
||||
// appid: '86043',
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"lylocal": "cross-env EGG_SERVER_ENV=lylocal npm run dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"crc": "^3.8.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"csprng": "^0.1.2",
|
||||
"egg": "^2.6.1",
|
||||
@@ -37,6 +38,7 @@
|
||||
"egg-xtransit": "^1.2.2",
|
||||
"moment": "^2.29.1",
|
||||
"mongoose-transactions": "^1.1.4",
|
||||
"redis": "^3.1.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"request": "^2.88.2",
|
||||
"request-promise": "^4.2.6",
|
||||
@@ -45,6 +47,7 @@
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^2.2.40",
|
||||
"@types/node": "^7.0.12",
|
||||
"@types/redis": "^2.8.31",
|
||||
"@types/request-promise": "^4.1.47",
|
||||
"@types/supertest": "^2.0.0",
|
||||
"autod": "^3.0.1",
|
||||
@@ -72,4 +75,4 @@
|
||||
],
|
||||
"author": "liangtongchuan",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user