防沉迷:不使用厚土sdk
This commit is contained in:
@@ -8,6 +8,7 @@ import { GuildRankParam, GuildLeader, RankParam, LineupParam } from '../domain/r
|
||||
import { comBtlRanges } from '../pubUtils/data';
|
||||
import { setRankRedisFromDb } from './rankService';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import moment = require('moment');
|
||||
/**
|
||||
* 在服务重新启动时,将信息存入redis
|
||||
*/
|
||||
@@ -346,6 +347,34 @@ export async function getAllOnlineRoles() {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将玩家登录时间记录到
|
||||
* @param userCode 玩家user表里的userCode
|
||||
* @param isToday 累计记录还是当日记录
|
||||
* @returns 分钟
|
||||
*/
|
||||
export async function incOnlineTime(userCode: string, isToday: boolean, incTime: number) {
|
||||
moment.locale('zh-cn');
|
||||
let today = moment().format('YYYYMMDD');
|
||||
let key = isToday? REDIS_KEY.ONLINE_TIME: `${REDIS_KEY.ONLINE_TIME}:${today}`;
|
||||
if(isToday) {
|
||||
let tomorrow = moment().add(1, 'days').hours(0).minutes(0).seconds(0).format('x');
|
||||
await redisClient().expireatAsync(key, parseInt(tomorrow));
|
||||
}
|
||||
return await redisClient().hincrbyAsync(key, userCode, incTime);
|
||||
}
|
||||
|
||||
export async function setOnlineTime(userCode: string, isToday: boolean, setTime: number) {
|
||||
moment.locale('zh-cn');
|
||||
let today = moment().format('YYYYMMDD');
|
||||
let key = isToday? REDIS_KEY.ONLINE_TIME: `${REDIS_KEY.ONLINE_TIME}:${today}`;
|
||||
if(isToday) {
|
||||
let tomorrow = moment().add(1, 'days').hours(0).minutes(0).seconds(0).format('x');
|
||||
await redisClient().expireatAsync(key, parseInt(tomorrow));
|
||||
}
|
||||
return await redisClient().hsetAsync(key, userCode, setTime);
|
||||
}
|
||||
|
||||
|
||||
// 排行榜是否存在
|
||||
export async function smembersAsync(key: string) {
|
||||
|
||||
Reference in New Issue
Block a user