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;
@Opcodes(PacketOpcodes.SetPlayerBirthdayReq)
public class HandlerSetPlayerBirthdayReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload);
@Override
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();
int month = req.getBirthday().getMonth();
// RET_BIRTHDAY_CANNOT_BE_SET_TWICE = 7009
if (session.getPlayer().hasBirthday()) {
session.send(new PacketSetPlayerBirthdayRsp(7009));
return;
}
// Update birthday value
session.getPlayer().setBirthday(day, month);
int month = req.getBirthday().getMonth();
int day = req.getBirthday().getDay();
// Save birthday month and day
session.getPlayer().save();
SocialDetail.Builder detail = session.getPlayer().getSocialDetail();
// RET_BIRTHDAY_FORMAT_ERROR = 7022
if (!isValidBirthday(month, day)) {
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;
import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp;
public class PacketSetPlayerBirthdayRsp extends GenshinPacket {
public PacketSetPlayerBirthdayRsp(GenshinPlayer player) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
.setBirthday(player.getBirthday().toProto())
.build();
public PacketSetPlayerBirthdayRsp(int retCode) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
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