mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Updated netty + fix network crash
This commit is contained in:
parent
eb5659c235
commit
589079f8f6
@ -18,9 +18,9 @@ dependencies {
|
|||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||||
api group: 'io.netty', name: 'netty-all', version: '4.1.48.Final'
|
api group: 'io.netty', name: 'netty-all', version: '4.1.50.Final'
|
||||||
|
|
||||||
api 'com.github.jhg023:Pbbl:1.0.1'
|
api 'com.github.jhg023:Pbbl:1.0.2'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
||||||
api group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
|
api group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.0'
|
||||||
@ -28,7 +28,7 @@ dependencies {
|
|||||||
api 'com.github.Querz:NBT:4.1'
|
api 'com.github.Querz:NBT:4.1'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||||
api group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
|
||||||
|
|
||||||
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class UpdateManager {
|
|||||||
player.refreshKeepAlive(time);
|
player.refreshKeepAlive(time);
|
||||||
player.getPlayerConnection().sendPacket(keepAlivePacket);
|
player.getPlayerConnection().sendPacket(keepAlivePacket);
|
||||||
} else if (lastKeepAlive >= KEEP_ALIVE_KICK) {
|
} else if (lastKeepAlive >= KEEP_ALIVE_KICK) {
|
||||||
TextComponent textComponent = TextComponent.of("No Keep Alive answer")
|
TextComponent textComponent = TextComponent.of("Timeout")
|
||||||
.color(TextColor.RED);
|
.color(TextColor.RED);
|
||||||
player.kick(textComponent);
|
player.kick(textComponent);
|
||||||
}
|
}
|
||||||
|
@ -249,9 +249,9 @@ public class Player extends LivingEntity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to initialize the player connection
|
* Used to initialize the player connection
|
||||||
* mostly used by {@link net.minestom.server.entity.fakeplayer.FakePlayer}
|
|
||||||
*/
|
*/
|
||||||
protected void playerConnectionInit() {
|
protected void playerConnectionInit() {
|
||||||
|
this.playerConnection.setPlayer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -282,9 +282,10 @@ public class Player extends LivingEntity {
|
|||||||
|
|
||||||
// Target block stage
|
// Target block stage
|
||||||
if (targetCustomBlock != null) {
|
if (targetCustomBlock != null) {
|
||||||
final int animationCount = 10;
|
final byte animationCount = 10;
|
||||||
long since = System.currentTimeMillis() - targetBlockTime;
|
long since = System.currentTimeMillis() - targetBlockTime;
|
||||||
byte stage = (byte) (since / (blockBreakTime / animationCount) - 1);
|
byte stage = (byte) (since / (blockBreakTime / animationCount) - 1);
|
||||||
|
stage = MathUtils.setBetween(stage, (byte) -1, animationCount);
|
||||||
if (stage != targetLastStage) {
|
if (stage != targetLastStage) {
|
||||||
sendBlockBreakAnimation(targetBlockPosition, stage);
|
sendBlockBreakAnimation(targetBlockPosition, stage);
|
||||||
}
|
}
|
||||||
@ -468,6 +469,7 @@ public class Player extends LivingEntity {
|
|||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
|
this.packets.clear();
|
||||||
clearBossBars();
|
clearBossBars();
|
||||||
if (getOpenInventory() != null)
|
if (getOpenInventory() != null)
|
||||||
getOpenInventory().removeViewer(this);
|
getOpenInventory().removeViewer(this);
|
||||||
|
@ -46,11 +46,13 @@ public class PacketListenerManager {
|
|||||||
|
|
||||||
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
public <T extends ClientPlayPacket> void process(T packet, Player player) {
|
||||||
|
|
||||||
PacketListenerConsumer<T> packetListenerConsumer = listeners.get(packet.getClass());
|
final Class clazz = packet.getClass();
|
||||||
|
|
||||||
|
PacketListenerConsumer<T> packetListenerConsumer = listeners.get(clazz);
|
||||||
|
|
||||||
// Listener can be null if none has been set before, call PacketConsumer anyway
|
// Listener can be null if none has been set before, call PacketConsumer anyway
|
||||||
if (packetListenerConsumer == null) {
|
if (packetListenerConsumer == null) {
|
||||||
System.err.println("Packet " + packet.getClass() + " does not have any default listener!");
|
System.err.println("Packet " + clazz + " does not have any default listener!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class PacketProcessor {
|
|||||||
|
|
||||||
switch (connectionState) {
|
switch (connectionState) {
|
||||||
case PLAY:
|
case PLAY:
|
||||||
Player player = connectionManager.getPlayer(playerConnection);
|
Player player = playerConnection.getPlayer();
|
||||||
ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(id);
|
ClientPlayPacket playPacket = (ClientPlayPacket) playPacketsHandler.getPacketInstance(id);
|
||||||
playPacket.read(packetReader);
|
playPacket.read(packetReader);
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public class PacketWriterUtils {
|
|||||||
playerConnection.sendPacket(serverPacket);
|
playerConnection.sendPacket(serverPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
buffer.release();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +46,8 @@ public class PacketWriterUtils {
|
|||||||
batchesPool.execute(() -> {
|
batchesPool.execute(() -> {
|
||||||
if (PlayerUtils.isNettyClient(playerConnection)) {
|
if (PlayerUtils.isNettyClient(playerConnection)) {
|
||||||
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
ByteBuf buffer = PacketUtils.writePacket(serverPacket);
|
||||||
playerConnection.sendPacket(buffer);
|
playerConnection.writePacket(buffer);
|
||||||
|
buffer.release();
|
||||||
} else {
|
} else {
|
||||||
playerConnection.sendPacket(serverPacket);
|
playerConnection.sendPacket(serverPacket);
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,9 @@ public class ClientChannel extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
public void channelRead(ChannelHandlerContext ctx, Object obj) {
|
||||||
PacketHandler packetHandler = (PacketHandler) msg;
|
PacketHandler packetHandler = (PacketHandler) obj;
|
||||||
|
|
||||||
int packetLength = packetHandler.length;
|
int packetLength = packetHandler.length;
|
||||||
ByteBuf buffer = packetHandler.buffer;
|
ByteBuf buffer = packetHandler.buffer;
|
||||||
|
|
||||||
@ -49,11 +50,6 @@ public class ClientChannel extends ChannelInboundHandlerAdapter {
|
|||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
|
||||||
super.channelReadComplete(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelInactive(ChannelHandlerContext ctx) {
|
public void channelInactive(ChannelHandlerContext ctx) {
|
||||||
PlayerConnection playerConnection = packetProcessor.getPlayerConnection(ctx);
|
PlayerConnection playerConnection = packetProcessor.getPlayerConnection(ctx);
|
||||||
@ -62,7 +58,6 @@ public class ClientChannel extends ChannelInboundHandlerAdapter {
|
|||||||
Player player = connectionManager.getPlayer(playerConnection);
|
Player player = connectionManager.getPlayer(playerConnection);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.remove();
|
player.remove();
|
||||||
|
|
||||||
connectionManager.removePlayer(playerConnection);
|
connectionManager.removePlayer(playerConnection);
|
||||||
}
|
}
|
||||||
packetProcessor.removePlayerConnection(ctx);
|
packetProcessor.removePlayerConnection(ctx);
|
||||||
|
@ -2,11 +2,14 @@ package net.minestom.server.network.packet.client;
|
|||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.listener.manager.PacketListenerManager;
|
||||||
|
|
||||||
public abstract class ClientPlayPacket implements ClientPacket {
|
public abstract class ClientPlayPacket implements ClientPacket {
|
||||||
|
|
||||||
|
private static final PacketListenerManager PACKET_LISTENER_MANAGER = MinecraftServer.getPacketListenerManager();
|
||||||
|
|
||||||
public void process(Player player) {
|
public void process(Player player) {
|
||||||
MinecraftServer.getPacketListenerManager().process(this, player);
|
PACKET_LISTENER_MANAGER.process(this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.network.player;
|
package net.minestom.server.network.player;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.network.ConnectionState;
|
import net.minestom.server.network.ConnectionState;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ import java.net.SocketAddress;
|
|||||||
*/
|
*/
|
||||||
public abstract class PlayerConnection {
|
public abstract class PlayerConnection {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
private ConnectionState connectionState;
|
private ConnectionState connectionState;
|
||||||
private boolean online;
|
private boolean online;
|
||||||
|
|
||||||
@ -35,6 +37,14 @@ public abstract class PlayerConnection {
|
|||||||
*/
|
*/
|
||||||
public abstract void disconnect();
|
public abstract void disconnect();
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlayer(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
return online;
|
return online;
|
||||||
}
|
}
|
||||||
|
@ -47,4 +47,16 @@ public class MathUtils {
|
|||||||
return number >= min && number <= max;
|
return number >= min && number <= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte setBetween(byte number, byte min, byte max) {
|
||||||
|
return number > max ? max : number < min ? min : number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int setBetween(int number, int min, int max) {
|
||||||
|
return number > max ? max : number < min ? min : number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float setBetween(float number, float min, float max) {
|
||||||
|
return number > max ? max : number < min ? min : number;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.minestom.server.utils.buffer;
|
package net.minestom.server.utils.buffer;
|
||||||
|
|
||||||
import pbbl.heap.HeapByteBufferPool;
|
import com.github.pbbl.heap.ByteBufferPool;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class BufferUtils {
|
public class BufferUtils {
|
||||||
|
|
||||||
private static HeapByteBufferPool pool = new HeapByteBufferPool();
|
private static ByteBufferPool pool = new ByteBufferPool();
|
||||||
|
|
||||||
public static BufferWrapper getBuffer(int size) {
|
public static BufferWrapper getBuffer(int size) {
|
||||||
return new BufferWrapper(pool.take(size));
|
return new BufferWrapper(pool.take(size));
|
||||||
|
Loading…
Reference in New Issue
Block a user