Commit 9fc8cc1c authored by Kengxxiao's avatar Kengxxiao Committed by GitHub
Browse files

Merge pull request #1 from Grasscutters/development

merge
parents 627a2f1e d1fc8c1f
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WeaponAwakenRspOuterClass.WeaponAwakenRsp;
public class PacketWeaponAwakenRsp extends GenshinPacket {
public class PacketWeaponAwakenRsp extends BasePacket {
public PacketWeaponAwakenRsp(GenshinAvatar avatar, GenshinItem item, GenshinItem feedWeapon, int oldRefineLevel) {
public PacketWeaponAwakenRsp(Avatar avatar, GameItem item, GameItem feedWeapon, int oldRefineLevel) {
super(PacketOpcodes.WeaponAwakenRsp);
WeaponAwakenRsp.Builder proto = WeaponAwakenRsp.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WeaponPromoteRspOuterClass.WeaponPromoteRsp;
public class PacketWeaponPromoteRsp extends GenshinPacket {
public class PacketWeaponPromoteRsp extends BasePacket {
public PacketWeaponPromoteRsp(GenshinItem item, int oldPromoteLevel) {
public PacketWeaponPromoteRsp(GameItem item, int oldPromoteLevel) {
super(PacketOpcodes.WeaponPromoteRsp);
WeaponPromoteRsp proto = WeaponPromoteRsp.newBuilder()
......
......@@ -2,15 +2,15 @@ package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.net.proto.WeaponUpgradeRspOuterClass.WeaponUpgradeRsp;
public class PacketWeaponUpgradeRsp extends GenshinPacket {
public class PacketWeaponUpgradeRsp extends BasePacket {
public PacketWeaponUpgradeRsp(GenshinItem item, int oldLevel, List<ItemParam> leftoverOres) {
public PacketWeaponUpgradeRsp(GameItem item, int oldLevel, List<ItemParam> leftoverOres) {
super(PacketOpcodes.WeaponUpgradeRsp);
WeaponUpgradeRsp proto = WeaponUpgradeRsp.newBuilder()
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WearEquipRspOuterClass.WearEquipRsp;
public class PacketWearEquipRsp extends GenshinPacket {
public class PacketWearEquipRsp extends BasePacket {
public PacketWearEquipRsp(long avatarGuid, long equipGuid) {
super(PacketOpcodes.WearEquipRsp);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.World;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PropValueOuterClass.PropValue;
import emu.grasscutter.net.proto.WorldDataNotifyOuterClass.WorldDataNotify;
public class PacketWorldDataNotify extends GenshinPacket {
public class PacketWorldDataNotify extends BasePacket {
public PacketWorldDataNotify(World world) {
super(PacketOpcodes.WorldDataNotify);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType;
import emu.grasscutter.net.proto.WorldPlayerDieNotifyOuterClass.WorldPlayerDieNotify;
public class PacketWorldPlayerDieNotify extends GenshinPacket {
public class PacketWorldPlayerDieNotify extends BasePacket {
public PacketWorldPlayerDieNotify(PlayerDieType playerDieType, int killerId) {
super(PacketOpcodes.WorldPlayerDieNotify);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.World;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WorldPlayerInfoNotifyOuterClass.WorldPlayerInfoNotify;
public class PacketWorldPlayerInfoNotify extends GenshinPacket {
public class PacketWorldPlayerInfoNotify extends BasePacket {
public PacketWorldPlayerInfoNotify(World world) {
super(PacketOpcodes.WorldPlayerInfoNotify);
......@@ -14,7 +14,7 @@ public class PacketWorldPlayerInfoNotify extends GenshinPacket {
WorldPlayerInfoNotify.Builder proto = WorldPlayerInfoNotify.newBuilder();
for (int i = 0; i < world.getPlayers().size(); i++) {
GenshinPlayer p = world.getPlayers().get(i);
Player p = world.getPlayers().get(i);
proto.addPlayerInfoList(p.getOnlinePlayerInfo());
proto.addPlayerUidList(p.getUid());
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.World;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WorldPlayerLocationNotifyOuterClass.WorldPlayerLocationNotify;
public class PacketWorldPlayerLocationNotify extends GenshinPacket {
public class PacketWorldPlayerLocationNotify extends BasePacket {
public PacketWorldPlayerLocationNotify(World world) {
super(PacketOpcodes.WorldPlayerLocationNotify);
WorldPlayerLocationNotify.Builder proto = WorldPlayerLocationNotify.newBuilder();
for (GenshinPlayer p : world.getPlayers()) {
proto.addPlayerLocList(p.getWorldPlayerLocationInfo());
for (Player p : world.getPlayers()) {
proto.addPlayerWorldLocList(p.getWorldPlayerLocationInfo());
}
this.setData(proto);
......
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.World;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerRTTInfoOuterClass.PlayerRTTInfo;
import emu.grasscutter.net.proto.WorldPlayerRTTNotifyOuterClass.WorldPlayerRTTNotify;
public class PacketWorldPlayerRTTNotify extends GenshinPacket {
public class PacketWorldPlayerRTTNotify extends BasePacket {
public PacketWorldPlayerRTTNotify(World world) {
super(PacketOpcodes.WorldPlayerRTTNotify);
WorldPlayerRTTNotify.Builder proto = WorldPlayerRTTNotify.newBuilder();
for (GenshinPlayer player : world.getPlayers()) {
for (Player player : world.getPlayers()) {
proto.addPlayerRttList(
PlayerRTTInfo.newBuilder()
.setUid(player.getUid())
......
package emu.grasscutter.task;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/*
* So what is cron expression?
The format of a Cron expression is as follows.
Second Minute Hour Day Month Week Year
Seconds: 0-59
Minute: 0-59
hour: 0-23
Day: 1-31
Month: 1-12
Week: 1-7 (0-6 sometimes)
Year: Specify your own
If you want to express every second or every minute or something like that, use the * symbol in that position;
if you want to express more than one such as every 15 minutes and every 30 minutes, you can write:`15, 30`.
For the rest of the wildcard characters, please Google them yourself
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Task {
String taskName() default "NO_NAME";
String taskCronExpression() default "0 0 0 0 0 ?";
String triggerName() default "NO_NAME";
}
package emu.grasscutter.task;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public interface TaskHandler extends Job {
default void execute(JobExecutionContext context) throws JobExecutionException {
}
}
package emu.grasscutter.task;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player;
import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.MutableTrigger;
import org.reflections.Reflections;
import java.util.*;
@SuppressWarnings({"UnusedReturnValue", "unused"})
public final class TaskMap {
private final Map<String, TaskHandler> tasks = new HashMap<>();
private final Map<String, Task> annotations = new HashMap<>();
private final SchedulerFactory schedulerFactory = new StdSchedulerFactory();
public TaskMap() {
this(false);
}
public TaskMap(boolean scan) {
if (scan) this.scan();
}
public static TaskMap getInstance() {
return Grasscutter.getGameServer().getTaskMap();
}
public TaskMap registerTask(String taskName, TaskHandler task) {
Task annotation = task.getClass().getAnnotation(Task.class);
this.annotations.put(taskName, annotation);
this.tasks.put(taskName, task);
// register task
try {
Scheduler scheduler = schedulerFactory.getScheduler();
JobDetail job = JobBuilder
.newJob(task.getClass())
.withIdentity(taskName)
.build();
Trigger convTrigger = TriggerBuilder.newTrigger()
.withIdentity(annotation.triggerName())
.withSchedule(CronScheduleBuilder.cronSchedule(annotation.taskCronExpression()))
.build();
scheduler.scheduleJob(job, convTrigger);
scheduler.start();
} catch (SchedulerException e) {
e.printStackTrace();
}
return this;
}
public List<TaskHandler> getHandlersAsList() {
return new LinkedList<>(this.tasks.values());
}
public HashMap<String, TaskHandler> getHandlers() {
return new LinkedHashMap<>(this.tasks);
}
public TaskHandler getHandler(String taskName) {
return this.tasks.get(taskName);
}
private void scan() {
Reflections reflector = Grasscutter.reflector;
Set<Class<?>> classes = reflector.getTypesAnnotatedWith(Task.class);
classes.forEach(annotated -> {
try {
Task taskData = annotated.getAnnotation(Task.class);
Object object = annotated.newInstance();
if (object instanceof TaskHandler)
this.registerTask(taskData.taskName(), (TaskHandler) object);
else Grasscutter.getLogger().error("Class " + annotated.getName() + " is not a TaskHandler!");
} catch (Exception exception) {
Grasscutter.getLogger().error("Failed to register task handler for " + annotated.getSimpleName(), exception);
}
});
}
}
package emu.grasscutter.task.tasks;
import emu.grasscutter.database.DatabaseManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.task.Task;
import emu.grasscutter.task.TaskHandler;
import java.util.List;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@Task(taskName = "MoonCard", taskCronExpression = "0 0 0 * * ?", triggerName = "MoonCardTrigger")
// taskCronExpression: Fixed time period: 0:0:0 every day (twenty-four hour system)
public final class MoonCard implements TaskHandler {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
List<Player> players = DatabaseManager.getDatastore().find(Player.class).stream().toList();
for (Player player : players) {
if (player.isOnline()) {
if (player.inMoonCard()) {
player.getTodayMoonCard();
}
}
}
}
}
......@@ -18,9 +18,9 @@ import java.util.stream.Collectors;
import com.google.gson.reflect.TypeToken;
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.ItemData;
......@@ -45,48 +45,48 @@ public final class Tools {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
writer.println("// Genshin Impact " + GenshinConstants.VERSION + " GM Handbook");
writer.println("// Grasscutter " + GameConstants.VERSION + " GM Handbook");
writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator());
list = new ArrayList<>(GenshinData.getAvatarDataMap().keySet());
list = new ArrayList<>(GameData.getAvatarDataMap().keySet());
Collections.sort(list);
writer.println("// Avatars");
for (Integer id : list) {
AvatarData data = GenshinData.getAvatarDataMap().get(id);
AvatarData data = GameData.getAvatarDataMap().get(id);
writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
}
writer.println();
list = new ArrayList<>(GenshinData.getItemDataMap().keySet());
list = new ArrayList<>(GameData.getItemDataMap().keySet());
Collections.sort(list);
writer.println("// Items");
for (Integer id : list) {
ItemData data = GenshinData.getItemDataMap().get(id);
ItemData data = GameData.getItemDataMap().get(id);
writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
}
writer.println();
writer.println("// Scenes");
list = new ArrayList<>(GenshinData.getSceneDataMap().keySet());
list = new ArrayList<>(GameData.getSceneDataMap().keySet());
Collections.sort(list);
for (Integer id : list) {
SceneData data = GenshinData.getSceneDataMap().get(id);
SceneData data = GameData.getSceneDataMap().get(id);
writer.println(data.getId() + " : " + data.getScriptData());
}
writer.println();
writer.println("// Monsters");
list = new ArrayList<>(GenshinData.getMonsterDataMap().keySet());
list = new ArrayList<>(GameData.getMonsterDataMap().keySet());
Collections.sort(list);
for (Integer id : list) {
MonsterData data = GenshinData.getMonsterDataMap().get(id);
MonsterData data = GameData.getMonsterDataMap().get(id);
writer.println(data.getId() + " : " + map.get(data.getNameTextMapHash()));
}
}
......
......@@ -34,7 +34,7 @@ public final class Crypto {
public static void extractSecretKeyBuffer(byte[] data) {
try {
GetPlayerTokenRsp p = GetPlayerTokenRsp.parseFrom(data);
FileUtils.write(Grasscutter.getConfig().KEY_FOLDER + "secretKeyBuffer.bin", p.getSecretKeyBuffer().toByteArray());
FileUtils.write(Grasscutter.getConfig().KEY_FOLDER + "secretKeyBuffer.bin", p.getSecretKeyBytes().toByteArray());
Grasscutter.getLogger().info("Secret Key: " + p.getSecretKey());
} catch (Exception e) {
Grasscutter.getLogger().error("Crypto error.", e);
......
package emu.grasscutter.utils;
import java.util.Date;
import java.util.Calendar;
public final class DateHelper {
public static Date onlyYearMonthDay(Date now) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(now);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
}
......@@ -174,11 +174,11 @@ public final class Utils {
// Check for resources folder.
if(!fileExists(resourcesFolder)) {
logger.info("Creating resources folder...");
logger.info("Place a copy of 'GenshinData' in the resources folder.");
logger.info("Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder.");
createFolder(resourcesFolder); exit = true;
}
// Check for GenshinData.
// Check for BinOutput + ExcelBinOuput.
if(!fileExists(resourcesFolder + "BinOutput") ||
!fileExists(resourcesFolder + "ExcelBinOutput")) {
logger.info("Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder.");
......
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