登录优化: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,44 +0,0 @@
|
||||
import * as crc from 'crc';
|
||||
import { ServerInfo } from 'pinus';
|
||||
|
||||
|
||||
|
||||
let roleRoute = new Map<string, Map<string, string>>()
|
||||
|
||||
export function dispatch(uid: string, connectors: ServerInfo[], serverType: 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' })
|
||||
// }
|
||||
// }
|
||||
|
||||
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];
|
||||
}
|
||||
let index = Math.abs(crc.crc32(uid)) % connectors.length;
|
||||
return connectors[index];
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
};
|
||||
@@ -1,96 +0,0 @@
|
||||
import * as Redis from 'redis';
|
||||
import { promisifyAll } from 'bluebird';
|
||||
|
||||
// 映射 redis 接口
|
||||
declare module 'redis' {
|
||||
export interface RedisClient extends NodeJS.EventEmitter {
|
||||
// key 是否存在。
|
||||
existsAsync(key: string): Promise<number>;
|
||||
// 在 key 存在时删除 key。
|
||||
delAsync(key: string): Promise<number>;
|
||||
// 在 key 存在时删除 key。
|
||||
keysAsync(pattern: string): Promise<string[]>;
|
||||
// 设置过期时间
|
||||
expireAsync(key: string, time: number): Promise<number>;
|
||||
// 按时间戳设置过期时间
|
||||
expireatAsync(key: string, time: number): Promise<number>;
|
||||
// string类型存储
|
||||
setexAsync(key: string, time: number, value: string): Promise<number>;
|
||||
// 获取存储string类型value
|
||||
getAsync(key: string): Promise<string>;
|
||||
// 获取存储string类型value
|
||||
setAsync(key: string, value: string): Promise<number>;
|
||||
// 删除哈希表 key 中的一个或多个指定字段
|
||||
hdelAsync(key: string, field: string): Promise<number>;
|
||||
// 将哈希表 key 中的字段 field 的值设为 value
|
||||
hsetAsync<T>(key: string, field: string, value: T): Promise<T>;
|
||||
// 获取存储在哈希表中指定字段的值
|
||||
hgetAsync(key: string, field: string): Promise<any>;
|
||||
// 获取存储在哈希表中指定字段的值。
|
||||
hexistsAsync(key: string, field: string): Promise<number>;
|
||||
// 获取哈希表中所有字段和值
|
||||
hgetallAsync(key: string): Promise<any>;
|
||||
// 增值
|
||||
hincrbyAsync(key: string, field: string, inc: number): Promise<number>;
|
||||
|
||||
// 移除并返回集合中的一个随机元素
|
||||
spopAsync(key: string, count?: number): Promise<number>;
|
||||
// 移除集合中一个或多个成员
|
||||
sremAsync(key: string, member: string): Promise<number>;
|
||||
// 返回集合中一个或多个随机数
|
||||
srandmemberAsync(key: string, count?: number): Promise<string|string[]>;
|
||||
// 判断成员元素是否是集合的成员
|
||||
sismemberAsync(key: string, member: string): Promise<boolean>;
|
||||
|
||||
// 向有序集合添加一个或多个成员,或者更新已存在成员的分数
|
||||
zaddAsync(key: string, score: number, member: string): Promise<number>;
|
||||
// 返回有序集中指定分数区间内的成员,分数从高到低排序
|
||||
zrevrangebyscoreAsync(key: string, max: (string|number), min: (string|number), withscores?: string, limit?:string, offset?: number, count?:number): Promise<string[]>;
|
||||
// 获取有序集合的成员数
|
||||
zcardAsync(key: string): Promise<number>;
|
||||
// 移除有序集合中给定的排名区间的所有成员
|
||||
zremrangebyrankAsync(key: string, start: number, stop: number): Promise<number>;
|
||||
// 移除有序集中的一个或多个成员
|
||||
zremAsync(key: string, member: string): Promise<number>;
|
||||
// 返回有序集中指定成员的排名,从小到大
|
||||
zrankAsync(key: string, field: string): Promise<number>;
|
||||
// 返回有序集中指定成员的排名,从大到小
|
||||
zrevrankAsync(key: string, field: string): Promise<number>;
|
||||
// 命令返回有序集中,指定区间内的成员,从大到小
|
||||
zrevrangeAsync(key: string, start: number, end: number, withscores?: string): Promise<string[]>;
|
||||
// 对有序集合中指定成员的分数加上增量 increment
|
||||
zincrbyAsync(key: string, increment: number, member: string): Promise<number>;
|
||||
// 对有序集合中指定成员的分数加上增量 increment
|
||||
zunionstoreAsync(destination: string, numkeys: number, ...args: any): Promise<number>;
|
||||
// 返回有序集中,成员的分数值
|
||||
zscoreAsync(key: string, member: string): Promise<number>;
|
||||
// 显示集合成员
|
||||
smembersAsync(key: string): Promise<string[]>;
|
||||
// 增加集合成员
|
||||
saddAsync(key: string, values: string[]): Promise<string>;
|
||||
|
||||
}
|
||||
export interface Multi extends Commands<Multi> {
|
||||
execAsync(...args: any[]): Promise<any>;
|
||||
}
|
||||
}
|
||||
|
||||
export function connectRedis(redisArr: string, redisPw: string) {
|
||||
|
||||
// 创建 redis 连接
|
||||
const oldRedisClient = Redis.createClient(6379, redisArr, {detect_buffers: true});
|
||||
oldRedisClient.auth(redisPw, (err, reply) => {
|
||||
if (err) {
|
||||
console.log('redis err', err);
|
||||
} else {
|
||||
console.log('redis suc');
|
||||
}
|
||||
})
|
||||
|
||||
// 转 promise
|
||||
const client = promisifyAll(oldRedisClient) as Redis.RedisClient;
|
||||
promisifyAll(Redis.Multi.prototype);
|
||||
client.set('hello', 'redis', Redis.print);
|
||||
|
||||
return client;
|
||||
}
|
||||
Reference in New Issue
Block a user