This commit is contained in:
xy
2026-03-13 01:38:40 +00:00
parent e6e4f88257
commit 28855885cd
311 changed files with 89544 additions and 94350 deletions
+37 -20
View File
@@ -1,12 +1,12 @@
import { Service } from 'egg';
import { resResult as pubResult } from '../pubUtils/util';
import { gameData } from 'app/pubUtils/data';
import { resResult as pubResult } from '../../../shared/pubUtils/util';
import { gameData } from '../../../shared/pubUtils/data';
import { RedisClient } from 'redis';
import { REDIS_KEY, SERVER_STATUS } from '@consts';
import { getRedisSubChannel } from 'app/pubUtils/sdkUtil';
import { ServerlistType } from '@db/Serverlist';
import { nowSeconds } from 'app/pubUtils/timeUtil';
import { checkWhiteList } from 'app/pubUtils/sysUtil';
import { REDIS_KEY, SERVER_STATUS } from '../../../shared/consts';
import { getRedisSubChannel } from '../../../shared/pubUtils/sdkUtil';
import { ServerlistType } from '../../../shared/db/Serverlist';
import { nowSeconds } from '../../../shared/pubUtils/timeUtil';
import { checkWhiteList } from '../../../shared/pubUtils/sysUtil';
const csprng = require('csprng');
/**
* Utils Service
@@ -21,7 +21,7 @@ export default class Utils extends Service {
return `${csprng(len, radix)}`;
}
public genCode(len) {
public genCode(len: number) {
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
const charArr = chars.split('');
let code = '';
@@ -43,7 +43,7 @@ export default class Utils extends Service {
return code;
}
public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) {
public resResult(status: {code: number, simStr: string}, data?: any, customMsg?: string) {
return pubResult(status, data, customMsg);
}
@@ -62,18 +62,18 @@ export default class Utils extends Service {
}
public async checkOnlineUser(userCode: string) {
let redisClient: RedisClient = this.ctx.app.context.redisClient;
let onlineRoleId = await redisClient.hgetAsync(REDIS_KEY.USER_CODE, userCode);
let redisClient: RedisClient = (this.ctx.app.context as any).redisClient;
let onlineRoleId = await (redisClient as any).hgetAsync(REDIS_KEY.USER_CODE, userCode);
let isWhiteList = await checkWhiteList(this.ctx.app.config.realEnv, this.ctx.clientIp, this.ctx.uid);
if (!isWhiteList && !!onlineRoleId) { // 多地登陆踢下线
let str = await redisClient.hgetAsync(REDIS_KEY.ONLINE_USERS, onlineRoleId);
let str = await (redisClient as any).hgetAsync(REDIS_KEY.ONLINE_USERS, onlineRoleId);
if(str) {
try {
let [,sid] = str?.split('|')??[];
let name = getRedisSubChannel(REDIS_KEY.USER_CHANNEL, this.ctx.app.config.env);
await redisClient.publishAsync(name, `${sid}|${onlineRoleId}`);
await (redisClient as any).publishAsync(name, `${sid}|${onlineRoleId}`);
} catch(e) {
console.error('checkOnlineUser', e);
}
@@ -82,22 +82,22 @@ export default class Utils extends Service {
}
public async pushPubAccountGiftChannel(activityId: number, userCode: string, channelId: string) {
let redisClient: RedisClient = this.ctx.app.context.redisClient;
let redisClient: RedisClient = (this.ctx.app.context as any).redisClient;
try {
let name = getRedisSubChannel(REDIS_KEY.PUBLIC_ACCOUNT_GIFT, this.ctx.app.config.env);
await redisClient.publishAsync(name, `${activityId}|${userCode}|${channelId}`);
await (redisClient as any).publishAsync(name, `${activityId}|${userCode}|${channelId}`);
} catch(e) {
console.error('pushPubAccountGiftChannel', e);
}
}
public async pushGiftCodeChannel(roleId: string, giftCode: string) {
let redisClient: RedisClient = this.ctx.app.context.redisClient;
let redisClient: RedisClient = (this.ctx.app.context as any).redisClient;
try {
let name = getRedisSubChannel(REDIS_KEY.SEND_GIFT_CODE, this.ctx.app.config.env);
await redisClient.publishAsync(name, `${roleId}|${giftCode}`);
await (redisClient as any).publishAsync(name, `${roleId}|${giftCode}`);
} catch(e) {
console.error('pushPubAccountGiftChannel', e);
}
@@ -109,9 +109,9 @@ export default class Utils extends Service {
if(gameData.serverConst.CLOSE_LOGIN == 1) return false;
if(gameData.serverConst.CLOSE_LOGIN_WHEN_ONLINE_MAX) {
let redisClient: RedisClient = this.ctx.app.context.redisClient;
let count = await redisClient.hlenAsync(REDIS_KEY.ONLINE_USERS);
const Max = await redisClient.getAsync(REDIS_KEY.MAX_ONLINE_USERS);
let redisClient: RedisClient = (this.ctx.app.context as any).redisClient;
let count = await (redisClient as any).hlenAsync(REDIS_KEY.ONLINE_USERS);
const Max = await (redisClient as any).getAsync(REDIS_KEY.MAX_ONLINE_USERS);
console.log('validateCanLogin:', count, Max);
if(Max && count >= parseInt(Max)) {
@@ -128,11 +128,28 @@ export default class Utils extends Service {
// 比较以 . 分隔的版本号。返回 0 则版本号相等,返回正数则 versionA 大,返回负数则 versionB 大
public compareVersion (versionA: string, versionB: string) {
if (!versionA && !versionB) {
return 0;
}
if (!versionA) {
return -1;
}
if (!versionB) {
return 1;
}
var vA = versionA.split('.');
var vB = versionB.split('.');
for (var i = 0; i < vA.length; ++i) {
var a = parseInt(vA[i]);
var b = parseInt(vB[i] || '0');
if (isNaN(a) || isNaN(b)) {
if (a === b) {
continue;
} else {
return isNaN(a) ? -1 : 1;
}
}
if (a === b) {
} else {