From b7cd139ed18a4bee9fee5fb7ad2e418b978792ab Mon Sep 17 00:00:00 2001 From: lightings <17062401@qq.com> Date: Wed, 17 May 2023 14:20:01 +0800 Subject: [PATCH] ... --- game-server/app/dao/guildDao.js | 10 +++- .../app/servers/chat/handler/chatHandler.js | 56 ++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/game-server/app/dao/guildDao.js b/game-server/app/dao/guildDao.js index f05293b..6d5f719 100644 --- a/game-server/app/dao/guildDao.js +++ b/game-server/app/dao/guildDao.js @@ -111,7 +111,7 @@ class GuildDao { async getGuildInfo(gId) { const guild = await this.getGuild(gId); if (guild) { - const countmember = await this.countGuildMembers(gId); + const countmember = await this.countGuildMembers(gId); guild.countmember = countmember; return guild; } @@ -171,7 +171,7 @@ class GuildDao { } async kick(uId, mId) { - const ql = "SELECT * FROM t_guild_members WHERE uid=?"; + const ql = "SELECT * FROM t_guild_members WHERE uid=? AND apply=2"; const rl = await query_guild(ql, [uId]); if (rl && rl.length > 0) { const qfm = "SELECT * FROM t_guild_members WHERE uid=? AND apply=2"; @@ -304,6 +304,12 @@ class GuildDao { return false; } + async deleteGuildMember(gId, uId) { + const q = "DELETE FROM t_guild_members WHERE guild_idx=? AND uid=?"; + const r = await query_guild(q, [gId, uId]); + return r != null; + } + async getMemberInfo(guildId, uid) { const query = "SELECT * FROM t_guild_members WHERE guild_idx = ? AND uid = ? AND apply = 2"; diff --git a/game-server/app/servers/chat/handler/chatHandler.js b/game-server/app/servers/chat/handler/chatHandler.js index df1a911..2513efa 100644 --- a/game-server/app/servers/chat/handler/chatHandler.js +++ b/game-server/app/servers/chat/handler/chatHandler.js @@ -232,7 +232,7 @@ class ChatHandler { * @apiParam {String} from 发送者信息 * @apiParam {String} content 聊天内容 * @apiParam {String} contentType 内容类型 - * @apiParam {String} type 聊天类型 [ world | team ] + * @apiParam {String} type 聊天类型 [ world | team | private ] * * @apiSuccessExample {json} Success-Response: * { @@ -325,4 +325,58 @@ class ChatHandler { msg: "User not team member", }); } + + /** @api {post} chat.chatHandler.privateChat privateChat 私聊 + * @apiGroup Chat + * + * @apiParam {String} content 聊天内容 + * @apiParam {String} contentType 内容类型 + * @apiParam {String} targetuid 目标用户ID + * + * @apiSuccess {Number} code 状态码 + * + * @apiSuccessExample {json} Success-Response: + * { + * "code": 200 + * } + * + * @apiErrorExample {json} Error-Response: + * { + * "code": 500, + * "msg": "Failed to private chat." + * } + * + * + */ + async privateChat(msg, session, next) { + const { uid } = session; + const userInfo = session.get("userInfo"); + const senderInfo = { + username: userInfo.name, + account_id: userInfo.account_id, + head_frame: userInfo.head_frame, + head_id: userInfo.head_id, + }; + const content = msg.content; + const contentType = msg.contentType; + const targetuid = msg.targetuid; + const channelId = `privateChannel_${targetuid}`; + + this.gcs.add(channelId, session.uid, session.get("sid"), function () {}); + this.gcs.pushMessage( + "connector", + "onChat", + { + code: Code.OK, + route: "onChat", + from: senderInfo, + content: content, + contentType: contentType, + type: "private", + }, + channelId + ); + + next(null, { code: 200 }); + } }