diff --git a/src/main/java/com/minecrafttas/common/server/interfaces/PacketID.java b/src/main/java/com/minecrafttas/common/server/interfaces/PacketID.java index acd7eea2..522cd42b 100644 --- a/src/main/java/com/minecrafttas/common/server/interfaces/PacketID.java +++ b/src/main/java/com/minecrafttas/common/server/interfaces/PacketID.java @@ -4,13 +4,27 @@ import com.minecrafttas.common.server.Client.Side; public interface PacketID { + /** + * @return The numerical ID of the packet + */ public int getID(); - - public CompactPacketHandler getLambda(); - + /** + * Only used in combination with {@link #getLambda()} + * @return The side of the packet this is registered to + */ public Side getSide(); - + /** + * Used for compact small lambda packet handlers + * @return The lamda to run when receiving a packet + */ + public CompactPacketHandler getLambda(); + /** + * @return The name of the packet + */ public String getName(); + /** + * @return Whether the packet should be used in trace messages + */ public boolean shouldTrace(); } diff --git a/src/main/java/com/minecrafttas/tasmod/commands/CommandClearInputs.java b/src/main/java/com/minecrafttas/tasmod/commands/CommandClearInputs.java index ab6fcc5b..b93ac489 100644 --- a/src/main/java/com/minecrafttas/tasmod/commands/CommandClearInputs.java +++ b/src/main/java/com/minecrafttas/tasmod/commands/CommandClearInputs.java @@ -26,7 +26,7 @@ public String getUsage(ICommandSender sender) { public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if(sender instanceof EntityPlayer) { try { - TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.CLEAR_INNPUTS)); + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.PLAYBACK_CLEAR_INPUTS)); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/minecrafttas/tasmod/networking/TASmodPackets.java b/src/main/java/com/minecrafttas/tasmod/networking/TASmodPackets.java index ae960af2..d62135e0 100644 --- a/src/main/java/com/minecrafttas/tasmod/networking/TASmodPackets.java +++ b/src/main/java/com/minecrafttas/tasmod/networking/TASmodPackets.java @@ -4,6 +4,10 @@ import com.minecrafttas.common.server.Client.Side; import com.minecrafttas.common.server.interfaces.PacketID; import com.minecrafttas.tasmod.commands.CommandFolder; +import com.minecrafttas.tasmod.playback.PlaybackControllerClient; +import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; +import com.minecrafttas.tasmod.playback.PlaybackSerialiser; +import com.minecrafttas.tasmod.savestates.SavestateHandlerServer.PlayerHandler.MotionData; import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer.TickratePauseState; import net.minecraft.nbt.NBTTagCompound; @@ -17,37 +21,31 @@ public enum TASmodPackets implements PacketID { /** *
Ticksync is a system to sync the tick execution between client and server. * Both can tick independent from each other causing issues with playback. - * *
This is used to notify the other to start ticking and shouldn't be used otherwise. - * *
SIDE: Both
* ARGS: None
*/
TICKSYNC(false),
/**
*
Sets the tickrate/gamespeed - * *
SIDE: Both
* ARGS: int tickrate
*/
TICKRATE_CHANGE,
/**
*
Sets the tickrate to 0, pausing the game. Also unpauses the game - * *
SIDE: Both
* ARGS: {@link TickratePauseState} state The paused state
*/
TICKRATE_ZERO,
/**
*
While in tickrate 0, advances the game by one tick - * *
SIDE: Both
* ARGS: None
*/
TICKRATE_ADVANCE,
/**
*
Creates a savestate - * *
SIDE: Both
* ARGS:
* Client->Server: int The index of the savestate that should be created. -1 to create the latest savestate, might overwrite existing savestates.
@@ -56,7 +54,6 @@ public enum TASmodPackets implements PacketID {
SAVESTATE_SAVE,
/**
*
Loads a savestate - * *
SIDE: Both
* ARGS:
* Client->Server int The index of the savestate that should be loaded
@@ -75,17 +72,91 @@ public enum TASmodPackets implements PacketID {
* ARGS: {@link NBTTagCompound} compound The playerdata
*/
SAVESTATE_PLAYER,
+ /**
+ *
Used for storing the client motion data on the server. + *
SIDE: BOTH
+ * ARGS:
+ * Server->ClientNone
+ * Client->Server {@link MotionData} motionData An Object containing all necessary motion data
+ */
SAVESTATE_REQUEST_MOTION,
+ /**
+ *
Unloads the chunks on the client side + *
SIDE: Client
+ * ARGS: none
+ */
SAVESTATE_UNLOAD_CHUNKS,
- CLEAR_INNPUTS,
+ /**
+ *
Notifies the client to clear all inputs from the input buffer in {@link PlaybackControllerClient} + *
SIDE: Both
+ * ARGS: none
+ */
+ PLAYBACK_CLEAR_INPUTS,
+ /**
+ *
Notifies the client to quit to the main menu and start recording inputs in {@link PlaybackControllerClient} + *
SIDE: Both
+ * ARGS: none
+ */
PLAYBACK_FULLRECORD,
+ /**
+ *
Notifies the client to quit to the main menu and start playing back inputs in {@link PlaybackControllerClient} + *
SIDE: Both
+ * ARGS: none
+ */
PLAYBACK_FULLPLAY,
+ /**
+ *
Notifies the client to quit the game. Upon restarting the game, the specified tasfile will be loaded and played back in {@link PlaybackControllerClient} + *
SIDE: Both
+ * ARGS:
+ * Client->Server None
+ * Server->Client String filename The TASfile name to load on restart
+ */
PLAYBACK_RESTARTANDPLAY,
+ /**
+ *
Notifies the client to store the current inputs to a file in {@link PlaybackControllerClient}. This is done using {@link PlaybackSerialiser} + *
SIDE: Both
+ * ARGS:
+ * Client->Server None
+ * Server->Client String filename The TASfile name to store
+ */
PLAYBACK_SAVE,
+ /**
+ *
Notifies the client to load the inputs from a file in {@link PlaybackControllerClient}. This is done using {@link PlaybackSerialiser} + *
SIDE: Both
+ * ARGS:
+ * Client->Server None
+ * Server->Client String filename The TASfile name to load
+ */
PLAYBACK_LOAD,
+ /**
+ *
Notifies the client activate "playuntil" in {@link PlaybackControllerClient}. The next playback will stop at the specified tick and the client will enter recording mode + *
SIDE: Both
+ * ARGS:
+ * Client->Server None
+ * Server->Client int tick The tick when to stop playing back and start recording
+ */
PLAYBACK_PLAYUNTIL,
+ /**
+ *
A permissionless teleport packet, used for setting the playerdata on the server. Used for teleporting the player back to the start of the TAS when using /play
+ *
SIDE: Server
+ * ARGS:
+ * double x The x value
+ * double y etc...
+ * double z
+ * float angleYaw
+ * float anglePitch
+ */
PLAYBACK_TELEPORT,
- STATESYNC,
+ /**
+ *
Notifies the players to change the {@link TASstate} + *
SIDE: Both
+ * ARGS:
+ * Client->Server {@link TASstate} state The new state everyone should adapt
+ * Server->Client
+ * {@link TASstate} state The new state everyone should adapt
+ * boolean verbose If a chat message should be printed
+ */
+ PLAYBACK_STATE,
/**
*
Opens a TASmod related folder on the file system *
The action describes which folder to open: @@ -109,7 +180,19 @@ public enum TASmodPackets implements PacketID { break; } }), + /** + *
Sets the KillTheRNG seed + *
SIDE: Both
+ * ARGS:
+ * long seed The new KillTheRNG seed
+ */
KILLTHERNG_SEED,
+ /**
+ *
Sets the KillTheRNG start seed when starting recording + *
SIDE: Both
+ * ARGS:
+ * long seed The new KillTheRNG seed
+ */
KILLTHERNG_STARTSEED;
private Side side;
diff --git a/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java
index 0e53fdea..c00a5aa3 100644
--- a/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java
+++ b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerClient.java
@@ -1,7 +1,7 @@
package com.minecrafttas.tasmod.playback;
import static com.minecrafttas.tasmod.TASmod.LOGGER;
-import static com.minecrafttas.tasmod.networking.TASmodPackets.CLEAR_INNPUTS;
+import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_CLEAR_INPUTS;
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_FULLPLAY;
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_FULLRECORD;
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_LOAD;
@@ -9,7 +9,7 @@
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_RESTARTANDPLAY;
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_SAVE;
import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_TELEPORT;
-import static com.minecrafttas.tasmod.networking.TASmodPackets.STATESYNC;
+import static com.minecrafttas.tasmod.networking.TASmodPackets.PLAYBACK_STATE;
import java.io.File;
import java.io.IOException;
@@ -147,7 +147,7 @@ public class PlaybackControllerClient implements ClientPacketHandler {
*/
public void setTASState(TASstate stateIn) {
try {
- TASmodClient.client.send(new TASmodBufferBuilder(STATESYNC).writeTASState(stateIn));
+ TASmodClient.client.send(new TASmodBufferBuilder(PLAYBACK_STATE).writeTASState(stateIn));
} catch (Exception e) {
e.printStackTrace();
}
@@ -171,7 +171,7 @@ public String setTASStateClient(TASstate stateIn) {
* @return The message printed in the chat
*/
public String setTASStateClient(TASstate stateIn, boolean verbose) {
- ControlByteHandler.reset();
+ ControlByteHandler.reset(); // FIXME Controlbytes are resetting when loading a world, due to "Paused" state being active during loading... Fix Paused state shenanigans?
if (state == stateIn) {
switch (stateIn) {
case PLAYBACK:
@@ -832,8 +832,8 @@ public PacketID[] getAcceptedPacketIDs() {
PLAYBACK_RESTARTANDPLAY,
PLAYBACK_PLAYUNTIL,
PLAYBACK_TELEPORT,
- CLEAR_INNPUTS,
- STATESYNC
+ PLAYBACK_CLEAR_INPUTS,
+ PLAYBACK_STATE
};
}
@@ -926,14 +926,14 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
TASmodClient.virtual.getContainer().setPlayUntil(until);
break;
- case CLEAR_INNPUTS:
+ case PLAYBACK_CLEAR_INPUTS:
TASmodClient.virtual.getContainer().clear();
break;
case PLAYBACK_TELEPORT:
throw new WrongSideException(packet, Side.CLIENT);
- case STATESYNC:
+ case PLAYBACK_STATE:
TASstate networkState = TASmodBufferBuilder.readTASState(buf);
boolean verbose = TASmodBufferBuilder.readBoolean(buf);
Task task = ()->{
diff --git a/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerServer.java b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerServer.java
index ffe6729e..98fd36f5 100644
--- a/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerServer.java
+++ b/src/main/java/com/minecrafttas/tasmod/playback/PlaybackControllerServer.java
@@ -33,9 +33,9 @@ public class PlaybackControllerServer implements ServerPacketHandler {
public PacketID[] getAcceptedPacketIDs() {
return new TASmodPackets[]
{
- STATESYNC,
+ PLAYBACK_STATE,
PLAYBACK_TELEPORT,
- CLEAR_INNPUTS,
+ PLAYBACK_CLEAR_INPUTS,
PLAYBACK_FULLPLAY,
PLAYBACK_FULLRECORD,
PLAYBACK_RESTARTANDPLAY,
@@ -51,7 +51,7 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
switch (packet) {
- case STATESYNC:
+ case PLAYBACK_STATE:
TASstate networkState = TASmodBufferBuilder.readTASState(buf);
/* TODO Permissions */
setState(networkState);
@@ -73,9 +73,9 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
});
break;
- case CLEAR_INNPUTS:
- TASmod.server.sendToAll(new TASmodBufferBuilder(CLEAR_INNPUTS));
-
+ case PLAYBACK_CLEAR_INPUTS:
+ TASmod.server.sendToAll(new TASmodBufferBuilder(PLAYBACK_CLEAR_INPUTS));
+ break;
case PLAYBACK_FULLPLAY:
case PLAYBACK_FULLRECORD:
case PLAYBACK_RESTARTANDPLAY:
@@ -93,7 +93,7 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
public void setState(TASstate stateIn) {
setServerState(stateIn);
try {
- TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.STATESYNC).writeTASState(state).writeBoolean(true));
+ TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.PLAYBACK_STATE).writeTASState(state).writeBoolean(true));
} catch (Exception e) {
e.printStackTrace();
}