Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/main/java/com/minecrafttas/mctcommon/networking/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.channels.CompletionHandler;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
Expand Down Expand Up @@ -53,9 +54,9 @@ public class Client {
*/
private boolean local = false;


public enum Side {
CLIENT, SERVER;
CLIENT,
SERVER;
}

/**
Expand All @@ -71,7 +72,7 @@ public enum Side {
public Client(String host, int port, PacketID[] packetIDs, String name, boolean local) throws Exception {
LOGGER.info(Client, "Connecting server to {}:{}", host, port);
this.socket = AsynchronousSocketChannel.open();
this.socket.connect(new InetSocketAddress(host, port)).get();
this.socket.connect(new InetSocketAddress(host, port)).get(2, TimeUnit.SECONDS);
this.socket.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
this.socket.setOption(StandardSocketOptions.TCP_NODELAY, true);

Expand Down Expand Up @@ -173,7 +174,7 @@ public void completed(Integer result, Object attachment) {
readBuffer.clear().limit(4);
socket.read(readBuffer, null, this);
} catch (Throwable exc) {
if(exc instanceof ExecutionException && !isClosed()) {
if (exc instanceof ExecutionException && !isClosed()) {
LOGGER.debug(getLoggerMarker(), "{} terminated the connection!", getOppositeSide().name());
try {
close();
Expand All @@ -189,7 +190,7 @@ public void completed(Integer result, Object attachment) {
@Override
public void failed(Throwable exc, Object attachment) {
if (exc instanceof AsynchronousCloseException || exc instanceof IOException) {
if(isClosed()) {
if (isClosed()) {
return;
}
LOGGER.debug(getLoggerMarker(), "{} terminated the connection!", getOppositeSide().name());
Expand All @@ -199,7 +200,7 @@ public void failed(Throwable exc, Object attachment) {
LOGGER.error(getLoggerMarker(), "Attempted to close connection but failed", e);
}
} else {
if(isClosed()) {
if (isClosed()) {
return;
}
LOGGER.error(getLoggerMarker(), "Something went wrong, terminating connection!", exc);
Expand All @@ -221,7 +222,7 @@ public void failed(Throwable exc, Object attachment) {
* @throws Exception Networking exception
*/
public void send(ByteBufferBuilder bufferBuilder) throws Exception {
if(bufferBuilder.getPacketID() != null && bufferBuilder.getPacketID().shouldTrace())
if (bufferBuilder.getPacketID() != null && bufferBuilder.getPacketID().shouldTrace())
LOGGER.trace(getLoggerMarker(), "Sending a {} packet to the {} with content:\n{}", bufferBuilder.getPacketID(), getOppositeSide(), bufferBuilder.getPacketContent());
// wait for previous buffer to send
if (this.future != null && !this.future.isDone())
Expand Down Expand Up @@ -264,7 +265,7 @@ private void close() throws IOException {
private Marker getLoggerMarker() {
return side == Side.CLIENT ? Client : Server;
}

private Side getOppositeSide() {
return side == Side.CLIENT ? Side.SERVER : Side.CLIENT;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.concurrent.TimeoutException;

import org.apache.logging.log4j.Level;

Expand Down Expand Up @@ -243,11 +244,12 @@ public void onPlayerJoinedClientSide(EntityPlayerSP player) {
try {
// connect to server and authenticate
client = new Client(IP, PORT, TASmodPackets.values(), mc.getSession().getUsername(), local);
} catch (TimeoutException e) {
mc.getConnection().getNetworkManager().closeChannel(null);
} catch (Exception e) {
LOGGER.error("Unable to connect TASmod client: {}", e.getMessage());
e.printStackTrace();
}
ticksyncClient.setEnabled(true);
});
}
}
Expand Down Expand Up @@ -298,7 +300,6 @@ private void initializeCustomPacketHandler() {
} catch (Exception e) {
LOGGER.error("Unable to connect TASmod client: {}", e);
}
ticksyncClient.setEnabled(true);
}
}

Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/com/minecrafttas/tasmod/gui/GuiMultiplayerWarn.java

This file was deleted.

23 changes: 11 additions & 12 deletions src/main/java/com/minecrafttas/tasmod/mixin/MixinTimer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.minecrafttas.tasmod.mixin;


import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -21,36 +20,36 @@
*
*/
public class MixinTimer {

@Shadow
private int elapsedTicks;
private int elapsedTicks;
@Shadow
private float renderPartialTicks;
private float renderPartialTicks;
@Shadow
private float elapsedPartialTicks;
private float elapsedPartialTicks;
@Shadow
private long lastSyncSysClock;
private long lastSyncSysClock;
@Shadow
private float tickLength;
private float tickLength;

@Unique
private long millisLastTick;
@Unique
private long lastGameLoop;
@Unique
private float lastTickDuration;

@Inject(method = "updateTimer", at = @At("HEAD"), cancellable = true)
public void inject_tick(CallbackInfo ci) {
if (TASmodClient.client != null && !TASmodClient.client.isClosed() && TASmodClient.ticksyncClient.isEnabled()) {
if (TASmodClient.client != null && !TASmodClient.client.isClosed()) {
lastSyncSysClock = Minecraft.getSystemTime(); // update the tick tracker so that after returning to scheduling the client won't catch up all ticks (max 10)
this.elapsedTicks = 0; // do not do any ticks
long newGameLoop = Minecraft.getSystemTime();
if (TickSyncClient.shouldTick.compareAndSet(true, false)) {
this.elapsedTicks++;
this.lastTickDuration = newGameLoop - this.millisLastTick;
if(TASmodClient.tickratechanger.advanceTick) {
lastTickDuration = TASmodClient.tickratechanger.millisecondsPerTick; // Keep the lastTick duration steady during tickadvance, since it grows larger the longer you wait in tickrate 0
if (TASmodClient.tickratechanger.advanceTick) {
lastTickDuration = TASmodClient.tickratechanger.millisecondsPerTick; // Keep the lastTick duration steady during tickadvance, since it grows larger the longer you wait in tickrate 0
}
this.millisLastTick = newGameLoop; // Update millisLastTick
this.renderPartialTicks = 0; // Reset after the tick
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class TickSyncClient implements ClientPacketHandler, EventClientTickPost

public static final AtomicBoolean shouldTick = new AtomicBoolean(true);

private boolean enabled = false;

@Override
public PacketID[] getAcceptedPacketIDs() {
return new TASmodPackets[] { TASmodPackets.TICKSYNC };
Expand All @@ -52,7 +50,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) {
*/
@Override
public void onClientTickPost(Minecraft mc) {
if (TASmodClient.client == null || TASmodClient.client.isClosed() || !enabled) {
if (TASmodClient.client == null || TASmodClient.client.isClosed()) {
return;
}

Expand All @@ -62,12 +60,4 @@ public void onClientTickPost(Minecraft mc) {
LOGGER.error("Unable to send packet to server:", e);
}
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
1 change: 0 additions & 1 deletion src/main/resources/tasmod.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"MixinTextfield",

// Events
"events.MixinGuiMainMenu",
"events.MixinGuiIngame",
"events.MixinEntityRenderer",

Expand Down