mirror of https://github.com/Minestom/Minestom.git
Initial replay testing attempt
This commit is contained in:
parent
77d1888cbc
commit
fc9ded0afc
|
@ -45,6 +45,7 @@ dependencies {
|
||||||
// Junit Testing Framework
|
// Junit Testing Framework
|
||||||
testImplementation(libs.junit.api)
|
testImplementation(libs.junit.api)
|
||||||
testImplementation(libs.junit.params)
|
testImplementation(libs.junit.params)
|
||||||
|
testImplementation("com.github.ReplayMod:ReplayStudio:70f59efaa3")
|
||||||
testRuntimeOnly(libs.junit.engine)
|
testRuntimeOnly(libs.junit.engine)
|
||||||
// Only here to ensure J9 module support for extensions and our classloaders
|
// Only here to ensure J9 module support for extensions and our classloaders
|
||||||
testCompileOnly(libs.mockito.core)
|
testCompileOnly(libs.mockito.core)
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package net.minestom.server.extra.ac;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
|
public class AntiCheatTest extends UtilsAC {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws URISyntaxException, IOException {
|
||||||
|
retrieveReplay("replay_demo.mcpr");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package net.minestom.server.extra.ac;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.replaymod.replaystudio.PacketData;
|
||||||
|
import com.replaymod.replaystudio.Studio;
|
||||||
|
import com.replaymod.replaystudio.filter.StreamFilter;
|
||||||
|
import com.replaymod.replaystudio.lib.viaversion.api.protocol.packet.State;
|
||||||
|
import com.replaymod.replaystudio.lib.viaversion.api.protocol.version.ProtocolVersion;
|
||||||
|
import com.replaymod.replaystudio.protocol.PacketTypeRegistry;
|
||||||
|
import com.replaymod.replaystudio.replay.ReplayFile;
|
||||||
|
import com.replaymod.replaystudio.replay.ZipReplayFile;
|
||||||
|
import com.replaymod.replaystudio.stream.PacketStream;
|
||||||
|
import com.replaymod.replaystudio.studio.ReplayStudio;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class UtilsAC {
|
||||||
|
|
||||||
|
private static final ReplayStudio STUDIO = new ReplayStudio();
|
||||||
|
|
||||||
|
void retrieveReplay(String name) {
|
||||||
|
try {
|
||||||
|
final File dir = new File(ClassLoader.getSystemResource(name).toURI());
|
||||||
|
final ReplayFile replayFile = new ZipReplayFile(STUDIO, dir);
|
||||||
|
|
||||||
|
final PacketTypeRegistry registry = PacketTypeRegistry.get(ProtocolVersion.getProtocol(MinecraftServer.PROTOCOL_VERSION), State.PLAY);
|
||||||
|
PacketStream stream = replayFile.getPacketData(registry).asPacketStream();
|
||||||
|
stream.start();
|
||||||
|
stream.addFilter(new ProgressFilter()); // Required for some reason
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
PacketData packetData;
|
||||||
|
while ((packetData = stream.next()) != null) {
|
||||||
|
// TODO how to retrieve server-bound packets?
|
||||||
|
System.out.println("packet " + packetData.getPacket().getType() + " - " + packetData.getTime());
|
||||||
|
if (count++ >= 10) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.end();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class ProgressFilter implements StreamFilter {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "progress";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(Studio studio, JsonObject config) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart(PacketStream stream) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPacket(PacketStream stream, PacketData data) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnd(PacketStream stream, long timestamp) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Loading…
Reference in New Issue