mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Run packet listeners async from the Netty threads + Correctly shutdown
plugin if the server is in online mode.
This commit is contained in:
@ -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
|
######0.3.1
|
||||||
|
|
||||||
* Improved BungeeCord security
|
* Improved BungeeCord security
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package com.github.games647.fastlogin.bukkit;
|
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.BukkitJoinListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.StartPacketListener;
|
import com.github.games647.fastlogin.bukkit.listener.StartPacketListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.BungeeCordListener;
|
import com.github.games647.fastlogin.bukkit.listener.BungeeCordListener;
|
||||||
import com.github.games647.fastlogin.bukkit.listener.EncryptionPacketListener;
|
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.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.utility.SafeCacheBuilder;
|
import com.comphenix.protocol.utility.SafeCacheBuilder;
|
||||||
import com.github.games647.fastlogin.bukkit.hooks.AuthPlugin;
|
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.cache.CacheLoader;
|
||||||
import com.google.common.collect.MapMaker;
|
import com.google.common.collect.MapMaker;
|
||||||
import com.google.common.collect.Sets;
|
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
|
@Override
|
||||||
public void onEnable() {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//register packet listeners on success
|
//register packet listeners on success
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
protocolManager.addPacketListener(new HandshakePacketListener(this));
|
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
|
//register commands using a unique name
|
||||||
getCommand("premium").setExecutor(new PremiumCommand(this));
|
getCommand("premium").setExecutor(new PremiumCommand(this));
|
||||||
|
@ -2,6 +2,7 @@ package com.github.games647.fastlogin.bukkit;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -28,7 +28,6 @@ import java.util.logging.Level;
|
|||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
@ -205,7 +204,6 @@ public class EncryptionPacketListener extends PacketAdapter {
|
|||||||
private boolean hasJoinedServer(String username, String serverId) {
|
private boolean hasJoinedServer(String username, String serverId) {
|
||||||
try {
|
try {
|
||||||
String url = HAS_JOINED_URL + "username=" + username + "&serverId=" + serverId;
|
String url = HAS_JOINED_URL + "username=" + username + "&serverId=" + serverId;
|
||||||
|
|
||||||
HttpURLConnection conn = plugin.getConnection(url);
|
HttpURLConnection conn = plugin.getConnection(url);
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
@ -215,13 +213,6 @@ public class EncryptionPacketListener extends PacketAdapter {
|
|||||||
//http://wiki.vg/Protocol_Encryption#Server
|
//http://wiki.vg/Protocol_Encryption#Server
|
||||||
JSONObject userData = (JSONObject) JSONValue.parseWithException(line);
|
JSONObject userData = (JSONObject) JSONValue.parseWithException(line);
|
||||||
String uuid = (String) userData.get("id");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -11,17 +11,12 @@ import java.util.logging.Level;
|
|||||||
/**
|
/**
|
||||||
* Listens to incoming handshake packets.
|
* Listens to incoming handshake packets.
|
||||||
*
|
*
|
||||||
* As BungeeCord sends additional information on the Handshake,
|
* As BungeeCord sends additional information on the Handshake, we can detect it and check so if the player is coming
|
||||||
* we can detect it and check so if the player is coming from a
|
* from a BungeeCord instance. IpForward has to be activated in the BungeeCord config to send these extra information.
|
||||||
* BungeeCord instance. IpForward has to be activated in the
|
|
||||||
* BungeeCord config to send these extra information.
|
|
||||||
*
|
*
|
||||||
* Packet information:
|
* Packet information: http://wiki.vg/Protocol#Handshake
|
||||||
* http://wiki.vg/Protocol#Handshake
|
|
||||||
*
|
*
|
||||||
* Int=Protocol version
|
* Int=Protocol version String=connecting server address (and additional information from BungeeCord) int=server port
|
||||||
* String=connecting server address (and additional information from BungeeCord)
|
|
||||||
* int=server port
|
|
||||||
* int=next state
|
* int=next state
|
||||||
*/
|
*/
|
||||||
public class HandshakePacketListener extends PacketAdapter {
|
public class HandshakePacketListener extends PacketAdapter {
|
||||||
|
@ -12,7 +12,6 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
11
pom.xml
11
pom.xml
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<!--Possibility to deploy directly to the plugins folder-->
|
||||||
|
<outputDir>${basedir}/target</outputDir>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
@ -55,6 +57,15 @@
|
|||||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${outputDir}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
|
Reference in New Issue
Block a user