匹配游戏中途退出, 无法在此进入游戏
This commit is contained in:
parent
4ebf1c3626
commit
0f719d4bd1
@ -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,
|
||||
|
@ -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 {}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) => {
|
||||
|
@ -27,12 +27,16 @@ export async function usersByScore(min: number, max: number) {
|
||||
/**
|
||||
* 设置在游戏中的状态
|
||||
* @param {string} accountid
|
||||
* @param seconds
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user