Commit 4e5d72a9 authored by Asnxthaony's avatar Asnxthaony Committed by Melledy
Browse files

sanity check

parent 122568ad
...@@ -11,23 +11,57 @@ import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp; ...@@ -11,23 +11,57 @@ import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp;
@Opcodes(PacketOpcodes.SetPlayerBirthdayReq) @Opcodes(PacketOpcodes.SetPlayerBirthdayReq)
public class HandlerSetPlayerBirthdayReq extends PacketHandler { public class HandlerSetPlayerBirthdayReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload); SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload);
if (req.getBirthday().getDay() > 0 && req.getBirthday().getMonth() > 0) { // RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009
int day = req.getBirthday().getDay(); if (session.getPlayer().hasBirthday()) {
int month = req.getBirthday().getMonth(); session.send(new PacketSetPlayerBirthdayRsp(7009));
return;
}
// Update birthday value int month = req.getBirthday().getMonth();
session.getPlayer().setBirthday(day, month); int day = req.getBirthday().getDay();
// Save birthday month and day // RET_BIRTHDAY_FORMAT_ERROR = 7022
session.getPlayer().save(); if (!isValidBirthday(month, day)) {
SocialDetail.Builder detail = session.getPlayer().getSocialDetail(); session.send(new PacketSetPlayerBirthdayRsp(7022));
return;
}
// Update birthday value
session.getPlayer().setBirthday(day, month);
// Save birthday month and day
session.getPlayer().save();
SocialDetail.Builder detail = session.getPlayer().getSocialDetail();
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;
}
session.send(new PacketSetPlayerBirthdayRsp(session.getPlayer()));
session.send(new PacketGetPlayerSocialDetailRsp(detail));
}
}
} }
...@@ -6,13 +6,24 @@ import emu.grasscutter.net.packet.PacketOpcodes; ...@@ -6,13 +6,24 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp; import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp;
public class PacketSetPlayerBirthdayRsp extends GenshinPacket { public class PacketSetPlayerBirthdayRsp extends GenshinPacket {
public PacketSetPlayerBirthdayRsp(GenshinPlayer player) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder() public PacketSetPlayerBirthdayRsp(int retCode) {
.setBirthday(player.getBirthday().toProto()) super(PacketOpcodes.SetPlayerBirthdayRsp);
.build();
this.setData(proto); SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
} .setRetcode(retCode)
.build();
this.setData(proto);
}
public PacketSetPlayerBirthdayRsp(GenshinPlayer player) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
.setBirthday(player.getBirthday().toProto())
.build();
this.setData(proto);
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment