diff --git a/src/api/controllers/puzzle.controller.ts b/src/api/controllers/puzzle.controller.ts index 4b02145..582403b 100644 --- a/src/api/controllers/puzzle.controller.ts +++ b/src/api/controllers/puzzle.controller.ts @@ -29,6 +29,7 @@ import { } from '../../services/GameLogic' import { Shop, validShopId } from '../../models/shop/Shop' import { ShopActivity } from '../../models/shop/ShopActivity' +import { GameUser } from '../../models/GameUser' class PuzzleController extends BaseController { @@ -226,6 +227,11 @@ class PuzzleController extends BaseController { } let activity = await ShopActivity.findById(aid) let shopData = await Shop.fetchByID(shop) + let gameUser = await GameUser.getByAccountID(accountid) + if (gameUser) { + data.nickname = gameUser.nickname + data.avatar = gameUser.avatar + } shop = shopData.id if (!activity) { throw new ZError(13, 'activity not found') @@ -243,7 +249,7 @@ class PuzzleController extends BaseController { beginTime = history.begin sessionMatch = history.id if (!history.members.has(accountid)) { - let rsp = await joinRoom({roomId: history.room}) + let rsp = await joinRoom(Object.assign(data, {roomId: history.room})) if (rsp.status != 200) { new RoomState().unlock(shop) throw new ZError(11, 'error create room') diff --git a/src/models/GameUser.ts b/src/models/GameUser.ts index 14e3f29..4637a28 100644 --- a/src/models/GameUser.ts +++ b/src/models/GameUser.ts @@ -3,7 +3,7 @@ import { getModelForClass, index, modelOptions, - prop + prop, ReturnModelType } from '@typegoose/typegoose' import { BaseModule } from './Base' @@ -39,7 +39,10 @@ class GameUserClass extends BaseModule { @prop() public lockedTime?: Date; - + public static async getByAccountID(this: ReturnModelType, accountId: string) { + let records = await this.find({accountId}).limit(1) + return records.length > 0 ? records[0] : null + } } export const GameUser = getModelForClass(GameUserClass, {existingConnection: GameUserClass.db}); diff --git a/src/services/WsSvr.ts b/src/services/WsSvr.ts index 343ade4..713a4df 100644 --- a/src/services/WsSvr.ts +++ b/src/services/WsSvr.ts @@ -172,6 +172,26 @@ export async function updateScore(roomId: string, data: any) { }) } +/** + * 更新用户信息 + * @param {string} roomId + * @param data + */ +export async function updateInfo(roomId: string, data: any) { + console.log(`updateInfo: ${roomId}, ${JSON.stringify(data)}`) + const url = `${apiBase}/room/call` + const args = [data] + const params = { + roomId, + method: 'updatePlayerInfo', + args: JSON.stringify(args) + } + return axios.post(url, params) + .then(res => { + return res.data + }) +} + /** * 更新游戏轮数 * @param {string} roomId