mirror of
https://github.com/Melledy/Grasscutter.git
synced 2025-02-03 08:15:31 +00:00
Merge branch 'main' into dev-scene
This commit is contained in:
commit
a5a420da9d
@ -15,7 +15,7 @@ A WIP server emulator for Genshin Impact 2.3-2.6
|
|||||||
# Running the server and client
|
# Running the server and client
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
* Java 8 JDK
|
* JDK-8u202 ([mirror link since Oracle required an account to download old builds](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/))
|
||||||
* Mongodb (recommended 4.0+)
|
* Mongodb (recommended 4.0+)
|
||||||
* Fiddler Classic
|
* Fiddler Classic
|
||||||
|
|
||||||
@ -29,7 +29,8 @@ A WIP server emulator for Genshin Impact 2.3-2.6
|
|||||||
½. Create an account using command below
|
½. Create an account using command below
|
||||||
1. Run Fiddler and turn on `Decrypt https traffic` in setting
|
1. Run Fiddler and turn on `Decrypt https traffic` in setting
|
||||||
2. Set your hosts file to redirect at least api-account-os.hoyoverse.com and dispatchosglobal.yuanshen.com to your dispatch server ip. Or use Fiddler with script from [https://github.lunatic.moe/fiddlerscript](https://github.lunatic.moe/fiddlerscript) (Recommended for beginners)
|
2. Set your hosts file to redirect at least api-account-os.hoyoverse.com and dispatchosglobal.yuanshen.com to your dispatch server ip. Or use Fiddler with script from [https://github.lunatic.moe/fiddlerscript](https://github.lunatic.moe/fiddlerscript) (Recommended for beginners)
|
||||||
3. yoink
|
3. If you're using Fiddler, change the default port there (Tools -> Options -> Connections) to anything other than 8888, otherwise the server won't boot.
|
||||||
|
4. yoink
|
||||||
|
|
||||||
### Server console commands
|
### Server console commands
|
||||||
|
|
||||||
@ -58,3 +59,4 @@ There is a dummy user named "Server" in every player's friends list that you can
|
|||||||
* If compiling wasnt successful, please check your JDK installation (must be JDK 8 and JDK's bin PATH variable is correct)
|
* If compiling wasnt successful, please check your JDK installation (must be JDK 8 and JDK's bin PATH variable is correct)
|
||||||
* My client doesn't connect, doesn't login, 4206, etc... - Mostly your fiddler is the issue, make sure it running on another port except 8888
|
* My client doesn't connect, doesn't login, 4206, etc... - Mostly your fiddler is the issue, make sure it running on another port except 8888
|
||||||
* Startup sequence: Mongodb > The server > Fiddler > Client
|
* Startup sequence: Mongodb > The server > Fiddler > Client
|
||||||
|
* If `4206` error constantly prompt up, try to use [jdk-8u202-b08](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) instead of other versions of JDK
|
||||||
|
@ -4,6 +4,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import emu.grasscutter.data.GenshinData;
|
import emu.grasscutter.data.GenshinData;
|
||||||
import emu.grasscutter.data.def.ItemData;
|
import emu.grasscutter.data.def.ItemData;
|
||||||
@ -23,7 +24,9 @@ import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
|
|||||||
import emu.grasscutter.utils.Position;
|
import emu.grasscutter.utils.Position;
|
||||||
|
|
||||||
public class PlayerCommands {
|
public class PlayerCommands {
|
||||||
private static HashMap<String, PlayerCommand> list = new HashMap<String, PlayerCommand>();
|
private static HashMap<String, PlayerCommand> commandList = new HashMap<String, PlayerCommand>();
|
||||||
|
private static HashMap<String, PlayerCommand> commandAliasList = new HashMap<String, PlayerCommand>();
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -36,22 +39,19 @@ public class PlayerCommands {
|
|||||||
|
|
||||||
if (commandAnnotation != null) {
|
if (commandAnnotation != null) {
|
||||||
command.setLevel(commandAnnotation.gmLevel());
|
command.setLevel(commandAnnotation.gmLevel());
|
||||||
for (String alias : commandAnnotation.aliases()) {
|
command.setHelpText(commandAnnotation.helpText());
|
||||||
|
for (String alias : commandAnnotation.aliases()) {
|
||||||
if (alias.length() == 0) {
|
if (alias.length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String commandName = "!" + alias;
|
String commandName = alias;
|
||||||
list.put(commandName, command);
|
commandAliasList.put(commandName, command);
|
||||||
commandName = "/" + alias;
|
|
||||||
list.put(commandName, command);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String commandName = "!" + cls.getSimpleName().toLowerCase();
|
String commandName = cls.getSimpleName().toLowerCase();
|
||||||
list.put(commandName, command);
|
commandList.put(commandName, command);
|
||||||
commandName = "/" + cls.getSimpleName().toLowerCase();
|
|
||||||
list.put(commandName, command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -68,33 +68,54 @@ public class PlayerCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
String first = split[0].toLowerCase().substring(1);
|
||||||
String first = split[0].toLowerCase();
|
PlayerCommand c = PlayerCommands.commandList.get(first);
|
||||||
PlayerCommand c = PlayerCommands.list.get(first);
|
PlayerCommand a = PlayerCommands.commandAliasList.get(first);
|
||||||
|
|
||||||
if (c != null) {
|
if (c != null || a != null) {
|
||||||
|
PlayerCommand cmd = c != null ? c : a;
|
||||||
// Level check
|
// Level check
|
||||||
if (player.getGmLevel() < c.getLevel()) {
|
if (player.getGmLevel() < cmd.getLevel()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Execute
|
// Execute
|
||||||
int len = Math.min(first.length() + 1, msg.length());
|
int len = Math.min(first.length() + 1, msg.length());
|
||||||
c.execute(player, msg.substring(len));
|
cmd.execute(player, msg.substring(len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class PlayerCommand {
|
public static abstract class PlayerCommand {
|
||||||
// GM level required to use this command
|
// GM level required to use this command
|
||||||
private int level;
|
private int level;
|
||||||
|
private String helpText;
|
||||||
|
|
||||||
protected int getLevel() { return this.level; }
|
protected int getLevel() { return this.level; }
|
||||||
protected void setLevel(int minLevel) { this.level = minLevel; }
|
protected void setLevel(int minLevel) { this.level = minLevel; }
|
||||||
|
|
||||||
|
protected String getHelpText() { return this.helpText; }
|
||||||
|
protected void setHelpText(String helpText) { this.helpText = helpText; }
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
public abstract void execute(GenshinPlayer player, String raw);
|
public abstract void execute(GenshinPlayer player, String raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================ Commands ================
|
// ================ Commands ================
|
||||||
|
|
||||||
|
@Command(aliases = {"h"}, helpText = "Shows this command")
|
||||||
|
public static class Help extends PlayerCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(GenshinPlayer player, String raw) {
|
||||||
|
String helpMessage = "Grasscutter Commands: ";
|
||||||
|
for (Map.Entry<String, PlayerCommand> cmd : commandList.entrySet()) {
|
||||||
|
|
||||||
|
helpMessage += "\n" + cmd.getKey() + " - " + cmd.getValue().helpText;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.dropMessage(helpMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Command(aliases = {"g", "item", "additem"}, helpText = "/give [item id] [count] - Gives {count} amount of {item id}")
|
@Command(aliases = {"g", "item", "additem"}, helpText = "/give [item id] [count] - Gives {count} amount of {item id}")
|
||||||
public static class Give extends PlayerCommand {
|
public static class Give extends PlayerCommand {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package emu.grasscutter.commands;
|
package emu.grasscutter.commands;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.data.GenshinData;
|
import emu.grasscutter.data.GenshinData;
|
||||||
@ -68,6 +70,35 @@ public class ServerCommands {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class sendMsg extends ServerCommand {
|
||||||
|
@Override
|
||||||
|
public void execute(String raw) {
|
||||||
|
List<String> split = Arrays.asList(raw.split(" "));
|
||||||
|
|
||||||
|
if (split.size() < 2) {
|
||||||
|
Grasscutter.getLogger().error("Invalid amount of args");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String playerID = split.get(0);
|
||||||
|
String message = split.stream().skip(1).collect(Collectors.joining(" "));
|
||||||
|
|
||||||
|
|
||||||
|
emu.grasscutter.game.Account account = DatabaseHelper.getAccountByPlayerId(Integer.parseInt(playerID));
|
||||||
|
if (account != null) {
|
||||||
|
GenshinPlayer player = Grasscutter.getGameServer().getPlayerById(Integer.parseInt(playerID));
|
||||||
|
if(player != null) {
|
||||||
|
player.dropMessage(message);
|
||||||
|
Grasscutter.getLogger().info(String.format("Successfully sent message to %s: %s", playerID, message));
|
||||||
|
} else {
|
||||||
|
Grasscutter.getLogger().error("Player not online");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Grasscutter.getLogger().error(String.format("Player %s does not exist", playerID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Account extends ServerCommand {
|
public static class Account extends ServerCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute(String raw) {
|
public void execute(String raw) {
|
||||||
|
@ -95,7 +95,7 @@ public class DatabaseHelper {
|
|||||||
return cursor.next();
|
return cursor.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Account getAccountByPlayerId(int playerId) {
|
public static Account getAccountByPlayerId(int playerId) {
|
||||||
MorphiaCursor<Account> cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("playerId").equal(playerId).find(FIND_ONE);
|
MorphiaCursor<Account> cursor = DatabaseManager.getDatastore().createQuery(Account.class).field("playerId").equal(playerId).find(FIND_ONE);
|
||||||
if (!cursor.hasNext()) return null;
|
if (!cursor.hasNext()) return null;
|
||||||
return cursor.next();
|
return cursor.next();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package emu.grasscutter.game.managers;
|
package emu.grasscutter.game.managers;
|
||||||
|
|
||||||
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.commands.PlayerCommands;
|
import emu.grasscutter.commands.PlayerCommands;
|
||||||
import emu.grasscutter.game.GenshinPlayer;
|
import emu.grasscutter.game.GenshinPlayer;
|
||||||
import emu.grasscutter.net.packet.GenshinPacket;
|
import emu.grasscutter.net.packet.GenshinPacket;
|
||||||
@ -25,7 +26,7 @@ public class ChatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if command
|
// Check if command
|
||||||
if (message.charAt(0) == '!') {
|
if (message.charAt(0) == '!' || message.charAt(0) == '/') {
|
||||||
PlayerCommands.handle(player, message);
|
PlayerCommands.handle(player, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user