From d7328dda506cd14cdb3e181cbc09c42eb94163fe Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 20 Apr 2022 21:11:57 -0400 Subject: [PATCH 01/35] Update Morphia to 2.x --- build.gradle | 11 +- .../grasscutter/database/DatabaseCounter.java | 2 +- .../grasscutter/database/DatabaseHelper.java | 117 +++++++----------- .../grasscutter/database/DatabaseManager.java | 42 +++---- .../java/emu/grasscutter/game/Account.java | 2 +- .../emu/grasscutter/game/GenshinPlayer.java | 2 +- .../game/avatar/GenshinAvatar.java | 2 +- .../grasscutter/game/friends/Friendship.java | 2 +- .../game/inventory/GenshinItem.java | 2 +- 9 files changed, 73 insertions(+), 109 deletions(-) diff --git a/build.gradle b/build.gradle index 97477456a..bfd5be045 100644 --- a/build.gradle +++ b/build.gradle @@ -14,17 +14,16 @@ plugins { id 'application' } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 17 +targetCompatibility = 17 repositories { mavenCentral() - jcenter() } dependencies { implementation fileTree(dir: 'lib', include: ['*.jar']) - + implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32' implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.6' implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6' @@ -33,9 +32,9 @@ dependencies { implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.8' implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1' - implementation group: 'org.reflections', name: 'reflections', version: '0.9.12' + implementation group: 'org.reflections', name: 'reflections', version: '0.10.2' - implementation group: 'dev.morphia.morphia', name: 'core', version: '1.6.1' + implementation group: 'dev.morphia.morphia', name: 'morphia-core', version: '2.2.6' implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1' } diff --git a/src/main/java/emu/grasscutter/database/DatabaseCounter.java b/src/main/java/emu/grasscutter/database/DatabaseCounter.java index 37fa59d7c..a70fe518a 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseCounter.java +++ b/src/main/java/emu/grasscutter/database/DatabaseCounter.java @@ -3,7 +3,7 @@ package emu.grasscutter.database; import dev.morphia.annotations.Entity; import dev.morphia.annotations.Id; -@Entity(value = "counters", noClassnameStored = true) +@Entity(value = "counters", useDiscriminator = false) public class DatabaseCounter { @Id private String id; diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index 0289c3e71..27a20159f 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -2,41 +2,33 @@ package emu.grasscutter.database; import java.util.List; -import com.mongodb.WriteResult; - -import dev.morphia.query.FindOptions; -import dev.morphia.query.Query; -import dev.morphia.query.internal.MorphiaCursor; +import com.mongodb.client.result.DeleteResult; +import dev.morphia.query.experimental.filters.Filters; import emu.grasscutter.GenshinConstants; -import emu.grasscutter.Grasscutter; import emu.grasscutter.game.Account; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.friends.Friendship; import emu.grasscutter.game.inventory.GenshinItem; -public class DatabaseHelper { - - protected static FindOptions FIND_ONE = new FindOptions().limit(1); - +public final class DatabaseHelper { public static Account createAccount(String username) { return createAccountWithId(username, 0); } - + public static Account createAccountWithId(String username, int reservedId) { // Unique names only Account exists = DatabaseHelper.getAccountByName(username); if (exists != null) { return null; } - + // Make sure there are no id collisions if (reservedId > 0) { // Cannot make account with the same uid as the server console if (reservedId == GenshinConstants.SERVER_CONSOLE_UID) { return null; } - exists = DatabaseHelper.getAccountByPlayerId(reservedId); if (exists != null) { return null; @@ -47,10 +39,10 @@ public class DatabaseHelper { Account account = new Account(); account.setUsername(username); account.setId(Integer.toString(DatabaseManager.getNextId(account))); - + if (reservedId > 0) { account.setPlayerId(reservedId); - } + } DatabaseHelper.saveAccount(account); return account; @@ -63,65 +55,52 @@ public class DatabaseHelper { if (exists != null) { return null; } - + // Account Account account = new Account(); account.setId(Integer.toString(DatabaseManager.getNextId(account))); account.setUsername(username); account.setPassword(password); - DatabaseHelper.saveAccount(account); + DatabaseHelper.saveAccount(account); return account; } public static void saveAccount(Account account) { DatabaseManager.getDatastore().save(account); } - + public static Account getAccountByName(String username) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).first(); } - + public static Account getAccountByToken(String token) { - if (token == null) return null; - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("token").equal(token).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + if(token == null) return null; + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("token", token)).first(); } - + public static Account getAccountById(String uid) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("_id").equal(uid).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("_id", uid)).first(); } - + public static Account getAccountByPlayerId(int playerId) { - MorphiaCursor cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("playerId").equal(playerId).find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("playerId", playerId)).first(); } - + public static boolean deleteAccount(String username) { - Query q = DatabaseManager.getDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username); - return DatabaseManager.getDatastore().findAndDelete(q) != null; + return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).delete().getDeletedCount() > 0; } - + public static GenshinPlayer getPlayerById(int id) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id); - MorphiaCursor cursor = query.find(FIND_ONE); - if (!cursor.hasNext()) return null; - return cursor.next(); + return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first(); } - + public static boolean checkPlayerExists(int id) { - MorphiaCursor query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id).find(FIND_ONE); - return query.hasNext(); + return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first() != null; } - + public static synchronized GenshinPlayer createPlayer(GenshinPlayer character, int reservedId) { // Check if reserved id - int id = 0; + int id; if (reservedId > 0 && !checkPlayerExists(reservedId)) { id = reservedId; character.setUid(id); @@ -136,10 +115,10 @@ public class DatabaseHelper { DatabaseManager.getDatastore().save(character); return character; } - + public static synchronized int getNextPlayerId(int reservedId) { // Check if reserved id - int id = 0; + int id; if (reservedId > 0 && !checkPlayerExists(reservedId)) { id = reservedId; } else { @@ -150,41 +129,37 @@ public class DatabaseHelper { } return id; } - + public static void savePlayer(GenshinPlayer character) { DatabaseManager.getDatastore().save(character); } - + public static void saveAvatar(GenshinAvatar avatar) { DatabaseManager.getDatastore().save(avatar); } - + public static List getAvatars(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinAvatar.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); } - + public static void saveItem(GenshinItem item) { DatabaseManager.getDatastore().save(item); } - + public static boolean deleteItem(GenshinItem item) { - WriteResult result = DatabaseManager.getDatastore().delete(item); + DeleteResult result = DatabaseManager.getDatastore().delete(item); return result.wasAcknowledged(); } - + public static List getInventoryItems(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(GenshinItem.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(GenshinItem.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getFriends(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("ownerId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); } - + public static List getReverseFriends(GenshinPlayer player) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("friendId", player.getUid()); - return query.find().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("friendId", player.getUid())).stream().toList(); } public static void saveFriendship(Friendship friendship) { @@ -196,13 +171,9 @@ public class DatabaseHelper { } public static Friendship getReverseFriendship(Friendship friendship) { - Query query = DatabaseManager.getDatastore().createQuery(Friendship.class); - query.and( - query.criteria("ownerId").equal(friendship.getFriendId()), - query.criteria("friendId").equal(friendship.getOwnerId()) - ); - MorphiaCursor reverseFriendship = query.find(FIND_ONE); - if (!reverseFriendship.hasNext()) return null; - return reverseFriendship.next(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.and( + Filters.eq("ownerId", friendship.getFriendId()), + Filters.eq("friendId", friendship.getOwnerId()) + )).first(); } } diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 97e27a81a..3dccbcc0e 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -1,13 +1,15 @@ package emu.grasscutter.database; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientURI; import com.mongodb.MongoCommandException; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoIterable; import dev.morphia.Datastore; import dev.morphia.Morphia; +import dev.morphia.mapping.MapperOptions; +import dev.morphia.query.experimental.filters.Filters; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.Account; import emu.grasscutter.game.GenshinPlayer; @@ -23,10 +25,6 @@ public final class DatabaseManager { DatabaseCounter.class, Account.class, GenshinPlayer.class, GenshinAvatar.class, GenshinItem.class, Friendship.class }; - public static MongoClient getMongoClient() { - return mongoClient; - } - public static Datastore getDatastore() { return datastore; } @@ -37,27 +35,23 @@ public final class DatabaseManager { public static void initialize() { // Initialize - mongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().DatabaseUrl)); - Morphia morphia = new Morphia(); + mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); - // TODO Update when migrating to Morphia 2.0 - morphia.getMapper().getOptions().setStoreEmpties(true); - morphia.getMapper().getOptions().setStoreNulls(false); - morphia.getMapper().getOptions().setDisableEmbeddedIndexes(true); - - // Map - morphia.map(mappedClasses); - - // Build datastore - datastore = morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection); + // Set mapper options. + MapperOptions mapperOptions = MapperOptions.builder() + .storeEmpties(true).storeNulls(false).build(); + // Create data store. + datastore = Morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection, mapperOptions); + // Map classes. + datastore.getMapper().map(mappedClasses); // Ensure indexes try { datastore.ensureIndexes(); - } catch (MongoCommandException e) { - Grasscutter.getLogger().info("Mongo index error: ", e); + } catch (MongoCommandException exception) { + Grasscutter.getLogger().info("Mongo index error: ", exception); // Duplicate index error - if (e.getCode() == 85) { + if (exception.getCode() == 85) { // Drop all indexes and re add them MongoIterable collections = datastore.getDatabase().listCollectionNames(); for (String name : collections) { @@ -68,9 +62,9 @@ public final class DatabaseManager { } } } - + public static synchronized int getNextId(Class c) { - DatabaseCounter counter = getDatastore().createQuery(DatabaseCounter.class).field("_id").equal(c.getSimpleName()).find().tryNext(); + DatabaseCounter counter = getDatastore().find(DatabaseCounter.class).filter(Filters.eq("_id", c.getName())).first(); if (counter == null) { counter = new DatabaseCounter(c.getSimpleName()); } @@ -80,7 +74,7 @@ public final class DatabaseManager { getDatastore().save(counter); } } - + public static synchronized int getNextId(Object o) { return getNextId(o.getClass()); } diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 2eeeed3b1..3eff38cf9 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -15,7 +15,7 @@ import java.util.List; import com.mongodb.DBObject; -@Entity(value = "accounts", noClassnameStored = true) +@Entity(value = "accounts", useDiscriminator = false) public class Account { @Id private String id; diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index 1d8650e54..535ef06d9 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -58,7 +58,7 @@ import emu.grasscutter.utils.Position; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -@Entity(value = "players", noClassnameStored = true) +@Entity(value = "players", useDiscriminator = false) public class GenshinPlayer { @Id private int id; @Indexed(options = @IndexOptions(unique = true)) private String accountId; diff --git a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java index a5dcb3ee8..d16208047 100644 --- a/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java +++ b/src/main/java/emu/grasscutter/game/avatar/GenshinAvatar.java @@ -50,7 +50,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -@Entity(value = "avatars", noClassnameStored = true) +@Entity(value = "avatars", useDiscriminator = false) public class GenshinAvatar { @Id private ObjectId id; @Indexed private int ownerId; // Id of player that this avatar belongs to diff --git a/src/main/java/emu/grasscutter/game/friends/Friendship.java b/src/main/java/emu/grasscutter/game/friends/Friendship.java index 2be7d1fce..7ac147b6a 100644 --- a/src/main/java/emu/grasscutter/game/friends/Friendship.java +++ b/src/main/java/emu/grasscutter/game/friends/Friendship.java @@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; -@Entity(value = "friendships", noClassnameStored = true) +@Entity(value = "friendships", useDiscriminator = false) public class Friendship { @Id private ObjectId id; diff --git a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java index 0b0db49c4..a395825da 100644 --- a/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java +++ b/src/main/java/emu/grasscutter/game/inventory/GenshinItem.java @@ -34,7 +34,7 @@ import emu.grasscutter.net.proto.SceneWeaponInfoOuterClass.SceneWeaponInfo; import emu.grasscutter.net.proto.WeaponOuterClass.Weapon; import emu.grasscutter.utils.WeightedList; -@Entity(value = "items", noClassnameStored = true) +@Entity(value = "items", useDiscriminator = false) public class GenshinItem { @Id private ObjectId id; @Indexed private int ownerId; From b902fa6f48300f9daefec6d1a666b5a908d44b15 Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 20 Apr 2022 23:56:27 -0400 Subject: [PATCH 02/35] Fix command detection --- src/main/java/emu/grasscutter/Grasscutter.java | 2 +- src/main/java/emu/grasscutter/command/CommandMap.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 0e34c120d..a66c71254 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -34,7 +34,7 @@ public final class Grasscutter { private static DispatchServer dispatchServer; private static GameServer gameServer; - public static final Reflections reflector = new Reflections(); + public static final Reflections reflector = new Reflections("emu.grasscutter"); static { // Declare logback configuration. diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index 007fafe17..f735bc642 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -11,6 +11,7 @@ import java.util.*; public final class CommandMap { private final Map commands = new HashMap<>(); private final Map annotations = new HashMap<>(); + public CommandMap() { this(false); } From 0a96012f2c128c5217ec6a1344d3906ffa06016a Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Thu, 21 Apr 2022 02:07:05 -0400 Subject: [PATCH 03/35] why is `Account#onLoad` THE DAMN REASON FOR HOURS OF TESTING --- build.gradle | 4 +-- .../grasscutter/database/DatabaseManager.java | 3 +- .../java/emu/grasscutter/game/Account.java | 28 ++++++++----------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index bfd5be045..dcc109d0e 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,8 @@ plugins { id 'application' } -sourceCompatibility = 17 -targetCompatibility = 17 +sourceCompatibility = 16 +targetCompatibility = 16 repositories { mavenCentral() diff --git a/src/main/java/emu/grasscutter/database/DatabaseManager.java b/src/main/java/emu/grasscutter/database/DatabaseManager.java index 3dccbcc0e..004f6ba80 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseManager.java +++ b/src/main/java/emu/grasscutter/database/DatabaseManager.java @@ -18,7 +18,6 @@ import emu.grasscutter.game.friends.Friendship; import emu.grasscutter.game.inventory.GenshinItem; public final class DatabaseManager { - private static MongoClient mongoClient; private static Datastore datastore; private static final Class[] mappedClasses = new Class[] { @@ -35,7 +34,7 @@ public final class DatabaseManager { public static void initialize() { // Initialize - mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); + MongoClient mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl); // Set mapper options. MapperOptions mapperOptions = MapperOptions.builder() diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index 3eff38cf9..073bf10fd 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -1,20 +1,13 @@ package emu.grasscutter.game; -import dev.morphia.annotations.Collation; -import dev.morphia.annotations.Entity; -import dev.morphia.annotations.Id; -import dev.morphia.annotations.Indexed; -import dev.morphia.annotations.PreLoad; +import dev.morphia.annotations.*; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Utils; -import dev.morphia.annotations.IndexOptions; import java.util.ArrayList; import java.util.List; -import com.mongodb.DBObject; - @Entity(value = "accounts", useDiscriminator = false) public class Account { @Id private String id; @@ -30,7 +23,7 @@ public class Account { private String token; private String sessionKey; // Session token for dispatch server private List permissions; - + @Deprecated public Account() { this.permissions = new ArrayList<>(); @@ -121,15 +114,16 @@ public class Account { return this.token; } - @PreLoad - public void onLoad(DBObject dbObj) { - // Grant the superuser permissions to accounts created before the permissions update - if (!dbObj.containsField("permissions")) { - this.addPermission("*"); - } - } - public void save() { DatabaseHelper.saveAccount(this); } + +// TODO: Find an implementation for this. Morphia 2.0 breaks this method for some reason? +// @PreLoad +// public void onLoad(DBObject object) { +// // Grant the superuser permissions to accounts created before the permissions update +// if (!object.containsField("permissions")) { +// this.addPermission("*"); +// } +// } } From 06101f1b9c85e472158f7384bede4b21f2347d74 Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:19:47 -0400 Subject: [PATCH 04/35] Morphia call fixes; add `@Entity` to more classes 1. During the conversion of Morphia calls to the new API, some of the `Filter.eq()` calls had their `field` set to `playerId` due to a copy/paste typo. 2. Morphia 2 switches to the codec system, so anything that will be serialized in the pipeline requires the `@Entity` annotation. --- src/main/java/emu/grasscutter/database/DatabaseHelper.java | 4 ++-- src/main/java/emu/grasscutter/game/TeamInfo.java | 2 ++ src/main/java/emu/grasscutter/game/TeamManager.java | 2 ++ .../java/emu/grasscutter/game/avatar/AvatarProfileData.java | 3 +++ src/main/java/emu/grasscutter/game/friends/PlayerProfile.java | 1 + .../emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java | 3 +++ src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java | 3 +++ src/main/java/emu/grasscutter/utils/Position.java | 2 ++ 8 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/database/DatabaseHelper.java b/src/main/java/emu/grasscutter/database/DatabaseHelper.java index 27a20159f..b70365225 100644 --- a/src/main/java/emu/grasscutter/database/DatabaseHelper.java +++ b/src/main/java/emu/grasscutter/database/DatabaseHelper.java @@ -139,7 +139,7 @@ public final class DatabaseHelper { } public static List getAvatars(GenshinPlayer player) { - return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); + return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static void saveItem(GenshinItem item) { @@ -155,7 +155,7 @@ public final class DatabaseHelper { return DatabaseManager.getDatastore().find(GenshinItem.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getFriends(GenshinPlayer player) { - return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("playerId", player.getUid())).stream().toList(); + return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList(); } public static List getReverseFriends(GenshinPlayer player) { diff --git a/src/main/java/emu/grasscutter/game/TeamInfo.java b/src/main/java/emu/grasscutter/game/TeamInfo.java index 0a12b1d2c..83220a7e5 100644 --- a/src/main/java/emu/grasscutter/game/TeamInfo.java +++ b/src/main/java/emu/grasscutter/game/TeamInfo.java @@ -3,10 +3,12 @@ package emu.grasscutter.game; import java.util.ArrayList; import java.util.List; +import dev.morphia.annotations.Entity; import emu.grasscutter.GenshinConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.game.avatar.GenshinAvatar; +@Entity public class TeamInfo { private String name; private List avatars; diff --git a/src/main/java/emu/grasscutter/game/TeamManager.java b/src/main/java/emu/grasscutter/game/TeamManager.java index 4cd7bfcdf..2ab9639c2 100644 --- a/src/main/java/emu/grasscutter/game/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/TeamManager.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import dev.morphia.annotations.Entity; import dev.morphia.annotations.Transient; import emu.grasscutter.GenshinConstants; import emu.grasscutter.Grasscutter; @@ -41,6 +42,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; +@Entity public class TeamManager { @Transient private GenshinPlayer player; diff --git a/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java b/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java index 5458c1752..d04c9d326 100644 --- a/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java +++ b/src/main/java/emu/grasscutter/game/avatar/AvatarProfileData.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.avatar; +import dev.morphia.annotations.Entity; + +@Entity public class AvatarProfileData { private int avatarId; private int level; diff --git a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java index cc7408aa6..50889ad0c 100644 --- a/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java +++ b/src/main/java/emu/grasscutter/game/friends/PlayerProfile.java @@ -4,6 +4,7 @@ import dev.morphia.annotations.*; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.utils.Utils; +@Entity public class PlayerProfile { @Transient private GenshinPlayer player; diff --git a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java index 2e144226e..b0c85d355 100644 --- a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java +++ b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaBannerInfo.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.gacha; +import dev.morphia.annotations.Entity; + +@Entity public class PlayerGachaBannerInfo { private int pity5 = 0; private int pity4 = 0; diff --git a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java index c3aabcb76..8dd0e380e 100644 --- a/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java +++ b/src/main/java/emu/grasscutter/game/gacha/PlayerGachaInfo.java @@ -1,5 +1,8 @@ package emu.grasscutter.game.gacha; +import dev.morphia.annotations.Entity; + +@Entity public class PlayerGachaInfo { private PlayerGachaBannerInfo standardBanner; private PlayerGachaBannerInfo eventCharacterBanner; diff --git a/src/main/java/emu/grasscutter/utils/Position.java b/src/main/java/emu/grasscutter/utils/Position.java index 6a02dacba..f2ecb6915 100644 --- a/src/main/java/emu/grasscutter/utils/Position.java +++ b/src/main/java/emu/grasscutter/utils/Position.java @@ -2,8 +2,10 @@ package emu.grasscutter.utils; import java.io.Serializable; +import dev.morphia.annotations.Entity; import emu.grasscutter.net.proto.VectorOuterClass.Vector; +@Entity public class Position implements Serializable { private static final long serialVersionUID = -2001232313615923575L; From 46b527df4d776c34d1f48bf1ad41bacde49870a6 Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Fri, 22 Apr 2022 13:05:06 +0800 Subject: [PATCH 05/35] Log files --- .gitignore | 7 ++++--- src/main/resources/logback.xml | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1cd17e099..9df6d0071 100644 --- a/.gitignore +++ b/.gitignore @@ -47,12 +47,13 @@ tmp/ # Grasscutter resources/* +logs/* data/AbilityEmbryos.json data/OpenConfig.json proto/auto/ proto/protoc.exe GM Handbook.txt -config.json -mitmdump.exe -grasscutter.jar +config.json +mitmdump.exe +grasscutter.jar mongod.exe diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 666b53b42..477c1ac5b 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -4,8 +4,19 @@ [%d{HH:mm:ss}] [%highlight(%level)] %msg%n + + logs/latest.log + + logs/log.%d{yyyy-MM-dd}_%d{HH}.log.tar.gz + 24 + + + %d{yyyy-MM-dd'T'HH:mm:ss'Z'} - %m%n + + + \ No newline at end of file From 215ee2a3b29cc083eba69a77990b7adba2732bbe Mon Sep 17 00:00:00 2001 From: fumbling <104180076+fumbling644o@users.noreply.github.com> Date: Fri, 22 Apr 2022 02:32:27 -0400 Subject: [PATCH 06/35] Explicitly load and save UTF-8 for the handbook This fixes potential output issues for non-Latin scripts when exporting the handbook by changing the filename in the code. --- src/main/java/emu/grasscutter/tools/Tools.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index 6f6466773..638d61e12 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -3,6 +3,7 @@ package emu.grasscutter.tools; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -30,13 +31,13 @@ public final class Tools { ResourceLoader.loadResources(); Map map; - try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"))) { + try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"), StandardCharsets.UTF_8)) { map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken>() {}.getType()); } List list; String fileName = "./GM Handbook.txt"; - try (FileWriter fileWriter = new FileWriter(fileName); PrintWriter writer = new PrintWriter(fileWriter)) { + try (PrintWriter writer = new PrintWriter(fileName, StandardCharsets.UTF_8)) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); From b629e8c652f86b039b5c80b88e47c6b78458d292 Mon Sep 17 00:00:00 2001 From: Sam <100821827+01101sam@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:36:24 +0800 Subject: [PATCH 07/35] [typo] Fix resources folder tips --- src/main/java/emu/grasscutter/utils/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/utils/Utils.java b/src/main/java/emu/grasscutter/utils/Utils.java index 251898bd4..4077c1ce7 100644 --- a/src/main/java/emu/grasscutter/utils/Utils.java +++ b/src/main/java/emu/grasscutter/utils/Utils.java @@ -158,7 +158,7 @@ public final class Utils { // Check for GenshinData. if(!fileExists(resourcesFolder + "BinOutput") || !fileExists(resourcesFolder + "ExcelBinOutput")) { - logger.info("Place a copy of 'GenshinData' in the resources folder."); + logger.info("Place a copy of 'BinOutput' in the resources folder."); exit = true; } From 2aaf70c031580b6623d1879e49d67cd6fbc8b2d0 Mon Sep 17 00:00:00 2001 From: Sam <100821827+01101sam@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:43:06 +0800 Subject: [PATCH 08/35] [typo-upd] Add missing folder --- src/main/java/emu/grasscutter/utils/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/utils/Utils.java b/src/main/java/emu/grasscutter/utils/Utils.java index 4077c1ce7..c481ffd07 100644 --- a/src/main/java/emu/grasscutter/utils/Utils.java +++ b/src/main/java/emu/grasscutter/utils/Utils.java @@ -158,7 +158,7 @@ public final class Utils { // Check for GenshinData. if(!fileExists(resourcesFolder + "BinOutput") || !fileExists(resourcesFolder + "ExcelBinOutput")) { - logger.info("Place a copy of 'BinOutput' in the resources folder."); + logger.info("Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder."); exit = true; } From 370483fae299aa6139fcd0c7a6a1025f5ae68d82 Mon Sep 17 00:00:00 2001 From: alt3ri <95161279+alt3ri@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:28:52 +0700 Subject: [PATCH 09/35] Added /talent command Set current character talent level by using /talent command. > /talent getid - Gets current character talent ID > /talent set - Sets current character's talent level --- .../command/commands/TalentCommand.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/TalentCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java new file mode 100644 index 000000000..178942b42 --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -0,0 +1,109 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify; +import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp; +import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; + +import java.util.List; + +@Command(label = "talent", usage = "talent ", + description = "Set talent level for your current active character", permission = "player.settalent") +public class TalentCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 0 || args.size() < 1){ + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + } + + String cmdSwitch = args.get(0); + switch (cmdSwitch) { + default: + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + case "set": + try { + int skillId = Integer.parseInt(args.get(1)); + int nextLevel = Integer.parseInt(args.get(2)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + GenshinAvatar avatar = entity.getAvatar(); + int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); + int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); + int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); + int currentLevelNorAtk = avatar.getSkillLevelMap().get(skillIdNorAtk); + int currentLevelE = avatar.getSkillLevelMap().get(skillIdE); + int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ); + if (args.size() < 2){ + CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); + return; + } + if (nextLevel > 16){ + CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16"); + return; + } + if (skillId == skillIdNorAtk){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdNorAtk, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent Normal ATK to " + nextLevel + "."); + } + if (skillId == skillIdE){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdE, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent E to " + nextLevel + "."); + } + if (skillId == skillIdQ){ + // Upgrade skill + avatar.getSkillLevelMap().put(skillIdQ, nextLevel); + avatar.save(); + + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel)); + CommandHandler.sendMessage(sender, "Set talent Q to " + nextLevel + "."); + } + + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid skill ID."); + return; + } + + break; + case "getid": + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + GenshinAvatar avatar = entity.getAvatar(); + int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); + int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); + int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); + + CommandHandler.sendMessage(sender, "Normal Attack ID " + skillIdNorAtk + "."); + CommandHandler.sendMessage(sender, "E skill ID " + skillIdE + "."); + CommandHandler.sendMessage(sender, "Q skill ID " + skillIdQ + "."); + break; + } + } +} From 63898a18df898ea1e3787e1f8ca8453f6a65b3e8 Mon Sep 17 00:00:00 2001 From: alt3ri <95161279+alt3ri@users.noreply.github.com> Date: Fri, 22 Apr 2022 17:38:58 +0700 Subject: [PATCH 10/35] Deleted 2 lines --- .../java/emu/grasscutter/command/commands/TalentCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index 178942b42..2ced6f1c3 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -5,10 +5,8 @@ import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import java.util.List; From 9b23bfa55696b4adb5392f16070bf91c01ba53f3 Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Fri, 22 Apr 2022 05:20:02 -0700 Subject: [PATCH 11/35] Revert "Explicitly load and save UTF-8 for the handbook" This reverts commit 215ee2a3b29cc083eba69a77990b7adba2732bbe. --- src/main/java/emu/grasscutter/tools/Tools.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index 638d61e12..6f6466773 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -3,7 +3,6 @@ package emu.grasscutter.tools; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -31,13 +30,13 @@ public final class Tools { ResourceLoader.loadResources(); Map map; - try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"), StandardCharsets.UTF_8)) { + try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"))) { map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken>() {}.getType()); } List list; String fileName = "./GM Handbook.txt"; - try (PrintWriter writer = new PrintWriter(fileName, StandardCharsets.UTF_8)) { + try (FileWriter fileWriter = new FileWriter(fileName); PrintWriter writer = new PrintWriter(fileWriter)) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); From e02917a5272c3b4b64588d55033a20838758a685 Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Fri, 22 Apr 2022 21:25:58 +0800 Subject: [PATCH 12/35] Add FrontHTTPS field to Dispatch server Signed-off-by: Jaida Wu --- src/main/java/emu/grasscutter/Config.java | 1 + .../java/emu/grasscutter/server/dispatch/DispatchServer.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 267ab67f2..e83bce6a2 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -30,6 +30,7 @@ public final class Config { public String KeystorePath = "./keystore.p12"; public String KeystorePassword = ""; public Boolean UseSSL = true; + public Boolean FrontHTTPS = true; public boolean AutomaticallyCreateAccounts = false; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index ad8354867..09828b1b4 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -101,7 +101,7 @@ public final class DispatchServer { .setName("os_usa") .setTitle(Grasscutter.getConfig().getGameServerOptions().Name) .setType("DEV_PUBLIC") - .setDispatchUrl("https://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + getAddress().getPort() + "/query_cur_region_" + defaultServerName) + .setDispatchUrl("http" + (Grasscutter.getConfig().getDispatchOptions().FrontHTTPS ? "s" : "") + "://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + getAddress().getPort() + "/query_cur_region_" + defaultServerName) .build(); usedNames.add(defaultServerName); servers.add(server); @@ -131,7 +131,7 @@ public final class DispatchServer { .setName(regionInfo.Name) .setTitle(regionInfo.Title) .setType("DEV_PUBLIC") - .setDispatchUrl("https://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + getAddress().getPort() + "/query_cur_region_" + regionInfo.Name) + .setDispatchUrl("http" + (Grasscutter.getConfig().getDispatchOptions().FrontHTTPS ? "s" : "") + "://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + getAddress().getPort() + "/query_cur_region_" + regionInfo.Name) .build(); usedNames.add(regionInfo.Name); servers.add(server); From 8b3b419abc6586c79c67b5c6c4217b6210efb989 Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Fri, 22 Apr 2022 22:00:13 +0800 Subject: [PATCH 13/35] Update proxy.py --- proxy.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy.py b/proxy.py index 86145cde6..11625cc20 100644 --- a/proxy.py +++ b/proxy.py @@ -57,7 +57,9 @@ class MlgmXyysd_Genshin_Impact_Proxy: "minor-api.mihoyo.com", "public-data-api.mihoyo.com", "uspider.yuanshen.com", - "sdk-static.mihoyo.com" + "sdk-static.mihoyo.com", + "abtest-api-data-sg.hoyoverse.com", + "log-upload-os.hoyoverse.com" ] def request(self, flow: http.HTTPFlow) -> None: From 68218cbb49700cc366c489d55c821a1ec23bc83f Mon Sep 17 00:00:00 2001 From: PasserbyAlpha Date: Fri, 22 Apr 2022 23:11:29 +0800 Subject: [PATCH 14/35] fixed encoding problem when generating gm handbook --- src/main/java/emu/grasscutter/tools/Tools.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index 6f6466773..fd614f4c1 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -1,8 +1,11 @@ package emu.grasscutter.tools; +import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; +import java.io.InputStreamReader; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -30,7 +33,7 @@ public final class Tools { ResourceLoader.loadResources(); Map map; - try (FileReader fileReader = new FileReader(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json"))) { + try (InputStreamReader fileReader = new InputStreamReader(new FileInputStream(Utils.toFilePath(Grasscutter.getConfig().RESOURCE_FOLDER + "TextMap/TextMapEN.json")), StandardCharsets.UTF_8)) { map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken>() {}.getType()); } From 104d10352b47a851785ed0e7d6c1f0a5efa0d55e Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 23 Apr 2022 01:16:55 +0800 Subject: [PATCH 15/35] Add PublicPort field to Dispatch server --- src/main/java/emu/grasscutter/Config.java | 1 + .../java/emu/grasscutter/server/dispatch/DispatchServer.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index e83bce6a2..662138557 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -27,6 +27,7 @@ public final class Config { public String Ip = "0.0.0.0"; public String PublicIp = "127.0.0.1"; public int Port = 443; + public int PublicPort = 0; public String KeystorePath = "./keystore.p12"; public String KeystorePassword = ""; public Boolean UseSSL = true; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 09828b1b4..7fe431423 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -101,7 +101,7 @@ public final class DispatchServer { .setName("os_usa") .setTitle(Grasscutter.getConfig().getGameServerOptions().Name) .setType("DEV_PUBLIC") - .setDispatchUrl("http" + (Grasscutter.getConfig().getDispatchOptions().FrontHTTPS ? "s" : "") + "://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + getAddress().getPort() + "/query_cur_region_" + defaultServerName) + .setDispatchUrl("http" + (Grasscutter.getConfig().getDispatchOptions().FrontHTTPS ? "s" : "") + "://" + (Grasscutter.getConfig().getDispatchOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getDispatchOptions().Ip : Grasscutter.getConfig().getDispatchOptions().PublicIp) + ":" + (Grasscutter.getConfig().getDispatchOptions().PublicPort != 0 ? Grasscutter.getConfig().getDispatchOptions().PublicPort : Grasscutter.getConfig().getDispatchOptions().Port) + "/query_cur_region_" + defaultServerName) .build(); usedNames.add(defaultServerName); servers.add(server); From 4605c6506e45726c906b895f64fa463d81628e49 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 23 Apr 2022 01:42:04 +0800 Subject: [PATCH 16/35] Add PublicPort field to server --- src/main/java/emu/grasscutter/Config.java | 1 + .../java/emu/grasscutter/server/dispatch/DispatchServer.java | 2 +- .../grasscutter/server/packet/send/PacketPlayerLoginRsp.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 662138557..4a6f71680 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -54,6 +54,7 @@ public final class Config { public String Ip = "0.0.0.0"; public String PublicIp = "127.0.0.1"; public int Port = 22102; + public int PublicPort = 0; public String DispatchServerDatabaseUrl = "mongodb://localhost:27017"; public String DispatchServerDatabaseCollection = "grasscutter"; diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 7fe431423..7c7915675 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -108,7 +108,7 @@ public final class DispatchServer { RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder() .setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getGameServerOptions().Ip : Grasscutter.getConfig().getGameServerOptions().PublicIp)) - .setPort(Grasscutter.getConfig().getGameServerOptions().Port) + .setPort(Grasscutter.getConfig().getGameServerOptions().PublicPort != 0 ? Grasscutter.getConfig().getGameServerOptions().PublicPort : Grasscutter.getConfig().getGameServerOptions().Port) .setSecretKey(ByteString.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin"))) .build(); diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java index a5e167100..3a796c7ad 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerLoginRsp.java @@ -41,7 +41,7 @@ public class PacketPlayerLoginRsp extends GenshinPacket { RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder() .setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getGameServerOptions().Ip : Grasscutter.getConfig().getGameServerOptions().PublicIp)) - .setPort(Grasscutter.getConfig().getGameServerOptions().Port) + .setPort(Grasscutter.getConfig().getGameServerOptions().PublicPort != 0 ? Grasscutter.getConfig().getGameServerOptions().PublicPort : Grasscutter.getConfig().getGameServerOptions().Port) .setSecretKey(ByteString.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin"))) .build(); From 3ca181e76ddc64b40d124671cf1e383f17a5199a Mon Sep 17 00:00:00 2001 From: yarik0chka Date: Fri, 22 Apr 2022 23:24:51 +0500 Subject: [PATCH 17/35] Implemented sitting --- .../grasscutter/net/packet/PacketOpcodes.java | 3 ++- .../recv/HandleEvtAvatarSitDownNotify.java | 21 ++++++++++++++++ .../server/packet/recv/HandleSitReq.java | 24 +++++++++++++++++++ .../send/PacketEvtAvatarSitDownNotify.java | 20 ++++++++++++++++ .../server/packet/send/PacketSitRsp.java | 21 ++++++++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandleEvtAvatarSitDownNotify.java create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandleSitReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketSitRsp.java diff --git a/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java b/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java index 418f16a4b..365055e26 100644 --- a/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java +++ b/src/main/java/emu/grasscutter/net/packet/PacketOpcodes.java @@ -1034,6 +1034,8 @@ public class PacketOpcodes { public static final int ShowTemplateReminderNotify = 3164; public static final int SignInInfoReq = 2510; public static final int SignInInfoRsp = 2515; + public static final int SitReq = 354; + public static final int SitRsp = 335; public static final int SocialDataNotify = 4063; public static final int SpringUseReq = 1720; public static final int SpringUseRsp = 1727; @@ -1208,5 +1210,4 @@ public class PacketOpcodes { public static final int WorldRoutineChangeNotify = 3548; public static final int WorldRoutineTypeCloseNotify = 3513; public static final int WorldRoutineTypeRefreshNotify = 3545; - } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandleEvtAvatarSitDownNotify.java b/src/main/java/emu/grasscutter/server/packet/recv/HandleEvtAvatarSitDownNotify.java new file mode 100644 index 000000000..8f653dde9 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandleEvtAvatarSitDownNotify.java @@ -0,0 +1,21 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketEvtAvatarSitDownNotify; + +@Opcodes(PacketOpcodes.EvtAvatarSitDownNotify) +public class HandleEvtAvatarSitDownNotify extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + EvtAvatarSitDownNotify notify = EvtAvatarSitDownNotify.parseFrom(payload); + + session.send(new PacketEvtAvatarSitDownNotify(notify)); + } + +} + diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandleSitReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandleSitReq.java new file mode 100644 index 000000000..418d99eef --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandleSitReq.java @@ -0,0 +1,24 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SitReqOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketSitRsp; +import emu.grasscutter.utils.Position; + +@Opcodes(PacketOpcodes.SitReq) +public class HandleSitReq extends PacketHandler { + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SitReqOuterClass.SitReq req = SitReqOuterClass.SitReq.parseFrom(payload); + + float x = req.getPosition().getX(); + float y = req.getPosition().getY(); + float z = req.getPosition().getZ(); + + session.send(new PacketSitRsp(req.getChairId(), new Position(x, y, z), session.getPlayer().getTeamManager().getCurrentAvatarEntity().getId())); + } + +} \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java new file mode 100644 index 000000000..6a051024a --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketEvtAvatarSitDownNotify.java @@ -0,0 +1,20 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.EvtAvatarSitDownNotifyOuterClass.EvtAvatarSitDownNotify; + +public class PacketEvtAvatarSitDownNotify extends GenshinPacket { + + public PacketEvtAvatarSitDownNotify(EvtAvatarSitDownNotify notify) { + super(PacketOpcodes.EvtAvatarSitDownNotify); + + EvtAvatarSitDownNotify proto = EvtAvatarSitDownNotify.newBuilder() + .setEntityId(notify.getEntityId()) + .setPosition(notify.getPosition()) + .setChairId(notify.getChairId()) + .build(); + + this.setData(proto); + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSitRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSitRsp.java new file mode 100644 index 000000000..70893965b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSitRsp.java @@ -0,0 +1,21 @@ +package emu.grasscutter.server.packet.send; + +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SitRspOuterClass.SitRsp; +import emu.grasscutter.utils.Position; + +public class PacketSitRsp extends GenshinPacket { + + public PacketSitRsp(long chairId, Position pos, int EntityId) { + super(PacketOpcodes.SitRsp); + + SitRsp proto = SitRsp.newBuilder() + .setEntityId(EntityId) + .setPosition(pos.toProto()) + .setChairId(chairId) + .build(); + + this.setData(proto); + } +} From 6cc0fdaeedba5b684a6247fe0d8e3cfedff0c78c Mon Sep 17 00:00:00 2001 From: PasserbyAlpha Date: Sat, 23 Apr 2022 02:28:34 +0800 Subject: [PATCH 18/35] use OutputStreamWriter to ensure the charset of output is utf8 [from fumbling644o] --- src/main/java/emu/grasscutter/tools/Tools.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index fd614f4c1..1afcc1ebe 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -1,9 +1,11 @@ package emu.grasscutter.tools; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; @@ -39,7 +41,7 @@ public final class Tools { List list; String fileName = "./GM Handbook.txt"; - try (FileWriter fileWriter = new FileWriter(fileName); PrintWriter writer = new PrintWriter(fileWriter)) { + try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName), StandardCharsets.UTF_8), false)) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); From cdf6c697f1f1f2da1b5747bb7c52427c44e5813b Mon Sep 17 00:00:00 2001 From: Raeliana <55598870+Raeliana@users.noreply.github.com> Date: Sat, 23 Apr 2022 02:48:04 +0300 Subject: [PATCH 19/35] Create ClearWeaponsCommand.java A command to clear unlocked and unequipped artifacts --- .../command/commands/ClearWeaponsCommand.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java b/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java new file mode 100644 index 000000000..8fab1768b --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java @@ -0,0 +1,29 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.inventory.ItemType; + +import java.util.List; + +@Command(label = "clearweapons", usage = "clearweapons", + description = "Deletes all unequipped and unlocked weapons, including yellow rarity ones from your inventory", + aliases = {"clearwpns"}, permission = "player.clearweapons") +public final class ClearWeaponsCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; // TODO: clear player's weapons from console or other players + } + + Inventory playerInventory = sender.getInventory(); + playerInventory.getItems().values().stream() + .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON) + .filter(item -> !item.isLocked() && !item.isEquipped()) + .forEach(item -> playerInventory.removeItem(item, item.getCount())); + } +} From 7fd0b371d004831ba8b222cc4ee50050707b1ee8 Mon Sep 17 00:00:00 2001 From: Miyucchi Date: Sat, 23 Apr 2022 03:22:32 +0200 Subject: [PATCH 20/35] Profile set birthday feature --- .../emu/grasscutter/game/GenshinPlayer.java | 16 ++++- .../game/player/PlayerBirthday.java | 68 +++++++++++++++++++ .../recv/HandlerSetPlayerBirthdayReq.java | 38 +++++++++++ .../send/PacketSetPlayerBirthdayRsp.java | 22 ++++++ 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/game/player/PlayerBirthday.java create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java diff --git a/src/main/java/emu/grasscutter/game/GenshinPlayer.java b/src/main/java/emu/grasscutter/game/GenshinPlayer.java index 44f960198..5a8b96748 100644 --- a/src/main/java/emu/grasscutter/game/GenshinPlayer.java +++ b/src/main/java/emu/grasscutter/game/GenshinPlayer.java @@ -18,6 +18,7 @@ import emu.grasscutter.game.friends.PlayerProfile; import emu.grasscutter.game.gacha.PlayerGachaInfo; import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.player.PlayerBirthday; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.net.packet.GenshinPacket; @@ -73,6 +74,7 @@ public class GenshinPlayer { private int nameCardId = 210001; private Position pos; private Position rotation; + private PlayerBirthday birthday; private Map properties; private Set nameCardList; @@ -139,6 +141,8 @@ public class GenshinPlayer { this.combatInvokeHandler = new InvokeHandler(PacketCombatInvocationsNotify.class); this.abilityInvokeHandler = new InvokeHandler(PacketAbilityInvocationsNotify.class); this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class); + + this.birthday = new PlayerBirthday(); } // On player creation @@ -150,6 +154,7 @@ public class GenshinPlayer { this.nickname = "Traveler"; this.signature = ""; this.teamManager = new TeamManager(this); + this.birthday = new PlayerBirthday(); this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1); this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1); this.setProperty(PlayerProperty.PROP_SPRING_AUTO_USE_PERCENT, 50); @@ -642,6 +647,15 @@ public class GenshinPlayer { return onlineInfo.build(); } + public PlayerBirthday getBirthday(){ + return this.birthday; + } + + public void setBirthday(int d, int m) { + this.birthday = new PlayerBirthday(d, m); + this.updateProfile(); + } + public SocialDetail.Builder getSocialDetail() { SocialDetail.Builder social = SocialDetail.newBuilder() .setUid(this.getUid()) @@ -649,7 +663,7 @@ public class GenshinPlayer { .setNickname(this.getNickname()) .setSignature(this.getSignature()) .setLevel(this.getLevel()) - .setBirthday(Birthday.newBuilder()) + .setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty()) .setWorldLevel(this.getWorldLevel()) .setUnk1(1) .setUnk3(1) diff --git a/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java new file mode 100644 index 000000000..733f58ee5 --- /dev/null +++ b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java @@ -0,0 +1,68 @@ +package emu.grasscutter.game.player; + +import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday; + +public class PlayerBirthday { + private int day; + private int month; + + public PlayerBirthday(){ + this.day = 0; + this.month = 0; + } + + public PlayerBirthday(int day, int month){ + this.day = day; + this.month = month; + } + + public PlayerBirthday set(PlayerBirthday birth){ + this.day = birth.day; + this.month = birth.month; + + return this; + } + + public PlayerBirthday set(int d, int m){ + this.day = d; + this.month = m; + + return this; + } + + public PlayerBirthday setDay(int value){ + this.day = value; + return this; + } + + public PlayerBirthday setMonth(int value){ + this.month = value; + return this; + } + + public int getDay(){ + return this.day; + } + + public int getMonth(){ + return this.month; + } + + public Birthday toProto(){ + return Birthday.newBuilder() + .setDay(this.getDay()) + .setMonth(this.getMonth()) + .build(); + } + + public Birthday.Builder getFilledProtoWhenNotEmpty(){ + if(this.getDay() > 0) + { + return Birthday.newBuilder() + .setDay(this.getDay()) + .setMonth(this.getMonth()); + } + + return Birthday.newBuilder(); + } +} \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java new file mode 100644 index 000000000..0edb08f73 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSetPlayerBirthdayReq.java @@ -0,0 +1,38 @@ +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.proto.SetPlayerBirthdayReqOuterClass.SetPlayerBirthdayReq; + +import com.google.gson.Gson; + +@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); + + if(req.getBirth() != null && req.getBirth().getDay() > 0 && req.getBirth().getMonth() > 0) + { + int day = req.getBirth().getDay(); + int month = req.getBirth().getMonth(); + + // 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)); + } + } +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java new file mode 100644 index 000000000..acca25068 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java @@ -0,0 +1,22 @@ +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(GenshinPlayer player) { + super(PacketOpcodes.SetPlayerBirthdayRsp); + + SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder() + .setBirth(player.getBirthday().toProto()) + .build(); + + this.setData(proto); + + if(Grasscutter.getConfig().DebugMode == true) Grasscutter.getLogger().info("Sending packet"); + } +} From 539970fd504d3cd10c81d8dc6edc24e8d8a284ae Mon Sep 17 00:00:00 2001 From: Miyucchi Date: Sat, 23 Apr 2022 03:29:08 +0200 Subject: [PATCH 21/35] Feature: SetBirthdayDate --- .../server/packet/send/PacketSetPlayerBirthdayRsp.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java index acca25068..9b73b6b13 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSetPlayerBirthdayRsp.java @@ -16,7 +16,5 @@ public class PacketSetPlayerBirthdayRsp extends GenshinPacket { .build(); this.setData(proto); - - if(Grasscutter.getConfig().DebugMode == true) Grasscutter.getLogger().info("Sending packet"); } } From 52b7dc5e7f912634c21ae7991271a5455e468497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5BDATA=20EXPUNGED=5D=20=E2=96=88=E2=96=88=E2=96=88?= <26019675+lwd-temp@users.noreply.github.com> Date: Sat, 23 Apr 2022 09:37:30 +0800 Subject: [PATCH 22/35] fix vbs generation when path is empty --- start.cmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/start.cmd b/start.cmd index 8c89f359e..8c525dfc8 100644 --- a/start.cmd +++ b/start.cmd @@ -74,7 +74,9 @@ 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.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k",0 >> "%temp%\proxy.vbs" "%temp%\proxy.vbs" del /f /q "%temp%\proxy.vbs" >nul 2>nul @@ -117,7 +119,9 @@ set DATABASE=true mkdir "%DATABASE_STORAGE_PATH%" >nul 2>nul echo set ws = createobject("wscript.shell") > "%temp%\db.vbs" +if not "%MONGODB_PATH%" == "" ( echo ws.currentdirectory = "%MONGODB_PATH%" >> "%temp%\db.vbs" +) echo ws.run "cmd /c mongod.exe --dbpath "^&chr(34)^&"%DATABASE_STORAGE_PATH%"^&chr(34)^&"",0 >> "%temp%\db.vbs" "%temp%\db.vbs" del /f /q "%temp%\db.vbs" >nul 2>nul From 7b9447602b29a81e9eb17a95fac6c31eb6a3a62b Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Fri, 22 Apr 2022 19:26:48 -0700 Subject: [PATCH 23/35] Change java version requirement in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 853c37ae3..e6843b116 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 * If you update from an older version, delete `config.json` for regeneration ### Prerequisites -* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle required an account to download old builds) +* Java 16 * Mongodb (recommended 4.0+) * Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc. From b98860c48087520c2a62154ba417da3defc89607 Mon Sep 17 00:00:00 2001 From: Magix Date: Fri, 22 Apr 2022 22:34:00 -0400 Subject: [PATCH 24/35] Update the keystore This is for Java 11+ purposes! The existing keystore will **not** work. --- keystore.p12 | Bin 2389 -> 2679 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/keystore.p12 b/keystore.p12 index 9fa5cf19c6611eeada69c4d18df372578eef4845..5ea492e292dce655be2b7b8adaca0293427000d7 100644 GIT binary patch literal 2679 zcmY+EcQ_l27RD1ID$;?_Qc+4N@exGrRch2GV%3UWJ4UreD>O!}qDJi!BSuS&+Iy6i zpkh?*T~(Bt<+}H|_xqmv$9c{<@B5zf=MRa8cvAtXk$8w8m`;G8PT0Q)qy^^SA#e~L z!g?+6jcf*7CJ+W$&bjiW<>!JtIJHS-0K(Z^bHNL9691ZuX#L?PJ}!@YeIAMl)DbtrO}nV;Zp)NVB(>C)_R>* z4y~@nZ!L`PY#FNxkjtAM;liFK>R6BgdMLexsmgcOu#~x=Z|l(Uh5F*6fG>ae&30{B ziW5wt56EN-(gZ_k`dDF0<&_dSlIibux1cCka#ei{mgnt=n4@G^Y{RUrAKCy6Q0Ka>yn5Aa;#q{U#H{(RwA9?C*R#Qh=8J zchloI^d@*K&oe<#(c@9dhgKRUcvH%}*5bIRnaULCS;#H+vk2W3cUdV;q|H1()l^z*iew34!uVG4e|?-QkwE1K7OE9=5DC zxDQ3|2c}*PdD>YWN`;E{q#|4v>$12OtB$UuhaD{%=`PE^u?2(0)Rdp5+Hq^tZ?Y>m z?`OT04a8@6+?O9jKg?ZeL9zJx=R@3&|00qnRULk1(UDxYz9A;Zh>Pi4og?Oa+5&2i zzAFvW6oBcj%J7tB-FMimC;rqR$BmNiJtGt+IUb}h2oz{FeLnJiE3;uLeL|gaRE>w8 zG-qmU$KTct`wS+YVOw)=eZkXJea4vtuH{2xLY18m%$R2rd5^< zQ_k9lcRnTME1yxn=Mk86ieQxP4#uvGW8dZQ{xsUe@u5Fo_hjD0_}N?y&=o02gx3?zkB&3a?7tG{Hw27aN_{S+Ctb__0#~06 z8f8>U#A=l0?Z*o^jJN1n28>1B@7>nTjuF1q2v{o=rWwRA)Zlu}4Et{>V+9;EscZF7 z`Cj@Qgx;nWei&)GeL?&+K0&Rd#0t~ zpiN!F=%>(rPzK9#E`c2_W|-p|nYt9$ZrVHB{G>@~-U6@*tk^Rj)s*;cV9t02sp;vp z@SPz!T@@xQ=^%XZE<0wn14qK4gA@{G!R?Yej^pE^cl{A?;Z}_~L`HCyr(5y2`@{tP zKIP%YX^GnG)6dZ?dM!Gd&j(g6SF!e<1s}ra{5eFSa%!&!%DN1BJ3Da)vEXSP)czh8 zLjl2y1|yZ|A^ua@Cf8NkW5VamOK1(_CPT;ZqZz%Z(nL= zu4i0vJ3&0-m7~l=?0eAp#=d;y$xu0)1z+)uWKVfDO7>E(=>}Jm?az`8~ zE`^dniHIRl=P*tBJ46dU=j-!xDTE3LIB!q>ae)6vT=2h%tBz4}Gs8s!)h<{U^N*_3 z17m4N{zKenc#z@^{(#ny4t=8lW+qwfmqht8Q|L-=8?BkNa|!Q{kBUW4GGR*~?Y05? zi5ce_*S;GRLHXhuxetQY`*+=U@CAb5Hg)vl(i@)7b2WG}xGEBZmr4zt4JNE=gn8?# zzG+XEE!dOA^7E-DonRTZ)L!gw8gFJ5Kd| zh0(MN{LyOBFC6C*ns5J#XB(3t6wyB9B{DC560)qLnBf;; z{s-S}MpkEkJ;%CVl%+l~8DV`h$$b@Pz89S1CWR)i7x`+w{ zOu>5<^%I@A%%%BK_3Wlj3&zw1(Pex=UXyqWg*S3x6EdNH;WF%3j)_Q9sUt zJ6C-Iba@lmI^kRtzB)<4o}IX+pWmyaJ`Z&5rm$5v?2luXZf_)ju*c2;s>yX) z@!d&z*OzIvy~9GICzrK2PfU6;TA0_yKWbmS)8^q?D)=7qX;IDZaJsE;l%F*>vl5o( z$CSBnoZNZGbGl4!brNeYG(5QR;fV##i8ZJ|{Iu`uhLl&-^hu6>o1*QEPaS=q(z?a4 zBszxeFQ>V^cTPC8a_9)p$dN%VF9${N^)jIb(J$w9|SnUY8sg?8aRZ3!r3hqndzQTZ5STxvAZXJVw}}tz&$+%Ilb{ z!mn&6Qg>HL?|`B_LK#!&G>XO(MbA@sp)_M@0e3S=s8EQ>ue7<UAS++yKC*?ogVB|D12Lih$R-+ zWj(yZ&54vpav|x!G>A*oRBSW=5bWdj(E{tjZNniSzfjjxkz2;6ygMLRriLSPwC^qg UvYa-S?yWXMjOjjS5Rj1bFNHevzW@LL literal 2389 zcmY+Ec{~#iAIG=Z?1)XwnQ|ppn33YA%zfmJIm4WV+-Ht5+AkvaH8r9vk#gV5uLF%7 z<(T%9Smiz|w|VOIdYK%8B^*2QDBd1__3hZOO21A7plcKrp~f zB1dqxyxB_xowD1MWzWtL+#lKR#AdD?3=5Vl#dfnFc)9pI7t>iW!aXVhMWrE05v@ES zgDAjTA4DP}M(kXI(v{le9tT6xctP)j}}|yBz<{}HZ)XG<)Urhs+(Te zF=?HNFKbfb5-z@!2%QMK&`7Ax3%{ z>nsu>X_+#XC84}m0IR#K%t(mzcug!|0Mtr*2>n$@{l-|o~>K5dB0$}+@btW7+- z)B-@bD{GzPY89DxdR+;oI+)7*ioU7^_a=ZHFh);3-)eI5kZ$*Kjej>UrsCd}IDhK~ zh55$;s;ow&hu+6_Cqs0oa#a{b`nD7~3m0}vm19T1!)>(vn@5n7vT*`xl}mT??)U@6 zKN~4)7I>68S7*O8)}$$m z7tTc-3bsDGMC}0KI0!TeBlYg}AIK8Lw9Q`i$kw5Vq$d{RGufDu7e?;t95mh1$fd__sI9=tHL5kS<%%chpY!$P!(`8Bpld2v- zb$G7hWM_68emc4e{C<6T5CHM7X`@-3hFabgpW=2)*)t?XRTQJ#!qcl|p-Qr^ODNav zR3Fqe+9@gBHHdU8uc4|5`iLH1egLz{vvg6T z1Kz;GP6JDGA2Sz} z;&n)+K|sRJd0^I?!s=2RFKg$;y!QG{`_;iV%XCftpzfGIOWw*}j=c%95E^MjC=XVe zMB;n$4ZXA?VxW#<^vUXS)N%dm!pt&~ojIXyR$r2ZcI_c^jmwF<*s{%;*KJEXdYa>x zLWrqN(Lz=3eUVBEf5CS_nkO7ET9DQAq4bKEwOyP$l`7Q5qJ(eVpJ?AgjxZrl@iNYh zeknZN`-wqjyA^|GlKR_O24VaY^Or@0YB`a$L6NIhw)%(VY9wVSj81{0(7I>e`}q-) zm|gv!G8xNVQ1+|xA*+3!c#QAjH>2GYN#MEJc0Ivmb?jJLAW-btGfFE1R2DW*@^0ofpe#sDAfDe3~w|6n9z`XpKd)crV%7sS*x; z$R~nSMX9&ofZXsoz85RP*u^JmZ;b>H0Evdd_!!i^pm(@ z_Cx(^+eNt-?lfQJ^;4K}ji-|5Ugx}R%Pbk;GDp@vh*0p^47vr5rkLi=bTvZ3)$f~} zy>&jS;UU<2M#|&@#Mwne1wxy_W2j*3*=5Z}@p~kAkqW&CvNV;hG$;AS=YULJc|C01 z6K{1Ww$ota44>-g-aByQRQ1Ni-l_OYE!98MGubHlB`eU!4>ON-{mZ=JPC54l^$8PU z_A^BZ08XrHW0cyn#pz`e=C#GSzC_dMmG^6O0vx}gw_sWmJcdEvx@Q~J5!RP`_FysCx1CD1u9vyEE4Q!?!$Q+%eP4nz%zPDDW_UtS(wpWuv!sfjnN4=v- zM|g6_2p!${!W;hd)Z%HBzJNz+K<(5hFU4katWn>os}Y>OzVp-&#VpocwMOEGwErGW z8el5z=K2k5bTAJ|asnn7J(mk6`{Ec~$1 z-KeTHi zgke-L5*RoqL;=YG5`h4~Xt(}3K%|OqA`Acgr_%+A-sBE#C>SOj?p>dLp9T26lK%o^ C169fZ From 0992fc11b4093229e70803a61767010358b99b86 Mon Sep 17 00:00:00 2001 From: Magix Date: Fri, 22 Apr 2022 23:53:37 -0400 Subject: [PATCH 25/35] Add keystore password --- src/main/java/emu/grasscutter/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 4a6f71680..980102957 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -29,7 +29,7 @@ public final class Config { public int Port = 443; public int PublicPort = 0; public String KeystorePath = "./keystore.p12"; - public String KeystorePassword = ""; + public String KeystorePassword = "123456"; public Boolean UseSSL = true; public Boolean FrontHTTPS = true; From 8afcc0b89a7fb45f29af3c03c6ba71c6c8aa46dc Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Sat, 23 Apr 2022 02:20:18 -0400 Subject: [PATCH 26/35] Add message for bind failure (HTTP) --- .../grasscutter/netty/MihoyoKcpServer.java | 5 ++-- .../server/dispatch/DispatchServer.java | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/netty/MihoyoKcpServer.java b/src/main/java/emu/grasscutter/netty/MihoyoKcpServer.java index c3a9297b2..41e8ad412 100644 --- a/src/main/java/emu/grasscutter/netty/MihoyoKcpServer.java +++ b/src/main/java/emu/grasscutter/netty/MihoyoKcpServer.java @@ -64,9 +64,8 @@ public class MihoyoKcpServer extends Thread { // Wait until the server socket is closed. f.channel().closeFuture().sync(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (Exception exception) { + Grasscutter.getLogger().error("Unable to start game server.", exception); } finally { // Close finish(); diff --git a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java index 7c7915675..ea7c1166e 100644 --- a/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java +++ b/src/main/java/emu/grasscutter/server/dispatch/DispatchServer.java @@ -24,6 +24,7 @@ import emu.grasscutter.utils.Utils; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import java.io.*; +import java.net.BindException; import java.net.InetSocketAddress; import java.net.URI; import java.net.URLDecoder; @@ -158,12 +159,21 @@ public final class DispatchServer { Grasscutter.getLogger().error("[Dispatch] Error while initializing region info!", e); } } + + private HttpServer safelyCreateServer(InetSocketAddress address) { + try { + return HttpServer.create(address, 0); + } catch (BindException ignored) { + Grasscutter.getLogger().error("Unable to bind to port: " + getAddress().getPort() + " (HTTP)"); + } catch (Exception exception) { + Grasscutter.getLogger().error("Unable to start HTTP server.", exception); + } return null; + } public void start() throws Exception { HttpServer server; if (Grasscutter.getConfig().getDispatchOptions().UseSSL) { - HttpsServer httpsServer; - httpsServer = HttpsServer.create(getAddress(), 0); + HttpsServer httpsServer = HttpsServer.create(getAddress(), 0); SSLContext sslContext = SSLContext.getInstance("TLS"); try (FileInputStream fis = new FileInputStream(Grasscutter.getConfig().getDispatchOptions().KeystorePath)) { char[] keystorePassword = Grasscutter.getConfig().getDispatchOptions().KeystorePassword.toCharArray(); @@ -176,14 +186,20 @@ public final class DispatchServer { httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); server = httpsServer; + } catch (BindException ignored) { + Grasscutter.getLogger().error("Unable to bind to port: " + getAddress().getPort() + " (HTTPS)"); + server = this.safelyCreateServer(this.getAddress()); } catch (Exception e) { Grasscutter.getLogger().warn("[Dispatch] No SSL cert found! Falling back to HTTP server."); Grasscutter.getConfig().getDispatchOptions().UseSSL = false; - server = HttpServer.create(getAddress(), 0); + server = this.safelyCreateServer(this.getAddress()); } } else { - server = HttpServer.create(getAddress(), 0); + server = this.safelyCreateServer(this.getAddress()); } + + if(server == null) + throw new NullPointerException("An HTTP server was not created."); server.createContext("/", t -> responseHTML(t, "Hello")); From 1c3df04f4505a5adc26e719b48a13fe8d89d603a Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Sat, 23 Apr 2022 15:33:10 +0800 Subject: [PATCH 27/35] Fix proxy daemon can't find script Signed-off-by: Jaida Wu --- start.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.cmd b/start.cmd index 8c525dfc8..8d682a213 100644 --- a/start.cmd +++ b/start.cmd @@ -75,9 +75,9 @@ 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",0 >> "%temp%\proxy.vbs" "%temp%\proxy.vbs" del /f /q "%temp%\proxy.vbs" >nul 2>nul From cd08c52b359ed1a8c3e7019d806d1c6eb3542a2c Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Sat, 23 Apr 2022 15:39:56 +0800 Subject: [PATCH 28/35] Fix PlayerBirthday exception Signed-off-by: Jaida Wu --- src/main/java/emu/grasscutter/game/player/PlayerBirthday.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java index 733f58ee5..13a8e7c58 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerBirthday.java @@ -1,7 +1,9 @@ package emu.grasscutter.game.player; +import dev.morphia.annotations.Entity; import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday; +@Entity public class PlayerBirthday { private int day; private int month; From 3eabd4034520906cd91774787fc0ef3c944b8e17 Mon Sep 17 00:00:00 2001 From: Jaida Wu Date: Sat, 23 Apr 2022 16:47:13 +0800 Subject: [PATCH 29/35] Make some control panel happy Signed-off-by: Jaida Wu --- src/main/java/emu/grasscutter/Grasscutter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index ad1107e8e..5335a2254 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -118,6 +118,7 @@ public final class Grasscutter { public static void startConsole() { String input; + getLogger().info("Done! For help, type \"help\""); try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { while ((input = br.readLine()) != null) { try { From 91894380cbf8710052d19ebf297c632d4320f02d Mon Sep 17 00:00:00 2001 From: TheLostTree <65834918+TheLostTree@users.noreply.github.com> Date: Sat, 23 Apr 2022 03:19:33 -0700 Subject: [PATCH 30/35] drowning added --- .../recv/HandlerSceneEntityDrownReq.java | 43 +++++++++++++++++++ .../send/PacketSceneEntityDrownRsp.java | 4 ++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java create mode 100644 src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java new file mode 100644 index 000000000..91f27c65b --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java @@ -0,0 +1,43 @@ +package emu.grasscutter.server.packet.recv; + +import emu.grasscutter.game.entity.GenshinEntity; +import emu.grasscutter.game.props.LifeState; +import emu.grasscutter.net.packet.Opcodes; +import emu.grasscutter.net.packet.PacketHandler; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityDrownReqOuterClass.SceneEntityDrownReq; +import emu.grasscutter.net.proto.VisionTypeOuterClass; +import emu.grasscutter.server.game.GameSession; +import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeRsp; +import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; +import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify; +import emu.grasscutter.server.packet.send.PacketSceneEntityDrownRsp; + +@Opcodes(PacketOpcodes.SceneEntityDrownReq) +public class HandlerSceneEntityDrownReq extends PacketHandler { + + @Override + public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { + SceneEntityDrownReq req = SceneEntityDrownReq.parseFrom(payload); + + + GenshinEntity entity = session.getPlayer().getScene().getEntityById(req.getEntityId()); + + + PacketLifeStateChangeNotify lifeStateChangeNotify = new PacketLifeStateChangeNotify(entity, entity, LifeState.LIFE_DEAD); + PacketSceneEntityDrownRsp drownRsp = new PacketSceneEntityDrownRsp(req.getEntityId()); + + + + //kill entity + broadcast it + + session.getPlayer().getScene().broadcastPacket(lifeStateChangeNotify); + session.getPlayer().getScene().broadcastPacket(drownRsp); + + //TODO: make a list somewhere of all entities to remove per tick rather than one by one + + session.getPlayer().getScene().removeEntity(entity, VisionTypeOuterClass.VisionType.VisionDie); + + } + +} diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java new file mode 100644 index 000000000..2918c2f66 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java @@ -0,0 +1,4 @@ +package emu.grasscutter.server.packet.send; + +public class PacketSceneEntityDrownReq { +} From 3d9b71dc4d4f376a175b36d53b5734b900fc5a2e Mon Sep 17 00:00:00 2001 From: TheLostTree <65834918+TheLostTree@users.noreply.github.com> Date: Sat, 23 Apr 2022 03:32:08 -0700 Subject: [PATCH 31/35] git doesnt like me --- .../recv/HandlerSceneEntityDrownReq.java | 2 -- .../packet/send/PacketSceneEntityDrownRsp.java | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java index 91f27c65b..005141958 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneEntityDrownReq.java @@ -8,9 +8,7 @@ import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.SceneEntityDrownReqOuterClass.SceneEntityDrownReq; import emu.grasscutter.net.proto.VisionTypeOuterClass; import emu.grasscutter.server.game.GameSession; -import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeRsp; import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; -import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify; import emu.grasscutter.server.packet.send.PacketSceneEntityDrownRsp; @Opcodes(PacketOpcodes.SceneEntityDrownReq) diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java index 2918c2f66..4d3a2b232 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneEntityDrownRsp.java @@ -1,4 +1,20 @@ package emu.grasscutter.server.packet.send; -public class PacketSceneEntityDrownReq { +import emu.grasscutter.game.entity.GenshinEntity; +import emu.grasscutter.net.packet.GenshinPacket; +import emu.grasscutter.net.packet.PacketOpcodes; +import emu.grasscutter.net.proto.SceneEntityDrownRspOuterClass.SceneEntityDrownRsp; +import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; + +public class PacketSceneEntityDrownRsp extends GenshinPacket { + + public PacketSceneEntityDrownRsp(int entityId) { + super(PacketOpcodes.SceneEntityDrownRsp); + + SceneEntityDrownRsp proto = new SceneEntityDrownRsp().toBuilder().setEntityId(entityId).build(); + + this.setData(proto); + } } + + From 31f617e7f0a0c034c6b64f53318257fbba1477f0 Mon Sep 17 00:00:00 2001 From: TheLostTree <65834918+TheLostTree@users.noreply.github.com> Date: Sat, 23 Apr 2022 03:32:18 -0700 Subject: [PATCH 32/35] Update Grasscutter-Protos --- Grasscutter-Protos | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grasscutter-Protos b/Grasscutter-Protos index 0537e9cc4..dd17415b7 160000 --- a/Grasscutter-Protos +++ b/Grasscutter-Protos @@ -1 +1 @@ -Subproject commit 0537e9cc4c7856a7c6f88bbbaa908a80c4ee677e +Subproject commit dd17415b71dfcff049e72dbe8a76173611f4b0ae From 6a4534d33d9a5d73845c9d585e0b031fc7975e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9C=9F=E5=BF=83?= <1307993674@qq.com> Date: Sat, 23 Apr 2022 20:51:36 +0800 Subject: [PATCH 33/35] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6843b116..311e764cd 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6 2. Set network proxy to `127.0.0.1:8080` or the proxy port you specified. 4. *yoink* -* or you can use `run.cmd` to start Server & Proxy daemon with one click +* or you can use `start.cmd` to start Server & Proxy daemon with one click # Grasscutter commands There is a dummy user named "Server" in every player's friends list that you can message to use commands. Commands also work in other chat rooms, such as private/team chats. From 301d0a174c29d543df65aa0437eb61b90ce52a9f Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 23 Apr 2022 21:13:45 +0800 Subject: [PATCH 34/35] Add another way to set talent level --- .../command/commands/TalentCommand.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index 2ced6f1c3..21cf66249 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -2,6 +2,7 @@ package emu.grasscutter.command.commands; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.def.AvatarSkillDepotData; import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.entity.EntityAvatar; @@ -21,8 +22,9 @@ public class TalentCommand implements CommandHandler { return; } - if (args.size() < 0 || args.size() < 1){ + if (args.size() < 1){ CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "Another way to set talent level: /talent "); CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); return; } @@ -31,6 +33,7 @@ public class TalentCommand implements CommandHandler { switch (cmdSwitch) { default: CommandHandler.sendMessage(sender, "To set talent level: /talent set "); + CommandHandler.sendMessage(sender, "Another way to set talent level: /talent "); CommandHandler.sendMessage(sender, "To get talent ID: /talent getid"); return; case "set": @@ -90,6 +93,45 @@ public class TalentCommand implements CommandHandler { return; } + break; + case "n": case "e": case "q": + try { + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + GenshinAvatar avatar = entity.getAvatar(); + AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot(); + int skillId; + switch (cmdSwitch) { + default: + skillId = SkillDepot.getSkills().get(0); + break; + case "e": + skillId = SkillDepot.getSkills().get(1); + break; + case "q": + skillId = SkillDepot.getEnergySkill(); + break; + } + int nextLevel = Integer.parseInt(args.get(1)); + int currentLevel = avatar.getSkillLevelMap().get(skillId); + if (args.size() < 1){ + CommandHandler.sendMessage(sender, "To set talent level: /talent "); + return; + } + if (nextLevel > 16){ + CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16"); + return; + } + // Upgrade skill + avatar.getSkillLevelMap().put(skillId, nextLevel); + avatar.save(); + // Packet + sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel)); + sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel)); + CommandHandler.sendMessage(sender, "Set this talent to " + nextLevel + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid talent level."); + return; + } break; case "getid": EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); From 2dd8932144c8808af5c6aa288ed0a7e8d0e6e30b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sun, 24 Apr 2022 03:10:07 +0800 Subject: [PATCH 35/35] Add Teleport command --- .../command/commands/PositionCommand.java | 3 +- .../command/commands/TelePortCommand.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/emu/grasscutter/command/commands/TelePortCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java index 639301c7f..8bdf3c754 100644 --- a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java @@ -17,6 +17,7 @@ public final class PositionCommand implements CommandHandler { return; } - sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ())); + sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f\nScene id: %d", + sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ(), sender.getSceneId())); } } diff --git a/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java new file mode 100644 index 000000000..1a9e4f87a --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/TelePortCommand.java @@ -0,0 +1,43 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.utils.Position; + +import java.util.List; + +@Command(label = "teleport", usage = "teleport ", aliases = {"tp"}, + description = "Change the player's position.", permission = "player.teleport") +public class TelePortCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 3){ + CommandHandler.sendMessage(sender, "Usage: /tp [scene id]"); + return; + } + + try { + float x = Float.parseFloat(args.get(0)); + float y = Float.parseFloat(args.get(1)); + float z = Float.parseFloat(args.get(2)); + int sceneId = sender.getSceneId(); + if (args.size() == 4){ + sceneId = Integer.parseInt(args.get(3)); + } + Position target = new Position(x, y, z); + boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, target); + if (!result) { + CommandHandler.sendMessage(sender, "Invalid position."); + } + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid position."); + } + } +}