Fix the chat history not correctly showing.

This commit is contained in:
kyoko
2022-06-12 11:37:44 +08:00
committed by Luke H-W
parent 38107326a1
commit 80f9346983
8 changed files with 189 additions and 48 deletions

View File

@@ -13,8 +13,10 @@ public class HandlerPullPrivateChatReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
PullPrivateChatReq req = PullPrivateChatReq.parseFrom(payload);
session.getServer().getChatManager().handlePullPrivateChatReq(session.getPlayer(), req.getTargetUid());
session.send(new PacketPullPrivateChatRsp());
// session.send(new PacketPullPrivateChatRsp(req.getTargetUid()));
}
}

View File

@@ -10,6 +10,6 @@ import emu.grasscutter.server.packet.send.PacketPullRecentChatRsp;
public class HandlerPullRecentChatReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
session.send(new PacketPullRecentChatRsp(session.getPlayer()));
session.getServer().getChatManager().handlePullRecentChatReq(session.getPlayer());
}
}

View File

@@ -6,6 +6,8 @@ import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo;
import emu.grasscutter.net.proto.PrivateChatNotifyOuterClass.PrivateChatNotify;
public class PacketPrivateChatNotify extends BasePacket {
private ChatInfo info;
public PacketPrivateChatNotify(int senderId, int recvId, String message) {
super(PacketOpcodes.PrivateChatNotify);
@@ -15,7 +17,8 @@ public class PacketPrivateChatNotify extends BasePacket {
.setToUid(recvId)
.setText(message)
.build();
this.info = info;
PrivateChatNotify proto = PrivateChatNotify.newBuilder()
.setChatInfo(info)
.build();
@@ -32,6 +35,7 @@ public class PacketPrivateChatNotify extends BasePacket {
.setToUid(recvId)
.setIcon(emote)
.build();
this.info = info;
PrivateChatNotify proto = PrivateChatNotify.newBuilder()
.setChatInfo(info)
@@ -39,4 +43,8 @@ public class PacketPrivateChatNotify extends BasePacket {
this.setData(proto);
}
public ChatInfo getChatInfo() {
return this.info;
}
}

View File

@@ -1,16 +1,29 @@
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ChatInfoOuterClass.ChatInfo;
import emu.grasscutter.net.proto.PullPrivateChatRspOuterClass.PullPrivateChatRsp;
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
public class PacketPullPrivateChatRsp extends BasePacket {
public PacketPullPrivateChatRsp() {
public PacketPullPrivateChatRsp(List<ChatInfo> history) {
super(PacketOpcodes.PullPrivateChatRsp);
PullPrivateChatRsp proto = PullPrivateChatRsp.newBuilder().build();
PullPrivateChatRsp.Builder builder = PullPrivateChatRsp.newBuilder();
if (history == null) {
builder.setRetcode(Retcode.RET_FAIL_VALUE);
}
else {
for (var info : history) {
builder.addChatInfo(info);
}
}
this.setData(proto);
this.setData(builder.build());
}
}

View File

@@ -10,33 +10,14 @@ import emu.grasscutter.utils.Utils;
import static emu.grasscutter.Configuration.*;
import java.util.List;
public class PacketPullRecentChatRsp extends BasePacket {
public PacketPullRecentChatRsp(Player player) {
public PacketPullRecentChatRsp(List<ChatInfo> messages) {
super(PacketOpcodes.PullRecentChatRsp);
var joinOptions = GAME_INFO.joinOptions;
PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder();
if (joinOptions.welcomeEmotes != null && joinOptions.welcomeEmotes.length > 0) {
ChatInfo welcomeEmote = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(GameConstants.SERVER_CONSOLE_UID)
.setToUid(player.getUid())
.setIcon(joinOptions.welcomeEmotes[Utils.randomRange(0, joinOptions.welcomeEmotes.length - 1)])
.build();
proto.addChatInfo(welcomeEmote);
}
if (joinOptions.welcomeMessage != null && joinOptions.welcomeMessage.length() > 0) {
ChatInfo welcomeMessage = ChatInfo.newBuilder()
.setTime((int) (System.currentTimeMillis() / 1000))
.setUid(GameConstants.SERVER_CONSOLE_UID)
.setToUid(player.getUid())
.setText(joinOptions.welcomeMessage)
.build();
proto.addChatInfo(welcomeMessage);
}
PullRecentChatRsp.Builder proto = PullRecentChatRsp.newBuilder()
.addAllChatInfo(messages);
this.setData(proto);
}