From 8afa624f44797d1e1707a23dade2cc995848e331 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Thu, 4 Jan 2024 15:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E6=9C=8D=E8=81=8A=E5=A4=A9=E5=88=86?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/chat/ApiSend.ts | 4 +++- src/public/chat.ts | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/api_s2c/chat/ApiSend.ts b/src/api_s2c/chat/ApiSend.ts index 4d182d0..7ae9a4c 100644 --- a/src/api_s2c/chat/ApiSend.ts +++ b/src/api_s2c/chat/ApiSend.ts @@ -1,6 +1,6 @@ import { ApiCall, WsClientStatus } from "tsrpc"; import { ActionLog } from '../../public/actionLog/actionLog'; -import { ChatFun } from '../../public/chat'; +import { ChatFun, getCrossChatGroupByOpenDay } from '../../public/chat'; import { ReqSend, ResSend } from "../../shared/protocols/chat/PtlSend"; import { chatMsgLog } from "../../shared/protocols/type" import { getGud } from "../../public/gud"; @@ -40,6 +40,8 @@ export default async function (call: ApiCall) { if (sendData.type == 'cross' && G.clientCross?.status == WsClientStatus.Opened) { //如果是跨服的话,调用跨服API的这条协议 + sendData.otherData.group = getCrossChatGroupByOpenDay(); + G.clientCross.sendMsg('msg_cross/CrossChat', sendData); call.succ({}); return; diff --git a/src/public/chat.ts b/src/public/chat.ts index d0e2286..877f6fd 100644 --- a/src/public/chat.ts +++ b/src/public/chat.ts @@ -3,6 +3,7 @@ import { ApiCall } from 'tsrpc'; import { MsgChat } from '../shared/protocols/msg_s2c/MsgChat'; import { player } from '../shared/protocols/user/type'; import { chatLog, chatMsgLog } from '../shared/protocols/type' +import { PublicShared } from '../shared/public/public'; const msgListLen = { 'cross': 30, @@ -10,6 +11,20 @@ const msgListLen = { 'guild': 20 }; +/** + * 通过开服天数,获取跨服聊天分组 + */ +export function getCrossChatGroupByOpenDay(){ + let openday = PublicShared.getOpenServerDay(); + if(openday<=7){ + return 1; + }else if(openday <= 30){ + return 2; + }else{ + return 3; + } +} + export class ChatFun { /**新增消息 */ static async newMsg(sendData: MsgChat) { @@ -23,7 +38,11 @@ export class ChatFun { G.server.broadcastClusterMsg('msg_s2c/Chat', sendData,{ghId:(sendData.sender as player)?.ghId}); }else if(sendData.type == 'cross'){ //所有的子进程都会收到,不需要集群内分别广播 - G.server.broadcastMsg('msg_s2c/Chat', sendData); + if(sendData?.otherData?.group == getCrossChatGroupByOpenDay()){ + //如果时候同一个分组的 + delete sendData?.otherData?.group; + G.server.broadcastMsg('msg_s2c/Chat', sendData); + } }else{ G.server.broadcastClusterMsg('msg_s2c/Chat', sendData); }