diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 68ca52d..5ffa6d7 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -45,9 +45,13 @@ export default class AccountController extends BaseController { } return result } - @router('get /svr/:accountid/uinfo') + @router('post /svr/:accountid/uinfo') async simpleInfo(req: any) { let account = req.user + let {isMatch} = req.params + if (isMatch) { + await setGameing(account._id, 15 * 60) + } return { accountid: account._id, nickname: account.nickname, @@ -92,7 +96,7 @@ export default class AccountController extends BaseController { account.isnew = 0 await account.save() } - await setGameing(accountid) + await setGameing(accountid, 30) return { accountid: account._id, nickname: account.nickname, diff --git a/src/controllers/MatchController.ts b/src/controllers/MatchController.ts index 15d56ad..fe9c9c7 100644 --- a/src/controllers/MatchController.ts +++ b/src/controllers/MatchController.ts @@ -4,6 +4,7 @@ import { BaseConst } from '../constants/BaseConst' import { ZError } from '../common/ZError' import { MatchCfg } from '../cfg/parsers/MatchCfg' import { BagItem } from '../models/BagItem' +import { checkGameing, setGameing } from '../service/rank' export default class MatchController extends BaseController { @@ -14,6 +15,10 @@ export default class MatchController extends BaseController { if (!cfg || !cfg.consume) { throw new ZError(10, 'match not found') } + let gameing = await checkGameing(accountid) + if (gameing) { + throw new ZError(12, 'gameing') + } let itemObj = cfg.consume.split(':') let itemid: number = parseInt(itemObj[0]) let count: number = parseInt(itemObj[1]) @@ -28,4 +33,5 @@ export default class MatchController extends BaseController { await record.save() return {} } + } diff --git a/src/controllers/RecordController.ts b/src/controllers/RecordController.ts index 2301b9b..e18e515 100644 --- a/src/controllers/RecordController.ts +++ b/src/controllers/RecordController.ts @@ -9,7 +9,7 @@ import { MatchCfg } from '../cfg/parsers/MatchCfg' import ItemCtrl from '../logic/ItemCtrl' import { ItemInfo } from '../logic/ItemDef' import { BagItem } from '../models/BagItem' -import { updateRank } from '../service/rank' +import { setGameEnd, updateRank } from '../service/rank' export default class RecordController extends BaseController { @role('anon') @@ -56,7 +56,7 @@ export default class RecordController extends BaseController { error(`save game record, account not found: ${ player.accountid }`) continue } - + await setGameEnd(player.accountid) user.season_score = Math.max((user.season_score + player.scoreChange) | 0, fc.get(70002).number) await updateRank(user._id, user.season_score) if (!user.season_data) { diff --git a/src/redis/RedisClient.ts b/src/redis/RedisClient.ts index e5e8170..ca0ef3e 100644 --- a/src/redis/RedisClient.ts +++ b/src/redis/RedisClient.ts @@ -95,6 +95,11 @@ export class RedisClient { this.pub.setex(key, seconds, value, resolve)); } + public async expire(key: string, seconds: number) { + return new Promise((resolve) => + this.pub.expire(key, seconds, resolve)); + } + public async get(key: string) { return new Promise((resolve, reject) => { this.pub.get(key, (err, data) => { diff --git a/src/service/rank.ts b/src/service/rank.ts index 5ab0b51..22b291b 100644 --- a/src/service/rank.ts +++ b/src/service/rank.ts @@ -27,12 +27,16 @@ export async function usersByScore(min: number, max: number) { /** * 设置在游戏中的状态 * @param {string} accountid + * @param seconds * @return {Promise} */ -export async function setGameing(accountid: string) { - await new RedisClient().setex('gameing_' + accountid, (Date.now() / 1000 | 0) + '', 30) +export async function setGameing(accountid: string, seconds: number) { + await new RedisClient().setex('gameing_' + accountid, (Date.now() / 1000 | 0) + '', seconds) } +export async function setGameEnd(accountid: string) { + await new RedisClient().expire('gameing_' + accountid, 0) +} /** * 检查是否在游戏中 * @param {string} accountid