Commit dce13cf6 authored by Magix's avatar Magix Committed by GitHub
Browse files

Merge branch 'development' into plugin-system

parents 832c460a b6fedcf2
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp;
import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBirthdayReqOuterClass.SetPlayerBirthdayReq;
import com.google.gson.Gson;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp;
import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp;
@Opcodes(PacketOpcodes.SetPlayerBirthdayReq)
public class HandlerSetPlayerBirthdayReq extends PacketHandler {
......@@ -19,10 +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.getBirth() != null && req.getBirth().getDay() > 0 && req.getBirth().getMonth() > 0)
{
int day = req.getBirth().getDay();
int month = req.getBirth().getMonth();
// 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);
......@@ -34,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;
}
}
package emu.grasscutter.server.packet.recv;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.common.RewardItemData;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp;
@Opcodes(PacketOpcodes.TakePlayerLevelRewardReq)
public class HandlerTakePlayerLevelRewardReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
TakePlayerLevelRewardReq req = TakePlayerLevelRewardReq.parseFrom(payload);
int level = req.getLevel();
int rewardId = GenshinData.getPlayerLevelDataMap().get(level).getRewardId();
if (rewardId != 0) {
List<RewardItemData> rewardItems = GenshinData.getRewardDataMap().get(rewardId).getRewardItemList();
List<GenshinItem> items = new LinkedList<>();
for (RewardItemData rewardItem : rewardItems) {
if (rewardItem != null) {
if (rewardItem.getItemId() != 0) {
items.add(new GenshinItem(rewardItem.getItemId(), rewardItem.getItemCount()));
}
}
}
session.getPlayer().getInventory().addItems(items);
session.getPlayer().sendPacket(new PacketItemAddHintNotify(items, ActionReason.PlayerUpgradeReward));
Set<Integer> rewardedLevels = session.getPlayer().getRewardedLevels();
rewardedLevels.add(level);
session.getPlayer().setRewardedLevels(rewardedLevels);
}
session.send(new PacketTakePlayerLevelRewardRsp(level, rewardId));
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.props.FetterState;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarFetterDataNotifyOuterClass.AvatarFetterDataNotify;
import emu.grasscutter.net.proto.AvatarFetterInfoOuterClass.AvatarFetterInfo;
import emu.grasscutter.net.proto.FetterDataOuterClass.FetterData;
public class PacketAvatarFetterDataNotify extends GenshinPacket {
public PacketAvatarFetterDataNotify(GenshinAvatar avatar) {
super(PacketOpcodes.AvatarFetterDataNotify);
int fetterLevel = avatar.getFetterLevel();
AvatarFetterInfo.Builder avatarFetter = AvatarFetterInfo.newBuilder()
.setExpLevel(avatar.getFetterLevel());
if (fetterLevel != 10) {
avatarFetter.setExpNumber(avatar.getFetterExp());
}
if (avatar.getFetterList() != null) {
for (int i = 0; i < avatar.getFetterList().size(); i++) {
avatarFetter.addFetterList(
FetterData.newBuilder()
.setFetterId(avatar.getFetterList().get(i))
.setFetterState(FetterState.FINISH.getValue())
);
}
}
int cardId = avatar.getNameCardId();
if (avatar.getPlayer().getNameCardList().contains(cardId)) {
avatarFetter.addRewardedFetterLevelList(10);
}
AvatarFetterInfo avatarFetterInfo = avatarFetter.build();
AvatarFetterDataNotify proto = AvatarFetterDataNotify.newBuilder()
.putFetterInfoMap(avatar.getGuid(), avatarFetterInfo)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AvatarFetterLevelRewardRspOuterClass.AvatarFetterLevelRewardRsp;
public class PacketAvatarFetterLevelRewardRsp extends GenshinPacket {
public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel, int rewardId) {
super(PacketOpcodes.AvatarFetterLevelRewardRsp);
AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder()
.setAvatarGuid(guid)
.setFetterLevel(fetterLevel)
.setRetcode(0)
.setRewardId(rewardId)
.build();
this.setData(proto);
}
public PacketAvatarFetterLevelRewardRsp(long guid, int fetterLevel) {
super(PacketOpcodes.AvatarFetterLevelRewardRsp);
AvatarFetterLevelRewardRsp proto = AvatarFetterLevelRewardRsp.newBuilder()
.setAvatarGuid(guid)
.setFetterLevel(fetterLevel)
.setRetcode(1)
.setRewardId(0)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import java.util.Set;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerLevelRewardUpdateNotifyOuterClass.PlayerLevelRewardUpdateNotify;
public class PacketPlayerLevelRewardUpdateNotify extends GenshinPacket {
public PacketPlayerLevelRewardUpdateNotify(Set<Integer> rewardedLevels) {
super(PacketOpcodes.PlayerLevelRewardUpdateNotify);
PlayerLevelRewardUpdateNotify.Builder proto = PlayerLevelRewardUpdateNotify.newBuilder();
for (Integer level : rewardedLevels) {
proto.addLevelList(level);
}
this.setData(proto.build());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
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);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
.setBirth(player.getBirthday().toProto())
.setBirthday(player.getBirthday().toProto())
.build();
this.setData(proto);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp;
public class PacketTakePlayerLevelRewardRsp extends GenshinPacket {
public PacketTakePlayerLevelRewardRsp(int level, int rewardId) {
super(PacketOpcodes.TakePlayerLevelRewardRsp);
int retcode = 0;
if (rewardId == 0) {
retcode = 1;
}
TakePlayerLevelRewardRsp proto = TakePlayerLevelRewardRsp.newBuilder()
.setLevel(level)
.setRewardId(rewardId)
.setRetcode(retcode)
.build();
this.setData(proto);
}
}
......@@ -74,10 +74,11 @@ for /f "tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVe
@rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1
echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs"
if not "%MITMDUMP_PATH%" == "" (
echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs"
echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs"
)
echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k",0 >> "%temp%\proxy.vbs"
echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%CUR_PATH%%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k --allow-hosts "^&chr(34)^&".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com"^&chr(34),0 >> "%temp%\proxy.vbs"
"%temp%\proxy.vbs"
del /f /q "%temp%\proxy.vbs" >nul 2>nul
......
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