Run packet listeners async from the Netty threads + Correctly shutdown

plugin if the server is in online mode.
This commit is contained in:
games647
2015-11-23 20:20:40 +01:00
parent f8c10d6890
commit d118de8649
7 changed files with 33 additions and 34 deletions

View File

@ -1,3 +1,9 @@
######0.3.2
* Run packet readers in a different thread (separated from the Netty I/O Thread)
-> Improves performance
* Fixed Plugin disable if the server is in online mode but have to be in offline mode
######0.3.1
* Improved BungeeCord security

View File

@ -1,14 +1,15 @@
package com.github.games647.fastlogin.bukkit;
import com.comphenix.protocol.AsynchronousManager;
import com.github.games647.fastlogin.bukkit.listener.BukkitJoinListener;
import com.github.games647.fastlogin.bukkit.listener.StartPacketListener;
import com.github.games647.fastlogin.bukkit.listener.BungeeCordListener;
import com.github.games647.fastlogin.bukkit.listener.EncryptionPacketListener;
import com.github.games647.fastlogin.bukkit.listener.HandshakePacketListener;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin;
import com.github.games647.fastlogin.bukkit.listener.HandshakePacketListener;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Sets;
@ -59,28 +60,23 @@ public class FastLoginBukkit extends JavaPlugin {
}
});
@Override
public void onLoad() {
//online mode is only changeable after a restart so check it here
if (getServer().getOnlineMode()) {
//we need to require offline to prevent a session request for a offline player
getLogger().severe("Server have to be in offline mode");
setEnabled(false);
}
}
@Override
public void onEnable() {
if (!isEnabled() || !registerHooks()) {
if (getServer().getOnlineMode() || !registerHooks()) {
//we need to require offline to prevent a session request for a offline player
getLogger().severe("Server have to be in offline mode and have an auth plugin installed");
setEnabled(false);
return;
}
//register packet listeners on success
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
protocolManager.addPacketListener(new HandshakePacketListener(this));
protocolManager.addPacketListener(new StartPacketListener(this, protocolManager));
protocolManager.addPacketListener(new EncryptionPacketListener(this, protocolManager));
//we are performing HTTP request on these so run it async (seperate from the Netty IO threads)
AsynchronousManager asynchronousManager = protocolManager.getAsynchronousManager();
asynchronousManager.registerAsyncHandler(new StartPacketListener(this, protocolManager)).start();
asynchronousManager.registerAsyncHandler(new EncryptionPacketListener(this, protocolManager)).start();
//register commands using a unique name
getCommand("premium").setExecutor(new PremiumCommand(this));

View File

@ -2,6 +2,7 @@ package com.github.games647.fastlogin.bukkit;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;

View File

@ -28,7 +28,6 @@ import java.util.logging.Level;
import javax.crypto.SecretKey;
import org.bukkit.entity.Player;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
@ -205,7 +204,6 @@ public class EncryptionPacketListener extends PacketAdapter {
private boolean hasJoinedServer(String username, String serverId) {
try {
String url = HAS_JOINED_URL + "username=" + username + "&serverId=" + serverId;
HttpURLConnection conn = plugin.getConnection(url);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
@ -215,13 +213,6 @@ public class EncryptionPacketListener extends PacketAdapter {
//http://wiki.vg/Protocol_Encryption#Server
JSONObject userData = (JSONObject) JSONValue.parseWithException(line);
String uuid = (String) userData.get("id");
String name = (String) userData.get("name");
JSONArray properties = (JSONArray) userData.get("properties");
JSONObject skinData = (JSONObject) properties.get(0);
//base64 encoded skin data
String encodedSkin = (String) skinData.get("value");
return true;
}
} catch (Exception ex) {

View File

@ -11,17 +11,12 @@ import java.util.logging.Level;
/**
* Listens to incoming handshake packets.
*
* As BungeeCord sends additional information on the Handshake,
* we can detect it and check so if the player is coming from a
* BungeeCord instance. IpForward has to be activated in the
* BungeeCord config to send these extra information.
* As BungeeCord sends additional information on the Handshake, we can detect it and check so if the player is coming
* from a BungeeCord instance. IpForward has to be activated in the BungeeCord config to send these extra information.
*
* Packet information:
* http://wiki.vg/Protocol#Handshake
* Packet information: http://wiki.vg/Protocol#Handshake
*
* Int=Protocol version
* String=connecting server address (and additional information from BungeeCord)
* int=server port
* Int=Protocol version String=connecting server address (and additional information from BungeeCord) int=server port
* int=next state
*/
public class HandshakePacketListener extends PacketAdapter {

View File

@ -12,7 +12,6 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.security.PublicKey;
import java.util.Random;
import java.util.logging.Level;
import java.util.regex.Pattern;

11
pom.xml
View File

@ -17,6 +17,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--Possibility to deploy directly to the plugins folder-->
<outputDir>${basedir}/target</outputDir>
</properties>
<modules>
@ -55,6 +57,15 @@
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${outputDir}</outputDirectory>
</configuration>
</plugin>
</plugins>
<resources>