mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 09:56:57 +00:00
Merge branch 'development' into xmplay-readme
This commit is contained in:
commit
262a049bd7
7
.gitignore
vendored
7
.gitignore
vendored
@ -47,12 +47,13 @@ tmp/
|
|||||||
|
|
||||||
# Grasscutter
|
# Grasscutter
|
||||||
resources/*
|
resources/*
|
||||||
|
logs/*
|
||||||
data/AbilityEmbryos.json
|
data/AbilityEmbryos.json
|
||||||
data/OpenConfig.json
|
data/OpenConfig.json
|
||||||
proto/auto/
|
proto/auto/
|
||||||
proto/protoc.exe
|
proto/protoc.exe
|
||||||
GM Handbook.txt
|
GM Handbook.txt
|
||||||
config.json
|
config.json
|
||||||
mitmdump.exe
|
mitmdump.exe
|
||||||
grasscutter.jar
|
grasscutter.jar
|
||||||
mongod.exe
|
mongod.exe
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 0537e9cc4c7856a7c6f88bbbaa908a80c4ee677e
|
Subproject commit dd17415b71dfcff049e72dbe8a76173611f4b0ae
|
@ -16,7 +16,7 @@ A WIP server reimplementation for *some anime game* 2.3-2.6
|
|||||||
* If you updated from an older version, delete `config.json` to regenerate it.
|
* If you updated from an older version, delete `config.json` to regenerate it.
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle requires an account to download old builds)
|
* Java 16
|
||||||
* Mongodb (recommended 4.0+)
|
* Mongodb (recommended 4.0+)
|
||||||
* Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc.
|
* Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc.
|
||||||
|
|
||||||
@ -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.
|
2. Set network proxy to `127.0.0.1:8080` or the proxy port you specified.
|
||||||
4. *yoink*
|
4. *yoink*
|
||||||
|
|
||||||
* or you can use `run.cmd` to start the Server & Proxy daemon with one click
|
* or you can use `start.cmd` to start Server & Proxy daemon with one click
|
||||||
|
|
||||||
# Grasscutter commands
|
# 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.
|
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.
|
||||||
|
11
build.gradle
11
build.gradle
@ -14,17 +14,16 @@ plugins {
|
|||||||
id 'application'
|
id 'application'
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 16
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 16
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
||||||
|
|
||||||
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
|
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-core', version: '1.2.6'
|
||||||
implementation group: 'ch.qos.logback', name: 'logback-classic', 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.code.gson', name: 'gson', version: '2.8.8'
|
||||||
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1'
|
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'
|
implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1'
|
||||||
}
|
}
|
||||||
|
BIN
keystore.p12
BIN
keystore.p12
Binary file not shown.
4
proxy.py
4
proxy.py
@ -57,7 +57,9 @@ class MlgmXyysd_Genshin_Impact_Proxy:
|
|||||||
"minor-api.mihoyo.com",
|
"minor-api.mihoyo.com",
|
||||||
"public-data-api.mihoyo.com",
|
"public-data-api.mihoyo.com",
|
||||||
"uspider.yuanshen.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:
|
def request(self, flow: http.HTTPFlow) -> None:
|
||||||
|
@ -27,9 +27,11 @@ public final class Config {
|
|||||||
public String Ip = "0.0.0.0";
|
public String Ip = "0.0.0.0";
|
||||||
public String PublicIp = "127.0.0.1";
|
public String PublicIp = "127.0.0.1";
|
||||||
public int Port = 443;
|
public int Port = 443;
|
||||||
|
public int PublicPort = 0;
|
||||||
public String KeystorePath = "./keystore.p12";
|
public String KeystorePath = "./keystore.p12";
|
||||||
public String KeystorePassword = "";
|
public String KeystorePassword = "123456";
|
||||||
public Boolean UseSSL = true;
|
public Boolean UseSSL = true;
|
||||||
|
public Boolean FrontHTTPS = true;
|
||||||
|
|
||||||
public boolean AutomaticallyCreateAccounts = false;
|
public boolean AutomaticallyCreateAccounts = false;
|
||||||
|
|
||||||
@ -52,6 +54,7 @@ public final class Config {
|
|||||||
public String Ip = "0.0.0.0";
|
public String Ip = "0.0.0.0";
|
||||||
public String PublicIp = "127.0.0.1";
|
public String PublicIp = "127.0.0.1";
|
||||||
public int Port = 22102;
|
public int Port = 22102;
|
||||||
|
public int PublicPort = 0;
|
||||||
|
|
||||||
public String DispatchServerDatabaseUrl = "mongodb://localhost:27017";
|
public String DispatchServerDatabaseUrl = "mongodb://localhost:27017";
|
||||||
public String DispatchServerDatabaseCollection = "grasscutter";
|
public String DispatchServerDatabaseCollection = "grasscutter";
|
||||||
|
@ -34,7 +34,7 @@ public final class Grasscutter {
|
|||||||
private static DispatchServer dispatchServer;
|
private static DispatchServer dispatchServer;
|
||||||
private static GameServer gameServer;
|
private static GameServer gameServer;
|
||||||
|
|
||||||
public static final Reflections reflector = new Reflections();
|
public static final Reflections reflector = new Reflections("emu.grasscutter");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Declare logback configuration.
|
// Declare logback configuration.
|
||||||
@ -118,6 +118,7 @@ public final class Grasscutter {
|
|||||||
|
|
||||||
public static void startConsole() {
|
public static void startConsole() {
|
||||||
String input;
|
String input;
|
||||||
|
getLogger().info("Done! For help, type \"help\"");
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
|
||||||
while ((input = br.readLine()) != null) {
|
while ((input = br.readLine()) != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -11,6 +11,7 @@ import java.util.*;
|
|||||||
public final class CommandMap {
|
public final class CommandMap {
|
||||||
private final Map<String, CommandHandler> commands = new HashMap<>();
|
private final Map<String, CommandHandler> commands = new HashMap<>();
|
||||||
private final Map<String, Command> annotations = new HashMap<>();
|
private final Map<String, Command> annotations = new HashMap<>();
|
||||||
|
|
||||||
public CommandMap() {
|
public CommandMap() {
|
||||||
this(false);
|
this(false);
|
||||||
}
|
}
|
||||||
|
@ -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<String> 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()));
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ public final class PositionCommand implements CommandHandler {
|
|||||||
return;
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,149 @@
|
|||||||
|
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;
|
||||||
|
import emu.grasscutter.server.packet.send.PacketAvatarSkillChangeNotify;
|
||||||
|
import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Command(label = "talent", usage = "talent <talentID> <value>",
|
||||||
|
description = "Set talent level for your current active character", permission = "player.settalent")
|
||||||
|
public class TalentCommand implements CommandHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(GenshinPlayer sender, List<String> args) {
|
||||||
|
if (sender == null) {
|
||||||
|
CommandHandler.sendMessage(null, "Run this command in-game.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() < 1){
|
||||||
|
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
|
||||||
|
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
|
||||||
|
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 <talentID> <value>");
|
||||||
|
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
|
||||||
|
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 <talentID> <value>");
|
||||||
|
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 "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 <n or e or q> <value>");
|
||||||
|
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();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 <x> <y> <z>", aliases = {"tp"},
|
||||||
|
description = "Change the player's position.", permission = "player.teleport")
|
||||||
|
public class TelePortCommand implements CommandHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(GenshinPlayer sender, List<String> args) {
|
||||||
|
if (sender == null) {
|
||||||
|
CommandHandler.sendMessage(null, "Run this command in-game.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() < 3){
|
||||||
|
CommandHandler.sendMessage(sender, "Usage: /tp <x> <y> <z> [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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ package emu.grasscutter.database;
|
|||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Id;
|
import dev.morphia.annotations.Id;
|
||||||
|
|
||||||
@Entity(value = "counters", noClassnameStored = true)
|
@Entity(value = "counters", useDiscriminator = false)
|
||||||
public class DatabaseCounter {
|
public class DatabaseCounter {
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
@ -2,41 +2,33 @@ package emu.grasscutter.database;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.mongodb.WriteResult;
|
import com.mongodb.client.result.DeleteResult;
|
||||||
|
import dev.morphia.query.experimental.filters.Filters;
|
||||||
import dev.morphia.query.FindOptions;
|
|
||||||
import dev.morphia.query.Query;
|
|
||||||
import dev.morphia.query.internal.MorphiaCursor;
|
|
||||||
import emu.grasscutter.GenshinConstants;
|
import emu.grasscutter.GenshinConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
|
||||||
import emu.grasscutter.game.Account;
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.game.GenshinPlayer;
|
import emu.grasscutter.game.GenshinPlayer;
|
||||||
import emu.grasscutter.game.avatar.GenshinAvatar;
|
import emu.grasscutter.game.avatar.GenshinAvatar;
|
||||||
import emu.grasscutter.game.friends.Friendship;
|
import emu.grasscutter.game.friends.Friendship;
|
||||||
import emu.grasscutter.game.inventory.GenshinItem;
|
import emu.grasscutter.game.inventory.GenshinItem;
|
||||||
|
|
||||||
public class DatabaseHelper {
|
public final class DatabaseHelper {
|
||||||
|
|
||||||
protected static FindOptions FIND_ONE = new FindOptions().limit(1);
|
|
||||||
|
|
||||||
public static Account createAccount(String username) {
|
public static Account createAccount(String username) {
|
||||||
return createAccountWithId(username, 0);
|
return createAccountWithId(username, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account createAccountWithId(String username, int reservedId) {
|
public static Account createAccountWithId(String username, int reservedId) {
|
||||||
// Unique names only
|
// Unique names only
|
||||||
Account exists = DatabaseHelper.getAccountByName(username);
|
Account exists = DatabaseHelper.getAccountByName(username);
|
||||||
if (exists != null) {
|
if (exists != null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure there are no id collisions
|
// Make sure there are no id collisions
|
||||||
if (reservedId > 0) {
|
if (reservedId > 0) {
|
||||||
// Cannot make account with the same uid as the server console
|
// Cannot make account with the same uid as the server console
|
||||||
if (reservedId == GenshinConstants.SERVER_CONSOLE_UID) {
|
if (reservedId == GenshinConstants.SERVER_CONSOLE_UID) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
exists = DatabaseHelper.getAccountByPlayerId(reservedId);
|
exists = DatabaseHelper.getAccountByPlayerId(reservedId);
|
||||||
if (exists != null) {
|
if (exists != null) {
|
||||||
return null;
|
return null;
|
||||||
@ -47,10 +39,10 @@ public class DatabaseHelper {
|
|||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
account.setUsername(username);
|
account.setUsername(username);
|
||||||
account.setId(Integer.toString(DatabaseManager.getNextId(account)));
|
account.setId(Integer.toString(DatabaseManager.getNextId(account)));
|
||||||
|
|
||||||
if (reservedId > 0) {
|
if (reservedId > 0) {
|
||||||
account.setPlayerId(reservedId);
|
account.setPlayerId(reservedId);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseHelper.saveAccount(account);
|
DatabaseHelper.saveAccount(account);
|
||||||
return account;
|
return account;
|
||||||
@ -63,65 +55,52 @@ public class DatabaseHelper {
|
|||||||
if (exists != null) {
|
if (exists != null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
account.setId(Integer.toString(DatabaseManager.getNextId(account)));
|
account.setId(Integer.toString(DatabaseManager.getNextId(account)));
|
||||||
account.setUsername(username);
|
account.setUsername(username);
|
||||||
account.setPassword(password);
|
account.setPassword(password);
|
||||||
DatabaseHelper.saveAccount(account);
|
DatabaseHelper.saveAccount(account);
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAccount(Account account) {
|
public static void saveAccount(Account account) {
|
||||||
DatabaseManager.getAccountDatastore().save(account);
|
DatabaseManager.getAccountDatastore().save(account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account getAccountByName(String username) {
|
public static Account getAccountByName(String username) {
|
||||||
MorphiaCursor<Account> cursor = DatabaseManager.getAccountDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username).find(FIND_ONE);
|
return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).first();
|
||||||
if (!cursor.hasNext()) return null;
|
|
||||||
return cursor.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account getAccountByToken(String token) {
|
public static Account getAccountByToken(String token) {
|
||||||
if (token == null) return null;
|
if(token == null) return null;
|
||||||
MorphiaCursor<Account> cursor = DatabaseManager.getAccountDatastore().createQuery(Account.class).field("token").equal(token).find(FIND_ONE);
|
return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("token", token)).first();
|
||||||
if (!cursor.hasNext()) return null;
|
|
||||||
return cursor.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account getAccountById(String uid) {
|
public static Account getAccountById(String uid) {
|
||||||
MorphiaCursor<Account> cursor = DatabaseManager.getAccountDatastore().createQuery(Account.class).field("_id").equal(uid).find(FIND_ONE);
|
return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("_id", uid)).first();
|
||||||
if (!cursor.hasNext()) return null;
|
|
||||||
return cursor.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account getAccountByPlayerId(int playerId) {
|
public static Account getAccountByPlayerId(int playerId) {
|
||||||
MorphiaCursor<Account> cursor = DatabaseManager.getAccountDatastore().createQuery(Account.class).field("playerId").equal(playerId).find(FIND_ONE);
|
return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("playerId", playerId)).first();
|
||||||
if (!cursor.hasNext()) return null;
|
|
||||||
return cursor.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteAccount(String username) {
|
public static boolean deleteAccount(String username) {
|
||||||
Query<Account> q = DatabaseManager.getAccountDatastore().createQuery(Account.class).field("username").equalIgnoreCase(username);
|
return DatabaseManager.getDatastore().find(Account.class).filter(Filters.eq("username", username)).delete().getDeletedCount() > 0;
|
||||||
return DatabaseManager.getDatastore().findAndDelete(q) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenshinPlayer getPlayerById(int id) {
|
public static GenshinPlayer getPlayerById(int id) {
|
||||||
Query<GenshinPlayer> query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id);
|
return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first();
|
||||||
MorphiaCursor<GenshinPlayer> cursor = query.find(FIND_ONE);
|
|
||||||
if (!cursor.hasNext()) return null;
|
|
||||||
return cursor.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkPlayerExists(int id) {
|
public static boolean checkPlayerExists(int id) {
|
||||||
MorphiaCursor<GenshinPlayer> query = DatabaseManager.getDatastore().createQuery(GenshinPlayer.class).field("_id").equal(id).find(FIND_ONE);
|
return DatabaseManager.getDatastore().find(GenshinPlayer.class).filter(Filters.eq("_id", id)).first() != null;
|
||||||
return query.hasNext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized GenshinPlayer createPlayer(GenshinPlayer character, int reservedId) {
|
public static synchronized GenshinPlayer createPlayer(GenshinPlayer character, int reservedId) {
|
||||||
// Check if reserved id
|
// Check if reserved id
|
||||||
int id = 0;
|
int id;
|
||||||
if (reservedId > 0 && !checkPlayerExists(reservedId)) {
|
if (reservedId > 0 && !checkPlayerExists(reservedId)) {
|
||||||
id = reservedId;
|
id = reservedId;
|
||||||
character.setUid(id);
|
character.setUid(id);
|
||||||
@ -136,10 +115,10 @@ public class DatabaseHelper {
|
|||||||
DatabaseManager.getDatastore().save(character);
|
DatabaseManager.getDatastore().save(character);
|
||||||
return character;
|
return character;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int getNextPlayerId(int reservedId) {
|
public static synchronized int getNextPlayerId(int reservedId) {
|
||||||
// Check if reserved id
|
// Check if reserved id
|
||||||
int id = 0;
|
int id;
|
||||||
if (reservedId > 0 && !checkPlayerExists(reservedId)) {
|
if (reservedId > 0 && !checkPlayerExists(reservedId)) {
|
||||||
id = reservedId;
|
id = reservedId;
|
||||||
} else {
|
} else {
|
||||||
@ -150,41 +129,37 @@ public class DatabaseHelper {
|
|||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void savePlayer(GenshinPlayer character) {
|
public static void savePlayer(GenshinPlayer character) {
|
||||||
DatabaseManager.getDatastore().save(character);
|
DatabaseManager.getDatastore().save(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAvatar(GenshinAvatar avatar) {
|
public static void saveAvatar(GenshinAvatar avatar) {
|
||||||
DatabaseManager.getDatastore().save(avatar);
|
DatabaseManager.getDatastore().save(avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<GenshinAvatar> getAvatars(GenshinPlayer player) {
|
public static List<GenshinAvatar> getAvatars(GenshinPlayer player) {
|
||||||
Query<GenshinAvatar> query = DatabaseManager.getDatastore().createQuery(GenshinAvatar.class).filter("ownerId", player.getUid());
|
return DatabaseManager.getDatastore().find(GenshinAvatar.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList();
|
||||||
return query.find().toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveItem(GenshinItem item) {
|
public static void saveItem(GenshinItem item) {
|
||||||
DatabaseManager.getDatastore().save(item);
|
DatabaseManager.getDatastore().save(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteItem(GenshinItem item) {
|
public static boolean deleteItem(GenshinItem item) {
|
||||||
WriteResult result = DatabaseManager.getDatastore().delete(item);
|
DeleteResult result = DatabaseManager.getDatastore().delete(item);
|
||||||
return result.wasAcknowledged();
|
return result.wasAcknowledged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<GenshinItem> getInventoryItems(GenshinPlayer player) {
|
public static List<GenshinItem> getInventoryItems(GenshinPlayer player) {
|
||||||
Query<GenshinItem> query = DatabaseManager.getDatastore().createQuery(GenshinItem.class).filter("ownerId", player.getUid());
|
return DatabaseManager.getDatastore().find(GenshinItem.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList();
|
||||||
return query.find().toList();
|
|
||||||
}
|
}
|
||||||
public static List<Friendship> getFriends(GenshinPlayer player) {
|
public static List<Friendship> getFriends(GenshinPlayer player) {
|
||||||
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("ownerId", player.getUid());
|
return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("ownerId", player.getUid())).stream().toList();
|
||||||
return query.find().toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Friendship> getReverseFriends(GenshinPlayer player) {
|
public static List<Friendship> getReverseFriends(GenshinPlayer player) {
|
||||||
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class).filter("friendId", player.getUid());
|
return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("friendId", player.getUid())).stream().toList();
|
||||||
return query.find().toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveFriendship(Friendship friendship) {
|
public static void saveFriendship(Friendship friendship) {
|
||||||
@ -196,13 +171,9 @@ public class DatabaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Friendship getReverseFriendship(Friendship friendship) {
|
public static Friendship getReverseFriendship(Friendship friendship) {
|
||||||
Query<Friendship> query = DatabaseManager.getDatastore().createQuery(Friendship.class);
|
return DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.and(
|
||||||
query.and(
|
Filters.eq("ownerId", friendship.getFriendId()),
|
||||||
query.criteria("ownerId").equal(friendship.getFriendId()),
|
Filters.eq("friendId", friendship.getOwnerId())
|
||||||
query.criteria("friendId").equal(friendship.getOwnerId())
|
)).first();
|
||||||
);
|
|
||||||
MorphiaCursor<Friendship> reverseFriendship = query.find(FIND_ONE);
|
|
||||||
if (!reverseFriendship.hasNext()) return null;
|
|
||||||
return reverseFriendship.next();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
package emu.grasscutter.database;
|
package emu.grasscutter.database;
|
||||||
|
|
||||||
import com.mongodb.MongoClient;
|
|
||||||
import com.mongodb.MongoClientURI;
|
import com.mongodb.MongoClientURI;
|
||||||
import com.mongodb.MongoCommandException;
|
import com.mongodb.MongoCommandException;
|
||||||
|
import com.mongodb.client.MongoClient;
|
||||||
|
import com.mongodb.client.MongoClients;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import com.mongodb.client.MongoIterable;
|
import com.mongodb.client.MongoIterable;
|
||||||
|
|
||||||
import dev.morphia.Datastore;
|
import dev.morphia.Datastore;
|
||||||
import dev.morphia.Morphia;
|
import dev.morphia.Morphia;
|
||||||
|
import dev.morphia.mapping.MapperOptions;
|
||||||
|
import dev.morphia.query.experimental.filters.Filters;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.game.Account;
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.game.GenshinPlayer;
|
import emu.grasscutter.game.GenshinPlayer;
|
||||||
@ -16,6 +19,7 @@ import emu.grasscutter.game.friends.Friendship;
|
|||||||
import emu.grasscutter.game.inventory.GenshinItem;
|
import emu.grasscutter.game.inventory.GenshinItem;
|
||||||
|
|
||||||
public final class DatabaseManager {
|
public final class DatabaseManager {
|
||||||
|
|
||||||
private static MongoClient mongoClient;
|
private static MongoClient mongoClient;
|
||||||
private static MongoClient dispatchMongoClient;
|
private static MongoClient dispatchMongoClient;
|
||||||
|
|
||||||
@ -26,15 +30,11 @@ public final class DatabaseManager {
|
|||||||
DatabaseCounter.class, Account.class, GenshinPlayer.class, GenshinAvatar.class, GenshinItem.class, Friendship.class
|
DatabaseCounter.class, Account.class, GenshinPlayer.class, GenshinAvatar.class, GenshinItem.class, Friendship.class
|
||||||
};
|
};
|
||||||
|
|
||||||
public static MongoClient getMongoClient() {
|
public static Datastore getDatastore() {
|
||||||
return mongoClient;
|
return datastore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Datastore getDatastore() {
|
public static MongoDatabase getDatabase() {
|
||||||
return datastore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MongoDatabase getDatabase() {
|
|
||||||
return getDatastore().getDatabase();
|
return getDatastore().getDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,27 +50,23 @@ public final class DatabaseManager {
|
|||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
// Initialize
|
// Initialize
|
||||||
mongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().DatabaseUrl));
|
MongoClient mongoClient = MongoClients.create(Grasscutter.getConfig().DatabaseUrl);
|
||||||
Morphia morphia = new Morphia();
|
|
||||||
|
|
||||||
// TODO Update when migrating to Morphia 2.0
|
// Set mapper options.
|
||||||
morphia.getMapper().getOptions().setStoreEmpties(true);
|
MapperOptions mapperOptions = MapperOptions.builder()
|
||||||
morphia.getMapper().getOptions().setStoreNulls(false);
|
.storeEmpties(true).storeNulls(false).build();
|
||||||
morphia.getMapper().getOptions().setDisableEmbeddedIndexes(true);
|
// Create data store.
|
||||||
|
datastore = Morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection, mapperOptions);
|
||||||
// Map
|
// Map classes.
|
||||||
morphia.map(mappedClasses);
|
datastore.getMapper().map(mappedClasses);
|
||||||
|
|
||||||
// Build datastore
|
|
||||||
datastore = morphia.createDatastore(mongoClient, Grasscutter.getConfig().DatabaseCollection);
|
|
||||||
|
|
||||||
// Ensure indexes
|
// Ensure indexes
|
||||||
try {
|
try {
|
||||||
datastore.ensureIndexes();
|
datastore.ensureIndexes();
|
||||||
} catch (MongoCommandException e) {
|
} catch (MongoCommandException exception) {
|
||||||
Grasscutter.getLogger().info("Mongo index error: ", e);
|
Grasscutter.getLogger().info("Mongo index error: ", exception);
|
||||||
// Duplicate index error
|
// Duplicate index error
|
||||||
if (e.getCode() == 85) {
|
if (exception.getCode() == 85) {
|
||||||
// Drop all indexes and re add them
|
// Drop all indexes and re add them
|
||||||
MongoIterable<String> collections = datastore.getDatabase().listCollectionNames();
|
MongoIterable<String> collections = datastore.getDatabase().listCollectionNames();
|
||||||
for (String name : collections) {
|
for (String name : collections) {
|
||||||
@ -82,8 +78,8 @@ public final class DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
|
if(Grasscutter.getConfig().RunMode.equalsIgnoreCase("GAME_ONLY")) {
|
||||||
dispatchMongoClient = new MongoClient(new MongoClientURI(Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseUrl));
|
dispatchMongoClient = MongoClients.create(Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseUrl);
|
||||||
dispatchDatastore = morphia.createDatastore(dispatchMongoClient, Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseCollection);
|
dispatchDatastore = Morphia.createDatastore(dispatchMongoClient, Grasscutter.getConfig().getGameServerOptions().DispatchServerDatabaseCollection);
|
||||||
|
|
||||||
// Ensure indexes for dispatch server
|
// Ensure indexes for dispatch server
|
||||||
try {
|
try {
|
||||||
@ -103,9 +99,9 @@ public final class DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int getNextId(Class<?> c) {
|
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) {
|
if (counter == null) {
|
||||||
counter = new DatabaseCounter(c.getSimpleName());
|
counter = new DatabaseCounter(c.getSimpleName());
|
||||||
}
|
}
|
||||||
@ -115,7 +111,7 @@ public final class DatabaseManager {
|
|||||||
getDatastore().save(counter);
|
getDatastore().save(counter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int getNextId(Object o) {
|
public static synchronized int getNextId(Object o) {
|
||||||
return getNextId(o.getClass());
|
return getNextId(o.getClass());
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
package emu.grasscutter.game;
|
package emu.grasscutter.game;
|
||||||
|
|
||||||
import dev.morphia.annotations.AlsoLoad;
|
import dev.morphia.annotations.*;
|
||||||
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 emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.utils.Crypto;
|
import emu.grasscutter.utils.Crypto;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import dev.morphia.annotations.IndexOptions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bson.Document;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
|
||||||
@Entity(value = "accounts", noClassnameStored = true)
|
@Entity(value = "accounts", useDiscriminator = false)
|
||||||
public class Account {
|
public class Account {
|
||||||
@Id private String id;
|
@Id private String id;
|
||||||
|
|
||||||
@ -31,7 +27,7 @@ public class Account {
|
|||||||
private String token;
|
private String token;
|
||||||
private String sessionKey; // Session token for dispatch server
|
private String sessionKey; // Session token for dispatch server
|
||||||
private List<String> permissions;
|
private List<String> permissions;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Account() {
|
public Account() {
|
||||||
this.permissions = new ArrayList<>();
|
this.permissions = new ArrayList<>();
|
||||||
@ -122,15 +118,15 @@ public class Account {
|
|||||||
return this.token;
|
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() {
|
public void save() {
|
||||||
DatabaseHelper.saveAccount(this);
|
DatabaseHelper.saveAccount(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreLoad
|
||||||
|
public void onLoad(Document document) {
|
||||||
|
// Grant the superuser permissions to accounts created before the permissions update
|
||||||
|
if (!document.containsKey("permissions")) {
|
||||||
|
this.addPermission("*");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import emu.grasscutter.game.friends.PlayerProfile;
|
|||||||
import emu.grasscutter.game.gacha.PlayerGachaInfo;
|
import emu.grasscutter.game.gacha.PlayerGachaInfo;
|
||||||
import emu.grasscutter.game.inventory.GenshinItem;
|
import emu.grasscutter.game.inventory.GenshinItem;
|
||||||
import emu.grasscutter.game.inventory.Inventory;
|
import emu.grasscutter.game.inventory.Inventory;
|
||||||
|
import emu.grasscutter.game.player.PlayerBirthday;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
import emu.grasscutter.net.packet.GenshinPacket;
|
import emu.grasscutter.net.packet.GenshinPacket;
|
||||||
@ -61,7 +62,7 @@ import emu.grasscutter.utils.Position;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
@Entity(value = "players", noClassnameStored = true)
|
@Entity(value = "players", useDiscriminator = false)
|
||||||
public class GenshinPlayer {
|
public class GenshinPlayer {
|
||||||
@Id private int id;
|
@Id private int id;
|
||||||
@Indexed(options = @IndexOptions(unique = true)) private String accountId;
|
@Indexed(options = @IndexOptions(unique = true)) private String accountId;
|
||||||
@ -73,6 +74,7 @@ public class GenshinPlayer {
|
|||||||
private int nameCardId = 210001;
|
private int nameCardId = 210001;
|
||||||
private Position pos;
|
private Position pos;
|
||||||
private Position rotation;
|
private Position rotation;
|
||||||
|
private PlayerBirthday birthday;
|
||||||
|
|
||||||
private Map<Integer, Integer> properties;
|
private Map<Integer, Integer> properties;
|
||||||
private Set<Integer> nameCardList;
|
private Set<Integer> nameCardList;
|
||||||
@ -139,6 +141,8 @@ public class GenshinPlayer {
|
|||||||
this.combatInvokeHandler = new InvokeHandler(PacketCombatInvocationsNotify.class);
|
this.combatInvokeHandler = new InvokeHandler(PacketCombatInvocationsNotify.class);
|
||||||
this.abilityInvokeHandler = new InvokeHandler(PacketAbilityInvocationsNotify.class);
|
this.abilityInvokeHandler = new InvokeHandler(PacketAbilityInvocationsNotify.class);
|
||||||
this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class);
|
this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class);
|
||||||
|
|
||||||
|
this.birthday = new PlayerBirthday();
|
||||||
}
|
}
|
||||||
|
|
||||||
// On player creation
|
// On player creation
|
||||||
@ -150,6 +154,7 @@ public class GenshinPlayer {
|
|||||||
this.nickname = "Traveler";
|
this.nickname = "Traveler";
|
||||||
this.signature = "";
|
this.signature = "";
|
||||||
this.teamManager = new TeamManager(this);
|
this.teamManager = new TeamManager(this);
|
||||||
|
this.birthday = new PlayerBirthday();
|
||||||
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1);
|
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1);
|
||||||
this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1);
|
this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1);
|
||||||
this.setProperty(PlayerProperty.PROP_SPRING_AUTO_USE_PERCENT, 50);
|
this.setProperty(PlayerProperty.PROP_SPRING_AUTO_USE_PERCENT, 50);
|
||||||
@ -642,6 +647,15 @@ public class GenshinPlayer {
|
|||||||
return onlineInfo.build();
|
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() {
|
public SocialDetail.Builder getSocialDetail() {
|
||||||
SocialDetail.Builder social = SocialDetail.newBuilder()
|
SocialDetail.Builder social = SocialDetail.newBuilder()
|
||||||
.setUid(this.getUid())
|
.setUid(this.getUid())
|
||||||
@ -649,7 +663,7 @@ public class GenshinPlayer {
|
|||||||
.setNickname(this.getNickname())
|
.setNickname(this.getNickname())
|
||||||
.setSignature(this.getSignature())
|
.setSignature(this.getSignature())
|
||||||
.setLevel(this.getLevel())
|
.setLevel(this.getLevel())
|
||||||
.setBirthday(Birthday.newBuilder())
|
.setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty())
|
||||||
.setWorldLevel(this.getWorldLevel())
|
.setWorldLevel(this.getWorldLevel())
|
||||||
.setUnk1(1)
|
.setUnk1(1)
|
||||||
.setUnk3(1)
|
.setUnk3(1)
|
||||||
|
@ -3,10 +3,12 @@ package emu.grasscutter.game;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
import emu.grasscutter.GenshinConstants;
|
import emu.grasscutter.GenshinConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.game.avatar.GenshinAvatar;
|
import emu.grasscutter.game.avatar.GenshinAvatar;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class TeamInfo {
|
public class TeamInfo {
|
||||||
private String name;
|
private String name;
|
||||||
private List<Integer> avatars;
|
private List<Integer> avatars;
|
||||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Transient;
|
import dev.morphia.annotations.Transient;
|
||||||
import emu.grasscutter.GenshinConstants;
|
import emu.grasscutter.GenshinConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
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.IntOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class TeamManager {
|
public class TeamManager {
|
||||||
@Transient private GenshinPlayer player;
|
@Transient private GenshinPlayer player;
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package emu.grasscutter.game.avatar;
|
package emu.grasscutter.game.avatar;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class AvatarProfileData {
|
public class AvatarProfileData {
|
||||||
private int avatarId;
|
private int avatarId;
|
||||||
private int level;
|
private int level;
|
||||||
|
@ -56,7 +56,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
@Entity(value = "avatars", noClassnameStored = true)
|
@Entity(value = "avatars", useDiscriminator = false)
|
||||||
public class GenshinAvatar {
|
public class GenshinAvatar {
|
||||||
@Id private ObjectId id;
|
@Id private ObjectId id;
|
||||||
@Indexed private int ownerId; // Id of player that this avatar belongs to
|
@Indexed private int ownerId; // Id of player that this avatar belongs to
|
||||||
|
@ -9,7 +9,7 @@ import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief;
|
|||||||
import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState;
|
import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState;
|
||||||
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
|
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
|
||||||
|
|
||||||
@Entity(value = "friendships", noClassnameStored = true)
|
@Entity(value = "friendships", useDiscriminator = false)
|
||||||
public class Friendship {
|
public class Friendship {
|
||||||
@Id private ObjectId id;
|
@Id private ObjectId id;
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import dev.morphia.annotations.*;
|
|||||||
import emu.grasscutter.game.GenshinPlayer;
|
import emu.grasscutter.game.GenshinPlayer;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class PlayerProfile {
|
public class PlayerProfile {
|
||||||
@Transient private GenshinPlayer player;
|
@Transient private GenshinPlayer player;
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package emu.grasscutter.game.gacha;
|
package emu.grasscutter.game.gacha;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class PlayerGachaBannerInfo {
|
public class PlayerGachaBannerInfo {
|
||||||
private int pity5 = 0;
|
private int pity5 = 0;
|
||||||
private int pity4 = 0;
|
private int pity4 = 0;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package emu.grasscutter.game.gacha;
|
package emu.grasscutter.game.gacha;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class PlayerGachaInfo {
|
public class PlayerGachaInfo {
|
||||||
private PlayerGachaBannerInfo standardBanner;
|
private PlayerGachaBannerInfo standardBanner;
|
||||||
private PlayerGachaBannerInfo eventCharacterBanner;
|
private PlayerGachaBannerInfo eventCharacterBanner;
|
||||||
|
@ -34,7 +34,7 @@ import emu.grasscutter.net.proto.SceneWeaponInfoOuterClass.SceneWeaponInfo;
|
|||||||
import emu.grasscutter.net.proto.WeaponOuterClass.Weapon;
|
import emu.grasscutter.net.proto.WeaponOuterClass.Weapon;
|
||||||
import emu.grasscutter.utils.WeightedList;
|
import emu.grasscutter.utils.WeightedList;
|
||||||
|
|
||||||
@Entity(value = "items", noClassnameStored = true)
|
@Entity(value = "items", useDiscriminator = false)
|
||||||
public class GenshinItem {
|
public class GenshinItem {
|
||||||
@Id private ObjectId id;
|
@Id private ObjectId id;
|
||||||
@Indexed private int ownerId;
|
@Indexed private int ownerId;
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -1034,6 +1034,8 @@ public class PacketOpcodes {
|
|||||||
public static final int ShowTemplateReminderNotify = 3164;
|
public static final int ShowTemplateReminderNotify = 3164;
|
||||||
public static final int SignInInfoReq = 2510;
|
public static final int SignInInfoReq = 2510;
|
||||||
public static final int SignInInfoRsp = 2515;
|
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 SocialDataNotify = 4063;
|
||||||
public static final int SpringUseReq = 1720;
|
public static final int SpringUseReq = 1720;
|
||||||
public static final int SpringUseRsp = 1727;
|
public static final int SpringUseRsp = 1727;
|
||||||
@ -1208,5 +1210,4 @@ public class PacketOpcodes {
|
|||||||
public static final int WorldRoutineChangeNotify = 3548;
|
public static final int WorldRoutineChangeNotify = 3548;
|
||||||
public static final int WorldRoutineTypeCloseNotify = 3513;
|
public static final int WorldRoutineTypeCloseNotify = 3513;
|
||||||
public static final int WorldRoutineTypeRefreshNotify = 3545;
|
public static final int WorldRoutineTypeRefreshNotify = 3545;
|
||||||
|
|
||||||
}
|
}
|
@ -64,9 +64,8 @@ public class MihoyoKcpServer extends Thread {
|
|||||||
|
|
||||||
// Wait until the server socket is closed.
|
// Wait until the server socket is closed.
|
||||||
f.channel().closeFuture().sync();
|
f.channel().closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception exception) {
|
||||||
// TODO Auto-generated catch block
|
Grasscutter.getLogger().error("Unable to start game server.", exception);
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
} finally {
|
||||||
// Close
|
// Close
|
||||||
finish();
|
finish();
|
||||||
|
@ -24,6 +24,7 @@ import emu.grasscutter.utils.Utils;
|
|||||||
import javax.net.ssl.KeyManagerFactory;
|
import javax.net.ssl.KeyManagerFactory;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.net.BindException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
@ -101,14 +102,14 @@ public final class DispatchServer {
|
|||||||
.setName("os_usa")
|
.setName("os_usa")
|
||||||
.setTitle(Grasscutter.getConfig().getGameServerOptions().Name)
|
.setTitle(Grasscutter.getConfig().getGameServerOptions().Name)
|
||||||
.setType("DEV_PUBLIC")
|
.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) + ":" + (Grasscutter.getConfig().getDispatchOptions().PublicPort != 0 ? Grasscutter.getConfig().getDispatchOptions().PublicPort : Grasscutter.getConfig().getDispatchOptions().Port) + "/query_cur_region_" + defaultServerName)
|
||||||
.build();
|
.build();
|
||||||
usedNames.add(defaultServerName);
|
usedNames.add(defaultServerName);
|
||||||
servers.add(server);
|
servers.add(server);
|
||||||
|
|
||||||
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
|
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
|
||||||
.setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getGameServerOptions().Ip : Grasscutter.getConfig().getGameServerOptions().PublicIp))
|
.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")))
|
.setSecretKey(ByteString.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin")))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ public final class DispatchServer {
|
|||||||
.setName(regionInfo.Name)
|
.setName(regionInfo.Name)
|
||||||
.setTitle(regionInfo.Title)
|
.setTitle(regionInfo.Title)
|
||||||
.setType("DEV_PUBLIC")
|
.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();
|
.build();
|
||||||
usedNames.add(regionInfo.Name);
|
usedNames.add(regionInfo.Name);
|
||||||
servers.add(server);
|
servers.add(server);
|
||||||
@ -158,12 +159,21 @@ public final class DispatchServer {
|
|||||||
Grasscutter.getLogger().error("[Dispatch] Error while initializing region info!", e);
|
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 {
|
public void start() throws Exception {
|
||||||
HttpServer server;
|
HttpServer server;
|
||||||
if (Grasscutter.getConfig().getDispatchOptions().UseSSL) {
|
if (Grasscutter.getConfig().getDispatchOptions().UseSSL) {
|
||||||
HttpsServer httpsServer;
|
HttpsServer httpsServer = HttpsServer.create(getAddress(), 0);
|
||||||
httpsServer = HttpsServer.create(getAddress(), 0);
|
|
||||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||||
try (FileInputStream fis = new FileInputStream(Grasscutter.getConfig().getDispatchOptions().KeystorePath)) {
|
try (FileInputStream fis = new FileInputStream(Grasscutter.getConfig().getDispatchOptions().KeystorePath)) {
|
||||||
char[] keystorePassword = Grasscutter.getConfig().getDispatchOptions().KeystorePassword.toCharArray();
|
char[] keystorePassword = Grasscutter.getConfig().getDispatchOptions().KeystorePassword.toCharArray();
|
||||||
@ -176,14 +186,20 @@ public final class DispatchServer {
|
|||||||
|
|
||||||
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
|
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
|
||||||
server = httpsServer;
|
server = httpsServer;
|
||||||
|
} catch (BindException ignored) {
|
||||||
|
Grasscutter.getLogger().error("Unable to bind to port: " + getAddress().getPort() + " (HTTPS)");
|
||||||
|
server = this.safelyCreateServer(this.getAddress());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Grasscutter.getLogger().warn("[Dispatch] No SSL cert found! Falling back to HTTP server.");
|
Grasscutter.getLogger().warn("[Dispatch] No SSL cert found! Falling back to HTTP server.");
|
||||||
Grasscutter.getConfig().getDispatchOptions().UseSSL = false;
|
Grasscutter.getConfig().getDispatchOptions().UseSSL = false;
|
||||||
server = HttpServer.create(getAddress(), 0);
|
server = this.safelyCreateServer(this.getAddress());
|
||||||
}
|
}
|
||||||
} else {
|
} 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"));
|
server.createContext("/", t -> responseHTML(t, "Hello"));
|
||||||
|
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
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.PacketLifeStateChangeNotify;
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,7 @@ public class PacketPlayerLoginRsp extends GenshinPacket {
|
|||||||
|
|
||||||
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
|
RegionInfo serverRegion = regionQuery.getRegionInfo().toBuilder()
|
||||||
.setIp((Grasscutter.getConfig().getGameServerOptions().PublicIp.isEmpty() ? Grasscutter.getConfig().getGameServerOptions().Ip : Grasscutter.getConfig().getGameServerOptions().PublicIp))
|
.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")))
|
.setSecretKey(ByteString.copyFrom(FileUtils.read(Grasscutter.getConfig().KEY_FOLDER + "dispatchSeed.bin")))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package emu.grasscutter.server.packet.send;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,13 @@
|
|||||||
package emu.grasscutter.tools;
|
package emu.grasscutter.tools;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -30,13 +35,13 @@ public final class Tools {
|
|||||||
ResourceLoader.loadResources();
|
ResourceLoader.loadResources();
|
||||||
|
|
||||||
Map<Long, String> map;
|
Map<Long, String> 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<Map<Long, String>>() {}.getType());
|
map = Grasscutter.getGsonFactory().fromJson(fileReader, new TypeToken<Map<Long, String>>() {}.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> list;
|
List<Integer> list;
|
||||||
String fileName = "./GM Handbook.txt";
|
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");
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
@ -2,8 +2,10 @@ package emu.grasscutter.utils;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import dev.morphia.annotations.Entity;
|
||||||
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
|
import emu.grasscutter.net.proto.VectorOuterClass.Vector;
|
||||||
|
|
||||||
|
@Entity
|
||||||
public class Position implements Serializable {
|
public class Position implements Serializable {
|
||||||
private static final long serialVersionUID = -2001232313615923575L;
|
private static final long serialVersionUID = -2001232313615923575L;
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ public final class Utils {
|
|||||||
// Check for GenshinData.
|
// Check for GenshinData.
|
||||||
if(!fileExists(resourcesFolder + "BinOutput") ||
|
if(!fileExists(resourcesFolder + "BinOutput") ||
|
||||||
!fileExists(resourcesFolder + "ExcelBinOutput")) {
|
!fileExists(resourcesFolder + "ExcelBinOutput")) {
|
||||||
logger.info("Place a copy of 'GenshinData' in the resources folder.");
|
logger.info("Place a copy of 'BinOutput' and 'ExcelBinOutput' in the resources folder.");
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,19 @@
|
|||||||
<pattern>[%d{HH:mm:ss}] [%highlight(%level)] %msg%n</pattern>
|
<pattern>[%d{HH:mm:ss}] [%highlight(%level)] %msg%n</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>logs/latest.log</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>logs/log.%d{yyyy-MM-dd}_%d{HH}.log.tar.gz</fileNamePattern>
|
||||||
|
<maxHistory>24</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss'Z'} - %m%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
<logger name="org.reflections" level="OFF"/>
|
<logger name="org.reflections" level="OFF"/>
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
</root>
|
</root>
|
||||||
</Configuration>
|
</Configuration>
|
@ -74,8 +74,10 @@ for /f "tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVe
|
|||||||
|
|
||||||
@rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1
|
@rem TODO: External proxy when ORIG_PROXY_ENABLE == 0x1
|
||||||
echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs"
|
echo set ws = createobject("wscript.shell") > "%temp%\proxy.vbs"
|
||||||
echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%temp%\proxy.vbs"
|
if not "%MITMDUMP_PATH%" == "" (
|
||||||
echo ws.run "cmd /c mitmdump.exe -s "^&chr(34)^&"%PROXY_SCRIPT_NAME%"^&chr(34)^&" -k",0 >> "%temp%\proxy.vbs"
|
echo ws.currentdirectory = "%MITMDUMP_PATH%" >> "%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"
|
"%temp%\proxy.vbs"
|
||||||
del /f /q "%temp%\proxy.vbs" >nul 2>nul
|
del /f /q "%temp%\proxy.vbs" >nul 2>nul
|
||||||
|
|
||||||
@ -117,7 +119,9 @@ set DATABASE=true
|
|||||||
mkdir "%DATABASE_STORAGE_PATH%" >nul 2>nul
|
mkdir "%DATABASE_STORAGE_PATH%" >nul 2>nul
|
||||||
|
|
||||||
echo set ws = createobject("wscript.shell") > "%temp%\db.vbs"
|
echo set ws = createobject("wscript.shell") > "%temp%\db.vbs"
|
||||||
|
if not "%MONGODB_PATH%" == "" (
|
||||||
echo ws.currentdirectory = "%MONGODB_PATH%" >> "%temp%\db.vbs"
|
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"
|
echo ws.run "cmd /c mongod.exe --dbpath "^&chr(34)^&"%DATABASE_STORAGE_PATH%"^&chr(34)^&"",0 >> "%temp%\db.vbs"
|
||||||
"%temp%\db.vbs"
|
"%temp%\db.vbs"
|
||||||
del /f /q "%temp%\db.vbs" >nul 2>nul
|
del /f /q "%temp%\db.vbs" >nul 2>nul
|
||||||
|
Loading…
Reference in New Issue
Block a user