sanity check

This commit is contained in:
Asnxthaony 2022-04-25 14:51:34 +08:00 committed by Melledy
parent 6350d83ad0
commit 25111ed907
3 changed files with 189 additions and 179 deletions

View File

@ -1,7 +1,5 @@
package emu.grasscutter.game;
import java.util.*;
import dev.morphia.annotations.*;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
@ -23,7 +21,6 @@ import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry;
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
import emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType;
@ -35,34 +32,13 @@ import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.proto.WorldPlayerLocationInfoOuterClass.WorldPlayerLocationInfo;
import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketAbilityInvocationsNotify;
import emu.grasscutter.server.packet.send.PacketAvatarAddNotify;
import emu.grasscutter.server.packet.send.PacketAvatarDataNotify;
import emu.grasscutter.server.packet.send.PacketAvatarGainCostumeNotify;
import emu.grasscutter.server.packet.send.PacketAvatarGainFlycloakNotify;
import emu.grasscutter.server.packet.send.PacketClientAbilityInitFinishNotify;
import emu.grasscutter.server.packet.send.PacketCombatInvocationsNotify;
import emu.grasscutter.server.packet.send.PacketGadgetInteractRsp;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.server.packet.send.PacketOpenStateUpdateNotify;
import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpResultNotify;
import emu.grasscutter.server.packet.send.PacketPlayerDataNotify;
import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import emu.grasscutter.server.packet.send.PacketPlayerPropNotify;
import emu.grasscutter.server.packet.send.PacketPlayerStoreNotify;
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
import emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify;
import emu.grasscutter.server.packet.send.PacketPlayerLevelRewardUpdateNotify;
import emu.grasscutter.server.packet.send.PacketSetNameCardRsp;
import emu.grasscutter.server.packet.send.PacketStoreWeightLimitNotify;
import emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerLocationNotify;
import emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.*;
@Entity(value = "players", useDiscriminator = false)
public class GenshinPlayer {
@Id private int id;
@ -115,7 +91,8 @@ public class GenshinPlayer {
@Transient private final InvokeHandler<AbilityInvokeEntry> abilityInvokeHandler;
@Transient private final InvokeHandler<AbilityInvokeEntry> clientAbilityInitFinishHandler;
@Deprecated @SuppressWarnings({ "rawtypes", "unchecked" }) // Morphia only!
@Deprecated
@SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only!
public GenshinPlayer() {
this.inventory = new Inventory(this);
this.avatars = new AvatarStorage(this);
@ -584,6 +561,7 @@ public class GenshinPlayer {
/**
* Sends a message to another player.
*
* @param sender The sender of the message.
* @param message The message to send.
*/
@ -650,7 +628,7 @@ public class GenshinPlayer {
return onlineInfo.build();
}
public PlayerBirthday getBirthday(){
public PlayerBirthday getBirthday() {
return this.birthday;
}
@ -659,6 +637,10 @@ public class GenshinPlayer {
this.updateProfile();
}
public boolean hasBirthday() {
return this.birthday.getDay() > 0;
}
public Set<Integer> getRewardedLevels() {
return rewardedLevels;
}
@ -668,34 +650,16 @@ public class GenshinPlayer {
}
public SocialDetail.Builder getSocialDetail() {
SocialDetail.Builder social = SocialDetail.newBuilder()
.setUid(this.getUid())
.setAvatar(HeadImage.newBuilder().setAvatarId(this.getHeadImage()))
.setNickname(this.getNickname())
.setSignature(this.getSignature())
.setLevel(this.getLevel())
.setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty())
.setWorldLevel(this.getWorldLevel())
.setUnk1(1)
.setUnk3(1)
.setNameCardId(this.getNameCardId())
.setFinishAchievementNum(0);
SocialDetail.Builder social = SocialDetail.newBuilder().setUid(this.getUid()).setAvatar(HeadImage.newBuilder().setAvatarId(this.getHeadImage())).setNickname(this.getNickname()).setSignature(this.getSignature()).setLevel(this.getLevel()).setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty()).setWorldLevel(this.getWorldLevel()).setUnk1(1).setUnk3(1).setNameCardId(this.getNameCardId()).setFinishAchievementNum(0);
return social;
}
public WorldPlayerLocationInfo getWorldPlayerLocationInfo() {
return WorldPlayerLocationInfo.newBuilder()
.setSceneId(this.getSceneId())
.setPlayerLoc(this.getPlayerLocationInfo())
.build();
return WorldPlayerLocationInfo.newBuilder().setSceneId(this.getSceneId()).setPlayerLoc(this.getPlayerLocationInfo()).build();
}
public PlayerLocationInfo getPlayerLocationInfo() {
return PlayerLocationInfo.newBuilder()
.setUid(this.getUid())
.setPos(this.getPos().toProto())
.setRot(this.getRotation().toProto())
.build();
return PlayerLocationInfo.newBuilder().setUid(this.getUid()).setPos(this.getPos().toProto()).setRot(this.getRotation().toProto()).build();
}
public synchronized void onTick() {
@ -745,7 +709,8 @@ public class GenshinPlayer {
// Make sure these exist
if (this.getTeamManager() == null) {
this.teamManager = new TeamManager(this);
} if (this.getProfile().getUid() == 0) {
}
if (this.getProfile().getUid() == 0) {
this.getProfile().syncWithCharacter(this);
}
@ -810,7 +775,7 @@ public class GenshinPlayer {
}
public enum SceneLoadState {
NONE (0), LOADING (1), INIT (2), LOADED (3);
NONE(0), LOADING(1), INIT(2), LOADED(3);
private final int value;

View File

@ -15,9 +15,20 @@ public class HandlerSetPlayerBirthdayReq extends PacketHandler {
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload);
if (req.getBirthday().getDay() > 0 && req.getBirthday().getMonth() > 0) {
int day = req.getBirthday().getDay();
// RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009
if (session.getPlayer().hasBirthday()) {
session.send(new PacketSetPlayerBirthdayRsp(7009));
return;
}
int month = req.getBirthday().getMonth();
int day = req.getBirthday().getDay();
// RET_BIRTHDAY_FORMAT_ERROR = 7022
if (!isValidBirthday(month, day)) {
session.send(new PacketSetPlayerBirthdayRsp(7022));
return;
}
// Update birthday value
session.getPlayer().setBirthday(day, month);
@ -29,5 +40,28 @@ public class HandlerSetPlayerBirthdayReq extends PacketHandler {
session.send(new PacketSetPlayerBirthdayRsp(session.getPlayer()));
session.send(new PacketGetPlayerSocialDetailRsp(detail));
}
private boolean isValidBirthday(int month, int day) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return day > 0 & day <= 31;
case 4:
case 6:
case 9:
case 11:
return day > 0 && day <= 30;
case 2:
return day > 0 & day <= 29;
}
return false;
}
}

View File

@ -6,6 +6,17 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp;
public class PacketSetPlayerBirthdayRsp extends GenshinPacket {
public PacketSetPlayerBirthdayRsp(int retCode) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
.setRetcode(retCode)
.build();
this.setData(proto);
}
public PacketSetPlayerBirthdayRsp(GenshinPlayer player) {
super(PacketOpcodes.SetPlayerBirthdayRsp);