geforkt von SteamWar/BungeeCore
Merge branch 'removingPair' of SteamWar/BungeeCore into master
Dieser Commit ist enthalten in:
Commit
7d08c0069c
@ -5,7 +5,6 @@ import de.steamwar.bungeecore.listeners.BasicListener;
|
|||||||
import de.steamwar.bungeecore.sql.Mod;
|
import de.steamwar.bungeecore.sql.Mod;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.UnpooledByteBufAllocator;
|
import io.netty.buffer.UnpooledByteBufAllocator;
|
||||||
import javafx.util.Pair;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
import net.md_5.bungee.api.connection.Connection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -74,11 +73,11 @@ public class Forge extends BasicListener {
|
|||||||
ProxiedPlayer p = (ProxiedPlayer) sender;
|
ProxiedPlayer p = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
if (data[0] == 2) {
|
if (data[0] == 2) {
|
||||||
Pair<Integer, Integer> numMods = Utils.readVarInt(data, 1);
|
Utils.VarInt numMods = Utils.readVarInt(data, 1);
|
||||||
List<Mod> mods = new LinkedList<>();
|
List<Mod> mods = new LinkedList<>();
|
||||||
|
|
||||||
int bytePos = 1 + numMods.getKey();
|
int bytePos = 1 + numMods.length;
|
||||||
for (int i = 0; i < numMods.getValue(); i++) {
|
for (int i = 0; i < numMods.value; i++) {
|
||||||
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
|
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
|
||||||
bytePos += 1 + data[bytePos];
|
bytePos += 1 + data[bytePos];
|
||||||
//Version information is unused
|
//Version information is unused
|
||||||
|
@ -5,23 +5,22 @@ import com.google.gson.stream.JsonReader;
|
|||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
import de.steamwar.bungeecore.listeners.BasicListener;
|
import de.steamwar.bungeecore.listeners.BasicListener;
|
||||||
import de.steamwar.bungeecore.sql.Mod;
|
import de.steamwar.bungeecore.sql.Mod;
|
||||||
import javafx.util.Pair;
|
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.connection.Connection;
|
import net.md_5.bungee.api.connection.Connection;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class LabyMod extends BasicListener {
|
public class LabyMod extends BasicListener {
|
||||||
|
|
||||||
private static Set<ProxiedPlayer> labyModUsers = new HashSet<>();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPluginMessageEvent(PluginMessageEvent event){
|
public void onPluginMessageEvent(PluginMessageEvent event){
|
||||||
if(!event.getTag().equals("LMC"))
|
if(!event.getTag().equals("LMC"))
|
||||||
@ -32,7 +31,6 @@ public class LabyMod extends BasicListener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
labyModUsers.add((ProxiedPlayer) sender);
|
|
||||||
updateGameInfo((ProxiedPlayer) sender);
|
updateGameInfo((ProxiedPlayer) sender);
|
||||||
byte[] data = event.getData();
|
byte[] data = event.getData();
|
||||||
|
|
||||||
@ -40,15 +38,15 @@ public class LabyMod extends BasicListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void runAsync(byte[] data, ProxiedPlayer player) {
|
private void runAsync(byte[] data, ProxiedPlayer player) {
|
||||||
Pair<Integer, String> purpose = readString(data, 0);
|
VarString purpose = readString(data, 0);
|
||||||
if(!"INFO".equals(purpose.getValue()))
|
if(!"INFO".equals(purpose.value))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Pair<Integer, String> value = readString(data, purpose.getKey());
|
VarString value = readString(data, purpose.length);
|
||||||
List<Mod> mods = new LinkedList<>();
|
List<Mod> mods = new LinkedList<>();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
InfoPacket info = new InfoPacket(value.getValue());
|
InfoPacket info = new InfoPacket(value.value);
|
||||||
for(InfoPacket.Addon addon : info.addons) {
|
for(InfoPacket.Addon addon : info.addons) {
|
||||||
mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD));
|
mods.add(Mod.get(addon.name, Mod.Platform.LABYMOD));
|
||||||
}
|
}
|
||||||
@ -59,10 +57,10 @@ public class LabyMod extends BasicListener {
|
|||||||
Utils.handleMods(player, mods);
|
Utils.handleMods(player, mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Integer, String> readString(byte[] array, int startPos){
|
private VarString readString(byte[] array, int startPos){
|
||||||
Pair<Integer, Integer> varInt = Utils.readVarInt(array, startPos);
|
Utils.VarInt varInt = Utils.readVarInt(array, startPos);
|
||||||
startPos += varInt.getKey();
|
startPos += varInt.length;
|
||||||
return new Pair<>(varInt.getValue()+varInt.getKey(), new String(Arrays.copyOfRange(array, startPos, startPos + varInt.getValue()), StandardCharsets.UTF_8));
|
return new VarString(varInt.value+varInt.length, new String(Arrays.copyOfRange(array, startPos, startPos + varInt.value), StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGameInfo(ProxiedPlayer proxiedPlayer) {
|
private void updateGameInfo(ProxiedPlayer proxiedPlayer) {
|
||||||
@ -76,6 +74,16 @@ public class LabyMod extends BasicListener {
|
|||||||
proxiedPlayer.sendData("LMC", output.getBytes());
|
proxiedPlayer.sendData("LMC", output.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class VarString{
|
||||||
|
private final int length;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
private VarString(int length, String value) {
|
||||||
|
this.length = length;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class InfoPacket{
|
private static class InfoPacket{
|
||||||
String version = null;
|
String version = null;
|
||||||
Feature ccp = null;
|
Feature ccp = null;
|
||||||
@ -154,11 +162,4 @@ public class LabyMod extends BasicListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onDisconnect(PlayerDisconnectEvent event){
|
|
||||||
labyModUsers.remove(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: PlayerHandshakeEvent
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import de.steamwar.bungeecore.BungeeCore;
|
|||||||
import de.steamwar.bungeecore.sql.Mod;
|
import de.steamwar.bungeecore.sql.Mod;
|
||||||
import de.steamwar.bungeecore.sql.Mod.ModType;
|
import de.steamwar.bungeecore.sql.Mod.ModType;
|
||||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||||
import javafx.util.Pair;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@ -16,7 +15,7 @@ import java.util.List;
|
|||||||
class Utils {
|
class Utils {
|
||||||
private Utils(){}
|
private Utils(){}
|
||||||
|
|
||||||
static Pair<Integer, Integer> readVarInt(byte[] array, int startPos) {
|
static VarInt readVarInt(byte[] array, int startPos) {
|
||||||
int numRead = 0;
|
int numRead = 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
byte read;
|
byte read;
|
||||||
@ -31,7 +30,7 @@ class Utils {
|
|||||||
}
|
}
|
||||||
} while ((read & 0b10000000) != 0);
|
} while ((read & 0b10000000) != 0);
|
||||||
|
|
||||||
return new Pair<>(numRead, result);
|
return new VarInt(numRead, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean handleMods(ProxiedPlayer player, List<Mod> mods){
|
static boolean handleMods(ProxiedPlayer player, List<Mod> mods){
|
||||||
@ -68,4 +67,14 @@ class Utils {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class VarInt{
|
||||||
|
final int length;
|
||||||
|
final int value;
|
||||||
|
|
||||||
|
VarInt(int length, int value){
|
||||||
|
this.length = length;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren