Compare commits

...

4 Commits

3 changed files with 91 additions and 53 deletions

View File

@ -1,18 +1,23 @@
import { ApiCall } from "tsrpc"; import {ApiCall} from "tsrpc";
import { ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser } from "../../cross/protocols/hbzb/PtlUpdateHbzbCrossUser"; import {ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser} from "../../cross/protocols/hbzb/PtlUpdateHbzbCrossUser";
/**更新跨服数据库里,黑帮争霸的玩家数据 */ /**更新跨服数据库里,黑帮争霸的玩家数据 */
export default async function (call: ApiCall<ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser>) { export default async function (call: ApiCall<ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser>) {
let setData = { let setData: any = {
"data":{ "data": {
player: call.req.user.player, player: call.req.user.player,
roles: call.req.user.roles, roles: call.req.user.roles,
uid: call.req.uid uid: call.req.uid
}, },
"jifen": -999999,
"rank": -999999,
"zbsgroup":""
}; };
G.mongodb.collection('hbzb_user_cross').updateOne({ uid: setData.data.uid }, { $set: setData }, { upsert: true }); if (call.req.isNew) {
call.succ({ }); setData = {
...setData,
"jifen": -999999,
"rank": -999999,
"zbsgroup": ""
}
}
G.mongodb.collection('hbzb_user_cross').updateOne({uid: setData.data.uid}, {$set: setData}, {upsert: true});
call.succ({});
} }

View File

@ -1,18 +1,16 @@
import { ApiCall } from "tsrpc"; import {ApiCall} from "tsrpc";
import { Rank } from '../../../public/rank/rank'; import {Rank} from '../../../public/rank/rank';
import { ReqOpen, ResOpen } from "../../../shared/protocols/hbzb/jfs/PtlOpen"; import {ReqOpen, ResOpen} from "../../../shared/protocols/hbzb/jfs/PtlOpen";
import { PublicShared } from '../../../shared/public/public'; import {PublicShared} from '../../../shared/public/public';
import { getHbzbData, getMyRank, getToper200RankUid, updateHbzbCrossUser } from "./fun"; import {getHbzbData, getMyRank, getToper200RankUid, updateHbzbCrossUser} from "./fun";
export default async function (call: ApiCall<ReqOpen, ResOpen>) { export default async function (call: ApiCall<ReqOpen, ResOpen>) {
//查看本地数据库里,刷出来的玩家数据 //查看本地数据库里,刷出来的玩家数据
let dbData = await getHbzbData(call.uid ); let dbData = await getHbzbData(call.uid);
let data: typeof dbData.data = dbData?.data || {} as any; let data: typeof dbData.data = dbData?.data || {} as any;
if (dbData == null) { //如果没有,则同步到跨服
//如果没有,则同步到跨服 await updateHbzbCrossUser(await call.conn.getDefaultFightData(), dbData == null);
await updateHbzbCrossUser(await call.conn.getDefaultFightData(), true);
}
if (!data.refreshTime || data.refreshTime < PublicShared.getToDayZeroTime()) { if (!data.refreshTime || data.refreshTime < PublicShared.getToDayZeroTime()) {
data.winNum = 0; data.winNum = 0;
@ -26,19 +24,21 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
//积分赛时的排行榜,是本服积分排序 //积分赛时的排行榜,是本服积分排序
data.jifen = 0; data.jifen = 0;
//但是刷出来的对手,是跨服的玩家 //但是刷出来的对手,是跨服的玩家
let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', { uid: call.uid, auto: true }); let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', {uid: call.uid, auto: true});
if (!callRes.isSucc){ if (!callRes.isSucc) {
//todo 健壮性处理 //todo 健壮性处理
return call.errorCode(-4) return call.errorCode(-4)
} }
if (callRes.res.enemy.length) if (callRes.res.enemy.length)
data.enemy = callRes.res.enemy.map(e => { return { ...e, result: null }; }); data.enemy = callRes.res.enemy.map(e => {
return {...e, result: null};
});
} }
G.mongodb.cPlayerInfo('hbzb').updateOne( G.mongodb.cPlayerInfo('hbzb').updateOne(
{ uid: call.uid, type: 'hbzb' }, {uid: call.uid, type: 'hbzb'},
{ $set: { data: data } }, {$set: {data: data}},
{ upsert: true } {upsert: true}
); );
} }

View File

@ -21,34 +21,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
color[heroCon[v.heroId].colour] += 1; color[heroCon[v.heroId].colour] += 1;
}); });
// 修复配件数据 await checkDataAndFix(call, list)
let peijianids = [];
Object.values(list).map(hero => {
hero.peijian && Object.values(hero.peijian).map(
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
)
});
let peijians = (await G.mongodb.collection("peijian").find(
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
let changes = {};
Object.values(list).map(hero => {
for (let pos in hero.peijian) {
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
hero.peijian[pos] = "";
changes[hero._id] = hero.peijian;
}
}
})
for (let oid in changes) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: changes[oid]}}
)
}
// 记录玩家最大等级,颜色相关数据 注册任务用 // 记录玩家最大等级,颜色相关数据 注册任务用
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'}, await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'},
@ -69,3 +42,63 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({uid: call.uid, type: 'gbzj'}))?.rec || {} gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({uid: call.uid, type: 'gbzj'}))?.rec || {}
}); });
} }
/**
*
* @param call
* @param list
*/
async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
try {
// 修复配件数据
let peijianids = [];
Object.values(list).map(hero => {
hero.peijian && Object.values(hero.peijian).map(
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
)
});
let peijians = (await G.mongodb.collection("peijian").find(
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
let shiwuIds = R.flatten(R.values(list).map(hero => R.values(hero.shiwu).map(i => G.mongodb.conversionId(i._id))))
let shiwus = (await G.mongodb.collection("shiwu").find(
{uid: call.uid, _id: {$in: shiwuIds}}, {projection: {_id: 1}}
).toArray()).map(i => G.mongodb.conversionId(i._id));
let peijianChanges = {};
let shiwuChanges = {};
Object.values(list).map(hero => {
for (let pos in hero.peijian) {
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
hero.peijian[pos] = "";
peijianChanges[hero._id] = hero.peijian;
}
}
for (let pos in hero.shiwu) {
if (!shiwus.includes(hero.shiwu[pos]._id)) {
hero.shiwu = R.omit([pos], hero.shiwu)
shiwuChanges[hero._id] = hero.shiwu;
}
}
})
for (let oid in peijianChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
)
}
for (let oid in shiwuChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {shiwu: shiwuChanges[oid]}}
)
}
} catch (e) {
console.log('======修复英雄配件和饰物报错====',e)
}
}