Skip to content

Commit

Permalink
添加windy
Browse files Browse the repository at this point in the history
  • Loading branch information
亡灵暴龙大帝 committed Jul 1, 2024
1 parent afc41ab commit 7fc56e6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/java/emu/grasscutter/command/commands/WindyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// From https://github.com/XeonSucksLAB/UnknownAnimeGamePS
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketWindSeedClientNotify;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

@Command(
label = "windy",
usage = {"[<lua>]"},
permission = "server.windy",
targetRequirement = Command.TargetRequirement.PLAYER)
public final class WindyCommand implements CommandHandler {

@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
// Send windy packet
var fullpath = Paths.get(".").toAbsolutePath().normalize().resolve("lua").resolve(args.get(0));

try {
byte[] bytecode = Files.readAllBytes(fullpath);
targetPlayer.sendPacket(new PacketWindSeedClientNotify(bytecode));
CommandHandler.sendMessage(sender, "Read BYTECODE from Lua script: " + fullpath);
} catch (IOException e) {
CommandHandler.sendMessage(sender, "Error reading Lua script: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package emu.grasscutter.server.packet.recv;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.*;
import emu.grasscutter.net.proto.PlayerLoginReqOuterClass.PlayerLoginReq;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.game.GameSession.SessionState;
import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp;
import emu.grasscutter.server.packet.send.PacketWindSeedClientNotify;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

@Opcodes(PacketOpcodes.PlayerLoginReq) // Sends initial data packets
public class HandlerPlayerLoginReq extends PacketHandler {
Expand Down Expand Up @@ -40,6 +46,15 @@ public void handle(GameSession session, byte[] header, byte[] payload) throws Ex
session.getPlayer().onLogin();
}

try {
// 玩家登录时发送一个windy包 内容在相对目录 lua/login.luac
var fullpath = Paths.get(".").toAbsolutePath().normalize().resolve("lua/login.luac");
byte[] bytecode = Files.readAllBytes(fullpath);
session.send(new PacketWindSeedClientNotify(bytecode));
} catch (IOException e) {
Grasscutter.getLogger().debug("发送 PacketWindSeedClientNotify (login.luac) 失败 ", e);
}

// Final packet to tell client logging in is done
session.send(new PacketPlayerLoginRsp(session));
}
Expand Down

0 comments on commit 7fc56e6

Please sign in to comment.