From 7e6b20de1a42d1e86027c5275cd24b93ea8738bd Mon Sep 17 00:00:00 2001 From: BaiSugar <97774724+BaiSugar@users.noreply.github.com> Date: Sat, 30 Apr 2022 00:20:46 +0800 Subject: [PATCH] Added interface display for multiplayer games (#360) --- .../command/commands/GiveAllCommand.java | 3 ++ .../recv/HandlerGetOnlinePlayerListReq.java | 15 ++++++ .../send/PacketGetOnlinePlayerListRsp.java | 53 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerGetOnlinePlayerListReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index 94437e0e2..cdf2adbc1 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -83,6 +83,9 @@ public class GiveAllCommand implements CommandHandler { Avatar avatar = new Avatar(avatarData); avatar.setLevel(90); avatar.setPromoteLevel(6); + for(int i = 1;i <= 6;++i){ + avatar.getTalentIdList().add((avatar.getAvatarId()-10000000)*10+i); + } // This will handle stats and talents avatar.recalcStats(); player.addAvatar(avatar); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetOnlinePlayerListReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetOnlinePlayerListReq.java new file mode 100644 index 000000000..16dc591d5 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerGetOnlinePlayerListReq.java @@ -0,0 +1,15 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketGetOnlinePlayerListRsp; + +@Opcodes(PacketOpcodes.GetOnlinePlayerListReq) +public class HandlerGetOnlinePlayerListReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + session.send(new PacketGetOnlinePlayerListRsp(session.getPlayer())); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java new file mode 100644 index 000000000..85cf5429e --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetOnlinePlayerListRsp.java @@ -0,0 +1,53 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.game.player.Player; +import emu.grasscutter.net.packet.BasePacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.GetOnlinePlayerListReqOuterClass; +import emu.grasscutter.net.proto.GetOnlinePlayerListRspOuterClass.*; +import emu.grasscutter.net.proto.MpSettingTypeOuterClass; +import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo; +import emu.grasscutter.net.proto.ProfilePictureOuterClass.ProfilePicture; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class PacketGetOnlinePlayerListRsp extends BasePacket { + public PacketGetOnlinePlayerListRsp(Player session){ + super(PacketOpcodes.GetOnlinePlayerListRsp); + Map playersMap = Grasscutter.getGameServer().getPlayers(); + GetOnlinePlayerListRsp.Builder proto = GetOnlinePlayerListRsp.newBuilder(); + if(playersMap.size() != 0){ + List playerInfoList = new ArrayList<>(); + + for(Player player:playersMap.values()){ + ProfilePicture.Builder picture = ProfilePicture.newBuilder(); + OnlinePlayerInfo.Builder playerInfo = OnlinePlayerInfo.newBuilder(); + + if(player.getUid() == session.getUid())continue; + picture.setAvatarId(player.getProfile().getAvatarId()) + .build(); + System.out.println(player.getHeadImage()); + playerInfo.setUid(player.getUid()) + .setNickname(player.getNickname()) + .setPlayerLevel(player.getLevel()) + .setMpSettingType(MpSettingTypeOuterClass.MpSettingType.MP_SETTING_ENTER_AFTER_APPLY) + .setCurPlayerNumInWorld(player.getWorld().getPlayerCount()) + .setWorldLevel(player.getWorldLevel()) + .setNameCardId(player.getNameCardId()) + .setProfilePicture(picture); + if(!Objects.equals(player.getSignature(), "")){ + playerInfo.setSignature(player.getSignature()); + } + playerInfoList.add(playerInfo.build()); + } + for (OnlinePlayerInfo onlinePlayerInfo : playerInfoList) { + proto.addPlayerInfoList(onlinePlayerInfo).build(); + } + } + this.setData(proto); + } +}