Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/new-raknet' into redrak
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/cn/nukkit/level/generator/Normal.java
#	src/main/java/cn/nukkit/raknet/server/UDPServerSocket.java
#	src/main/resources/lang
  • Loading branch information
Sleepybear committed Jan 15, 2020
2 parents 46b845f + f79eb4f commit da00d03
Show file tree
Hide file tree
Showing 81 changed files with 526 additions and 3,897 deletions.
37 changes: 20 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>com.nukkitx.network</groupId>
<artifactId>raknet</artifactId>
<version>1.6.15</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nukkitx</groupId>
<artifactId>fastutil-lite</artifactId>
Expand Down Expand Up @@ -90,19 +96,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.6.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>4.1.6.Final</version>
<scope>compile</scope>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -191,6 +184,20 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifestEntries>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<Main-Class>cn.nukkit.Nukkit</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
Expand Down Expand Up @@ -257,14 +264,10 @@
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cn.nukkit.Nukkit</mainClass>
</transformer>
<transformer
implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
</transformer>
</transformers>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
</configuration>
</plugin>
<plugin>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/cn/nukkit/Nukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.utils.ServerKiller;
import com.google.common.base.Preconditions;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.internal.logging.InternalLoggerFactory;
import io.netty.util.internal.logging.Log4J2LoggerFactory;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
Expand Down Expand Up @@ -63,6 +66,10 @@ public static void main(String[] args) {
// Force Mapped ByteBuffers for LevelDB till fixed.
System.setProperty("leveldb.mmap", "true");

// Netty logger for debug info
InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE);
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);

// Define args
OptionParser parser = new OptionParser();
parser.allowsUnrecognizedOptions();
Expand Down
100 changes: 34 additions & 66 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import cn.nukkit.potion.Effect;
import cn.nukkit.resourcepacks.ResourcePack;
import cn.nukkit.scheduler.AsyncTask;
import cn.nukkit.scheduler.Task;
import cn.nukkit.utils.*;
import co.aikar.timings.Timing;
import co.aikar.timings.Timings;
Expand Down Expand Up @@ -161,10 +160,9 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
protected Vector3 teleportPosition = null;

protected boolean connected = true;
protected final String ip;
protected final InetSocketAddress socketAddress;
protected boolean removeFormat = true;

protected final int port;
protected String username;
protected String iusername;
protected String displayName;
Expand Down Expand Up @@ -202,8 +200,6 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde

protected boolean checkMovement = true;

private final Int2ObjectOpenHashMap<Boolean> needACK = new Int2ObjectOpenHashMap<>();

private final Map<Integer, List<DataPacket>> batchedPackets = new TreeMap<>();

private PermissibleBase perm = null;
Expand Down Expand Up @@ -591,16 +587,7 @@ public void sendCommandData() {
if (count > 0) {
//TODO: structure checking
pk.commands = data;
int identifier = this.dataPacket(pk, true); // We *need* ACK so we can be sure that the client received the packet or not
Server.getInstance().getScheduler().scheduleDelayedTask(new Task() {
@Override
public void onRun(int currentTick) {
Boolean status = needACK.get(identifier);
if ((status == null || !status) && isOnline()) {
sendCommandData();
}
}
}, 60, true);
this.dataPacket(pk);
}
}

Expand All @@ -609,14 +596,13 @@ public Map<String, PermissionAttachmentInfo> getEffectivePermissions() {
return this.perm.getEffectivePermissions();
}

public Player(SourceInterface interfaz, Long clientID, String ip, int port) {
public Player(SourceInterface interfaz, Long clientID, InetSocketAddress socketAddress) {
super(null, new CompoundTag());
this.interfaz = interfaz;
this.perm = new PermissibleBase(this);
this.server = Server.getInstance();
this.lastBreak = -1;
this.ip = ip;
this.port = port;
this.socketAddress = socketAddress;
this.clientID = clientID;
this.loaderId = Level.generateChunkLoaderId(this);
this.chunksPerTick = this.server.getConfig("chunk-sending.per-tick", 4);
Expand Down Expand Up @@ -679,11 +665,15 @@ public void setSkin(Skin skin) {
}

public String getAddress() {
return this.ip;
return this.socketAddress.getAddress().getHostAddress();
}

public int getPort() {
return port;
return this.socketAddress.getPort();
}

public InetSocketAddress getSocketAddress() {
return this.socketAddress;
}

public Position getNextPosition() {
Expand Down Expand Up @@ -1060,33 +1050,24 @@ public boolean batchDataPacket(DataPacket packet) {
* @return packet successfully sent
*/
public boolean dataPacket(DataPacket packet) {
return this.dataPacket(packet, false) != -1;
}

public int dataPacket(DataPacket packet, boolean needACK) {
if (!this.connected) {
return -1;
return false;
}

try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return -1;
}

if (log.isTraceEnabled() && !(packet instanceof BatchPacket)) {
log.trace("Outbound {}: {}", this.getName(), packet);
return false;
}

Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

if (needACK && identifier != null) {
this.needACK.put(identifier, Boolean.FALSE);
return identifier;
}
this.interfaz.putPacket(this, packet, false, false);
}
return 0;
return true;
}

@Deprecated
public int dataPacket(DataPacket packet, boolean needACK) {
return this.dataPacket(packet) ? 0 : -1;
}

/**
Expand All @@ -1097,29 +1078,25 @@ public int dataPacket(DataPacket packet, boolean needACK) {
* @return packet successfully sent
*/
public boolean directDataPacket(DataPacket packet) {
return this.directDataPacket(packet, false) != -1;
}

public int directDataPacket(DataPacket packet, boolean needACK) {
if (!this.connected) {
return -1;
return false;
}

try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return -1;
return false;
}

Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);

if (needACK && identifier != null) {
this.needACK.put(identifier, Boolean.FALSE);
return identifier;
}
this.interfaz.putPacket(this, packet, false, true);
}
return 0;
return true;
}

@Deprecated
public int directDataPacket(DataPacket packet, boolean needACK) {
return this.directDataPacket(packet) ? 0 : -1;
}

public int getPing() {
Expand Down Expand Up @@ -2060,8 +2037,8 @@ protected void completeLoginSequence() {

this.server.getLogger().info(this.getServer().getLanguage().translateString("nukkit.player.logIn",
TextFormat.AQUA + this.username + TextFormat.WHITE,
this.ip,
String.valueOf(this.port),
this.getAddress(),
String.valueOf(this.getPort()),
String.valueOf(this.id),
this.level.getName(),
String.valueOf(NukkitMath.round(this.x, 4)),
Expand Down Expand Up @@ -2199,7 +2176,7 @@ public void handleDataPacket(DataPacket packet) {

@Override
public void onRun() {
e = new PlayerAsyncPreLoginEvent(username, uuid, ip, port);
e = new PlayerAsyncPreLoginEvent(username, uuid, Player.this.getAddress(), Player.this.getPort());
server.getPluginManager().callEvent(e);
}

Expand Down Expand Up @@ -3025,7 +3002,7 @@ public void onCompletion(Server server) {
if (spamBug) {
return;
}

this.setDataFlag(DATA_FLAGS, DATA_FLAG_ACTION, false);

if (this.canInteract(blockVector.add(0.5, 0.5, 0.5), this.isCreative() ? 13 : 7)) {
Expand Down Expand Up @@ -3630,8 +3607,8 @@ public void close(TextContainer message, String reason, boolean notify) {
this.spawned = false;
this.server.getLogger().info(this.getServer().getLanguage().translateString("nukkit.player.logOut",
TextFormat.AQUA + (this.getName() == null ? "" : this.getName()) + TextFormat.WHITE,
this.ip,
String.valueOf(this.port),
this.getAddress(),
String.valueOf(this.getPort()),
this.getServer().getLanguage().translateString(reason)));
this.windows.clear();
this.usedChunks.clear();
Expand Down Expand Up @@ -4875,15 +4852,6 @@ public boolean equals(Object obj) {
return Objects.equals(this.getUniqueId(), other.getUniqueId()) && this.getId() == other.getId();
}

/**
* Notifies an ACK response from the client
*
* @param identification packet identity
*/
public void notifyACK(int identification) {
needACK.put(identification, Boolean.TRUE);
}

public boolean isBreakingBlock() {
return this.breakingBlock != null;
}
Expand Down
Loading

0 comments on commit da00d03

Please sign in to comment.