From 8aa3a333d8c597cebb209323f3a5bb9e78ebd043 Mon Sep 17 00:00:00 2001 From: Tiberiu Iancu Date: Sun, 24 Jan 2021 14:25:36 +0100 Subject: [PATCH 01/11] Added generation stress test experiment + FlyTaskExecutor --- .../opencraft/yardstick/Yardstick.java | 4 + .../bot/ai/task/FlyTaskExecutor.java | 90 +++++++++++ .../Experiment9GenerationStressTest.java | 149 ++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java index c3ed573a..e2820e8f 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java @@ -42,6 +42,7 @@ import nl.tudelft.opencraft.yardstick.experiment.Experiment5SimpleWalk; import nl.tudelft.opencraft.yardstick.experiment.Experiment6InteractWalk; import nl.tudelft.opencraft.yardstick.experiment.Experiment8BoxWalkAround; +import nl.tudelft.opencraft.yardstick.experiment.Experiment9GenerationStressTest; import nl.tudelft.opencraft.yardstick.experiment.RemoteControlledExperiment; import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; import nl.tudelft.opencraft.yardstick.logging.SimpleTimeFormatter; @@ -163,6 +164,9 @@ public static void main(String[] args) { case 8: ex = new Experiment8BoxWalkAround(); break; + case 9: + ex = new Experiment9GenerationStressTest(); + break; default: System.out.println("Invalid experiment: " + OPTIONS.experiment); return; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java new file mode 100644 index 00000000..8f0edc2c --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java @@ -0,0 +1,90 @@ +package nl.tudelft.opencraft.yardstick.bot.ai.task; + +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; +import nl.tudelft.opencraft.yardstick.util.Vector3d; +import nl.tudelft.opencraft.yardstick.util.Vector3i; + +/** + * In order to avoid obstacles, the bot first flies to the maximum altitude, + * then flies to the target (X, Z) coordinates, then descends to meet the Y target + */ +public class FlyTaskExecutor extends AbstractTaskExecutor { + + public static final int maxY = 150; + private static final double speedY = 1; + private final double speedXZ; + + private Vector3i target; + + public FlyTaskExecutor(final Bot bot, Vector3i targetLocation, double speed) { + super(bot); + + this.target = targetLocation; + if (bot.getPlayer().getLocation().intVector().equals(target)) { + logger.warning("Useless fly task. Bot and given target location equal."); + } + + speedXZ = speed; + } + + @Override + protected TaskStatus onTick() { + // todo: perform additional checks for flying into objects + + Vector3d nextLocation = bot.getPlayer().getLocation(); + Vector3i currentLocation = nextLocation.intVector(); + int currX = currentLocation.getX(), currZ = currentLocation.getZ(); + + // check we have arrived + if (currentLocation.equals(target)) { + return TaskStatus.forSuccess(); + } + + // check if we have to descend + if (currX == target.getX() && currZ == target.getZ()) { + try { + int highestY = bot.getWorld().getHighestBlockAt(currX, currZ).getY(); + // check we can actually descend; if not, change target + if (highestY > target.getY()) { + target = new Vector3i(currX, highestY, currZ); + } + } catch (ChunkNotLoadedException ex) { + return TaskStatus.forFailure(String.format("Chunk that contains block %s not loaded", currentLocation)); + } + + double toDescend = -Math.min(nextLocation.getY() - (double) target.getY(), speedY); + nextLocation = nextLocation.add(0, toDescend, 0); + } else if (currentLocation.getY() < maxY) { + // we have to ascend + double toAscend = Math.min((double) maxY - nextLocation.getY(), speedY); + nextLocation = nextLocation.add(0, toAscend, 0); + } else { + // calculate delta movement + double diffX = Math.abs((double) target.getX() - nextLocation.getX()); + double diffZ = Math.abs((double) target.getZ() - nextLocation.getZ()); + double moveX = Math.min(diffX, speedXZ); + double moveZ = Math.min(diffZ, speedXZ); + + // adjust for angle + if (diffX < diffZ) { + moveX *= diffX / diffZ; + } else { + moveZ *= diffZ / diffX; + } + + // account for direction + if (target.getX() < nextLocation.getX()) moveX *= -1; + if (target.getZ() < nextLocation.getZ()) moveZ *= -1; + + nextLocation = nextLocation.add(moveX, 0, moveZ); + } + + // report location to server + bot.getController().updateLocation(nextLocation); + return TaskStatus.forInProgress(); + } + + @Override + protected void onStop() {} +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java new file mode 100644 index 00000000..ddd466ea --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java @@ -0,0 +1,149 @@ +package nl.tudelft.opencraft.yardstick.experiment; + +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.bot.ai.task.FlyTaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskStatus; +import nl.tudelft.opencraft.yardstick.util.Vector3i; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; + +public class Experiment9GenerationStressTest extends Experiment { + + private final List botList = Collections.synchronizedList(new ArrayList<>()); + private final Set targetSet = Collections.synchronizedSet(new HashSet<>()); + + private double angle = 0; + private double increment; + private double targetDistance; + private double botSpeed; + + private long startMillis; + private int durationInSeconds; + + public Experiment9GenerationStressTest() { + super(9, "Bots move away from the spawn location"); + } + + @Override + protected void before() { + int botsTotal = Integer.parseInt(options.experimentParams.get("bots")); + this.durationInSeconds = Integer.parseInt(options.experimentParams.getOrDefault("duration", "600")); + this.targetDistance = Integer.parseInt(options.experimentParams.getOrDefault("distance", "300")); + this.botSpeed = Double.parseDouble(options.experimentParams.getOrDefault("speed", "0.3")); + this.startMillis = System.currentTimeMillis(); + this.increment = 2 * Math.PI / botsTotal; + + // connect the bots; todo: synchronized? + for (int i = 0; i < botsTotal; i++) { + Bot bot = createBot(); + Thread connector = new Thread(newBotConnector(bot)); + connector.setName("Connector-" + bot.getName()); + connector.setDaemon(false); + connector.start(); + botList.add(bot); + } + } + + @Override + protected void tick() { + synchronized (botList) { + List disconnectedBots = botList.stream() + .filter(Bot::hasBeenDisconnected) + .collect(Collectors.toList()); + disconnectedBots.forEach(bot -> bot.disconnect("Bot is not connected")); + if (disconnectedBots.size() > 0) { + logger.warning("Bots disconnected: " + + disconnectedBots.stream().map(Bot::getName).reduce("", (a, b) -> a + ", " + b)); + botList.removeAll(disconnectedBots); + } + } + + synchronized (botList) { + for (Bot bot : botList) { + botTick(bot); + } + } + } + + private void botTick(Bot bot) { + if (!bot.isJoined()) { + return; + } + + // calculate bot target location if not already done + if (!targetSet.contains(bot)) { + // calculate target + Vector3i startLocation = bot.getPlayer().getLocation().intVector(); + int finalX = (int) Math.floor(targetDistance * Math.cos(angle)) + startLocation.getX(); + int finalZ = (int) Math.floor(targetDistance * Math.sin(angle)) + startLocation.getZ(); + angle += increment; + Vector3i botTarget = new Vector3i(finalX, FlyTaskExecutor.maxY, finalZ); + + // move bot towards target + bot.getLogger().info(String.format("Moving bot towards final target (%d, %d)", finalX, finalZ)); + bot.setTaskExecutor(new FlyTaskExecutor(bot, botTarget, botSpeed)); + targetSet.add(bot); + } + + // disconnect bot if arrived + TaskExecutor t = bot.getTaskExecutor(); + if (t == null || t.getStatus().getType() != TaskStatus.StatusType.IN_PROGRESS) { + bot.disconnect("Arrived at destination"); + } + } + + private Runnable newBotConnector(Bot bot) { + return () -> { + bot.connect(); + int sleep = 1000; + int tries = 3; + while (tries-- > 0 && (bot.getPlayer() == null || !bot.isJoined())) { + try { + Thread.sleep(sleep); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + if (!bot.isJoined()) { + logger.warning(String.format("Could not connect bot %s:%d.", options.host, options.port)); + bot.disconnect("Make sure to close all connections."); + } + }; + } + + protected Bot createBot() { + return newBot(UUID.randomUUID().toString().substring(0, 6)); + } + + @Override + protected boolean isDone() { + boolean timeUp = System.currentTimeMillis() - this.startMillis > this.durationInSeconds * 1_000; + if (timeUp) { + return true; + } else if (botList.size() > 0) { + boolean allBotsDisconnected; + synchronized (botList) { + allBotsDisconnected = botList.stream().allMatch(Bot::hasBeenDisconnected); + } + if (allBotsDisconnected) { + return true; + } + } + return false; + } + + @Override + protected void after() { + for (Bot bot : botList) { + bot.disconnect("disconnect"); + } + } +} From 3283df3e1a74950796129065e79d733f18e53429 Mon Sep 17 00:00:00 2001 From: Tiberiu Iancu Date: Sun, 14 Feb 2021 19:16:05 +0100 Subject: [PATCH 02/11] Added delay at the start of the experiment --- .../experiment/Experiment9GenerationStressTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java index ddd466ea..8ea6a9f0 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java @@ -26,6 +26,7 @@ public class Experiment9GenerationStressTest extends Experiment { private long startMillis; private int durationInSeconds; + private int delay; public Experiment9GenerationStressTest() { super(9, "Bots move away from the spawn location"); @@ -35,6 +36,7 @@ public Experiment9GenerationStressTest() { protected void before() { int botsTotal = Integer.parseInt(options.experimentParams.get("bots")); this.durationInSeconds = Integer.parseInt(options.experimentParams.getOrDefault("duration", "600")); + this.delay = Integer.parseInt(options.experimentParams.getOrDefault("delay", "0")) * 1000; this.targetDistance = Integer.parseInt(options.experimentParams.getOrDefault("distance", "300")); this.botSpeed = Double.parseDouble(options.experimentParams.getOrDefault("speed", "0.3")); this.startMillis = System.currentTimeMillis(); @@ -53,6 +55,10 @@ protected void before() { @Override protected void tick() { + if (System.currentTimeMillis() - startMillis < delay) { + return; + } + synchronized (botList) { List disconnectedBots = botList.stream() .filter(Bot::hasBeenDisconnected) From 9a63a96788fbad27c1fa4ff20ef6f43549baff47 Mon Sep 17 00:00:00 2001 From: Tiberiu Iancu Date: Mon, 22 Feb 2021 14:53:02 +0100 Subject: [PATCH 03/11] Distance is now a function of time and speed --- .../yardstick/experiment/Experiment9GenerationStressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java index 8ea6a9f0..46d565df 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java @@ -37,10 +37,10 @@ protected void before() { int botsTotal = Integer.parseInt(options.experimentParams.get("bots")); this.durationInSeconds = Integer.parseInt(options.experimentParams.getOrDefault("duration", "600")); this.delay = Integer.parseInt(options.experimentParams.getOrDefault("delay", "0")) * 1000; - this.targetDistance = Integer.parseInt(options.experimentParams.getOrDefault("distance", "300")); this.botSpeed = Double.parseDouble(options.experimentParams.getOrDefault("speed", "0.3")); this.startMillis = System.currentTimeMillis(); this.increment = 2 * Math.PI / botsTotal; + this.targetDistance = ((int) (1000 / TICK_MS) * durationInSeconds) * botSpeed; // connect the bots; todo: synchronized? for (int i = 0; i < botsTotal; i++) { From edaa093831bf05d88b6c29ee20704a6e18146d63 Mon Sep 17 00:00:00 2001 From: JyQuery Date: Fri, 6 Aug 2021 16:01:22 +0200 Subject: [PATCH 04/11] add straight walk and random behavior; fix bug on packet handler --- .../opencraft/yardstick/Yardstick.java | 21 +-- .../yardstick/bot/BotController.java | 5 + .../opencraft/yardstick/bot/BotListener.java | 69 ++++++++- .../yardstick/bot/ai/task/StandExecutor.java | 34 ++++ .../experiment/AbstractModelExperiment.java | 24 ++- .../experiment/Experiment10WalkStraight.java | 47 ++++++ .../experiment/Experiment11Random.java | 33 ++++ .../experiment/Experiment12RandomE2E.java | 39 +++++ .../yardstick/model/RandomModel.java | 120 ++++++++++++++ .../yardstick/model/SimpleMovementModel.java | 9 ++ .../model/StraightMovementModel.java | 146 ++++++++++++++++++ 11 files changed, 530 insertions(+), 17 deletions(-) create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java index e2820e8f..33e0ab79 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java @@ -34,16 +34,8 @@ import java.util.Properties; import java.util.Scanner; import java.util.logging.Level; -import nl.tudelft.opencraft.yardstick.experiment.Experiment; -import nl.tudelft.opencraft.yardstick.experiment.Experiment1SimpleJoin; -import nl.tudelft.opencraft.yardstick.experiment.Experiment2ScheduledJoin; -import nl.tudelft.opencraft.yardstick.experiment.Experiment3WalkAround; -import nl.tudelft.opencraft.yardstick.experiment.Experiment4MultiWalkAround; -import nl.tudelft.opencraft.yardstick.experiment.Experiment5SimpleWalk; -import nl.tudelft.opencraft.yardstick.experiment.Experiment6InteractWalk; -import nl.tudelft.opencraft.yardstick.experiment.Experiment8BoxWalkAround; -import nl.tudelft.opencraft.yardstick.experiment.Experiment9GenerationStressTest; -import nl.tudelft.opencraft.yardstick.experiment.RemoteControlledExperiment; + +import nl.tudelft.opencraft.yardstick.experiment.*; import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; import nl.tudelft.opencraft.yardstick.logging.SimpleTimeFormatter; import nl.tudelft.opencraft.yardstick.statistic.Statistics; @@ -167,6 +159,15 @@ public static void main(String[] args) { case 9: ex = new Experiment9GenerationStressTest(); break; + case 10: + ex = new Experiment10WalkStraight(); + break; + case 11: + ex = new Experiment11Random(); + break; + case 12: + ex = new Experiment12RandomE2E(); + break; default: System.out.println("Invalid experiment: " + OPTIONS.experiment); return; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java index 6751fec8..4cc89858 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java @@ -22,6 +22,7 @@ import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; import science.atlarge.opencraft.mcprotocollib.data.game.entity.player.Hand; import science.atlarge.opencraft.mcprotocollib.data.game.entity.player.PlayerAction; +import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.ClientChatPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerActionPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerPlaceBlockPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerPositionPacket; @@ -151,6 +152,10 @@ public void creativeInventoryAction(Material mat, int amt) { getSession().send(new ClientCreativeInventoryActionPacket(PLAYER_INVENTORY_HOTBAR_0, new ItemStack(mat.getId(), amt))); } + public void sendChatMsg(String msg) { + getSession().send(new ClientChatPacket(msg)); + } + /** * A state of breaking blocks. */ diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index ecae32ea..3de27bf8 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -18,12 +18,14 @@ package nl.tudelft.opencraft.yardstick.bot; +import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; import science.atlarge.opencraft.mcprotocollib.MinecraftProtocol; import science.atlarge.opencraft.mcprotocollib.data.SubProtocol; import science.atlarge.opencraft.mcprotocollib.data.game.chunk.Column; import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; import science.atlarge.opencraft.mcprotocollib.data.game.entity.type.GlobalEntityType; import science.atlarge.opencraft.mcprotocollib.data.game.world.block.BlockChangeRecord; +import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerPositionRotationPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.world.ClientTeleportConfirmPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerBossBarPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerChatPacket; @@ -110,7 +112,14 @@ import science.atlarge.opencraft.packetlib.event.session.PacketSentEvent; import science.atlarge.opencraft.packetlib.event.session.SessionListener; import science.atlarge.opencraft.packetlib.packet.Packet; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; import nl.tudelft.opencraft.yardstick.bot.entity.BotPlayer; @@ -141,6 +150,10 @@ public class BotListener implements SessionListener { private Server server; private World world; + private ConcurrentHashMap unhandledRecvPkt = new ConcurrentHashMap<>(); + private int pktCounter = 0; + private boolean serverJoinGame; + /** * Creates a new listener. * @@ -161,6 +174,7 @@ public void packetReceived(PacketReceivedEvent pre) { } Packet packet = pre.getPacket(); +// System.out.println(packet.getClass().getName()); if (packet instanceof ServerSpawnObjectPacket) { // 0x00 Spawn Object ServerSpawnObjectPacket p = (ServerSpawnObjectPacket) packet; @@ -309,6 +323,29 @@ public void packetReceived(PacketReceivedEvent pre) { ServerChatPacket p = (ServerChatPacket) packet; // TODO + // log time + long end = System.currentTimeMillis(); + + String key = null; + if (p.getMessage().getText().startsWith("There are")) + key = "banlist"; + if (p.getMessage().getText().startsWith("Banned player")) + key = "ban"; + if (p.getMessage().getText().startsWith("Unbanned")) + key = "unban"; + if (p.getMessage().getText().startsWith("Changing to clear")) + key = "clear"; + if (p.getMessage().getText().startsWith("Changing to rain and thunder")) + key = "thunder"; + try { + if (key != null) { + Experiment12RandomE2E.fw.write(end + "\t" + key + "\t" + (end - Experiment12RandomE2E.GMStartTime) + "\n"); + Experiment12RandomE2E.fw.flush(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } else if (packet instanceof ServerMultiBlockChangePacket) { // 0x10 Multi Block Change ServerMultiBlockChangePacket p = (ServerMultiBlockChangePacket) packet; @@ -451,6 +488,7 @@ public void packetReceived(PacketReceivedEvent pre) { ServerJoinGamePacket p = (ServerJoinGamePacket) packet; // TODO: Reduced debug info field? +// System.out.println(p); // Init the game this.world = new World(Dimension.forId(p.getDimension()), p.getWorldType()); bot.setWorld(world); @@ -463,6 +501,16 @@ public void packetReceived(PacketReceivedEvent pre) { this.player = new BotPlayer(bot, p.getEntityId()); player.setGamemode(p.getGameMode()); bot.setPlayer(player); + + // Replay the unhandled packet events before receiving server join game + serverJoinGame = true; + Iterator> iter = unhandledRecvPkt.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + packetReceived(entry.getValue()); + iter.remove(); + } + } else if (packet instanceof ServerMapDataPacket) { // 0x24 Map ServerMapDataPacket p = (ServerMapDataPacket) packet; @@ -511,7 +559,15 @@ public void packetReceived(PacketReceivedEvent pre) { ServerOpenTileEntityEditorPacket p = (ServerOpenTileEntityEditorPacket) packet; // TODO - } else if (packet instanceof ServerPlayerAbilitiesPacket) { + } + // ServerJoinGame packet is received after a few Player packets. + // Save them to handle later + else if (!serverJoinGame) { + unhandledRecvPkt.put(++pktCounter, pre); + return; + } + + else if (packet instanceof ServerPlayerAbilitiesPacket) { // 0x2B Player Abilities ServerPlayerAbilitiesPacket p = (ServerPlayerAbilitiesPacket) packet; @@ -539,16 +595,16 @@ public void packetReceived(PacketReceivedEvent pre) { } else if (packet instanceof ServerPlayerPositionRotationPacket) { // 0x2E Player Position And Look ServerPlayerPositionRotationPacket p = (ServerPlayerPositionRotationPacket) packet; - BotPlayer player = bot.getPlayer(); + player.setLocation(new Vector3d(p.getX(), p.getY(), p.getZ())); player.setPitch(p.getPitch()); player.setYaw(p.getYaw()); player.setOnGround(true); Session session = bot.getClient().getSession(); - session.send(new ClientTeleportConfirmPacket(p.getTeleportId())); - +// session.send(new ClientTeleportConfirmPacket(p.getTeleportId())); + session.send(new ClientPlayerPositionRotationPacket(true, p.getX(), p.getY(),p.getZ(),p.getYaw(),p.getPitch())); logger.info("Received new Player position: " + player.getLocation()); } else if (packet instanceof ServerPlayerUseBedPacket) { @@ -721,9 +777,10 @@ public void packetReceived(PacketReceivedEvent pre) { ServerEntityEffectPacket p = (ServerEntityEffectPacket) packet; // TODO - } else { - logger.warning("Received unhandled packet: " + packet.getClass().getName()); } +// else { +// logger.warning("Received unhandled packet: " + packet.getClass().getName()); +// } } @Override diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java new file mode 100644 index 00000000..46e7e4c7 --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java @@ -0,0 +1,34 @@ +package nl.tudelft.opencraft.yardstick.bot.ai.task; + +import nl.tudelft.opencraft.yardstick.bot.Bot; + +public class StandExecutor extends AbstractTaskExecutor{ + private int timeout = 1000; + private final long startTime; + + + public StandExecutor(Bot bot) { + super(bot); + startTime = System.currentTimeMillis(); + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + @Override + protected TaskStatus onTick() { + long nowTime = System.currentTimeMillis(); +// logger.info("standing, remaing time=" + (timeout+startTime - nowTime)); + if (nowTime - startTime >= timeout) { + return TaskStatus.forSuccess(); + } else { + return TaskStatus.forInProgress(); + } + } + + @Override + protected void onStop() { + + } +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java index 00799a19..09922eed 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java @@ -18,6 +18,7 @@ package nl.tudelft.opencraft.yardstick.experiment; +import java.io.IOException; import java.util.*; import java.util.stream.Collectors; import nl.tudelft.opencraft.yardstick.bot.Bot; @@ -98,8 +99,21 @@ private void botTick(Bot bot) { private Runnable newBotConnector(Bot bot) { return () -> { + long start = System.currentTimeMillis(); bot.connect(); - int sleep = 1000; + + // log login time if the bot is connected (exp12) + if (number == 12 && bot.isConnected()) { + long end = System.currentTimeMillis(); + try { + Experiment12RandomE2E.fw.write(end + "\t" + "login\t" + (end-start) + "\n"); + Experiment12RandomE2E.fw.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + int sleep = 2000; int tries = 3; while (tries-- > 0 && (bot.getPlayer() == null || !bot.isJoined())) { try { @@ -109,9 +123,13 @@ private Runnable newBotConnector(Bot bot) { break; } } + if (!bot.isJoined()) { logger.warning(String.format("Could not connect bot %s:%d.", options.host, options.port)); bot.disconnect("Make sure to close all connections."); + if (number == 10) { + Experiment10WalkStraight.currBotId -= Experiment10WalkStraight.clientCount; + } } }; } @@ -144,4 +162,8 @@ protected void after() { bot.disconnect("disconnect"); } } + + public BotModel getModel() { + return model; + } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java new file mode 100644 index 00000000..a12da3e6 --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java @@ -0,0 +1,47 @@ +/* + * Yardstick: A Benchmark for Minecraft-like Services + * Copyright (C) 2020 AtLarge Research + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package nl.tudelft.opencraft.yardstick.experiment; + +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.model.StraightMovementModel; +import java.util.UUID; + + +public class Experiment10WalkStraight extends AbstractModelExperiment { + + public static int currBotId; + public static int clientCount; + public static double walkSpeed; + + public Experiment10WalkStraight() { + super(10, "Bots move towards different directions based on their IDs", new StraightMovementModel()); + StraightMovementModel model = (StraightMovementModel) getModel(); + currBotId = Integer.parseInt(options.experimentParams.getOrDefault("botstartid", "0")); + clientCount = Integer.parseInt(options.experimentParams.getOrDefault("clientcount", "1")); + walkSpeed = Double.parseDouble(options.experimentParams.getOrDefault("walkspeed", "0.15")); + model.setWalkSpeed(walkSpeed); + + } + + protected Bot createBot() { + Bot bot = newBot(UUID.randomUUID().toString().substring(0, 6)+"-"+(currBotId)); + currBotId+=clientCount; + return bot; + } +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java new file mode 100644 index 00000000..9eb20f81 --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java @@ -0,0 +1,33 @@ +/* + * Yardstick: A Benchmark for Minecraft-like Services + * Copyright (C) 2020 AtLarge Research + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package nl.tudelft.opencraft.yardstick.experiment; + +import nl.tudelft.opencraft.yardstick.model.RandomModel; + +import java.io.FileWriter; + +public class Experiment11Random extends AbstractModelExperiment { + + public Experiment11Random() { + super(11, "Bots move around randomly and have a chance to break or place blocks", new RandomModel()); + RandomModel randomModel = (RandomModel) getModel(); + randomModel.setMovementDiameter(0); + } + +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java new file mode 100644 index 00000000..a2a7d15c --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java @@ -0,0 +1,39 @@ +package nl.tudelft.opencraft.yardstick.experiment; + +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.model.RandomModel; + +import java.io.FileWriter; +import java.util.UUID; + +public class Experiment12RandomE2E extends AbstractModelExperiment { + public static FileWriter fw; + private boolean GMjoined; + private String GMuser; + public static long GMStartTime; + public static String GMCommand; + + public Experiment12RandomE2E() { + super(12, "Bots move around randomly with one GM; log E2E latency", new RandomModel()); + try { + fw = new FileWriter("event.log"); + } catch (Exception e) { + e.printStackTrace(); + } + GMuser = options.experimentParams.get("gmuser"); + GMCommand = options.experimentParams.getOrDefault("gmcommand", "random"); + RandomModel randomModel = (RandomModel) getModel(); + randomModel.setMovementDiameter(0); + randomModel.setGMUser(GMuser); + randomModel.setGMInterval(Long.parseLong(options.experimentParams.getOrDefault("gminterval", "10"))); + } + + protected Bot createBot() { + if (!GMjoined && GMuser!=null) { + GMjoined = true; + return newBot(GMuser); + } else { + return newBot(UUID.randomUUID().toString().substring(0, 6)); + } + } +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java new file mode 100644 index 00000000..8b3a64e4 --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java @@ -0,0 +1,120 @@ +package nl.tudelft.opencraft.yardstick.model; + +import nl.tudelft.opencraft.yardstick.Options; +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.bot.ai.task.StandExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.WalkTaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.world.Material; +import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; + +import java.util.ArrayList; +import java.util.Random; +import java.util.UUID; + + +public class RandomModel implements BotModel { + private BotModel interact = new SimpleInteractionModel(); + private BotModel movement = new SimpleMovementModel(); + + private String GMuser; + private long GMInterval; + private ArrayList bannedUser = new ArrayList<>(); + + public RandomModel(){ + + } + + @Override + public TaskExecutor newTask(Bot bot) { + TaskExecutor taskExecutor = null; + Random RANDOM = new Random(System.nanoTime()); + double random = RANDOM.nextDouble(); + + // GM execute command + if (bot.getName().equals(GMuser)) { + if (System.currentTimeMillis() - Experiment12RandomE2E.GMStartTime >= GMInterval * 1000) { + String command = null; + + switch (Experiment12RandomE2E.GMCommand) { + case "weather": + if (random < 1/2.0) + command = "/weather clear"; + else command = "/weather thunder"; + break; + + case "random": default: + if (random < 1 / 2.0) { + if (RANDOM.nextDouble() < 1 / 2.0) { + String target = UUID.randomUUID().toString().substring(0, 6); + command = "/ban " + target; + bannedUser.add(target); + } else if (bannedUser.size() > 0) { + int index = RANDOM.nextInt(bannedUser.size()); + command = "/pardon " + bannedUser.get(index); + bannedUser.remove(index); + } + } else { + command = "/banlist"; + } + break; + } + + if (command != null) { + Experiment12RandomE2E.GMStartTime = System.currentTimeMillis(); + bot.getController().sendChatMsg(command); + } + } + } + + + if (random <= 0.3) { + // Interact + taskExecutor = interact.newTask(bot); + } + else if (random > 0.3 && random <= 0.7) { + // Movement + taskExecutor = movement.newTask(bot); + + // random walk speed between [0.1, 0.4] + double walkSpeed = RANDOM.nextDouble() * 0.4; + if (walkSpeed < 0.1) + walkSpeed = 0.15; + ((WalkTaskExecutor) taskExecutor).setSpeed(walkSpeed); + } + + else if (random > 0.7 && random <= 0.8) { + // send msg + if (RANDOM.nextDouble() < 0.5) + bot.getController().sendChatMsg("hey"); + // get item + else { + Material mt = Material.getById(RANDOM.nextInt(187)); + if (mt != Material.UNKNOWN) + bot.getController().creativeInventoryAction(mt, RANDOM.nextInt(9) + 1); + } + StandExecutor stand = new StandExecutor(bot); + stand.setTimeout(500); + return stand; + } + + // stand still + else { + return new StandExecutor(bot); + } + + return taskExecutor; + } + + public void setMovementDiameter(int dia) { + movement = new SimpleMovementModel(dia); + } + + public void setGMUser(String GMuser) { + this.GMuser = GMuser; + } + + public void setGMInterval(long GMInterval) { + this.GMInterval = GMInterval; + } +} diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java index 7afc128a..1188e0da 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java @@ -78,6 +78,15 @@ public Vector3i newTargetLocation(Bot bot) { */ Vector3i getNewFieldLocation(Bot bot) { Vector3d originalLocation = getStartLocation(bot); + + // No bound random + if (boxDiameter == 0) { + int newX = (int) (originalLocation.getX() + RANDOM.nextInt(10) * (RANDOM.nextBoolean() ? -1 : 1) * RANDOM.nextDouble()); + int newZ = (int) (originalLocation.getZ() + RANDOM.nextInt(10) * (RANDOM.nextBoolean() ? -1 : 1) * RANDOM.nextDouble()); + return getTargetAt(bot, newX, newZ); + } + + int maxx = ((int) originalLocation.getX()) + boxDiameter / 2; int minx = ((int) originalLocation.getX()) - boxDiameter / 2; int maxz = ((int) originalLocation.getZ()) + boxDiameter / 2; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java new file mode 100644 index 00000000..d7bf11b0 --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java @@ -0,0 +1,146 @@ +/* + * Yardstick: A Benchmark for Minecraft-like Services + * Copyright (C) 2020 AtLarge Research + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package nl.tudelft.opencraft.yardstick.model; + +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.WalkTaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.world.Block; +import nl.tudelft.opencraft.yardstick.bot.world.BlockFace; +import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; +import nl.tudelft.opencraft.yardstick.util.Vector3d; +import nl.tudelft.opencraft.yardstick.util.Vector3i; +import nl.tudelft.opencraft.yardstick.util.ZigZagRange; + +import java.util.HashMap; +import java.util.Random; + +/** + * Represents a model which moves the bot randomly to short and long distance + * locations. + */ +public class StraightMovementModel implements BotModel { + private Random random; + public static HashMap botsTarget = new HashMap<>(); + public double walkSpeed = 0.15; + + public StraightMovementModel() { + this.random = new Random(); + } + + @Override + public TaskExecutor newTask(Bot bot) { + WalkTaskExecutor exe = new WalkTaskExecutor(bot, newTargetLocation(bot)); + if (walkSpeed != 0.15) + exe.setSpeed(walkSpeed); + return exe; + } + + public Vector3i newTargetLocation(Bot bot) { + Vector3d originalLocation = bot.getPlayer().getLocation(); + int dis = 16; + + int newX = (int) originalLocation.getX(); + int newZ = (int) originalLocation.getZ(); + + int botId = Integer.parseInt(bot.getName().split("-")[1]); + + double factor = 0; + if (botId > 7) + factor = botId / 8.0; + + switch (botId % 8) { + case 0: + newX+=dis; + newZ+=(int)factor*dis; + break; + case 1: + newZ+=dis; + newX+=(int)factor*dis; + break; + case 2: + newX-=dis; + newZ-=(int)factor*dis; + break; + case 3: + newZ-=dis; + newX-=(int)factor*dis; + break; + case 4: + newX+=dis+(int)factor*dis; + newZ+=dis+(int)factor*dis; + break; + case 5: + newX-=dis-(int)factor*dis; + newZ-=dis-(int)factor*dis; + break; + case 6: + newX+=dis+(int)factor*dis; + newZ-=dis-(int)factor*dis; + break; + case 7: + newX-=dis-(int)factor*dis; + newZ+=dis+(int)factor*dis; + break; + } + + Vector3i prevTarget = botsTarget.get(bot); + if (prevTarget!=null && (int)prevTarget.getX() == newX && (int)prevTarget.getZ() == newZ) { + newX = (int) (originalLocation.getX() + random.nextInt(8) * (random.nextBoolean() ? -1 : 1) * random.nextDouble()); + newZ = (int) (originalLocation.getZ() + random.nextInt(8) * (random.nextBoolean() ? -1 : 1) * random.nextDouble()); + } + +// String regionFile = "r." + (newX >> 5) + "." + (newZ >> 5); +// System.out.println("BotID="+botId+",newX="+newX+",newZ="+newZ); + + Vector3i nextTarget = getTargetAt(bot, newX, newZ); + botsTarget.put(bot, nextTarget); + + return nextTarget; + } + + private Vector3i getTargetAt(Bot bot, int x, int z) { + Vector3d botLoc = bot.getPlayer().getLocation(); + + int y = -1; + try { + for (ZigZagRange it = new ZigZagRange(0, 255, (int) botLoc.getY()); it.hasNext(); ) { + y = it.next(); + Block test = bot.getWorld().getBlockAt(x, y, z); + if (test.getMaterial().isTraversable() + && !test.getRelative(BlockFace.BOTTOM).getMaterial().isTraversable()) { + break; + } + } + + if (y < 0 || y > 255) { + return botLoc.intVector(); + } + + return new Vector3i(x, y, z); + } catch (ChunkNotLoadedException ex) { + bot.getLogger().warning("Bot target not loaded: (" + x + "," + y + "," + z + ")"); + return botLoc.intVector(); + } + } + + public void setWalkSpeed(double walkSpeed) { + this.walkSpeed = walkSpeed; + } +} From ae0dee2139c4d7df171fdb92f712ea3be091b647 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 16:29:07 +0100 Subject: [PATCH 05/11] style: format code and imports --- .../opencraft/yardstick/Yardstick.java | 15 +++- .../yardstick/bot/BotController.java | 20 ++--- .../opencraft/yardstick/bot/BotListener.java | 69 ++++++++------- .../ai/pathfinding/PathSearchProvider.java | 2 +- .../bot/ai/task/BreakBlocksTask.java | 5 +- .../bot/ai/task/BreakBlocksTaskExecutor.java | 4 +- .../bot/ai/task/FlyTaskExecutor.java | 11 ++- .../bot/ai/task/PlaceBlocksTask.java | 3 +- .../bot/ai/task/PlaceBlocksTaskExecutor.java | 12 +-- .../bot/ai/task/RandomSquareWalkXZTask.java | 3 +- .../yardstick/bot/ai/task/StandExecutor.java | 2 +- .../opencraft/yardstick/bot/ai/task/Task.java | 6 +- .../yardstick/bot/entity/BotPlayer.java | 5 +- .../yardstick/bot/entity/Entity.java | 1 - .../opencraft/yardstick/bot/world/Block.java | 6 +- .../yardstick/bot/world/Material.java | 13 ++- .../bot/world/SimpleWorldPhysics.java | 63 +++++++------- .../opencraft/yardstick/bot/world/World.java | 4 +- .../experiment/AbstractModelExperiment.java | 7 +- .../yardstick/experiment/Experiment.java | 8 +- .../experiment/Experiment10WalkStraight.java | 6 +- .../experiment/Experiment11Random.java | 2 - .../experiment/Experiment12RandomE2E.java | 7 +- .../experiment/Experiment1SimpleJoin.java | 2 +- .../experiment/Experiment2ScheduledJoin.java | 2 +- .../experiment/Experiment3WalkAround.java | 2 +- .../experiment/Experiment8BoxWalkAround.java | 10 +-- .../Experiment9GenerationStressTest.java | 11 ++- .../RemoteControlledExperiment.java | 11 ++- .../logging/SimpleConsoleHandler.java | 1 + .../yardstick/logging/SimpleFileHandler.java | 5 +- .../yardstick/model/RandomModel.java | 37 ++++---- .../model/SimpleInteractionModel.java | 2 +- .../yardstick/model/SimpleMovementModel.java | 2 +- .../model/StraightMovementModel.java | 47 +++++----- .../yardstick/statistic/Statistics.java | 86 ++++++++++--------- .../yardstick/statistic/StatisticsPusher.java | 4 +- .../opencraft/yardstick/util/PacketUtil.java | 4 +- .../opencraft/yardstick/util/Report.java | 6 +- .../opencraft/yardstick/util/Scheduler.java | 2 +- .../opencraft/yardstick/util/WorldUtil.java | 4 +- .../yardstick/workload/CsvConverter.java | 6 +- .../yardstick/workload/PacketEntry.java | 12 +-- .../yardstick/workload/WorkloadDumper.java | 10 +-- .../workload/WorkloadSessionListener.java | 2 +- 45 files changed, 285 insertions(+), 257 deletions(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java index 33e0ab79..0c45ee7e 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/Yardstick.java @@ -34,8 +34,19 @@ import java.util.Properties; import java.util.Scanner; import java.util.logging.Level; - -import nl.tudelft.opencraft.yardstick.experiment.*; +import nl.tudelft.opencraft.yardstick.experiment.Experiment; +import nl.tudelft.opencraft.yardstick.experiment.Experiment10WalkStraight; +import nl.tudelft.opencraft.yardstick.experiment.Experiment11Random; +import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; +import nl.tudelft.opencraft.yardstick.experiment.Experiment1SimpleJoin; +import nl.tudelft.opencraft.yardstick.experiment.Experiment2ScheduledJoin; +import nl.tudelft.opencraft.yardstick.experiment.Experiment3WalkAround; +import nl.tudelft.opencraft.yardstick.experiment.Experiment4MultiWalkAround; +import nl.tudelft.opencraft.yardstick.experiment.Experiment5SimpleWalk; +import nl.tudelft.opencraft.yardstick.experiment.Experiment6InteractWalk; +import nl.tudelft.opencraft.yardstick.experiment.Experiment8BoxWalkAround; +import nl.tudelft.opencraft.yardstick.experiment.Experiment9GenerationStressTest; +import nl.tudelft.opencraft.yardstick.experiment.RemoteControlledExperiment; import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; import nl.tudelft.opencraft.yardstick.logging.SimpleTimeFormatter; import nl.tudelft.opencraft.yardstick.statistic.Statistics; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java index 4cc89858..95328c7d 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotController.java @@ -18,6 +18,12 @@ package nl.tudelft.opencraft.yardstick.bot; +import nl.tudelft.opencraft.yardstick.bot.entity.BotPlayer; +import nl.tudelft.opencraft.yardstick.bot.world.Block; +import nl.tudelft.opencraft.yardstick.bot.world.BlockFace; +import nl.tudelft.opencraft.yardstick.bot.world.Material; +import nl.tudelft.opencraft.yardstick.util.Vector3d; +import nl.tudelft.opencraft.yardstick.util.Vector3i; import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.ItemStack; import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; import science.atlarge.opencraft.mcprotocollib.data.game.entity.player.Hand; @@ -31,12 +37,6 @@ import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.window.ClientCreativeInventoryActionPacket; import science.atlarge.opencraft.packetlib.Session; import science.atlarge.opencraft.packetlib.packet.Packet; -import nl.tudelft.opencraft.yardstick.bot.entity.BotPlayer; -import nl.tudelft.opencraft.yardstick.bot.world.Block; -import nl.tudelft.opencraft.yardstick.bot.world.BlockFace; -import nl.tudelft.opencraft.yardstick.bot.world.Material; -import nl.tudelft.opencraft.yardstick.util.Vector3d; -import nl.tudelft.opencraft.yardstick.util.Vector3i; /** * Represents actions for controlling a {@link Bot}. @@ -91,7 +91,7 @@ public void updateLocation(Vector3d vector) { * Updates the Minecraft server of the Bot's digging status. * * @param block the block the bot is digging. - * @param face the face the bot is digging. + * @param face the face the bot is digging. * @param state the digging state. */ public void updateDigging(Block block, BlockFace face, DiggingState state) { @@ -116,8 +116,8 @@ public void updateDigging(Block block, BlockFace face, DiggingState state) { /** * Updates the Minecraft server of block placement. * - * @param block The block the bot is placing. - * @param face The face the bot is placing at. + * @param block The block the bot is placing. + * @param face The face the bot is placing at. * @param hitpoint The hitpoint of the cursor. */ public void placeBlock(Vector3i block, BlockFace face, Vector3d hitpoint) { @@ -176,7 +176,7 @@ private double[] calculateYawPitch(Vector3d from, Vector3d to) { yaw += 360; } double pitch = -Math.asin(dv.getY() / r) / Math.PI * 180; - return new double[]{yaw, pitch}; + return new double[] {yaw, pitch}; } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index 3de27bf8..15ffa0c7 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -18,7 +18,29 @@ package nl.tudelft.opencraft.yardstick.bot; +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; +import nl.tudelft.opencraft.yardstick.bot.entity.BotPlayer; +import nl.tudelft.opencraft.yardstick.bot.entity.Entity; +import nl.tudelft.opencraft.yardstick.bot.entity.ExperienceOrb; +import nl.tudelft.opencraft.yardstick.bot.entity.LightningStrike; +import nl.tudelft.opencraft.yardstick.bot.entity.Mob; +import nl.tudelft.opencraft.yardstick.bot.entity.ObjectEntity; +import nl.tudelft.opencraft.yardstick.bot.entity.Painting; +import nl.tudelft.opencraft.yardstick.bot.entity.Player; +import nl.tudelft.opencraft.yardstick.bot.world.Block; +import nl.tudelft.opencraft.yardstick.bot.world.Chunk; +import nl.tudelft.opencraft.yardstick.bot.world.ChunkLocation; +import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; +import nl.tudelft.opencraft.yardstick.bot.world.Dimension; +import nl.tudelft.opencraft.yardstick.bot.world.World; import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; +import nl.tudelft.opencraft.yardstick.util.Vector3d; import science.atlarge.opencraft.mcprotocollib.MinecraftProtocol; import science.atlarge.opencraft.mcprotocollib.data.SubProtocol; import science.atlarge.opencraft.mcprotocollib.data.game.chunk.Column; @@ -26,7 +48,6 @@ import science.atlarge.opencraft.mcprotocollib.data.game.entity.type.GlobalEntityType; import science.atlarge.opencraft.mcprotocollib.data.game.world.block.BlockChangeRecord; import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerPositionRotationPacket; -import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.world.ClientTeleportConfirmPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerBossBarPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerChatPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerCombatPacket; @@ -113,31 +134,6 @@ import science.atlarge.opencraft.packetlib.event.session.SessionListener; import science.atlarge.opencraft.packetlib.packet.Packet; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Future; -import java.util.logging.Level; -import java.util.logging.Logger; -import nl.tudelft.opencraft.yardstick.bot.entity.BotPlayer; -import nl.tudelft.opencraft.yardstick.bot.entity.Entity; -import nl.tudelft.opencraft.yardstick.bot.entity.ExperienceOrb; -import nl.tudelft.opencraft.yardstick.bot.entity.LightningStrike; -import nl.tudelft.opencraft.yardstick.bot.entity.Mob; -import nl.tudelft.opencraft.yardstick.bot.entity.ObjectEntity; -import nl.tudelft.opencraft.yardstick.bot.entity.Painting; -import nl.tudelft.opencraft.yardstick.bot.entity.Player; -import nl.tudelft.opencraft.yardstick.bot.world.Block; -import nl.tudelft.opencraft.yardstick.bot.world.Chunk; -import nl.tudelft.opencraft.yardstick.bot.world.ChunkLocation; -import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; -import nl.tudelft.opencraft.yardstick.bot.world.Dimension; -import nl.tudelft.opencraft.yardstick.bot.world.World; -import nl.tudelft.opencraft.yardstick.util.Vector3d; - /** * Handles basic bot network traffic. */ @@ -327,16 +323,21 @@ public void packetReceived(PacketReceivedEvent pre) { long end = System.currentTimeMillis(); String key = null; - if (p.getMessage().getText().startsWith("There are")) + if (p.getMessage().getText().startsWith("There are")) { key = "banlist"; - if (p.getMessage().getText().startsWith("Banned player")) + } + if (p.getMessage().getText().startsWith("Banned player")) { key = "ban"; - if (p.getMessage().getText().startsWith("Unbanned")) + } + if (p.getMessage().getText().startsWith("Unbanned")) { key = "unban"; - if (p.getMessage().getText().startsWith("Changing to clear")) + } + if (p.getMessage().getText().startsWith("Changing to clear")) { key = "clear"; - if (p.getMessage().getText().startsWith("Changing to rain and thunder")) + } + if (p.getMessage().getText().startsWith("Changing to rain and thunder")) { key = "thunder"; + } try { if (key != null) { Experiment12RandomE2E.fw.write(end + "\t" + key + "\t" + (end - Experiment12RandomE2E.GMStartTime) + "\n"); @@ -565,9 +566,7 @@ public void packetReceived(PacketReceivedEvent pre) { else if (!serverJoinGame) { unhandledRecvPkt.put(++pktCounter, pre); return; - } - - else if (packet instanceof ServerPlayerAbilitiesPacket) { + } else if (packet instanceof ServerPlayerAbilitiesPacket) { // 0x2B Player Abilities ServerPlayerAbilitiesPacket p = (ServerPlayerAbilitiesPacket) packet; @@ -604,7 +603,7 @@ else if (packet instanceof ServerPlayerAbilitiesPacket) { Session session = bot.getClient().getSession(); // session.send(new ClientTeleportConfirmPacket(p.getTeleportId())); - session.send(new ClientPlayerPositionRotationPacket(true, p.getX(), p.getY(),p.getZ(),p.getYaw(),p.getPitch())); + session.send(new ClientPlayerPositionRotationPacket(true, p.getX(), p.getY(), p.getZ(), p.getYaw(), p.getPitch())); logger.info("Received new Player position: " + player.getLocation()); } else if (packet instanceof ServerPlayerUseBedPacket) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/pathfinding/PathSearchProvider.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/pathfinding/PathSearchProvider.java index fe01707a..b7d78002 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/pathfinding/PathSearchProvider.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/pathfinding/PathSearchProvider.java @@ -42,9 +42,9 @@ package nl.tudelft.opencraft.yardstick.bot.ai.pathfinding; import nl.tudelft.opencraft.yardstick.bot.ai.pathfinding.astar.heuristic.Heuristic; +import nl.tudelft.opencraft.yardstick.bot.world.World; import nl.tudelft.opencraft.yardstick.bot.world.WorldPhysics; import nl.tudelft.opencraft.yardstick.util.Vector3i; -import nl.tudelft.opencraft.yardstick.bot.world.World; public interface PathSearchProvider { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTask.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTask.java index 06d7470a..eeabb4d6 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTask.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTask.java @@ -18,14 +18,13 @@ package nl.tudelft.opencraft.yardstick.bot.ai.task; +import java.util.ArrayList; +import java.util.List; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.world.Block; import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; import nl.tudelft.opencraft.yardstick.util.Vector3i; -import java.util.ArrayList; -import java.util.List; - public class BreakBlocksTask implements Task { private List blockLocations; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTaskExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTaskExecutor.java index 364f5b03..f3875815 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTaskExecutor.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/BreakBlocksTaskExecutor.java @@ -18,9 +18,9 @@ package nl.tudelft.opencraft.yardstick.bot.ai.task; +import com.beust.jcommander.internal.Lists; import java.util.Iterator; import java.util.List; -import com.beust.jcommander.internal.Lists; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.BotController; import nl.tudelft.opencraft.yardstick.bot.world.Block; @@ -42,7 +42,7 @@ public class BreakBlocksTaskExecutor extends AbstractTaskExecutor { * Creates a new BreakBlocksTask. The blocks must be in reach and visible to * the bot. * - * @param bot the bot of the task. + * @param bot the bot of the task. * @param blocks the blocks that must be broken. */ public BreakBlocksTaskExecutor(Bot bot, List blocks) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java index 8f0edc2c..e17c8262 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/FlyTaskExecutor.java @@ -74,8 +74,12 @@ protected TaskStatus onTick() { } // account for direction - if (target.getX() < nextLocation.getX()) moveX *= -1; - if (target.getZ() < nextLocation.getZ()) moveZ *= -1; + if (target.getX() < nextLocation.getX()) { + moveX *= -1; + } + if (target.getZ() < nextLocation.getZ()) { + moveZ *= -1; + } nextLocation = nextLocation.add(moveX, 0, moveZ); } @@ -86,5 +90,6 @@ protected TaskStatus onTick() { } @Override - protected void onStop() {} + protected void onStop() { + } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTask.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTask.java index 4d34a0ea..034f5bef 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTask.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTask.java @@ -18,12 +18,11 @@ package nl.tudelft.opencraft.yardstick.bot.ai.task; +import java.util.List; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.world.Material; import nl.tudelft.opencraft.yardstick.util.Vector3i; -import java.util.List; - public class PlaceBlocksTask implements Task { private List blockPositions; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTaskExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTaskExecutor.java index f3db0f4e..1e6705ec 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTaskExecutor.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/PlaceBlocksTaskExecutor.java @@ -18,11 +18,11 @@ package nl.tudelft.opencraft.yardstick.bot.ai.task; +import com.beust.jcommander.internal.Lists; +import com.beust.jcommander.internal.Sets; import java.util.Iterator; import java.util.List; import java.util.Set; -import com.beust.jcommander.internal.Lists; -import com.beust.jcommander.internal.Sets; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.world.Block; import nl.tudelft.opencraft.yardstick.bot.world.BlockFace; @@ -45,9 +45,9 @@ public class PlaceBlocksTaskExecutor extends AbstractTaskExecutor { * Creates a new PlaceBlocksTask. The locations must be visible and * reachable to the bot. * - * @param bot the bot for the task. + * @param bot the bot for the task. * @param locations the locations at which to place blocks. - * @param material the material type of the blocks. + * @param material the material type of the blocks. */ public PlaceBlocksTaskExecutor(Bot bot, List locations, Material material) { super(bot); @@ -156,9 +156,9 @@ private Hitpoint tryGetHitpoint(Vector3d from, Block placeAt) { * Returns the hit point from a point to the center of a block face of a * block. * - * @param from The viewpoint or origin of the ray trace. + * @param from The viewpoint or origin of the ray trace. * @param support The block to ray trace to. - * @param face The face of the block. + * @param face The face of the block. * @return The hit point if the ray trace was successful, null if a * occluding block was found. */ diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/RandomSquareWalkXZTask.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/RandomSquareWalkXZTask.java index e50b8e9c..3490e9ed 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/RandomSquareWalkXZTask.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/RandomSquareWalkXZTask.java @@ -18,13 +18,12 @@ package nl.tudelft.opencraft.yardstick.bot.ai.task; +import java.util.Random; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; import nl.tudelft.opencraft.yardstick.util.Vector2i; import nl.tudelft.opencraft.yardstick.util.Vector3i; -import java.util.Random; - public class RandomSquareWalkXZTask implements Task { private Vector2i center; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java index 46e7e4c7..71758549 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java @@ -2,7 +2,7 @@ import nl.tudelft.opencraft.yardstick.bot.Bot; -public class StandExecutor extends AbstractTaskExecutor{ +public class StandExecutor extends AbstractTaskExecutor { private int timeout = 1000; private final long startTime; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/Task.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/Task.java index c1a42bf2..d000b449 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/Task.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/Task.java @@ -27,11 +27,11 @@ use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") -@JsonSubTypes({ +@JsonSubTypes( { @JsonSubTypes.Type(value = BreakBlocksTask.class, name = "break-blocks"), @JsonSubTypes.Type(value = PlaceBlocksTask.class, name = "place-blocks"), - @JsonSubTypes.Type(value = WalkXZTask.class, name="walk-xz"), - @JsonSubTypes.Type(value = RandomSquareWalkXZTask.class, name="random-square-walk-xz") + @JsonSubTypes.Type(value = WalkXZTask.class, name = "walk-xz"), + @JsonSubTypes.Type(value = RandomSquareWalkXZTask.class, name = "random-square-walk-xz") }) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) public interface Task { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/BotPlayer.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/BotPlayer.java index efc30bf3..39e9739a 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/BotPlayer.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/BotPlayer.java @@ -18,13 +18,12 @@ package nl.tudelft.opencraft.yardstick.bot.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.nio.charset.Charset; import java.util.UUID; - -import com.fasterxml.jackson.annotation.JsonIgnore; +import nl.tudelft.opencraft.yardstick.bot.Bot; import science.atlarge.opencraft.mcprotocollib.data.game.entity.player.GameMode; import science.atlarge.opencraft.packetlib.Session; -import nl.tudelft.opencraft.yardstick.bot.Bot; /** * Represents the bot as a player in the world. diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/Entity.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/Entity.java index ba0ee500..ec11576d 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/Entity.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/entity/Entity.java @@ -20,7 +20,6 @@ import java.util.Objects; import java.util.UUID; - import nl.tudelft.opencraft.yardstick.util.Vector3d; /** diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Block.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Block.java index 6cfb6d9d..1835bdb3 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Block.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Block.java @@ -18,13 +18,13 @@ package nl.tudelft.opencraft.yardstick.bot.world; -import science.atlarge.opencraft.mcprotocollib.data.game.chunk.BlockStorage; -import science.atlarge.opencraft.mcprotocollib.data.game.chunk.Column; -import science.atlarge.opencraft.mcprotocollib.data.game.world.block.BlockState; import com.google.common.base.Preconditions; import java.util.Objects; import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; import nl.tudelft.opencraft.yardstick.util.Vector3i; +import science.atlarge.opencraft.mcprotocollib.data.game.chunk.BlockStorage; +import science.atlarge.opencraft.mcprotocollib.data.game.chunk.Column; +import science.atlarge.opencraft.mcprotocollib.data.game.world.block.BlockState; public class Block { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Material.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Material.java index eb44382c..d09a292f 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Material.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/Material.java @@ -38,11 +38,20 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package nl.tudelft.opencraft.yardstick.bot.world; +import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.AXE; +import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.PICKAXE; +import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.SHEARS; +import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.SHOVEL; +import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.SWORD; +import static nl.tudelft.opencraft.yardstick.bot.world.Material.Flag.FLUID; +import static nl.tudelft.opencraft.yardstick.bot.world.Material.Flag.INDESTRUCTABLE; +import static nl.tudelft.opencraft.yardstick.bot.world.Material.Flag.INTERACTABLE; +import static nl.tudelft.opencraft.yardstick.bot.world.Material.Flag.TRAVERSABLE; + import nl.tudelft.opencraft.yardstick.bot.inventory.ToolType; -import static nl.tudelft.opencraft.yardstick.bot.inventory.ToolType.*; -import static nl.tudelft.opencraft.yardstick.bot.world.Material.Flag.*; public enum Material { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/SimpleWorldPhysics.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/SimpleWorldPhysics.java index d9184e68..22c63158 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/SimpleWorldPhysics.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/SimpleWorldPhysics.java @@ -38,42 +38,43 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package nl.tudelft.opencraft.yardstick.bot.world; import nl.tudelft.opencraft.yardstick.util.Vector3i; public class SimpleWorldPhysics implements WorldPhysics { - private static final Vector3i[] SURROUNDING = new Vector3i[]{ - // middle --- y + 0 - new Vector3i(-1, 0, 1), - new Vector3i(0, 0, 1), - new Vector3i(1, 0, 1), - new Vector3i(-1, 0, 0), - new Vector3i(1, 0, 0), - new Vector3i(-1, 0, -1), - new Vector3i(0, 0, -1), - new Vector3i(1, 0, -1), - // bottom --- y - 1 - new Vector3i(-1, -1, 1), - new Vector3i(0, -1, 1), - new Vector3i(1, -1, 1), - new Vector3i(-1, -1, 0), - new Vector3i(0, -1, 0), - new Vector3i(1, -1, 0), - new Vector3i(-1, -1, -1), - new Vector3i(0, -1, -1), - new Vector3i(1, -1, -1), - // top --- y + 1 - new Vector3i(-1, 1, 1), - new Vector3i(0, 1, 1), - new Vector3i(1, 1, 1), - new Vector3i(-1, 1, 0), - new Vector3i(0, 1, 0), - new Vector3i(1, 1, 0), - new Vector3i(-1, 1, -1), - new Vector3i(0, 1, -1), - new Vector3i(1, 1, -1),}; + private static final Vector3i[] SURROUNDING = new Vector3i[] { + // middle --- y + 0 + new Vector3i(-1, 0, 1), + new Vector3i(0, 0, 1), + new Vector3i(1, 0, 1), + new Vector3i(-1, 0, 0), + new Vector3i(1, 0, 0), + new Vector3i(-1, 0, -1), + new Vector3i(0, 0, -1), + new Vector3i(1, 0, -1), + // bottom --- y - 1 + new Vector3i(-1, -1, 1), + new Vector3i(0, -1, 1), + new Vector3i(1, -1, 1), + new Vector3i(-1, -1, 0), + new Vector3i(0, -1, 0), + new Vector3i(1, -1, 0), + new Vector3i(-1, -1, -1), + new Vector3i(0, -1, -1), + new Vector3i(1, -1, -1), + // top --- y + 1 + new Vector3i(-1, 1, 1), + new Vector3i(0, 1, 1), + new Vector3i(1, 1, 1), + new Vector3i(-1, 1, 0), + new Vector3i(0, 1, 0), + new Vector3i(1, 1, 0), + new Vector3i(-1, 1, -1), + new Vector3i(0, 1, -1), + new Vector3i(1, 1, -1),}; private final World world; @@ -113,7 +114,7 @@ public Vector3i[] findWalkable(Vector3i from) throws ChunkNotLoadedException { * @param locB The destination location. * @return True if the player can traverse. * @throws ChunkNotLoadedException If there is not enough information in the - * system to determine traversal. + * system to determine traversal. */ @Override public boolean canWalk(Vector3i locA, Vector3i locB) throws ChunkNotLoadedException { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/World.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/World.java index cc5ab047..06cbca01 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/World.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/world/World.java @@ -18,14 +18,14 @@ package nl.tudelft.opencraft.yardstick.bot.world; -import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; -import science.atlarge.opencraft.mcprotocollib.data.game.world.WorldType; import java.util.Collection; import java.util.HashMap; import java.util.Map; import nl.tudelft.opencraft.yardstick.bot.entity.Entity; import nl.tudelft.opencraft.yardstick.util.Vector3i; import org.jetbrains.annotations.NotNull; +import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; +import science.atlarge.opencraft.mcprotocollib.data.game.world.WorldType; /** * Represents world-related data visible to the bot. diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java index 09922eed..c337fe11 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java @@ -19,7 +19,10 @@ package nl.tudelft.opencraft.yardstick.experiment; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; @@ -106,7 +109,7 @@ private Runnable newBotConnector(Bot bot) { if (number == 12 && bot.isConnected()) { long end = System.currentTimeMillis(); try { - Experiment12RandomE2E.fw.write(end + "\t" + "login\t" + (end-start) + "\n"); + Experiment12RandomE2E.fw.write(end + "\t" + "login\t" + (end - start) + "\n"); Experiment12RandomE2E.fw.flush(); } catch (IOException e) { e.printStackTrace(); diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment.java index 1f05b425..6da095cb 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment.java @@ -18,10 +18,6 @@ package nl.tudelft.opencraft.yardstick.experiment; -import science.atlarge.opencraft.mcprotocollib.MinecraftProtocol; -import science.atlarge.opencraft.packetlib.Client; -import science.atlarge.opencraft.packetlib.Session; -import science.atlarge.opencraft.packetlib.tcp.TcpSessionFactory; import java.util.UUID; import nl.tudelft.opencraft.yardstick.Options; import nl.tudelft.opencraft.yardstick.Yardstick; @@ -33,6 +29,10 @@ import nl.tudelft.opencraft.yardstick.util.Scheduler; import nl.tudelft.opencraft.yardstick.workload.WorkloadDumper; import nl.tudelft.opencraft.yardstick.workload.WorkloadSessionListener; +import science.atlarge.opencraft.mcprotocollib.MinecraftProtocol; +import science.atlarge.opencraft.packetlib.Client; +import science.atlarge.opencraft.packetlib.Session; +import science.atlarge.opencraft.packetlib.tcp.TcpSessionFactory; /** * A runnable Yardstick experiment. diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java index a12da3e6..c6ee195f 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment10WalkStraight.java @@ -18,9 +18,9 @@ package nl.tudelft.opencraft.yardstick.experiment; +import java.util.UUID; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.model.StraightMovementModel; -import java.util.UUID; public class Experiment10WalkStraight extends AbstractModelExperiment { @@ -40,8 +40,8 @@ public Experiment10WalkStraight() { } protected Bot createBot() { - Bot bot = newBot(UUID.randomUUID().toString().substring(0, 6)+"-"+(currBotId)); - currBotId+=clientCount; + Bot bot = newBot(UUID.randomUUID().toString().substring(0, 6) + "-" + (currBotId)); + currBotId += clientCount; return bot; } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java index 9eb20f81..bde8c54c 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment11Random.java @@ -20,8 +20,6 @@ import nl.tudelft.opencraft.yardstick.model.RandomModel; -import java.io.FileWriter; - public class Experiment11Random extends AbstractModelExperiment { public Experiment11Random() { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java index a2a7d15c..e1b79688 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java @@ -1,10 +1,9 @@ package nl.tudelft.opencraft.yardstick.experiment; -import nl.tudelft.opencraft.yardstick.bot.Bot; -import nl.tudelft.opencraft.yardstick.model.RandomModel; - import java.io.FileWriter; import java.util.UUID; +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.model.RandomModel; public class Experiment12RandomE2E extends AbstractModelExperiment { public static FileWriter fw; @@ -29,7 +28,7 @@ public Experiment12RandomE2E() { } protected Bot createBot() { - if (!GMjoined && GMuser!=null) { + if (!GMjoined && GMuser != null) { GMjoined = true; return newBot(GMuser); } else { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment1SimpleJoin.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment1SimpleJoin.java index 8c036030..b25e7191 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment1SimpleJoin.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment1SimpleJoin.java @@ -30,7 +30,7 @@ public class Experiment1SimpleJoin extends Experiment { public Experiment1SimpleJoin() { super(1, "A simple experiment. A bot joins the server and disconnects after 10 seconds. " - + "The amount of packets and bytes that are both sent and received are counted and reported."); + + "The amount of packets and bytes that are both sent and received are counted and reported."); } @Override diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment2ScheduledJoin.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment2ScheduledJoin.java index b65558b2..f272701b 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment2ScheduledJoin.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment2ScheduledJoin.java @@ -18,10 +18,10 @@ package nl.tudelft.opencraft.yardstick.experiment; -import science.atlarge.opencraft.packetlib.Client; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import science.atlarge.opencraft.packetlib.Client; public class Experiment2ScheduledJoin extends Experiment { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment3WalkAround.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment3WalkAround.java index ec294585..b447e123 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment3WalkAround.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment3WalkAround.java @@ -18,11 +18,11 @@ package nl.tudelft.opencraft.yardstick.experiment; -import nl.tudelft.opencraft.yardstick.model.SimpleMovementModel; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskStatus; import nl.tudelft.opencraft.yardstick.bot.ai.task.WalkTaskExecutor; +import nl.tudelft.opencraft.yardstick.model.SimpleMovementModel; import nl.tudelft.opencraft.yardstick.util.Vector3i; public class Experiment3WalkAround extends Experiment { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment8BoxWalkAround.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment8BoxWalkAround.java index 501ab033..1d5323ca 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment8BoxWalkAround.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment8BoxWalkAround.java @@ -58,8 +58,8 @@ protected void before() { this.secondsBetweenJoin = Integer.parseInt(options.experimentParams.getOrDefault("joininterval", "1")); this.numberOfBotsPerJoin = Integer.parseInt(options.experimentParams.getOrDefault("numbotsperjoin", "1")); this.movement = new BoundingBoxMovementModel( - Integer.parseInt(options.experimentParams.getOrDefault("boxDiameter", "32")), - Boolean.parseBoolean(options.experimentParams.getOrDefault("spawnAnchor", "false")) + Integer.parseInt(options.experimentParams.getOrDefault("boxDiameter", "32")), + Boolean.parseBoolean(options.experimentParams.getOrDefault("spawnAnchor", "false")) ); this.startMillis = System.currentTimeMillis(); } @@ -68,13 +68,13 @@ protected void before() { protected void tick() { synchronized (botList) { List disconnectedBots = botList.stream() - .filter(bot -> !bot.isJoined()) - .collect(Collectors.toList()); + .filter(bot -> !bot.isJoined()) + .collect(Collectors.toList()); disconnectedBots.forEach(bot -> bot.disconnect("Bot is not connected")); botList.removeAll(disconnectedBots); } if (System.currentTimeMillis() - this.lastJoin > secondsBetweenJoin * 1000 - && botList.size() <= this.botsTotal) { + && botList.size() <= this.botsTotal) { lastJoin = System.currentTimeMillis(); int botsToConnect = Math.min(this.numberOfBotsPerJoin, this.botsTotal - botList.size()); for (int i = 0; i < botsToConnect; i++) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java index 46d565df..08e0d291 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment9GenerationStressTest.java @@ -1,11 +1,5 @@ package nl.tudelft.opencraft.yardstick.experiment; -import nl.tudelft.opencraft.yardstick.bot.Bot; -import nl.tudelft.opencraft.yardstick.bot.ai.task.FlyTaskExecutor; -import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; -import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskStatus; -import nl.tudelft.opencraft.yardstick.util.Vector3i; - import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -13,6 +7,11 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; +import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.bot.ai.task.FlyTaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; +import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskStatus; +import nl.tudelft.opencraft.yardstick.util.Vector3i; public class Experiment9GenerationStressTest extends Experiment { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/RemoteControlledExperiment.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/RemoteControlledExperiment.java index 477fc8b6..8c0bf364 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/RemoteControlledExperiment.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/RemoteControlledExperiment.java @@ -18,21 +18,20 @@ package nl.tudelft.opencraft.yardstick.experiment; +import static io.javalin.apibuilder.ApiBuilder.get; +import static io.javalin.apibuilder.ApiBuilder.path; +import static io.javalin.apibuilder.ApiBuilder.post; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.javalin.Javalin; import io.javalin.core.validation.Validator; import io.javalin.http.Context; import io.javalin.plugin.json.JavalinJson; +import java.util.HashMap; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.Task; -import nl.tudelft.opencraft.yardstick.bot.ai.task.WalkXZTask; import nl.tudelft.opencraft.yardstick.bot.world.ConnectException; -import nl.tudelft.opencraft.yardstick.util.Vector3i; - -import java.util.HashMap; - -import static io.javalin.apibuilder.ApiBuilder.*; public class RemoteControlledExperiment extends Experiment { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleConsoleHandler.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleConsoleHandler.java index 5962119a..35beaeb6 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleConsoleHandler.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleConsoleHandler.java @@ -15,6 +15,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ + package nl.tudelft.opencraft.yardstick.logging; import java.util.logging.Formatter; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleFileHandler.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleFileHandler.java index 61270793..40a22d3d 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleFileHandler.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/logging/SimpleFileHandler.java @@ -15,6 +15,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ + package nl.tudelft.opencraft.yardstick.logging; import java.io.File; @@ -36,7 +37,7 @@ public class SimpleFileHandler extends Handler { * file exists, it will be permanently deleted. * * @param formatter the formatter to use. - * @param file the file to write to. + * @param file the file to write to. */ public SimpleFileHandler(Formatter formatter, File file) { this(formatter, file.getPath()); @@ -51,7 +52,7 @@ public SimpleFileHandler(Formatter formatter, File file) { * the file exists, it will be permanently deleted. * * @param formatter the formatter to use. - * @param name the file to write to. + * @param name the file to write to. */ public SimpleFileHandler(Formatter formatter, String name) { Handler fileHandler = null; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java index 8b3a64e4..3a539269 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/RandomModel.java @@ -1,6 +1,8 @@ package nl.tudelft.opencraft.yardstick.model; -import nl.tudelft.opencraft.yardstick.Options; +import java.util.ArrayList; +import java.util.Random; +import java.util.UUID; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.StandExecutor; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; @@ -8,10 +10,6 @@ import nl.tudelft.opencraft.yardstick.bot.world.Material; import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; -import java.util.ArrayList; -import java.util.Random; -import java.util.UUID; - public class RandomModel implements BotModel { private BotModel interact = new SimpleInteractionModel(); @@ -21,12 +19,12 @@ public class RandomModel implements BotModel { private long GMInterval; private ArrayList bannedUser = new ArrayList<>(); - public RandomModel(){ + public RandomModel() { } @Override - public TaskExecutor newTask(Bot bot) { + public TaskExecutor newTask(Bot bot) { TaskExecutor taskExecutor = null; Random RANDOM = new Random(System.nanoTime()); double random = RANDOM.nextDouble(); @@ -38,12 +36,15 @@ public TaskExecutor newTask(Bot bot) { switch (Experiment12RandomE2E.GMCommand) { case "weather": - if (random < 1/2.0) + if (random < 1 / 2.0) { command = "/weather clear"; - else command = "/weather thunder"; + } else { + command = "/weather thunder"; + } break; - case "random": default: + case "random": + default: if (random < 1 / 2.0) { if (RANDOM.nextDouble() < 1 / 2.0) { String target = UUID.randomUUID().toString().substring(0, 6); @@ -71,27 +72,27 @@ public TaskExecutor newTask(Bot bot) { if (random <= 0.3) { // Interact taskExecutor = interact.newTask(bot); - } - else if (random > 0.3 && random <= 0.7) { + } else if (random > 0.3 && random <= 0.7) { // Movement taskExecutor = movement.newTask(bot); // random walk speed between [0.1, 0.4] double walkSpeed = RANDOM.nextDouble() * 0.4; - if (walkSpeed < 0.1) + if (walkSpeed < 0.1) { walkSpeed = 0.15; + } ((WalkTaskExecutor) taskExecutor).setSpeed(walkSpeed); - } - - else if (random > 0.7 && random <= 0.8) { + } else if (random > 0.7 && random <= 0.8) { // send msg - if (RANDOM.nextDouble() < 0.5) + if (RANDOM.nextDouble() < 0.5) { bot.getController().sendChatMsg("hey"); + } // get item else { Material mt = Material.getById(RANDOM.nextInt(187)); - if (mt != Material.UNKNOWN) + if (mt != Material.UNKNOWN) { bot.getController().creativeInventoryAction(mt, RANDOM.nextInt(9) + 1); + } } StandExecutor stand = new StandExecutor(bot); stand.setTimeout(500); diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleInteractionModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleInteractionModel.java index 8b2f5652..e0179c7c 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleInteractionModel.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleInteractionModel.java @@ -18,11 +18,11 @@ package nl.tudelft.opencraft.yardstick.model; +import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.ThreadLocalRandom; -import com.google.common.collect.Lists; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.BreakBlocksTaskExecutor; import nl.tudelft.opencraft.yardstick.bot.ai.task.PlaceBlocksTaskExecutor; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java index 1188e0da..aa15c7e0 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/SimpleMovementModel.java @@ -18,7 +18,6 @@ package nl.tudelft.opencraft.yardstick.model; -import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; import java.util.Random; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; @@ -29,6 +28,7 @@ import nl.tudelft.opencraft.yardstick.util.Vector3d; import nl.tudelft.opencraft.yardstick.util.Vector3i; import nl.tudelft.opencraft.yardstick.util.ZigZagRange; +import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; /** * Represents a model which moves the bot randomly to short and long distance diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java index d7bf11b0..c3505766 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/model/StraightMovementModel.java @@ -18,6 +18,8 @@ package nl.tudelft.opencraft.yardstick.model; +import java.util.HashMap; +import java.util.Random; import nl.tudelft.opencraft.yardstick.bot.Bot; import nl.tudelft.opencraft.yardstick.bot.ai.task.TaskExecutor; import nl.tudelft.opencraft.yardstick.bot.ai.task.WalkTaskExecutor; @@ -28,9 +30,6 @@ import nl.tudelft.opencraft.yardstick.util.Vector3i; import nl.tudelft.opencraft.yardstick.util.ZigZagRange; -import java.util.HashMap; -import java.util.Random; - /** * Represents a model which moves the bot randomly to short and long distance * locations. @@ -47,8 +46,9 @@ public StraightMovementModel() { @Override public TaskExecutor newTask(Bot bot) { WalkTaskExecutor exe = new WalkTaskExecutor(bot, newTargetLocation(bot)); - if (walkSpeed != 0.15) + if (walkSpeed != 0.15) { exe.setSpeed(walkSpeed); + } return exe; } @@ -62,46 +62,47 @@ public Vector3i newTargetLocation(Bot bot) { int botId = Integer.parseInt(bot.getName().split("-")[1]); double factor = 0; - if (botId > 7) + if (botId > 7) { factor = botId / 8.0; + } switch (botId % 8) { case 0: - newX+=dis; - newZ+=(int)factor*dis; + newX += dis; + newZ += (int) factor * dis; break; case 1: - newZ+=dis; - newX+=(int)factor*dis; + newZ += dis; + newX += (int) factor * dis; break; case 2: - newX-=dis; - newZ-=(int)factor*dis; + newX -= dis; + newZ -= (int) factor * dis; break; case 3: - newZ-=dis; - newX-=(int)factor*dis; + newZ -= dis; + newX -= (int) factor * dis; break; case 4: - newX+=dis+(int)factor*dis; - newZ+=dis+(int)factor*dis; + newX += dis + (int) factor * dis; + newZ += dis + (int) factor * dis; break; case 5: - newX-=dis-(int)factor*dis; - newZ-=dis-(int)factor*dis; + newX -= dis - (int) factor * dis; + newZ -= dis - (int) factor * dis; break; case 6: - newX+=dis+(int)factor*dis; - newZ-=dis-(int)factor*dis; + newX += dis + (int) factor * dis; + newZ -= dis - (int) factor * dis; break; case 7: - newX-=dis-(int)factor*dis; - newZ+=dis+(int)factor*dis; + newX -= dis - (int) factor * dis; + newZ += dis + (int) factor * dis; break; } Vector3i prevTarget = botsTarget.get(bot); - if (prevTarget!=null && (int)prevTarget.getX() == newX && (int)prevTarget.getZ() == newZ) { + if (prevTarget != null && (int) prevTarget.getX() == newX && (int) prevTarget.getZ() == newZ) { newX = (int) (originalLocation.getX() + random.nextInt(8) * (random.nextBoolean() ? -1 : 1) * random.nextDouble()); newZ = (int) (originalLocation.getZ() + random.nextInt(8) * (random.nextBoolean() ? -1 : 1) * random.nextDouble()); } @@ -124,7 +125,7 @@ private Vector3i getTargetAt(Bot bot, int x, int z) { y = it.next(); Block test = bot.getWorld().getBlockAt(x, y, z); if (test.getMaterial().isTraversable() - && !test.getRelative(BlockFace.BOTTOM).getMaterial().isTraversable()) { + && !test.getRelative(BlockFace.BOTTOM).getMaterial().isTraversable()) { break; } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/Statistics.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/Statistics.java index fd8ece00..e72282a7 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/Statistics.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/Statistics.java @@ -18,26 +18,32 @@ package nl.tudelft.opencraft.yardstick.statistic; +import io.prometheus.client.CollectorRegistry; +import io.prometheus.client.Counter; +import io.prometheus.client.Gauge; +import io.prometheus.client.Summary; import java.io.IOException; import java.util.HashSet; import java.util.logging.Level; +import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; +import nl.tudelft.opencraft.yardstick.logging.SubLogger; +import nl.tudelft.opencraft.yardstick.util.CountingOutputStream; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerJoinGamePacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerKeepAlivePacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.entity.ServerEntityHeadLookPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.entity.ServerEntityMovementPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.entity.ServerEntityTeleportPacket; import science.atlarge.opencraft.packetlib.Session; -import science.atlarge.opencraft.packetlib.event.session.*; +import science.atlarge.opencraft.packetlib.event.session.ConnectedEvent; +import science.atlarge.opencraft.packetlib.event.session.DisconnectedEvent; +import science.atlarge.opencraft.packetlib.event.session.DisconnectingEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketReceivedEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketSendingEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketSentEvent; +import science.atlarge.opencraft.packetlib.event.session.SessionListener; import science.atlarge.opencraft.packetlib.io.NetOutput; import science.atlarge.opencraft.packetlib.io.stream.StreamNetOutput; import science.atlarge.opencraft.packetlib.packet.Packet; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.Counter; -import io.prometheus.client.Gauge; -import io.prometheus.client.Summary; -import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; -import nl.tudelft.opencraft.yardstick.logging.SubLogger; -import nl.tudelft.opencraft.yardstick.util.CountingOutputStream; /** * Represents a {@link SessionListener} for collecting Yardstick statistics and @@ -75,52 +81,52 @@ public Statistics(String host, int port) { CollectorRegistry registry = pusher.getRegistry(); connected = Gauge.build() - .namespace("yardstick") - .name("bots_connected") - .help("Amount of isConnected bots") - .register(registry); + .namespace("yardstick") + .name("bots_connected") + .help("Amount of isConnected bots") + .register(registry); packIn = Counter.build() - .namespace("yardstick") - .name("packets_in") - .help("Packets received") - .register(registry); + .namespace("yardstick") + .name("packets_in") + .help("Packets received") + .register(registry); packOut = Counter.build() - .namespace("yardstick") - .name("packets_out") - .help("Packets sent") - .register(registry); + .namespace("yardstick") + .name("packets_out") + .help("Packets sent") + .register(registry); bytesIn = Summary.build() - .namespace("yardstick") - .name("bytes_in") - .help("Bytes received") - .register(registry); + .namespace("yardstick") + .name("bytes_in") + .help("Bytes received") + .register(registry); bytesOut = Summary.build() - .namespace("yardstick") - .name("bytes_out") - .help("Bytes sent") - .register(registry); + .namespace("yardstick") + .name("bytes_out") + .help("Bytes sent") + .register(registry); errors = Counter.build() - .namespace("yardstick") - .name("disconnect_errors") - .help("Amount of disconnects due to errors") - .register(registry); + .namespace("yardstick") + .name("disconnect_errors") + .help("Amount of disconnects due to errors") + .register(registry); keepAliveIn = Counter.build() - .namespace("yardstick") - .name("keep_alive_packets_in") - .help("The amount of Keep Alive packets received from the server.") - .register(registry); + .namespace("yardstick") + .name("keep_alive_packets_in") + .help("The amount of Keep Alive packets received from the server.") + .register(registry); entityPositionUpdate = Counter.build() - .namespace("yardstick") - .name("entity_position_updates") - .help("Number of packets received that update the location or rotation of an entity.") - .register(registry); + .namespace("yardstick") + .name("entity_position_updates") + .help("Number of packets received that update the location or rotation of an entity.") + .register(registry); } /** diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/StatisticsPusher.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/StatisticsPusher.java index 5a97edee..3b57f953 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/StatisticsPusher.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/StatisticsPusher.java @@ -18,11 +18,11 @@ package nl.tudelft.opencraft.yardstick.statistic; +import io.prometheus.client.CollectorRegistry; +import io.prometheus.client.exporter.PushGateway; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.PushGateway; import nl.tudelft.opencraft.yardstick.Yardstick; /** diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/PacketUtil.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/PacketUtil.java index 50279a0e..cb8620e3 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/PacketUtil.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/PacketUtil.java @@ -58,8 +58,8 @@ public static int packetLength(Packet packet) { * Returns the packet class corresponding to a packet integer identifier in * a {@link PacketProtocol}. * - * @param prot the packet protocol. - * @param id the ID of the packet. + * @param prot the packet protocol. + * @param id the ID of the packet. * @param outgoing whether the packet is client->server. * @return The packet class. * @throws Exception upon failure of any sort. diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Report.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Report.java index ab3646c4..8cc66a29 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Report.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Report.java @@ -43,8 +43,8 @@ public Report(String title) { /** * Puts a new key-value pair in the report. * - * @param id The key of the key-value pair. - * @param name The meaning of the key-value pair, in human readable form. + * @param id The key of the key-value pair. + * @param name The meaning of the key-value pair, in human readable form. * @param value The value of the key-value pair. */ public void put(String id, String name, Object value) { @@ -90,7 +90,7 @@ public static final class Entry { /** * Creates a new report entry. * - * @param name the name of the entry. + * @param name the name of the entry. * @param value the value of the entry. */ public Entry(String name, String value) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Scheduler.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Scheduler.java index 5e09b076..95d80aa0 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Scheduler.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/Scheduler.java @@ -36,7 +36,7 @@ public class Scheduler { * Creates a new Scheduler for executing tasks. * * @param tickMs the desired fixed delay between task executions, in - * milliseconds. + * milliseconds. */ public Scheduler(long tickMs) { this.tickNanos = TimeUnit.MILLISECONDS.toNanos(tickMs); diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/WorldUtil.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/WorldUtil.java index bcd8cf44..3ba76ddc 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/WorldUtil.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/util/WorldUtil.java @@ -38,7 +38,7 @@ private WorldUtil() { * environment (block occlusion). * * @param player the player. - * @param block the block the player is observing. + * @param block the block the player is observing. * @return an arbitrary block face that is visible, or null, if none exists. */ public static BlockFace getVisibleBlockFace(Player player, Block block) { @@ -70,7 +70,7 @@ public static BlockFace getVisibleBlockFace(Player player, Block block) { * surroundings (is there a block or entity occluding the face?). * * @param player the player. - * @param block the block the player is observing. + * @param block the block the player is observing. * @return an array of three block faces. */ public static BlockFace[] getDirectedBlockFaces(Player player, Block block) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/CsvConverter.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/CsvConverter.java index c2f1eb0b..3277a53c 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/CsvConverter.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/CsvConverter.java @@ -18,6 +18,8 @@ package nl.tudelft.opencraft.yardstick.workload; +import com.google.common.io.CountingInputStream; +import com.google.common.io.CountingOutputStream; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.DataInputStream; @@ -31,8 +33,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; -import com.google.common.io.CountingInputStream; -import com.google.common.io.CountingOutputStream; import nl.tudelft.opencraft.yardstick.Yardstick; /** @@ -49,7 +49,7 @@ private CsvConverter() { * Convert a binary message capture file to a CSV-formatted file. The input * file must exist, the output file may. * - * @param inFileName the input filename. + * @param inFileName the input filename. * @param outFileName the output filename. */ public static void convertCsv(String inFileName, String outFileName) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/PacketEntry.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/PacketEntry.java index 7ba553fe..69cc1c50 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/PacketEntry.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/PacketEntry.java @@ -21,8 +21,8 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import science.atlarge.opencraft.packetlib.packet.Packet; import nl.tudelft.opencraft.yardstick.util.PacketUtil; +import science.atlarge.opencraft.packetlib.packet.Packet; /** * Represents a snapshot of information of a specific message between the @@ -39,10 +39,10 @@ public class PacketEntry { * Creates a new PacketEntry. * * @param timestamp the unix nanotime that the message was sent or did - * arrive. - * @param packet a shorthand name for the message type. - * @param outgoing true if the message was client->server, false otherwise. - * @param length the length of the message in bytes. + * arrive. + * @param packet a shorthand name for the message type. + * @param outgoing true if the message was client->server, false otherwise. + * @param length the length of the message in bytes. */ public PacketEntry(long timestamp, String packet, boolean outgoing, int length) { this.timestamp = timestamp; @@ -82,7 +82,7 @@ public static PacketEntry readFrom(DataInputStream dis) throws IOException { /** * Converts a {@link Packet} to a PacketEntry. * - * @param packet the packet. + * @param packet the packet. * @param outgoing whether the packet was client->server. * @return the PacketEntry. */ diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadDumper.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadDumper.java index fb45646b..fec0cd87 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadDumper.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadDumper.java @@ -24,11 +24,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; +import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; +import nl.tudelft.opencraft.yardstick.logging.SubLogger; import science.atlarge.opencraft.packetlib.event.session.PacketReceivedEvent; import science.atlarge.opencraft.packetlib.event.session.PacketSentEvent; import science.atlarge.opencraft.packetlib.packet.Packet; -import nl.tudelft.opencraft.yardstick.logging.GlobalLogger; -import nl.tudelft.opencraft.yardstick.logging.SubLogger; /** * Handles {@link PacketSentEvent}s and {@link PacketReceivedEvent}s for @@ -86,7 +86,7 @@ private PacketEntryWriter getQueue(String botName) { * Handles a PacketSentEvent for a given bot. * * @param botName the name of the bot. - * @param pse the event. + * @param pse the event. */ public void packetSent(String botName, PacketSentEvent pse) { handlePacket(botName, pse.getPacket(), true); @@ -96,7 +96,7 @@ public void packetSent(String botName, PacketSentEvent pse) { * Handles a PacketReceivedEvent for a given bot. * * @param botName the name of the bot. - * @param pre the event. + * @param pre the event. */ public void packetReceived(String botName, PacketReceivedEvent pre) { handlePacket(botName, pre.getPacket(), false); @@ -122,8 +122,8 @@ public void start() { /** * Stops the dumper thread. * - * @see #start() * @throws IllegalStateException if the thread has not been started. + * @see #start() */ public void stop() { if (!running.getAndSet(false)) { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadSessionListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadSessionListener.java index a126008b..a1699bd3 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadSessionListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/workload/WorkloadSessionListener.java @@ -33,7 +33,7 @@ public class WorkloadSessionListener extends SessionAdapter { /** * Creates a new WorkloadSessionListener. * - * @param dumper the dumper to use. + * @param dumper the dumper to use. * @param botName The name of the bot this listener is attached to. */ public WorkloadSessionListener(WorkloadDumper dumper, String botName) { From 4cee6504338666a56cf9ed30e4adb07bad2eacc1 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 16:54:20 +0100 Subject: [PATCH 06/11] chore: remove commented code --- .../nl/tudelft/opencraft/yardstick/bot/BotListener.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index 43462724..52a01edb 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -170,7 +170,6 @@ public void packetReceived(PacketReceivedEvent pre) { } Packet packet = pre.getPacket(); -// System.out.println(packet.getClass().getName()); if (packet instanceof ServerSpawnObjectPacket) { // 0x00 Spawn Object ServerSpawnObjectPacket p = (ServerSpawnObjectPacket) packet; @@ -489,7 +488,6 @@ public void packetReceived(PacketReceivedEvent pre) { ServerJoinGamePacket p = (ServerJoinGamePacket) packet; // TODO: Reduced debug info field? -// System.out.println(p); // Init the game this.world = new World(Dimension.forId(p.getDimension()), p.getWorldType()); bot.setWorld(world); @@ -776,10 +774,9 @@ else if (!serverJoinGame) { ServerEntityEffectPacket p = (ServerEntityEffectPacket) packet; // TODO + } else { + logger.fine("Received unhandled packet: " + packet.getClass().getName()); } -// else { -// logger.warning("Received unhandled packet: " + packet.getClass().getName()); -// } } @Override From bc12406bd7e2ed2d31153cb3432505f4e16c9e10 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 16:58:10 +0100 Subject: [PATCH 07/11] fix: send correct packet type --- .../java/nl/tudelft/opencraft/yardstick/bot/BotListener.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index 52a01edb..bd925924 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -40,7 +40,7 @@ import science.atlarge.opencraft.mcprotocollib.data.game.entity.metadata.Position; import science.atlarge.opencraft.mcprotocollib.data.game.entity.type.GlobalEntityType; import science.atlarge.opencraft.mcprotocollib.data.game.world.block.BlockChangeRecord; -import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.player.ClientPlayerPositionRotationPacket; +import science.atlarge.opencraft.mcprotocollib.packet.ingame.client.world.ClientTeleportConfirmPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerBossBarPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerChatPacket; import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerCombatPacket; @@ -600,8 +600,7 @@ else if (!serverJoinGame) { player.setOnGround(true); Session session = bot.getClient().getSession(); -// session.send(new ClientTeleportConfirmPacket(p.getTeleportId())); - session.send(new ClientPlayerPositionRotationPacket(true, p.getX(), p.getY(), p.getZ(), p.getYaw(), p.getPitch())); + session.send(new ClientTeleportConfirmPacket(p.getTeleportId())); logger.info("Received new Player position: " + player.getLocation()); } else if (packet instanceof ServerPlayerUseBedPacket) { From c110636cc206d2a15fed88c0d5ed574a9a6e1bf4 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 17:10:27 +0100 Subject: [PATCH 08/11] chore: class for chat latency --- .../opencraft/yardstick/bot/BotListener.java | 30 -------- .../experiment/Experiment12RandomE2E.java | 21 +++-- .../statistic/ChatLatencyListener.java | 76 +++++++++++++++++++ 3 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/ChatLatencyListener.java diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index bd925924..61fa8ffa 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -32,7 +32,6 @@ import nl.tudelft.opencraft.yardstick.bot.world.ChunkNotLoadedException; import nl.tudelft.opencraft.yardstick.bot.world.Dimension; import nl.tudelft.opencraft.yardstick.bot.world.World; -import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; import nl.tudelft.opencraft.yardstick.util.Vector3d; import science.atlarge.opencraft.mcprotocollib.MinecraftProtocol; import science.atlarge.opencraft.mcprotocollib.data.SubProtocol; @@ -127,7 +126,6 @@ import science.atlarge.opencraft.packetlib.event.session.SessionListener; import science.atlarge.opencraft.packetlib.packet.Packet; -import java.io.IOException; import java.util.Iterator; import java.util.Map; import java.util.UUID; @@ -318,34 +316,6 @@ public void packetReceived(PacketReceivedEvent pre) { ServerChatPacket p = (ServerChatPacket) packet; // TODO - // log time - long end = System.currentTimeMillis(); - - String key = null; - if (p.getMessage().getText().startsWith("There are")) { - key = "banlist"; - } - if (p.getMessage().getText().startsWith("Banned player")) { - key = "ban"; - } - if (p.getMessage().getText().startsWith("Unbanned")) { - key = "unban"; - } - if (p.getMessage().getText().startsWith("Changing to clear")) { - key = "clear"; - } - if (p.getMessage().getText().startsWith("Changing to rain and thunder")) { - key = "thunder"; - } - try { - if (key != null) { - Experiment12RandomE2E.fw.write(end + "\t" + key + "\t" + (end - Experiment12RandomE2E.GMStartTime) + "\n"); - Experiment12RandomE2E.fw.flush(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } else if (packet instanceof ServerMultiBlockChangePacket) { // 0x10 Multi Block Change ServerMultiBlockChangePacket p = (ServerMultiBlockChangePacket) packet; diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java index e1b79688..5fc3aac7 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/Experiment12RandomE2E.java @@ -1,9 +1,13 @@ package nl.tudelft.opencraft.yardstick.experiment; -import java.io.FileWriter; -import java.util.UUID; import nl.tudelft.opencraft.yardstick.bot.Bot; +import nl.tudelft.opencraft.yardstick.game.GameArchitecture; import nl.tudelft.opencraft.yardstick.model.RandomModel; +import nl.tudelft.opencraft.yardstick.statistic.ChatLatencyListener; + +import java.io.FileWriter; +import java.time.Duration; +import java.util.UUID; public class Experiment12RandomE2E extends AbstractModelExperiment { public static FileWriter fw; @@ -12,8 +16,8 @@ public class Experiment12RandomE2E extends AbstractModelExperiment { public static long GMStartTime; public static String GMCommand; - public Experiment12RandomE2E() { - super(12, "Bots move around randomly with one GM; log E2E latency", new RandomModel()); + public Experiment12RandomE2E(int nodeID, GameArchitecture game, Duration duration) { + super(12, nodeID, game, duration, "Bots move around randomly with one GM; log E2E latency", new RandomModel()); try { fw = new FileWriter("event.log"); } catch (Exception e) { @@ -27,12 +31,17 @@ public Experiment12RandomE2E() { randomModel.setGMInterval(Long.parseLong(options.experimentParams.getOrDefault("gminterval", "10"))); } + @Override protected Bot createBot() { if (!GMjoined && GMuser != null) { GMjoined = true; - return newBot(GMuser); + Bot bot = newBot(GMuser); + bot.addListener(new ChatLatencyListener()); + return bot; } else { - return newBot(UUID.randomUUID().toString().substring(0, 6)); + Bot bot = newBot(UUID.randomUUID().toString().substring(0, 6)); + bot.addListener(new ChatLatencyListener()); + return bot; } } } diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/ChatLatencyListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/ChatLatencyListener.java new file mode 100644 index 00000000..00342e0e --- /dev/null +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/statistic/ChatLatencyListener.java @@ -0,0 +1,76 @@ +package nl.tudelft.opencraft.yardstick.statistic; + +import nl.tudelft.opencraft.yardstick.experiment.Experiment12RandomE2E; +import science.atlarge.opencraft.mcprotocollib.packet.ingame.server.ServerChatPacket; +import science.atlarge.opencraft.packetlib.event.session.ConnectedEvent; +import science.atlarge.opencraft.packetlib.event.session.DisconnectedEvent; +import science.atlarge.opencraft.packetlib.event.session.DisconnectingEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketReceivedEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketSendingEvent; +import science.atlarge.opencraft.packetlib.event.session.PacketSentEvent; +import science.atlarge.opencraft.packetlib.event.session.SessionListener; +import science.atlarge.opencraft.packetlib.packet.Packet; + +import java.io.IOException; + +public class ChatLatencyListener implements SessionListener { + @Override + public void packetReceived(PacketReceivedEvent event) { + Packet packet = event.getPacket(); + if (packet instanceof ServerChatPacket) { + ServerChatPacket p = (ServerChatPacket) packet; + // log time + long end = System.currentTimeMillis(); + + String key = null; + if (p.getMessage().getText().startsWith("There are")) { + key = "banlist"; + } + if (p.getMessage().getText().startsWith("Banned player")) { + key = "ban"; + } + if (p.getMessage().getText().startsWith("Unbanned")) { + key = "unban"; + } + if (p.getMessage().getText().startsWith("Changing to clear")) { + key = "clear"; + } + if (p.getMessage().getText().startsWith("Changing to rain and thunder")) { + key = "thunder"; + } + try { + if (key != null) { + Experiment12RandomE2E.fw.write(end + "\t" + key + "\t" + (end - Experiment12RandomE2E.GMStartTime) + "\n"); + Experiment12RandomE2E.fw.flush(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + @Override + public void packetSending(PacketSendingEvent event) { + + } + + @Override + public void packetSent(PacketSentEvent event) { + + } + + @Override + public void connected(ConnectedEvent event) { + + } + + @Override + public void disconnecting(DisconnectingEvent event) { + + } + + @Override + public void disconnected(DisconnectedEvent event) { + + } +} From 6feca67f6bf868f278a4eb2960cd22f8579c7160 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 17:14:32 +0100 Subject: [PATCH 09/11] chore: remove unnecessary variable --- .../opencraft/yardstick/bot/BotListener.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java index 61fa8ffa..79671e6f 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/BotListener.java @@ -126,10 +126,9 @@ import science.atlarge.opencraft.packetlib.event.session.SessionListener; import science.atlarge.opencraft.packetlib.packet.Packet; -import java.util.Iterator; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; /** @@ -144,8 +143,7 @@ public class BotListener implements SessionListener { private Server server; private World world; - private ConcurrentHashMap unhandledRecvPkt = new ConcurrentHashMap<>(); - private int pktCounter = 0; + private final List unhandledRecvPkt = new ArrayList<>(); private boolean serverJoinGame; /** @@ -473,13 +471,10 @@ public void packetReceived(PacketReceivedEvent pre) { // Replay the unhandled packet events before receiving server join game serverJoinGame = true; - Iterator> iter = unhandledRecvPkt.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = iter.next(); - packetReceived(entry.getValue()); - iter.remove(); + for (PacketReceivedEvent packetReceivedEvent : unhandledRecvPkt) { + packetReceived(packetReceivedEvent); } - + unhandledRecvPkt.clear(); } else if (packet instanceof ServerMapDataPacket) { // 0x24 Map ServerMapDataPacket p = (ServerMapDataPacket) packet; @@ -532,8 +527,7 @@ public void packetReceived(PacketReceivedEvent pre) { // ServerJoinGame packet is received after a few Player packets. // Save them to handle later else if (!serverJoinGame) { - unhandledRecvPkt.put(++pktCounter, pre); - return; + unhandledRecvPkt.add(pre); } else if (packet instanceof ServerPlayerAbilitiesPacket) { // 0x2B Player Abilities From 5eb8b06d872acf899e14218fc441420157ad7eb9 Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Mon, 7 Mar 2022 17:15:32 +0100 Subject: [PATCH 10/11] chore: remove commented code --- .../tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java | 1 - 1 file changed, 1 deletion(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java index 71758549..301edf7a 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/ai/task/StandExecutor.java @@ -19,7 +19,6 @@ public void setTimeout(int timeout) { @Override protected TaskStatus onTick() { long nowTime = System.currentTimeMillis(); -// logger.info("standing, remaing time=" + (timeout+startTime - nowTime)); if (nowTime - startTime >= timeout) { return TaskStatus.forSuccess(); } else { From 3c3f3d6437c6d744bf7566b1e75459e35c14351f Mon Sep 17 00:00:00 2001 From: Jesse Donkervliet Date: Wed, 9 Mar 2022 19:26:47 +0100 Subject: [PATCH 11/11] refactor: use timer to measure connect latency --- .../tudelft/opencraft/yardstick/bot/Bot.java | 21 ++++++++++++------- .../experiment/AbstractModelExperiment.java | 12 ----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/Bot.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/Bot.java index c13b73dc..84be34c9 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/Bot.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/bot/Bot.java @@ -28,6 +28,7 @@ import nl.tudelft.opencraft.yardstick.bot.world.SimpleWorldPhysics; import nl.tudelft.opencraft.yardstick.bot.world.World; import nl.tudelft.opencraft.yardstick.experiment.LoggerSessionListener; +import nl.tudelft.opencraft.yardstick.telemetry.Timer; import nl.tudelft.opencraft.yardstick.workload.WorkloadDumper; import nl.tudelft.opencraft.yardstick.workload.WorkloadSessionListener; import org.slf4j.Logger; @@ -121,14 +122,20 @@ public void addSessionListener(SessionListener... listeners) { * @throws IllegalStateException if the bot is already connected. */ public void connect() { - Session session = client.getSession(); - if (session.isConnected()) { - throw new IllegalStateException("Can not start connection. Bot already isConnected!"); - } - session.addListener(new LoggerSessionListener(logger)); - session.connect(); + Timer timer = new Timer("connect_latency"); + timer.start(); + try { + Session session = client.getSession(); + if (session.isConnected()) { + throw new IllegalStateException("Can not start connection. Bot already isConnected!"); + } + session.addListener(new LoggerSessionListener(logger)); + session.connect(); - initializeTaskTicker(); + initializeTaskTicker(); + } finally { + timer.stop(); + } } private void initializeTaskTicker() { diff --git a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java index 64e9b33e..722da257 100644 --- a/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java +++ b/yardstick/src/main/java/nl/tudelft/opencraft/yardstick/experiment/AbstractModelExperiment.java @@ -25,7 +25,6 @@ import nl.tudelft.opencraft.yardstick.game.GameArchitecture; import nl.tudelft.opencraft.yardstick.model.BotModel; -import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; @@ -94,17 +93,6 @@ private Runnable newBotConnector(Bot bot) { long start = System.currentTimeMillis(); bot.connect(); - // log login time if the bot is connected (exp12) - if (number == 12 && bot.isConnected()) { - long end = System.currentTimeMillis(); - try { - Experiment12RandomE2E.fw.write(end + "\t" + "login\t" + (end - start) + "\n"); - Experiment12RandomE2E.fw.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - } - int sleep = 2000; int tries = 3; while (tries-- > 0 && (bot.getPlayer() == null || !bot.isJoined())) {