防沉迷:不使用厚土sdk
This commit is contained in:
@@ -1,28 +1,23 @@
|
||||
|
||||
import { scheduleJob, Job, scheduledJobs } from 'node-schedule';
|
||||
import { scheduleJob, Job, } from 'node-schedule';
|
||||
import { PVPConfigModel } from '../db/SystemConfig';
|
||||
import PvpDefenseType, { PvpDefenseModel } from '../db/PvpDefense';
|
||||
import { PVP } from '../pubUtils/dicParam';
|
||||
import { nowSeconds, getAge, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil';
|
||||
import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank, getTodayGuildActivity } from '../pubUtils/data';
|
||||
import { deepCopy, resResult, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { deepCopy, getRandSingleEelm } from '../pubUtils/util';
|
||||
import { getLvByScore } from './pvpService';
|
||||
import { getAllOnlineRoles, getAllServers, initSingleRank, delGuildActivityRank } from './redisService';
|
||||
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME, SEND_NAME, SERVER_OPEN_TIME, COUNTER } from '../consts';
|
||||
import { MAIL_TYPE, REDIS_KEY, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME, SEND_NAME, SERVER_OPEN_TIME, COUNTER } from '../consts';
|
||||
import { RoleModel } from '../db/Role';
|
||||
import { MailModel, MailType } from '../db/Mail';
|
||||
import { pinus } from 'pinus';
|
||||
import { indexOf } from 'underscore';
|
||||
import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
|
||||
import { settleGuildWeekly } from './guildService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { reportOnline } from '../pubUtils/httpUtil';
|
||||
import { UserModel } from '../db/User';
|
||||
import { getGuildActivityByDic, setMedianCe, sendEndMsgToAll, autoDeclare, sendGuildActivityStatus } from './guildActivityService';
|
||||
import { getGuildActivityByDic, sendEndMsgToAll, autoDeclare, sendGuildActivityStatus } from './guildActivityService';
|
||||
import { sendUngotDividendJob, startGuildAuction, startWorldAuction, stopAuction } from './auctionService';
|
||||
import { DicGuildActivity } from '../pubUtils/dictionary/DicGuildActivity';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { dispatch } from '../util/dispatcher';
|
||||
import { Rank } from './rankService';
|
||||
import { checkTask } from './taskService';
|
||||
@@ -30,6 +25,7 @@ import { everydayRefresh } from './connectorService';
|
||||
import { initMarquee, initMaintenance } from './gmService';
|
||||
import moment = require('moment');
|
||||
import { CounterModel } from '../db/Counter';
|
||||
import { reportOneOnline } from './authenticateService';
|
||||
|
||||
const PER_SECOND = 1 * 1000;
|
||||
const PER_DAY = 24 * 60 * 60;
|
||||
@@ -336,56 +332,12 @@ export async function resetPvpRanks() {
|
||||
export async function reportOnlineSchedule() {
|
||||
let allRoles = await getAllOnlineRoles();
|
||||
console.log('reportOnlineSchedule all roles count: ', allRoles.length)
|
||||
for (let { roleId, userCode, sid, pkgName } of allRoles) {
|
||||
let result = reportOneOnline(roleId, userCode, sid, pkgName);
|
||||
for (let { roleId, userCode, sid } of allRoles) {
|
||||
let result = reportOneOnline(roleId, userCode, sid, false);
|
||||
if (!result) continue;
|
||||
}
|
||||
}
|
||||
|
||||
export async function reportOneOnline(roleId: string, userCode: string, sid: string, pkgName: string) {
|
||||
|
||||
let result = await reportOnline(userCode, pkgName); // 连接sdk
|
||||
if (!result || result.code == -1) return false;
|
||||
|
||||
let user = await UserModel.findUserByUserCode(userCode);
|
||||
if (!user) return false;
|
||||
let { reportTime = new Date(), lastLoginTime = new Date(), guestTime, isGuest, hasAuthenticated, birthday } = user;
|
||||
|
||||
let age = getAge(birthday);
|
||||
let isAdult = age >= ADULT_AGE;
|
||||
|
||||
if (isGuest || !hasAuthenticated) {
|
||||
let lastTime = lastLoginTime > reportTime ? lastLoginTime.getTime() : reportTime.getTime();
|
||||
let guestTimeInc = Math.floor((Date.now() - lastTime) / 1000);
|
||||
user = await UserModel.updatePlayTime(userCode, guestTimeInc, result.total); // 记录时间
|
||||
|
||||
guestTime = user.guestTime;
|
||||
|
||||
if (guestTime > GUEST_MAX_TIME) {
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest,
|
||||
guestTime, // 游客已体验时间
|
||||
hasAuthenticated, // 是否进行过实名认证
|
||||
isAdult, // 是否已成年
|
||||
todayPlayTime: result.total, // 今天已游戏时长
|
||||
type: ADDICTION_PREVENTION_CODE.GUEST,
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
}
|
||||
} else {
|
||||
if (result.code != ADDICTION_PREVENTION_CODE.SUCCESS && result.age != -1) { // 未成年人防沉迷
|
||||
user = await UserModel.updatePlayTime(userCode, 0, result.total, result.code); // 记录时间
|
||||
|
||||
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
|
||||
isGuest,
|
||||
guestTime, // 游客已体验时间
|
||||
hasAuthenticated, // 是否进行过实名认证
|
||||
isAdult, // 是否已成年
|
||||
todayPlayTime: result.total, // 今天已游戏时长
|
||||
type: result.code
|
||||
}), [{ uid: roleId, sid: sid }]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 军团活动,每晚8点开启
|
||||
|
||||
Reference in New Issue
Block a user